Skip to content

Commit

Permalink
Added ResultCodes to SubmitTransactionResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekn committed Feb 24, 2016
1 parent de09803 commit 79e2260
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/stellar/java-stellar-sdk.svg)](https://travis-ci.org/stellar/java-stellar-sdk)

This library provides API to connect to [horizon](https://github.com/stellar/horizon).
This library provides API to build transactions and connect to [Horizon](https://github.com/stellar/horizon).

### Download

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public TooManyRequestsException(int retryAfter) {

/**
* Returns number of seconds a client should wait before sending requests again.
* @return
*/
public int getRetryAfter() {
return retryAfter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import org.stellar.sdk.Server;

import java.util.ArrayList;

/**
* Represents server response after submitting transaction.
* @see Server#submitTransaction(org.stellar.sdk.Transaction)
Expand Down Expand Up @@ -34,6 +36,9 @@ public Long getLedger() {
return ledger;
}

/**
* Additional information returned by a server. This will be <code>null</code> if transaction succeeded.
*/
public Extras getExtras() {
return extras;
}
Expand All @@ -46,10 +51,13 @@ public static class Extras {
private final String envelopeXdr;
@SerializedName("result_xdr")
private final String resultXdr;
@SerializedName("result_codes")
private final ResultCodes resultCodes;

Extras(String envelopeXdr, String resultXdr) {
Extras(String envelopeXdr, String resultXdr, ResultCodes resultCodes) {
this.envelopeXdr = envelopeXdr;
this.resultXdr = resultXdr;
this.resultCodes = resultCodes;
}

/**
Expand All @@ -67,5 +75,36 @@ public String getEnvelopeXdr() {
public String getResultXdr() {
return resultXdr;
}

/**
* Returns ResultCodes object that contains result codes for transaction.
*/
public ResultCodes getResultCodes() {
return resultCodes;
}

/**
* Contains result codes for this transaction.
* @see <a href="https://github.com/stellar/horizon/blob/master/src/github.com/stellar/horizon/codes/main.go" target="_blank">Possible values</a>
*/
public static class ResultCodes {
@SerializedName("transaction")
private final String transactionResultCode;
@SerializedName("operations")
private final ArrayList<String> operationsResultCodes;

public ResultCodes(String transactionResultCode, ArrayList<String> operationsResultCodes) {
this.transactionResultCode = transactionResultCode;
this.operationsResultCodes = operationsResultCodes;
}

public String getTransactionResultCode() {
return transactionResultCode;
}

public ArrayList<String> getOperationsResultCodes() {
return operationsResultCodes;
}
}
}
}
4 changes: 4 additions & 0 deletions src/test/java/org/stellar/sdk/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void testSubmitTransactionSuccess() throws IOException {
assertTrue(response.isSuccess());
assertEquals(response.getLedger(), new Long(826150L));
assertEquals(response.getHash(), "2634d2cf5adcbd3487d1df042166eef53830115844fdde1588828667bf93ff42");
assertNull(response.getExtras());
}

@Test
Expand All @@ -120,5 +121,8 @@ public void testSubmitTransactionFail() throws IOException {
assertNull(response.getHash());
assertEquals(response.getExtras().getEnvelopeXdr(), "AAAAAK4Pg4OEkjGmSN0AN37K/dcKyKPT2DC90xvjjawKp136AAAAZAAKsZQAAAABAAAAAAAAAAEAAAAJSmF2YSBGVFchAAAAAAAAAQAAAAAAAAABAAAAAG9wfBI7rRYoBlX3qRa0KOnI75W5BaPU6NbyKmm2t71MAAAAAAAAAAABMS0AAAAAAAAAAAEKp136AAAAQOWEjL+Sm+WP2puE9dLIxWlOibIEOz8PsXyG77jOCVdHZfQvkgB49Mu5wqKCMWWIsDSLFekwUsLaunvmXrpyBwQ=");
assertEquals(response.getExtras().getResultXdr(), "AAAAAAAAAGT/////AAAAAQAAAAAAAAAB////+wAAAAA=");
assertNotNull(response.getExtras());
assertEquals("tx_failed", response.getExtras().getResultCodes().getTransactionResultCode());
assertEquals("op_no_destination", response.getExtras().getResultCodes().getOperationsResultCodes().get(0));
}
}

0 comments on commit 79e2260

Please sign in to comment.