2

I am working on a small and very basic project, essentially doing a POC involving stellar transactions. I am a newbie with stellar. I have two clients running the same code, and a 'banker' who collects the transactions and notifies the two clients of received transactions. I followed the stellar developer documentation and am able to successfully send two transactions (one from each client) to the banker, and receive/parse the incoming transactions from the banker.

However, when I go to reply to the clients from the banker, the transaction is seemingly never sent. There is no exception, but when I query the server for transactions involving the banker test account immediately following the submission of the transactions, the latest record (descending order) is still the incoming message from the client. If anyone could provide any insight as to what I may be doing wrong, it would be greatly appreciated.

Here is the client transaction being sent:

    Network.useTestNetwork();
    Server server = new Server("https://horizon-testnet.stellar.org");

    KeyPair destination = KeyPair.fromAccountId(bankerAccountId);

    try {
        server.accounts().account(destination);
    }
    catch(Exception e) {
        System.out.println(e.getMessage());
        return;
    }

    AccountResponse sourceAccount;
    try {
        sourceAccount = server.accounts().account(pair);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        return;
    }

    Transaction transaction = new Transaction.Builder(sourceAccount)
            .addOperation(new PaymentOperation.Builder(destination, new AssetTypeNative(), betAmount).build())
            .addMemo(Memo.text(Double.parseDouble(betAmount) + " " + randomNumber))
            .build();
    // Sign the transaction to prove you are actually the person sending it.
    transaction.sign(pair);


    // And finally, send it off to Stellar!
    try {
      SubmitTransactionResponse response = server.submitTransaction(transaction);
      System.out.println("Success!");
    } catch (Exception e) {
      System.out.println("Something went wrong!");
      System.out.println(e.getMessage());
    }

And here is my attempt (after receiving the client message(s)) to reply:

    KeyPair destination1 = KeyPair.fromAccountId(player1.getAccountId());
    System.out.println(player1.getAccountId());
    KeyPair destination2 = KeyPair.fromAccountId(player2.getAccountId());
    System.out.println(player2.getAccountId());

    Network.useTestNetwork();
    server = new Server("https://horizon-testnet.stellar.org");

    try {
        server.accounts().account(destination1);
        server.accounts().account(destination2);
    }
    catch(Exception e) {
        System.out.println(e.getMessage());
        return;
    }

    AccountResponse sourceAccount;
    try {
        sourceAccount = server.accounts().account(pair);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        return;
    }

    Transaction t1 = new Transaction.Builder(sourceAccount)
            .addOperation(new PaymentOperation.Builder(destination1, new AssetTypeNative(), noBet).build())
            .addMemo(Memo.text("reveal values"))
            .build();
    t1.sign(pair);

    Transaction t2 = new Transaction.Builder(sourceAccount)
            .addOperation(new PaymentOperation.Builder(destination2, new AssetTypeNative(), noBet).build())
            .addMemo(Memo.text("reveal values"))
            .build();
    t2.sign(pair);

    try {
          SubmitTransactionResponse response1 = server.submitTransaction(t1);
          SubmitTransactionResponse response2 = server.submitTransaction(t2);

          System.out.println("Success!");
        } catch (Exception e) {
          System.out.println("Something went wrong!");
          System.out.println(e.getMessage());
        }

I have verified that the destination and source accounts are the correct values. Right after this, I query the server and check the records (in descending order..) and the two transactions are not present.

  • Your code sample doesn't define all the values. For example, how is pair defined? – Synesso Apr 12 '18 at 23:09
1

I have tried your code, but needed to make some assumptions about values such as pair.

The code performs transactions successfully, and I can see both txns from the client and the banker.

In your code, you are signing both transactions with pair. So unless you are redefining this variable, it may not be doing what you expect.

How are you checking the network for your transactions? If you are looking at all operations you might consider a filtered view instead, such as transactions by account or operations by account.

  • Thanks for you response. As of now I have pair hardcoded. These are two separate classes by the way. I am checking the network for transactions by this line --> "ArrayList<TransactionResponse> records = server.transactions().forAccount(pair).order(RequestBuilder.Order.DESC).execute().getRecords();" It's good to know you can see the transactions from both. I will manually check pair again in both classes, but I believe I already tried this. – caseyjg Apr 13 '18 at 13:52
  • Yeah, I confirmed the source and destination account ID's for both transactions being sent by the banker. There has to be something else I'm missing -- I'm sending the transactions the same way in both classes and the submission doesn't cause an exception. – caseyjg Apr 13 '18 at 14:25
0

Solved. The issue was I was sending a bet amount of 0, as I just wanted to send an alert message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.