From db6dd5ba37e8e207aad47c3fe2deb4d33ff1b0cb Mon Sep 17 00:00:00 2001 From: Sunny G Date: Wed, 1 Aug 2018 20:55:54 -0700 Subject: [PATCH 1/2] updates :xdr, updates XDR types, beginning to remaining XDR types --- .iex.exs | 10 + lib/stellar/xdr/types/ledger.ex | 78 +++ lib/stellar/xdr/types/ledger_entries.ex | 234 +++---- lib/stellar/xdr/types/transaction.ex | 772 +++++++++++------------- lib/stellar/xdr/types/types.ex | 87 +-- mix.exs | 2 +- mix.lock | 4 +- 7 files changed, 575 insertions(+), 612 deletions(-) create mode 100644 .iex.exs create mode 100644 lib/stellar/xdr/types/ledger.ex diff --git a/.iex.exs b/.iex.exs new file mode 100644 index 0000000..28fc263 --- /dev/null +++ b/.iex.exs @@ -0,0 +1,10 @@ +alias Stellar.XDR.Types + +ledger_header_data = "AAAACcks7SEfHkDuhjvmvF+gKaINj3tDOa5WM4nJwaN5sMyn1D/Cw44W08u6FCpdM/FQHQ4aeskY9MAlKlq6A/xO1QgAAAAAW2I60gAAAAAAAAAAIlFSBMfJDmczeRK3yru+7i4ES6ft6COlHIPOJfE8FTaOu1onEG4cVZMH2qvVXAMaAjFjS2Qz7RANhJ/R0CQQMACdlSEOc/6udibiZAA/v9/PJqaoAAAA1gAAAAAACJANAAAAZABMS0AAAAAyKM0WUC2QMHCSFH/B9hVSscs79BALzSpdRqiLtUxd7Pio/PUHmpYDSdUYvqfv5dJ2Y68U/0aj6MiccIg/RjGiP9WP/ufHKMzernlVpSy2Nh2GFKq7QlkwfqBbXFvCMpcNnLfxQtZ/DqPjHr85qQBYJwxJfEmU2jRhLpMSgIFiFSIAAAAA" + +ledger_header = + ledger_header_data + |> Base.decode64! + |> IO.inspect(label: :ledger_header_binary) + |> Types.Ledger.LedgerHeader.decode + |> IO.inspect(label: :ledger_header) diff --git a/lib/stellar/xdr/types/ledger.ex b/lib/stellar/xdr/types/ledger.ex new file mode 100644 index 0000000..1b0fc30 --- /dev/null +++ b/lib/stellar/xdr/types/ledger.ex @@ -0,0 +1,78 @@ +defmodule Stellar.XDR.Types.Ledger do + alias XDR.Type.{ + Enum, + FixedArray, + Union, + VariableArray, + VariableOpaque, + Void + } + + alias Stellar.XDR.Types.{ + Hash, + Int32, + Int64, + UInt32, + UInt64 + } + + defmodule Ext do + use Union, + switch: Int32, + cases: [ + {0, Void} + ] + end + + defmodule UpgradeType do + use VariableOpaque, max_len: 128 + end + + defmodule Upgrades do + use VariableArray, max_len: 6, type: UpgradeType + end + + defmodule StellarValue do + require Ext + + use XDR.Type.Struct, + txSetHash: Hash, + closeTime: UInt64, + upgrades: Upgrades, + ext: Ext + end + + defmodule SkipList do + require Stellar.XDR.Types.Hash + use FixedArray, len: 4, type: Stellar.XDR.Types.Hash + end + + defmodule LedgerHeader do + require Ext + + use XDR.Type.Struct, + ledgerVersion: UInt32, + previousLedgerHash: Hash, + scpValue: StellarValue, + txSetResultHash: Hash, + bucketListHash: Hash, + ledgerSeq: UInt32, + totalCoins: Int64, + feePool: Int64, + inflationSeq: UInt32, + idPool: UInt64, + baseFee: UInt32, + baseReserve: UInt32, + maxTxSetSize: UInt32, + skipList: SkipList, + ext: Ext + end + + defmodule LedgerUpgradeType do + use Enum, + LEDGER_UPGRADE_VERSION: 1, + LEDGER_UPGRADE_BASE_FEE: 2, + LEDGER_UPGRADE_MAX_TX_SET_SIZE: 3, + LEDGER_UPGRADE_BASE_RESERVE: 4 + end +end diff --git a/lib/stellar/xdr/types/ledger_entries.ex b/lib/stellar/xdr/types/ledger_entries.ex index 4473c95..4630477 100644 --- a/lib/stellar/xdr/types/ledger_entries.ex +++ b/lib/stellar/xdr/types/ledger_entries.ex @@ -1,30 +1,42 @@ defmodule Stellar.XDR.Types.LedgerEntries do alias XDR.Type.{ - FixedOpaque, Enum, + FixedOpaque, Union, + VariableArray, VariableOpaque, - Void, - Int, - Uint, - HyperInt, - HyperUint, - VariableArray + Void } - alias Stellar.XDR.Types.SignerKey - alias Stellar.XDR.Types.PublicKey, as: AccountID + alias Stellar.XDR.Types.{ + Int32, + Int64, + PublicKey, + SignerKey, + UInt32, + UInt64 + } + + alias PublicKey, as: AccountID defmodule Thresholds do use FixedOpaque, len: 4 end + defmodule Ext do + use Union, + switch: Int32, + cases: [ + {0, Void} + ] + end + defmodule String32 do - use VariableArray, spec: [max_len: 32, type: XDR.Type.String] + use VariableArray, max_len: 32, type: XDR.Type.String end defmodule String64 do - use VariableArray, spec: [max_len: 64, type: XDR.Type.String] + use VariableArray, max_len: 64, type: XDR.Type.String end defmodule DataValue do @@ -33,22 +45,18 @@ defmodule Stellar.XDR.Types.LedgerEntries do defmodule AssetType do use Enum, - spec: [ - ASSET_TYPE_NATIVE: 0, - ASSET_TYPE_CREDIT_ALPHANUM4: 1, - ASSET_TYPE_CREDIT_ALPHANUM12: 2 - ] + ASSET_TYPE_NATIVE: 0, + ASSET_TYPE_CREDIT_ALPHANUM4: 1, + ASSET_TYPE_CREDIT_ALPHANUM12: 2 end defmodule Asset do use Union, - spec: [ - switch: AssetType, - cases: [ - {0, Void}, - {1, AssetTypeCreditAlphaNum4}, - {2, AssetTypeCreditAlphaNum12} - ] + switch: AssetType, + cases: [ + {0, Void}, + {1, AssetTypeCreditAlphaNum4}, + {2, AssetTypeCreditAlphaNum12} ] end @@ -62,173 +70,131 @@ defmodule Stellar.XDR.Types.LedgerEntries do defmodule AssetTypeCreditAlphaNum4 do use XDR.Type.Struct, - spec: [ - assetCode: AssetCode4, - issuer: AccountID - ] + assetCode: AssetCode4, + issuer: AccountID end defmodule AssetTypeCreditAlphaNum12 do use XDR.Type.Struct, - spec: [ - assetCode: AssetCode12, - issuer: AccountID - ] + assetCode: AssetCode12, + issuer: AccountID end defmodule Price do use XDR.Type.Struct, - spec: [ - n: Int, - d: Int - ] + n: Int32, + d: Int32 end defmodule ThresholdIndexes do use Enum, - spec: [ - THRESHOLD_MASTER_WEIGHT: 0, - THRESHOLD_LOW: 1, - THRESHOLD_MED: 2, - THRESHOLD_HIGH: 3 - ] + THRESHOLD_MASTER_WEIGHT: 0, + THRESHOLD_LOW: 1, + THRESHOLD_MED: 2, + THRESHOLD_HIGH: 3 end defmodule LedgerEntryType do use Enum, - spec: [ - ACCOUNT: 0, - TRUSTLINE: 1, - OFFER: 2, - DATA: 3 - ] + ACCOUNT: 0, + TRUSTLINE: 1, + OFFER: 2, + DATA: 3 end defmodule Signer do use XDR.Type.Struct, - spec: [ - key: SignerKey, - weight: Uint - ] + key: SignerKey, + weight: UInt32 + end + + defmodule Signers do + use VariableArray, max_len: 20, type: Signer end defmodule AccountFlags do use Enum, - spec: [ - AUTH_REQUIRED_FLAG: 0x1, - AUTH_REVOCABLE_FLAG: 0x2, - AUTH_IMMUTABLE_FLAG: 0x4 - ] + AUTH_REQUIRED_FLAG: 0x1, + AUTH_REVOCABLE_FLAG: 0x2, + AUTH_IMMUTABLE_FLAG: 0x4 end defmodule AccountEntry do use XDR.Type.Struct, - spec: [ - accountID: AccountID, - balance: HyperInt, - seqNum: HyperUint, - numSubEntries: Uint, - inflationDest: AccountID, - flags: Uint, - homeDomain: XDR.Type.String, - thresholds: Thresholds, - signers: Signers, - ext: Ext - ] - - defmodule Signers do - use VariableArray, spec: [max_len: 20, type: Signer] - end - end - - defmodule Ext do - use Union, - spec: [ - switch: Int, - cases: [ - {0, Void} - ] - ] + accountID: AccountID, + balance: Int64, + seqNum: UInt64, + numSubEntries: UInt32, + inflationDest: AccountID, + flags: UInt32, + homeDomain: XDR.Type.String, + thresholds: Thresholds, + signers: Signers, + ext: Ext end defmodule TrustLineFlags do use Enum, - spec: [ - AUTHORIZED_FLAG: 1 - ] + AUTHORIZED_FLAG: 1 end defmodule TrustLineEntry do use XDR.Type.Struct, - spec: [ - accountID: AccountID, - asset: Asset, - balance: HyperInt, - limit: HyperInt, - flags: Uint, - ext: Ext - ] + accountID: AccountID, + asset: Asset, + balance: Int64, + limit: Int64, + flags: UInt32, + ext: Ext end defmodule OfferEntryFlags do use Enum, - spec: [ - PASSIVE_FLAG: 1 - ] + PASSIVE_FLAG: 1 end defmodule OfferEntry do use XDR.Type.Struct, - spec: [ - sellerID: AccountID, - offerID: HyperUint, - selling: Asset, - buying: Asset, - amount: HyperInt, - price: Price, - flags: Uint, - ext: Ext - ] + sellerID: AccountID, + offerID: UInt64, + selling: Asset, + buying: Asset, + amount: Int64, + price: Price, + flags: UInt32, + ext: Ext end defmodule DataEntry do use XDR.Type.Struct, - spec: [ - accountID: AccountID, - dataName: String64, - dataValue: DataValue, - ext: Ext + accountID: AccountID, + dataName: String64, + dataValue: DataValue, + ext: Ext + end + + defmodule LedgerEntryData do + use Union, + switch: LedgerEntryType, + cases: [ + {0, AccountEntry}, + {1, TrustLineEntry}, + {2, OfferEntry}, + {3, DataEntry} ] end defmodule LedgerEntry do use XDR.Type.Struct, - spec: [ - lastModifiedLedgerSeq: Uint, - data: Data, - ext: Ext - ] - - defmodule Data do - use Union, - spec: [ - switch: LedgerEntryType, - cases: [ - {0, AccountEntry}, - {1, TrustLineEntry}, - {2, OfferEntry}, - {3, DataEntry} - ] - ] - end + lastModifiedLedgerSeq: UInt32, + data: LedgerEntryData, + ext: Ext end defmodule EnvelopeType do use Enum, - spec: [ - ENVELOPE_TYPE_SCP: 1, - ENVELOPE_TYPE_TX: 2, - ENVELOPE_TYPE_AUTH: 3 - ] + ENVELOPE_TYPE_SCP: 1, + ENVELOPE_TYPE_TX: 2, + ENVELOPE_TYPE_AUTH: 3 end end diff --git a/lib/stellar/xdr/types/transaction.ex b/lib/stellar/xdr/types/transaction.ex index a343399..46c2492 100644 --- a/lib/stellar/xdr/types/transaction.ex +++ b/lib/stellar/xdr/types/transaction.ex @@ -3,666 +3,568 @@ defmodule Stellar.XDR.Types.Transaction do Enum, Union, Void, - Int, - Uint, - HyperInt, - HyperUint, - VariableArray, - Uint + VariableArray } - alias Stellar.XDR.Types.{SignatureHint, Signature, Hash} - alias Stellar.XDR.Types.PublicKey, as: AccountID + alias Stellar.XDR.Types.{ + Hash, + Int32, + Int64, + LedgerEntries, + PublicKey, + Signature, + SignatureHint, + UInt32, + UInt64 + } - alias Stellar.Types.LedgerEntries.{ + alias LedgerEntries.{ Asset, - Price, - String32, - Signer, + AssetType, AssetCode4, AssetCode12, - String64, DataValue, - Ext, - OfferEntry + OfferEntry, + Price, + Signer, + String32, + String64 } + alias PublicKey, as: AccountID + + defmodule Ext do + use Union, + switch: Int32, + cases: [ + {0, Void} + ] + end + defmodule DecoratedSignature do use XDR.Type.Struct, - spec: [ - hint: SignatureHint, - signature: Signature - ] + hint: SignatureHint, + signature: Signature + end + + defmodule DecoratedSignatures do + use VariableArray, max_len: 20, type: DecoratedSignature + end + + defmodule AssetPaths do + use VariableArray, max_len: 5, type: Asset end defmodule OperationType do use Enum, - spec: [ - CREATE_ACCOUNT: 0, - PAYMENT: 1, - PATH_PAYMENT: 2, - MANAGE_OFFER: 3, - CREATE_PASSIVE_OFFER: 4, - SET_OPTIONS: 5, - CHANGE_TRUST: 6, - ALLOW_TRUST: 7, - ACCOUNT_MERGE: 8, - INFLATION: 9, - MANAGE_DATA: 10 - ] + CREATE_ACCOUNT: 0, + PAYMENT: 1, + PATH_PAYMENT: 2, + MANAGE_OFFER: 3, + CREATE_PASSIVE_OFFER: 4, + SET_OPTIONS: 5, + CHANGE_TRUST: 6, + ALLOW_TRUST: 7, + ACCOUNT_MERGE: 8, + INFLATION: 9, + MANAGE_DATA: 10 end defmodule CreateAccountOp do use XDR.Type.Struct, - spec: [ - destination: AccountID, - startingBalance: HyperInt - ] + destination: AccountID, + startingBalance: Int64 end defmodule PaymentOp do use XDR.Type.Struct, - spec: [ - destination: AccountID, - asset: Asset, - amount: HyperInt - ] + destination: AccountID, + asset: Asset, + amount: Int64 end defmodule PathPaymentOp do use XDR.Type.Struct, - spec: [ - sendAsset: Asset, - sendMax: HyperInt, - destination: AccountID, - destinationAsset: Asset, - destinationAmount: HyperInt, - path: AssetPaths - ] - - defmodule AssetPaths do - use VariableArray, spec: [max_len: 5, type: Asset] - end + sendAsset: Asset, + sendMax: Int64, + destination: AccountID, + destinationAsset: Asset, + destinationAmount: Int64, + path: AssetPaths end defmodule ManageOfferOp do use XDR.Type.Struct, - spec: [ - selling: Asset, - buying: Asset, - amount: HyperInt, - price: Price, - offerID: HyperUint - ] + selling: Asset, + buying: Asset, + amount: Int64, + price: Price, + offerID: UInt64 end defmodule CreatePassiveOfferOp do use XDR.Type.Struct, - spec: [ - selling: Asset, - buying: Asset, - amount: HyperInt, - price: Price - ] + selling: Asset, + buying: Asset, + amount: Int64, + price: Price end defmodule SetOptionsOp do use XDR.Type.Struct, - spec: [ - inflationDest: AccountID, - clearFlags: Uint, - setFlags: Uint, - masterWeight: Uint, - lowThreshold: Uint, - medThreshold: Uint, - highThreshold: Uint, - homeDomain: String32, - signer: Signer - ] + inflationDest: AccountID, + clearFlags: UInt32, + setFlags: UInt32, + masterWeight: UInt32, + lowThreshold: UInt32, + medThreshold: UInt32, + highThreshold: UInt32, + homeDomain: String32, + signer: Signer end defmodule ChangeTrustOp do use XDR.Type.Struct, - spec: [ - line: Asset, - limit: HyperInt + line: Asset, + limit: Int64 + end + + defmodule Asset do + use Union, + switch: AssetType, + cases: [ + {1, AssetCode4}, + {2, AssetCode12} ] end defmodule AllowTrustOp do use XDR.Type.Struct, - spec: [ - trustor: AccountID, - asset: Asset - ] - - defmodule Asset do - use Union, - spec: [ - switch: AssetType, - cases: [ - {1, AssetCode4}, - {2, AssetCode12} - ] - ] - end + trustor: AccountID, + asset: Asset end defmodule ManageDataOp do use XDR.Type.Struct, - spec: [ - dataName: String64, - dataValue: DataValue + dataName: String64, + dataValue: DataValue + end + + defmodule OperationUnion do + use Union, + switch: OperationType, + cases: [ + {0, CreateAccountOp}, + {1, PaymentOp}, + {2, PathPaymentOp}, + {3, ManageOfferOp}, + {4, CreatePassiveOfferOp}, + {5, SetOptionsOp}, + {6, ChangeTrustOp}, + {7, AllowTrustOp}, + {8, AccountID}, + {9, Void}, + {10, ManageDataOp} ] end defmodule Operation do use XDR.Type.Struct, - spec: [ - sourceAccount: AccountID, - body: OperationUnion - ] + sourceAccount: AccountID, + body: OperationUnion + end - defmodule OperationUnion do - use Union, - spec: [ - switch: OperationType, - cases: [ - {0, CreateAccountOp}, - {1, PaymentOp}, - {2, PathPaymentOp}, - {3, ManageOfferOp}, - {4, CreatePassiveOfferOp}, - {5, SetOptionsOp}, - {6, ChangeTrustOp}, - {7, AllowTrustOp}, - {8, AccountID}, - {9, Void}, - {10, ManageDataOp} - ] - ] - end + defmodule Operations do + use VariableArray, max_len: 100, type: Operation end defmodule MemoType do use Enum, - spec: [ - MEMO_NONE: 0, - MEMO_TEXT: 1, - MEMO_ID: 2, - MEMO_HASH: 3, - MEMO_RETURN: 4 - ] + MEMO_NONE: 0, + MEMO_TEXT: 1, + MEMO_ID: 2, + MEMO_HASH: 3, + MEMO_RETURN: 4 end defmodule Text do - use VariableArray, spec: [max_len: 28, type: XDR.Type.String] + use VariableArray, max_len: 28, type: XDR.Type.String end defmodule Memo do use Union, - spec: [ - switch: MemoType, - cases: [ - {0, Void}, - {1, Text}, - {2, HyperUint}, - {3, Hash}, - {4, Hash} - ] + switch: MemoType, + cases: [ + {0, Void}, + {1, Text}, + {2, UInt64}, + {3, Hash}, + {4, Hash} ] end defmodule TimeBounds do use XDR.Type.Struct, - spec: [ - minTime: HyperUint, - maxTime: HyperUint - ] + minTime: UInt64, + maxTime: UInt64 end defmodule Transaction do use XDR.Type.Struct, - spec: [ - sourceAccount: AccountID, - fee: Int, - seqNum: HyperUint, - timeBounds: TimeBounds, - memo: Memo, - operations: Operations, - ext: Ext - ] + sourceAccount: AccountID, + fee: Int32, + seqNum: UInt64, + timeBounds: TimeBounds, + memo: Memo, + operations: Operations, + ext: Ext + end - defmodule Operations do - use VariableArray, spec: [max_len: 100, type: Operation] - end + defmodule TaggedTransaction do + use Union, + switch: MemoType, + cases: [ + {0, Transaction} + ] end defmodule TransactionSignaturePayload do use XDR.Type.Struct, - spec: [ - networkId: Hash, - taggedTransaction: TaggedTransaction - ] - - defmodule TaggedTransaction do - use Union, - spec: [ - switch: MemoType, - cases: [ - {0, Transaction} - ] - ] - end + networkId: Hash, + taggedTransaction: TaggedTransaction end defmodule TransactionEnvelope do use XDR.Type.Struct, - spec: [ - tx: Transaction, - signatures: DecoratedSignatures - ] - - defmodule DecoratedSignatures do - use VariableArray, spec: [max_len: 20, type: DecoratedSignature] - end + tx: Transaction, + signatures: DecoratedSignatures end defmodule ClaimOfferAtom do use XDR.Type.Struct, - spec: [ - sellerID: AccountID, - offerID: HyperUint, - assetSold: Asset, - amountSold: HyperInt, - assetBought: Asset, - amountBought: HyperInt - ] + sellerID: AccountID, + offerID: UInt64, + assetSold: Asset, + amountSold: Int64, + assetBought: Asset, + amountBought: Int64 + end + + defmodule ClaimOfferAtoms do + use VariableArray, type: ClaimOfferAtom end defmodule CreateAccountResultCode do use Enum, - spec: [ - CREATE_ACCOUNT_SUCCESS: 0, - CREATE_ACCOUNT_MALFORMED: -1, - CREATE_ACCOUNT_UNDERFUNDED: -2, - CREATE_ACCOUNT_LOW_RESERVE: -3, - CREATE_ACCOUNT_ALREADY_EXIST: -4 - ] + CREATE_ACCOUNT_SUCCESS: 0, + CREATE_ACCOUNT_MALFORMED: -1, + CREATE_ACCOUNT_UNDERFUNDED: -2, + CREATE_ACCOUNT_LOW_RESERVE: -3, + CREATE_ACCOUNT_ALREADY_EXIST: -4 end defmodule CreateAccountResult do use Union, - spec: [ - switch: CreateAccountResultCode, - cases: [ - {0, VOID} - ] + switch: CreateAccountResultCode, + cases: [ + {0, VOID} ] end defmodule PaymentResultCode do use Enum, - spec: [ - PAYMENT_SUCCESS: 0, - PAYMENT_MALFORMED: -1, - PAYMENT_UNDERFUNDED: -2, - PAYMENT_SRC_NO_TRUST: -3, - PAYMENT_SRC_NOT_AUTHORIZED: -4, - PAYMENT_NO_DESTINATION: -5, - PAYMENT_NO_TRUST: -6, - PAYMENT_NOT_AUTHORIZED: -7, - PAYMENT_LINE_FULL: -8, - PAYMENT_NO_ISSUER: -9 - ] + PAYMENT_SUCCESS: 0, + PAYMENT_MALFORMED: -1, + PAYMENT_UNDERFUNDED: -2, + PAYMENT_SRC_NO_TRUST: -3, + PAYMENT_SRC_NOT_AUTHORIZED: -4, + PAYMENT_NO_DESTINATION: -5, + PAYMENT_NO_TRUST: -6, + PAYMENT_NOT_AUTHORIZED: -7, + PAYMENT_LINE_FULL: -8, + PAYMENT_NO_ISSUER: -9 end defmodule PaymentResult do use Union, - spec: [ - switch: PaymentResultCode, - cases: [ - {0, VOID} - ] + switch: PaymentResultCode, + cases: [ + {0, VOID} ] end defmodule PathPaymentResultCode do use Enum, - spec: [ - PATH_PAYMENT_SUCCESS: 0, - PATH_PAYMENT_MALFORMED: -1, - PATH_PAYMENT_UNDERFUNDED: -2, - PATH_PAYMENT_SRC_NO_TRUST: -3, - PATH_PAYMENT_SRC_NOT_AUTHORIZED: -4, - PATH_PAYMENT_NO_DESTINATION: -5, - PATH_PAYMENT_NO_TRUST: -6, - PATH_PAYMENT_NOT_AUTHORIZED: -7, - PATH_PAYMENT_LINE_FULL: -8, - PATH_PAYMENT_NO_ISSUER: -9, - PATH_PAYMENT_TOO_FEW_OFFERS: -10, - PATH_PAYMENT_OFFER_CROSS_SELF: -11, - PATH_PAYMENT_OVER_SENDMAX: -12 - ] + PATH_PAYMENT_SUCCESS: 0, + PATH_PAYMENT_MALFORMED: -1, + PATH_PAYMENT_UNDERFUNDED: -2, + PATH_PAYMENT_SRC_NO_TRUST: -3, + PATH_PAYMENT_SRC_NOT_AUTHORIZED: -4, + PATH_PAYMENT_NO_DESTINATION: -5, + PATH_PAYMENT_NO_TRUST: -6, + PATH_PAYMENT_NOT_AUTHORIZED: -7, + PATH_PAYMENT_LINE_FULL: -8, + PATH_PAYMENT_NO_ISSUER: -9, + PATH_PAYMENT_TOO_FEW_OFFERS: -10, + PATH_PAYMENT_OFFER_CROSS_SELF: -11, + PATH_PAYMENT_OVER_SENDMAX: -12 end defmodule SimplePaymentResult do use XDR.Type.Struct, - spec: [ - destination: AccountID, - asset: Asset, - amount: HyperInt - ] + destination: AccountID, + asset: Asset, + amount: Int64 end defmodule PathPaymentResult do use Union, - spec: [ - switch: PathPaymentResultCode, - cases: [ - {0, PaymentSuccess}, - {-9, Asset} - ] + switch: PathPaymentResultCode, + cases: [ + {0, PaymentSuccess}, + {-9, Asset} ] defmodule PaymentSuccess do use XDR.Type.Struct, - spec: [ - offers: ClaimOfferAtoms, - last: SimplePaymentResult - ] - - defmodule ClaimOfferAtoms do - use VariableArray, spec: [type: ClaimOfferAtom] - end + offers: ClaimOfferAtoms, + last: SimplePaymentResult end end defmodule ManageOfferResultCode do use Enum, - spec: [ - MANAGE_OFFER_SUCCESS: 0, - MANAGE_OFFER_MALFORMED: -1, - MANAGE_OFFER_SELL_NO_TRUST: -2, - MANAGE_OFFER_BUY_NO_TRUST: -3, - MANAGE_OFFER_SELL_NOT_AUTHORIZED: -4, - MANAGE_OFFER_BUY_NOT_AUTHORIZED: -5, - MANAGE_OFFER_LINE_FULL: -6, - MANAGE_OFFER_UNDERFUNDED: -7, - MANAGE_OFFER_CROSS_SELF: -8, - MANAGE_OFFER_SELL_NO_ISSUER: -9, - MANAGE_OFFER_BUY_NO_ISSUER: -10, - MANAGE_OFFER_NOT_FOUND: -11, - MANAGE_OFFER_LOW_RESERVE: -12 - ] + MANAGE_OFFER_SUCCESS: 0, + MANAGE_OFFER_MALFORMED: -1, + MANAGE_OFFER_SELL_NO_TRUST: -2, + MANAGE_OFFER_BUY_NO_TRUST: -3, + MANAGE_OFFER_SELL_NOT_AUTHORIZED: -4, + MANAGE_OFFER_BUY_NOT_AUTHORIZED: -5, + MANAGE_OFFER_LINE_FULL: -6, + MANAGE_OFFER_UNDERFUNDED: -7, + MANAGE_OFFER_CROSS_SELF: -8, + MANAGE_OFFER_SELL_NO_ISSUER: -9, + MANAGE_OFFER_BUY_NO_ISSUER: -10, + MANAGE_OFFER_NOT_FOUND: -11, + MANAGE_OFFER_LOW_RESERVE: -12 end defmodule ManageOfferEffect do use Enum, - spec: [ - MANAGE_OFFER_CREATED: 0, - MANAGE_OFFER_UPDATED: 1, - MANAGE_OFFER_DELETED: 2 - ] + MANAGE_OFFER_CREATED: 0, + MANAGE_OFFER_UPDATED: 1, + MANAGE_OFFER_DELETED: 2 end - defmodule ClaimOfferAtoms do - use VariableArray, spec: [type: ClaimOfferAtom] + defmodule OfferUnion do + use Union, + switch: ManageOfferEffect, + cases: [ + {0, OfferEntry}, + {1, OfferEntry}, + {2, VOID} + ] end defmodule ManageOfferSuccessResult do use XDR.Type.Struct, - spec: [ - offersClaimed: ClaimOfferAtoms, - offer: OfferUnion - ] - - defmodule OfferUnion do - use Union, - spec: [ - switch: ManageOfferEffect, - cases: [ - {0, OfferEntry}, - {1, OfferEntry}, - {2, VOID} - ] - ] - end + offersClaimed: ClaimOfferAtoms, + offer: OfferUnion end defmodule ManageOfferResult do use Union, - spec: [ - switch: ManageOfferResultCode, - cases: [ - {0, ManageOfferSuccessResult} - ] + switch: ManageOfferResultCode, + cases: [ + {0, ManageOfferSuccessResult} ] end defmodule SetOptionsResultCode do use Enum, - spec: [ - SET_OPTIONS_SUCCESS: 0, - SET_OPTIONS_LOW_RESERVE: -1, - SET_OPTIONS_TOO_MANY_SIGNERS: -2, - SET_OPTIONS_BAD_FLAGS: -3, - SET_OPTIONS_INVALID_INFLATION: -4, - SET_OPTIONS_CANT_CHANGE: -5, - SET_OPTIONS_UNKNOWN_FLAG: -6, - SET_OPTIONS_THRESHOLD_OUT_OF_RANGE: -7, - SET_OPTIONS_BAD_SIGNER: -8, - SET_OPTIONS_INVALID_HOME_DOMAIN: -9 - ] + SET_OPTIONS_SUCCESS: 0, + SET_OPTIONS_LOW_RESERVE: -1, + SET_OPTIONS_TOO_MANY_SIGNERS: -2, + SET_OPTIONS_BAD_FLAGS: -3, + SET_OPTIONS_INVALID_INFLATION: -4, + SET_OPTIONS_CANT_CHANGE: -5, + SET_OPTIONS_UNKNOWN_FLAG: -6, + SET_OPTIONS_THRESHOLD_OUT_OF_RANGE: -7, + SET_OPTIONS_BAD_SIGNER: -8, + SET_OPTIONS_INVALID_HOME_DOMAIN: -9 end defmodule SetOptionsResult do use Union, - spec: [ - switch: SetOptionsResultCode, - cases: [ - {0, VOID} - ] + switch: SetOptionsResultCode, + cases: [ + {0, VOID} ] end defmodule ChangeTrustResultCode do use Enum, - spec: [ - CHANGE_TRUST_SUCCESS: 0, - CHANGE_TRUST_MALFORMED: -1, - CHANGE_TRUST_NO_ISSUER: -2, - CHANGE_TRUST_INVALID_LIMIT: -3, - CHANGE_TRUST_LOW_RESERVE: -4, - CHANGE_TRUST_SELF_NOT_ALLOWED: -5 - ] + CHANGE_TRUST_SUCCESS: 0, + CHANGE_TRUST_MALFORMED: -1, + CHANGE_TRUST_NO_ISSUER: -2, + CHANGE_TRUST_INVALID_LIMIT: -3, + CHANGE_TRUST_LOW_RESERVE: -4, + CHANGE_TRUST_SELF_NOT_ALLOWED: -5 end defmodule ChangeTrustResult do use Union, - spec: [ - switch: ChangeTrustResultCode, - cases: [ - {0, VOID} - ] + switch: ChangeTrustResultCode, + cases: [ + {0, VOID} ] end defmodule AllowTrustResultCode do use Enum, - spec: [ - ALLOW_TRUST_SUCCESS: 0, - ALLOW_TRUST_MALFORMED: -1, - ALLOW_TRUST_NO_TRUST_LINE: -2, - ALLOW_TRUST_TRUST_NOT_REQUIRED: -3, - ALLOW_TRUST_CANT_REVOKE: -4, - ALLOW_TRUST_SELF_NOT_ALLOWED: -5 - ] + ALLOW_TRUST_SUCCESS: 0, + ALLOW_TRUST_MALFORMED: -1, + ALLOW_TRUST_NO_TRUST_LINE: -2, + ALLOW_TRUST_TRUST_NOT_REQUIRED: -3, + ALLOW_TRUST_CANT_REVOKE: -4, + ALLOW_TRUST_SELF_NOT_ALLOWED: -5 end defmodule AllowTrustResult do use Union, - spec: [ - switch: AllowTrustResultCode, - cases: [ - {0, VOID} - ] + switch: AllowTrustResultCode, + cases: [ + {0, VOID} ] end defmodule AccountMergeResultCode do use Enum, - spec: [ - ACCOUNT_MERGE_SUCCESS: 0, - ACCOUNT_MERGE_MALFORMED: -1, - ACCOUNT_MERGE_NO_ACCOUNT: -2, - ACCOUNT_MERGE_IMMUTABLE_SET: -3, - ACCOUNT_MERGE_HAS_SUB_ENTRIES: -4 - ] + ACCOUNT_MERGE_SUCCESS: 0, + ACCOUNT_MERGE_MALFORMED: -1, + ACCOUNT_MERGE_NO_ACCOUNT: -2, + ACCOUNT_MERGE_IMMUTABLE_SET: -3, + ACCOUNT_MERGE_HAS_SUB_ENTRIES: -4 end defmodule AccountMergeResult do use Union, - spec: [ - switch: AccountMergeResultCode, - cases: [ - {0, HyperInt}, - {-1, VOID} - ] + switch: AccountMergeResultCode, + cases: [ + {0, Int64}, + {-1, VOID} ] end defmodule InflationResultCode do use Enum, - spec: [ - INFLATION_SUCCESS: 0, - INFLATION_NOT_TIME: -1 - ] + INFLATION_SUCCESS: 0, + INFLATION_NOT_TIME: -1 end defmodule InflationPayout do use XDR.Type.Struct, - spec: [ - destination: AccountID, - amount: HyperInt - ] + destination: AccountID, + amount: Int64 + end + + defmodule Payouts do + use VariableArray, type: InflationPayout end defmodule InflationResult do use Union, - spec: [ - switch: InflationResultCode, - cases: [ - {0, Payouts}, - {-1, VOID} - ] + switch: InflationResultCode, + cases: [ + {0, Payouts}, + {-1, VOID} ] - - defmodule Payouts do - use VariableArray, spec: [type: InflationPayout] - end end defmodule ManageDataResultCode do use Enum, - spec: [ - MANAGE_DATA_SUCCESS: 0, - MANAGE_DATA_NOT_SUPPORTED_YET: -1, - MANAGE_DATA_NAME_NOT_FOUND: -2, - MANAGE_DATA_LOW_RESERVE: -3, - MANAGE_DATA_INVALID_NAME: -4 - ] + MANAGE_DATA_SUCCESS: 0, + MANAGE_DATA_NOT_SUPPORTED_YET: -1, + MANAGE_DATA_NAME_NOT_FOUND: -2, + MANAGE_DATA_LOW_RESERVE: -3, + MANAGE_DATA_INVALID_NAME: -4 end defmodule ManageDataResult do use Union, - spec: [ - switch: ManageDataResultCode, - cases: [ - {0, VOID} - ] + switch: ManageDataResultCode, + cases: [ + {0, VOID} ] end defmodule OperationResultCode do use Enum, - spec: [ - opINNER: 0, - opBAD_AUTH: -1, - opNO_ACCOUNT: -2 - ] + opINNER: 0, + opBAD_AUTH: -1, + opNO_ACCOUNT: -2 end defmodule OperationResult do use Union, - spec: [ - switch: OperationResultCode, - cases: [ - {0, OperationResultInner} - ] + switch: OperationResultCode, + cases: [ + {0, OperationResultInner} ] defmodule OperationResultInner do use Union, - spec: [ - switch: OperationType, - cases: [ - {0, CreateAccountResult}, - {1, PaymentResult}, - {2, PathPaymentResult}, - {3, ManageOfferResult}, - {4, ManageOfferResult}, - {5, SetOptionsResult}, - {6, ChangeTrustResult}, - {7, AllowTrustResult}, - {8, AccountMergeResult}, - {9, InflationResult}, - {10, ManageDataResult} - ] + switch: OperationType, + cases: [ + {0, CreateAccountResult}, + {1, PaymentResult}, + {2, PathPaymentResult}, + {3, ManageOfferResult}, + {4, ManageOfferResult}, + {5, SetOptionsResult}, + {6, ChangeTrustResult}, + {7, AllowTrustResult}, + {8, AccountMergeResult}, + {9, InflationResult}, + {10, ManageDataResult} ] end end defmodule TransactionResultCode do use Enum, - spec: [ - txSUCCESS: 0, - txFAILED: -1, - txTOO_EARLY: -2, - txTOO_LATE: -3, - txMISSING_OPERATION: -4, - txBAD_SEQ: -5, - txBAD_AUTH: -6, - txINSUFFICIENT_BALANCE: -7, - txNO_ACCOUNT: -8, - txINSUFFICIENT_FEE: -9, - txBAD_AUTH_EXTRA: -10, - txINTERNAL_ERROR: -11 + txSUCCESS: 0, + txFAILED: -1, + txTOO_EARLY: -2, + txTOO_LATE: -3, + txMISSING_OPERATION: -4, + txBAD_SEQ: -5, + txBAD_AUTH: -6, + txINSUFFICIENT_BALANCE: -7, + txNO_ACCOUNT: -8, + txINSUFFICIENT_FEE: -9, + txBAD_AUTH_EXTRA: -10, + txINTERNAL_ERROR: -11 + end + + defmodule OperationResults do + use VariableArray, type: OperationResult + end + + defmodule TransactionResultResult do + use Union, + switch: TransactionResultCode, + cases: [ + {0, OperationResults}, + {-1, OperationResults}, + {-2, VOID} ] end defmodule TransactionResult do use XDR.Type.Struct, - spec: [ - feeCharged: HyperInt, - result: TransactionResultResult, - ext: Ext - ] - - defmodule TransactionResultResult do - use Union, - spec: [ - switch: TransactionResultCode, - cases: [ - {0, OperationResults}, - {-1, OperationResults}, - {-2, VOID} - ] - ] - - defmodule OperationResults do - use VariableArray, spec: [type: OperationResult] - end - end + feeCharged: Int64, + result: TransactionResultResult, + ext: Ext end end diff --git a/lib/stellar/xdr/types/types.ex b/lib/stellar/xdr/types/types.ex index 062382c..7b7e10d 100644 --- a/lib/stellar/xdr/types/types.ex +++ b/lib/stellar/xdr/types/types.ex @@ -1,58 +1,73 @@ defmodule Stellar.XDR.Types do - alias XDR.Type.{FixedOpaque, Enum, Union, VariableOpaque} + alias XDR.Type.{ + Enum, + FixedOpaque, + HyperInt, + HyperUint, + Int, + Uint, + Union, + VariableOpaque + } - defmodule Hash do - use FixedOpaque, len: 32 + defmodule UInt32 do + use Uint + end + + defmodule UInt64 do + use HyperUint end defmodule UInt256 do use FixedOpaque, len: 32 end + defmodule Int32 do + use Int + end + + defmodule Int64 do + use HyperInt + end + + defmodule Hash do + use FixedOpaque, len: 32 + end + defmodule CryptoKeyType do use Enum, - spec: [ - KEY_TYPE_ED25519: 0, - KEY_TYPE_PRE_AUTH_TX: 1, - KEY_TYPE_HASH_X: 2 - ] + KEY_TYPE_ED25519: 0, + KEY_TYPE_PRE_AUTH_TX: 1, + KEY_TYPE_HASH_X: 2 end defmodule PublicKeyType do use Enum, - spec: [ - PUBLIC_KEY_TYPE_ED25519: 0 - ] + PUBLIC_KEY_TYPE_ED25519: 0 end defmodule SignerKeyType do use Enum, - spec: [ - SIGNER_KEY_TYPE_ED25519: 0, - SIGNER_KEY_TYPE_PRE_AUTH_TX: 1, - SIGNER_KEY_TYPE_HASH_X: 2 - ] + SIGNER_KEY_TYPE_ED25519: 0, + SIGNER_KEY_TYPE_PRE_AUTH_TX: 1, + SIGNER_KEY_TYPE_HASH_X: 2 end defmodule PublicKey do use Union, - spec: [ - switch: PublicKeyType, - cases: [ - {0, UInt256} - ] + switch: PublicKeyType, + cases: [ + {0, UInt256} ] end defmodule SignerKey do use Union, - spec: [ - switch: SignerKeyType, - cases: [ - {0, UInt256}, - {1, UInt256}, - {2, UInt256} - ] + switch: SignerKeyType, + cases: [ + {0, UInt256}, + {1, UInt256}, + {2, UInt256} ] end @@ -70,29 +85,21 @@ defmodule Stellar.XDR.Types do defmodule Curve25519Secret do use XDR.Type.Struct, - spec: [ - key: Key32 - ] + key: Key32 end defmodule Curve25519Public do use XDR.Type.Struct, - spec: [ - key: Key32 - ] + key: Key32 end defmodule HmacSha256Key do use XDR.Type.Struct, - spec: [ - key: Key32 - ] + key: Key32 end defmodule HmacSha256Mac do use XDR.Type.Struct, - spec: [ - mac: Key32 - ] + mac: Key32 end end diff --git a/mix.exs b/mix.exs index b274823..2b9c7f1 100644 --- a/mix.exs +++ b/mix.exs @@ -45,7 +45,7 @@ defmodule Stellar.MixProject do {:ex_doc, "~> 0.18.1", only: :dev}, {:bypass, "~> 0.8.1", only: :test}, {:excoveralls, "~> 0.8.0", only: :test}, - {:xdr, "~> 0.1.1"} + {:xdr, github: "sunny-g/xdr", branch: "v0.2.0"} ] end diff --git a/mix.lock b/mix.lock index 514d943..322e050 100644 --- a/mix.lock +++ b/mix.lock @@ -19,11 +19,11 @@ "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, "mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [:mix], [], "hexpm"}, "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, - "ok": {:hex, :ok, "1.11.0", "0acbb73d98b5198db963ae710dad2e6efeed05149871a30e1eb08a91ae4f7042", [:mix], [], "hexpm"}, + "ok": {:git, "https://github.com/sunny-g/ok.git", "e9bd5108b054cc12d45358790c693d640e8df388", []}, "parse_trans": {:hex, :parse_trans, "3.2.0", "2adfa4daf80c14dc36f522cf190eb5c4ee3e28008fc6394397c16f62a26258c2", [:rebar3], [], "hexpm"}, "plug": {:hex, :plug, "1.5.1", "1ff35bdecfb616f1a2b1c935ab5e4c47303f866cb929d2a76f0541e553a58165", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.3", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"}, "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"}, - "xdr": {:hex, :xdr, "0.1.2", "6774f6b921267ab87c09d24e0a0cceca03503f6506f10b33321bf856df25ad0c", [:mix], [{:math, "~> 0.3.0", [hex: :math, repo: "hexpm", optional: false]}, {:ok, "~> 1.9", [hex: :ok, repo: "hexpm", optional: false]}], "hexpm"}, + "xdr": {:git, "https://github.com/sunny-g/xdr.git", "3e8b6352f6100b70bffb71fafa394a59affddae3", [branch: "v0.2.0"]}, } From c7ad8ce01cc525f4da79a11d0a979d90f38ec801 Mon Sep 17 00:00:00 2001 From: Sunny G Date: Thu, 2 Aug 2018 22:16:49 -0700 Subject: [PATCH 2/2] finishes porting over Stellar XDR types --- lib/stellar/xdr/types/SCP.ex | 117 +++++++++ lib/stellar/xdr/types/ledger.ex | 223 ++++++++++++++-- lib/stellar/xdr/types/ledger_entries.ex | 97 ++++--- lib/stellar/xdr/types/overlay.ex | 170 +++++++++++++ lib/stellar/xdr/types/transaction.ex | 323 +++++++++++++----------- lib/stellar/xdr/types/types.ex | 43 +++- 6 files changed, 764 insertions(+), 209 deletions(-) create mode 100644 lib/stellar/xdr/types/SCP.ex create mode 100644 lib/stellar/xdr/types/overlay.ex diff --git a/lib/stellar/xdr/types/SCP.ex b/lib/stellar/xdr/types/SCP.ex new file mode 100644 index 0000000..231c5cb --- /dev/null +++ b/lib/stellar/xdr/types/SCP.ex @@ -0,0 +1,117 @@ +defmodule Stellar.XDR.Types.SCP do + alias XDR.Type.{ + Enum, + Optional, + Struct, + Union, + VariableArray, + VariableOpaque + } + + alias Stellar.XDR.Types.{ + Hash, + NodeID, + PublicKey, + Signature, + UInt32, + UInt64 + } + + defmodule Value do + use VariableOpaque + end + + defmodule Values do + use VariableArray, type: Value + end + + defmodule SCPBallot do + use Struct, + counter: UInt32, + value: Value + end + + defmodule SCPNomination do + use Struct, + quorumSetHash: Hash, + votes: Values, + accepted: Values + end + + defmodule SCPStatementType do + use Enum, + SCP_ST_PREPARE: 0, + SCP_ST_CONFIRM: 1, + SCP_ST_EXTERNALIZE: 2, + SCP_ST_NOMINATE: 3 + end + + defmodule OptionalSCPBallot do + use Optional, for: SCPBallot + end + + defmodule SCPStatementPrepare do + use Struct, + quorumSetHash: Hash, + ballot: SCPBallot, + prepared: OptionalSCPBallot, + preparedPrime: OptionalSCPBallot, + nC: UInt32, + nH: UInt32 + end + + defmodule SCPStatementConfirm do + use Struct, + ballot: SCPBallot, + nPrepared: UInt32, + nCommit: UInt32, + nH: UInt32, + quorumSetHash: Hash + end + + defmodule SCPStatementExternalize do + use Struct, + commit: SCPBallot, + nH: UInt32, + commitQuorumSetHash: Hash + end + + defmodule SCPStatementPledge do + use Union, + switch: SCPStatementType, + cases: [ + SCP_ST_PREPARE: SCPStatementPrepare, + SCP_ST_CONFIRM: SCPStatementConfirm, + SCP_ST_EXTERNALIZE: SCPStatementExternalize, + SCP_ST_NOMINATE: SCPNomination + ] + end + + defmodule SCPStatement do + use Struct, + nodeID: NodeID, + slotIndex: UInt64, + pledges: SCPStatementPledge + end + + defmodule SCPEnvelope do + use Struct, + statement: SCPStatement, + signature: Signature + end + + defmodule Validators do + use VariableArray, type: PublicKey + end + + defmodule SCPQuorumSets do + use VariableArray, type: SCPQuorumSet + end + + defmodule SCPQuorumSet do + use Struct, + threshold: UInt32, + validators: Validators, + innerSets: SCPQuorumSets + end +end diff --git a/lib/stellar/xdr/types/ledger.ex b/lib/stellar/xdr/types/ledger.ex index 1b0fc30..b481d95 100644 --- a/lib/stellar/xdr/types/ledger.ex +++ b/lib/stellar/xdr/types/ledger.ex @@ -2,27 +2,43 @@ defmodule Stellar.XDR.Types.Ledger do alias XDR.Type.{ Enum, FixedArray, + Struct, Union, VariableArray, - VariableOpaque, - Void + VariableOpaque } alias Stellar.XDR.Types.{ + DefaultExt, Hash, Int32, Int64, + LedgerEntries, + PublicKey, + SCP, + Transaction, UInt32, UInt64 } - defmodule Ext do - use Union, - switch: Int32, - cases: [ - {0, Void} - ] - end + alias LedgerEntries.{ + Asset, + LedgerEntry, + LedgerEntryType, + String64 + } + + alias PublicKey, as: AccountID + + alias Transaction.{ + TransactionEnvelope, + TransactionResult + } + + alias SCP.{ + SCPEnvelope, + SCPQuorumSets + } defmodule UpgradeType do use VariableOpaque, max_len: 128 @@ -33,13 +49,11 @@ defmodule Stellar.XDR.Types.Ledger do end defmodule StellarValue do - require Ext - - use XDR.Type.Struct, + use Struct, txSetHash: Hash, closeTime: UInt64, upgrades: Upgrades, - ext: Ext + ext: DefaultExt end defmodule SkipList do @@ -48,9 +62,7 @@ defmodule Stellar.XDR.Types.Ledger do end defmodule LedgerHeader do - require Ext - - use XDR.Type.Struct, + use Struct, ledgerVersion: UInt32, previousLedgerHash: Hash, scpValue: StellarValue, @@ -65,7 +77,7 @@ defmodule Stellar.XDR.Types.Ledger do baseReserve: UInt32, maxTxSetSize: UInt32, skipList: SkipList, - ext: Ext + ext: DefaultExt end defmodule LedgerUpgradeType do @@ -75,4 +87,181 @@ defmodule Stellar.XDR.Types.Ledger do LEDGER_UPGRADE_MAX_TX_SET_SIZE: 3, LEDGER_UPGRADE_BASE_RESERVE: 4 end + + defmodule LedgerUpgrade do + use Union, + switch: LedgerUpgradeType, + cases: [ + LEDGER_UPGRADE_VERSION: UInt32, + LEDGER_UPGRADE_BASE_FEE: UInt32, + LEDGER_UPGRADE_MAX_TX_SET_SIZE: UInt32, + LEDGER_UPGRADE_BASE_RESERVE: UInt32 + ] + end + + defmodule LedgerKeyAccount do + use Struct, + accountID: AccountID + end + + defmodule LedgerKeyTrustLine do + use Struct, + accountID: AccountID, + asset: Asset + end + + defmodule LedgerKeyOffer do + use Struct, + accountID: AccountID, + offerID: UInt64 + end + + defmodule LedgerKeyData do + use Struct, + accountID: AccountID, + dataName: String64 + end + + defmodule LedgerKey do + use Union, + switch: LedgerEntryType, + cases: [ + ACCOUNT: LedgerKeyAccount, + TRUSTLINE: LedgerKeyTrustLine, + OFFER: LedgerKeyOffer, + DATA: LedgerKeyData + ] + end + + defmodule BucketEntryType do + use Enum, + LIVEENTRY: 0, + DEADENTRY: 1 + end + + defmodule BucketEntry do + use Union, + switch: BucketEntryType, + cases: [ + LIVEENTRY: LedgerEntry, + DEADENTRY: LedgerKey + ] + end + + defmodule TransactionEnvelopes do + use VariableArray, type: TransactionEnvelope + end + + defmodule TransactionSet do + use Struct, + previousLedgerHash: Hash, + txs: TransactionEnvelopes + end + + defmodule TransactionResultPair do + use Struct, + transactionHash: Hash, + result: TransactionResult + end + + defmodule TransactionResultPairs do + use VariableArray, type: TransactionResultPair + end + + defmodule TransactionResultSet do + use Struct, + results: TransactionResultPairs + end + + defmodule TransactionHistoryEntry do + use Struct, + ledgerSeq: UInt32, + txSet: TransactionSet, + ext: DefaultExt + end + + defmodule TransactionHistoryResultEntry do + use Struct, + ledgerSeq: UInt32, + txResultSet: TransactionResultSet, + ext: DefaultExt + end + + defmodule LedgerHeaderHistoryEntry do + use Struct, + hash: Hash, + header: LedgerHeader, + ext: DefaultExt + end + + defmodule SCPEnvelopes do + use VariableArray, type: SCPEnvelope + end + + defmodule LedgerSCPMessages do + use Struct, + ledgerSeq: UInt32, + messages: SCPEnvelopes + end + + defmodule SCPHistoryEntryV0 do + use Struct, + quorumSets: SCPQuorumSets, + ledgerMessages: LedgerSCPMessages + end + + defmodule SCPHistoryEntry do + use Union, + switch: Int32, + cases: [ + {0, SCPHistoryEntryV0} + ] + end + + defmodule LedgerEntryChangeType do + use Enum, + LEDGER_ENTRY_CREATED: 0, + LEDGER_ENTRY_UPDATED: 1, + LEDGER_ENTRY_REMOVED: 2, + LEDGER_ENTRY_STATE: 3 + end + + defmodule LedgerEntryChange do + use Union, + switch: LedgerEntryChangeType, + cases: [ + LEDGER_ENTRY_CREATED: LedgerEntry, + LEDGER_ENTRY_UPDATED: LedgerEntry, + LEDGER_ENTRY_REMOVED: LedgerKey, + LEDGER_ENTRY_STATE: LedgerEntry + ] + end + + defmodule LedgerEntryChanges do + use VariableArray, type: LedgerEntryChange + end + + defmodule OperationMeta do + use Struct, + changes: LedgerEntryChanges + end + + defmodule OperationMetas do + use VariableArray, type: OperationMeta + end + + defmodule TransactionMetaV1 do + use Struct, + txChanges: LedgerEntryChanges, + operations: OperationMetas + end + + defmodule TransactionMeta do + use Union, + switch: Int32, + cases: [ + {0, OperationMetas}, + {1, TransactionMetaV1} + ] + end end diff --git a/lib/stellar/xdr/types/ledger_entries.ex b/lib/stellar/xdr/types/ledger_entries.ex index 4630477..4d3f1f1 100644 --- a/lib/stellar/xdr/types/ledger_entries.ex +++ b/lib/stellar/xdr/types/ledger_entries.ex @@ -2,13 +2,17 @@ defmodule Stellar.XDR.Types.LedgerEntries do alias XDR.Type.{ Enum, FixedOpaque, + Struct, Union, VariableArray, VariableOpaque, Void } + alias XDR.Util.Delegate + alias Stellar.XDR.Types.{ + DefaultExt, Int32, Int64, PublicKey, @@ -23,14 +27,6 @@ defmodule Stellar.XDR.Types.LedgerEntries do use FixedOpaque, len: 4 end - defmodule Ext do - use Union, - switch: Int32, - cases: [ - {0, Void} - ] - end - defmodule String32 do use VariableArray, max_len: 32, type: XDR.Type.String end @@ -39,6 +35,10 @@ defmodule Stellar.XDR.Types.LedgerEntries do use VariableArray, max_len: 64, type: XDR.Type.String end + defmodule SequenceNumber do + use Delegate, to: Int64 + end + defmodule DataValue do use VariableOpaque, max_len: 64 end @@ -50,16 +50,6 @@ defmodule Stellar.XDR.Types.LedgerEntries do ASSET_TYPE_CREDIT_ALPHANUM12: 2 end - defmodule Asset do - use Union, - switch: AssetType, - cases: [ - {0, Void}, - {1, AssetTypeCreditAlphaNum4}, - {2, AssetTypeCreditAlphaNum12} - ] - end - defmodule AssetCode4 do use FixedOpaque, len: 4 end @@ -69,23 +59,39 @@ defmodule Stellar.XDR.Types.LedgerEntries do end defmodule AssetTypeCreditAlphaNum4 do - use XDR.Type.Struct, + use Struct, assetCode: AssetCode4, issuer: AccountID end defmodule AssetTypeCreditAlphaNum12 do - use XDR.Type.Struct, + use Struct, assetCode: AssetCode12, issuer: AccountID end + defmodule Asset do + use Union, + switch: AssetType, + cases: [ + ASSET_TYPE_NATIVE: Void, + ASSET_TYPE_CREDIT_ALPHANUM4: AssetTypeCreditAlphaNum4, + ASSET_TYPE_CREDIT_ALPHANUM12: AssetTypeCreditAlphaNum12 + ] + end + defmodule Price do - use XDR.Type.Struct, + use Struct, n: Int32, d: Int32 end + defmodule Liabilities do + use Struct, + buying: Int64, + selling: Int64 + end + defmodule ThresholdIndexes do use Enum, THRESHOLD_MASTER_WEIGHT: 0, @@ -103,7 +109,7 @@ defmodule Stellar.XDR.Types.LedgerEntries do end defmodule Signer do - use XDR.Type.Struct, + use Struct, key: SignerKey, weight: UInt32 end @@ -119,8 +125,23 @@ defmodule Stellar.XDR.Types.LedgerEntries do AUTH_IMMUTABLE_FLAG: 0x4 end + defmodule LiabilitiesExt do + use Struct, + liabilities: Liabilities, + ext: DefaultExt + end + + defmodule AccountEntryExt do + use Union, + switch: Int32, + cases: [ + {0, Void}, + {1, LiabilitiesExt} + ] + end + defmodule AccountEntry do - use XDR.Type.Struct, + use Struct, accountID: AccountID, balance: Int64, seqNum: UInt64, @@ -130,7 +151,7 @@ defmodule Stellar.XDR.Types.LedgerEntries do homeDomain: XDR.Type.String, thresholds: Thresholds, signers: Signers, - ext: Ext + ext: DefaultExt end defmodule TrustLineFlags do @@ -138,14 +159,18 @@ defmodule Stellar.XDR.Types.LedgerEntries do AUTHORIZED_FLAG: 1 end + defmodule TrustLineEntryExt do + use Delegate, to: AccountEntryExt + end + defmodule TrustLineEntry do - use XDR.Type.Struct, + use Struct, accountID: AccountID, asset: Asset, balance: Int64, limit: Int64, flags: UInt32, - ext: Ext + ext: TrustLineEntryExt end defmodule OfferEntryFlags do @@ -154,7 +179,7 @@ defmodule Stellar.XDR.Types.LedgerEntries do end defmodule OfferEntry do - use XDR.Type.Struct, + use Struct, sellerID: AccountID, offerID: UInt64, selling: Asset, @@ -162,33 +187,33 @@ defmodule Stellar.XDR.Types.LedgerEntries do amount: Int64, price: Price, flags: UInt32, - ext: Ext + ext: DefaultExt end defmodule DataEntry do - use XDR.Type.Struct, + use Struct, accountID: AccountID, dataName: String64, dataValue: DataValue, - ext: Ext + ext: DefaultExt end defmodule LedgerEntryData do use Union, switch: LedgerEntryType, cases: [ - {0, AccountEntry}, - {1, TrustLineEntry}, - {2, OfferEntry}, - {3, DataEntry} + ACCOUNT: AccountEntry, + TRUSTLINE: TrustLineEntry, + OFFER: OfferEntry, + DATA: DataEntry ] end defmodule LedgerEntry do - use XDR.Type.Struct, + use Struct, lastModifiedLedgerSeq: UInt32, data: LedgerEntryData, - ext: Ext + ext: DefaultExt end defmodule EnvelopeType do diff --git a/lib/stellar/xdr/types/overlay.ex b/lib/stellar/xdr/types/overlay.ex new file mode 100644 index 0000000..4be5ce1 --- /dev/null +++ b/lib/stellar/xdr/types/overlay.ex @@ -0,0 +1,170 @@ +defmodule Stellar.XDR.Types.Overlay do + alias XDR.Type.{ + Enum, + FixedOpaque, + Struct, + Union, + VariableArray, + Void + } + + alias Stellar.XDR.Types.{ + Curve25519Public, + Hash, + HmacSha256Mac, + Int32, + NodeID, + SCP, + Signature, + Transaction, + UInt32, + UInt64, + UInt256 + } + + alias Transaction.{ + TransactionEnvelope, + TransactionSet + } + + alias SCP.{ + SCPQuorumSet, + SCPEnvelope + } + + defmodule ErrorCode do + use Enum, + ERR_MISC: 0, + ERR_DATA: 1, + ERR_CONF: 2, + ERR_AUTH: 3, + ERR_LOAD: 4 + end + + defmodule String100 do + use XDR.Type.String, max_len: 100 + end + + defmodule Error do + use Struct, + code: ErrorCode, + msg: String100 + end + + defmodule AuthCert do + use Struct, + pubkey: Curve25519Public, + expiration: UInt64, + sig: Signature + end + + defmodule Hello do + use Struct, + ledgerVersion: UInt32, + overlayVersion: UInt32, + overMinVersion: UInt32, + networkID: Hash, + versionStr: String100, + listeningPort: Int32, + peerID: NodeID, + cert: AuthCert, + nonce: UInt256 + end + + defmodule Auth do + use Struct, + unused: Int32 + end + + defmodule IPAddrType do + use Enum, + IPv4: 0, + IPv6: 1 + end + + defmodule IPv4 do + use FixedOpaque, len: 4 + end + + defmodule IPv6 do + use FixedOpaque, len: 16 + end + + defmodule IP do + use Union, + switch: IPAddrType, + cases: [ + IPv4: IPv4, + IPv6: IPv6 + ] + end + + defmodule PeerAddress do + use Struct, + ip: IP, + port: UInt32, + numFailures: UInt32 + end + + defmodule MessageType do + use Enum, + ERROR_MSG: 0, + AUTH: 2, + DONT_HAVE: 3, + GET_PEERS: 4, + PEERS: 5, + GET_TX_SET: 6, + TX_SET: 7, + TRANSACTION: 8, + GET_SCP_QUORUMSET: 9, + SCP_QUORUMSET: 10, + SCP_MESSAGE: 11, + GET_SCP_STATE: 12, + HELLO: 13 + end + + defmodule DontHave do + use Struct, + type: MessageType, + reqHash: UInt256 + end + + defmodule Peers do + use VariableArray, max_len: 100, type: PeerAddress + end + + defmodule StellarMessage do + use Union, + switch: MessageType, + cases: [ + ERROR_MSG: Error, + AUTH: Auth, + DONT_HAVE: DontHave, + GET_PEERS: Void, + PEERS: Peers, + GET_TX_SET: UInt256, + TX_SET: TransactionSet, + TRANSACTION: TransactionEnvelope, + GET_SCP_QUORUMSET: UInt256, + SCP_QUORUMSET: SCPQuorumSet, + SCP_MESSAGE: SCPEnvelope, + GET_SCP_STATE: UInt32, + HELLO: Hello + ] + end + + defmodule AuthenticatedMessageV0 do + use Struct, + sequence: UInt64, + message: StellarMessage, + mac: HmacSha256Mac + end + + defmodule AuthenticatedMessage do + use Union, + switch: UInt32, + cases: [ + {0, AuthenticatedMessageV0} + ] + end +end diff --git a/lib/stellar/xdr/types/transaction.ex b/lib/stellar/xdr/types/transaction.ex index 46c2492..c7235f4 100644 --- a/lib/stellar/xdr/types/transaction.ex +++ b/lib/stellar/xdr/types/transaction.ex @@ -1,12 +1,16 @@ defmodule Stellar.XDR.Types.Transaction do alias XDR.Type.{ + Bool, Enum, + Optional, + Struct, Union, Void, VariableArray } alias Stellar.XDR.Types.{ + DefaultExt, Hash, Int32, Int64, @@ -20,12 +24,11 @@ defmodule Stellar.XDR.Types.Transaction do alias LedgerEntries.{ Asset, - AssetType, - AssetCode4, - AssetCode12, DataValue, + EnvelopeType, OfferEntry, Price, + SequenceNumber, Signer, String32, String64 @@ -33,28 +36,12 @@ defmodule Stellar.XDR.Types.Transaction do alias PublicKey, as: AccountID - defmodule Ext do - use Union, - switch: Int32, - cases: [ - {0, Void} - ] - end - defmodule DecoratedSignature do - use XDR.Type.Struct, + use Struct, hint: SignatureHint, signature: Signature end - defmodule DecoratedSignatures do - use VariableArray, max_len: 20, type: DecoratedSignature - end - - defmodule AssetPaths do - use VariableArray, max_len: 5, type: Asset - end - defmodule OperationType do use Enum, CREATE_ACCOUNT: 0, @@ -67,24 +54,29 @@ defmodule Stellar.XDR.Types.Transaction do ALLOW_TRUST: 7, ACCOUNT_MERGE: 8, INFLATION: 9, - MANAGE_DATA: 10 + MANAGE_DATA: 10, + BUMP_SEQUENCE: 11 end defmodule CreateAccountOp do - use XDR.Type.Struct, + use Struct, destination: AccountID, startingBalance: Int64 end defmodule PaymentOp do - use XDR.Type.Struct, + use Struct, destination: AccountID, asset: Asset, amount: Int64 end + defmodule AssetPaths do + use VariableArray, max_len: 5, type: Asset + end + defmodule PathPaymentOp do - use XDR.Type.Struct, + use Struct, sendAsset: Asset, sendMax: Int64, destination: AccountID, @@ -94,7 +86,7 @@ defmodule Stellar.XDR.Types.Transaction do end defmodule ManageOfferOp do - use XDR.Type.Struct, + use Struct, selling: Asset, buying: Asset, amount: Int64, @@ -103,79 +95,89 @@ defmodule Stellar.XDR.Types.Transaction do end defmodule CreatePassiveOfferOp do - use XDR.Type.Struct, + use Struct, selling: Asset, buying: Asset, amount: Int64, price: Price end + defmodule OptionalUInt32 do + use Optional, for: UInt32 + end + + defmodule OptionalString32 do + use Optional, for: String32 + end + + defmodule OptionalSigner do + use Optional, for: Signer + end + defmodule SetOptionsOp do - use XDR.Type.Struct, + use Struct, inflationDest: AccountID, - clearFlags: UInt32, - setFlags: UInt32, - masterWeight: UInt32, - lowThreshold: UInt32, - medThreshold: UInt32, - highThreshold: UInt32, - homeDomain: String32, - signer: Signer + clearFlags: OptionalUInt32, + setFlags: OptionalUInt32, + masterWeight: OptionalUInt32, + lowThreshold: OptionalUInt32, + medThreshold: OptionalUInt32, + highThreshold: OptionalUInt32, + homeDomain: OptionalString32, + signer: OptionalSigner end defmodule ChangeTrustOp do - use XDR.Type.Struct, + use Struct, line: Asset, limit: Int64 end - defmodule Asset do - use Union, - switch: AssetType, - cases: [ - {1, AssetCode4}, - {2, AssetCode12} - ] - end - defmodule AllowTrustOp do - use XDR.Type.Struct, + use Struct, trustor: AccountID, - asset: Asset + asset: Asset, + authorize: Bool + end + + defmodule OptionalDataValue do + use Optional, for: DataValue end defmodule ManageDataOp do - use XDR.Type.Struct, + use Struct, dataName: String64, - dataValue: DataValue + dataValue: OptionalDataValue + end + + defmodule BumpSequenceOp do + use Struct, + bumpTo: SequenceNumber end - defmodule OperationUnion do + defmodule OperationBody do use Union, switch: OperationType, cases: [ - {0, CreateAccountOp}, - {1, PaymentOp}, - {2, PathPaymentOp}, - {3, ManageOfferOp}, - {4, CreatePassiveOfferOp}, - {5, SetOptionsOp}, - {6, ChangeTrustOp}, - {7, AllowTrustOp}, - {8, AccountID}, - {9, Void}, - {10, ManageDataOp} + CREATE_ACCOUNT: CreateAccountOp, + PAYMENT: PaymentOp, + PATH_PAYMENT: PathPaymentOp, + MANAGE_OFFER: ManageOfferOp, + CREATE_PASSIVE_OFFER: CreatePassiveOfferOp, + SET_OPTIONS: SetOptionsOp, + CHANGE_TRUST: ChangeTrustOp, + ALLOW_TRUST: AllowTrustOp, + ACCOUNT_MERGE: AccountID, + INFLATION: Void, + MANAGE_DATA: ManageDataOp, + BUMP_SEQUENCE: BumpSequenceOp ] end defmodule Operation do - use XDR.Type.Struct, + use Struct, sourceAccount: AccountID, - body: OperationUnion - end - - defmodule Operations do - use VariableArray, max_len: 100, type: Operation + body: OperationBody end defmodule MemoType do @@ -187,7 +189,7 @@ defmodule Stellar.XDR.Types.Transaction do MEMO_RETURN: 4 end - defmodule Text do + defmodule MemoText do use VariableArray, max_len: 28, type: XDR.Type.String end @@ -195,53 +197,65 @@ defmodule Stellar.XDR.Types.Transaction do use Union, switch: MemoType, cases: [ - {0, Void}, - {1, Text}, - {2, UInt64}, - {3, Hash}, - {4, Hash} + MEMO_NONE: Void, + MEMO_TEXT: MemoText, + MEMO_ID: UInt64, + MEMO_HASH: Hash, + MEMO_RETURN: Hash ] end defmodule TimeBounds do - use XDR.Type.Struct, + use Struct, minTime: UInt64, maxTime: UInt64 end + defmodule OptionalTimeBounds do + use Optional, for: TimeBounds + end + + defmodule Operations do + use VariableArray, max_len: 100, type: Operation + end + defmodule Transaction do - use XDR.Type.Struct, + use Struct, sourceAccount: AccountID, fee: Int32, seqNum: UInt64, - timeBounds: TimeBounds, + timeBounds: OptionalTimeBounds, memo: Memo, operations: Operations, - ext: Ext + ext: DefaultExt end defmodule TaggedTransaction do use Union, - switch: MemoType, + switch: EnvelopeType, cases: [ - {0, Transaction} + ENVELOPE_TYPE_TX: Transaction ] end defmodule TransactionSignaturePayload do - use XDR.Type.Struct, + use Struct, networkId: Hash, taggedTransaction: TaggedTransaction end + defmodule DecoratedSignatures do + use VariableArray, max_len: 20, type: DecoratedSignature + end + defmodule TransactionEnvelope do - use XDR.Type.Struct, + use Struct, tx: Transaction, signatures: DecoratedSignatures end defmodule ClaimOfferAtom do - use XDR.Type.Struct, + use Struct, sellerID: AccountID, offerID: UInt64, assetSold: Asset, @@ -250,10 +264,6 @@ defmodule Stellar.XDR.Types.Transaction do amountBought: Int64 end - defmodule ClaimOfferAtoms do - use VariableArray, type: ClaimOfferAtom - end - defmodule CreateAccountResultCode do use Enum, CREATE_ACCOUNT_SUCCESS: 0, @@ -267,8 +277,9 @@ defmodule Stellar.XDR.Types.Transaction do use Union, switch: CreateAccountResultCode, cases: [ - {0, VOID} - ] + {0, Void} + ], + default: Void end defmodule PaymentResultCode do @@ -289,8 +300,9 @@ defmodule Stellar.XDR.Types.Transaction do use Union, switch: PaymentResultCode, cases: [ - {0, VOID} - ] + {0, Void} + ], + default: Void end defmodule PathPaymentResultCode do @@ -311,25 +323,29 @@ defmodule Stellar.XDR.Types.Transaction do end defmodule SimplePaymentResult do - use XDR.Type.Struct, + use Struct, destination: AccountID, asset: Asset, amount: Int64 end + defmodule ClaimOfferAtoms do + use VariableArray, type: ClaimOfferAtom + end + + defmodule PathPaymentSuccess do + use Struct, + offers: ClaimOfferAtoms, + last: SimplePaymentResult + end + defmodule PathPaymentResult do use Union, switch: PathPaymentResultCode, cases: [ - {0, PaymentSuccess}, - {-9, Asset} + PATH_PAYMENT_SUCCESS: PathPaymentSuccess, + PATH_PAYMENT_NO_ISSUER: Asset ] - - defmodule PaymentSuccess do - use XDR.Type.Struct, - offers: ClaimOfferAtoms, - last: SimplePaymentResult - end end defmodule ManageOfferResultCode do @@ -356,28 +372,29 @@ defmodule Stellar.XDR.Types.Transaction do MANAGE_OFFER_DELETED: 2 end - defmodule OfferUnion do + defmodule ManageOfferEffectData do use Union, switch: ManageOfferEffect, cases: [ - {0, OfferEntry}, - {1, OfferEntry}, - {2, VOID} + MANAGE_OFFER_CREATED: OfferEntry, + MANAGE_OFFER_UPDATED: OfferEntry, + MANAGE_OFFER_DELETED: Void ] end defmodule ManageOfferSuccessResult do - use XDR.Type.Struct, + use Struct, offersClaimed: ClaimOfferAtoms, - offer: OfferUnion + offer: ManageOfferEffectData end defmodule ManageOfferResult do use Union, switch: ManageOfferResultCode, cases: [ - {0, ManageOfferSuccessResult} - ] + MANAGE_OFFER_SUCCESS: ManageOfferSuccessResult + ], + default: Void end defmodule SetOptionsResultCode do @@ -398,8 +415,9 @@ defmodule Stellar.XDR.Types.Transaction do use Union, switch: SetOptionsResultCode, cases: [ - {0, VOID} - ] + SET_OPTIONS_SUCCESS: Void + ], + default: Void end defmodule ChangeTrustResultCode do @@ -416,8 +434,9 @@ defmodule Stellar.XDR.Types.Transaction do use Union, switch: ChangeTrustResultCode, cases: [ - {0, VOID} - ] + CHANGE_TRUST_SUCCESS: Void + ], + default: Void end defmodule AllowTrustResultCode do @@ -434,8 +453,9 @@ defmodule Stellar.XDR.Types.Transaction do use Union, switch: AllowTrustResultCode, cases: [ - {0, VOID} - ] + ALLOW_TRUST_SUCCESS: Void + ], + default: Void end defmodule AccountMergeResultCode do @@ -451,9 +471,9 @@ defmodule Stellar.XDR.Types.Transaction do use Union, switch: AccountMergeResultCode, cases: [ - {0, Int64}, - {-1, VOID} - ] + ACCOUNT_MERGE_SUCCESS: Int64 + ], + default: Void end defmodule InflationResultCode do @@ -463,7 +483,7 @@ defmodule Stellar.XDR.Types.Transaction do end defmodule InflationPayout do - use XDR.Type.Struct, + use Struct, destination: AccountID, amount: Int64 end @@ -476,9 +496,9 @@ defmodule Stellar.XDR.Types.Transaction do use Union, switch: InflationResultCode, cases: [ - {0, Payouts}, - {-1, VOID} - ] + INFLATION_SUCCESS: Payouts + ], + default: Void end defmodule ManageDataResultCode do @@ -494,39 +514,58 @@ defmodule Stellar.XDR.Types.Transaction do use Union, switch: ManageDataResultCode, cases: [ - {0, VOID} - ] + MANAGE_DATA_SUCCESS: Void + ], + default: Void + end + + defmodule BumpSequenceResultCode do + use Enum, + BUMP_SEQUENCE_SUCCESS: 0, + BUMP_SEQUENCE_BAD_SEQ: -1 + end + + defmodule BumpSequenceResult do + use Union, + switch: BumpSequenceResultCode, + cases: [ + BUMP_SEQUENCE_SUCCESS: Void + ], + default: Void end defmodule OperationResultCode do use Enum, opINNER: 0, opBAD_AUTH: -1, - opNO_ACCOUNT: -2 + opNO_ACCOUNT: -2, + opNOT_SUPPORTED: -3 end defmodule OperationResult do use Union, switch: OperationResultCode, cases: [ - {0, OperationResultInner} - ] + opINNER: OperationResultInner + ], + default: Void defmodule OperationResultInner do use Union, switch: OperationType, cases: [ - {0, CreateAccountResult}, - {1, PaymentResult}, - {2, PathPaymentResult}, - {3, ManageOfferResult}, - {4, ManageOfferResult}, - {5, SetOptionsResult}, - {6, ChangeTrustResult}, - {7, AllowTrustResult}, - {8, AccountMergeResult}, - {9, InflationResult}, - {10, ManageDataResult} + CREATE_ACCOUNT: CreateAccountResult, + PAYMENT: PaymentResult, + PATH_PAYMENT: PathPaymentResult, + MANAGE_OFFER: ManageOfferResult, + CREATE_PASSIVE_OFFER: ManageOfferResult, + SET_OPTIONS: SetOptionsResult, + CHANGE_TRUST: ChangeTrustResult, + ALLOW_TRUST: AllowTrustResult, + ACCOUNT_MERGE: AccountMergeResult, + INFLATION: InflationResult, + MANAGE_DATA: ManageDataResult, + BUMP_SEQUENCE: BumpSequenceResult ] end end @@ -555,16 +594,16 @@ defmodule Stellar.XDR.Types.Transaction do use Union, switch: TransactionResultCode, cases: [ - {0, OperationResults}, - {-1, OperationResults}, - {-2, VOID} - ] + txSUCCESS: OperationResults, + txFAILED: OperationResults + ], + default: Void end defmodule TransactionResult do - use XDR.Type.Struct, + use Struct, feeCharged: Int64, result: TransactionResultResult, - ext: Ext + ext: DefaultExt end end diff --git a/lib/stellar/xdr/types/types.ex b/lib/stellar/xdr/types/types.ex index 7b7e10d..e39c7f4 100644 --- a/lib/stellar/xdr/types/types.ex +++ b/lib/stellar/xdr/types/types.ex @@ -7,31 +7,42 @@ defmodule Stellar.XDR.Types do Int, Uint, Union, - VariableOpaque + VariableOpaque, + Void } - defmodule UInt32 do - use Uint - end + alias XDR.Util.Delegate - defmodule UInt64 do - use HyperUint + defmodule Hash do + use FixedOpaque, len: 32 end defmodule UInt256 do use FixedOpaque, len: 32 end + defmodule UInt32 do + use Delegate, to: Uint + end + + defmodule UInt64 do + use Delegate, to: HyperUint + end + defmodule Int32 do - use Int + use Delegate, to: Int end defmodule Int64 do - use HyperInt + use Delegate, to: HyperInt end - defmodule Hash do - use FixedOpaque, len: 32 + defmodule DefaultExt do + use Union, + switch: Int32, + cases: [ + {0, Void} + ] end defmodule CryptoKeyType do @@ -57,17 +68,21 @@ defmodule Stellar.XDR.Types do use Union, switch: PublicKeyType, cases: [ - {0, UInt256} + PUBLIC_KEY_TYPE_ED25519: UInt256 ] end + defmodule NodeID do + use Delegate, to: PublicKey + end + defmodule SignerKey do use Union, switch: SignerKeyType, cases: [ - {0, UInt256}, - {1, UInt256}, - {2, UInt256} + SIGNER_KEY_TYPE_ED25519: UInt256, + SIGNER_KEY_TYPE_PRE_AUTH_TX: UInt256, + SIGNER_KEY_TYPE_HASH_X: UInt256 ] end