Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] finishes porting over Stellar XDR types #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .iex.exs
Original file line number Diff line number Diff line change
@@ -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)
117 changes: 117 additions & 0 deletions lib/stellar/xdr/types/SCP.ex
Original file line number Diff line number Diff line change
@@ -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
267 changes: 267 additions & 0 deletions lib/stellar/xdr/types/ledger.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
defmodule Stellar.XDR.Types.Ledger do
alias XDR.Type.{
Enum,
FixedArray,
Struct,
Union,
VariableArray,
VariableOpaque
}

alias Stellar.XDR.Types.{
DefaultExt,
Hash,
Int32,
Int64,
LedgerEntries,
PublicKey,
SCP,
Transaction,
UInt32,
UInt64
}

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
end

defmodule Upgrades do
use VariableArray, max_len: 6, type: UpgradeType
end

defmodule StellarValue do
use Struct,
txSetHash: Hash,
closeTime: UInt64,
upgrades: Upgrades,
ext: DefaultExt
end

defmodule SkipList do
require Stellar.XDR.Types.Hash
use FixedArray, len: 4, type: Stellar.XDR.Types.Hash
end

defmodule LedgerHeader do
use 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: DefaultExt
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

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
Loading