diff --git a/src/main/java/org/stellar/sdk/AbstractTransaction.java b/src/main/java/org/stellar/sdk/AbstractTransaction.java index 0cef65a2c..50e908122 100644 --- a/src/main/java/org/stellar/sdk/AbstractTransaction.java +++ b/src/main/java/org/stellar/sdk/AbstractTransaction.java @@ -4,8 +4,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.io.BaseEncoding; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -15,8 +13,6 @@ import org.stellar.sdk.xdr.SignatureHint; import org.stellar.sdk.xdr.TransactionEnvelope; import org.stellar.sdk.xdr.TransactionSignaturePayload; -import org.stellar.sdk.xdr.XdrDataInputStream; -import org.stellar.sdk.xdr.XdrDataOutputStream; public abstract class AbstractTransaction { protected final Network mNetwork; @@ -120,13 +116,7 @@ public void addSignature(DecoratedSignature signature) { */ public String toEnvelopeXdrBase64() { try { - TransactionEnvelope envelope = this.toEnvelopeXdr(); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - XdrDataOutputStream xdrOutputStream = new XdrDataOutputStream(outputStream); - TransactionEnvelope.encode(xdrOutputStream, envelope); - - BaseEncoding base64Encoding = BaseEncoding.base64(); - return base64Encoding.encode(outputStream.toByteArray()); + return toEnvelopeXdr().toXdrBase64(); } catch (IOException e) { throw new AssertionError(e); } @@ -176,11 +166,7 @@ public static AbstractTransaction fromEnvelopeXdr(TransactionEnvelope envelope, */ public static AbstractTransaction fromEnvelopeXdr( AccountConverter accountConverter, String envelope, Network network) throws IOException { - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(envelope); - - TransactionEnvelope transactionEnvelope = - TransactionEnvelope.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); + TransactionEnvelope transactionEnvelope = TransactionEnvelope.fromXdrBase64(envelope); return fromEnvelopeXdr(accountConverter, transactionEnvelope, network); } @@ -201,15 +187,13 @@ public static byte[] getTransactionSignatureBase( TransactionSignaturePayload.TransactionSignaturePayloadTaggedTransaction taggedTransaction, Network network) { try { - TransactionSignaturePayload payload = new TransactionSignaturePayload(); - Hash hash = new Hash(); - hash.setHash(network.getNetworkId()); - payload.setNetworkId(hash); - payload.setTaggedTransaction(taggedTransaction); - ByteArrayOutputStream txOutputStream = new ByteArrayOutputStream(); - XdrDataOutputStream xdrOutputStream = new XdrDataOutputStream(txOutputStream); - payload.encode(xdrOutputStream); - return txOutputStream.toByteArray(); + Hash networkIdHash = new Hash(network.getNetworkId()); + TransactionSignaturePayload payload = + new TransactionSignaturePayload.Builder() + .networkId(networkIdHash) + .taggedTransaction(taggedTransaction) + .build(); + return payload.toXdrByteArray(); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/org/stellar/sdk/ClaimClaimableBalanceOperation.java b/src/main/java/org/stellar/sdk/ClaimClaimableBalanceOperation.java index 8bf42b9dd..fda2895c1 100644 --- a/src/main/java/org/stellar/sdk/ClaimClaimableBalanceOperation.java +++ b/src/main/java/org/stellar/sdk/ClaimClaimableBalanceOperation.java @@ -3,6 +3,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.IOException; import org.stellar.sdk.xdr.*; public class ClaimClaimableBalanceOperation extends Operation { @@ -18,8 +20,16 @@ public String getBalanceId() { @Override org.stellar.sdk.xdr.Operation.OperationBody toOperationBody(AccountConverter accountConverter) { + byte[] balanceIdBytes = BaseEncoding.base16().lowerCase().decode(this.balanceId.toLowerCase()); + ClaimableBalanceID balanceId; + try { + balanceId = ClaimableBalanceID.fromXdrByteArray(balanceIdBytes); + } catch (IOException e) { + throw new IllegalArgumentException("invalid balanceId: " + this.balanceId, e); + } + ClaimClaimableBalanceOp op = new ClaimClaimableBalanceOp(); - op.setBalanceID(Util.claimableBalanceIdToXDR(balanceId)); + op.setBalanceID(balanceId); org.stellar.sdk.xdr.Operation.OperationBody body = new org.stellar.sdk.xdr.Operation.OperationBody(); body.setDiscriminant(OperationType.CLAIM_CLAIMABLE_BALANCE); @@ -38,7 +48,11 @@ public static class Builder { * @param op {@link ClaimClaimableBalanceOp} */ Builder(ClaimClaimableBalanceOp op) { - balanceId = Util.xdrToClaimableBalanceId(op.getBalanceID()); + try { + balanceId = BaseEncoding.base16().lowerCase().encode(op.getBalanceID().toXdrByteArray()); + } catch (IOException e) { + throw new IllegalArgumentException("Invalid balanceId in the operation", e); + } } /** diff --git a/src/main/java/org/stellar/sdk/ClawbackClaimableBalanceOperation.java b/src/main/java/org/stellar/sdk/ClawbackClaimableBalanceOperation.java index 772b16391..d9ea2315b 100644 --- a/src/main/java/org/stellar/sdk/ClawbackClaimableBalanceOperation.java +++ b/src/main/java/org/stellar/sdk/ClawbackClaimableBalanceOperation.java @@ -3,6 +3,9 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.IOException; +import org.stellar.sdk.xdr.ClaimableBalanceID; import org.stellar.sdk.xdr.ClawbackClaimableBalanceOp; import org.stellar.sdk.xdr.OperationType; @@ -26,9 +29,17 @@ public String getBalanceId() { @Override org.stellar.sdk.xdr.Operation.OperationBody toOperationBody(AccountConverter accountConverter) { + byte[] balanceIdBytes = BaseEncoding.base16().lowerCase().decode(this.balanceId.toLowerCase()); + ClaimableBalanceID balanceId; + try { + balanceId = ClaimableBalanceID.fromXdrByteArray(balanceIdBytes); + } catch (IOException e) { + throw new IllegalArgumentException("invalid balanceId: " + this.balanceId, e); + } + ClawbackClaimableBalanceOp op = new ClawbackClaimableBalanceOp(); - op.setBalanceID(Util.claimableBalanceIdToXDR(balanceId)); + op.setBalanceID(balanceId); org.stellar.sdk.xdr.Operation.OperationBody body = new org.stellar.sdk.xdr.Operation.OperationBody(); @@ -48,7 +59,11 @@ public static class Builder { private String mSourceAccount; Builder(ClawbackClaimableBalanceOp op) { - balanceId = Util.xdrToClaimableBalanceId(op.getBalanceID()); + try { + balanceId = BaseEncoding.base16().lowerCase().encode(op.getBalanceID().toXdrByteArray()); + } catch (IOException e) { + throw new IllegalArgumentException("Invalid balanceId in the operation", e); + } } /** diff --git a/src/main/java/org/stellar/sdk/Operation.java b/src/main/java/org/stellar/sdk/Operation.java index 54d479295..f9af93cb3 100644 --- a/src/main/java/org/stellar/sdk/Operation.java +++ b/src/main/java/org/stellar/sdk/Operation.java @@ -2,15 +2,12 @@ import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.io.BaseEncoding; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.math.BigDecimal; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.experimental.SuperBuilder; -import org.stellar.sdk.xdr.XdrDataOutputStream; /** Abstract class for operations. */ @SuperBuilder(toBuilder = true) @@ -51,12 +48,7 @@ public org.stellar.sdk.xdr.Operation toXdr() { /** Returns base64-encoded Operation XDR object. */ public String toXdrBase64(AccountConverter accountConverter) { try { - org.stellar.sdk.xdr.Operation operation = this.toXdr(accountConverter); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - XdrDataOutputStream xdrOutputStream = new XdrDataOutputStream(outputStream); - org.stellar.sdk.xdr.Operation.encode(xdrOutputStream, operation); - BaseEncoding base64Encoding = BaseEncoding.base64(); - return base64Encoding.encode(outputStream.toByteArray()); + return toXdr(accountConverter).toXdrBase64(); } catch (IOException e) { throw new AssertionError(e); } diff --git a/src/main/java/org/stellar/sdk/RevokeClaimableBalanceSponsorshipOperation.java b/src/main/java/org/stellar/sdk/RevokeClaimableBalanceSponsorshipOperation.java index 9e2026256..763f47010 100644 --- a/src/main/java/org/stellar/sdk/RevokeClaimableBalanceSponsorshipOperation.java +++ b/src/main/java/org/stellar/sdk/RevokeClaimableBalanceSponsorshipOperation.java @@ -3,6 +3,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.IOException; import org.stellar.sdk.xdr.*; public class RevokeClaimableBalanceSponsorshipOperation extends Operation { @@ -18,13 +20,21 @@ public String getBalanceId() { @Override org.stellar.sdk.xdr.Operation.OperationBody toOperationBody(AccountConverter accountConverter) { + byte[] balanceIdBytes = BaseEncoding.base16().lowerCase().decode(this.balanceId.toLowerCase()); + ClaimableBalanceID balanceId; + try { + balanceId = ClaimableBalanceID.fromXdrByteArray(balanceIdBytes); + } catch (IOException e) { + throw new IllegalArgumentException("invalid balanceId: " + this.balanceId, e); + } + RevokeSponsorshipOp op = new RevokeSponsorshipOp(); LedgerKey key = new LedgerKey(); key.setDiscriminant(LedgerEntryType.CLAIMABLE_BALANCE); LedgerKey.LedgerKeyClaimableBalance claimableBalance = new LedgerKey.LedgerKeyClaimableBalance(); - claimableBalance.setBalanceID(Util.claimableBalanceIdToXDR(balanceId)); + claimableBalance.setBalanceID(balanceId); key.setClaimableBalance(claimableBalance); op.setLedgerKey(key); op.setDiscriminant(RevokeSponsorshipType.REVOKE_SPONSORSHIP_LEDGER_ENTRY); @@ -49,8 +59,14 @@ public static class Builder { * @param op {@link RevokeSponsorshipOp} */ Builder(RevokeSponsorshipOp op) { - balanceId = - Util.xdrToClaimableBalanceId(op.getLedgerKey().getClaimableBalance().getBalanceID()); + try { + balanceId = + BaseEncoding.base16() + .lowerCase() + .encode(op.getLedgerKey().getClaimableBalance().getBalanceID().toXdrByteArray()); + } catch (IOException e) { + throw new IllegalArgumentException("Invalid claimableBalance in the operation", e); + } } /** diff --git a/src/main/java/org/stellar/sdk/SorobanServer.java b/src/main/java/org/stellar/sdk/SorobanServer.java index f1b81fe99..410721bc9 100644 --- a/src/main/java/org/stellar/sdk/SorobanServer.java +++ b/src/main/java/org/stellar/sdk/SorobanServer.java @@ -1,10 +1,7 @@ package org.stellar.sdk; -import com.google.common.io.BaseEncoding; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; @@ -14,7 +11,6 @@ import java.util.Optional; import java.util.UUID; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; import javax.annotation.Nullable; import okhttp3.HttpUrl; import okhttp3.MediaType; @@ -48,8 +44,6 @@ import org.stellar.sdk.xdr.SCVal; import org.stellar.sdk.xdr.SorobanAuthorizationEntry; import org.stellar.sdk.xdr.SorobanTransactionData; -import org.stellar.sdk.xdr.XdrDataInputStream; -import org.stellar.sdk.xdr.XdrDataOutputStream; /** * Main class used to connect to the Soroban-RPC instance and exposes an interface for requests to @@ -122,8 +116,12 @@ public TransactionBuilderAccount getAccount(String accountId) if (entries == null || entries.isEmpty()) { throw new AccountNotFoundException(accountId); } - LedgerEntry.LedgerEntryData ledgerEntryData = - ledgerEntryDataFromXdrBase64(entries.get(0).getXdr()); + LedgerEntry.LedgerEntryData ledgerEntryData; + try { + ledgerEntryData = LedgerEntry.LedgerEntryData.fromXdrBase64(entries.get(0).getXdr()); + } catch (IOException e) { + throw new IllegalArgumentException("Invalid ledgerEntryData: " + entries.get(0).getXdr(), e); + } long sequence = ledgerEntryData.getAccount().getSeqNum().getSequenceNumber().getInt64(); return new Account(accountId, sequence); } @@ -220,8 +218,16 @@ public GetLedgerEntriesResponse getLedgerEntries(Collection keys) throw new IllegalArgumentException("At least one key must be provided."); } - List xdrKeys = - keys.stream().map(SorobanServer::ledgerKeyToXdrBase64).collect(Collectors.toList()); + List xdrKeys = new ArrayList<>(keys.size()); + for (LedgerKey key : keys) { + String xdrBase64; + try { + xdrBase64 = key.toXdrBase64(); + } catch (IOException e) { + throw new IllegalArgumentException("Invalid ledgerKey: " + key, e); + } + xdrKeys.add(xdrBase64); + } GetLedgerEntriesRequest params = new GetLedgerEntriesRequest(xdrKeys); return this.sendRequest( "getLedgerEntries", @@ -421,7 +427,11 @@ private Transaction assembleTransaction( List newEntries = new ArrayList<>(originalEntries); if (simulateHostFunctionResult.getAuth() != null) { for (String auth : simulateHostFunctionResult.getAuth()) { - newEntries.add(sorobanAuthorizationEntryFromXdrBase64(auth)); + try { + newEntries.add(SorobanAuthorizationEntry.fromXdrBase64(auth)); + } catch (IOException e) { + throw new IllegalArgumentException("Invalid auth: " + auth, e); + } } } operation = @@ -432,8 +442,14 @@ private Transaction assembleTransaction( .build(); } - SorobanTransactionData sorobanData = - Util.sorobanTransactionDataToXDR(simulateTransactionResponse.getTransactionData()); + SorobanTransactionData sorobanData; + try { + sorobanData = + SorobanTransactionData.fromXdrBase64(simulateTransactionResponse.getTransactionData()); + } catch (IOException e) { + throw new IllegalArgumentException( + "Invalid transactionData: " + simulateTransactionResponse.getTransactionData(), e); + } return new Transaction( transaction.getAccountConverter(), @@ -477,44 +493,6 @@ private static String generateRequestId() { return UUID.randomUUID().toString(); } - private static String ledgerKeyToXdrBase64(LedgerKey ledgerKey) { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); - try { - ledgerKey.encode(xdrDataOutputStream); - } catch (IOException e) { - throw new IllegalArgumentException("invalid ledgerKey.", e); - } - BaseEncoding base64Encoding = BaseEncoding.base64(); - return base64Encoding.encode(byteArrayOutputStream.toByteArray()); - } - - private static LedgerEntry.LedgerEntryData ledgerEntryDataFromXdrBase64(String ledgerEntryData) { - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(ledgerEntryData); - ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); - XdrDataInputStream xdrInputStream = new XdrDataInputStream(inputStream); - try { - return LedgerEntry.LedgerEntryData.decode(xdrInputStream); - } catch (IOException e) { - throw new IllegalArgumentException("invalid ledgerEntryData: " + ledgerEntryData, e); - } - } - - private static SorobanAuthorizationEntry sorobanAuthorizationEntryFromXdrBase64( - String sorobanAuthorizationEntry) { - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(sorobanAuthorizationEntry); - ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); - XdrDataInputStream xdrInputStream = new XdrDataInputStream(inputStream); - try { - return SorobanAuthorizationEntry.decode(xdrInputStream); - } catch (IOException e) { - throw new IllegalArgumentException( - "invalid ledgerEntryData: " + sorobanAuthorizationEntry, e); - } - } - /** * Represents the "durability keyspace" that this ledger key belongs to, check {@link * SorobanServer#getContractData} for more details. diff --git a/src/main/java/org/stellar/sdk/StrKey.java b/src/main/java/org/stellar/sdk/StrKey.java index c6ab224f6..26db710b3 100644 --- a/src/main/java/org/stellar/sdk/StrKey.java +++ b/src/main/java/org/stellar/sdk/StrKey.java @@ -98,9 +98,7 @@ public static AccountID encodeToXDRAccountId(String data) { PublicKey publicKey = new PublicKey(); publicKey.setDiscriminant(PublicKeyType.PUBLIC_KEY_TYPE_ED25519); try { - publicKey.setEd25519( - Uint256.decode( - new XdrDataInputStream(new ByteArrayInputStream(decodeStellarAccountId(data))))); + publicKey.setEd25519(Uint256.fromXdrByteArray(decodeStellarAccountId(data))); } catch (IOException e) { throw new IllegalArgumentException("invalid address: " + data, e); } @@ -118,9 +116,7 @@ public static MuxedAccount encodeToXDRMuxedAccount(String data) { case ACCOUNT_ID: muxed.setDiscriminant(CryptoKeyType.KEY_TYPE_ED25519); try { - muxed.setEd25519( - Uint256.decode( - new XdrDataInputStream(new ByteArrayInputStream(decodeStellarAccountId(data))))); + muxed.setEd25519(Uint256.fromXdrByteArray(decodeStellarAccountId(data))); } catch (IOException e) { throw new IllegalArgumentException("invalid address: " + data, e); } @@ -176,8 +172,7 @@ public static SignedPayloadSigner decodeSignedPayload(char[] data) { byte[] signedPayloadRaw = decodeCheck(VersionByte.SIGNED_PAYLOAD, data); SignerKey.SignerKeyEd25519SignedPayload xdrPayloadSigner = - SignerKey.SignerKeyEd25519SignedPayload.decode( - new XdrDataInputStream(new ByteArrayInputStream(signedPayloadRaw))); + SignerKey.SignerKeyEd25519SignedPayload.fromXdrByteArray(signedPayloadRaw); return new SignedPayloadSigner( xdrPayloadSigner.getEd25519().getUint256(), xdrPayloadSigner.getPayload()); diff --git a/src/main/java/org/stellar/sdk/TransactionBuilder.java b/src/main/java/org/stellar/sdk/TransactionBuilder.java index 487034086..da85d14f5 100644 --- a/src/main/java/org/stellar/sdk/TransactionBuilder.java +++ b/src/main/java/org/stellar/sdk/TransactionBuilder.java @@ -5,6 +5,7 @@ import static org.stellar.sdk.TransactionPreconditions.TIMEOUT_INFINITE; import com.google.common.base.Function; +import java.io.IOException; import java.math.BigInteger; import java.util.Collection; import java.util.List; @@ -280,7 +281,12 @@ public TransactionBuilder setSorobanData(SorobanTransactionData sorobanData) { * @return Builder object so you can chain methods. */ public TransactionBuilder setSorobanData(String sorobanData) { - SorobanTransactionData data = Util.sorobanTransactionDataToXDR(sorobanData); + SorobanTransactionData data; + try { + data = SorobanTransactionData.fromXdrBase64(sorobanData); + } catch (IOException e) { + throw new IllegalArgumentException("Invalid Soroban data: " + sorobanData, e); + } return setSorobanData(data); } } diff --git a/src/main/java/org/stellar/sdk/Util.java b/src/main/java/org/stellar/sdk/Util.java index eaa458058..dd76e6f93 100644 --- a/src/main/java/org/stellar/sdk/Util.java +++ b/src/main/java/org/stellar/sdk/Util.java @@ -1,16 +1,8 @@ package org.stellar.sdk; -import com.google.common.io.BaseEncoding; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; -import org.stellar.sdk.xdr.ClaimableBalanceID; -import org.stellar.sdk.xdr.SorobanTransactionData; -import org.stellar.sdk.xdr.XdrDataInputStream; -import org.stellar.sdk.xdr.XdrDataOutputStream; public class Util { @@ -101,66 +93,6 @@ public static String getSdkVersion() { return clientVersion; } - public static ClaimableBalanceID claimableBalanceIdToXDR(String balanceId) { - byte[] balanceIdBytes = BaseEncoding.base16().lowerCase().decode(balanceId.toLowerCase()); - XdrDataInputStream balanceIdXdrDataInputStream = - new XdrDataInputStream(new ByteArrayInputStream(balanceIdBytes)); - - try { - return ClaimableBalanceID.decode(balanceIdXdrDataInputStream); - } catch (IOException e) { - throw new IllegalArgumentException("invalid balanceId: " + balanceId, e); - } - } - - public static String xdrToClaimableBalanceId(ClaimableBalanceID balanceId) { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); - try { - balanceId.encode(xdrDataOutputStream); - } catch (IOException e) { - throw new IllegalArgumentException("invalid claimClaimableBalanceOp.", e); - } - return BaseEncoding.base16().lowerCase().encode(byteArrayOutputStream.toByteArray()); - } - - /** - * Convert {@link SorobanTransactionData} XDR String representation to {@link - * SorobanTransactionData} object. - * - * @param sorobanData XDR String representation of a {@link SorobanTransactionData} - * @return {@link SorobanTransactionData} - */ - public static SorobanTransactionData sorobanTransactionDataToXDR(String sorobanData) { - BaseEncoding base64Encoding = BaseEncoding.base64(); - byte[] bytes = base64Encoding.decode(sorobanData); - ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); - XdrDataInputStream xdrInputStream = new XdrDataInputStream(inputStream); - try { - return SorobanTransactionData.decode(xdrInputStream); - } catch (IOException e) { - throw new IllegalArgumentException("invalid sorobanData: " + sorobanData, e); - } - } - - /** - * Convert {@link SorobanTransactionData} object to XDR String representation. - * - * @param sorobanData {@link SorobanTransactionData} object - * @return XDR String representation of a {@link SorobanTransactionData} - */ - public static String xdrToSorobanTransactionData(SorobanTransactionData sorobanData) { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); - try { - sorobanData.encode(xdrDataOutputStream); - } catch (IOException e) { - throw new IllegalArgumentException("invalid sorobanData.", e); - } - BaseEncoding base64Encoding = BaseEncoding.base64(); - return base64Encoding.encode(byteArrayOutputStream.toByteArray()); - } - public static AssetTypeCreditAlphaNum assertNonNativeAsset(Asset asset) { if (asset instanceof AssetTypeCreditAlphaNum) { return (AssetTypeCreditAlphaNum) asset; diff --git a/src/main/java/org/stellar/sdk/xdr/AccountEntry.java b/src/main/java/org/stellar/sdk/xdr/AccountEntry.java index 57ed904d9..03be0dd10 100644 --- a/src/main/java/org/stellar/sdk/xdr/AccountEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/AccountEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -227,6 +230,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AccountEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AccountEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID accountID; private Int64 balance; @@ -305,7 +334,7 @@ public AccountEntry build() { } } - public static class AccountEntryExt { + public static class AccountEntryExt implements XdrElement { public AccountEntryExt() {} Integer v; @@ -396,5 +425,31 @@ public boolean equals(Object object) { AccountEntryExt other = (AccountEntryExt) object; return Objects.equal(this.v1, other.v1) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AccountEntryExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AccountEntryExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV1.java b/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV1.java index 5f5548726..fe0ea8027 100644 --- a/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV1.java +++ b/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV1.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -81,6 +84,32 @@ public boolean equals(Object object) { return Objects.equal(this.liabilities, other.liabilities) && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AccountEntryExtensionV1 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AccountEntryExtensionV1 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Liabilities liabilities; private AccountEntryExtensionV1Ext ext; @@ -103,7 +132,7 @@ public AccountEntryExtensionV1 build() { } } - public static class AccountEntryExtensionV1Ext { + public static class AccountEntryExtensionV1Ext implements XdrElement { public AccountEntryExtensionV1Ext() {} Integer v; @@ -196,5 +225,31 @@ public boolean equals(Object object) { AccountEntryExtensionV1Ext other = (AccountEntryExtensionV1Ext) object; return Objects.equal(this.v2, other.v2) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AccountEntryExtensionV1Ext fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AccountEntryExtensionV1Ext fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV2.java b/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV2.java index 6fcbd89e0..8d4151a4a 100644 --- a/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV2.java +++ b/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV2.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -121,6 +124,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AccountEntryExtensionV2 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AccountEntryExtensionV2 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 numSponsored; private Uint32 numSponsoring; @@ -157,7 +186,7 @@ public AccountEntryExtensionV2 build() { } } - public static class AccountEntryExtensionV2Ext { + public static class AccountEntryExtensionV2Ext implements XdrElement { public AccountEntryExtensionV2Ext() {} Integer v; @@ -250,5 +279,31 @@ public boolean equals(Object object) { AccountEntryExtensionV2Ext other = (AccountEntryExtensionV2Ext) object; return Objects.equal(this.v3, other.v3) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AccountEntryExtensionV2Ext fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AccountEntryExtensionV2Ext fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV3.java b/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV3.java index 44a51aef3..0affd3ae1 100644 --- a/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV3.java +++ b/src/main/java/org/stellar/sdk/xdr/AccountEntryExtensionV3.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -94,6 +97,32 @@ public boolean equals(Object object) { && Objects.equal(this.seqTime, other.seqTime); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AccountEntryExtensionV3 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AccountEntryExtensionV3 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ExtensionPoint ext; private Uint32 seqLedger; diff --git a/src/main/java/org/stellar/sdk/xdr/AccountFlags.java b/src/main/java/org/stellar/sdk/xdr/AccountFlags.java index 35b38cb06..a763bf8e8 100644 --- a/src/main/java/org/stellar/sdk/xdr/AccountFlags.java +++ b/src/main/java/org/stellar/sdk/xdr/AccountFlags.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -67,4 +70,30 @@ public static void encode(XdrDataOutputStream stream, AccountFlags value) throws public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AccountFlags fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AccountFlags fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/AccountID.java b/src/main/java/org/stellar/sdk/xdr/AccountID.java index 25f5a81a4..1dfed5969 100644 --- a/src/main/java/org/stellar/sdk/xdr/AccountID.java +++ b/src/main/java/org/stellar/sdk/xdr/AccountID.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,4 +62,30 @@ public boolean equals(Object object) { AccountID other = (AccountID) object; return Objects.equal(this.AccountID, other.AccountID); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AccountID fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AccountID fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/AccountMergeResult.java b/src/main/java/org/stellar/sdk/xdr/AccountMergeResult.java index d9aa45f26..84564a788 100644 --- a/src/main/java/org/stellar/sdk/xdr/AccountMergeResult.java +++ b/src/main/java/org/stellar/sdk/xdr/AccountMergeResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -129,4 +132,30 @@ public boolean equals(Object object) { return Objects.equal(this.sourceAccountBalance, other.sourceAccountBalance) && Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AccountMergeResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AccountMergeResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/AccountMergeResultCode.java b/src/main/java/org/stellar/sdk/xdr/AccountMergeResultCode.java index 837c6cd65..9400e622c 100644 --- a/src/main/java/org/stellar/sdk/xdr/AccountMergeResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/AccountMergeResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -77,4 +80,30 @@ public static void encode(XdrDataOutputStream stream, AccountMergeResultCode val public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AccountMergeResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AccountMergeResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/AllowTrustOp.java b/src/main/java/org/stellar/sdk/xdr/AllowTrustOp.java index d47b32de6..c2a66a639 100644 --- a/src/main/java/org/stellar/sdk/xdr/AllowTrustOp.java +++ b/src/main/java/org/stellar/sdk/xdr/AllowTrustOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -89,6 +92,32 @@ public boolean equals(Object object) { && Objects.equal(this.authorize, other.authorize); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AllowTrustOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AllowTrustOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID trustor; private AssetCode asset; diff --git a/src/main/java/org/stellar/sdk/xdr/AllowTrustResult.java b/src/main/java/org/stellar/sdk/xdr/AllowTrustResult.java index def5ef34d..ee87de8c3 100644 --- a/src/main/java/org/stellar/sdk/xdr/AllowTrustResult.java +++ b/src/main/java/org/stellar/sdk/xdr/AllowTrustResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -106,4 +109,30 @@ public boolean equals(Object object) { AllowTrustResult other = (AllowTrustResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AllowTrustResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AllowTrustResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/AllowTrustResultCode.java b/src/main/java/org/stellar/sdk/xdr/AllowTrustResultCode.java index 350ea0076..3f33db982 100644 --- a/src/main/java/org/stellar/sdk/xdr/AllowTrustResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/AllowTrustResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -74,4 +77,30 @@ public static void encode(XdrDataOutputStream stream, AllowTrustResultCode value public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AllowTrustResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AllowTrustResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/AlphaNum12.java b/src/main/java/org/stellar/sdk/xdr/AlphaNum12.java index 87573ea1b..b86dd0dc2 100644 --- a/src/main/java/org/stellar/sdk/xdr/AlphaNum12.java +++ b/src/main/java/org/stellar/sdk/xdr/AlphaNum12.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.issuer, other.issuer); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AlphaNum12 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AlphaNum12 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AssetCode12 assetCode; private AccountID issuer; diff --git a/src/main/java/org/stellar/sdk/xdr/AlphaNum4.java b/src/main/java/org/stellar/sdk/xdr/AlphaNum4.java index 2b8110bff..4d981dd1d 100644 --- a/src/main/java/org/stellar/sdk/xdr/AlphaNum4.java +++ b/src/main/java/org/stellar/sdk/xdr/AlphaNum4.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.issuer, other.issuer); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AlphaNum4 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AlphaNum4 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AssetCode4 assetCode; private AccountID issuer; diff --git a/src/main/java/org/stellar/sdk/xdr/Asset.java b/src/main/java/org/stellar/sdk/xdr/Asset.java index 02c6dd642..20594ea09 100644 --- a/src/main/java/org/stellar/sdk/xdr/Asset.java +++ b/src/main/java/org/stellar/sdk/xdr/Asset.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -140,4 +143,30 @@ public boolean equals(Object object) { && Objects.equal(this.alphaNum12, other.alphaNum12) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Asset fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Asset fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/AssetCode.java b/src/main/java/org/stellar/sdk/xdr/AssetCode.java index cbc64cfc3..3f1675d11 100644 --- a/src/main/java/org/stellar/sdk/xdr/AssetCode.java +++ b/src/main/java/org/stellar/sdk/xdr/AssetCode.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -134,4 +137,30 @@ public boolean equals(Object object) { && Objects.equal(this.assetCode12, other.assetCode12) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AssetCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AssetCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/AssetCode12.java b/src/main/java/org/stellar/sdk/xdr/AssetCode12.java index 04567eb0d..887725fe2 100644 --- a/src/main/java/org/stellar/sdk/xdr/AssetCode12.java +++ b/src/main/java/org/stellar/sdk/xdr/AssetCode12.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -62,4 +65,30 @@ public boolean equals(Object object) { AssetCode12 other = (AssetCode12) object; return Arrays.equals(this.AssetCode12, other.AssetCode12); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AssetCode12 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AssetCode12 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/AssetCode4.java b/src/main/java/org/stellar/sdk/xdr/AssetCode4.java index 306d2030a..8b8643cff 100644 --- a/src/main/java/org/stellar/sdk/xdr/AssetCode4.java +++ b/src/main/java/org/stellar/sdk/xdr/AssetCode4.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -62,4 +65,30 @@ public boolean equals(Object object) { AssetCode4 other = (AssetCode4) object; return Arrays.equals(this.AssetCode4, other.AssetCode4); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AssetCode4 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AssetCode4 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/AssetType.java b/src/main/java/org/stellar/sdk/xdr/AssetType.java index 15777e107..fafca9365 100644 --- a/src/main/java/org/stellar/sdk/xdr/AssetType.java +++ b/src/main/java/org/stellar/sdk/xdr/AssetType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -57,4 +60,30 @@ public static void encode(XdrDataOutputStream stream, AssetType value) throws IO public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AssetType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AssetType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Auth.java b/src/main/java/org/stellar/sdk/xdr/Auth.java index 4322bd92d..42b03842d 100644 --- a/src/main/java/org/stellar/sdk/xdr/Auth.java +++ b/src/main/java/org/stellar/sdk/xdr/Auth.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -58,6 +61,32 @@ public boolean equals(Object object) { return Objects.equal(this.flags, other.flags); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Auth fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Auth fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Integer flags; diff --git a/src/main/java/org/stellar/sdk/xdr/AuthCert.java b/src/main/java/org/stellar/sdk/xdr/AuthCert.java index 4de722778..5d5482b8e 100644 --- a/src/main/java/org/stellar/sdk/xdr/AuthCert.java +++ b/src/main/java/org/stellar/sdk/xdr/AuthCert.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -87,6 +90,32 @@ public boolean equals(Object object) { && Objects.equal(this.sig, other.sig); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AuthCert fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AuthCert fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Curve25519Public pubkey; private Uint64 expiration; diff --git a/src/main/java/org/stellar/sdk/xdr/AuthenticatedMessage.java b/src/main/java/org/stellar/sdk/xdr/AuthenticatedMessage.java index 7289d31e0..49cff396a 100644 --- a/src/main/java/org/stellar/sdk/xdr/AuthenticatedMessage.java +++ b/src/main/java/org/stellar/sdk/xdr/AuthenticatedMessage.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -112,7 +115,33 @@ public boolean equals(Object object) { return Objects.equal(this.v0, other.v0) && Objects.equal(this.v, other.v); } - public static class AuthenticatedMessageV0 { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AuthenticatedMessage fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AuthenticatedMessage fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class AuthenticatedMessageV0 implements XdrElement { public AuthenticatedMessageV0() {} private Uint64 sequence; @@ -182,6 +211,32 @@ public boolean equals(Object object) { && Objects.equal(this.mac, other.mac); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static AuthenticatedMessageV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static AuthenticatedMessageV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint64 sequence; private StellarMessage message; diff --git a/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesOp.java b/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesOp.java index 0f0053e49..2213e8288 100644 --- a/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesOp.java +++ b/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -63,6 +66,32 @@ public boolean equals(Object object) { return Objects.equal(this.sponsoredID, other.sponsoredID); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BeginSponsoringFutureReservesOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BeginSponsoringFutureReservesOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID sponsoredID; diff --git a/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResult.java b/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResult.java index aea6d1dd9..0fb172a4d 100644 --- a/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResult.java +++ b/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -103,4 +106,31 @@ public boolean equals(Object object) { BeginSponsoringFutureReservesResult other = (BeginSponsoringFutureReservesResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BeginSponsoringFutureReservesResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BeginSponsoringFutureReservesResult fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResultCode.java b/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResultCode.java index c7c0cda1c..96c2e7487 100644 --- a/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/BeginSponsoringFutureReservesResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -63,4 +66,32 @@ public static void encode( public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BeginSponsoringFutureReservesResultCode fromXdrBase64(String xdr) + throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BeginSponsoringFutureReservesResultCode fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/BucketEntry.java b/src/main/java/org/stellar/sdk/xdr/BucketEntry.java index 1db3f00e3..6305c02d8 100644 --- a/src/main/java/org/stellar/sdk/xdr/BucketEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/BucketEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -161,4 +164,30 @@ public boolean equals(Object object) { && Objects.equal(this.metaEntry, other.metaEntry) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BucketEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BucketEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/BucketEntryType.java b/src/main/java/org/stellar/sdk/xdr/BucketEntryType.java index ae31ea954..273a4a792 100644 --- a/src/main/java/org/stellar/sdk/xdr/BucketEntryType.java +++ b/src/main/java/org/stellar/sdk/xdr/BucketEntryType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,4 +62,30 @@ public static void encode(XdrDataOutputStream stream, BucketEntryType value) thr public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BucketEntryType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BucketEntryType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/BucketMetadata.java b/src/main/java/org/stellar/sdk/xdr/BucketMetadata.java index 7fc95ff7e..1d2b37bf6 100644 --- a/src/main/java/org/stellar/sdk/xdr/BucketMetadata.java +++ b/src/main/java/org/stellar/sdk/xdr/BucketMetadata.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -81,6 +84,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BucketMetadata fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BucketMetadata fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 ledgerVersion; private BucketMetadataExt ext; @@ -103,7 +132,7 @@ public BucketMetadata build() { } } - public static class BucketMetadataExt { + public static class BucketMetadataExt implements XdrElement { public BucketMetadataExt() {} Integer v; @@ -171,5 +200,31 @@ public boolean equals(Object object) { BucketMetadataExt other = (BucketMetadataExt) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BucketMetadataExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BucketMetadataExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationOp.java b/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationOp.java index 5ba718eba..2c396ac27 100644 --- a/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationOp.java +++ b/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -74,6 +77,32 @@ public boolean equals(Object object) { && Objects.equal(this.ledgersToExpire, other.ledgersToExpire); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BumpFootprintExpirationOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BumpFootprintExpirationOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ExtensionPoint ext; private Uint32 ledgersToExpire; diff --git a/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationResult.java b/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationResult.java index 286820801..38b943184 100644 --- a/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationResult.java +++ b/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -98,4 +101,30 @@ public boolean equals(Object object) { BumpFootprintExpirationResult other = (BumpFootprintExpirationResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BumpFootprintExpirationResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BumpFootprintExpirationResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationResultCode.java b/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationResultCode.java index 8e33eae94..15366d027 100644 --- a/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/BumpFootprintExpirationResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -58,4 +61,30 @@ public static void encode(XdrDataOutputStream stream, BumpFootprintExpirationRes public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BumpFootprintExpirationResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BumpFootprintExpirationResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/BumpSequenceOp.java b/src/main/java/org/stellar/sdk/xdr/BumpSequenceOp.java index 42f7ebb27..73d3bc385 100644 --- a/src/main/java/org/stellar/sdk/xdr/BumpSequenceOp.java +++ b/src/main/java/org/stellar/sdk/xdr/BumpSequenceOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,6 +62,32 @@ public boolean equals(Object object) { return Objects.equal(this.bumpTo, other.bumpTo); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BumpSequenceOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BumpSequenceOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SequenceNumber bumpTo; diff --git a/src/main/java/org/stellar/sdk/xdr/BumpSequenceResult.java b/src/main/java/org/stellar/sdk/xdr/BumpSequenceResult.java index bda89846d..9e9dbd2ad 100644 --- a/src/main/java/org/stellar/sdk/xdr/BumpSequenceResult.java +++ b/src/main/java/org/stellar/sdk/xdr/BumpSequenceResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -91,4 +94,30 @@ public boolean equals(Object object) { BumpSequenceResult other = (BumpSequenceResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BumpSequenceResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BumpSequenceResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/BumpSequenceResultCode.java b/src/main/java/org/stellar/sdk/xdr/BumpSequenceResultCode.java index f2863fd71..a19bf8d67 100644 --- a/src/main/java/org/stellar/sdk/xdr/BumpSequenceResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/BumpSequenceResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -52,4 +55,30 @@ public static void encode(XdrDataOutputStream stream, BumpSequenceResultCode val public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static BumpSequenceResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static BumpSequenceResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ChangeTrustAsset.java b/src/main/java/org/stellar/sdk/xdr/ChangeTrustAsset.java index 3429e5e17..d9bbfa9bf 100644 --- a/src/main/java/org/stellar/sdk/xdr/ChangeTrustAsset.java +++ b/src/main/java/org/stellar/sdk/xdr/ChangeTrustAsset.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -168,4 +171,30 @@ public boolean equals(Object object) { && Objects.equal(this.liquidityPool, other.liquidityPool) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ChangeTrustAsset fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ChangeTrustAsset fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ChangeTrustOp.java b/src/main/java/org/stellar/sdk/xdr/ChangeTrustOp.java index 796155609..2bf7124f2 100644 --- a/src/main/java/org/stellar/sdk/xdr/ChangeTrustOp.java +++ b/src/main/java/org/stellar/sdk/xdr/ChangeTrustOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -74,6 +77,32 @@ public boolean equals(Object object) { return Objects.equal(this.line, other.line) && Objects.equal(this.limit, other.limit); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ChangeTrustOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ChangeTrustOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ChangeTrustAsset line; private Int64 limit; diff --git a/src/main/java/org/stellar/sdk/xdr/ChangeTrustResult.java b/src/main/java/org/stellar/sdk/xdr/ChangeTrustResult.java index 1b4b2671b..09215f4a3 100644 --- a/src/main/java/org/stellar/sdk/xdr/ChangeTrustResult.java +++ b/src/main/java/org/stellar/sdk/xdr/ChangeTrustResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -112,4 +115,30 @@ public boolean equals(Object object) { ChangeTrustResult other = (ChangeTrustResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ChangeTrustResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ChangeTrustResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ChangeTrustResultCode.java b/src/main/java/org/stellar/sdk/xdr/ChangeTrustResultCode.java index 3cd497a15..97423b061 100644 --- a/src/main/java/org/stellar/sdk/xdr/ChangeTrustResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/ChangeTrustResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -84,4 +87,30 @@ public static void encode(XdrDataOutputStream stream, ChangeTrustResultCode valu public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ChangeTrustResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ChangeTrustResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimAtom.java b/src/main/java/org/stellar/sdk/xdr/ClaimAtom.java index be5afcca3..1ebc0f6dc 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimAtom.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimAtom.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -157,4 +160,30 @@ public boolean equals(Object object) { && Objects.equal(this.liquidityPool, other.liquidityPool) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimAtom fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimAtom fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimAtomType.java b/src/main/java/org/stellar/sdk/xdr/ClaimAtomType.java index cabffa386..282762069 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimAtomType.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimAtomType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -53,4 +56,30 @@ public static void encode(XdrDataOutputStream stream, ClaimAtomType value) throw public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimAtomType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimAtomType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceOp.java b/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceOp.java index 295b81f79..86bccbc3c 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceOp.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -60,6 +63,32 @@ public boolean equals(Object object) { return Objects.equal(this.balanceID, other.balanceID); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimClaimableBalanceOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimClaimableBalanceOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ClaimableBalanceID balanceID; diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceResult.java b/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceResult.java index 2d14c10de..749857b86 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceResult.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -105,4 +108,30 @@ public boolean equals(Object object) { ClaimClaimableBalanceResult other = (ClaimClaimableBalanceResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimClaimableBalanceResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimClaimableBalanceResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceResultCode.java b/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceResultCode.java index 64d4ad25a..5a6521eed 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimClaimableBalanceResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -67,4 +70,30 @@ public static void encode(XdrDataOutputStream stream, ClaimClaimableBalanceResul public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimClaimableBalanceResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimClaimableBalanceResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimLiquidityAtom.java b/src/main/java/org/stellar/sdk/xdr/ClaimLiquidityAtom.java index 388799459..e03acda88 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimLiquidityAtom.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimLiquidityAtom.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -120,6 +123,32 @@ public boolean equals(Object object) { && Objects.equal(this.amountBought, other.amountBought); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimLiquidityAtom fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimLiquidityAtom fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private PoolID liquidityPoolID; private Asset assetSold; diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimOfferAtom.java b/src/main/java/org/stellar/sdk/xdr/ClaimOfferAtom.java index 7010f3c86..c379e7d9a 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimOfferAtom.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimOfferAtom.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -140,6 +143,32 @@ public boolean equals(Object object) { && Objects.equal(this.amountBought, other.amountBought); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimOfferAtom fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimOfferAtom fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID sellerID; private Int64 offerID; diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimOfferAtomV0.java b/src/main/java/org/stellar/sdk/xdr/ClaimOfferAtomV0.java index 649135d75..aa3e635f6 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimOfferAtomV0.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimOfferAtomV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -140,6 +143,32 @@ public boolean equals(Object object) { && Objects.equal(this.amountBought, other.amountBought); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimOfferAtomV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimOfferAtomV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint256 sellerEd25519; private Int64 offerID; diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimPredicate.java b/src/main/java/org/stellar/sdk/xdr/ClaimPredicate.java index 84da08ecb..43e58652a 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimPredicate.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimPredicate.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -247,4 +250,30 @@ public boolean equals(Object object) { && Objects.equal(this.relBefore, other.relBefore) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimPredicate fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimPredicate fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimPredicateType.java b/src/main/java/org/stellar/sdk/xdr/ClaimPredicateType.java index 1896dfaa2..bbd4e3db1 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimPredicateType.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimPredicateType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -66,4 +69,30 @@ public static void encode(XdrDataOutputStream stream, ClaimPredicateType value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimPredicateType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimPredicateType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceEntry.java b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceEntry.java index 13f57ae2f..54ab38357 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -142,6 +145,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimableBalanceEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimableBalanceEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ClaimableBalanceID balanceID; private Claimant[] claimants; @@ -185,7 +214,7 @@ public ClaimableBalanceEntry build() { } } - public static class ClaimableBalanceEntryExt { + public static class ClaimableBalanceEntryExt implements XdrElement { public ClaimableBalanceEntryExt() {} Integer v; @@ -277,5 +306,31 @@ public boolean equals(Object object) { ClaimableBalanceEntryExt other = (ClaimableBalanceEntryExt) object; return Objects.equal(this.v1, other.v1) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimableBalanceEntryExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimableBalanceEntryExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceEntryExtensionV1.java b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceEntryExtensionV1.java index 44dcd484c..0ef0744c0 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceEntryExtensionV1.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceEntryExtensionV1.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -83,6 +86,32 @@ public boolean equals(Object object) { return Objects.equal(this.ext, other.ext) && Objects.equal(this.flags, other.flags); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimableBalanceEntryExtensionV1 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimableBalanceEntryExtensionV1 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ClaimableBalanceEntryExtensionV1Ext ext; private Uint32 flags; @@ -105,7 +134,7 @@ public ClaimableBalanceEntryExtensionV1 build() { } } - public static class ClaimableBalanceEntryExtensionV1Ext { + public static class ClaimableBalanceEntryExtensionV1Ext implements XdrElement { public ClaimableBalanceEntryExtensionV1Ext() {} Integer v; @@ -177,5 +206,32 @@ public boolean equals(Object object) { ClaimableBalanceEntryExtensionV1Ext other = (ClaimableBalanceEntryExtensionV1Ext) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimableBalanceEntryExtensionV1Ext fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimableBalanceEntryExtensionV1Ext fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceFlags.java b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceFlags.java index 11b85d6f0..5958a0162 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceFlags.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceFlags.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -48,4 +51,30 @@ public static void encode(XdrDataOutputStream stream, ClaimableBalanceFlags valu public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimableBalanceFlags fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimableBalanceFlags fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceID.java b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceID.java index 7fc4f4d8e..53bb5bdc0 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceID.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceID.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -104,4 +107,30 @@ public boolean equals(Object object) { ClaimableBalanceID other = (ClaimableBalanceID) object; return Objects.equal(this.v0, other.v0) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimableBalanceID fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimableBalanceID fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceIDType.java b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceIDType.java index df62c8154..80e989b58 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceIDType.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimableBalanceIDType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -46,4 +49,30 @@ public static void encode(XdrDataOutputStream stream, ClaimableBalanceIDType val public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimableBalanceIDType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimableBalanceIDType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Claimant.java b/src/main/java/org/stellar/sdk/xdr/Claimant.java index df2334477..dc797111e 100644 --- a/src/main/java/org/stellar/sdk/xdr/Claimant.java +++ b/src/main/java/org/stellar/sdk/xdr/Claimant.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -109,7 +112,33 @@ public boolean equals(Object object) { return Objects.equal(this.v0, other.v0) && Objects.equal(this.type, other.type); } - public static class ClaimantV0 { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Claimant fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Claimant fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class ClaimantV0 implements XdrElement { public ClaimantV0() {} private AccountID destination; @@ -165,6 +194,32 @@ public boolean equals(Object object) { && Objects.equal(this.predicate, other.predicate); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimantV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimantV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID destination; private ClaimPredicate predicate; diff --git a/src/main/java/org/stellar/sdk/xdr/ClaimantType.java b/src/main/java/org/stellar/sdk/xdr/ClaimantType.java index cc0eed652..3432fcd00 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClaimantType.java +++ b/src/main/java/org/stellar/sdk/xdr/ClaimantType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -45,4 +48,30 @@ public static void encode(XdrDataOutputStream stream, ClaimantType value) throws public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClaimantType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClaimantType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceOp.java b/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceOp.java index 4fdcf6b9e..900d16622 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceOp.java +++ b/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -60,6 +63,32 @@ public boolean equals(Object object) { return Objects.equal(this.balanceID, other.balanceID); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClawbackClaimableBalanceOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClawbackClaimableBalanceOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ClaimableBalanceID balanceID; diff --git a/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResult.java b/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResult.java index 97dcbad82..162b55f42 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResult.java +++ b/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -103,4 +106,30 @@ public boolean equals(Object object) { ClawbackClaimableBalanceResult other = (ClawbackClaimableBalanceResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClawbackClaimableBalanceResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClawbackClaimableBalanceResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResultCode.java b/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResultCode.java index cd14746a6..04d2014a7 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/ClawbackClaimableBalanceResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -62,4 +65,30 @@ public static void encode(XdrDataOutputStream stream, ClawbackClaimableBalanceRe public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClawbackClaimableBalanceResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClawbackClaimableBalanceResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClawbackOp.java b/src/main/java/org/stellar/sdk/xdr/ClawbackOp.java index 3ba348c99..44a9e7528 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClawbackOp.java +++ b/src/main/java/org/stellar/sdk/xdr/ClawbackOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -87,6 +90,32 @@ public boolean equals(Object object) { && Objects.equal(this.amount, other.amount); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClawbackOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClawbackOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Asset asset; private MuxedAccount from; diff --git a/src/main/java/org/stellar/sdk/xdr/ClawbackResult.java b/src/main/java/org/stellar/sdk/xdr/ClawbackResult.java index d228e8931..53c2c8df3 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClawbackResult.java +++ b/src/main/java/org/stellar/sdk/xdr/ClawbackResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -100,4 +103,30 @@ public boolean equals(Object object) { ClawbackResult other = (ClawbackResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClawbackResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClawbackResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ClawbackResultCode.java b/src/main/java/org/stellar/sdk/xdr/ClawbackResultCode.java index bb0ad1406..1aee628e5 100644 --- a/src/main/java/org/stellar/sdk/xdr/ClawbackResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/ClawbackResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -65,4 +68,30 @@ public static void encode(XdrDataOutputStream stream, ClawbackResultCode value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ClawbackResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ClawbackResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractBandwidthV0.java b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractBandwidthV0.java index 91a6ab982..fd67a882e 100644 --- a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractBandwidthV0.java +++ b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractBandwidthV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -96,6 +99,32 @@ public boolean equals(Object object) { && Objects.equal(this.feePropagateData1KB, other.feePropagateData1KB); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ConfigSettingContractBandwidthV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ConfigSettingContractBandwidthV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 ledgerMaxPropagateSizeBytes; private Uint32 txMaxSizeBytes; diff --git a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractComputeV0.java b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractComputeV0.java index b0b77fc96..cf721573f 100644 --- a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractComputeV0.java +++ b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractComputeV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -116,6 +119,32 @@ public boolean equals(Object object) { && Objects.equal(this.txMemoryLimit, other.txMemoryLimit); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ConfigSettingContractComputeV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ConfigSettingContractComputeV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Int64 ledgerMaxInstructions; private Int64 txMaxInstructions; diff --git a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractExecutionLanesV0.java b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractExecutionLanesV0.java index be130f4d2..4e695c2a3 100644 --- a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractExecutionLanesV0.java +++ b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractExecutionLanesV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -64,6 +67,33 @@ public boolean equals(Object object) { return Objects.equal(this.ledgerMaxTxCount, other.ledgerMaxTxCount); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ConfigSettingContractExecutionLanesV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ConfigSettingContractExecutionLanesV0 fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 ledgerMaxTxCount; diff --git a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractHistoricalDataV0.java b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractHistoricalDataV0.java index 630a5a83c..fe42e4b53 100644 --- a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractHistoricalDataV0.java +++ b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractHistoricalDataV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -63,6 +66,33 @@ public boolean equals(Object object) { return Objects.equal(this.feeHistorical1KB, other.feeHistorical1KB); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ConfigSettingContractHistoricalDataV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ConfigSettingContractHistoricalDataV0 fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Int64 feeHistorical1KB; diff --git a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractLedgerCostV0.java b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractLedgerCostV0.java index 51abdb861..8880a5582 100644 --- a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractLedgerCostV0.java +++ b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractLedgerCostV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -305,6 +308,32 @@ public boolean equals(Object object) { && Objects.equal(this.bucketListGrowthFactor, other.bucketListGrowthFactor); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ConfigSettingContractLedgerCostV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ConfigSettingContractLedgerCostV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 ledgerMaxReadLedgerEntries; private Uint32 ledgerMaxReadBytes; diff --git a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractMetaDataV0.java b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractMetaDataV0.java index cef7eb792..3d17551d7 100644 --- a/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractMetaDataV0.java +++ b/src/main/java/org/stellar/sdk/xdr/ConfigSettingContractMetaDataV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -79,6 +82,32 @@ public boolean equals(Object object) { && Objects.equal(this.feeExtendedMetaData1KB, other.feeExtendedMetaData1KB); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ConfigSettingContractMetaDataV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ConfigSettingContractMetaDataV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 txMaxExtendedMetaDataSizeBytes; private Int64 feeExtendedMetaData1KB; diff --git a/src/main/java/org/stellar/sdk/xdr/ConfigSettingEntry.java b/src/main/java/org/stellar/sdk/xdr/ConfigSettingEntry.java index 0ca29091d..2a576ebe9 100644 --- a/src/main/java/org/stellar/sdk/xdr/ConfigSettingEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/ConfigSettingEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -450,4 +453,30 @@ public boolean equals(Object object) { && Arrays.equals(this.bucketListSizeWindow, other.bucketListSizeWindow) && Objects.equal(this.configSettingID, other.configSettingID); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ConfigSettingEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ConfigSettingEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ConfigSettingID.java b/src/main/java/org/stellar/sdk/xdr/ConfigSettingID.java index 1f45b8766..7cd979a66 100644 --- a/src/main/java/org/stellar/sdk/xdr/ConfigSettingID.java +++ b/src/main/java/org/stellar/sdk/xdr/ConfigSettingID.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -93,4 +96,30 @@ public static void encode(XdrDataOutputStream stream, ConfigSettingID value) thr public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ConfigSettingID fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ConfigSettingID fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ConfigUpgradeSet.java b/src/main/java/org/stellar/sdk/xdr/ConfigUpgradeSet.java index ff18850cf..35f990000 100644 --- a/src/main/java/org/stellar/sdk/xdr/ConfigUpgradeSet.java +++ b/src/main/java/org/stellar/sdk/xdr/ConfigUpgradeSet.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -66,6 +69,32 @@ public boolean equals(Object object) { return Arrays.equals(this.updatedEntry, other.updatedEntry); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ConfigUpgradeSet fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ConfigUpgradeSet fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ConfigSettingEntry[] updatedEntry; diff --git a/src/main/java/org/stellar/sdk/xdr/ConfigUpgradeSetKey.java b/src/main/java/org/stellar/sdk/xdr/ConfigUpgradeSetKey.java index bb24fa626..0d10ff674 100644 --- a/src/main/java/org/stellar/sdk/xdr/ConfigUpgradeSetKey.java +++ b/src/main/java/org/stellar/sdk/xdr/ConfigUpgradeSetKey.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.contentHash, other.contentHash); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ConfigUpgradeSetKey fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ConfigUpgradeSetKey fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash contractID; private Hash contentHash; diff --git a/src/main/java/org/stellar/sdk/xdr/Constants.java b/src/main/java/org/stellar/sdk/xdr/Constants.java index 2438dd144..60813b258 100644 --- a/src/main/java/org/stellar/sdk/xdr/Constants.java +++ b/src/main/java/org/stellar/sdk/xdr/Constants.java @@ -6,9 +6,6 @@ public final class Constants { private Constants() {} - public static final int CONTRACT_COST_COUNT_LIMIT = 1024; - public static final int SC_SPEC_DOC_LIMIT = 1024; - public static final int SCSYMBOL_LIMIT = 32; public static final int MASK_ACCOUNT_FLAGS = 0x7; public static final int MASK_ACCOUNT_FLAGS_V17 = 0xF; public static final int MAX_SIGNERS = 20; @@ -24,4 +21,7 @@ private Constants() {} public static final int TX_DEMAND_VECTOR_MAX_SIZE = 1000; public static final int MAX_OPS_PER_TX = 100; public static final int LIQUIDITY_POOL_FEE_V18 = 30; + public static final int SC_SPEC_DOC_LIMIT = 1024; + public static final int SCSYMBOL_LIMIT = 32; + public static final int CONTRACT_COST_COUNT_LIMIT = 1024; } diff --git a/src/main/java/org/stellar/sdk/xdr/ContractCodeEntry.java b/src/main/java/org/stellar/sdk/xdr/ContractCodeEntry.java index 74fdc6cd2..0035614b0 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractCodeEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractCodeEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -109,6 +112,32 @@ public boolean equals(Object object) { && Objects.equal(this.expirationLedgerSeq, other.expirationLedgerSeq); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractCodeEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractCodeEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ExtensionPoint ext; private Hash hash; @@ -145,7 +174,7 @@ public ContractCodeEntry build() { } } - public static class ContractCodeEntryBody { + public static class ContractCodeEntryBody implements XdrElement { public ContractCodeEntryBody() {} ContractEntryBodyType bodyType; @@ -241,5 +270,31 @@ public boolean equals(Object object) { ContractCodeEntryBody other = (ContractCodeEntryBody) object; return Arrays.equals(this.code, other.code) && Objects.equal(this.bodyType, other.bodyType); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractCodeEntryBody fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractCodeEntryBody fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/ContractCostParamEntry.java b/src/main/java/org/stellar/sdk/xdr/ContractCostParamEntry.java index 4be8af934..062868a05 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractCostParamEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractCostParamEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -89,6 +92,32 @@ public boolean equals(Object object) { && Objects.equal(this.linearTerm, other.linearTerm); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractCostParamEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractCostParamEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ExtensionPoint ext; private Int64 constTerm; diff --git a/src/main/java/org/stellar/sdk/xdr/ContractCostParams.java b/src/main/java/org/stellar/sdk/xdr/ContractCostParams.java index 033bad8d9..4c5654b11 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractCostParams.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractCostParams.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -68,4 +71,30 @@ public boolean equals(Object object) { ContractCostParams other = (ContractCostParams) object; return Arrays.equals(this.ContractCostParams, other.ContractCostParams); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractCostParams fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractCostParams fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ContractCostType.java b/src/main/java/org/stellar/sdk/xdr/ContractCostType.java index 3752a793d..645779b4a 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractCostType.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractCostType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -200,4 +203,30 @@ public static void encode(XdrDataOutputStream stream, ContractCostType value) th public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractCostType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractCostType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ContractDataDurability.java b/src/main/java/org/stellar/sdk/xdr/ContractDataDurability.java index 992ecab54..a286b47a9 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractDataDurability.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractDataDurability.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -49,4 +52,30 @@ public static void encode(XdrDataOutputStream stream, ContractDataDurability val public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractDataDurability fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractDataDurability fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ContractDataEntry.java b/src/main/java/org/stellar/sdk/xdr/ContractDataEntry.java index 18c5ac90b..e6e3e82b3 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractDataEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractDataEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -127,6 +130,32 @@ public boolean equals(Object object) { && Objects.equal(this.expirationLedgerSeq, other.expirationLedgerSeq); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractDataEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractDataEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCAddress contract; private SCVal key; @@ -170,7 +199,7 @@ public ContractDataEntry build() { } } - public static class ContractDataEntryBody { + public static class ContractDataEntryBody implements XdrElement { public ContractDataEntryBody() {} ContractEntryBodyType bodyType; @@ -263,7 +292,33 @@ public boolean equals(Object object) { return Objects.equal(this.data, other.data) && Objects.equal(this.bodyType, other.bodyType); } - public static class ContractDataEntryData { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractDataEntryBody fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractDataEntryBody fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class ContractDataEntryData implements XdrElement { public ContractDataEntryData() {} private Uint32 flags; @@ -319,6 +374,32 @@ public boolean equals(Object object) { return Objects.equal(this.flags, other.flags) && Objects.equal(this.val, other.val); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractDataEntryData fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractDataEntryData fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 flags; private SCVal val; diff --git a/src/main/java/org/stellar/sdk/xdr/ContractDataFlags.java b/src/main/java/org/stellar/sdk/xdr/ContractDataFlags.java index f1871f5ee..0e20ed10a 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractDataFlags.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractDataFlags.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -47,4 +50,30 @@ public static void encode(XdrDataOutputStream stream, ContractDataFlags value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractDataFlags fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractDataFlags fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ContractEntryBodyType.java b/src/main/java/org/stellar/sdk/xdr/ContractEntryBodyType.java index eae02b395..9bf5b1f89 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractEntryBodyType.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractEntryBodyType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -49,4 +52,30 @@ public static void encode(XdrDataOutputStream stream, ContractEntryBodyType valu public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractEntryBodyType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractEntryBodyType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ContractEvent.java b/src/main/java/org/stellar/sdk/xdr/ContractEvent.java index 3b9c703b2..5bc8e9287 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractEvent.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractEvent.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -122,6 +125,32 @@ public boolean equals(Object object) { && Objects.equal(this.body, other.body); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractEvent fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractEvent fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ExtensionPoint ext; private Hash contractID; @@ -158,7 +187,7 @@ public ContractEvent build() { } } - public static class ContractEventBody { + public static class ContractEventBody implements XdrElement { public ContractEventBody() {} Integer v; @@ -246,7 +275,33 @@ public boolean equals(Object object) { return Objects.equal(this.v0, other.v0) && Objects.equal(this.v, other.v); } - public static class ContractEventV0 { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractEventBody fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractEventBody fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class ContractEventV0 implements XdrElement { public ContractEventV0() {} private SCVec topics; @@ -301,6 +356,32 @@ public boolean equals(Object object) { return Objects.equal(this.topics, other.topics) && Objects.equal(this.data, other.data); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractEventV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractEventV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCVec topics; private SCVal data; diff --git a/src/main/java/org/stellar/sdk/xdr/ContractEventType.java b/src/main/java/org/stellar/sdk/xdr/ContractEventType.java index ce50fbafb..19adb659c 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractEventType.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractEventType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -54,4 +57,30 @@ public static void encode(XdrDataOutputStream stream, ContractEventType value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractEventType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractEventType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ContractExecutable.java b/src/main/java/org/stellar/sdk/xdr/ContractExecutable.java index ef40b3766..889f9274f 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractExecutable.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractExecutable.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -110,4 +113,30 @@ public boolean equals(Object object) { ContractExecutable other = (ContractExecutable) object; return Objects.equal(this.wasm_hash, other.wasm_hash) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractExecutable fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractExecutable fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ContractExecutableType.java b/src/main/java/org/stellar/sdk/xdr/ContractExecutableType.java index 5689b059f..4670c06ed 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractExecutableType.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractExecutableType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -50,4 +53,30 @@ public static void encode(XdrDataOutputStream stream, ContractExecutableType val public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractExecutableType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractExecutableType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ContractIDPreimage.java b/src/main/java/org/stellar/sdk/xdr/ContractIDPreimage.java index 72f2ceecb..b264111c9 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractIDPreimage.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractIDPreimage.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -136,7 +139,33 @@ public boolean equals(Object object) { && Objects.equal(this.type, other.type); } - public static class ContractIDPreimageFromAddress { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractIDPreimage fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractIDPreimage fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class ContractIDPreimageFromAddress implements XdrElement { public ContractIDPreimageFromAddress() {} private SCAddress address; @@ -195,6 +224,32 @@ public boolean equals(Object object) { return Objects.equal(this.address, other.address) && Objects.equal(this.salt, other.salt); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractIDPreimageFromAddress fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractIDPreimageFromAddress fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCAddress address; private Uint256 salt; diff --git a/src/main/java/org/stellar/sdk/xdr/ContractIDPreimageType.java b/src/main/java/org/stellar/sdk/xdr/ContractIDPreimageType.java index af4ba33b2..ef49dd359 100644 --- a/src/main/java/org/stellar/sdk/xdr/ContractIDPreimageType.java +++ b/src/main/java/org/stellar/sdk/xdr/ContractIDPreimageType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -50,4 +53,30 @@ public static void encode(XdrDataOutputStream stream, ContractIDPreimageType val public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ContractIDPreimageType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ContractIDPreimageType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/CreateAccountOp.java b/src/main/java/org/stellar/sdk/xdr/CreateAccountOp.java index 876177148..12ced4a18 100644 --- a/src/main/java/org/stellar/sdk/xdr/CreateAccountOp.java +++ b/src/main/java/org/stellar/sdk/xdr/CreateAccountOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.startingBalance, other.startingBalance); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static CreateAccountOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static CreateAccountOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID destination; private Int64 startingBalance; diff --git a/src/main/java/org/stellar/sdk/xdr/CreateAccountResult.java b/src/main/java/org/stellar/sdk/xdr/CreateAccountResult.java index d2f106765..c4052db18 100644 --- a/src/main/java/org/stellar/sdk/xdr/CreateAccountResult.java +++ b/src/main/java/org/stellar/sdk/xdr/CreateAccountResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -101,4 +104,30 @@ public boolean equals(Object object) { CreateAccountResult other = (CreateAccountResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static CreateAccountResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static CreateAccountResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/CreateAccountResultCode.java b/src/main/java/org/stellar/sdk/xdr/CreateAccountResultCode.java index 0af2f9d09..80356ab87 100644 --- a/src/main/java/org/stellar/sdk/xdr/CreateAccountResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/CreateAccountResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -66,4 +69,30 @@ public static void encode(XdrDataOutputStream stream, CreateAccountResultCode va public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static CreateAccountResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static CreateAccountResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceOp.java b/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceOp.java index 27da5e9f0..fd088563d 100644 --- a/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceOp.java +++ b/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -97,6 +100,32 @@ public boolean equals(Object object) { && Arrays.equals(this.claimants, other.claimants); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static CreateClaimableBalanceOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static CreateClaimableBalanceOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Asset asset; private Int64 amount; diff --git a/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResult.java b/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResult.java index 08cff736f..b77bcf6e6 100644 --- a/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResult.java +++ b/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -125,4 +128,30 @@ public boolean equals(Object object) { CreateClaimableBalanceResult other = (CreateClaimableBalanceResult) object; return Objects.equal(this.balanceID, other.balanceID) && Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static CreateClaimableBalanceResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static CreateClaimableBalanceResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResultCode.java b/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResultCode.java index 99c0d7138..043255af4 100644 --- a/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/CreateClaimableBalanceResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -67,4 +70,30 @@ public static void encode(XdrDataOutputStream stream, CreateClaimableBalanceResu public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static CreateClaimableBalanceResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static CreateClaimableBalanceResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/CreateContractArgs.java b/src/main/java/org/stellar/sdk/xdr/CreateContractArgs.java index 1d38d73e9..7caeb531e 100644 --- a/src/main/java/org/stellar/sdk/xdr/CreateContractArgs.java +++ b/src/main/java/org/stellar/sdk/xdr/CreateContractArgs.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.executable, other.executable); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static CreateContractArgs fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static CreateContractArgs fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ContractIDPreimage contractIDPreimage; private ContractExecutable executable; diff --git a/src/main/java/org/stellar/sdk/xdr/CreatePassiveSellOfferOp.java b/src/main/java/org/stellar/sdk/xdr/CreatePassiveSellOfferOp.java index 2e6543775..1112b6421 100644 --- a/src/main/java/org/stellar/sdk/xdr/CreatePassiveSellOfferOp.java +++ b/src/main/java/org/stellar/sdk/xdr/CreatePassiveSellOfferOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -102,6 +105,32 @@ public boolean equals(Object object) { && Objects.equal(this.price, other.price); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static CreatePassiveSellOfferOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static CreatePassiveSellOfferOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Asset selling; private Asset buying; diff --git a/src/main/java/org/stellar/sdk/xdr/CryptoKeyType.java b/src/main/java/org/stellar/sdk/xdr/CryptoKeyType.java index bcb36cd6e..518ded557 100644 --- a/src/main/java/org/stellar/sdk/xdr/CryptoKeyType.java +++ b/src/main/java/org/stellar/sdk/xdr/CryptoKeyType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -63,4 +66,30 @@ public static void encode(XdrDataOutputStream stream, CryptoKeyType value) throw public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static CryptoKeyType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static CryptoKeyType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Curve25519Public.java b/src/main/java/org/stellar/sdk/xdr/Curve25519Public.java index 9534a1992..3e43fffed 100644 --- a/src/main/java/org/stellar/sdk/xdr/Curve25519Public.java +++ b/src/main/java/org/stellar/sdk/xdr/Curve25519Public.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -62,6 +65,32 @@ public boolean equals(Object object) { return Arrays.equals(this.key, other.key); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Curve25519Public fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Curve25519Public fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private byte[] key; diff --git a/src/main/java/org/stellar/sdk/xdr/Curve25519Secret.java b/src/main/java/org/stellar/sdk/xdr/Curve25519Secret.java index 8ca01275b..90ea87d2a 100644 --- a/src/main/java/org/stellar/sdk/xdr/Curve25519Secret.java +++ b/src/main/java/org/stellar/sdk/xdr/Curve25519Secret.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -62,6 +65,32 @@ public boolean equals(Object object) { return Arrays.equals(this.key, other.key); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Curve25519Secret fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Curve25519Secret fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private byte[] key; diff --git a/src/main/java/org/stellar/sdk/xdr/DataEntry.java b/src/main/java/org/stellar/sdk/xdr/DataEntry.java index b1faf5d7a..d00de786b 100644 --- a/src/main/java/org/stellar/sdk/xdr/DataEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/DataEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -108,6 +111,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static DataEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static DataEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID accountID; private String64 dataName; @@ -144,7 +173,7 @@ public DataEntry build() { } } - public static class DataEntryExt { + public static class DataEntryExt implements XdrElement { public DataEntryExt() {} Integer v; @@ -212,5 +241,31 @@ public boolean equals(Object object) { DataEntryExt other = (DataEntryExt) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static DataEntryExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static DataEntryExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/DataValue.java b/src/main/java/org/stellar/sdk/xdr/DataValue.java index e9ff69844..7d3e0aed6 100644 --- a/src/main/java/org/stellar/sdk/xdr/DataValue.java +++ b/src/main/java/org/stellar/sdk/xdr/DataValue.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -63,4 +66,30 @@ public boolean equals(Object object) { DataValue other = (DataValue) object; return Arrays.equals(this.DataValue, other.DataValue); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static DataValue fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static DataValue fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/DecoratedSignature.java b/src/main/java/org/stellar/sdk/xdr/DecoratedSignature.java index b522ac237..80b1728b9 100644 --- a/src/main/java/org/stellar/sdk/xdr/DecoratedSignature.java +++ b/src/main/java/org/stellar/sdk/xdr/DecoratedSignature.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -72,6 +75,32 @@ public boolean equals(Object object) { return Objects.equal(this.hint, other.hint) && Objects.equal(this.signature, other.signature); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static DecoratedSignature fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static DecoratedSignature fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SignatureHint hint; private Signature signature; diff --git a/src/main/java/org/stellar/sdk/xdr/DiagnosticEvent.java b/src/main/java/org/stellar/sdk/xdr/DiagnosticEvent.java index 9f9c3e355..735a2eddb 100644 --- a/src/main/java/org/stellar/sdk/xdr/DiagnosticEvent.java +++ b/src/main/java/org/stellar/sdk/xdr/DiagnosticEvent.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.event, other.event); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static DiagnosticEvent fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static DiagnosticEvent fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Boolean inSuccessfulContractCall; private ContractEvent event; diff --git a/src/main/java/org/stellar/sdk/xdr/DontHave.java b/src/main/java/org/stellar/sdk/xdr/DontHave.java index f72aeb633..2952ea1c2 100644 --- a/src/main/java/org/stellar/sdk/xdr/DontHave.java +++ b/src/main/java/org/stellar/sdk/xdr/DontHave.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -72,6 +75,32 @@ public boolean equals(Object object) { return Objects.equal(this.type, other.type) && Objects.equal(this.reqHash, other.reqHash); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static DontHave fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static DontHave fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private MessageType type; private Uint256 reqHash; diff --git a/src/main/java/org/stellar/sdk/xdr/Duration.java b/src/main/java/org/stellar/sdk/xdr/Duration.java index f71595f4b..bb740d7f9 100644 --- a/src/main/java/org/stellar/sdk/xdr/Duration.java +++ b/src/main/java/org/stellar/sdk/xdr/Duration.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,4 +62,30 @@ public boolean equals(Object object) { Duration other = (Duration) object; return Objects.equal(this.Duration, other.Duration); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Duration fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Duration fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/EncryptedBody.java b/src/main/java/org/stellar/sdk/xdr/EncryptedBody.java index 9b63a633e..980f98085 100644 --- a/src/main/java/org/stellar/sdk/xdr/EncryptedBody.java +++ b/src/main/java/org/stellar/sdk/xdr/EncryptedBody.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -63,4 +66,30 @@ public boolean equals(Object object) { EncryptedBody other = (EncryptedBody) object; return Arrays.equals(this.EncryptedBody, other.EncryptedBody); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static EncryptedBody fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static EncryptedBody fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResult.java b/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResult.java index 9b9fd0758..ed2ee43b6 100644 --- a/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResult.java +++ b/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -97,4 +100,30 @@ public boolean equals(Object object) { EndSponsoringFutureReservesResult other = (EndSponsoringFutureReservesResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static EndSponsoringFutureReservesResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static EndSponsoringFutureReservesResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResultCode.java b/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResultCode.java index 067946337..861615933 100644 --- a/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/EndSponsoringFutureReservesResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -54,4 +57,31 @@ public static void encode(XdrDataOutputStream stream, EndSponsoringFutureReserve public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static EndSponsoringFutureReservesResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static EndSponsoringFutureReservesResultCode fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/EnvelopeType.java b/src/main/java/org/stellar/sdk/xdr/EnvelopeType.java index 836692826..98a9505d9 100644 --- a/src/main/java/org/stellar/sdk/xdr/EnvelopeType.java +++ b/src/main/java/org/stellar/sdk/xdr/EnvelopeType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -81,4 +84,30 @@ public static void encode(XdrDataOutputStream stream, EnvelopeType value) throws public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static EnvelopeType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static EnvelopeType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Error.java b/src/main/java/org/stellar/sdk/xdr/Error.java index 2060216b9..c1fd69dfb 100644 --- a/src/main/java/org/stellar/sdk/xdr/Error.java +++ b/src/main/java/org/stellar/sdk/xdr/Error.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -71,6 +74,32 @@ public boolean equals(Object object) { return Objects.equal(this.code, other.code) && Objects.equal(this.msg, other.msg); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Error fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Error fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ErrorCode code; private XdrString msg; diff --git a/src/main/java/org/stellar/sdk/xdr/ErrorCode.java b/src/main/java/org/stellar/sdk/xdr/ErrorCode.java index 554effd5f..b5131668f 100644 --- a/src/main/java/org/stellar/sdk/xdr/ErrorCode.java +++ b/src/main/java/org/stellar/sdk/xdr/ErrorCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -61,4 +64,30 @@ public static void encode(XdrDataOutputStream stream, ErrorCode value) throws IO public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ErrorCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ErrorCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ExtensionPoint.java b/src/main/java/org/stellar/sdk/xdr/ExtensionPoint.java index f7a666a1a..25cd82247 100644 --- a/src/main/java/org/stellar/sdk/xdr/ExtensionPoint.java +++ b/src/main/java/org/stellar/sdk/xdr/ExtensionPoint.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -85,4 +88,30 @@ public boolean equals(Object object) { ExtensionPoint other = (ExtensionPoint) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ExtensionPoint fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ExtensionPoint fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/FeeBumpTransaction.java b/src/main/java/org/stellar/sdk/xdr/FeeBumpTransaction.java index 7698fad97..2908b9273 100644 --- a/src/main/java/org/stellar/sdk/xdr/FeeBumpTransaction.java +++ b/src/main/java/org/stellar/sdk/xdr/FeeBumpTransaction.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -111,6 +114,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static FeeBumpTransaction fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static FeeBumpTransaction fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private MuxedAccount feeSource; private Int64 fee; @@ -147,7 +176,7 @@ public FeeBumpTransaction build() { } } - public static class FeeBumpTransactionInnerTx { + public static class FeeBumpTransactionInnerTx implements XdrElement { public FeeBumpTransactionInnerTx() {} EnvelopeType type; @@ -235,9 +264,35 @@ public boolean equals(Object object) { FeeBumpTransactionInnerTx other = (FeeBumpTransactionInnerTx) object; return Objects.equal(this.v1, other.v1) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static FeeBumpTransactionInnerTx fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static FeeBumpTransactionInnerTx fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } - public static class FeeBumpTransactionExt { + public static class FeeBumpTransactionExt implements XdrElement { public FeeBumpTransactionExt() {} Integer v; @@ -306,5 +361,31 @@ public boolean equals(Object object) { FeeBumpTransactionExt other = (FeeBumpTransactionExt) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static FeeBumpTransactionExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static FeeBumpTransactionExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/FeeBumpTransactionEnvelope.java b/src/main/java/org/stellar/sdk/xdr/FeeBumpTransactionEnvelope.java index 22d3fd767..af9739bc0 100644 --- a/src/main/java/org/stellar/sdk/xdr/FeeBumpTransactionEnvelope.java +++ b/src/main/java/org/stellar/sdk/xdr/FeeBumpTransactionEnvelope.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -84,6 +87,32 @@ public boolean equals(Object object) { return Objects.equal(this.tx, other.tx) && Arrays.equals(this.signatures, other.signatures); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static FeeBumpTransactionEnvelope fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static FeeBumpTransactionEnvelope fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private FeeBumpTransaction tx; private DecoratedSignature[] signatures; diff --git a/src/main/java/org/stellar/sdk/xdr/FloodAdvert.java b/src/main/java/org/stellar/sdk/xdr/FloodAdvert.java index 22e8f8b9c..e05c9269b 100644 --- a/src/main/java/org/stellar/sdk/xdr/FloodAdvert.java +++ b/src/main/java/org/stellar/sdk/xdr/FloodAdvert.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,6 +62,32 @@ public boolean equals(Object object) { return Objects.equal(this.txHashes, other.txHashes); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static FloodAdvert fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static FloodAdvert fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private TxAdvertVector txHashes; diff --git a/src/main/java/org/stellar/sdk/xdr/FloodDemand.java b/src/main/java/org/stellar/sdk/xdr/FloodDemand.java index f21c6db2b..c7e7d231f 100644 --- a/src/main/java/org/stellar/sdk/xdr/FloodDemand.java +++ b/src/main/java/org/stellar/sdk/xdr/FloodDemand.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,6 +62,32 @@ public boolean equals(Object object) { return Objects.equal(this.txHashes, other.txHashes); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static FloodDemand fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static FloodDemand fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private TxDemandVector txHashes; diff --git a/src/main/java/org/stellar/sdk/xdr/GeneralizedTransactionSet.java b/src/main/java/org/stellar/sdk/xdr/GeneralizedTransactionSet.java index 0ea7eec2f..bf8b72417 100644 --- a/src/main/java/org/stellar/sdk/xdr/GeneralizedTransactionSet.java +++ b/src/main/java/org/stellar/sdk/xdr/GeneralizedTransactionSet.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -106,4 +109,30 @@ public boolean equals(Object object) { GeneralizedTransactionSet other = (GeneralizedTransactionSet) object; return Objects.equal(this.v1TxSet, other.v1TxSet) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static GeneralizedTransactionSet fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static GeneralizedTransactionSet fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Hash.java b/src/main/java/org/stellar/sdk/xdr/Hash.java index 9b2678c9c..f04b8343e 100644 --- a/src/main/java/org/stellar/sdk/xdr/Hash.java +++ b/src/main/java/org/stellar/sdk/xdr/Hash.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -61,4 +64,30 @@ public boolean equals(Object object) { Hash other = (Hash) object; return Arrays.equals(this.Hash, other.Hash); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Hash fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Hash fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/HashIDPreimage.java b/src/main/java/org/stellar/sdk/xdr/HashIDPreimage.java index 931f0c3f3..343874cc9 100644 --- a/src/main/java/org/stellar/sdk/xdr/HashIDPreimage.java +++ b/src/main/java/org/stellar/sdk/xdr/HashIDPreimage.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -209,7 +212,33 @@ public boolean equals(Object object) { && Objects.equal(this.type, other.type); } - public static class HashIDPreimageOperationID { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static HashIDPreimage fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static HashIDPreimage fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class HashIDPreimageOperationID implements XdrElement { public HashIDPreimageOperationID() {} private AccountID sourceAccount; @@ -279,6 +308,32 @@ public boolean equals(Object object) { && Objects.equal(this.opNum, other.opNum); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static HashIDPreimageOperationID fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static HashIDPreimageOperationID fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID sourceAccount; private SequenceNumber seqNum; @@ -309,7 +364,7 @@ public HashIDPreimageOperationID build() { } } - public static class HashIDPreimageRevokeID { + public static class HashIDPreimageRevokeID implements XdrElement { public HashIDPreimageRevokeID() {} private AccountID sourceAccount; @@ -406,6 +461,32 @@ public boolean equals(Object object) { && Objects.equal(this.asset, other.asset); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static HashIDPreimageRevokeID fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static HashIDPreimageRevokeID fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID sourceAccount; private SequenceNumber seqNum; @@ -450,7 +531,7 @@ public HashIDPreimageRevokeID build() { } } - public static class HashIDPreimageContractID { + public static class HashIDPreimageContractID implements XdrElement { public HashIDPreimageContractID() {} private Hash networkID; @@ -507,6 +588,32 @@ public boolean equals(Object object) { && Objects.equal(this.contractIDPreimage, other.contractIDPreimage); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static HashIDPreimageContractID fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static HashIDPreimageContractID fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash networkID; private ContractIDPreimage contractIDPreimage; @@ -530,7 +637,7 @@ public HashIDPreimageContractID build() { } } - public static class HashIDPreimageSorobanAuthorization { + public static class HashIDPreimageSorobanAuthorization implements XdrElement { public HashIDPreimageSorobanAuthorization() {} private Hash networkID; @@ -619,6 +726,33 @@ public boolean equals(Object object) { && Objects.equal(this.invocation, other.invocation); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static HashIDPreimageSorobanAuthorization fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static HashIDPreimageSorobanAuthorization fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash networkID; private Int64 nonce; diff --git a/src/main/java/org/stellar/sdk/xdr/Hello.java b/src/main/java/org/stellar/sdk/xdr/Hello.java index f1fec50d6..e131ee4f0 100644 --- a/src/main/java/org/stellar/sdk/xdr/Hello.java +++ b/src/main/java/org/stellar/sdk/xdr/Hello.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -179,6 +182,32 @@ public boolean equals(Object object) { && Objects.equal(this.nonce, other.nonce); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Hello fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Hello fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 ledgerVersion; private Uint32 overlayVersion; diff --git a/src/main/java/org/stellar/sdk/xdr/HmacSha256Key.java b/src/main/java/org/stellar/sdk/xdr/HmacSha256Key.java index 1b84a0074..289cbf05c 100644 --- a/src/main/java/org/stellar/sdk/xdr/HmacSha256Key.java +++ b/src/main/java/org/stellar/sdk/xdr/HmacSha256Key.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -62,6 +65,32 @@ public boolean equals(Object object) { return Arrays.equals(this.key, other.key); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static HmacSha256Key fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static HmacSha256Key fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private byte[] key; diff --git a/src/main/java/org/stellar/sdk/xdr/HmacSha256Mac.java b/src/main/java/org/stellar/sdk/xdr/HmacSha256Mac.java index a24a2d717..1d361a93a 100644 --- a/src/main/java/org/stellar/sdk/xdr/HmacSha256Mac.java +++ b/src/main/java/org/stellar/sdk/xdr/HmacSha256Mac.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -62,6 +65,32 @@ public boolean equals(Object object) { return Arrays.equals(this.mac, other.mac); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static HmacSha256Mac fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static HmacSha256Mac fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private byte[] mac; diff --git a/src/main/java/org/stellar/sdk/xdr/HostFunction.java b/src/main/java/org/stellar/sdk/xdr/HostFunction.java index 28d837199..f62984d1d 100644 --- a/src/main/java/org/stellar/sdk/xdr/HostFunction.java +++ b/src/main/java/org/stellar/sdk/xdr/HostFunction.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -163,4 +166,30 @@ public boolean equals(Object object) { && Arrays.equals(this.wasm, other.wasm) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static HostFunction fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static HostFunction fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/HostFunctionType.java b/src/main/java/org/stellar/sdk/xdr/HostFunctionType.java index d8bfdbc8f..a374f9ed9 100644 --- a/src/main/java/org/stellar/sdk/xdr/HostFunctionType.java +++ b/src/main/java/org/stellar/sdk/xdr/HostFunctionType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -53,4 +56,30 @@ public static void encode(XdrDataOutputStream stream, HostFunctionType value) th public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static HostFunctionType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static HostFunctionType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/IPAddrType.java b/src/main/java/org/stellar/sdk/xdr/IPAddrType.java index 08d887d10..8d62a3d48 100644 --- a/src/main/java/org/stellar/sdk/xdr/IPAddrType.java +++ b/src/main/java/org/stellar/sdk/xdr/IPAddrType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -49,4 +52,30 @@ public static void encode(XdrDataOutputStream stream, IPAddrType value) throws I public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static IPAddrType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static IPAddrType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/InflationPayout.java b/src/main/java/org/stellar/sdk/xdr/InflationPayout.java index 1c9ed7008..ffb1923db 100644 --- a/src/main/java/org/stellar/sdk/xdr/InflationPayout.java +++ b/src/main/java/org/stellar/sdk/xdr/InflationPayout.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.amount, other.amount); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static InflationPayout fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static InflationPayout fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID destination; private Int64 amount; diff --git a/src/main/java/org/stellar/sdk/xdr/InflationResult.java b/src/main/java/org/stellar/sdk/xdr/InflationResult.java index 33c8bd2f9..a4452ba16 100644 --- a/src/main/java/org/stellar/sdk/xdr/InflationResult.java +++ b/src/main/java/org/stellar/sdk/xdr/InflationResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -119,4 +122,30 @@ public boolean equals(Object object) { InflationResult other = (InflationResult) object; return Arrays.equals(this.payouts, other.payouts) && Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static InflationResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static InflationResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/InflationResultCode.java b/src/main/java/org/stellar/sdk/xdr/InflationResultCode.java index 01a7f5f5a..8cf4e12f0 100644 --- a/src/main/java/org/stellar/sdk/xdr/InflationResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/InflationResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -52,4 +55,30 @@ public static void encode(XdrDataOutputStream stream, InflationResultCode value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static InflationResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static InflationResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/InnerTransactionResult.java b/src/main/java/org/stellar/sdk/xdr/InnerTransactionResult.java index 823051107..a7e514ed6 100644 --- a/src/main/java/org/stellar/sdk/xdr/InnerTransactionResult.java +++ b/src/main/java/org/stellar/sdk/xdr/InnerTransactionResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -122,6 +125,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static InnerTransactionResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static InnerTransactionResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Int64 feeCharged; private InnerTransactionResultResult result; @@ -151,7 +180,7 @@ public InnerTransactionResult build() { } } - public static class InnerTransactionResultResult { + public static class InnerTransactionResultResult implements XdrElement { public InnerTransactionResultResult() {} TransactionResultCode code; @@ -284,9 +313,35 @@ public boolean equals(Object object) { InnerTransactionResultResult other = (InnerTransactionResultResult) object; return Arrays.equals(this.results, other.results) && Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static InnerTransactionResultResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static InnerTransactionResultResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } - public static class InnerTransactionResultExt { + public static class InnerTransactionResultExt implements XdrElement { public InnerTransactionResultExt() {} Integer v; @@ -355,5 +410,31 @@ public boolean equals(Object object) { InnerTransactionResultExt other = (InnerTransactionResultExt) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static InnerTransactionResultExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static InnerTransactionResultExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/InnerTransactionResultPair.java b/src/main/java/org/stellar/sdk/xdr/InnerTransactionResultPair.java index 8a07e440a..878e4e75b 100644 --- a/src/main/java/org/stellar/sdk/xdr/InnerTransactionResultPair.java +++ b/src/main/java/org/stellar/sdk/xdr/InnerTransactionResultPair.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -74,6 +77,32 @@ public boolean equals(Object object) { && Objects.equal(this.result, other.result); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static InnerTransactionResultPair fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static InnerTransactionResultPair fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash transactionHash; private InnerTransactionResult result; diff --git a/src/main/java/org/stellar/sdk/xdr/Int128Parts.java b/src/main/java/org/stellar/sdk/xdr/Int128Parts.java index d77fcd1da..2bf2552c3 100644 --- a/src/main/java/org/stellar/sdk/xdr/Int128Parts.java +++ b/src/main/java/org/stellar/sdk/xdr/Int128Parts.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -71,6 +74,32 @@ public boolean equals(Object object) { return Objects.equal(this.hi, other.hi) && Objects.equal(this.lo, other.lo); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Int128Parts fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Int128Parts fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Int64 hi; private Uint64 lo; diff --git a/src/main/java/org/stellar/sdk/xdr/Int256Parts.java b/src/main/java/org/stellar/sdk/xdr/Int256Parts.java index 6f477f135..66f9204a7 100644 --- a/src/main/java/org/stellar/sdk/xdr/Int256Parts.java +++ b/src/main/java/org/stellar/sdk/xdr/Int256Parts.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -100,6 +103,32 @@ public boolean equals(Object object) { && Objects.equal(this.lo_lo, other.lo_lo); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Int256Parts fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Int256Parts fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Int64 hi_hi; private Uint64 hi_lo; diff --git a/src/main/java/org/stellar/sdk/xdr/Int32.java b/src/main/java/org/stellar/sdk/xdr/Int32.java index 15ba2b46e..b887dd2d9 100644 --- a/src/main/java/org/stellar/sdk/xdr/Int32.java +++ b/src/main/java/org/stellar/sdk/xdr/Int32.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -58,4 +61,30 @@ public boolean equals(Object object) { Int32 other = (Int32) object; return Objects.equal(this.int32, other.int32); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Int32 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Int32 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Int64.java b/src/main/java/org/stellar/sdk/xdr/Int64.java index 08f7bb020..c47b05bfd 100644 --- a/src/main/java/org/stellar/sdk/xdr/Int64.java +++ b/src/main/java/org/stellar/sdk/xdr/Int64.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -58,4 +61,30 @@ public boolean equals(Object object) { Int64 other = (Int64) object; return Objects.equal(this.int64, other.int64); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Int64 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Int64 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionOp.java b/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionOp.java index 4805f092e..59d82dd6a 100644 --- a/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionOp.java +++ b/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -85,6 +88,32 @@ public boolean equals(Object object) { && Arrays.equals(this.auth, other.auth); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static InvokeHostFunctionOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static InvokeHostFunctionOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private HostFunction hostFunction; private SorobanAuthorizationEntry[] auth; diff --git a/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionResult.java b/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionResult.java index 417cd911d..494fb3500 100644 --- a/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionResult.java +++ b/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -17,7 +20,6 @@ // case INVOKE_HOST_FUNCTION_MALFORMED: // case INVOKE_HOST_FUNCTION_TRAPPED: // case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: -// case INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: // void; // }; @@ -80,7 +82,6 @@ public static void encode( case INVOKE_HOST_FUNCTION_MALFORMED: case INVOKE_HOST_FUNCTION_TRAPPED: case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: - case INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: break; } } @@ -100,7 +101,6 @@ public static InvokeHostFunctionResult decode(XdrDataInputStream stream) throws case INVOKE_HOST_FUNCTION_MALFORMED: case INVOKE_HOST_FUNCTION_TRAPPED: case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: - case INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: break; } return decodedInvokeHostFunctionResult; @@ -120,4 +120,30 @@ public boolean equals(Object object) { InvokeHostFunctionResult other = (InvokeHostFunctionResult) object; return Objects.equal(this.success, other.success) && Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static InvokeHostFunctionResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static InvokeHostFunctionResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionResultCode.java b/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionResultCode.java index 1f211d434..b88f149df 100644 --- a/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -17,8 +20,7 @@ // // codes considered as "failure" for the operation // INVOKE_HOST_FUNCTION_MALFORMED = -1, // INVOKE_HOST_FUNCTION_TRAPPED = -2, -// INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3, -// INVOKE_HOST_FUNCTION_ENTRY_EXPIRED = -4 +// INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3 // }; // =========================================================================== @@ -27,7 +29,6 @@ public enum InvokeHostFunctionResultCode implements XdrElement { INVOKE_HOST_FUNCTION_MALFORMED(-1), INVOKE_HOST_FUNCTION_TRAPPED(-2), INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED(-3), - INVOKE_HOST_FUNCTION_ENTRY_EXPIRED(-4), ; private int mValue; @@ -50,8 +51,6 @@ public static InvokeHostFunctionResultCode decode(XdrDataInputStream stream) thr return INVOKE_HOST_FUNCTION_TRAPPED; case -3: return INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED; - case -4: - return INVOKE_HOST_FUNCTION_ENTRY_EXPIRED; default: throw new RuntimeException("Unknown enum value: " + value); } @@ -65,4 +64,30 @@ public static void encode(XdrDataOutputStream stream, InvokeHostFunctionResultCo public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static InvokeHostFunctionResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static InvokeHostFunctionResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionSuccessPreImage.java b/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionSuccessPreImage.java index f8ef45bb1..feefc9cd5 100644 --- a/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionSuccessPreImage.java +++ b/src/main/java/org/stellar/sdk/xdr/InvokeHostFunctionSuccessPreImage.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -86,6 +89,32 @@ public boolean equals(Object object) { && Arrays.equals(this.events, other.events); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static InvokeHostFunctionSuccessPreImage fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static InvokeHostFunctionSuccessPreImage fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCVal returnValue; private ContractEvent[] events; diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerBounds.java b/src/main/java/org/stellar/sdk/xdr/LedgerBounds.java index a2e75d0fe..596b79023 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerBounds.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerBounds.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.maxLedger, other.maxLedger); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerBounds fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerBounds fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 minLedger; private Uint32 maxLedger; diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerCloseMeta.java b/src/main/java/org/stellar/sdk/xdr/LedgerCloseMeta.java index 63ef3ced1..ea5942334 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerCloseMeta.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerCloseMeta.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -157,4 +160,30 @@ public boolean equals(Object object) { && Objects.equal(this.v2, other.v2) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerCloseMeta fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerCloseMeta fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV0.java b/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV0.java index 4ddb87a9b..5a8d90e96 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV0.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -154,6 +157,32 @@ public boolean equals(Object object) { && Arrays.equals(this.scpInfo, other.scpInfo); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerCloseMetaV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerCloseMetaV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private LedgerHeaderHistoryEntry ledgerHeader; private TransactionSet txSet; diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV1.java b/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV1.java index 7c286efef..727aad9c7 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV1.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV1.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -154,6 +157,32 @@ public boolean equals(Object object) { && Arrays.equals(this.scpInfo, other.scpInfo); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerCloseMetaV1 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerCloseMetaV1 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private LedgerHeaderHistoryEntry ledgerHeader; private GeneralizedTransactionSet txSet; diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV2.java b/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV2.java index b056cb34c..ee92e31a2 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV2.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerCloseMetaV2.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -245,6 +248,32 @@ public boolean equals(Object object) { && Arrays.equals(this.evictedPersistentLedgerEntries, other.evictedPersistentLedgerEntries); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerCloseMetaV2 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerCloseMetaV2 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ExtensionPoint ext; private LedgerHeaderHistoryEntry ledgerHeader; diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerCloseValueSignature.java b/src/main/java/org/stellar/sdk/xdr/LedgerCloseValueSignature.java index 5d928167d..f834aff58 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerCloseValueSignature.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerCloseValueSignature.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -74,6 +77,32 @@ public boolean equals(Object object) { && Objects.equal(this.signature, other.signature); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerCloseValueSignature fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerCloseValueSignature fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private NodeID nodeID; private Signature signature; diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerEntry.java b/src/main/java/org/stellar/sdk/xdr/LedgerEntry.java index a12a5d356..574c3bdcd 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -118,6 +121,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 lastModifiedLedgerSeq; private LedgerEntryData data; @@ -147,7 +176,7 @@ public LedgerEntry build() { } } - public static class LedgerEntryData { + public static class LedgerEntryData implements XdrElement { public LedgerEntryData() {} LedgerEntryType type; @@ -437,9 +466,35 @@ public boolean equals(Object object) { && Objects.equal(this.configSetting, other.configSetting) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerEntryData fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerEntryData fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } - public static class LedgerEntryExt { + public static class LedgerEntryExt implements XdrElement { public LedgerEntryExt() {} Integer v; @@ -530,5 +585,31 @@ public boolean equals(Object object) { LedgerEntryExt other = (LedgerEntryExt) object; return Objects.equal(this.v1, other.v1) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerEntryExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerEntryExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerEntryChange.java b/src/main/java/org/stellar/sdk/xdr/LedgerEntryChange.java index 0893e8f8c..cda0a7137 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerEntryChange.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerEntryChange.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -183,4 +186,30 @@ public boolean equals(Object object) { && Objects.equal(this.state, other.state) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerEntryChange fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerEntryChange fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerEntryChangeType.java b/src/main/java/org/stellar/sdk/xdr/LedgerEntryChangeType.java index 262e2b569..170bbb957 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerEntryChangeType.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerEntryChangeType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -58,4 +61,30 @@ public static void encode(XdrDataOutputStream stream, LedgerEntryChangeType valu public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerEntryChangeType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerEntryChangeType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerEntryChanges.java b/src/main/java/org/stellar/sdk/xdr/LedgerEntryChanges.java index 4f25eaedb..395b6d3cd 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerEntryChanges.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerEntryChanges.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -67,4 +70,30 @@ public boolean equals(Object object) { LedgerEntryChanges other = (LedgerEntryChanges) object; return Arrays.equals(this.LedgerEntryChanges, other.LedgerEntryChanges); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerEntryChanges fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerEntryChanges fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerEntryExtensionV1.java b/src/main/java/org/stellar/sdk/xdr/LedgerEntryExtensionV1.java index 018739ddf..f0cdf88f3 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerEntryExtensionV1.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerEntryExtensionV1.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -80,6 +83,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerEntryExtensionV1 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerEntryExtensionV1 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SponsorshipDescriptor sponsoringID; private LedgerEntryExtensionV1Ext ext; @@ -102,7 +131,7 @@ public LedgerEntryExtensionV1 build() { } } - public static class LedgerEntryExtensionV1Ext { + public static class LedgerEntryExtensionV1Ext implements XdrElement { public LedgerEntryExtensionV1Ext() {} Integer v; @@ -171,5 +200,31 @@ public boolean equals(Object object) { LedgerEntryExtensionV1Ext other = (LedgerEntryExtensionV1Ext) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerEntryExtensionV1Ext fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerEntryExtensionV1Ext fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerEntryType.java b/src/main/java/org/stellar/sdk/xdr/LedgerEntryType.java index 2fc3d2e93..fb93bcda4 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerEntryType.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerEntryType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -77,4 +80,30 @@ public static void encode(XdrDataOutputStream stream, LedgerEntryType value) thr public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerEntryType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerEntryType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerFootprint.java b/src/main/java/org/stellar/sdk/xdr/LedgerFootprint.java index bc17b02a0..2800c971b 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerFootprint.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerFootprint.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -90,6 +93,32 @@ public boolean equals(Object object) { && Arrays.equals(this.readWrite, other.readWrite); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerFootprint fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerFootprint fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private LedgerKey[] readOnly; private LedgerKey[] readWrite; diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerHeader.java b/src/main/java/org/stellar/sdk/xdr/LedgerHeader.java index 1993ba949..aff6b0089 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerHeader.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerHeader.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -299,6 +302,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerHeader fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerHeader fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 ledgerVersion; private Hash previousLedgerHash; @@ -412,7 +441,7 @@ public LedgerHeader build() { } } - public static class LedgerHeaderExt { + public static class LedgerHeaderExt implements XdrElement { public LedgerHeaderExt() {} Integer v; @@ -503,5 +532,31 @@ public boolean equals(Object object) { LedgerHeaderExt other = (LedgerHeaderExt) object; return Objects.equal(this.v1, other.v1) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerHeaderExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerHeaderExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerHeaderExtensionV1.java b/src/main/java/org/stellar/sdk/xdr/LedgerHeaderExtensionV1.java index dd8750822..5ed005ab8 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerHeaderExtensionV1.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerHeaderExtensionV1.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -79,6 +82,32 @@ public boolean equals(Object object) { return Objects.equal(this.flags, other.flags) && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerHeaderExtensionV1 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerHeaderExtensionV1 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 flags; private LedgerHeaderExtensionV1Ext ext; @@ -101,7 +130,7 @@ public LedgerHeaderExtensionV1 build() { } } - public static class LedgerHeaderExtensionV1Ext { + public static class LedgerHeaderExtensionV1Ext implements XdrElement { public LedgerHeaderExtensionV1Ext() {} Integer v; @@ -171,5 +200,31 @@ public boolean equals(Object object) { LedgerHeaderExtensionV1Ext other = (LedgerHeaderExtensionV1Ext) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerHeaderExtensionV1Ext fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerHeaderExtensionV1Ext fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerHeaderFlags.java b/src/main/java/org/stellar/sdk/xdr/LedgerHeaderFlags.java index 6f459b35f..85988d04b 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerHeaderFlags.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerHeaderFlags.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -70,4 +73,30 @@ public static void encode(XdrDataOutputStream stream, LedgerHeaderFlags value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerHeaderFlags fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerHeaderFlags fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerHeaderHistoryEntry.java b/src/main/java/org/stellar/sdk/xdr/LedgerHeaderHistoryEntry.java index e37f25504..82bbe293b 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerHeaderHistoryEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerHeaderHistoryEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -95,6 +98,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerHeaderHistoryEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerHeaderHistoryEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash hash; private LedgerHeader header; @@ -124,7 +153,7 @@ public LedgerHeaderHistoryEntry build() { } } - public static class LedgerHeaderHistoryEntryExt { + public static class LedgerHeaderHistoryEntryExt implements XdrElement { public LedgerHeaderHistoryEntryExt() {} Integer v; @@ -194,5 +223,31 @@ public boolean equals(Object object) { LedgerHeaderHistoryEntryExt other = (LedgerHeaderHistoryEntryExt) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerHeaderHistoryEntryExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerHeaderHistoryEntryExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerKey.java b/src/main/java/org/stellar/sdk/xdr/LedgerKey.java index 5b2ca4aca..ef527d173 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerKey.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerKey.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -363,7 +366,33 @@ public boolean equals(Object object) { && Objects.equal(this.type, other.type); } - public static class LedgerKeyAccount { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerKey fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerKey fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class LedgerKeyAccount implements XdrElement { public LedgerKeyAccount() {} private AccountID accountID; @@ -406,6 +435,32 @@ public boolean equals(Object object) { return Objects.equal(this.accountID, other.accountID); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerKeyAccount fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerKeyAccount fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID accountID; @@ -422,7 +477,7 @@ public LedgerKeyAccount build() { } } - public static class LedgerKeyTrustLine { + public static class LedgerKeyTrustLine implements XdrElement { public LedgerKeyTrustLine() {} private AccountID accountID; @@ -479,6 +534,32 @@ public boolean equals(Object object) { && Objects.equal(this.asset, other.asset); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerKeyTrustLine fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerKeyTrustLine fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID accountID; private TrustLineAsset asset; @@ -502,7 +583,7 @@ public LedgerKeyTrustLine build() { } } - public static class LedgerKeyOffer { + public static class LedgerKeyOffer implements XdrElement { public LedgerKeyOffer() {} private AccountID sellerID; @@ -558,6 +639,32 @@ public boolean equals(Object object) { && Objects.equal(this.offerID, other.offerID); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerKeyOffer fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerKeyOffer fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID sellerID; private Int64 offerID; @@ -581,7 +688,7 @@ public LedgerKeyOffer build() { } } - public static class LedgerKeyData { + public static class LedgerKeyData implements XdrElement { public LedgerKeyData() {} private AccountID accountID; @@ -637,6 +744,32 @@ public boolean equals(Object object) { && Objects.equal(this.dataName, other.dataName); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerKeyData fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerKeyData fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID accountID; private String64 dataName; @@ -660,7 +793,7 @@ public LedgerKeyData build() { } } - public static class LedgerKeyClaimableBalance { + public static class LedgerKeyClaimableBalance implements XdrElement { public LedgerKeyClaimableBalance() {} private ClaimableBalanceID balanceID; @@ -704,6 +837,32 @@ public boolean equals(Object object) { return Objects.equal(this.balanceID, other.balanceID); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerKeyClaimableBalance fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerKeyClaimableBalance fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ClaimableBalanceID balanceID; @@ -720,7 +879,7 @@ public LedgerKeyClaimableBalance build() { } } - public static class LedgerKeyLiquidityPool { + public static class LedgerKeyLiquidityPool implements XdrElement { public LedgerKeyLiquidityPool() {} private PoolID liquidityPoolID; @@ -764,6 +923,32 @@ public boolean equals(Object object) { return Objects.equal(this.liquidityPoolID, other.liquidityPoolID); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerKeyLiquidityPool fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerKeyLiquidityPool fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private PoolID liquidityPoolID; @@ -780,7 +965,7 @@ public LedgerKeyLiquidityPool build() { } } - public static class LedgerKeyContractData { + public static class LedgerKeyContractData implements XdrElement { public LedgerKeyContractData() {} private SCAddress contract; @@ -863,6 +1048,32 @@ public boolean equals(Object object) { && Objects.equal(this.bodyType, other.bodyType); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerKeyContractData fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerKeyContractData fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCAddress contract; private SCVal key; @@ -900,7 +1111,7 @@ public LedgerKeyContractData build() { } } - public static class LedgerKeyContractCode { + public static class LedgerKeyContractCode implements XdrElement { public LedgerKeyContractCode() {} private Hash hash; @@ -956,6 +1167,32 @@ public boolean equals(Object object) { return Objects.equal(this.hash, other.hash) && Objects.equal(this.bodyType, other.bodyType); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerKeyContractCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerKeyContractCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash hash; private ContractEntryBodyType bodyType; @@ -979,7 +1216,7 @@ public LedgerKeyContractCode build() { } } - public static class LedgerKeyConfigSetting { + public static class LedgerKeyConfigSetting implements XdrElement { public LedgerKeyConfigSetting() {} private ConfigSettingID configSettingID; @@ -1023,6 +1260,32 @@ public boolean equals(Object object) { return Objects.equal(this.configSettingID, other.configSettingID); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerKeyConfigSetting fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerKeyConfigSetting fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ConfigSettingID configSettingID; diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerSCPMessages.java b/src/main/java/org/stellar/sdk/xdr/LedgerSCPMessages.java index 4a99ba955..015d56615 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerSCPMessages.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerSCPMessages.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -82,6 +85,32 @@ public boolean equals(Object object) { && Arrays.equals(this.messages, other.messages); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerSCPMessages fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerSCPMessages fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 ledgerSeq; private SCPEnvelope[] messages; diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerUpgrade.java b/src/main/java/org/stellar/sdk/xdr/LedgerUpgrade.java index 72ae50ad8..995b36531 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerUpgrade.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerUpgrade.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -242,4 +245,30 @@ public boolean equals(Object object) { && Objects.equal(this.newConfig, other.newConfig) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerUpgrade fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerUpgrade fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LedgerUpgradeType.java b/src/main/java/org/stellar/sdk/xdr/LedgerUpgradeType.java index d728ec31f..47876e276 100644 --- a/src/main/java/org/stellar/sdk/xdr/LedgerUpgradeType.java +++ b/src/main/java/org/stellar/sdk/xdr/LedgerUpgradeType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -66,4 +69,30 @@ public static void encode(XdrDataOutputStream stream, LedgerUpgradeType value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LedgerUpgradeType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LedgerUpgradeType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Liabilities.java b/src/main/java/org/stellar/sdk/xdr/Liabilities.java index 22c9e554a..b1d0b0d5a 100644 --- a/src/main/java/org/stellar/sdk/xdr/Liabilities.java +++ b/src/main/java/org/stellar/sdk/xdr/Liabilities.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -72,6 +75,32 @@ public boolean equals(Object object) { return Objects.equal(this.buying, other.buying) && Objects.equal(this.selling, other.selling); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Liabilities fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Liabilities fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Int64 buying; private Int64 selling; diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolConstantProductParameters.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolConstantProductParameters.java index 1749d58be..387e18e69 100644 --- a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolConstantProductParameters.java +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolConstantProductParameters.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -91,6 +94,34 @@ public boolean equals(Object object) { && Objects.equal(this.fee, other.fee); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolConstantProductParameters fromXdrBase64(String xdr) + throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolConstantProductParameters fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Asset assetA; private Asset assetB; diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositOp.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositOp.java index f76f98752..a059f37b7 100644 --- a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositOp.java +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -117,6 +120,32 @@ public boolean equals(Object object) { && Objects.equal(this.maxPrice, other.maxPrice); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolDepositOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolDepositOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private PoolID liquidityPoolID; private Int64 maxAmountA; diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResult.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResult.java index 0abc15f7b..cf555d95f 100644 --- a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResult.java +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -110,4 +113,30 @@ public boolean equals(Object object) { LiquidityPoolDepositResult other = (LiquidityPoolDepositResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolDepositResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolDepositResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResultCode.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResultCode.java index d24a52369..d9b5afe02 100644 --- a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolDepositResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -82,4 +85,30 @@ public static void encode(XdrDataOutputStream stream, LiquidityPoolDepositResult public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolDepositResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolDepositResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolEntry.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolEntry.java index 77c7fdfb1..ec5a2003d 100644 --- a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -88,6 +91,32 @@ public boolean equals(Object object) { && Objects.equal(this.body, other.body); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private PoolID liquidityPoolID; private LiquidityPoolEntryBody body; @@ -110,7 +139,7 @@ public LiquidityPoolEntry build() { } } - public static class LiquidityPoolEntryBody { + public static class LiquidityPoolEntryBody implements XdrElement { public LiquidityPoolEntryBody() {} LiquidityPoolType type; @@ -202,7 +231,33 @@ public boolean equals(Object object) { && Objects.equal(this.type, other.type); } - public static class LiquidityPoolEntryConstantProduct { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolEntryBody fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolEntryBody fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class LiquidityPoolEntryConstantProduct implements XdrElement { public LiquidityPoolEntryConstantProduct() {} private LiquidityPoolConstantProductParameters params; @@ -308,6 +363,33 @@ public boolean equals(Object object) { && Objects.equal(this.poolSharesTrustLineCount, other.poolSharesTrustLineCount); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolEntryConstantProduct fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolEntryConstantProduct fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private LiquidityPoolConstantProductParameters params; private Int64 reserveA; diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolParameters.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolParameters.java index 4fdc23e2b..5b554bfdc 100644 --- a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolParameters.java +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolParameters.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -108,4 +111,30 @@ public boolean equals(Object object) { return Objects.equal(this.constantProduct, other.constantProduct) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolParameters fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolParameters fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolType.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolType.java index e7bf8e6cd..8c326247b 100644 --- a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolType.java +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -46,4 +49,30 @@ public static void encode(XdrDataOutputStream stream, LiquidityPoolType value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawOp.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawOp.java index 31881dd76..1a1f2802a 100644 --- a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawOp.java +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -102,6 +105,32 @@ public boolean equals(Object object) { && Objects.equal(this.minAmountB, other.minAmountB); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolWithdrawOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolWithdrawOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private PoolID liquidityPoolID; private Int64 amount; diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResult.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResult.java index c42ee7e58..5adf72fe6 100644 --- a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResult.java +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -105,4 +108,30 @@ public boolean equals(Object object) { LiquidityPoolWithdrawResult other = (LiquidityPoolWithdrawResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolWithdrawResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolWithdrawResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResultCode.java b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResultCode.java index a6ee0eb29..e99125470 100644 --- a/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/LiquidityPoolWithdrawResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,4 +76,30 @@ public static void encode(XdrDataOutputStream stream, LiquidityPoolWithdrawResul public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static LiquidityPoolWithdrawResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static LiquidityPoolWithdrawResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferOp.java b/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferOp.java index 8a1067a10..2a879abcf 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferOp.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -118,6 +121,32 @@ public boolean equals(Object object) { && Objects.equal(this.offerID, other.offerID); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageBuyOfferOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageBuyOfferOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Asset selling; private Asset buying; diff --git a/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferResult.java b/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferResult.java index a54a14a19..4e47b8dea 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferResult.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -144,4 +147,30 @@ public boolean equals(Object object) { ManageBuyOfferResult other = (ManageBuyOfferResult) object; return Objects.equal(this.success, other.success) && Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageBuyOfferResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageBuyOfferResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferResultCode.java b/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferResultCode.java index f9f2af825..48319a324 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageBuyOfferResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -101,4 +104,30 @@ public static void encode(XdrDataOutputStream stream, ManageBuyOfferResultCode v public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageBuyOfferResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageBuyOfferResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ManageDataOp.java b/src/main/java/org/stellar/sdk/xdr/ManageDataOp.java index ab7fe52e6..cac6b2772 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageDataOp.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageDataOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -81,6 +84,32 @@ public boolean equals(Object object) { && Objects.equal(this.dataValue, other.dataValue); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageDataOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageDataOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private String64 dataName; private DataValue dataValue; diff --git a/src/main/java/org/stellar/sdk/xdr/ManageDataResult.java b/src/main/java/org/stellar/sdk/xdr/ManageDataResult.java index e126cf1d4..9a801aebb 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageDataResult.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageDataResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -100,4 +103,30 @@ public boolean equals(Object object) { ManageDataResult other = (ManageDataResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageDataResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageDataResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ManageDataResultCode.java b/src/main/java/org/stellar/sdk/xdr/ManageDataResultCode.java index 96bdf6562..db63e205a 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageDataResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageDataResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -66,4 +69,30 @@ public static void encode(XdrDataOutputStream stream, ManageDataResultCode value public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageDataResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageDataResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ManageOfferEffect.java b/src/main/java/org/stellar/sdk/xdr/ManageOfferEffect.java index ce9a70558..e88d7ef17 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageOfferEffect.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageOfferEffect.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -54,4 +57,30 @@ public static void encode(XdrDataOutputStream stream, ManageOfferEffect value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageOfferEffect fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageOfferEffect fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ManageOfferSuccessResult.java b/src/main/java/org/stellar/sdk/xdr/ManageOfferSuccessResult.java index ace941539..8b649c160 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageOfferSuccessResult.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageOfferSuccessResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -93,6 +96,32 @@ public boolean equals(Object object) { && Objects.equal(this.offer, other.offer); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageOfferSuccessResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageOfferSuccessResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ClaimAtom[] offersClaimed; private ManageOfferSuccessResultOffer offer; @@ -115,7 +144,7 @@ public ManageOfferSuccessResult build() { } } - public static class ManageOfferSuccessResultOffer { + public static class ManageOfferSuccessResultOffer implements XdrElement { public ManageOfferSuccessResultOffer() {} ManageOfferEffect effect; @@ -212,5 +241,31 @@ public boolean equals(Object object) { ManageOfferSuccessResultOffer other = (ManageOfferSuccessResultOffer) object; return Objects.equal(this.offer, other.offer) && Objects.equal(this.effect, other.effect); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageOfferSuccessResultOffer fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageOfferSuccessResultOffer fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/ManageSellOfferOp.java b/src/main/java/org/stellar/sdk/xdr/ManageSellOfferOp.java index d5c46e8aa..b802452ae 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageSellOfferOp.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageSellOfferOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -117,6 +120,32 @@ public boolean equals(Object object) { && Objects.equal(this.offerID, other.offerID); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageSellOfferOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageSellOfferOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Asset selling; private Asset buying; diff --git a/src/main/java/org/stellar/sdk/xdr/ManageSellOfferResult.java b/src/main/java/org/stellar/sdk/xdr/ManageSellOfferResult.java index 4a9f839a4..38f812312 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageSellOfferResult.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageSellOfferResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -144,4 +147,30 @@ public boolean equals(Object object) { ManageSellOfferResult other = (ManageSellOfferResult) object; return Objects.equal(this.success, other.success) && Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageSellOfferResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageSellOfferResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/ManageSellOfferResultCode.java b/src/main/java/org/stellar/sdk/xdr/ManageSellOfferResultCode.java index 6bc21bc13..97faa4815 100644 --- a/src/main/java/org/stellar/sdk/xdr/ManageSellOfferResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/ManageSellOfferResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -104,4 +107,30 @@ public static void encode(XdrDataOutputStream stream, ManageSellOfferResultCode public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ManageSellOfferResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ManageSellOfferResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Memo.java b/src/main/java/org/stellar/sdk/xdr/Memo.java index e34cd5030..264e56d7a 100644 --- a/src/main/java/org/stellar/sdk/xdr/Memo.java +++ b/src/main/java/org/stellar/sdk/xdr/Memo.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -188,4 +191,30 @@ public boolean equals(Object object) { && Objects.equal(this.retHash, other.retHash) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Memo fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Memo fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/MemoType.java b/src/main/java/org/stellar/sdk/xdr/MemoType.java index 739f839ba..f1c47b717 100644 --- a/src/main/java/org/stellar/sdk/xdr/MemoType.java +++ b/src/main/java/org/stellar/sdk/xdr/MemoType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -61,4 +64,30 @@ public static void encode(XdrDataOutputStream stream, MemoType value) throws IOE public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static MemoType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static MemoType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/MessageType.java b/src/main/java/org/stellar/sdk/xdr/MessageType.java index 1a1b0113f..fb1d1b31a 100644 --- a/src/main/java/org/stellar/sdk/xdr/MessageType.java +++ b/src/main/java/org/stellar/sdk/xdr/MessageType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -131,4 +134,30 @@ public static void encode(XdrDataOutputStream stream, MessageType value) throws public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static MessageType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static MessageType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/MuxedAccount.java b/src/main/java/org/stellar/sdk/xdr/MuxedAccount.java index 78a5643f4..94a0162a4 100644 --- a/src/main/java/org/stellar/sdk/xdr/MuxedAccount.java +++ b/src/main/java/org/stellar/sdk/xdr/MuxedAccount.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -136,7 +139,33 @@ public boolean equals(Object object) { && Objects.equal(this.type, other.type); } - public static class MuxedAccountMed25519 { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static MuxedAccount fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static MuxedAccount fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class MuxedAccountMed25519 implements XdrElement { public MuxedAccountMed25519() {} private Uint64 id; @@ -192,6 +221,32 @@ public boolean equals(Object object) { return Objects.equal(this.id, other.id) && Objects.equal(this.ed25519, other.ed25519); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static MuxedAccountMed25519 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static MuxedAccountMed25519 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint64 id; private Uint256 ed25519; diff --git a/src/main/java/org/stellar/sdk/xdr/NodeID.java b/src/main/java/org/stellar/sdk/xdr/NodeID.java index ccd5ee635..c8d7f9afd 100644 --- a/src/main/java/org/stellar/sdk/xdr/NodeID.java +++ b/src/main/java/org/stellar/sdk/xdr/NodeID.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -58,4 +61,30 @@ public boolean equals(Object object) { NodeID other = (NodeID) object; return Objects.equal(this.NodeID, other.NodeID); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static NodeID fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static NodeID fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/OfferEntry.java b/src/main/java/org/stellar/sdk/xdr/OfferEntry.java index 0bb10895b..d4415109e 100644 --- a/src/main/java/org/stellar/sdk/xdr/OfferEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/OfferEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -178,6 +181,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static OfferEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static OfferEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID sellerID; private Int64 offerID; @@ -242,7 +271,7 @@ public OfferEntry build() { } } - public static class OfferEntryExt { + public static class OfferEntryExt implements XdrElement { public OfferEntryExt() {} Integer v; @@ -310,5 +339,31 @@ public boolean equals(Object object) { OfferEntryExt other = (OfferEntryExt) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static OfferEntryExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static OfferEntryExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/OfferEntryFlags.java b/src/main/java/org/stellar/sdk/xdr/OfferEntryFlags.java index 0c5bedc17..82721b7b1 100644 --- a/src/main/java/org/stellar/sdk/xdr/OfferEntryFlags.java +++ b/src/main/java/org/stellar/sdk/xdr/OfferEntryFlags.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -47,4 +50,30 @@ public static void encode(XdrDataOutputStream stream, OfferEntryFlags value) thr public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static OfferEntryFlags fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static OfferEntryFlags fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Operation.java b/src/main/java/org/stellar/sdk/xdr/Operation.java index eb44510e7..1bf37c92c 100644 --- a/src/main/java/org/stellar/sdk/xdr/Operation.java +++ b/src/main/java/org/stellar/sdk/xdr/Operation.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -142,6 +145,32 @@ public boolean equals(Object object) { && Objects.equal(this.body, other.body); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Operation fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Operation fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private MuxedAccount sourceAccount; private OperationBody body; @@ -164,7 +193,7 @@ public Operation build() { } } - public static class OperationBody { + public static class OperationBody implements XdrElement { public OperationBody() {} OperationType type; @@ -873,5 +902,31 @@ public boolean equals(Object object) { && Objects.equal(this.restoreFootprintOp, other.restoreFootprintOp) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static OperationBody fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static OperationBody fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/OperationMeta.java b/src/main/java/org/stellar/sdk/xdr/OperationMeta.java index 7ee0e0cc0..1390366f3 100644 --- a/src/main/java/org/stellar/sdk/xdr/OperationMeta.java +++ b/src/main/java/org/stellar/sdk/xdr/OperationMeta.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,6 +62,32 @@ public boolean equals(Object object) { return Objects.equal(this.changes, other.changes); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static OperationMeta fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static OperationMeta fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private LedgerEntryChanges changes; diff --git a/src/main/java/org/stellar/sdk/xdr/OperationResult.java b/src/main/java/org/stellar/sdk/xdr/OperationResult.java index 3401ae422..383079877 100644 --- a/src/main/java/org/stellar/sdk/xdr/OperationResult.java +++ b/src/main/java/org/stellar/sdk/xdr/OperationResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -183,7 +186,33 @@ public boolean equals(Object object) { return Objects.equal(this.tr, other.tr) && Objects.equal(this.code, other.code); } - public static class OperationResultTr { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static OperationResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static OperationResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class OperationResultTr implements XdrElement { public OperationResultTr() {} OperationType type; @@ -962,5 +991,31 @@ public boolean equals(Object object) { && Objects.equal(this.restoreFootprintResult, other.restoreFootprintResult) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static OperationResultTr fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static OperationResultTr fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/OperationResultCode.java b/src/main/java/org/stellar/sdk/xdr/OperationResultCode.java index 6f82a29a1..ebf4a5bcc 100644 --- a/src/main/java/org/stellar/sdk/xdr/OperationResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/OperationResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -71,4 +74,30 @@ public static void encode(XdrDataOutputStream stream, OperationResultCode value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static OperationResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static OperationResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/OperationType.java b/src/main/java/org/stellar/sdk/xdr/OperationType.java index 0acb5fcc1..c4c6d391e 100644 --- a/src/main/java/org/stellar/sdk/xdr/OperationType.java +++ b/src/main/java/org/stellar/sdk/xdr/OperationType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -149,4 +152,30 @@ public static void encode(XdrDataOutputStream stream, OperationType value) throw public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static OperationType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static OperationType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveOp.java b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveOp.java index 86ae96832..869a5202d 100644 --- a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveOp.java +++ b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -149,6 +152,32 @@ public boolean equals(Object object) { && Arrays.equals(this.path, other.path); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PathPaymentStrictReceiveOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PathPaymentStrictReceiveOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Asset sendAsset; private Int64 sendMax; diff --git a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResult.java b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResult.java index 331b8a79f..85caab2ac 100644 --- a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResult.java +++ b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -184,7 +187,33 @@ public boolean equals(Object object) { && Objects.equal(this.code, other.code); } - public static class PathPaymentStrictReceiveResultSuccess { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PathPaymentStrictReceiveResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PathPaymentStrictReceiveResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class PathPaymentStrictReceiveResultSuccess implements XdrElement { public PathPaymentStrictReceiveResultSuccess() {} private ClaimAtom[] offers; @@ -251,6 +280,34 @@ public boolean equals(Object object) { return Arrays.equals(this.offers, other.offers) && Objects.equal(this.last, other.last); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PathPaymentStrictReceiveResultSuccess fromXdrBase64(String xdr) + throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PathPaymentStrictReceiveResultSuccess fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ClaimAtom[] offers; private SimplePaymentResult last; diff --git a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResultCode.java b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResultCode.java index 00b81e661..1e30560e7 100644 --- a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictReceiveResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -107,4 +110,30 @@ public static void encode(XdrDataOutputStream stream, PathPaymentStrictReceiveRe public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PathPaymentStrictReceiveResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PathPaymentStrictReceiveResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendOp.java b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendOp.java index a8bcb85ee..109b4cf11 100644 --- a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendOp.java +++ b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -149,6 +152,32 @@ public boolean equals(Object object) { && Arrays.equals(this.path, other.path); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PathPaymentStrictSendOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PathPaymentStrictSendOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Asset sendAsset; private Int64 sendAmount; diff --git a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResult.java b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResult.java index 30411b068..d8300ef8c 100644 --- a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResult.java +++ b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -180,7 +183,33 @@ public boolean equals(Object object) { && Objects.equal(this.code, other.code); } - public static class PathPaymentStrictSendResultSuccess { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PathPaymentStrictSendResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PathPaymentStrictSendResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class PathPaymentStrictSendResultSuccess implements XdrElement { public PathPaymentStrictSendResultSuccess() {} private ClaimAtom[] offers; @@ -247,6 +276,33 @@ public boolean equals(Object object) { return Arrays.equals(this.offers, other.offers) && Objects.equal(this.last, other.last); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PathPaymentStrictSendResultSuccess fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PathPaymentStrictSendResultSuccess fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ClaimAtom[] offers; private SimplePaymentResult last; diff --git a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResultCode.java b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResultCode.java index 18b092988..fef80eff2 100644 --- a/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/PathPaymentStrictSendResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -106,4 +109,30 @@ public static void encode(XdrDataOutputStream stream, PathPaymentStrictSendResul public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PathPaymentStrictSendResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PathPaymentStrictSendResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/PaymentOp.java b/src/main/java/org/stellar/sdk/xdr/PaymentOp.java index a1f8f3166..4e159bf9f 100644 --- a/src/main/java/org/stellar/sdk/xdr/PaymentOp.java +++ b/src/main/java/org/stellar/sdk/xdr/PaymentOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -87,6 +90,32 @@ public boolean equals(Object object) { && Objects.equal(this.amount, other.amount); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PaymentOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PaymentOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private MuxedAccount destination; private Asset asset; diff --git a/src/main/java/org/stellar/sdk/xdr/PaymentResult.java b/src/main/java/org/stellar/sdk/xdr/PaymentResult.java index 42893b288..879831a58 100644 --- a/src/main/java/org/stellar/sdk/xdr/PaymentResult.java +++ b/src/main/java/org/stellar/sdk/xdr/PaymentResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -115,4 +118,30 @@ public boolean equals(Object object) { PaymentResult other = (PaymentResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PaymentResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PaymentResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/PaymentResultCode.java b/src/main/java/org/stellar/sdk/xdr/PaymentResultCode.java index 97c01f829..aa8b3e88b 100644 --- a/src/main/java/org/stellar/sdk/xdr/PaymentResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/PaymentResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -85,4 +88,30 @@ public static void encode(XdrDataOutputStream stream, PaymentResultCode value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PaymentResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PaymentResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/PeerAddress.java b/src/main/java/org/stellar/sdk/xdr/PeerAddress.java index ca8f24eac..59171a0dd 100644 --- a/src/main/java/org/stellar/sdk/xdr/PeerAddress.java +++ b/src/main/java/org/stellar/sdk/xdr/PeerAddress.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -95,6 +98,32 @@ public boolean equals(Object object) { && Objects.equal(this.numFailures, other.numFailures); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PeerAddress fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PeerAddress fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private PeerAddressIp ip; private Uint32 port; @@ -124,7 +153,7 @@ public PeerAddress build() { } } - public static class PeerAddressIp { + public static class PeerAddressIp implements XdrElement { public PeerAddressIp() {} IPAddrType type; @@ -242,5 +271,31 @@ public boolean equals(Object object) { && Arrays.equals(this.ipv6, other.ipv6) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PeerAddressIp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PeerAddressIp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/PeerStatList.java b/src/main/java/org/stellar/sdk/xdr/PeerStatList.java index 37b0c989e..365b758a5 100644 --- a/src/main/java/org/stellar/sdk/xdr/PeerStatList.java +++ b/src/main/java/org/stellar/sdk/xdr/PeerStatList.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -67,4 +70,30 @@ public boolean equals(Object object) { PeerStatList other = (PeerStatList) object; return Arrays.equals(this.PeerStatList, other.PeerStatList); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PeerStatList fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PeerStatList fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/PeerStats.java b/src/main/java/org/stellar/sdk/xdr/PeerStats.java index 71b6a49be..993a13257 100644 --- a/src/main/java/org/stellar/sdk/xdr/PeerStats.java +++ b/src/main/java/org/stellar/sdk/xdr/PeerStats.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -272,6 +275,32 @@ public boolean equals(Object object) { && Objects.equal(this.duplicateFetchMessageRecv, other.duplicateFetchMessageRecv); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PeerStats fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PeerStats fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private NodeID id; private XdrString versionStr; diff --git a/src/main/java/org/stellar/sdk/xdr/PersistedSCPState.java b/src/main/java/org/stellar/sdk/xdr/PersistedSCPState.java index 06fdf90ce..9e8ab197b 100644 --- a/src/main/java/org/stellar/sdk/xdr/PersistedSCPState.java +++ b/src/main/java/org/stellar/sdk/xdr/PersistedSCPState.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -131,4 +134,30 @@ public boolean equals(Object object) { && Objects.equal(this.v1, other.v1) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PersistedSCPState fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PersistedSCPState fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/PersistedSCPStateV0.java b/src/main/java/org/stellar/sdk/xdr/PersistedSCPStateV0.java index 307f3b206..e2a8592dc 100644 --- a/src/main/java/org/stellar/sdk/xdr/PersistedSCPStateV0.java +++ b/src/main/java/org/stellar/sdk/xdr/PersistedSCPStateV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -116,6 +119,32 @@ public boolean equals(Object object) { && Arrays.equals(this.txSets, other.txSets); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PersistedSCPStateV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PersistedSCPStateV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCPEnvelope[] scpEnvelopes; private SCPQuorumSet[] quorumSets; diff --git a/src/main/java/org/stellar/sdk/xdr/PersistedSCPStateV1.java b/src/main/java/org/stellar/sdk/xdr/PersistedSCPStateV1.java index 1414f2bf7..5ae64e598 100644 --- a/src/main/java/org/stellar/sdk/xdr/PersistedSCPStateV1.java +++ b/src/main/java/org/stellar/sdk/xdr/PersistedSCPStateV1.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -92,6 +95,32 @@ public boolean equals(Object object) { && Arrays.equals(this.quorumSets, other.quorumSets); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PersistedSCPStateV1 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PersistedSCPStateV1 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCPEnvelope[] scpEnvelopes; private SCPQuorumSet[] quorumSets; diff --git a/src/main/java/org/stellar/sdk/xdr/PoolID.java b/src/main/java/org/stellar/sdk/xdr/PoolID.java index 230f02888..c0457ace9 100644 --- a/src/main/java/org/stellar/sdk/xdr/PoolID.java +++ b/src/main/java/org/stellar/sdk/xdr/PoolID.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -58,4 +61,30 @@ public boolean equals(Object object) { PoolID other = (PoolID) object; return Objects.equal(this.PoolID, other.PoolID); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PoolID fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PoolID fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/PreconditionType.java b/src/main/java/org/stellar/sdk/xdr/PreconditionType.java index 4f1435880..353f87188 100644 --- a/src/main/java/org/stellar/sdk/xdr/PreconditionType.java +++ b/src/main/java/org/stellar/sdk/xdr/PreconditionType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -53,4 +56,30 @@ public static void encode(XdrDataOutputStream stream, PreconditionType value) th public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PreconditionType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PreconditionType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Preconditions.java b/src/main/java/org/stellar/sdk/xdr/Preconditions.java index fc34c61c0..587eab130 100644 --- a/src/main/java/org/stellar/sdk/xdr/Preconditions.java +++ b/src/main/java/org/stellar/sdk/xdr/Preconditions.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -137,4 +140,30 @@ public boolean equals(Object object) { && Objects.equal(this.v2, other.v2) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Preconditions fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Preconditions fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/PreconditionsV2.java b/src/main/java/org/stellar/sdk/xdr/PreconditionsV2.java index 500576d02..7f95d06e3 100644 --- a/src/main/java/org/stellar/sdk/xdr/PreconditionsV2.java +++ b/src/main/java/org/stellar/sdk/xdr/PreconditionsV2.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -191,6 +194,32 @@ public boolean equals(Object object) { && Arrays.equals(this.extraSigners, other.extraSigners); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PreconditionsV2 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PreconditionsV2 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private TimeBounds timeBounds; private LedgerBounds ledgerBounds; diff --git a/src/main/java/org/stellar/sdk/xdr/Price.java b/src/main/java/org/stellar/sdk/xdr/Price.java index 0d4794d85..a6831d043 100644 --- a/src/main/java/org/stellar/sdk/xdr/Price.java +++ b/src/main/java/org/stellar/sdk/xdr/Price.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -71,6 +74,32 @@ public boolean equals(Object object) { return Objects.equal(this.n, other.n) && Objects.equal(this.d, other.d); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Price fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Price fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Int32 n; private Int32 d; diff --git a/src/main/java/org/stellar/sdk/xdr/PublicKey.java b/src/main/java/org/stellar/sdk/xdr/PublicKey.java index cf6fd34f2..cfe9b4d70 100644 --- a/src/main/java/org/stellar/sdk/xdr/PublicKey.java +++ b/src/main/java/org/stellar/sdk/xdr/PublicKey.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -104,4 +107,30 @@ public boolean equals(Object object) { PublicKey other = (PublicKey) object; return Objects.equal(this.ed25519, other.ed25519) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PublicKey fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PublicKey fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/PublicKeyType.java b/src/main/java/org/stellar/sdk/xdr/PublicKeyType.java index 38655d863..9ce503ee7 100644 --- a/src/main/java/org/stellar/sdk/xdr/PublicKeyType.java +++ b/src/main/java/org/stellar/sdk/xdr/PublicKeyType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -45,4 +48,30 @@ public static void encode(XdrDataOutputStream stream, PublicKeyType value) throw public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static PublicKeyType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static PublicKeyType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/RestoreFootprintOp.java b/src/main/java/org/stellar/sdk/xdr/RestoreFootprintOp.java index 7a11e393b..b46ef9800 100644 --- a/src/main/java/org/stellar/sdk/xdr/RestoreFootprintOp.java +++ b/src/main/java/org/stellar/sdk/xdr/RestoreFootprintOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,6 +62,32 @@ public boolean equals(Object object) { return Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static RestoreFootprintOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static RestoreFootprintOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ExtensionPoint ext; diff --git a/src/main/java/org/stellar/sdk/xdr/RestoreFootprintResult.java b/src/main/java/org/stellar/sdk/xdr/RestoreFootprintResult.java index 1c0145f19..992cb6da2 100644 --- a/src/main/java/org/stellar/sdk/xdr/RestoreFootprintResult.java +++ b/src/main/java/org/stellar/sdk/xdr/RestoreFootprintResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -95,4 +98,30 @@ public boolean equals(Object object) { RestoreFootprintResult other = (RestoreFootprintResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static RestoreFootprintResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static RestoreFootprintResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/RestoreFootprintResultCode.java b/src/main/java/org/stellar/sdk/xdr/RestoreFootprintResultCode.java index a31823310..03005accb 100644 --- a/src/main/java/org/stellar/sdk/xdr/RestoreFootprintResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/RestoreFootprintResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -57,4 +60,30 @@ public static void encode(XdrDataOutputStream stream, RestoreFootprintResultCode public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static RestoreFootprintResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static RestoreFootprintResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipOp.java b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipOp.java index 6f315559d..9c626c763 100644 --- a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipOp.java +++ b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -137,7 +140,33 @@ public boolean equals(Object object) { && Objects.equal(this.type, other.type); } - public static class RevokeSponsorshipOpSigner { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static RevokeSponsorshipOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static RevokeSponsorshipOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class RevokeSponsorshipOpSigner implements XdrElement { public RevokeSponsorshipOpSigner() {} private AccountID accountID; @@ -194,6 +223,32 @@ public boolean equals(Object object) { && Objects.equal(this.signerKey, other.signerKey); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static RevokeSponsorshipOpSigner fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static RevokeSponsorshipOpSigner fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID accountID; private SignerKey signerKey; diff --git a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResult.java b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResult.java index 4ddc146cd..ad6aa5555 100644 --- a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResult.java +++ b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -104,4 +107,30 @@ public boolean equals(Object object) { RevokeSponsorshipResult other = (RevokeSponsorshipResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static RevokeSponsorshipResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static RevokeSponsorshipResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResultCode.java b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResultCode.java index 970066134..2f8ca595e 100644 --- a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -69,4 +72,30 @@ public static void encode(XdrDataOutputStream stream, RevokeSponsorshipResultCod public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static RevokeSponsorshipResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static RevokeSponsorshipResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipType.java b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipType.java index 7b3278b68..5b568419d 100644 --- a/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipType.java +++ b/src/main/java/org/stellar/sdk/xdr/RevokeSponsorshipType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -50,4 +53,30 @@ public static void encode(XdrDataOutputStream stream, RevokeSponsorshipType valu public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static RevokeSponsorshipType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static RevokeSponsorshipType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCAddress.java b/src/main/java/org/stellar/sdk/xdr/SCAddress.java index f07786859..e3217a128 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCAddress.java +++ b/src/main/java/org/stellar/sdk/xdr/SCAddress.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -131,4 +134,30 @@ public boolean equals(Object object) { && Objects.equal(this.contractId, other.contractId) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCAddress fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCAddress fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCAddressType.java b/src/main/java/org/stellar/sdk/xdr/SCAddressType.java index 06a646f17..f80ce3068 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCAddressType.java +++ b/src/main/java/org/stellar/sdk/xdr/SCAddressType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -49,4 +52,30 @@ public static void encode(XdrDataOutputStream stream, SCAddressType value) throw public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCAddressType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCAddressType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCBytes.java b/src/main/java/org/stellar/sdk/xdr/SCBytes.java index 26b4df89c..0b111ada5 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCBytes.java +++ b/src/main/java/org/stellar/sdk/xdr/SCBytes.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -62,4 +65,30 @@ public boolean equals(Object object) { SCBytes other = (SCBytes) object; return Arrays.equals(this.SCBytes, other.SCBytes); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCBytes fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCBytes fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCContractInstance.java b/src/main/java/org/stellar/sdk/xdr/SCContractInstance.java index c5cd2db3b..d9fe5b6e0 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCContractInstance.java +++ b/src/main/java/org/stellar/sdk/xdr/SCContractInstance.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -80,6 +83,32 @@ public boolean equals(Object object) { && Objects.equal(this.storage, other.storage); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCContractInstance fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCContractInstance fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ContractExecutable executable; private SCMap storage; diff --git a/src/main/java/org/stellar/sdk/xdr/SCEnvMetaEntry.java b/src/main/java/org/stellar/sdk/xdr/SCEnvMetaEntry.java index e31461699..64ac8f1c3 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCEnvMetaEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/SCEnvMetaEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -105,4 +108,30 @@ public boolean equals(Object object) { return Objects.equal(this.interfaceVersion, other.interfaceVersion) && Objects.equal(this.kind, other.kind); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCEnvMetaEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCEnvMetaEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCEnvMetaKind.java b/src/main/java/org/stellar/sdk/xdr/SCEnvMetaKind.java index 423f45e1f..97c82d4d7 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCEnvMetaKind.java +++ b/src/main/java/org/stellar/sdk/xdr/SCEnvMetaKind.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -45,4 +48,30 @@ public static void encode(XdrDataOutputStream stream, SCEnvMetaKind value) throw public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCEnvMetaKind fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCEnvMetaKind fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCError.java b/src/main/java/org/stellar/sdk/xdr/SCError.java index 80cb18b08..c41c9f840 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCError.java +++ b/src/main/java/org/stellar/sdk/xdr/SCError.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -71,6 +74,32 @@ public boolean equals(Object object) { return Objects.equal(this.type, other.type) && Objects.equal(this.code, other.code); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCError fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCError fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCErrorType type; private SCErrorCode code; diff --git a/src/main/java/org/stellar/sdk/xdr/SCErrorCode.java b/src/main/java/org/stellar/sdk/xdr/SCErrorCode.java index d5374df5e..635a68f20 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCErrorCode.java +++ b/src/main/java/org/stellar/sdk/xdr/SCErrorCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -81,4 +84,30 @@ public static void encode(XdrDataOutputStream stream, SCErrorCode value) throws public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCErrorCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCErrorCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCErrorType.java b/src/main/java/org/stellar/sdk/xdr/SCErrorType.java index a1cdd808d..8637ebee6 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCErrorType.java +++ b/src/main/java/org/stellar/sdk/xdr/SCErrorType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -81,4 +84,30 @@ public static void encode(XdrDataOutputStream stream, SCErrorType value) throws public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCErrorType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCErrorType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCMap.java b/src/main/java/org/stellar/sdk/xdr/SCMap.java index bc82a97ef..18579f452 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCMap.java +++ b/src/main/java/org/stellar/sdk/xdr/SCMap.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -66,4 +69,30 @@ public boolean equals(Object object) { SCMap other = (SCMap) object; return Arrays.equals(this.SCMap, other.SCMap); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCMap fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCMap fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCMapEntry.java b/src/main/java/org/stellar/sdk/xdr/SCMapEntry.java index 66c82b895..953813bf6 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCMapEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/SCMapEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -72,6 +75,32 @@ public boolean equals(Object object) { return Objects.equal(this.key, other.key) && Objects.equal(this.val, other.val); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCMapEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCMapEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCVal key; private SCVal val; diff --git a/src/main/java/org/stellar/sdk/xdr/SCMetaEntry.java b/src/main/java/org/stellar/sdk/xdr/SCMetaEntry.java index 2b344cdd5..66006bccf 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCMetaEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/SCMetaEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -104,4 +107,30 @@ public boolean equals(Object object) { SCMetaEntry other = (SCMetaEntry) object; return Objects.equal(this.v0, other.v0) && Objects.equal(this.kind, other.kind); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCMetaEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCMetaEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCMetaKind.java b/src/main/java/org/stellar/sdk/xdr/SCMetaKind.java index 80c2fe476..519e5c416 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCMetaKind.java +++ b/src/main/java/org/stellar/sdk/xdr/SCMetaKind.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -45,4 +48,30 @@ public static void encode(XdrDataOutputStream stream, SCMetaKind value) throws I public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCMetaKind fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCMetaKind fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCMetaV0.java b/src/main/java/org/stellar/sdk/xdr/SCMetaV0.java index 0cb552c5e..65a032f11 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCMetaV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCMetaV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -52,8 +55,8 @@ public void encode(XdrDataOutputStream stream) throws IOException { public static SCMetaV0 decode(XdrDataInputStream stream) throws IOException { SCMetaV0 decodedSCMetaV0 = new SCMetaV0(); - decodedSCMetaV0.key = XdrString.decode(stream, 2147483647); - decodedSCMetaV0.val = XdrString.decode(stream, 2147483647); + decodedSCMetaV0.key = XdrString.decode(stream, Integer.MAX_VALUE); + decodedSCMetaV0.val = XdrString.decode(stream, Integer.MAX_VALUE); return decodedSCMetaV0; } @@ -72,6 +75,32 @@ public boolean equals(Object object) { return Objects.equal(this.key, other.key) && Objects.equal(this.val, other.val); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCMetaV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCMetaV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString key; private XdrString val; diff --git a/src/main/java/org/stellar/sdk/xdr/SCNonceKey.java b/src/main/java/org/stellar/sdk/xdr/SCNonceKey.java index 3e888fa51..7033ae777 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCNonceKey.java +++ b/src/main/java/org/stellar/sdk/xdr/SCNonceKey.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -58,6 +61,32 @@ public boolean equals(Object object) { return Objects.equal(this.nonce, other.nonce); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCNonceKey fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCNonceKey fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Int64 nonce; diff --git a/src/main/java/org/stellar/sdk/xdr/SCPBallot.java b/src/main/java/org/stellar/sdk/xdr/SCPBallot.java index 2fdfce8ec..ecafbfbb8 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCPBallot.java +++ b/src/main/java/org/stellar/sdk/xdr/SCPBallot.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -72,6 +75,32 @@ public boolean equals(Object object) { return Objects.equal(this.counter, other.counter) && Objects.equal(this.value, other.value); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPBallot fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPBallot fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 counter; private Value value; diff --git a/src/main/java/org/stellar/sdk/xdr/SCPEnvelope.java b/src/main/java/org/stellar/sdk/xdr/SCPEnvelope.java index 7ff943118..ba74c4a19 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCPEnvelope.java +++ b/src/main/java/org/stellar/sdk/xdr/SCPEnvelope.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.signature, other.signature); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPEnvelope fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPEnvelope fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCPStatement statement; private Signature signature; diff --git a/src/main/java/org/stellar/sdk/xdr/SCPHistoryEntry.java b/src/main/java/org/stellar/sdk/xdr/SCPHistoryEntry.java index 94764adda..8aa74c90b 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCPHistoryEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/SCPHistoryEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -104,4 +107,30 @@ public boolean equals(Object object) { SCPHistoryEntry other = (SCPHistoryEntry) object; return Objects.equal(this.v0, other.v0) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPHistoryEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPHistoryEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCPHistoryEntryV0.java b/src/main/java/org/stellar/sdk/xdr/SCPHistoryEntryV0.java index 2536f0a2a..d566c0d16 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCPHistoryEntryV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCPHistoryEntryV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -82,6 +85,32 @@ public boolean equals(Object object) { && Objects.equal(this.ledgerMessages, other.ledgerMessages); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPHistoryEntryV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPHistoryEntryV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCPQuorumSet[] quorumSets; private LedgerSCPMessages ledgerMessages; diff --git a/src/main/java/org/stellar/sdk/xdr/SCPNomination.java b/src/main/java/org/stellar/sdk/xdr/SCPNomination.java index b0880da67..83f6acab3 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCPNomination.java +++ b/src/main/java/org/stellar/sdk/xdr/SCPNomination.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -105,6 +108,32 @@ public boolean equals(Object object) { && Arrays.equals(this.accepted, other.accepted); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPNomination fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPNomination fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash quorumSetHash; private Value[] votes; diff --git a/src/main/java/org/stellar/sdk/xdr/SCPQuorumSet.java b/src/main/java/org/stellar/sdk/xdr/SCPQuorumSet.java index e691286ff..de5e595ad 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCPQuorumSet.java +++ b/src/main/java/org/stellar/sdk/xdr/SCPQuorumSet.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -105,6 +108,32 @@ public boolean equals(Object object) { && Arrays.equals(this.innerSets, other.innerSets); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPQuorumSet fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPQuorumSet fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 threshold; private NodeID[] validators; diff --git a/src/main/java/org/stellar/sdk/xdr/SCPStatement.java b/src/main/java/org/stellar/sdk/xdr/SCPStatement.java index fe30c9828..19afe3ad8 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCPStatement.java +++ b/src/main/java/org/stellar/sdk/xdr/SCPStatement.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -119,6 +122,32 @@ public boolean equals(Object object) { && Objects.equal(this.pledges, other.pledges); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPStatement fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPStatement fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private NodeID nodeID; private Uint64 slotIndex; @@ -148,7 +177,7 @@ public SCPStatement build() { } } - public static class SCPStatementPledges { + public static class SCPStatementPledges implements XdrElement { public SCPStatementPledges() {} SCPStatementType type; @@ -311,7 +340,33 @@ public boolean equals(Object object) { && Objects.equal(this.type, other.type); } - public static class SCPStatementPrepare { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPStatementPledges fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPStatementPledges fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class SCPStatementPrepare implements XdrElement { public SCPStatementPrepare() {} private Hash quorumSetHash; @@ -437,6 +492,32 @@ public boolean equals(Object object) { && Objects.equal(this.nH, other.nH); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPStatementPrepare fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPStatementPrepare fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash quorumSetHash; private SCPBallot ballot; @@ -488,7 +569,7 @@ public SCPStatementPrepare build() { } } - public static class SCPStatementConfirm { + public static class SCPStatementConfirm implements XdrElement { public SCPStatementConfirm() {} private SCPBallot ballot; @@ -585,6 +666,32 @@ public boolean equals(Object object) { && Objects.equal(this.quorumSetHash, other.quorumSetHash); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPStatementConfirm fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPStatementConfirm fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCPBallot ballot; private Uint32 nPrepared; @@ -629,7 +736,7 @@ public SCPStatementConfirm build() { } } - public static class SCPStatementExternalize { + public static class SCPStatementExternalize implements XdrElement { public SCPStatementExternalize() {} private SCPBallot commit; @@ -699,6 +806,32 @@ public boolean equals(Object object) { && Objects.equal(this.commitQuorumSetHash, other.commitQuorumSetHash); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPStatementExternalize fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPStatementExternalize fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCPBallot commit; private Uint32 nH; diff --git a/src/main/java/org/stellar/sdk/xdr/SCPStatementType.java b/src/main/java/org/stellar/sdk/xdr/SCPStatementType.java index 1297c606a..f5c30b6ba 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCPStatementType.java +++ b/src/main/java/org/stellar/sdk/xdr/SCPStatementType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -57,4 +60,30 @@ public static void encode(XdrDataOutputStream stream, SCPStatementType value) th public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCPStatementType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCPStatementType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecEntry.java b/src/main/java/org/stellar/sdk/xdr/SCSpecEntry.java index 6b0c4b7f8..ce6ecb4f7 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -215,4 +218,30 @@ public boolean equals(Object object) { && Objects.equal(this.udtErrorEnumV0, other.udtErrorEnumV0) && Objects.equal(this.kind, other.kind); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecEntryKind.java b/src/main/java/org/stellar/sdk/xdr/SCSpecEntryKind.java index b4669fd52..f8dd60ab4 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecEntryKind.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecEntryKind.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -61,4 +64,30 @@ public static void encode(XdrDataOutputStream stream, SCSpecEntryKind value) thr public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecEntryKind fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecEntryKind fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecFunctionInputV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecFunctionInputV0.java index bc2befbea..a228df41b 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecFunctionInputV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecFunctionInputV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -88,6 +91,32 @@ public boolean equals(Object object) { && Objects.equal(this.type, other.type); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecFunctionInputV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecFunctionInputV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString doc; private XdrString name; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecFunctionV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecFunctionV0.java index a616cab12..aab785d87 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecFunctionV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecFunctionV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -119,6 +122,32 @@ public boolean equals(Object object) { && Arrays.equals(this.outputs, other.outputs); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecFunctionV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecFunctionV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString doc; private SCSymbol name; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecType.java b/src/main/java/org/stellar/sdk/xdr/SCSpecType.java index 7829ff041..ea4bd7f66 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecType.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -151,4 +154,30 @@ public static void encode(XdrDataOutputStream stream, SCSpecType value) throws I public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeBytesN.java b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeBytesN.java index f00387ccd..e375d69e6 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeBytesN.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeBytesN.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,6 +62,32 @@ public boolean equals(Object object) { return Objects.equal(this.n, other.n); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecTypeBytesN fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecTypeBytesN fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 n; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeDef.java b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeDef.java index 4efedf536..8688a209f 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeDef.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeDef.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -353,4 +356,30 @@ public boolean equals(Object object) { && Objects.equal(this.udt, other.udt) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecTypeDef fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecTypeDef fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeMap.java b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeMap.java index c55a50d8e..951bd127e 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeMap.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeMap.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.valueType, other.valueType); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecTypeMap fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecTypeMap fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCSpecTypeDef keyType; private SCSpecTypeDef valueType; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeOption.java b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeOption.java index 18dcc55cd..d1d0cb123 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeOption.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeOption.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,6 +62,32 @@ public boolean equals(Object object) { return Objects.equal(this.valueType, other.valueType); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecTypeOption fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecTypeOption fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCSpecTypeDef valueType; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeResult.java b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeResult.java index 35696f14e..6f30f380f 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeResult.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.errorType, other.errorType); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecTypeResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecTypeResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCSpecTypeDef okType; private SCSpecTypeDef errorType; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeSet.java b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeSet.java index 3a09358ee..067604074 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeSet.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeSet.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,6 +62,32 @@ public boolean equals(Object object) { return Objects.equal(this.elementType, other.elementType); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecTypeSet fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecTypeSet fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCSpecTypeDef elementType; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeTuple.java b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeTuple.java index 664789374..553ec02dd 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeTuple.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeTuple.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -67,6 +70,32 @@ public boolean equals(Object object) { return Arrays.equals(this.valueTypes, other.valueTypes); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecTypeTuple fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecTypeTuple fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCSpecTypeDef[] valueTypes; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeUDT.java b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeUDT.java index 0a7427f0b..83bf40eca 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeUDT.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeUDT.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,6 +62,32 @@ public boolean equals(Object object) { return Objects.equal(this.name, other.name); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecTypeUDT fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecTypeUDT fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString name; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeVec.java b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeVec.java index d26aa0995..5ec71dd5f 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecTypeVec.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecTypeVec.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,6 +62,32 @@ public boolean equals(Object object) { return Objects.equal(this.elementType, other.elementType); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecTypeVec fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecTypeVec fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCSpecTypeDef elementType; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTEnumCaseV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTEnumCaseV0.java index d2477e240..a43a8c8cb 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTEnumCaseV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTEnumCaseV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -88,6 +91,32 @@ public boolean equals(Object object) { && Objects.equal(this.value, other.value); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecUDTEnumCaseV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecUDTEnumCaseV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString doc; private XdrString name; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTEnumV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTEnumV0.java index 6af62f4bf..11fa51cc4 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTEnumV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTEnumV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -110,6 +113,32 @@ public boolean equals(Object object) { && Arrays.equals(this.cases, other.cases); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecUDTEnumV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecUDTEnumV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString doc; private XdrString lib; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTErrorEnumCaseV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTErrorEnumCaseV0.java index 7488ff854..dcb4f669b 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTErrorEnumCaseV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTErrorEnumCaseV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -88,6 +91,32 @@ public boolean equals(Object object) { && Objects.equal(this.value, other.value); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecUDTErrorEnumCaseV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecUDTErrorEnumCaseV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString doc; private XdrString name; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTErrorEnumV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTErrorEnumV0.java index 887768faa..aa15970bd 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTErrorEnumV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTErrorEnumV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -111,6 +114,32 @@ public boolean equals(Object object) { && Arrays.equals(this.cases, other.cases); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecUDTErrorEnumV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecUDTErrorEnumV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString doc; private XdrString lib; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTStructFieldV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTStructFieldV0.java index 4aacf1a40..015a73b4c 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTStructFieldV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTStructFieldV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -88,6 +91,32 @@ public boolean equals(Object object) { && Objects.equal(this.type, other.type); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecUDTStructFieldV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecUDTStructFieldV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString doc; private XdrString name; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTStructV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTStructV0.java index 26be1f931..ba72eb34f 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTStructV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTStructV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -110,6 +113,32 @@ public boolean equals(Object object) { && Arrays.equals(this.fields, other.fields); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecUDTStructV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecUDTStructV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString doc; private XdrString lib; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseTupleV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseTupleV0.java index b678f4c1a..8f66aea79 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseTupleV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseTupleV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -97,6 +100,32 @@ public boolean equals(Object object) { && Arrays.equals(this.type, other.type); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecUDTUnionCaseTupleV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecUDTUnionCaseTupleV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString doc; private XdrString name; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseV0.java index 301c06c93..14eb90fc9 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -132,4 +135,30 @@ public boolean equals(Object object) { && Objects.equal(this.tupleCase, other.tupleCase) && Objects.equal(this.kind, other.kind); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecUDTUnionCaseV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecUDTUnionCaseV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseV0Kind.java b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseV0Kind.java index f47dd3ee3..378dd6293 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseV0Kind.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseV0Kind.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -50,4 +53,30 @@ public static void encode(XdrDataOutputStream stream, SCSpecUDTUnionCaseV0Kind v public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecUDTUnionCaseV0Kind fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecUDTUnionCaseV0Kind fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseVoidV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseVoidV0.java index 25f9db25f..0e4387425 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseVoidV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionCaseVoidV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { return Objects.equal(this.doc, other.doc) && Objects.equal(this.name, other.name); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecUDTUnionCaseVoidV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecUDTUnionCaseVoidV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString doc; private XdrString name; diff --git a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionV0.java b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionV0.java index 7a8be142f..2f6f311f4 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionV0.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSpecUDTUnionV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -110,6 +113,32 @@ public boolean equals(Object object) { && Arrays.equals(this.cases, other.cases); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSpecUDTUnionV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSpecUDTUnionV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private XdrString doc; private XdrString lib; diff --git a/src/main/java/org/stellar/sdk/xdr/SCString.java b/src/main/java/org/stellar/sdk/xdr/SCString.java index 916a608ce..ed1a0f5e0 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCString.java +++ b/src/main/java/org/stellar/sdk/xdr/SCString.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -41,7 +44,7 @@ public void encode(XdrDataOutputStream stream) throws IOException { public static SCString decode(XdrDataInputStream stream) throws IOException { SCString decodedSCString = new SCString(); - decodedSCString.SCString = XdrString.decode(stream, 2147483647); + decodedSCString.SCString = XdrString.decode(stream, Integer.MAX_VALUE); return decodedSCString; } @@ -59,4 +62,30 @@ public boolean equals(Object object) { SCString other = (SCString) object; return Objects.equal(this.SCString, other.SCString); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCString fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCString fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCSymbol.java b/src/main/java/org/stellar/sdk/xdr/SCSymbol.java index ce7f02918..4ffd515fa 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCSymbol.java +++ b/src/main/java/org/stellar/sdk/xdr/SCSymbol.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,4 +62,30 @@ public boolean equals(Object object) { SCSymbol other = (SCSymbol) object; return Objects.equal(this.SCSymbol, other.SCSymbol); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCSymbol fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCSymbol fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCVal.java b/src/main/java/org/stellar/sdk/xdr/SCVal.java index 6c29d68c6..94838a0d6 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCVal.java +++ b/src/main/java/org/stellar/sdk/xdr/SCVal.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -661,4 +664,30 @@ public boolean equals(Object object) { && Objects.equal(this.instance, other.instance) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCVal fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCVal fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCValType.java b/src/main/java/org/stellar/sdk/xdr/SCValType.java index e6ad5512b..5a37a337d 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCValType.java +++ b/src/main/java/org/stellar/sdk/xdr/SCValType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -159,4 +162,30 @@ public static void encode(XdrDataOutputStream stream, SCValType value) throws IO public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCValType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCValType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SCVec.java b/src/main/java/org/stellar/sdk/xdr/SCVec.java index 69594dc52..9a1ba2fd5 100644 --- a/src/main/java/org/stellar/sdk/xdr/SCVec.java +++ b/src/main/java/org/stellar/sdk/xdr/SCVec.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -66,4 +69,30 @@ public boolean equals(Object object) { SCVec other = (SCVec) object; return Arrays.equals(this.SCVec, other.SCVec); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SCVec fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SCVec fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SendMore.java b/src/main/java/org/stellar/sdk/xdr/SendMore.java index 44738a60e..eae1eb499 100644 --- a/src/main/java/org/stellar/sdk/xdr/SendMore.java +++ b/src/main/java/org/stellar/sdk/xdr/SendMore.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,6 +62,32 @@ public boolean equals(Object object) { return Objects.equal(this.numMessages, other.numMessages); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SendMore fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SendMore fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 numMessages; diff --git a/src/main/java/org/stellar/sdk/xdr/SendMoreExtended.java b/src/main/java/org/stellar/sdk/xdr/SendMoreExtended.java index 0656a3dc2..2336ed9ff 100644 --- a/src/main/java/org/stellar/sdk/xdr/SendMoreExtended.java +++ b/src/main/java/org/stellar/sdk/xdr/SendMoreExtended.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -73,6 +76,32 @@ public boolean equals(Object object) { && Objects.equal(this.numBytes, other.numBytes); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SendMoreExtended fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SendMoreExtended fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 numMessages; private Uint32 numBytes; diff --git a/src/main/java/org/stellar/sdk/xdr/SequenceNumber.java b/src/main/java/org/stellar/sdk/xdr/SequenceNumber.java index 8a8178d5e..8254459d9 100644 --- a/src/main/java/org/stellar/sdk/xdr/SequenceNumber.java +++ b/src/main/java/org/stellar/sdk/xdr/SequenceNumber.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,4 +62,30 @@ public boolean equals(Object object) { SequenceNumber other = (SequenceNumber) object; return Objects.equal(this.SequenceNumber, other.SequenceNumber); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SequenceNumber fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SequenceNumber fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SetOptionsOp.java b/src/main/java/org/stellar/sdk/xdr/SetOptionsOp.java index 39a561e38..d5270c794 100644 --- a/src/main/java/org/stellar/sdk/xdr/SetOptionsOp.java +++ b/src/main/java/org/stellar/sdk/xdr/SetOptionsOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -259,6 +262,32 @@ public boolean equals(Object object) { && Objects.equal(this.signer, other.signer); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SetOptionsOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SetOptionsOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID inflationDest; private Uint32 clearFlags; diff --git a/src/main/java/org/stellar/sdk/xdr/SetOptionsResult.java b/src/main/java/org/stellar/sdk/xdr/SetOptionsResult.java index 422c23f68..ca3b917a5 100644 --- a/src/main/java/org/stellar/sdk/xdr/SetOptionsResult.java +++ b/src/main/java/org/stellar/sdk/xdr/SetOptionsResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -118,4 +121,30 @@ public boolean equals(Object object) { SetOptionsResult other = (SetOptionsResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SetOptionsResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SetOptionsResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SetOptionsResultCode.java b/src/main/java/org/stellar/sdk/xdr/SetOptionsResultCode.java index 7d874cddd..4d7eb1c5b 100644 --- a/src/main/java/org/stellar/sdk/xdr/SetOptionsResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/SetOptionsResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -89,4 +92,30 @@ public static void encode(XdrDataOutputStream stream, SetOptionsResultCode value public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SetOptionsResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SetOptionsResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsOp.java b/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsOp.java index 3a016082c..3b7723965 100644 --- a/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsOp.java +++ b/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsOp.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -103,6 +106,32 @@ public boolean equals(Object object) { && Objects.equal(this.setFlags, other.setFlags); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SetTrustLineFlagsOp fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SetTrustLineFlagsOp fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID trustor; private Asset asset; diff --git a/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResult.java b/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResult.java index 30f608e58..87b30607d 100644 --- a/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResult.java +++ b/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -104,4 +107,30 @@ public boolean equals(Object object) { SetTrustLineFlagsResult other = (SetTrustLineFlagsResult) object; return Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SetTrustLineFlagsResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SetTrustLineFlagsResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResultCode.java b/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResultCode.java index e26de75a6..68a9e5466 100644 --- a/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/SetTrustLineFlagsResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -70,4 +73,30 @@ public static void encode(XdrDataOutputStream stream, SetTrustLineFlagsResultCod public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SetTrustLineFlagsResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SetTrustLineFlagsResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Signature.java b/src/main/java/org/stellar/sdk/xdr/Signature.java index e0b8689f1..ece133856 100644 --- a/src/main/java/org/stellar/sdk/xdr/Signature.java +++ b/src/main/java/org/stellar/sdk/xdr/Signature.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -63,4 +66,30 @@ public boolean equals(Object object) { Signature other = (Signature) object; return Arrays.equals(this.Signature, other.Signature); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Signature fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Signature fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SignatureHint.java b/src/main/java/org/stellar/sdk/xdr/SignatureHint.java index 0dba1fca7..f4b48399a 100644 --- a/src/main/java/org/stellar/sdk/xdr/SignatureHint.java +++ b/src/main/java/org/stellar/sdk/xdr/SignatureHint.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -62,4 +65,30 @@ public boolean equals(Object object) { SignatureHint other = (SignatureHint) object; return Arrays.equals(this.SignatureHint, other.SignatureHint); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SignatureHint fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SignatureHint fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SignedSurveyRequestMessage.java b/src/main/java/org/stellar/sdk/xdr/SignedSurveyRequestMessage.java index a4efce260..0a44490ae 100644 --- a/src/main/java/org/stellar/sdk/xdr/SignedSurveyRequestMessage.java +++ b/src/main/java/org/stellar/sdk/xdr/SignedSurveyRequestMessage.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -74,6 +77,32 @@ public boolean equals(Object object) { && Objects.equal(this.request, other.request); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SignedSurveyRequestMessage fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SignedSurveyRequestMessage fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Signature requestSignature; private SurveyRequestMessage request; diff --git a/src/main/java/org/stellar/sdk/xdr/SignedSurveyResponseMessage.java b/src/main/java/org/stellar/sdk/xdr/SignedSurveyResponseMessage.java index b611590a9..44f44e13b 100644 --- a/src/main/java/org/stellar/sdk/xdr/SignedSurveyResponseMessage.java +++ b/src/main/java/org/stellar/sdk/xdr/SignedSurveyResponseMessage.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -75,6 +78,32 @@ public boolean equals(Object object) { && Objects.equal(this.response, other.response); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SignedSurveyResponseMessage fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SignedSurveyResponseMessage fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Signature responseSignature; private SurveyResponseMessage response; diff --git a/src/main/java/org/stellar/sdk/xdr/Signer.java b/src/main/java/org/stellar/sdk/xdr/Signer.java index 594bbf4f2..484e661b7 100644 --- a/src/main/java/org/stellar/sdk/xdr/Signer.java +++ b/src/main/java/org/stellar/sdk/xdr/Signer.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -71,6 +74,32 @@ public boolean equals(Object object) { return Objects.equal(this.key, other.key) && Objects.equal(this.weight, other.weight); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Signer fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Signer fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SignerKey key; private Uint32 weight; diff --git a/src/main/java/org/stellar/sdk/xdr/SignerKey.java b/src/main/java/org/stellar/sdk/xdr/SignerKey.java index c2b0d660d..d91d722e6 100644 --- a/src/main/java/org/stellar/sdk/xdr/SignerKey.java +++ b/src/main/java/org/stellar/sdk/xdr/SignerKey.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -194,7 +197,33 @@ public boolean equals(Object object) { && Objects.equal(this.type, other.type); } - public static class SignerKeyEd25519SignedPayload { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SignerKey fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SignerKey fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class SignerKeyEd25519SignedPayload implements XdrElement { public SignerKeyEd25519SignedPayload() {} private Uint256 ed25519; @@ -258,6 +287,32 @@ public boolean equals(Object object) { && Arrays.equals(this.payload, other.payload); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SignerKeyEd25519SignedPayload fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SignerKeyEd25519SignedPayload fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint256 ed25519; private byte[] payload; diff --git a/src/main/java/org/stellar/sdk/xdr/SignerKeyType.java b/src/main/java/org/stellar/sdk/xdr/SignerKeyType.java index f5fb66af0..85e62c944 100644 --- a/src/main/java/org/stellar/sdk/xdr/SignerKeyType.java +++ b/src/main/java/org/stellar/sdk/xdr/SignerKeyType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -57,4 +60,30 @@ public static void encode(XdrDataOutputStream stream, SignerKeyType value) throw public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SignerKeyType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SignerKeyType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SimplePaymentResult.java b/src/main/java/org/stellar/sdk/xdr/SimplePaymentResult.java index 104b958d6..ff690be75 100644 --- a/src/main/java/org/stellar/sdk/xdr/SimplePaymentResult.java +++ b/src/main/java/org/stellar/sdk/xdr/SimplePaymentResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -88,6 +91,32 @@ public boolean equals(Object object) { && Objects.equal(this.amount, other.amount); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SimplePaymentResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SimplePaymentResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID destination; private Asset asset; diff --git a/src/main/java/org/stellar/sdk/xdr/SorobanAddressCredentials.java b/src/main/java/org/stellar/sdk/xdr/SorobanAddressCredentials.java index 272a08b3a..4ee671117 100644 --- a/src/main/java/org/stellar/sdk/xdr/SorobanAddressCredentials.java +++ b/src/main/java/org/stellar/sdk/xdr/SorobanAddressCredentials.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -103,6 +106,32 @@ public boolean equals(Object object) { && Objects.equal(this.signatureArgs, other.signatureArgs); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SorobanAddressCredentials fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SorobanAddressCredentials fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCAddress address; private Int64 nonce; diff --git a/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizationEntry.java b/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizationEntry.java index 74da85821..14458a411 100644 --- a/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizationEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizationEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -74,6 +77,32 @@ public boolean equals(Object object) { && Objects.equal(this.rootInvocation, other.rootInvocation); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SorobanAuthorizationEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SorobanAuthorizationEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SorobanCredentials credentials; private SorobanAuthorizedInvocation rootInvocation; diff --git a/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedContractFunction.java b/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedContractFunction.java index f690f590d..5b2c29bb5 100644 --- a/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedContractFunction.java +++ b/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedContractFunction.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -91,6 +94,32 @@ public boolean equals(Object object) { && Objects.equal(this.args, other.args); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SorobanAuthorizedContractFunction fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SorobanAuthorizedContractFunction fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SCAddress contractAddress; private SCSymbol functionName; diff --git a/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedFunction.java b/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedFunction.java index c0ef0f14c..b988e570d 100644 --- a/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedFunction.java +++ b/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedFunction.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -134,4 +137,30 @@ public boolean equals(Object object) { && Objects.equal(this.createContractHostFn, other.createContractHostFn) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SorobanAuthorizedFunction fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SorobanAuthorizedFunction fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedFunctionType.java b/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedFunctionType.java index d4cb00caa..c6b379c35 100644 --- a/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedFunctionType.java +++ b/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedFunctionType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -50,4 +53,30 @@ public static void encode(XdrDataOutputStream stream, SorobanAuthorizedFunctionT public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SorobanAuthorizedFunctionType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SorobanAuthorizedFunctionType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedInvocation.java b/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedInvocation.java index 994508930..1a2ffb74a 100644 --- a/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedInvocation.java +++ b/src/main/java/org/stellar/sdk/xdr/SorobanAuthorizedInvocation.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -87,6 +90,32 @@ public boolean equals(Object object) { && Arrays.equals(this.subInvocations, other.subInvocations); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SorobanAuthorizedInvocation fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SorobanAuthorizedInvocation fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private SorobanAuthorizedFunction function; private SorobanAuthorizedInvocation[] subInvocations; diff --git a/src/main/java/org/stellar/sdk/xdr/SorobanCredentials.java b/src/main/java/org/stellar/sdk/xdr/SorobanCredentials.java index 88a21e72a..3500dedef 100644 --- a/src/main/java/org/stellar/sdk/xdr/SorobanCredentials.java +++ b/src/main/java/org/stellar/sdk/xdr/SorobanCredentials.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -110,4 +113,30 @@ public boolean equals(Object object) { SorobanCredentials other = (SorobanCredentials) object; return Objects.equal(this.address, other.address) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SorobanCredentials fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SorobanCredentials fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SorobanCredentialsType.java b/src/main/java/org/stellar/sdk/xdr/SorobanCredentialsType.java index 85ebf85f7..2b802b010 100644 --- a/src/main/java/org/stellar/sdk/xdr/SorobanCredentialsType.java +++ b/src/main/java/org/stellar/sdk/xdr/SorobanCredentialsType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -50,4 +53,30 @@ public static void encode(XdrDataOutputStream stream, SorobanCredentialsType val public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SorobanCredentialsType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SorobanCredentialsType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SorobanResources.java b/src/main/java/org/stellar/sdk/xdr/SorobanResources.java index 531b5794e..9ebacdd0e 100644 --- a/src/main/java/org/stellar/sdk/xdr/SorobanResources.java +++ b/src/main/java/org/stellar/sdk/xdr/SorobanResources.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -23,7 +26,7 @@ // uint32 writeBytes; // // // Maximum size of dynamic metadata produced by this contract ( -// // bytes read from ledger + bytes written to ledger + event bytes written to meta). +// // currently only includes the events). // uint32 extendedMetaDataSizeBytes; // }; @@ -128,6 +131,32 @@ public boolean equals(Object object) { && Objects.equal(this.extendedMetaDataSizeBytes, other.extendedMetaDataSizeBytes); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SorobanResources fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SorobanResources fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private LedgerFootprint footprint; private Uint32 instructions; diff --git a/src/main/java/org/stellar/sdk/xdr/SorobanTransactionData.java b/src/main/java/org/stellar/sdk/xdr/SorobanTransactionData.java index d8fff4305..87db2f534 100644 --- a/src/main/java/org/stellar/sdk/xdr/SorobanTransactionData.java +++ b/src/main/java/org/stellar/sdk/xdr/SorobanTransactionData.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -89,6 +92,32 @@ public boolean equals(Object object) { && Objects.equal(this.refundableFee, other.refundableFee); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SorobanTransactionData fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SorobanTransactionData fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ExtensionPoint ext; private SorobanResources resources; diff --git a/src/main/java/org/stellar/sdk/xdr/SorobanTransactionMeta.java b/src/main/java/org/stellar/sdk/xdr/SorobanTransactionMeta.java index 396cad274..018214361 100644 --- a/src/main/java/org/stellar/sdk/xdr/SorobanTransactionMeta.java +++ b/src/main/java/org/stellar/sdk/xdr/SorobanTransactionMeta.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -129,6 +132,32 @@ public boolean equals(Object object) { && Arrays.equals(this.diagnosticEvents, other.diagnosticEvents); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SorobanTransactionMeta fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SorobanTransactionMeta fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ExtensionPoint ext; private ContractEvent[] events; diff --git a/src/main/java/org/stellar/sdk/xdr/SponsorshipDescriptor.java b/src/main/java/org/stellar/sdk/xdr/SponsorshipDescriptor.java index 9f85dc4ee..d93cf6a51 100644 --- a/src/main/java/org/stellar/sdk/xdr/SponsorshipDescriptor.java +++ b/src/main/java/org/stellar/sdk/xdr/SponsorshipDescriptor.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -68,4 +71,30 @@ public boolean equals(Object object) { SponsorshipDescriptor other = (SponsorshipDescriptor) object; return Objects.equal(this.SponsorshipDescriptor, other.SponsorshipDescriptor); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SponsorshipDescriptor fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SponsorshipDescriptor fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/StateExpirationSettings.java b/src/main/java/org/stellar/sdk/xdr/StateExpirationSettings.java index 2686ce32f..5fb509169 100644 --- a/src/main/java/org/stellar/sdk/xdr/StateExpirationSettings.java +++ b/src/main/java/org/stellar/sdk/xdr/StateExpirationSettings.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -188,6 +191,32 @@ public boolean equals(Object object) { && Objects.equal(this.evictionScanSize, other.evictionScanSize); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static StateExpirationSettings fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static StateExpirationSettings fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 maxEntryExpiration; private Uint32 minTempEntryExpiration; diff --git a/src/main/java/org/stellar/sdk/xdr/StellarMessage.java b/src/main/java/org/stellar/sdk/xdr/StellarMessage.java index 18500e468..28f2fd92e 100644 --- a/src/main/java/org/stellar/sdk/xdr/StellarMessage.java +++ b/src/main/java/org/stellar/sdk/xdr/StellarMessage.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -620,4 +623,30 @@ public boolean equals(Object object) { && Objects.equal(this.floodDemand, other.floodDemand) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static StellarMessage fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static StellarMessage fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/StellarValue.java b/src/main/java/org/stellar/sdk/xdr/StellarValue.java index 38f0cec12..881eafb0d 100644 --- a/src/main/java/org/stellar/sdk/xdr/StellarValue.java +++ b/src/main/java/org/stellar/sdk/xdr/StellarValue.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -126,6 +129,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static StellarValue fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static StellarValue fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash txSetHash; private TimePoint closeTime; @@ -162,7 +191,7 @@ public StellarValue build() { } } - public static class StellarValueExt { + public static class StellarValueExt implements XdrElement { public StellarValueExt() {} StellarValueType v; @@ -254,5 +283,31 @@ public boolean equals(Object object) { return Objects.equal(this.lcValueSignature, other.lcValueSignature) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static StellarValueExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static StellarValueExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/StellarValueType.java b/src/main/java/org/stellar/sdk/xdr/StellarValueType.java index 912103727..510dc3f6c 100644 --- a/src/main/java/org/stellar/sdk/xdr/StellarValueType.java +++ b/src/main/java/org/stellar/sdk/xdr/StellarValueType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -49,4 +52,30 @@ public static void encode(XdrDataOutputStream stream, StellarValueType value) th public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static StellarValueType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static StellarValueType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/StoredTransactionSet.java b/src/main/java/org/stellar/sdk/xdr/StoredTransactionSet.java index f9e41f8df..ae3c5ad03 100644 --- a/src/main/java/org/stellar/sdk/xdr/StoredTransactionSet.java +++ b/src/main/java/org/stellar/sdk/xdr/StoredTransactionSet.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -132,4 +135,30 @@ public boolean equals(Object object) { && Objects.equal(this.generalizedTxSet, other.generalizedTxSet) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static StoredTransactionSet fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static StoredTransactionSet fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/String32.java b/src/main/java/org/stellar/sdk/xdr/String32.java index 1f130b881..9fa8f9320 100644 --- a/src/main/java/org/stellar/sdk/xdr/String32.java +++ b/src/main/java/org/stellar/sdk/xdr/String32.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,4 +62,30 @@ public boolean equals(Object object) { String32 other = (String32) object; return Objects.equal(this.string32, other.string32); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static String32 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static String32 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/String64.java b/src/main/java/org/stellar/sdk/xdr/String64.java index cb3ea069f..497f0e732 100644 --- a/src/main/java/org/stellar/sdk/xdr/String64.java +++ b/src/main/java/org/stellar/sdk/xdr/String64.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,4 +62,30 @@ public boolean equals(Object object) { String64 other = (String64) object; return Objects.equal(this.string64, other.string64); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static String64 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static String64 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SurveyMessageCommandType.java b/src/main/java/org/stellar/sdk/xdr/SurveyMessageCommandType.java index 0c2b0ed1b..c72db98a1 100644 --- a/src/main/java/org/stellar/sdk/xdr/SurveyMessageCommandType.java +++ b/src/main/java/org/stellar/sdk/xdr/SurveyMessageCommandType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -46,4 +49,30 @@ public static void encode(XdrDataOutputStream stream, SurveyMessageCommandType v public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SurveyMessageCommandType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SurveyMessageCommandType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SurveyMessageResponseType.java b/src/main/java/org/stellar/sdk/xdr/SurveyMessageResponseType.java index 77b2d423d..2df60adfd 100644 --- a/src/main/java/org/stellar/sdk/xdr/SurveyMessageResponseType.java +++ b/src/main/java/org/stellar/sdk/xdr/SurveyMessageResponseType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -50,4 +53,30 @@ public static void encode(XdrDataOutputStream stream, SurveyMessageResponseType public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SurveyMessageResponseType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SurveyMessageResponseType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SurveyRequestMessage.java b/src/main/java/org/stellar/sdk/xdr/SurveyRequestMessage.java index 6aa03b9dd..81f92b543 100644 --- a/src/main/java/org/stellar/sdk/xdr/SurveyRequestMessage.java +++ b/src/main/java/org/stellar/sdk/xdr/SurveyRequestMessage.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -121,6 +124,32 @@ public boolean equals(Object object) { && Objects.equal(this.commandType, other.commandType); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SurveyRequestMessage fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SurveyRequestMessage fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private NodeID surveyorPeerID; private NodeID surveyedPeerID; diff --git a/src/main/java/org/stellar/sdk/xdr/SurveyResponseBody.java b/src/main/java/org/stellar/sdk/xdr/SurveyResponseBody.java index 6bbe9e508..75cd873c5 100644 --- a/src/main/java/org/stellar/sdk/xdr/SurveyResponseBody.java +++ b/src/main/java/org/stellar/sdk/xdr/SurveyResponseBody.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -131,4 +134,30 @@ public boolean equals(Object object) { && Objects.equal(this.topologyResponseBodyV1, other.topologyResponseBodyV1) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SurveyResponseBody fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SurveyResponseBody fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/SurveyResponseMessage.java b/src/main/java/org/stellar/sdk/xdr/SurveyResponseMessage.java index e806f88a3..843f1d6b4 100644 --- a/src/main/java/org/stellar/sdk/xdr/SurveyResponseMessage.java +++ b/src/main/java/org/stellar/sdk/xdr/SurveyResponseMessage.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -121,6 +124,32 @@ public boolean equals(Object object) { && Objects.equal(this.encryptedBody, other.encryptedBody); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static SurveyResponseMessage fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static SurveyResponseMessage fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private NodeID surveyorPeerID; private NodeID surveyedPeerID; diff --git a/src/main/java/org/stellar/sdk/xdr/ThresholdIndexes.java b/src/main/java/org/stellar/sdk/xdr/ThresholdIndexes.java index a67d5c1eb..5702020c0 100644 --- a/src/main/java/org/stellar/sdk/xdr/ThresholdIndexes.java +++ b/src/main/java/org/stellar/sdk/xdr/ThresholdIndexes.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -57,4 +60,30 @@ public static void encode(XdrDataOutputStream stream, ThresholdIndexes value) th public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static ThresholdIndexes fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static ThresholdIndexes fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Thresholds.java b/src/main/java/org/stellar/sdk/xdr/Thresholds.java index bea371c22..3c32de1bf 100644 --- a/src/main/java/org/stellar/sdk/xdr/Thresholds.java +++ b/src/main/java/org/stellar/sdk/xdr/Thresholds.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -62,4 +65,30 @@ public boolean equals(Object object) { Thresholds other = (Thresholds) object; return Arrays.equals(this.Thresholds, other.Thresholds); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Thresholds fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Thresholds fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/TimeBounds.java b/src/main/java/org/stellar/sdk/xdr/TimeBounds.java index 4d94d37ce..875b3d0f5 100644 --- a/src/main/java/org/stellar/sdk/xdr/TimeBounds.java +++ b/src/main/java/org/stellar/sdk/xdr/TimeBounds.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -72,6 +75,32 @@ public boolean equals(Object object) { return Objects.equal(this.minTime, other.minTime) && Objects.equal(this.maxTime, other.maxTime); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TimeBounds fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TimeBounds fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private TimePoint minTime; private TimePoint maxTime; diff --git a/src/main/java/org/stellar/sdk/xdr/TimePoint.java b/src/main/java/org/stellar/sdk/xdr/TimePoint.java index e80c7170b..f82679331 100644 --- a/src/main/java/org/stellar/sdk/xdr/TimePoint.java +++ b/src/main/java/org/stellar/sdk/xdr/TimePoint.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -59,4 +62,30 @@ public boolean equals(Object object) { TimePoint other = (TimePoint) object; return Objects.equal(this.TimePoint, other.TimePoint); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TimePoint fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TimePoint fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/TopologyResponseBodyV0.java b/src/main/java/org/stellar/sdk/xdr/TopologyResponseBodyV0.java index 0bbd9f6b9..7a43b161f 100644 --- a/src/main/java/org/stellar/sdk/xdr/TopologyResponseBodyV0.java +++ b/src/main/java/org/stellar/sdk/xdr/TopologyResponseBodyV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -107,6 +110,32 @@ public boolean equals(Object object) { && Objects.equal(this.totalOutboundPeerCount, other.totalOutboundPeerCount); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TopologyResponseBodyV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TopologyResponseBodyV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private PeerStatList inboundPeers; private PeerStatList outboundPeers; diff --git a/src/main/java/org/stellar/sdk/xdr/TopologyResponseBodyV1.java b/src/main/java/org/stellar/sdk/xdr/TopologyResponseBodyV1.java index 874a309c0..c8059f697 100644 --- a/src/main/java/org/stellar/sdk/xdr/TopologyResponseBodyV1.java +++ b/src/main/java/org/stellar/sdk/xdr/TopologyResponseBodyV1.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -138,6 +141,32 @@ public boolean equals(Object object) { && Objects.equal(this.maxOutboundPeerCount, other.maxOutboundPeerCount); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TopologyResponseBodyV1 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TopologyResponseBodyV1 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private PeerStatList inboundPeers; private PeerStatList outboundPeers; diff --git a/src/main/java/org/stellar/sdk/xdr/Transaction.java b/src/main/java/org/stellar/sdk/xdr/Transaction.java index 1fb66aaf5..f5cf25588 100644 --- a/src/main/java/org/stellar/sdk/xdr/Transaction.java +++ b/src/main/java/org/stellar/sdk/xdr/Transaction.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -177,6 +180,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Transaction fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Transaction fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private MuxedAccount sourceAccount; private Uint32 fee; @@ -234,7 +263,7 @@ public Transaction build() { } } - public static class TransactionExt { + public static class TransactionExt implements XdrElement { public TransactionExt() {} Integer v; @@ -325,5 +354,31 @@ public boolean equals(Object object) { TransactionExt other = (TransactionExt) object; return Objects.equal(this.sorobanData, other.sorobanData) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionEnvelope.java b/src/main/java/org/stellar/sdk/xdr/TransactionEnvelope.java index 4befb76cd..c837b112c 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionEnvelope.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionEnvelope.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -158,4 +161,30 @@ public boolean equals(Object object) { && Objects.equal(this.feeBump, other.feeBump) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionEnvelope fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionEnvelope fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionHistoryEntry.java b/src/main/java/org/stellar/sdk/xdr/TransactionHistoryEntry.java index a5f59ede7..f270ef9c8 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionHistoryEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionHistoryEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -97,6 +100,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionHistoryEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionHistoryEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 ledgerSeq; private TransactionSet txSet; @@ -126,7 +155,7 @@ public TransactionHistoryEntry build() { } } - public static class TransactionHistoryEntryExt { + public static class TransactionHistoryEntryExt implements XdrElement { public TransactionHistoryEntryExt() {} Integer v; @@ -222,5 +251,31 @@ public boolean equals(Object object) { return Objects.equal(this.generalizedTxSet, other.generalizedTxSet) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionHistoryEntryExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionHistoryEntryExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionHistoryResultEntry.java b/src/main/java/org/stellar/sdk/xdr/TransactionHistoryResultEntry.java index 6c024bcde..c4431b7bb 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionHistoryResultEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionHistoryResultEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -97,6 +100,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionHistoryResultEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionHistoryResultEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint32 ledgerSeq; private TransactionResultSet txResultSet; @@ -126,7 +155,7 @@ public TransactionHistoryResultEntry build() { } } - public static class TransactionHistoryResultEntryExt { + public static class TransactionHistoryResultEntryExt implements XdrElement { public TransactionHistoryResultEntryExt() {} Integer v; @@ -198,5 +227,31 @@ public boolean equals(Object object) { TransactionHistoryResultEntryExt other = (TransactionHistoryResultEntryExt) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionHistoryResultEntryExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionHistoryResultEntryExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionMeta.java b/src/main/java/org/stellar/sdk/xdr/TransactionMeta.java index 3e23ca42c..e774bf88e 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionMeta.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionMeta.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -192,4 +195,30 @@ public boolean equals(Object object) { && Objects.equal(this.v3, other.v3) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionMeta fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionMeta fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionMetaV1.java b/src/main/java/org/stellar/sdk/xdr/TransactionMetaV1.java index 5eb2e440c..5e1eacca0 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionMetaV1.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionMetaV1.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -82,6 +85,32 @@ public boolean equals(Object object) { && Arrays.equals(this.operations, other.operations); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionMetaV1 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionMetaV1 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private LedgerEntryChanges txChanges; private OperationMeta[] operations; diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionMetaV2.java b/src/main/java/org/stellar/sdk/xdr/TransactionMetaV2.java index 6980da5c6..08e04a479 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionMetaV2.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionMetaV2.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -99,6 +102,32 @@ public boolean equals(Object object) { && Objects.equal(this.txChangesAfter, other.txChangesAfter); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionMetaV2 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionMetaV2 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private LedgerEntryChanges txChangesBefore; private OperationMeta[] operations; diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionMetaV3.java b/src/main/java/org/stellar/sdk/xdr/TransactionMetaV3.java index fe0112b41..fa335d95d 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionMetaV3.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionMetaV3.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -141,6 +144,32 @@ public boolean equals(Object object) { && Objects.equal(this.sorobanMeta, other.sorobanMeta); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionMetaV3 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionMetaV3 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private ExtensionPoint ext; private LedgerEntryChanges txChangesBefore; diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionPhase.java b/src/main/java/org/stellar/sdk/xdr/TransactionPhase.java index 737f994e1..fdda2be93 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionPhase.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionPhase.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -113,4 +116,30 @@ public boolean equals(Object object) { TransactionPhase other = (TransactionPhase) object; return Arrays.equals(this.v0Components, other.v0Components) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionPhase fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionPhase fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionResult.java b/src/main/java/org/stellar/sdk/xdr/TransactionResult.java index 34a68ea31..d4f310bf5 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionResult.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionResult.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -122,6 +125,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Int64 feeCharged; private TransactionResultResult result; @@ -151,7 +180,7 @@ public TransactionResult build() { } } - public static class TransactionResultResult { + public static class TransactionResultResult implements XdrElement { public TransactionResultResult() {} TransactionResultCode code; @@ -309,9 +338,35 @@ public boolean equals(Object object) { && Arrays.equals(this.results, other.results) && Objects.equal(this.code, other.code); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionResultResult fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionResultResult fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } - public static class TransactionResultExt { + public static class TransactionResultExt implements XdrElement { public TransactionResultExt() {} Integer v; @@ -380,5 +435,31 @@ public boolean equals(Object object) { TransactionResultExt other = (TransactionResultExt) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionResultExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionResultExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionResultCode.java b/src/main/java/org/stellar/sdk/xdr/TransactionResultCode.java index 79bfb63c6..8f0d827df 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionResultCode.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionResultCode.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -124,4 +127,30 @@ public static void encode(XdrDataOutputStream stream, TransactionResultCode valu public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionResultCode fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionResultCode fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionResultMeta.java b/src/main/java/org/stellar/sdk/xdr/TransactionResultMeta.java index c67b9ef9b..5c2009027 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionResultMeta.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionResultMeta.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -88,6 +91,32 @@ public boolean equals(Object object) { && Objects.equal(this.txApplyProcessing, other.txApplyProcessing); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionResultMeta fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionResultMeta fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private TransactionResultPair result; private LedgerEntryChanges feeProcessing; diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionResultPair.java b/src/main/java/org/stellar/sdk/xdr/TransactionResultPair.java index 82667278f..261a02976 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionResultPair.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionResultPair.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -74,6 +77,32 @@ public boolean equals(Object object) { && Objects.equal(this.result, other.result); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionResultPair fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionResultPair fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash transactionHash; private TransactionResult result; diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionResultSet.java b/src/main/java/org/stellar/sdk/xdr/TransactionResultSet.java index 3e237a5ff..58afcfcc1 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionResultSet.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionResultSet.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -68,6 +71,32 @@ public boolean equals(Object object) { return Arrays.equals(this.results, other.results); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionResultSet fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionResultSet fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private TransactionResultPair[] results; diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionSet.java b/src/main/java/org/stellar/sdk/xdr/TransactionSet.java index 65cad977a..81fdc7786 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionSet.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionSet.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -82,6 +85,32 @@ public boolean equals(Object object) { && Arrays.equals(this.txs, other.txs); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionSet fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionSet fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash previousLedgerHash; private TransactionEnvelope[] txs; diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionSetV1.java b/src/main/java/org/stellar/sdk/xdr/TransactionSetV1.java index ce0d8aac8..d90406653 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionSetV1.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionSetV1.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -82,6 +85,32 @@ public boolean equals(Object object) { && Arrays.equals(this.phases, other.phases); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionSetV1 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionSetV1 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash previousLedgerHash; private TransactionPhase[] phases; diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionSignaturePayload.java b/src/main/java/org/stellar/sdk/xdr/TransactionSignaturePayload.java index 9a9f09974..113063f35 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionSignaturePayload.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionSignaturePayload.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -85,6 +88,32 @@ public boolean equals(Object object) { && Objects.equal(this.taggedTransaction, other.taggedTransaction); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionSignaturePayload fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionSignaturePayload fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Hash networkId; private TransactionSignaturePayloadTaggedTransaction taggedTransaction; @@ -108,7 +137,7 @@ public TransactionSignaturePayload build() { } } - public static class TransactionSignaturePayloadTaggedTransaction { + public static class TransactionSignaturePayloadTaggedTransaction implements XdrElement { public TransactionSignaturePayloadTaggedTransaction() {} EnvelopeType type; @@ -231,5 +260,33 @@ public boolean equals(Object object) { && Objects.equal(this.feeBump, other.feeBump) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionSignaturePayloadTaggedTransaction fromXdrBase64(String xdr) + throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionSignaturePayloadTaggedTransaction fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionV0.java b/src/main/java/org/stellar/sdk/xdr/TransactionV0.java index d7658cd16..06c46c0c3 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionV0.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionV0.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -172,6 +175,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionV0 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionV0 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint256 sourceAccountEd25519; private Uint32 fee; @@ -229,7 +258,7 @@ public TransactionV0 build() { } } - public static class TransactionV0Ext { + public static class TransactionV0Ext implements XdrElement { public TransactionV0Ext() {} Integer v; @@ -297,5 +326,31 @@ public boolean equals(Object object) { TransactionV0Ext other = (TransactionV0Ext) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionV0Ext fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionV0Ext fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionV0Envelope.java b/src/main/java/org/stellar/sdk/xdr/TransactionV0Envelope.java index 808f32ae0..11b519c33 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionV0Envelope.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionV0Envelope.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -84,6 +87,32 @@ public boolean equals(Object object) { return Objects.equal(this.tx, other.tx) && Arrays.equals(this.signatures, other.signatures); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionV0Envelope fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionV0Envelope fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private TransactionV0 tx; private DecoratedSignature[] signatures; diff --git a/src/main/java/org/stellar/sdk/xdr/TransactionV1Envelope.java b/src/main/java/org/stellar/sdk/xdr/TransactionV1Envelope.java index 9a06fbda4..8d88ddd3f 100644 --- a/src/main/java/org/stellar/sdk/xdr/TransactionV1Envelope.java +++ b/src/main/java/org/stellar/sdk/xdr/TransactionV1Envelope.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -84,6 +87,32 @@ public boolean equals(Object object) { return Objects.equal(this.tx, other.tx) && Arrays.equals(this.signatures, other.signatures); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TransactionV1Envelope fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TransactionV1Envelope fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Transaction tx; private DecoratedSignature[] signatures; diff --git a/src/main/java/org/stellar/sdk/xdr/TrustLineAsset.java b/src/main/java/org/stellar/sdk/xdr/TrustLineAsset.java index 1e1226026..09aab0c9e 100644 --- a/src/main/java/org/stellar/sdk/xdr/TrustLineAsset.java +++ b/src/main/java/org/stellar/sdk/xdr/TrustLineAsset.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -168,4 +171,30 @@ public boolean equals(Object object) { && Objects.equal(this.liquidityPoolID, other.liquidityPoolID) && Objects.equal(this.type, other.type); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TrustLineAsset fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TrustLineAsset fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/TrustLineEntry.java b/src/main/java/org/stellar/sdk/xdr/TrustLineEntry.java index f1c65dcc2..4cfca2ff5 100644 --- a/src/main/java/org/stellar/sdk/xdr/TrustLineEntry.java +++ b/src/main/java/org/stellar/sdk/xdr/TrustLineEntry.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -153,6 +156,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TrustLineEntry fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TrustLineEntry fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private AccountID accountID; private TrustLineAsset asset; @@ -203,7 +232,7 @@ public TrustLineEntry build() { } } - public static class TrustLineEntryExt { + public static class TrustLineEntryExt implements XdrElement { public TrustLineEntryExt() {} Integer v; @@ -295,7 +324,33 @@ public boolean equals(Object object) { return Objects.equal(this.v1, other.v1) && Objects.equal(this.v, other.v); } - public static class TrustLineEntryV1 { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TrustLineEntryExt fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TrustLineEntryExt fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class TrustLineEntryV1 implements XdrElement { public TrustLineEntryV1() {} private Liabilities liabilities; @@ -351,6 +406,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TrustLineEntryV1 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TrustLineEntryV1 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Liabilities liabilities; private TrustLineEntryV1Ext ext; @@ -373,7 +454,7 @@ public TrustLineEntryV1 build() { } } - public static class TrustLineEntryV1Ext { + public static class TrustLineEntryV1Ext implements XdrElement { public TrustLineEntryV1Ext() {} Integer v; @@ -465,6 +546,32 @@ public boolean equals(Object object) { TrustLineEntryV1Ext other = (TrustLineEntryV1Ext) object; return Objects.equal(this.v2, other.v2) && Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TrustLineEntryV1Ext fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TrustLineEntryV1Ext fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } } diff --git a/src/main/java/org/stellar/sdk/xdr/TrustLineEntryExtensionV2.java b/src/main/java/org/stellar/sdk/xdr/TrustLineEntryExtensionV2.java index 35c475dba..35ace927c 100644 --- a/src/main/java/org/stellar/sdk/xdr/TrustLineEntryExtensionV2.java +++ b/src/main/java/org/stellar/sdk/xdr/TrustLineEntryExtensionV2.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -80,6 +83,32 @@ public boolean equals(Object object) { && Objects.equal(this.ext, other.ext); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TrustLineEntryExtensionV2 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TrustLineEntryExtensionV2 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Int32 liquidityPoolUseCount; private TrustLineEntryExtensionV2Ext ext; @@ -102,7 +131,7 @@ public TrustLineEntryExtensionV2 build() { } } - public static class TrustLineEntryExtensionV2Ext { + public static class TrustLineEntryExtensionV2Ext implements XdrElement { public TrustLineEntryExtensionV2Ext() {} Integer v; @@ -174,5 +203,31 @@ public boolean equals(Object object) { TrustLineEntryExtensionV2Ext other = (TrustLineEntryExtensionV2Ext) object; return Objects.equal(this.v, other.v); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TrustLineEntryExtensionV2Ext fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TrustLineEntryExtensionV2Ext fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } } diff --git a/src/main/java/org/stellar/sdk/xdr/TrustLineFlags.java b/src/main/java/org/stellar/sdk/xdr/TrustLineFlags.java index 3f4be20b7..4e3c5698c 100644 --- a/src/main/java/org/stellar/sdk/xdr/TrustLineFlags.java +++ b/src/main/java/org/stellar/sdk/xdr/TrustLineFlags.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -58,4 +61,30 @@ public static void encode(XdrDataOutputStream stream, TrustLineFlags value) thro public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TrustLineFlags fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TrustLineFlags fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/TxAdvertVector.java b/src/main/java/org/stellar/sdk/xdr/TxAdvertVector.java index f186d6387..342600868 100644 --- a/src/main/java/org/stellar/sdk/xdr/TxAdvertVector.java +++ b/src/main/java/org/stellar/sdk/xdr/TxAdvertVector.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -67,4 +70,30 @@ public boolean equals(Object object) { TxAdvertVector other = (TxAdvertVector) object; return Arrays.equals(this.TxAdvertVector, other.TxAdvertVector); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TxAdvertVector fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TxAdvertVector fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/TxDemandVector.java b/src/main/java/org/stellar/sdk/xdr/TxDemandVector.java index 1cc302b63..43b3a5b06 100644 --- a/src/main/java/org/stellar/sdk/xdr/TxDemandVector.java +++ b/src/main/java/org/stellar/sdk/xdr/TxDemandVector.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -67,4 +70,30 @@ public boolean equals(Object object) { TxDemandVector other = (TxDemandVector) object; return Arrays.equals(this.TxDemandVector, other.TxDemandVector); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TxDemandVector fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TxDemandVector fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/TxSetComponent.java b/src/main/java/org/stellar/sdk/xdr/TxSetComponent.java index bb01ce02c..192a9a0e5 100644 --- a/src/main/java/org/stellar/sdk/xdr/TxSetComponent.java +++ b/src/main/java/org/stellar/sdk/xdr/TxSetComponent.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -114,7 +117,33 @@ public boolean equals(Object object) { && Objects.equal(this.type, other.type); } - public static class TxSetComponentTxsMaybeDiscountedFee { + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TxSetComponent fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TxSetComponent fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + + public static class TxSetComponentTxsMaybeDiscountedFee implements XdrElement { public TxSetComponentTxsMaybeDiscountedFee() {} private Int64 baseFee; @@ -189,6 +218,33 @@ public boolean equals(Object object) { return Objects.equal(this.baseFee, other.baseFee) && Arrays.equals(this.txs, other.txs); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TxSetComponentTxsMaybeDiscountedFee fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TxSetComponentTxsMaybeDiscountedFee fromXdrByteArray(byte[] xdr) + throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Int64 baseFee; private TransactionEnvelope[] txs; diff --git a/src/main/java/org/stellar/sdk/xdr/TxSetComponentType.java b/src/main/java/org/stellar/sdk/xdr/TxSetComponentType.java index 4b9408854..9c9d2e49d 100644 --- a/src/main/java/org/stellar/sdk/xdr/TxSetComponentType.java +++ b/src/main/java/org/stellar/sdk/xdr/TxSetComponentType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -48,4 +51,30 @@ public static void encode(XdrDataOutputStream stream, TxSetComponentType value) public void encode(XdrDataOutputStream stream) throws IOException { encode(stream, this); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static TxSetComponentType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static TxSetComponentType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/UInt128Parts.java b/src/main/java/org/stellar/sdk/xdr/UInt128Parts.java index e66e95183..1b3d039f7 100644 --- a/src/main/java/org/stellar/sdk/xdr/UInt128Parts.java +++ b/src/main/java/org/stellar/sdk/xdr/UInt128Parts.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -71,6 +74,32 @@ public boolean equals(Object object) { return Objects.equal(this.hi, other.hi) && Objects.equal(this.lo, other.lo); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static UInt128Parts fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static UInt128Parts fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint64 hi; private Uint64 lo; diff --git a/src/main/java/org/stellar/sdk/xdr/UInt256Parts.java b/src/main/java/org/stellar/sdk/xdr/UInt256Parts.java index f7151f260..8f8395708 100644 --- a/src/main/java/org/stellar/sdk/xdr/UInt256Parts.java +++ b/src/main/java/org/stellar/sdk/xdr/UInt256Parts.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -100,6 +103,32 @@ public boolean equals(Object object) { && Objects.equal(this.lo_lo, other.lo_lo); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static UInt256Parts fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static UInt256Parts fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private Uint64 hi_hi; private Uint64 hi_lo; diff --git a/src/main/java/org/stellar/sdk/xdr/Uint256.java b/src/main/java/org/stellar/sdk/xdr/Uint256.java index bd7832e1a..a2ae110cc 100644 --- a/src/main/java/org/stellar/sdk/xdr/Uint256.java +++ b/src/main/java/org/stellar/sdk/xdr/Uint256.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -61,4 +64,30 @@ public boolean equals(Object object) { Uint256 other = (Uint256) object; return Arrays.equals(this.uint256, other.uint256); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Uint256 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Uint256 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Uint32.java b/src/main/java/org/stellar/sdk/xdr/Uint32.java index 8c66f883f..3ebbdd803 100644 --- a/src/main/java/org/stellar/sdk/xdr/Uint32.java +++ b/src/main/java/org/stellar/sdk/xdr/Uint32.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -58,4 +61,30 @@ public boolean equals(Object object) { Uint32 other = (Uint32) object; return Objects.equal(this.uint32, other.uint32); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Uint32 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Uint32 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Uint64.java b/src/main/java/org/stellar/sdk/xdr/Uint64.java index 819c554d6..698c44ecc 100644 --- a/src/main/java/org/stellar/sdk/xdr/Uint64.java +++ b/src/main/java/org/stellar/sdk/xdr/Uint64.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -58,4 +61,30 @@ public boolean equals(Object object) { Uint64 other = (Uint64) object; return Objects.equal(this.uint64, other.uint64); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Uint64 fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Uint64 fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/UpgradeEntryMeta.java b/src/main/java/org/stellar/sdk/xdr/UpgradeEntryMeta.java index 1eb4bbd40..d85a4b994 100644 --- a/src/main/java/org/stellar/sdk/xdr/UpgradeEntryMeta.java +++ b/src/main/java/org/stellar/sdk/xdr/UpgradeEntryMeta.java @@ -6,6 +6,9 @@ import static org.stellar.sdk.xdr.Constants.*; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; // === xdr source ============================================================ @@ -72,6 +75,32 @@ public boolean equals(Object object) { return Objects.equal(this.upgrade, other.upgrade) && Objects.equal(this.changes, other.changes); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static UpgradeEntryMeta fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static UpgradeEntryMeta fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + public static final class Builder { private LedgerUpgrade upgrade; private LedgerEntryChanges changes; diff --git a/src/main/java/org/stellar/sdk/xdr/UpgradeType.java b/src/main/java/org/stellar/sdk/xdr/UpgradeType.java index cdd8d52de..16a090c60 100644 --- a/src/main/java/org/stellar/sdk/xdr/UpgradeType.java +++ b/src/main/java/org/stellar/sdk/xdr/UpgradeType.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -63,4 +66,30 @@ public boolean equals(Object object) { UpgradeType other = (UpgradeType) object; return Arrays.equals(this.UpgradeType, other.UpgradeType); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static UpgradeType fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static UpgradeType fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/Value.java b/src/main/java/org/stellar/sdk/xdr/Value.java index c8b719389..86c1b6d04 100644 --- a/src/main/java/org/stellar/sdk/xdr/Value.java +++ b/src/main/java/org/stellar/sdk/xdr/Value.java @@ -5,6 +5,9 @@ import static org.stellar.sdk.xdr.Constants.*; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -62,4 +65,30 @@ public boolean equals(Object object) { Value other = (Value) object; return Arrays.equals(this.Value, other.Value); } + + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static Value fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static Value fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } } diff --git a/src/main/java/org/stellar/sdk/xdr/XdrElement.java b/src/main/java/org/stellar/sdk/xdr/XdrElement.java index fffc167ed..511360659 100644 --- a/src/main/java/org/stellar/sdk/xdr/XdrElement.java +++ b/src/main/java/org/stellar/sdk/xdr/XdrElement.java @@ -5,4 +5,8 @@ /** Common parent interface for all generated classes. */ interface XdrElement { void encode(XdrDataOutputStream stream) throws IOException; + + String toXdrBase64() throws IOException; + + byte[] toXdrByteArray() throws IOException; } diff --git a/src/main/java/org/stellar/sdk/xdr/XdrString.java b/src/main/java/org/stellar/sdk/xdr/XdrString.java index ab0e0ff24..df1bdea8b 100644 --- a/src/main/java/org/stellar/sdk/xdr/XdrString.java +++ b/src/main/java/org/stellar/sdk/xdr/XdrString.java @@ -1,5 +1,8 @@ package org.stellar.sdk.xdr; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InvalidClassException; import java.nio.charset.Charset; @@ -36,6 +39,40 @@ public byte[] getBytes() { return this.bytes; } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes, maxSize); + } + + public static XdrString fromXdrBase64(String xdr) throws IOException { + return fromXdrBase64(xdr, Integer.MAX_VALUE); + } + + public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream, maxSize); + } + + public static XdrString fromXdrByteArray(byte[] xdr) throws IOException { + return fromXdrByteArray(xdr, Integer.MAX_VALUE); + } + @Override public int hashCode() { return Arrays.hashCode(this.bytes); diff --git a/src/main/java/org/stellar/sdk/xdr/XdrUnsignedHyperInteger.java b/src/main/java/org/stellar/sdk/xdr/XdrUnsignedHyperInteger.java index 8ef477129..ada4b6e31 100644 --- a/src/main/java/org/stellar/sdk/xdr/XdrUnsignedHyperInteger.java +++ b/src/main/java/org/stellar/sdk/xdr/XdrUnsignedHyperInteger.java @@ -1,6 +1,9 @@ package org.stellar.sdk.xdr; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.math.BigInteger; @@ -56,6 +59,32 @@ public BigInteger getNumber() { return number; } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static XdrUnsignedHyperInteger fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + @Override public int hashCode() { return Objects.hashCode(this.number); diff --git a/src/main/java/org/stellar/sdk/xdr/XdrUnsignedInteger.java b/src/main/java/org/stellar/sdk/xdr/XdrUnsignedInteger.java index b717ccd6e..37c5c3cf9 100644 --- a/src/main/java/org/stellar/sdk/xdr/XdrUnsignedInteger.java +++ b/src/main/java/org/stellar/sdk/xdr/XdrUnsignedInteger.java @@ -1,6 +1,9 @@ package org.stellar.sdk.xdr; import com.google.common.base.Objects; +import com.google.common.io.BaseEncoding; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; /** @@ -44,6 +47,32 @@ public void encode(XdrDataOutputStream stream) throws IOException { stream.writeInt(number.intValue()); } + @Override + public String toXdrBase64() throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + return base64Encoding.encode(toXdrByteArray()); + } + + @Override + public byte[] toXdrByteArray() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); + encode(xdrDataOutputStream); + return byteArrayOutputStream.toByteArray(); + } + + public static XdrUnsignedInteger fromXdrBase64(String xdr) throws IOException { + BaseEncoding base64Encoding = BaseEncoding.base64(); + byte[] bytes = base64Encoding.decode(xdr); + return fromXdrByteArray(bytes); + } + + public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); + XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); + return decode(xdrDataInputStream); + } + @Override public int hashCode() { return Objects.hashCode(this.number); diff --git a/src/test/java/org/stellar/sdk/SorobanServerTest.java b/src/test/java/org/stellar/sdk/SorobanServerTest.java index 7aae8ae34..57bba78ee 100644 --- a/src/test/java/org/stellar/sdk/SorobanServerTest.java +++ b/src/test/java/org/stellar/sdk/SorobanServerTest.java @@ -843,7 +843,7 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) Transaction newTx = server.prepareTransaction(transaction); SorobanTransactionData sorobanData = - Util.sorobanTransactionDataToXDR( + SorobanTransactionData.fromXdrBase64( "AAAAAAAAAAIAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAFAAAAAEAAAAAAAAAB300Hyg0HZG+Qie3zvsxLvugrNtFqd3AIntWy9bg2YvZAAAAAAAAAAEAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAEAAAAAEAAAACAAAADwAAAAdDb3VudGVyAAAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAQAAAAAAFcLDAAAF8AAAAQgAAAMcAAAAAAAAAJw="); InvokeHostFunctionOperation operation = InvokeHostFunctionOperation.builder() @@ -962,7 +962,7 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) Transaction newTx = server.prepareTransaction(transaction); SorobanTransactionData sorobanData = - Util.sorobanTransactionDataToXDR( + SorobanTransactionData.fromXdrBase64( "AAAAAAAAAAIAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAFAAAAAEAAAAAAAAAB300Hyg0HZG+Qie3zvsxLvugrNtFqd3AIntWy9bg2YvZAAAAAAAAAAEAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAEAAAAAEAAAACAAAADwAAAAdDb3VudGVyAAAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAQAAAAAAFcLDAAAF8AAAAQgAAAMcAAAAAAAAAJw="); InvokeHostFunctionOperation operation = InvokeHostFunctionOperation.builder() @@ -1091,7 +1091,7 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) Transaction newTx = server.prepareTransaction(transaction); SorobanTransactionData sorobanData = - Util.sorobanTransactionDataToXDR( + SorobanTransactionData.fromXdrBase64( "AAAAAAAAAAIAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAFAAAAAEAAAAAAAAAB300Hyg0HZG+Qie3zvsxLvugrNtFqd3AIntWy9bg2YvZAAAAAAAAAAEAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAEAAAAAEAAAACAAAADwAAAAdDb3VudGVyAAAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAQAAAAAAFcLDAAAF8AAAAQgAAAMcAAAAAAAAAJw="); InvokeHostFunctionOperation operation = InvokeHostFunctionOperation.builder() diff --git a/src/test/java/org/stellar/sdk/TransactionBuilderTest.java b/src/test/java/org/stellar/sdk/TransactionBuilderTest.java index 2e6ca7f84..8e525e676 100644 --- a/src/test/java/org/stellar/sdk/TransactionBuilderTest.java +++ b/src/test/java/org/stellar/sdk/TransactionBuilderTest.java @@ -1068,7 +1068,7 @@ public void voidBuilderSorobanDataXdrString() { } @Test - public void voidBuilderSorobanDataXdrObject() { + public void voidBuilderSorobanDataXdrObject() throws IOException { KeyPair source = KeyPair.fromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); KeyPair destination = @@ -1102,7 +1102,7 @@ public void voidBuilderSorobanDataXdrObject() { .refundableFee(new Int64(100L)) .ext(new ExtensionPoint.Builder().discriminant(0).build()) .build(); - String sorobanDataString = Util.xdrToSorobanTransactionData(sorobanData); + String sorobanDataString = sorobanData.toXdrBase64(); CreateContractArgs createContractArgs = new CreateContractArgs.Builder() diff --git a/src/test/java/org/stellar/sdk/UtilTest.java b/src/test/java/org/stellar/sdk/UtilTest.java deleted file mode 100644 index b362c2e63..000000000 --- a/src/test/java/org/stellar/sdk/UtilTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.stellar.sdk; - -import static org.junit.Assert.assertEquals; -import static org.stellar.sdk.Util.xdrToSorobanTransactionData; - -import org.junit.Test; -import org.stellar.sdk.xdr.*; - -public class UtilTest { - @Test - public void testXdrToSorobanTransactionData() { - LedgerKey ledgerKey = - new LedgerKey.Builder() - .discriminant(LedgerEntryType.ACCOUNT) - .account( - new LedgerKey.LedgerKeyAccount.Builder() - .accountID( - KeyPair.fromAccountId( - "GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO") - .getXdrAccountId()) - .build()) - .build(); - SorobanTransactionData sorobanData = - new SorobanTransactionData.Builder() - .resources( - new SorobanResources.Builder() - .footprint( - new LedgerFootprint.Builder() - .readOnly(new LedgerKey[] {ledgerKey}) - .readWrite(new LedgerKey[] {}) - .build()) - .extendedMetaDataSizeBytes(new Uint32(new XdrUnsignedInteger(216))) - .readBytes(new Uint32(new XdrUnsignedInteger(699))) - .writeBytes(new Uint32(new XdrUnsignedInteger(0))) - .instructions(new Uint32(new XdrUnsignedInteger(34567))) - .build()) - .refundableFee(new Int64(100L)) - .ext(new ExtensionPoint.Builder().discriminant(0).build()) - .build(); - String data = xdrToSorobanTransactionData(sorobanData); - String expected = - "AAAAAAAAAAEAAAAAAAAAAH8wYjTJienWf2nf2TEZi2APPWzmtkwiQHAftisIgyuHAAAAAAAAhwcAAAK7AAAAAAAAANgAAAAAAAAAZA=="; - assertEquals(expected, data); - } -} diff --git a/xdr/Stellar-transaction.x b/xdr/Stellar-transaction.x index 40768fea9..ca6308f5e 100644 --- a/xdr/Stellar-transaction.x +++ b/xdr/Stellar-transaction.x @@ -817,7 +817,7 @@ struct SorobanResources uint32 writeBytes; // Maximum size of dynamic metadata produced by this contract ( - // bytes read from ledger + bytes written to ledger + event bytes written to meta). + // currently only includes the events). uint32 extendedMetaDataSizeBytes; }; @@ -1793,8 +1793,7 @@ enum InvokeHostFunctionResultCode // codes considered as "failure" for the operation INVOKE_HOST_FUNCTION_MALFORMED = -1, INVOKE_HOST_FUNCTION_TRAPPED = -2, - INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3, - INVOKE_HOST_FUNCTION_ENTRY_EXPIRED = -4 + INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3 }; union InvokeHostFunctionResult switch (InvokeHostFunctionResultCode code) @@ -1804,7 +1803,6 @@ case INVOKE_HOST_FUNCTION_SUCCESS: case INVOKE_HOST_FUNCTION_MALFORMED: case INVOKE_HOST_FUNCTION_TRAPPED: case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: -case INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: void; };