From ddcb0c7dea5a56dce000d29dae8667b3ff247df7 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Mon, 27 Mar 2023 15:42:37 +0100 Subject: [PATCH] all: Update XDR to support the new value overhaul (#4814) * Gofmt * update xdr to 7356dc237ee0db5626561c129fb3fa4beaabbac6 * Soroban xdr value overhaul ScVal.Equals fixes (#4815) * Fix a bug in generated xdr for boolean unmarshalling * Output more helpful message when scval test fails * Fix equality for xdr ScVal overhaul * use bytes.equal * soroban-xdr-next-next: Fix txnbuild tests (#4817) * soroban-xdr-next-next: Fix XDR bool encoding/decoding (#4818) * all: Update libs & tests to support `ScVal`ue overhaul. (#4819) * services/horizon: Add `account_credited`/`debited` effects for SAC events. (#4806) * Include contract asset balance changes in payments (#4807) * all: Bump supported Go versions to 1.19 and 1.20. (#4810) * Use version 0.7.0 and 8abd3353c728f09ee1c8a2544f67a853e915afc2 of rs-soroban-sdk dependency * Embed XDR into a separate file for testing --------- Co-authored-by: shawn Co-authored-by: tamirms * ingest: Extract diagnostic events in GetOperationEvents() (#4820) --------- Co-authored-by: Alfonso Acosta Co-authored-by: George Co-authored-by: shawn Co-authored-by: tamirms --- .github/workflows/horizon.yml | 4 +- Makefile | 4 +- gxdr/xdr_generated.go | 2073 ++++++----- ingest/ledger_transaction.go | 16 +- ingest/ledger_transaction_test.go | 104 +- .../ingest/processors/contract_data.go | 333 +- .../ingest/processors/effects_processor.go | 15 +- .../ingest/processors/operations_processor.go | 8 +- .../processors/operations_processor_test.go | 31 +- .../internal/integration/contracts/Cargo.lock | 47 +- .../internal/integration/contracts/Cargo.toml | 8 +- .../contracts/increment/src/lib.rs | 4 +- .../contracts/soroban_token_spec.wasm | Bin 5782 -> 5730 bytes .../integration/invokehostfunction_test.go | 56 +- .../horizon/internal/integration/sac_test.go | 94 +- .../integration/testdata/soroban_add_u64.wasm | Bin 439 -> 505 bytes .../testdata/soroban_increment_contract.wasm | Bin 493 -> 494 bytes .../testdata/soroban_sac_test.wasm | Bin 1435 -> 1933 bytes support/contractevents/burn.go | 11 +- support/contractevents/event.go | 8 +- support/contractevents/event_test.go | 48 +- .../fixtures/transfer_event_xdr.bin | Bin 0 -> 224 bytes support/contractevents/generate.go | 28 +- support/contractevents/utils.go | 61 +- txnbuild/invoke_host_function_test.go | 22 +- xdr/Stellar-contract-spec.x | 47 +- xdr/Stellar-contract.x | 285 +- xdr/Stellar-ledger-entries.x | 2 - xdr/Stellar-ledger.x | 19 +- xdr/Stellar-transaction.x | 4 +- xdr/Stellar-types.x | 3 + xdr/scval.go | 183 +- xdr/scval_test.go | 2 +- xdr/xdr_generated.go | 3303 +++++++++-------- 34 files changed, 3756 insertions(+), 3067 deletions(-) create mode 100755 support/contractevents/fixtures/transfer_event_xdr.bin diff --git a/.github/workflows/horizon.yml b/.github/workflows/horizon.yml index efe06ab996..13eeabc085 100644 --- a/.github/workflows/horizon.yml +++ b/.github/workflows/horizon.yml @@ -34,8 +34,8 @@ jobs: env: HORIZON_INTEGRATION_TESTS_ENABLED: true HORIZON_INTEGRATION_TESTS_CORE_MAX_SUPPORTED_PROTOCOL: ${{ matrix.protocol-version }} - PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.8.1-1234.f94d66031.focal~soroban - PROTOCOL_20_CORE_DOCKER_IMG: gkudra/stellar-core:19.8.1-1234.f94d66031.focal-soroban + PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.8.1-1243.53ea43ace.focal~soroban + PROTOCOL_20_CORE_DOCKER_IMG: 2opremio/stellar-core:19.8.1-1243.53ea43ace.focal-soroban PROTOCOL_19_CORE_DEBIAN_PKG_VERSION: 19.5.0-1108.ca2fb0605.focal PROTOCOL_19_CORE_DOCKER_IMG: stellar/stellar-core:19.5.0-1108.ca2fb0605.focal PGHOST: localhost diff --git a/Makefile b/Makefile index c917c6ffa1..ba7fc5ac13 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,8 @@ xdr/Stellar-contract-spec.x \ xdr/Stellar-contract.x \ xdr/Stellar-internal.x -XDRGEN_COMMIT=57beb46bd3d1c77529218430bd6ed87cd69ac394 -XDRNEXT_COMMIT=df18148747e807618acf4639db41c4fd6f0be9fc +XDRGEN_COMMIT=80e38ef2a96489f6b501d4db3a350406e5aa3bab +XDRNEXT_COMMIT=7356dc237ee0db5626561c129fb3fa4beaabbac6 .PHONY: xdr xdr-clean xdr-update diff --git a/gxdr/xdr_generated.go b/gxdr/xdr_generated.go index b7d21dfe82..d363eb8926 100644 --- a/gxdr/xdr_generated.go +++ b/gxdr/xdr_generated.go @@ -117,10 +117,6 @@ type String64 = string // bound 64 type SequenceNumber = Int64 -type TimePoint = Uint64 - -type Duration = Uint64 - type DataValue = []byte // bound 64 // SHA256(LiquidityPoolParameters) @@ -1206,8 +1202,9 @@ type TransactionMetaV2 struct { type ContractEventType int32 const ( - SYSTEM ContractEventType = 0 - CONTRACT ContractEventType = 1 + SYSTEM ContractEventType = 0 + CONTRACT ContractEventType = 1 + DIAGNOSTIC ContractEventType = 2 ) type ContractEvent struct { @@ -1230,6 +1227,15 @@ type XdrAnon_ContractEvent_Body_V0 struct { Data SCVal } +type DiagnosticEvent struct { + InSuccessfulContractCall bool + Event ContractEvent +} + +type OperationDiagnosticEvents struct { + Events []DiagnosticEvent +} + type OperationEvents struct { Events []ContractEvent } @@ -1247,6 +1253,10 @@ type TransactionMetaV3 struct { TxResult TransactionResult // stores sha256(txChangesBefore, operations, txChangesAfter), Hashes [3]Hash + // Diagnostics events that are not hashed. One list per operation. + // This will contain all contract and diagnostic events. Even ones + // that were emitted in a failed contract call. + DiagnosticEvents []OperationDiagnosticEvents } // this is the meta produced when applying transactions @@ -2122,7 +2132,7 @@ type XdrAnon_ContractID_FromEd25519PublicKey struct { type CreateContractArgs struct { ContractID ContractID - Source SCContractCode + Source SCContractExecutable } type HostFunction struct { @@ -2284,7 +2294,7 @@ type XdrAnon_HashIDPreimage_SourceAccountContractID struct { } type XdrAnon_HashIDPreimage_CreateContractArgs struct { NetworkID Hash - Source SCContractCode + Source SCContractExecutable Salt Uint256 } type XdrAnon_HashIDPreimage_ContractAuth struct { @@ -3484,6 +3494,10 @@ type Uint64 = uint64 type Int64 = int64 +type TimePoint = Uint64 + +type Duration = Uint64 + // An ExtensionPoint is always marshaled as a 32-bit 0 value. At a // later point, it can be replaced by a different union so as to // extend a structure. @@ -3596,19 +3610,23 @@ type SCSpecType int32 const ( SC_SPEC_TYPE_VAL SCSpecType = 0 // Types with no parameters. - SC_SPEC_TYPE_U32 SCSpecType = 1 - SC_SPEC_TYPE_I32 SCSpecType = 2 - SC_SPEC_TYPE_U64 SCSpecType = 3 - SC_SPEC_TYPE_I64 SCSpecType = 4 - SC_SPEC_TYPE_U128 SCSpecType = 5 - SC_SPEC_TYPE_I128 SCSpecType = 6 - SC_SPEC_TYPE_BOOL SCSpecType = 7 - SC_SPEC_TYPE_SYMBOL SCSpecType = 8 - SC_SPEC_TYPE_BITSET SCSpecType = 9 - SC_SPEC_TYPE_STATUS SCSpecType = 10 - SC_SPEC_TYPE_BYTES SCSpecType = 11 - SC_SPEC_TYPE_INVOKER SCSpecType = 12 - SC_SPEC_TYPE_ADDRESS SCSpecType = 13 + SC_SPEC_TYPE_BOOL SCSpecType = 1 + SC_SPEC_TYPE_VOID SCSpecType = 2 + SC_SPEC_TYPE_STATUS SCSpecType = 3 + SC_SPEC_TYPE_U32 SCSpecType = 4 + SC_SPEC_TYPE_I32 SCSpecType = 5 + SC_SPEC_TYPE_U64 SCSpecType = 6 + SC_SPEC_TYPE_I64 SCSpecType = 7 + SC_SPEC_TYPE_TIMEPOINT SCSpecType = 8 + SC_SPEC_TYPE_DURATION SCSpecType = 9 + SC_SPEC_TYPE_U128 SCSpecType = 10 + SC_SPEC_TYPE_I128 SCSpecType = 11 + SC_SPEC_TYPE_U256 SCSpecType = 12 + SC_SPEC_TYPE_I256 SCSpecType = 13 + SC_SPEC_TYPE_BYTES SCSpecType = 14 + SC_SPEC_TYPE_STRING SCSpecType = 16 + SC_SPEC_TYPE_SYMBOL SCSpecType = 17 + SC_SPEC_TYPE_ADDRESS SCSpecType = 19 // Types with parameters. SC_SPEC_TYPE_OPTION SCSpecType = 1000 SC_SPEC_TYPE_RESULT SCSpecType = 1001 @@ -3657,7 +3675,7 @@ type SCSpecTypeUDT struct { type SCSpecTypeDef struct { // The union discriminant Type selects among the following arms: - // SC_SPEC_TYPE_VAL, SC_SPEC_TYPE_U64, SC_SPEC_TYPE_I64, SC_SPEC_TYPE_U128, SC_SPEC_TYPE_I128, SC_SPEC_TYPE_U32, SC_SPEC_TYPE_I32, SC_SPEC_TYPE_BOOL, SC_SPEC_TYPE_SYMBOL, SC_SPEC_TYPE_BITSET, SC_SPEC_TYPE_STATUS, SC_SPEC_TYPE_BYTES, SC_SPEC_TYPE_ADDRESS: + // SC_SPEC_TYPE_VAL, SC_SPEC_TYPE_BOOL, SC_SPEC_TYPE_VOID, SC_SPEC_TYPE_STATUS, SC_SPEC_TYPE_U32, SC_SPEC_TYPE_I32, SC_SPEC_TYPE_U64, SC_SPEC_TYPE_I64, SC_SPEC_TYPE_TIMEPOINT, SC_SPEC_TYPE_DURATION, SC_SPEC_TYPE_U128, SC_SPEC_TYPE_I128, SC_SPEC_TYPE_U256, SC_SPEC_TYPE_I256, SC_SPEC_TYPE_BYTES, SC_SPEC_TYPE_STRING, SC_SPEC_TYPE_SYMBOL, SC_SPEC_TYPE_ADDRESS: // void // SC_SPEC_TYPE_OPTION: // Option() *SCSpecTypeOption @@ -3792,32 +3810,49 @@ type SCSpecEntry struct { _u interface{} } -// A symbol is up to 10 chars drawn from [a-zA-Z0-9_], which can be packed -// into 60 bits with a 6-bit-per-character code, usable as a small key type -// to specify function, argument, tx-local environment and map entries -// efficiently. -type SCSymbol = string // bound 10 - type SCValType int32 const ( - SCV_U63 SCValType = 0 - SCV_U32 SCValType = 1 - SCV_I32 SCValType = 2 - SCV_STATIC SCValType = 3 - SCV_OBJECT SCValType = 4 - SCV_SYMBOL SCValType = 5 - SCV_BITSET SCValType = 6 - SCV_STATUS SCValType = 7 -) - -type SCStatic int32 - -const ( - SCS_VOID SCStatic = 0 - SCS_TRUE SCStatic = 1 - SCS_FALSE SCStatic = 2 - SCS_LEDGER_KEY_CONTRACT_CODE SCStatic = 3 + SCV_BOOL SCValType = 0 + SCV_VOID SCValType = 1 + SCV_STATUS SCValType = 2 + // 32 bits is the smallest type in WASM or XDR; no need for u8/u16. + SCV_U32 SCValType = 3 + SCV_I32 SCValType = 4 + // 64 bits is naturally supported by both WASM and XDR also. + SCV_U64 SCValType = 5 + SCV_I64 SCValType = 6 + // Time-related u64 subtypes with their own functions and formatting. + SCV_TIMEPOINT SCValType = 7 + SCV_DURATION SCValType = 8 + // 128 bits is naturally supported by Rust and we use it for Soroban + // fixed-point arithmetic prices / balances / similar "quantities". These + // are represented in XDR as a pair of 2 u64s, unlike {u,i}256 which is + // represented as an array of 32 bytes. + SCV_U128 SCValType = 9 + SCV_I128 SCValType = 10 + // 256 bits is the size of sha256 output, ed25519 keys, and the EVM machine + // word, so for interop use we include this even though it requires a small + // amount of Rust guest and/or host library code. + SCV_U256 SCValType = 11 + SCV_I256 SCValType = 12 + // Bytes come in 3 flavors, 2 of which have meaningfully different + // formatting and validity-checking / domain-restriction. + SCV_BYTES SCValType = 13 + SCV_STRING SCValType = 14 + SCV_SYMBOL SCValType = 15 + // Vecs and maps are just polymorphic containers of other ScVals. + SCV_VEC SCValType = 16 + SCV_MAP SCValType = 17 + // SCContractExecutable and SCAddressType are types that gets used separately from + // SCVal so we do not flatten their structures into separate SCVal cases. + SCV_CONTRACT_EXECUTABLE SCValType = 18 + SCV_ADDRESS SCValType = 19 + // SCV_LEDGER_KEY_CONTRACT_EXECUTABLE and SCV_LEDGER_KEY_NONCE are unique + // symbolic SCVals used as the key for ledger entries for a contract's code + // and an address' nonce, respectively. + SCV_LEDGER_KEY_CONTRACT_EXECUTABLE SCValType = 20 + SCV_LEDGER_KEY_NONCE SCValType = 21 ) type SCStatusType int32 @@ -3958,79 +3993,31 @@ type SCStatus struct { _u interface{} } -type SCVal struct { - // The union discriminant Type selects among the following arms: - // SCV_U63: - // U63() *Int64 - // SCV_U32: - // U32() *Uint32 - // SCV_I32: - // I32() *Int32 - // SCV_STATIC: - // Ic() *SCStatic - // SCV_OBJECT: - // Obj() **SCObject - // SCV_SYMBOL: - // Sym() *SCSymbol - // SCV_BITSET: - // Bits() *Uint64 - // SCV_STATUS: - // Status() *SCStatus - Type SCValType - _u interface{} -} - -type SCObjectType int32 - -const ( - SCO_VEC SCObjectType = 0 - SCO_MAP SCObjectType = 1 - SCO_U64 SCObjectType = 2 - SCO_I64 SCObjectType = 3 - SCO_U128 SCObjectType = 4 - SCO_I128 SCObjectType = 5 - SCO_BYTES SCObjectType = 6 - SCO_CONTRACT_CODE SCObjectType = 7 - SCO_ADDRESS SCObjectType = 8 - SCO_NONCE_KEY SCObjectType = 9 -) - -type SCMapEntry struct { - Key SCVal - Val SCVal +type Int128Parts struct { + // Both signed and unsigned 128-bit ints + // are transported in a pair of uint64s + // to reduce the risk of sign-extension. + Lo Uint64 + Hi Uint64 } -const SCVAL_LIMIT = 256000 - -type SCVec = []SCVal // bound SCVAL_LIMIT - -type SCMap = []SCMapEntry // bound SCVAL_LIMIT - -type SCContractCodeType int32 +type SCContractExecutableType int32 const ( - SCCONTRACT_CODE_WASM_REF SCContractCodeType = 0 - SCCONTRACT_CODE_TOKEN SCContractCodeType = 1 + SCCONTRACT_EXECUTABLE_WASM_REF SCContractExecutableType = 0 + SCCONTRACT_EXECUTABLE_TOKEN SCContractExecutableType = 1 ) -type SCContractCode struct { +type SCContractExecutable struct { // The union discriminant Type selects among the following arms: - // SCCONTRACT_CODE_WASM_REF: + // SCCONTRACT_EXECUTABLE_WASM_REF: // Wasm_id() *Hash - // SCCONTRACT_CODE_TOKEN: + // SCCONTRACT_EXECUTABLE_TOKEN: // void - Type SCContractCodeType + Type SCContractExecutableType _u interface{} } -type Int128Parts struct { - // Both signed and unsigned 128-bit ints - // are transported in a pair of uint64s - // to reduce the risk of sign-extension. - Lo Uint64 - Hi Uint64 -} - type SCAddressType int32 const ( @@ -4048,32 +4035,79 @@ type SCAddress struct { _u interface{} } -type SCObject struct { +const SCVAL_LIMIT = 256000 + +const SCSYMBOL_LIMIT = 32 + +type SCVec = []SCVal // bound SCVAL_LIMIT + +type SCMap = []SCMapEntry // bound SCVAL_LIMIT + +type SCBytes = []byte // bound SCVAL_LIMIT + +type SCString = string // bound SCVAL_LIMIT + +type SCSymbol = string // bound SCSYMBOL_LIMIT + +type SCNonceKey struct { + Nonce_address SCAddress +} + +type SCVal struct { // The union discriminant Type selects among the following arms: - // SCO_VEC: - // Vec() *SCVec - // SCO_MAP: - // Map() *SCMap - // SCO_U64: + // SCV_BOOL: + // B() *bool + // SCV_VOID: + // void + // SCV_STATUS: + // Error() *SCStatus + // SCV_U32: + // U32() *Uint32 + // SCV_I32: + // I32() *Int32 + // SCV_U64: // U64() *Uint64 - // SCO_I64: + // SCV_I64: // I64() *Int64 - // SCO_U128: + // SCV_TIMEPOINT: + // Timepoint() *TimePoint + // SCV_DURATION: + // Duration() *Duration + // SCV_U128: // U128() *Int128Parts - // SCO_I128: + // SCV_I128: // I128() *Int128Parts - // SCO_BYTES: - // Bin() *[]byte // bound SCVAL_LIMIT - // SCO_CONTRACT_CODE: - // ContractCode() *SCContractCode - // SCO_ADDRESS: + // SCV_U256: + // U256() *Uint256 + // SCV_I256: + // I256() *Uint256 + // SCV_BYTES: + // Bytes() *SCBytes + // SCV_STRING: + // Str() *SCString + // SCV_SYMBOL: + // Sym() *SCSymbol + // SCV_VEC: + // Vec() **SCVec + // SCV_MAP: + // Map() **SCMap + // SCV_CONTRACT_EXECUTABLE: + // Exec() *SCContractExecutable + // SCV_ADDRESS: // Address() *SCAddress - // SCO_NONCE_KEY: - // NonceAddress() *SCAddress - Type SCObjectType + // SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: + // void + // SCV_LEDGER_KEY_NONCE: + // Nonce_key() *SCNonceKey + Type SCValType _u interface{} } +type SCMapEntry struct { + Key SCVal + Val SCVal +} + type StoredTransactionSet struct { // The union discriminant V selects among the following arms: // 0: @@ -4753,26 +4787,6 @@ func XDR_SequenceNumber(v *SequenceNumber) XdrType_SequenceNumber { func (XdrType_SequenceNumber) XdrTypeName() string { return "SequenceNumber" } func (v XdrType_SequenceNumber) XdrUnwrap() XdrType { return v.XdrType_Int64 } -type XdrType_TimePoint struct { - XdrType_Uint64 -} - -func XDR_TimePoint(v *TimePoint) XdrType_TimePoint { - return XdrType_TimePoint{XDR_Uint64(v)} -} -func (XdrType_TimePoint) XdrTypeName() string { return "TimePoint" } -func (v XdrType_TimePoint) XdrUnwrap() XdrType { return v.XdrType_Uint64 } - -type XdrType_Duration struct { - XdrType_Uint64 -} - -func XDR_Duration(v *Duration) XdrType_Duration { - return XdrType_Duration{XDR_Uint64(v)} -} -func (XdrType_Duration) XdrTypeName() string { return "Duration" } -func (v XdrType_Duration) XdrUnwrap() XdrType { return v.XdrType_Uint64 } - type XdrType_DataValue struct { XdrVecOpaque } @@ -11343,12 +11357,14 @@ func (v *TransactionMetaV2) XdrRecurse(x XDR, name string) { func XDR_TransactionMetaV2(v *TransactionMetaV2) *TransactionMetaV2 { return v } var _XdrNames_ContractEventType = map[int32]string{ - int32(SYSTEM): "SYSTEM", - int32(CONTRACT): "CONTRACT", + int32(SYSTEM): "SYSTEM", + int32(CONTRACT): "CONTRACT", + int32(DIAGNOSTIC): "DIAGNOSTIC", } var _XdrValues_ContractEventType = map[string]int32{ - "SYSTEM": int32(SYSTEM), - "CONTRACT": int32(CONTRACT), + "SYSTEM": int32(SYSTEM), + "CONTRACT": int32(CONTRACT), + "DIAGNOSTIC": int32(DIAGNOSTIC), } func (ContractEventType) XdrEnumNames() map[int32]string { @@ -11566,6 +11582,92 @@ func (v *ContractEvent) XdrRecurse(x XDR, name string) { } func XDR_ContractEvent(v *ContractEvent) *ContractEvent { return v } +type XdrType_DiagnosticEvent = *DiagnosticEvent + +func (v *DiagnosticEvent) XdrPointer() interface{} { return v } +func (DiagnosticEvent) XdrTypeName() string { return "DiagnosticEvent" } +func (v DiagnosticEvent) XdrValue() interface{} { return v } +func (v *DiagnosticEvent) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (v *DiagnosticEvent) XdrRecurse(x XDR, name string) { + if name != "" { + name = x.Sprintf("%s.", name) + } + x.Marshal(x.Sprintf("%sinSuccessfulContractCall", name), XDR_bool(&v.InSuccessfulContractCall)) + x.Marshal(x.Sprintf("%sevent", name), XDR_ContractEvent(&v.Event)) +} +func XDR_DiagnosticEvent(v *DiagnosticEvent) *DiagnosticEvent { return v } + +type _XdrVec_unbounded_DiagnosticEvent []DiagnosticEvent + +func (_XdrVec_unbounded_DiagnosticEvent) XdrBound() uint32 { + const bound uint32 = 4294967295 // Force error if not const or doesn't fit + return bound +} +func (_XdrVec_unbounded_DiagnosticEvent) XdrCheckLen(length uint32) { + if length > uint32(4294967295) { + XdrPanic("_XdrVec_unbounded_DiagnosticEvent length %d exceeds bound 4294967295", length) + } else if int(length) < 0 { + XdrPanic("_XdrVec_unbounded_DiagnosticEvent length %d exceeds max int", length) + } +} +func (v _XdrVec_unbounded_DiagnosticEvent) GetVecLen() uint32 { return uint32(len(v)) } +func (v *_XdrVec_unbounded_DiagnosticEvent) SetVecLen(length uint32) { + v.XdrCheckLen(length) + if int(length) <= cap(*v) { + if int(length) != len(*v) { + *v = (*v)[:int(length)] + } + return + } + newcap := 2 * cap(*v) + if newcap < int(length) { // also catches overflow where 2*cap < 0 + newcap = int(length) + } else if bound := uint(4294967295); uint(newcap) > bound { + if int(bound) < 0 { + bound = ^uint(0) >> 1 + } + newcap = int(bound) + } + nv := make([]DiagnosticEvent, int(length), newcap) + copy(nv, *v) + *v = nv +} +func (v *_XdrVec_unbounded_DiagnosticEvent) XdrMarshalN(x XDR, name string, n uint32) { + v.XdrCheckLen(n) + for i := 0; i < int(n); i++ { + if i >= len(*v) { + v.SetVecLen(uint32(i + 1)) + } + XDR_DiagnosticEvent(&(*v)[i]).XdrMarshal(x, x.Sprintf("%s[%d]", name, i)) + } + if int(n) < len(*v) { + *v = (*v)[:int(n)] + } +} +func (v *_XdrVec_unbounded_DiagnosticEvent) XdrRecurse(x XDR, name string) { + size := XdrSize{Size: uint32(len(*v)), Bound: 4294967295} + x.Marshal(name, &size) + v.XdrMarshalN(x, name, size.Size) +} +func (_XdrVec_unbounded_DiagnosticEvent) XdrTypeName() string { return "DiagnosticEvent<>" } +func (v *_XdrVec_unbounded_DiagnosticEvent) XdrPointer() interface{} { return (*[]DiagnosticEvent)(v) } +func (v _XdrVec_unbounded_DiagnosticEvent) XdrValue() interface{} { return ([]DiagnosticEvent)(v) } +func (v *_XdrVec_unbounded_DiagnosticEvent) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } + +type XdrType_OperationDiagnosticEvents = *OperationDiagnosticEvents + +func (v *OperationDiagnosticEvents) XdrPointer() interface{} { return v } +func (OperationDiagnosticEvents) XdrTypeName() string { return "OperationDiagnosticEvents" } +func (v OperationDiagnosticEvents) XdrValue() interface{} { return v } +func (v *OperationDiagnosticEvents) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (v *OperationDiagnosticEvents) XdrRecurse(x XDR, name string) { + if name != "" { + name = x.Sprintf("%s.", name) + } + x.Marshal(x.Sprintf("%sevents", name), (*_XdrVec_unbounded_DiagnosticEvent)(&v.Events)) +} +func XDR_OperationDiagnosticEvents(v *OperationDiagnosticEvents) *OperationDiagnosticEvents { return v } + type _XdrVec_unbounded_ContractEvent []ContractEvent func (_XdrVec_unbounded_ContractEvent) XdrBound() uint32 { @@ -11710,6 +11812,71 @@ func (_XdrArray_3_Hash) XdrTypeName() string { return "Hash[]" } func (v *_XdrArray_3_Hash) XdrValue() interface{} { return v[:] } func (v *_XdrArray_3_Hash) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +type _XdrVec_unbounded_OperationDiagnosticEvents []OperationDiagnosticEvents + +func (_XdrVec_unbounded_OperationDiagnosticEvents) XdrBound() uint32 { + const bound uint32 = 4294967295 // Force error if not const or doesn't fit + return bound +} +func (_XdrVec_unbounded_OperationDiagnosticEvents) XdrCheckLen(length uint32) { + if length > uint32(4294967295) { + XdrPanic("_XdrVec_unbounded_OperationDiagnosticEvents length %d exceeds bound 4294967295", length) + } else if int(length) < 0 { + XdrPanic("_XdrVec_unbounded_OperationDiagnosticEvents length %d exceeds max int", length) + } +} +func (v _XdrVec_unbounded_OperationDiagnosticEvents) GetVecLen() uint32 { return uint32(len(v)) } +func (v *_XdrVec_unbounded_OperationDiagnosticEvents) SetVecLen(length uint32) { + v.XdrCheckLen(length) + if int(length) <= cap(*v) { + if int(length) != len(*v) { + *v = (*v)[:int(length)] + } + return + } + newcap := 2 * cap(*v) + if newcap < int(length) { // also catches overflow where 2*cap < 0 + newcap = int(length) + } else if bound := uint(4294967295); uint(newcap) > bound { + if int(bound) < 0 { + bound = ^uint(0) >> 1 + } + newcap = int(bound) + } + nv := make([]OperationDiagnosticEvents, int(length), newcap) + copy(nv, *v) + *v = nv +} +func (v *_XdrVec_unbounded_OperationDiagnosticEvents) XdrMarshalN(x XDR, name string, n uint32) { + v.XdrCheckLen(n) + for i := 0; i < int(n); i++ { + if i >= len(*v) { + v.SetVecLen(uint32(i + 1)) + } + XDR_OperationDiagnosticEvents(&(*v)[i]).XdrMarshal(x, x.Sprintf("%s[%d]", name, i)) + } + if int(n) < len(*v) { + *v = (*v)[:int(n)] + } +} +func (v *_XdrVec_unbounded_OperationDiagnosticEvents) XdrRecurse(x XDR, name string) { + size := XdrSize{Size: uint32(len(*v)), Bound: 4294967295} + x.Marshal(name, &size) + v.XdrMarshalN(x, name, size.Size) +} +func (_XdrVec_unbounded_OperationDiagnosticEvents) XdrTypeName() string { + return "OperationDiagnosticEvents<>" +} +func (v *_XdrVec_unbounded_OperationDiagnosticEvents) XdrPointer() interface{} { + return (*[]OperationDiagnosticEvents)(v) +} +func (v _XdrVec_unbounded_OperationDiagnosticEvents) XdrValue() interface{} { + return ([]OperationDiagnosticEvents)(v) +} +func (v *_XdrVec_unbounded_OperationDiagnosticEvents) XdrMarshal(x XDR, name string) { + x.Marshal(name, v) +} + type XdrType_TransactionMetaV3 = *TransactionMetaV3 func (v *TransactionMetaV3) XdrPointer() interface{} { return v } @@ -11726,6 +11893,7 @@ func (v *TransactionMetaV3) XdrRecurse(x XDR, name string) { x.Marshal(x.Sprintf("%sevents", name), (*_XdrVec_unbounded_OperationEvents)(&v.Events)) x.Marshal(x.Sprintf("%stxResult", name), XDR_TransactionResult(&v.TxResult)) x.Marshal(x.Sprintf("%shashes", name), (*_XdrArray_3_Hash)(&v.Hashes)) + x.Marshal(x.Sprintf("%sdiagnosticEvents", name), (*_XdrVec_unbounded_OperationDiagnosticEvents)(&v.DiagnosticEvents)) } func XDR_TransactionMetaV3(v *TransactionMetaV3) *TransactionMetaV3 { return v } @@ -15482,7 +15650,7 @@ func (v *CreateContractArgs) XdrRecurse(x XDR, name string) { name = x.Sprintf("%s.", name) } x.Marshal(x.Sprintf("%scontractID", name), XDR_ContractID(&v.ContractID)) - x.Marshal(x.Sprintf("%ssource", name), XDR_SCContractCode(&v.Source)) + x.Marshal(x.Sprintf("%ssource", name), XDR_SCContractExecutable(&v.Source)) } func XDR_CreateContractArgs(v *CreateContractArgs) *CreateContractArgs { return v } @@ -16671,7 +16839,7 @@ func (v *XdrAnon_HashIDPreimage_CreateContractArgs) XdrRecurse(x XDR, name strin name = x.Sprintf("%s.", name) } x.Marshal(x.Sprintf("%snetworkID", name), XDR_Hash(&v.NetworkID)) - x.Marshal(x.Sprintf("%ssource", name), XDR_SCContractCode(&v.Source)) + x.Marshal(x.Sprintf("%ssource", name), XDR_SCContractExecutable(&v.Source)) x.Marshal(x.Sprintf("%ssalt", name), XDR_Uint256(&v.Salt)) } func XDR_XdrAnon_HashIDPreimage_CreateContractArgs(v *XdrAnon_HashIDPreimage_CreateContractArgs) *XdrAnon_HashIDPreimage_CreateContractArgs { @@ -23706,6 +23874,26 @@ func XDR_Int64(v *Int64) XdrType_Int64 { func (XdrType_Int64) XdrTypeName() string { return "Int64" } func (v XdrType_Int64) XdrUnwrap() XdrType { return v.XdrType_int64 } +type XdrType_TimePoint struct { + XdrType_Uint64 +} + +func XDR_TimePoint(v *TimePoint) XdrType_TimePoint { + return XdrType_TimePoint{XDR_Uint64(v)} +} +func (XdrType_TimePoint) XdrTypeName() string { return "TimePoint" } +func (v XdrType_TimePoint) XdrUnwrap() XdrType { return v.XdrType_Uint64 } + +type XdrType_Duration struct { + XdrType_Uint64 +} + +func XDR_Duration(v *Duration) XdrType_Duration { + return XdrType_Duration{XDR_Uint64(v)} +} +func (XdrType_Duration) XdrTypeName() string { return "Duration" } +func (v XdrType_Duration) XdrUnwrap() XdrType { return v.XdrType_Uint64 } + var _XdrTags_ExtensionPoint = map[int32]bool{ XdrToI32(0): true, } @@ -24353,52 +24541,60 @@ func (u *SCEnvMetaEntry) XdrRecurse(x XDR, name string) { func XDR_SCEnvMetaEntry(v *SCEnvMetaEntry) *SCEnvMetaEntry { return v } var _XdrNames_SCSpecType = map[int32]string{ - int32(SC_SPEC_TYPE_VAL): "SC_SPEC_TYPE_VAL", - int32(SC_SPEC_TYPE_U32): "SC_SPEC_TYPE_U32", - int32(SC_SPEC_TYPE_I32): "SC_SPEC_TYPE_I32", - int32(SC_SPEC_TYPE_U64): "SC_SPEC_TYPE_U64", - int32(SC_SPEC_TYPE_I64): "SC_SPEC_TYPE_I64", - int32(SC_SPEC_TYPE_U128): "SC_SPEC_TYPE_U128", - int32(SC_SPEC_TYPE_I128): "SC_SPEC_TYPE_I128", - int32(SC_SPEC_TYPE_BOOL): "SC_SPEC_TYPE_BOOL", - int32(SC_SPEC_TYPE_SYMBOL): "SC_SPEC_TYPE_SYMBOL", - int32(SC_SPEC_TYPE_BITSET): "SC_SPEC_TYPE_BITSET", - int32(SC_SPEC_TYPE_STATUS): "SC_SPEC_TYPE_STATUS", - int32(SC_SPEC_TYPE_BYTES): "SC_SPEC_TYPE_BYTES", - int32(SC_SPEC_TYPE_INVOKER): "SC_SPEC_TYPE_INVOKER", - int32(SC_SPEC_TYPE_ADDRESS): "SC_SPEC_TYPE_ADDRESS", - int32(SC_SPEC_TYPE_OPTION): "SC_SPEC_TYPE_OPTION", - int32(SC_SPEC_TYPE_RESULT): "SC_SPEC_TYPE_RESULT", - int32(SC_SPEC_TYPE_VEC): "SC_SPEC_TYPE_VEC", - int32(SC_SPEC_TYPE_SET): "SC_SPEC_TYPE_SET", - int32(SC_SPEC_TYPE_MAP): "SC_SPEC_TYPE_MAP", - int32(SC_SPEC_TYPE_TUPLE): "SC_SPEC_TYPE_TUPLE", - int32(SC_SPEC_TYPE_BYTES_N): "SC_SPEC_TYPE_BYTES_N", - int32(SC_SPEC_TYPE_UDT): "SC_SPEC_TYPE_UDT", + int32(SC_SPEC_TYPE_VAL): "SC_SPEC_TYPE_VAL", + int32(SC_SPEC_TYPE_BOOL): "SC_SPEC_TYPE_BOOL", + int32(SC_SPEC_TYPE_VOID): "SC_SPEC_TYPE_VOID", + int32(SC_SPEC_TYPE_STATUS): "SC_SPEC_TYPE_STATUS", + int32(SC_SPEC_TYPE_U32): "SC_SPEC_TYPE_U32", + int32(SC_SPEC_TYPE_I32): "SC_SPEC_TYPE_I32", + int32(SC_SPEC_TYPE_U64): "SC_SPEC_TYPE_U64", + int32(SC_SPEC_TYPE_I64): "SC_SPEC_TYPE_I64", + int32(SC_SPEC_TYPE_TIMEPOINT): "SC_SPEC_TYPE_TIMEPOINT", + int32(SC_SPEC_TYPE_DURATION): "SC_SPEC_TYPE_DURATION", + int32(SC_SPEC_TYPE_U128): "SC_SPEC_TYPE_U128", + int32(SC_SPEC_TYPE_I128): "SC_SPEC_TYPE_I128", + int32(SC_SPEC_TYPE_U256): "SC_SPEC_TYPE_U256", + int32(SC_SPEC_TYPE_I256): "SC_SPEC_TYPE_I256", + int32(SC_SPEC_TYPE_BYTES): "SC_SPEC_TYPE_BYTES", + int32(SC_SPEC_TYPE_STRING): "SC_SPEC_TYPE_STRING", + int32(SC_SPEC_TYPE_SYMBOL): "SC_SPEC_TYPE_SYMBOL", + int32(SC_SPEC_TYPE_ADDRESS): "SC_SPEC_TYPE_ADDRESS", + int32(SC_SPEC_TYPE_OPTION): "SC_SPEC_TYPE_OPTION", + int32(SC_SPEC_TYPE_RESULT): "SC_SPEC_TYPE_RESULT", + int32(SC_SPEC_TYPE_VEC): "SC_SPEC_TYPE_VEC", + int32(SC_SPEC_TYPE_SET): "SC_SPEC_TYPE_SET", + int32(SC_SPEC_TYPE_MAP): "SC_SPEC_TYPE_MAP", + int32(SC_SPEC_TYPE_TUPLE): "SC_SPEC_TYPE_TUPLE", + int32(SC_SPEC_TYPE_BYTES_N): "SC_SPEC_TYPE_BYTES_N", + int32(SC_SPEC_TYPE_UDT): "SC_SPEC_TYPE_UDT", } var _XdrValues_SCSpecType = map[string]int32{ - "SC_SPEC_TYPE_VAL": int32(SC_SPEC_TYPE_VAL), - "SC_SPEC_TYPE_U32": int32(SC_SPEC_TYPE_U32), - "SC_SPEC_TYPE_I32": int32(SC_SPEC_TYPE_I32), - "SC_SPEC_TYPE_U64": int32(SC_SPEC_TYPE_U64), - "SC_SPEC_TYPE_I64": int32(SC_SPEC_TYPE_I64), - "SC_SPEC_TYPE_U128": int32(SC_SPEC_TYPE_U128), - "SC_SPEC_TYPE_I128": int32(SC_SPEC_TYPE_I128), - "SC_SPEC_TYPE_BOOL": int32(SC_SPEC_TYPE_BOOL), - "SC_SPEC_TYPE_SYMBOL": int32(SC_SPEC_TYPE_SYMBOL), - "SC_SPEC_TYPE_BITSET": int32(SC_SPEC_TYPE_BITSET), - "SC_SPEC_TYPE_STATUS": int32(SC_SPEC_TYPE_STATUS), - "SC_SPEC_TYPE_BYTES": int32(SC_SPEC_TYPE_BYTES), - "SC_SPEC_TYPE_INVOKER": int32(SC_SPEC_TYPE_INVOKER), - "SC_SPEC_TYPE_ADDRESS": int32(SC_SPEC_TYPE_ADDRESS), - "SC_SPEC_TYPE_OPTION": int32(SC_SPEC_TYPE_OPTION), - "SC_SPEC_TYPE_RESULT": int32(SC_SPEC_TYPE_RESULT), - "SC_SPEC_TYPE_VEC": int32(SC_SPEC_TYPE_VEC), - "SC_SPEC_TYPE_SET": int32(SC_SPEC_TYPE_SET), - "SC_SPEC_TYPE_MAP": int32(SC_SPEC_TYPE_MAP), - "SC_SPEC_TYPE_TUPLE": int32(SC_SPEC_TYPE_TUPLE), - "SC_SPEC_TYPE_BYTES_N": int32(SC_SPEC_TYPE_BYTES_N), - "SC_SPEC_TYPE_UDT": int32(SC_SPEC_TYPE_UDT), + "SC_SPEC_TYPE_VAL": int32(SC_SPEC_TYPE_VAL), + "SC_SPEC_TYPE_BOOL": int32(SC_SPEC_TYPE_BOOL), + "SC_SPEC_TYPE_VOID": int32(SC_SPEC_TYPE_VOID), + "SC_SPEC_TYPE_STATUS": int32(SC_SPEC_TYPE_STATUS), + "SC_SPEC_TYPE_U32": int32(SC_SPEC_TYPE_U32), + "SC_SPEC_TYPE_I32": int32(SC_SPEC_TYPE_I32), + "SC_SPEC_TYPE_U64": int32(SC_SPEC_TYPE_U64), + "SC_SPEC_TYPE_I64": int32(SC_SPEC_TYPE_I64), + "SC_SPEC_TYPE_TIMEPOINT": int32(SC_SPEC_TYPE_TIMEPOINT), + "SC_SPEC_TYPE_DURATION": int32(SC_SPEC_TYPE_DURATION), + "SC_SPEC_TYPE_U128": int32(SC_SPEC_TYPE_U128), + "SC_SPEC_TYPE_I128": int32(SC_SPEC_TYPE_I128), + "SC_SPEC_TYPE_U256": int32(SC_SPEC_TYPE_U256), + "SC_SPEC_TYPE_I256": int32(SC_SPEC_TYPE_I256), + "SC_SPEC_TYPE_BYTES": int32(SC_SPEC_TYPE_BYTES), + "SC_SPEC_TYPE_STRING": int32(SC_SPEC_TYPE_STRING), + "SC_SPEC_TYPE_SYMBOL": int32(SC_SPEC_TYPE_SYMBOL), + "SC_SPEC_TYPE_ADDRESS": int32(SC_SPEC_TYPE_ADDRESS), + "SC_SPEC_TYPE_OPTION": int32(SC_SPEC_TYPE_OPTION), + "SC_SPEC_TYPE_RESULT": int32(SC_SPEC_TYPE_RESULT), + "SC_SPEC_TYPE_VEC": int32(SC_SPEC_TYPE_VEC), + "SC_SPEC_TYPE_SET": int32(SC_SPEC_TYPE_SET), + "SC_SPEC_TYPE_MAP": int32(SC_SPEC_TYPE_MAP), + "SC_SPEC_TYPE_TUPLE": int32(SC_SPEC_TYPE_TUPLE), + "SC_SPEC_TYPE_BYTES_N": int32(SC_SPEC_TYPE_BYTES_N), + "SC_SPEC_TYPE_UDT": int32(SC_SPEC_TYPE_UDT), } func (SCSpecType) XdrEnumNames() map[int32]string { @@ -24438,7 +24634,7 @@ type XdrType_SCSpecType = *SCSpecType func XDR_SCSpecType(v *SCSpecType) *SCSpecType { return v } var _XdrComments_SCSpecType = map[int32]string{ - int32(SC_SPEC_TYPE_U32): "Types with no parameters.", + int32(SC_SPEC_TYPE_BOOL): "Types with no parameters.", int32(SC_SPEC_TYPE_OPTION): "Types with parameters.", int32(SC_SPEC_TYPE_UDT): "User defined types.", } @@ -24619,27 +24815,32 @@ func (v *SCSpecTypeUDT) XdrRecurse(x XDR, name string) { func XDR_SCSpecTypeUDT(v *SCSpecTypeUDT) *SCSpecTypeUDT { return v } var _XdrTags_SCSpecTypeDef = map[int32]bool{ - XdrToI32(SC_SPEC_TYPE_VAL): true, - XdrToI32(SC_SPEC_TYPE_U64): true, - XdrToI32(SC_SPEC_TYPE_I64): true, - XdrToI32(SC_SPEC_TYPE_U128): true, - XdrToI32(SC_SPEC_TYPE_I128): true, - XdrToI32(SC_SPEC_TYPE_U32): true, - XdrToI32(SC_SPEC_TYPE_I32): true, - XdrToI32(SC_SPEC_TYPE_BOOL): true, - XdrToI32(SC_SPEC_TYPE_SYMBOL): true, - XdrToI32(SC_SPEC_TYPE_BITSET): true, - XdrToI32(SC_SPEC_TYPE_STATUS): true, - XdrToI32(SC_SPEC_TYPE_BYTES): true, - XdrToI32(SC_SPEC_TYPE_ADDRESS): true, - XdrToI32(SC_SPEC_TYPE_OPTION): true, - XdrToI32(SC_SPEC_TYPE_RESULT): true, - XdrToI32(SC_SPEC_TYPE_VEC): true, - XdrToI32(SC_SPEC_TYPE_MAP): true, - XdrToI32(SC_SPEC_TYPE_SET): true, - XdrToI32(SC_SPEC_TYPE_TUPLE): true, - XdrToI32(SC_SPEC_TYPE_BYTES_N): true, - XdrToI32(SC_SPEC_TYPE_UDT): true, + XdrToI32(SC_SPEC_TYPE_VAL): true, + XdrToI32(SC_SPEC_TYPE_BOOL): true, + XdrToI32(SC_SPEC_TYPE_VOID): true, + XdrToI32(SC_SPEC_TYPE_STATUS): true, + XdrToI32(SC_SPEC_TYPE_U32): true, + XdrToI32(SC_SPEC_TYPE_I32): true, + XdrToI32(SC_SPEC_TYPE_U64): true, + XdrToI32(SC_SPEC_TYPE_I64): true, + XdrToI32(SC_SPEC_TYPE_TIMEPOINT): true, + XdrToI32(SC_SPEC_TYPE_DURATION): true, + XdrToI32(SC_SPEC_TYPE_U128): true, + XdrToI32(SC_SPEC_TYPE_I128): true, + XdrToI32(SC_SPEC_TYPE_U256): true, + XdrToI32(SC_SPEC_TYPE_I256): true, + XdrToI32(SC_SPEC_TYPE_BYTES): true, + XdrToI32(SC_SPEC_TYPE_STRING): true, + XdrToI32(SC_SPEC_TYPE_SYMBOL): true, + XdrToI32(SC_SPEC_TYPE_ADDRESS): true, + XdrToI32(SC_SPEC_TYPE_OPTION): true, + XdrToI32(SC_SPEC_TYPE_RESULT): true, + XdrToI32(SC_SPEC_TYPE_VEC): true, + XdrToI32(SC_SPEC_TYPE_MAP): true, + XdrToI32(SC_SPEC_TYPE_SET): true, + XdrToI32(SC_SPEC_TYPE_TUPLE): true, + XdrToI32(SC_SPEC_TYPE_BYTES_N): true, + XdrToI32(SC_SPEC_TYPE_UDT): true, } func (_ SCSpecTypeDef) XdrValidTags() map[int32]bool { @@ -24767,7 +24968,7 @@ func (u *SCSpecTypeDef) Udt() *SCSpecTypeUDT { } func (u SCSpecTypeDef) XdrValid() bool { switch u.Type { - case SC_SPEC_TYPE_VAL, SC_SPEC_TYPE_U64, SC_SPEC_TYPE_I64, SC_SPEC_TYPE_U128, SC_SPEC_TYPE_I128, SC_SPEC_TYPE_U32, SC_SPEC_TYPE_I32, SC_SPEC_TYPE_BOOL, SC_SPEC_TYPE_SYMBOL, SC_SPEC_TYPE_BITSET, SC_SPEC_TYPE_STATUS, SC_SPEC_TYPE_BYTES, SC_SPEC_TYPE_ADDRESS, SC_SPEC_TYPE_OPTION, SC_SPEC_TYPE_RESULT, SC_SPEC_TYPE_VEC, SC_SPEC_TYPE_MAP, SC_SPEC_TYPE_SET, SC_SPEC_TYPE_TUPLE, SC_SPEC_TYPE_BYTES_N, SC_SPEC_TYPE_UDT: + case SC_SPEC_TYPE_VAL, SC_SPEC_TYPE_BOOL, SC_SPEC_TYPE_VOID, SC_SPEC_TYPE_STATUS, SC_SPEC_TYPE_U32, SC_SPEC_TYPE_I32, SC_SPEC_TYPE_U64, SC_SPEC_TYPE_I64, SC_SPEC_TYPE_TIMEPOINT, SC_SPEC_TYPE_DURATION, SC_SPEC_TYPE_U128, SC_SPEC_TYPE_I128, SC_SPEC_TYPE_U256, SC_SPEC_TYPE_I256, SC_SPEC_TYPE_BYTES, SC_SPEC_TYPE_STRING, SC_SPEC_TYPE_SYMBOL, SC_SPEC_TYPE_ADDRESS, SC_SPEC_TYPE_OPTION, SC_SPEC_TYPE_RESULT, SC_SPEC_TYPE_VEC, SC_SPEC_TYPE_MAP, SC_SPEC_TYPE_SET, SC_SPEC_TYPE_TUPLE, SC_SPEC_TYPE_BYTES_N, SC_SPEC_TYPE_UDT: return true } return false @@ -24780,7 +24981,7 @@ func (u *SCSpecTypeDef) XdrUnionTagName() string { } func (u *SCSpecTypeDef) XdrUnionBody() XdrType { switch u.Type { - case SC_SPEC_TYPE_VAL, SC_SPEC_TYPE_U64, SC_SPEC_TYPE_I64, SC_SPEC_TYPE_U128, SC_SPEC_TYPE_I128, SC_SPEC_TYPE_U32, SC_SPEC_TYPE_I32, SC_SPEC_TYPE_BOOL, SC_SPEC_TYPE_SYMBOL, SC_SPEC_TYPE_BITSET, SC_SPEC_TYPE_STATUS, SC_SPEC_TYPE_BYTES, SC_SPEC_TYPE_ADDRESS: + case SC_SPEC_TYPE_VAL, SC_SPEC_TYPE_BOOL, SC_SPEC_TYPE_VOID, SC_SPEC_TYPE_STATUS, SC_SPEC_TYPE_U32, SC_SPEC_TYPE_I32, SC_SPEC_TYPE_U64, SC_SPEC_TYPE_I64, SC_SPEC_TYPE_TIMEPOINT, SC_SPEC_TYPE_DURATION, SC_SPEC_TYPE_U128, SC_SPEC_TYPE_I128, SC_SPEC_TYPE_U256, SC_SPEC_TYPE_I256, SC_SPEC_TYPE_BYTES, SC_SPEC_TYPE_STRING, SC_SPEC_TYPE_SYMBOL, SC_SPEC_TYPE_ADDRESS: return nil case SC_SPEC_TYPE_OPTION: return XDR_SCSpecTypeOption(u.Option()) @@ -24803,7 +25004,7 @@ func (u *SCSpecTypeDef) XdrUnionBody() XdrType { } func (u *SCSpecTypeDef) XdrUnionBodyName() string { switch u.Type { - case SC_SPEC_TYPE_VAL, SC_SPEC_TYPE_U64, SC_SPEC_TYPE_I64, SC_SPEC_TYPE_U128, SC_SPEC_TYPE_I128, SC_SPEC_TYPE_U32, SC_SPEC_TYPE_I32, SC_SPEC_TYPE_BOOL, SC_SPEC_TYPE_SYMBOL, SC_SPEC_TYPE_BITSET, SC_SPEC_TYPE_STATUS, SC_SPEC_TYPE_BYTES, SC_SPEC_TYPE_ADDRESS: + case SC_SPEC_TYPE_VAL, SC_SPEC_TYPE_BOOL, SC_SPEC_TYPE_VOID, SC_SPEC_TYPE_STATUS, SC_SPEC_TYPE_U32, SC_SPEC_TYPE_I32, SC_SPEC_TYPE_U64, SC_SPEC_TYPE_I64, SC_SPEC_TYPE_TIMEPOINT, SC_SPEC_TYPE_DURATION, SC_SPEC_TYPE_U128, SC_SPEC_TYPE_I128, SC_SPEC_TYPE_U256, SC_SPEC_TYPE_I256, SC_SPEC_TYPE_BYTES, SC_SPEC_TYPE_STRING, SC_SPEC_TYPE_SYMBOL, SC_SPEC_TYPE_ADDRESS: return "" case SC_SPEC_TYPE_OPTION: return "Option" @@ -24837,7 +25038,7 @@ func (u *SCSpecTypeDef) XdrRecurse(x XDR, name string) { } XDR_SCSpecType(&u.Type).XdrMarshal(x, x.Sprintf("%stype", name)) switch u.Type { - case SC_SPEC_TYPE_VAL, SC_SPEC_TYPE_U64, SC_SPEC_TYPE_I64, SC_SPEC_TYPE_U128, SC_SPEC_TYPE_I128, SC_SPEC_TYPE_U32, SC_SPEC_TYPE_I32, SC_SPEC_TYPE_BOOL, SC_SPEC_TYPE_SYMBOL, SC_SPEC_TYPE_BITSET, SC_SPEC_TYPE_STATUS, SC_SPEC_TYPE_BYTES, SC_SPEC_TYPE_ADDRESS: + case SC_SPEC_TYPE_VAL, SC_SPEC_TYPE_BOOL, SC_SPEC_TYPE_VOID, SC_SPEC_TYPE_STATUS, SC_SPEC_TYPE_U32, SC_SPEC_TYPE_I32, SC_SPEC_TYPE_U64, SC_SPEC_TYPE_I64, SC_SPEC_TYPE_TIMEPOINT, SC_SPEC_TYPE_DURATION, SC_SPEC_TYPE_U128, SC_SPEC_TYPE_I128, SC_SPEC_TYPE_U256, SC_SPEC_TYPE_I256, SC_SPEC_TYPE_BYTES, SC_SPEC_TYPE_STRING, SC_SPEC_TYPE_SYMBOL, SC_SPEC_TYPE_ADDRESS: return case SC_SPEC_TYPE_OPTION: x.Marshal(x.Sprintf("%soption", name), XDR_SCSpecTypeOption(u.Option())) @@ -25753,35 +25954,53 @@ func (u *SCSpecEntry) XdrRecurse(x XDR, name string) { } func XDR_SCSpecEntry(v *SCSpecEntry) *SCSpecEntry { return v } -type XdrType_SCSymbol struct { - XdrString -} - -func XDR_SCSymbol(v *SCSymbol) XdrType_SCSymbol { - return XdrType_SCSymbol{XdrString{v, 10}} -} -func (XdrType_SCSymbol) XdrTypeName() string { return "SCSymbol" } -func (v XdrType_SCSymbol) XdrUnwrap() XdrType { return v.XdrString } - var _XdrNames_SCValType = map[int32]string{ - int32(SCV_U63): "SCV_U63", - int32(SCV_U32): "SCV_U32", - int32(SCV_I32): "SCV_I32", - int32(SCV_STATIC): "SCV_STATIC", - int32(SCV_OBJECT): "SCV_OBJECT", - int32(SCV_SYMBOL): "SCV_SYMBOL", - int32(SCV_BITSET): "SCV_BITSET", - int32(SCV_STATUS): "SCV_STATUS", + int32(SCV_BOOL): "SCV_BOOL", + int32(SCV_VOID): "SCV_VOID", + int32(SCV_STATUS): "SCV_STATUS", + int32(SCV_U32): "SCV_U32", + int32(SCV_I32): "SCV_I32", + int32(SCV_U64): "SCV_U64", + int32(SCV_I64): "SCV_I64", + int32(SCV_TIMEPOINT): "SCV_TIMEPOINT", + int32(SCV_DURATION): "SCV_DURATION", + int32(SCV_U128): "SCV_U128", + int32(SCV_I128): "SCV_I128", + int32(SCV_U256): "SCV_U256", + int32(SCV_I256): "SCV_I256", + int32(SCV_BYTES): "SCV_BYTES", + int32(SCV_STRING): "SCV_STRING", + int32(SCV_SYMBOL): "SCV_SYMBOL", + int32(SCV_VEC): "SCV_VEC", + int32(SCV_MAP): "SCV_MAP", + int32(SCV_CONTRACT_EXECUTABLE): "SCV_CONTRACT_EXECUTABLE", + int32(SCV_ADDRESS): "SCV_ADDRESS", + int32(SCV_LEDGER_KEY_CONTRACT_EXECUTABLE): "SCV_LEDGER_KEY_CONTRACT_EXECUTABLE", + int32(SCV_LEDGER_KEY_NONCE): "SCV_LEDGER_KEY_NONCE", } var _XdrValues_SCValType = map[string]int32{ - "SCV_U63": int32(SCV_U63), - "SCV_U32": int32(SCV_U32), - "SCV_I32": int32(SCV_I32), - "SCV_STATIC": int32(SCV_STATIC), - "SCV_OBJECT": int32(SCV_OBJECT), - "SCV_SYMBOL": int32(SCV_SYMBOL), - "SCV_BITSET": int32(SCV_BITSET), - "SCV_STATUS": int32(SCV_STATUS), + "SCV_BOOL": int32(SCV_BOOL), + "SCV_VOID": int32(SCV_VOID), + "SCV_STATUS": int32(SCV_STATUS), + "SCV_U32": int32(SCV_U32), + "SCV_I32": int32(SCV_I32), + "SCV_U64": int32(SCV_U64), + "SCV_I64": int32(SCV_I64), + "SCV_TIMEPOINT": int32(SCV_TIMEPOINT), + "SCV_DURATION": int32(SCV_DURATION), + "SCV_U128": int32(SCV_U128), + "SCV_I128": int32(SCV_I128), + "SCV_U256": int32(SCV_U256), + "SCV_I256": int32(SCV_I256), + "SCV_BYTES": int32(SCV_BYTES), + "SCV_STRING": int32(SCV_STRING), + "SCV_SYMBOL": int32(SCV_SYMBOL), + "SCV_VEC": int32(SCV_VEC), + "SCV_MAP": int32(SCV_MAP), + "SCV_CONTRACT_EXECUTABLE": int32(SCV_CONTRACT_EXECUTABLE), + "SCV_ADDRESS": int32(SCV_ADDRESS), + "SCV_LEDGER_KEY_CONTRACT_EXECUTABLE": int32(SCV_LEDGER_KEY_CONTRACT_EXECUTABLE), + "SCV_LEDGER_KEY_NONCE": int32(SCV_LEDGER_KEY_NONCE), } func (SCValType) XdrEnumNames() map[int32]string { @@ -25820,54 +26039,21 @@ type XdrType_SCValType = *SCValType func XDR_SCValType(v *SCValType) *SCValType { return v } -var _XdrNames_SCStatic = map[int32]string{ - int32(SCS_VOID): "SCS_VOID", - int32(SCS_TRUE): "SCS_TRUE", - int32(SCS_FALSE): "SCS_FALSE", - int32(SCS_LEDGER_KEY_CONTRACT_CODE): "SCS_LEDGER_KEY_CONTRACT_CODE", -} -var _XdrValues_SCStatic = map[string]int32{ - "SCS_VOID": int32(SCS_VOID), - "SCS_TRUE": int32(SCS_TRUE), - "SCS_FALSE": int32(SCS_FALSE), - "SCS_LEDGER_KEY_CONTRACT_CODE": int32(SCS_LEDGER_KEY_CONTRACT_CODE), +var _XdrComments_SCValType = map[int32]string{ + int32(SCV_U32): "32 bits is the smallest type in WASM or XDR; no need for u8/u16.", + int32(SCV_U64): "64 bits is naturally supported by both WASM and XDR also.", + int32(SCV_TIMEPOINT): "Time-related u64 subtypes with their own functions and formatting.", + int32(SCV_U128): "128 bits is naturally supported by Rust and we use it for Soroban fixed-point arithmetic prices / balances / similar \"quantities\". These are represented in XDR as a pair of 2 u64s, unlike {u,i}256 which is represented as an array of 32 bytes.", + int32(SCV_U256): "256 bits is the size of sha256 output, ed25519 keys, and the EVM machine word, so for interop use we include this even though it requires a small amount of Rust guest and/or host library code.", + int32(SCV_BYTES): "Bytes come in 3 flavors, 2 of which have meaningfully different formatting and validity-checking / domain-restriction.", + int32(SCV_VEC): "Vecs and maps are just polymorphic containers of other ScVals.", + int32(SCV_CONTRACT_EXECUTABLE): "SCContractExecutable and SCAddressType are types that gets used separately from SCVal so we do not flatten their structures into separate SCVal cases.", + int32(SCV_LEDGER_KEY_CONTRACT_EXECUTABLE): "SCV_LEDGER_KEY_CONTRACT_EXECUTABLE and SCV_LEDGER_KEY_NONCE are unique symbolic SCVals used as the key for ledger entries for a contract's code and an address' nonce, respectively.", } -func (SCStatic) XdrEnumNames() map[int32]string { - return _XdrNames_SCStatic -} -func (v SCStatic) String() string { - if s, ok := _XdrNames_SCStatic[int32(v)]; ok { - return s - } - return fmt.Sprintf("SCStatic#%d", v) -} -func (v *SCStatic) Scan(ss fmt.ScanState, _ rune) error { - if tok, err := ss.Token(true, XdrSymChar); err != nil { - return err - } else { - stok := string(tok) - if val, ok := _XdrValues_SCStatic[stok]; ok { - *v = SCStatic(val) - return nil - } else if stok == "SCStatic" { - if n, err := fmt.Fscanf(ss, "#%d", (*int32)(v)); n == 1 && err == nil { - return nil - } - } - return XdrError(fmt.Sprintf("%s is not a valid SCStatic.", stok)) - } +func (e SCValType) XdrEnumComments() map[int32]string { + return _XdrComments_SCValType } -func (v SCStatic) GetU32() uint32 { return uint32(v) } -func (v *SCStatic) SetU32(n uint32) { *v = SCStatic(n) } -func (v *SCStatic) XdrPointer() interface{} { return v } -func (SCStatic) XdrTypeName() string { return "SCStatic" } -func (v SCStatic) XdrValue() interface{} { return v } -func (v *SCStatic) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } - -type XdrType_SCStatic = *SCStatic - -func XDR_SCStatic(v *SCStatic) *SCStatic { return v } var _XdrNames_SCStatusType = map[int32]string{ int32(SST_OK): "SST_OK", @@ -26633,385 +26819,280 @@ func (u *SCStatus) XdrRecurse(x XDR, name string) { } func XDR_SCStatus(v *SCStatus) *SCStatus { return v } -type _XdrPtr_SCObject struct { - p **SCObject -} -type _ptrflag_SCObject _XdrPtr_SCObject +type XdrType_Int128Parts = *Int128Parts -func (v _ptrflag_SCObject) String() string { - if *v.p == nil { - return "nil" +func (v *Int128Parts) XdrPointer() interface{} { return v } +func (Int128Parts) XdrTypeName() string { return "Int128Parts" } +func (v Int128Parts) XdrValue() interface{} { return v } +func (v *Int128Parts) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (v *Int128Parts) XdrRecurse(x XDR, name string) { + if name != "" { + name = x.Sprintf("%s.", name) } - return "non-nil" + x.Marshal(x.Sprintf("%slo", name), XDR_Uint64(&v.Lo)) + x.Marshal(x.Sprintf("%shi", name), XDR_Uint64(&v.Hi)) } -func (v _ptrflag_SCObject) Scan(ss fmt.ScanState, r rune) error { - tok, err := ss.Token(true, func(c rune) bool { - return c == '-' || (c >= 'a' && c <= 'z') - }) - if err != nil { - return err - } - switch string(tok) { - case "nil": - v.SetU32(0) - case "non-nil": - v.SetU32(1) - default: - return XdrError("SCObject flag should be \"nil\" or \"non-nil\"") - } - return nil +func XDR_Int128Parts(v *Int128Parts) *Int128Parts { return v } + +var _XdrNames_SCContractExecutableType = map[int32]string{ + int32(SCCONTRACT_EXECUTABLE_WASM_REF): "SCCONTRACT_EXECUTABLE_WASM_REF", + int32(SCCONTRACT_EXECUTABLE_TOKEN): "SCCONTRACT_EXECUTABLE_TOKEN", } -func (v _ptrflag_SCObject) GetU32() uint32 { - if *v.p == nil { - return 0 - } - return 1 +var _XdrValues_SCContractExecutableType = map[string]int32{ + "SCCONTRACT_EXECUTABLE_WASM_REF": int32(SCCONTRACT_EXECUTABLE_WASM_REF), + "SCCONTRACT_EXECUTABLE_TOKEN": int32(SCCONTRACT_EXECUTABLE_TOKEN), } -func (v _ptrflag_SCObject) SetU32(nv uint32) { - switch nv { - case 0: - *v.p = nil - case 1: - if *v.p == nil { - *v.p = new(SCObject) - } - default: - XdrPanic("*SCObject present flag value %d should be 0 or 1", nv) - } + +func (SCContractExecutableType) XdrEnumNames() map[int32]string { + return _XdrNames_SCContractExecutableType } -func (_ptrflag_SCObject) XdrTypeName() string { return "SCObject?" } -func (v _ptrflag_SCObject) XdrPointer() interface{} { return nil } -func (v _ptrflag_SCObject) XdrValue() interface{} { return v.GetU32() != 0 } -func (v _ptrflag_SCObject) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } -func (v _ptrflag_SCObject) XdrBound() uint32 { return 1 } -func (v _XdrPtr_SCObject) GetPresent() bool { return *v.p != nil } -func (v _XdrPtr_SCObject) SetPresent(present bool) { - if !present { - *v.p = nil - } else if *v.p == nil { - *v.p = new(SCObject) +func (v SCContractExecutableType) String() string { + if s, ok := _XdrNames_SCContractExecutableType[int32(v)]; ok { + return s } + return fmt.Sprintf("SCContractExecutableType#%d", v) } -func (v _XdrPtr_SCObject) XdrMarshalValue(x XDR, name string) { - if *v.p != nil { - XDR_SCObject(*v.p).XdrMarshal(x, name) +func (v *SCContractExecutableType) Scan(ss fmt.ScanState, _ rune) error { + if tok, err := ss.Token(true, XdrSymChar); err != nil { + return err + } else { + stok := string(tok) + if val, ok := _XdrValues_SCContractExecutableType[stok]; ok { + *v = SCContractExecutableType(val) + return nil + } else if stok == "SCContractExecutableType" { + if n, err := fmt.Fscanf(ss, "#%d", (*int32)(v)); n == 1 && err == nil { + return nil + } + } + return XdrError(fmt.Sprintf("%s is not a valid SCContractExecutableType.", stok)) } } -func (v _XdrPtr_SCObject) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } -func (v _XdrPtr_SCObject) XdrRecurse(x XDR, name string) { - x.Marshal(name, _ptrflag_SCObject(v)) - v.XdrMarshalValue(x, name) -} -func (_XdrPtr_SCObject) XdrTypeName() string { return "SCObject*" } -func (v _XdrPtr_SCObject) XdrPointer() interface{} { return v.p } -func (v _XdrPtr_SCObject) XdrValue() interface{} { return *v.p } +func (v SCContractExecutableType) GetU32() uint32 { return uint32(v) } +func (v *SCContractExecutableType) SetU32(n uint32) { *v = SCContractExecutableType(n) } +func (v *SCContractExecutableType) XdrPointer() interface{} { return v } +func (SCContractExecutableType) XdrTypeName() string { return "SCContractExecutableType" } +func (v SCContractExecutableType) XdrValue() interface{} { return v } +func (v *SCContractExecutableType) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } -var _XdrTags_SCVal = map[int32]bool{ - XdrToI32(SCV_U63): true, - XdrToI32(SCV_U32): true, - XdrToI32(SCV_I32): true, - XdrToI32(SCV_STATIC): true, - XdrToI32(SCV_OBJECT): true, - XdrToI32(SCV_SYMBOL): true, - XdrToI32(SCV_BITSET): true, - XdrToI32(SCV_STATUS): true, +type XdrType_SCContractExecutableType = *SCContractExecutableType + +func XDR_SCContractExecutableType(v *SCContractExecutableType) *SCContractExecutableType { return v } + +var _XdrTags_SCContractExecutable = map[int32]bool{ + XdrToI32(SCCONTRACT_EXECUTABLE_WASM_REF): true, + XdrToI32(SCCONTRACT_EXECUTABLE_TOKEN): true, } -func (_ SCVal) XdrValidTags() map[int32]bool { - return _XdrTags_SCVal +func (_ SCContractExecutable) XdrValidTags() map[int32]bool { + return _XdrTags_SCContractExecutable } -func (u *SCVal) U63() *Int64 { +func (u *SCContractExecutable) Wasm_id() *Hash { switch u.Type { - case SCV_U63: - if v, ok := u._u.(*Int64); ok { + case SCCONTRACT_EXECUTABLE_WASM_REF: + if v, ok := u._u.(*Hash); ok { return v } else { - var zero Int64 + var zero Hash u._u = &zero return &zero } default: - XdrPanic("SCVal.U63 accessed when Type == %v", u.Type) + XdrPanic("SCContractExecutable.Wasm_id accessed when Type == %v", u.Type) return nil } } -func (u *SCVal) U32() *Uint32 { +func (u SCContractExecutable) XdrValid() bool { switch u.Type { - case SCV_U32: - if v, ok := u._u.(*Uint32); ok { - return v - } else { - var zero Uint32 - u._u = &zero - return &zero - } - default: - XdrPanic("SCVal.U32 accessed when Type == %v", u.Type) - return nil + case SCCONTRACT_EXECUTABLE_WASM_REF, SCCONTRACT_EXECUTABLE_TOKEN: + return true } + return false } -func (u *SCVal) I32() *Int32 { +func (u *SCContractExecutable) XdrUnionTag() XdrNum32 { + return XDR_SCContractExecutableType(&u.Type) +} +func (u *SCContractExecutable) XdrUnionTagName() string { + return "Type" +} +func (u *SCContractExecutable) XdrUnionBody() XdrType { switch u.Type { - case SCV_I32: - if v, ok := u._u.(*Int32); ok { - return v - } else { - var zero Int32 - u._u = &zero - return &zero - } - default: - XdrPanic("SCVal.I32 accessed when Type == %v", u.Type) + case SCCONTRACT_EXECUTABLE_WASM_REF: + return XDR_Hash(u.Wasm_id()) + case SCCONTRACT_EXECUTABLE_TOKEN: return nil } + return nil } -func (u *SCVal) Ic() *SCStatic { +func (u *SCContractExecutable) XdrUnionBodyName() string { switch u.Type { - case SCV_STATIC: - if v, ok := u._u.(*SCStatic); ok { - return v - } else { - var zero SCStatic - u._u = &zero - return &zero - } - default: - XdrPanic("SCVal.Ic accessed when Type == %v", u.Type) - return nil + case SCCONTRACT_EXECUTABLE_WASM_REF: + return "Wasm_id" + case SCCONTRACT_EXECUTABLE_TOKEN: + return "" } + return "" } -func (u *SCVal) Obj() **SCObject { + +type XdrType_SCContractExecutable = *SCContractExecutable + +func (v *SCContractExecutable) XdrPointer() interface{} { return v } +func (SCContractExecutable) XdrTypeName() string { return "SCContractExecutable" } +func (v SCContractExecutable) XdrValue() interface{} { return v } +func (v *SCContractExecutable) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (u *SCContractExecutable) XdrRecurse(x XDR, name string) { + if name != "" { + name = x.Sprintf("%s.", name) + } + XDR_SCContractExecutableType(&u.Type).XdrMarshal(x, x.Sprintf("%stype", name)) switch u.Type { - case SCV_OBJECT: - if v, ok := u._u.(**SCObject); ok { - return v - } else { - var zero *SCObject - u._u = &zero - return &zero - } - default: - XdrPanic("SCVal.Obj accessed when Type == %v", u.Type) - return nil + case SCCONTRACT_EXECUTABLE_WASM_REF: + x.Marshal(x.Sprintf("%swasm_id", name), XDR_Hash(u.Wasm_id())) + return + case SCCONTRACT_EXECUTABLE_TOKEN: + return } + XdrPanic("invalid Type (%v) in SCContractExecutable", u.Type) } -func (u *SCVal) Sym() *SCSymbol { - switch u.Type { - case SCV_SYMBOL: - if v, ok := u._u.(*SCSymbol); ok { - return v - } else { - var zero SCSymbol - u._u = &zero - return &zero +func XDR_SCContractExecutable(v *SCContractExecutable) *SCContractExecutable { return v } + +var _XdrNames_SCAddressType = map[int32]string{ + int32(SC_ADDRESS_TYPE_ACCOUNT): "SC_ADDRESS_TYPE_ACCOUNT", + int32(SC_ADDRESS_TYPE_CONTRACT): "SC_ADDRESS_TYPE_CONTRACT", +} +var _XdrValues_SCAddressType = map[string]int32{ + "SC_ADDRESS_TYPE_ACCOUNT": int32(SC_ADDRESS_TYPE_ACCOUNT), + "SC_ADDRESS_TYPE_CONTRACT": int32(SC_ADDRESS_TYPE_CONTRACT), +} + +func (SCAddressType) XdrEnumNames() map[int32]string { + return _XdrNames_SCAddressType +} +func (v SCAddressType) String() string { + if s, ok := _XdrNames_SCAddressType[int32(v)]; ok { + return s + } + return fmt.Sprintf("SCAddressType#%d", v) +} +func (v *SCAddressType) Scan(ss fmt.ScanState, _ rune) error { + if tok, err := ss.Token(true, XdrSymChar); err != nil { + return err + } else { + stok := string(tok) + if val, ok := _XdrValues_SCAddressType[stok]; ok { + *v = SCAddressType(val) + return nil + } else if stok == "SCAddressType" { + if n, err := fmt.Fscanf(ss, "#%d", (*int32)(v)); n == 1 && err == nil { + return nil + } } - default: - XdrPanic("SCVal.Sym accessed when Type == %v", u.Type) - return nil + return XdrError(fmt.Sprintf("%s is not a valid SCAddressType.", stok)) } } -func (u *SCVal) Bits() *Uint64 { +func (v SCAddressType) GetU32() uint32 { return uint32(v) } +func (v *SCAddressType) SetU32(n uint32) { *v = SCAddressType(n) } +func (v *SCAddressType) XdrPointer() interface{} { return v } +func (SCAddressType) XdrTypeName() string { return "SCAddressType" } +func (v SCAddressType) XdrValue() interface{} { return v } +func (v *SCAddressType) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } + +type XdrType_SCAddressType = *SCAddressType + +func XDR_SCAddressType(v *SCAddressType) *SCAddressType { return v } + +var _XdrTags_SCAddress = map[int32]bool{ + XdrToI32(SC_ADDRESS_TYPE_ACCOUNT): true, + XdrToI32(SC_ADDRESS_TYPE_CONTRACT): true, +} + +func (_ SCAddress) XdrValidTags() map[int32]bool { + return _XdrTags_SCAddress +} +func (u *SCAddress) AccountId() *AccountID { switch u.Type { - case SCV_BITSET: - if v, ok := u._u.(*Uint64); ok { + case SC_ADDRESS_TYPE_ACCOUNT: + if v, ok := u._u.(*AccountID); ok { return v } else { - var zero Uint64 + var zero AccountID u._u = &zero return &zero } default: - XdrPanic("SCVal.Bits accessed when Type == %v", u.Type) + XdrPanic("SCAddress.AccountId accessed when Type == %v", u.Type) return nil } } -func (u *SCVal) Status() *SCStatus { +func (u *SCAddress) ContractId() *Hash { switch u.Type { - case SCV_STATUS: - if v, ok := u._u.(*SCStatus); ok { + case SC_ADDRESS_TYPE_CONTRACT: + if v, ok := u._u.(*Hash); ok { return v } else { - var zero SCStatus + var zero Hash u._u = &zero return &zero } default: - XdrPanic("SCVal.Status accessed when Type == %v", u.Type) + XdrPanic("SCAddress.ContractId accessed when Type == %v", u.Type) return nil } } -func (u SCVal) XdrValid() bool { +func (u SCAddress) XdrValid() bool { switch u.Type { - case SCV_U63, SCV_U32, SCV_I32, SCV_STATIC, SCV_OBJECT, SCV_SYMBOL, SCV_BITSET, SCV_STATUS: + case SC_ADDRESS_TYPE_ACCOUNT, SC_ADDRESS_TYPE_CONTRACT: return true } return false } -func (u *SCVal) XdrUnionTag() XdrNum32 { - return XDR_SCValType(&u.Type) +func (u *SCAddress) XdrUnionTag() XdrNum32 { + return XDR_SCAddressType(&u.Type) } -func (u *SCVal) XdrUnionTagName() string { +func (u *SCAddress) XdrUnionTagName() string { return "Type" } -func (u *SCVal) XdrUnionBody() XdrType { +func (u *SCAddress) XdrUnionBody() XdrType { switch u.Type { - case SCV_U63: - return XDR_Int64(u.U63()) - case SCV_U32: - return XDR_Uint32(u.U32()) - case SCV_I32: - return XDR_Int32(u.I32()) - case SCV_STATIC: - return XDR_SCStatic(u.Ic()) - case SCV_OBJECT: - return _XdrPtr_SCObject{u.Obj()} - case SCV_SYMBOL: - return XDR_SCSymbol(u.Sym()) - case SCV_BITSET: - return XDR_Uint64(u.Bits()) - case SCV_STATUS: - return XDR_SCStatus(u.Status()) + case SC_ADDRESS_TYPE_ACCOUNT: + return XDR_AccountID(u.AccountId()) + case SC_ADDRESS_TYPE_CONTRACT: + return XDR_Hash(u.ContractId()) } return nil } -func (u *SCVal) XdrUnionBodyName() string { +func (u *SCAddress) XdrUnionBodyName() string { switch u.Type { - case SCV_U63: - return "U63" - case SCV_U32: - return "U32" - case SCV_I32: - return "I32" - case SCV_STATIC: - return "Ic" - case SCV_OBJECT: - return "Obj" - case SCV_SYMBOL: - return "Sym" - case SCV_BITSET: - return "Bits" - case SCV_STATUS: - return "Status" + case SC_ADDRESS_TYPE_ACCOUNT: + return "AccountId" + case SC_ADDRESS_TYPE_CONTRACT: + return "ContractId" } return "" } -type XdrType_SCVal = *SCVal +type XdrType_SCAddress = *SCAddress -func (v *SCVal) XdrPointer() interface{} { return v } -func (SCVal) XdrTypeName() string { return "SCVal" } -func (v SCVal) XdrValue() interface{} { return v } -func (v *SCVal) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } -func (u *SCVal) XdrRecurse(x XDR, name string) { +func (v *SCAddress) XdrPointer() interface{} { return v } +func (SCAddress) XdrTypeName() string { return "SCAddress" } +func (v SCAddress) XdrValue() interface{} { return v } +func (v *SCAddress) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (u *SCAddress) XdrRecurse(x XDR, name string) { if name != "" { name = x.Sprintf("%s.", name) } - XDR_SCValType(&u.Type).XdrMarshal(x, x.Sprintf("%stype", name)) + XDR_SCAddressType(&u.Type).XdrMarshal(x, x.Sprintf("%stype", name)) switch u.Type { - case SCV_U63: - x.Marshal(x.Sprintf("%su63", name), XDR_Int64(u.U63())) - return - case SCV_U32: - x.Marshal(x.Sprintf("%su32", name), XDR_Uint32(u.U32())) - return - case SCV_I32: - x.Marshal(x.Sprintf("%si32", name), XDR_Int32(u.I32())) - return - case SCV_STATIC: - x.Marshal(x.Sprintf("%sic", name), XDR_SCStatic(u.Ic())) - return - case SCV_OBJECT: - x.Marshal(x.Sprintf("%sobj", name), _XdrPtr_SCObject{u.Obj()}) - return - case SCV_SYMBOL: - x.Marshal(x.Sprintf("%ssym", name), XDR_SCSymbol(u.Sym())) - return - case SCV_BITSET: - x.Marshal(x.Sprintf("%sbits", name), XDR_Uint64(u.Bits())) + case SC_ADDRESS_TYPE_ACCOUNT: + x.Marshal(x.Sprintf("%saccountId", name), XDR_AccountID(u.AccountId())) return - case SCV_STATUS: - x.Marshal(x.Sprintf("%sstatus", name), XDR_SCStatus(u.Status())) + case SC_ADDRESS_TYPE_CONTRACT: + x.Marshal(x.Sprintf("%scontractId", name), XDR_Hash(u.ContractId())) return } - XdrPanic("invalid Type (%v) in SCVal", u.Type) -} -func XDR_SCVal(v *SCVal) *SCVal { return v } - -var _XdrNames_SCObjectType = map[int32]string{ - int32(SCO_VEC): "SCO_VEC", - int32(SCO_MAP): "SCO_MAP", - int32(SCO_U64): "SCO_U64", - int32(SCO_I64): "SCO_I64", - int32(SCO_U128): "SCO_U128", - int32(SCO_I128): "SCO_I128", - int32(SCO_BYTES): "SCO_BYTES", - int32(SCO_CONTRACT_CODE): "SCO_CONTRACT_CODE", - int32(SCO_ADDRESS): "SCO_ADDRESS", - int32(SCO_NONCE_KEY): "SCO_NONCE_KEY", -} -var _XdrValues_SCObjectType = map[string]int32{ - "SCO_VEC": int32(SCO_VEC), - "SCO_MAP": int32(SCO_MAP), - "SCO_U64": int32(SCO_U64), - "SCO_I64": int32(SCO_I64), - "SCO_U128": int32(SCO_U128), - "SCO_I128": int32(SCO_I128), - "SCO_BYTES": int32(SCO_BYTES), - "SCO_CONTRACT_CODE": int32(SCO_CONTRACT_CODE), - "SCO_ADDRESS": int32(SCO_ADDRESS), - "SCO_NONCE_KEY": int32(SCO_NONCE_KEY), -} - -func (SCObjectType) XdrEnumNames() map[int32]string { - return _XdrNames_SCObjectType -} -func (v SCObjectType) String() string { - if s, ok := _XdrNames_SCObjectType[int32(v)]; ok { - return s - } - return fmt.Sprintf("SCObjectType#%d", v) -} -func (v *SCObjectType) Scan(ss fmt.ScanState, _ rune) error { - if tok, err := ss.Token(true, XdrSymChar); err != nil { - return err - } else { - stok := string(tok) - if val, ok := _XdrValues_SCObjectType[stok]; ok { - *v = SCObjectType(val) - return nil - } else if stok == "SCObjectType" { - if n, err := fmt.Fscanf(ss, "#%d", (*int32)(v)); n == 1 && err == nil { - return nil - } - } - return XdrError(fmt.Sprintf("%s is not a valid SCObjectType.", stok)) - } -} -func (v SCObjectType) GetU32() uint32 { return uint32(v) } -func (v *SCObjectType) SetU32(n uint32) { *v = SCObjectType(n) } -func (v *SCObjectType) XdrPointer() interface{} { return v } -func (SCObjectType) XdrTypeName() string { return "SCObjectType" } -func (v SCObjectType) XdrValue() interface{} { return v } -func (v *SCObjectType) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } - -type XdrType_SCObjectType = *SCObjectType - -func XDR_SCObjectType(v *SCObjectType) *SCObjectType { return v } - -type XdrType_SCMapEntry = *SCMapEntry - -func (v *SCMapEntry) XdrPointer() interface{} { return v } -func (SCMapEntry) XdrTypeName() string { return "SCMapEntry" } -func (v SCMapEntry) XdrValue() interface{} { return v } -func (v *SCMapEntry) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } -func (v *SCMapEntry) XdrRecurse(x XDR, name string) { - if name != "" { - name = x.Sprintf("%s.", name) - } - x.Marshal(x.Sprintf("%skey", name), XDR_SCVal(&v.Key)) - x.Marshal(x.Sprintf("%sval", name), XDR_SCVal(&v.Val)) + XdrPanic("invalid Type (%v) in SCAddress", u.Type) } -func XDR_SCMapEntry(v *SCMapEntry) *SCMapEntry { return v } +func XDR_SCAddress(v *SCAddress) *SCAddress { return v } type _XdrVec_256000_SCVal []SCVal @@ -27147,420 +27228,497 @@ func XDR_SCMap(v *SCMap) XdrType_SCMap { func (XdrType_SCMap) XdrTypeName() string { return "SCMap" } func (v XdrType_SCMap) XdrUnwrap() XdrType { return v._XdrVec_256000_SCMapEntry } -var _XdrNames_SCContractCodeType = map[int32]string{ - int32(SCCONTRACT_CODE_WASM_REF): "SCCONTRACT_CODE_WASM_REF", - int32(SCCONTRACT_CODE_TOKEN): "SCCONTRACT_CODE_TOKEN", +type XdrType_SCBytes struct { + XdrVecOpaque } -var _XdrValues_SCContractCodeType = map[string]int32{ - "SCCONTRACT_CODE_WASM_REF": int32(SCCONTRACT_CODE_WASM_REF), - "SCCONTRACT_CODE_TOKEN": int32(SCCONTRACT_CODE_TOKEN), + +func XDR_SCBytes(v *SCBytes) XdrType_SCBytes { + return XdrType_SCBytes{XdrVecOpaque{v, SCVAL_LIMIT}} } +func (XdrType_SCBytes) XdrTypeName() string { return "SCBytes" } +func (v XdrType_SCBytes) XdrUnwrap() XdrType { return v.XdrVecOpaque } -func (SCContractCodeType) XdrEnumNames() map[int32]string { - return _XdrNames_SCContractCodeType +type XdrType_SCString struct { + XdrString } -func (v SCContractCodeType) String() string { - if s, ok := _XdrNames_SCContractCodeType[int32(v)]; ok { - return s - } - return fmt.Sprintf("SCContractCodeType#%d", v) + +func XDR_SCString(v *SCString) XdrType_SCString { + return XdrType_SCString{XdrString{v, SCVAL_LIMIT}} } -func (v *SCContractCodeType) Scan(ss fmt.ScanState, _ rune) error { - if tok, err := ss.Token(true, XdrSymChar); err != nil { - return err - } else { - stok := string(tok) - if val, ok := _XdrValues_SCContractCodeType[stok]; ok { - *v = SCContractCodeType(val) - return nil - } else if stok == "SCContractCodeType" { - if n, err := fmt.Fscanf(ss, "#%d", (*int32)(v)); n == 1 && err == nil { - return nil - } - } - return XdrError(fmt.Sprintf("%s is not a valid SCContractCodeType.", stok)) - } +func (XdrType_SCString) XdrTypeName() string { return "SCString" } +func (v XdrType_SCString) XdrUnwrap() XdrType { return v.XdrString } + +type XdrType_SCSymbol struct { + XdrString } -func (v SCContractCodeType) GetU32() uint32 { return uint32(v) } -func (v *SCContractCodeType) SetU32(n uint32) { *v = SCContractCodeType(n) } -func (v *SCContractCodeType) XdrPointer() interface{} { return v } -func (SCContractCodeType) XdrTypeName() string { return "SCContractCodeType" } -func (v SCContractCodeType) XdrValue() interface{} { return v } -func (v *SCContractCodeType) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } -type XdrType_SCContractCodeType = *SCContractCodeType +func XDR_SCSymbol(v *SCSymbol) XdrType_SCSymbol { + return XdrType_SCSymbol{XdrString{v, SCSYMBOL_LIMIT}} +} +func (XdrType_SCSymbol) XdrTypeName() string { return "SCSymbol" } +func (v XdrType_SCSymbol) XdrUnwrap() XdrType { return v.XdrString } -func XDR_SCContractCodeType(v *SCContractCodeType) *SCContractCodeType { return v } +type XdrType_SCNonceKey = *SCNonceKey -var _XdrTags_SCContractCode = map[int32]bool{ - XdrToI32(SCCONTRACT_CODE_WASM_REF): true, - XdrToI32(SCCONTRACT_CODE_TOKEN): true, +func (v *SCNonceKey) XdrPointer() interface{} { return v } +func (SCNonceKey) XdrTypeName() string { return "SCNonceKey" } +func (v SCNonceKey) XdrValue() interface{} { return v } +func (v *SCNonceKey) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (v *SCNonceKey) XdrRecurse(x XDR, name string) { + if name != "" { + name = x.Sprintf("%s.", name) + } + x.Marshal(x.Sprintf("%snonce_address", name), XDR_SCAddress(&v.Nonce_address)) } +func XDR_SCNonceKey(v *SCNonceKey) *SCNonceKey { return v } -func (_ SCContractCode) XdrValidTags() map[int32]bool { - return _XdrTags_SCContractCode +type _XdrPtr_SCVec struct { + p **SCVec } -func (u *SCContractCode) Wasm_id() *Hash { - switch u.Type { - case SCCONTRACT_CODE_WASM_REF: - if v, ok := u._u.(*Hash); ok { - return v - } else { - var zero Hash - u._u = &zero - return &zero - } - default: - XdrPanic("SCContractCode.Wasm_id accessed when Type == %v", u.Type) - return nil +type _ptrflag_SCVec _XdrPtr_SCVec + +func (v _ptrflag_SCVec) String() string { + if *v.p == nil { + return "nil" } + return "non-nil" } -func (u SCContractCode) XdrValid() bool { - switch u.Type { - case SCCONTRACT_CODE_WASM_REF, SCCONTRACT_CODE_TOKEN: - return true +func (v _ptrflag_SCVec) Scan(ss fmt.ScanState, r rune) error { + tok, err := ss.Token(true, func(c rune) bool { + return c == '-' || (c >= 'a' && c <= 'z') + }) + if err != nil { + return err } - return false -} -func (u *SCContractCode) XdrUnionTag() XdrNum32 { - return XDR_SCContractCodeType(&u.Type) -} -func (u *SCContractCode) XdrUnionTagName() string { - return "Type" -} -func (u *SCContractCode) XdrUnionBody() XdrType { - switch u.Type { - case SCCONTRACT_CODE_WASM_REF: - return XDR_Hash(u.Wasm_id()) - case SCCONTRACT_CODE_TOKEN: - return nil + switch string(tok) { + case "nil": + v.SetU32(0) + case "non-nil": + v.SetU32(1) + default: + return XdrError("SCVec flag should be \"nil\" or \"non-nil\"") } return nil } -func (u *SCContractCode) XdrUnionBodyName() string { - switch u.Type { - case SCCONTRACT_CODE_WASM_REF: - return "Wasm_id" - case SCCONTRACT_CODE_TOKEN: - return "" +func (v _ptrflag_SCVec) GetU32() uint32 { + if *v.p == nil { + return 0 } - return "" + return 1 } - -type XdrType_SCContractCode = *SCContractCode - -func (v *SCContractCode) XdrPointer() interface{} { return v } -func (SCContractCode) XdrTypeName() string { return "SCContractCode" } -func (v SCContractCode) XdrValue() interface{} { return v } -func (v *SCContractCode) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } -func (u *SCContractCode) XdrRecurse(x XDR, name string) { - if name != "" { - name = x.Sprintf("%s.", name) - } - XDR_SCContractCodeType(&u.Type).XdrMarshal(x, x.Sprintf("%stype", name)) - switch u.Type { - case SCCONTRACT_CODE_WASM_REF: - x.Marshal(x.Sprintf("%swasm_id", name), XDR_Hash(u.Wasm_id())) - return - case SCCONTRACT_CODE_TOKEN: - return +func (v _ptrflag_SCVec) SetU32(nv uint32) { + switch nv { + case 0: + *v.p = nil + case 1: + if *v.p == nil { + *v.p = new(SCVec) + } + default: + XdrPanic("*SCVec present flag value %d should be 0 or 1", nv) } - XdrPanic("invalid Type (%v) in SCContractCode", u.Type) } -func XDR_SCContractCode(v *SCContractCode) *SCContractCode { return v } - -type XdrType_Int128Parts = *Int128Parts - -func (v *Int128Parts) XdrPointer() interface{} { return v } -func (Int128Parts) XdrTypeName() string { return "Int128Parts" } -func (v Int128Parts) XdrValue() interface{} { return v } -func (v *Int128Parts) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } -func (v *Int128Parts) XdrRecurse(x XDR, name string) { - if name != "" { - name = x.Sprintf("%s.", name) +func (_ptrflag_SCVec) XdrTypeName() string { return "SCVec?" } +func (v _ptrflag_SCVec) XdrPointer() interface{} { return nil } +func (v _ptrflag_SCVec) XdrValue() interface{} { return v.GetU32() != 0 } +func (v _ptrflag_SCVec) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (v _ptrflag_SCVec) XdrBound() uint32 { return 1 } +func (v _XdrPtr_SCVec) GetPresent() bool { return *v.p != nil } +func (v _XdrPtr_SCVec) SetPresent(present bool) { + if !present { + *v.p = nil + } else if *v.p == nil { + *v.p = new(SCVec) } - x.Marshal(x.Sprintf("%slo", name), XDR_Uint64(&v.Lo)) - x.Marshal(x.Sprintf("%shi", name), XDR_Uint64(&v.Hi)) } -func XDR_Int128Parts(v *Int128Parts) *Int128Parts { return v } - -var _XdrNames_SCAddressType = map[int32]string{ - int32(SC_ADDRESS_TYPE_ACCOUNT): "SC_ADDRESS_TYPE_ACCOUNT", - int32(SC_ADDRESS_TYPE_CONTRACT): "SC_ADDRESS_TYPE_CONTRACT", +func (v _XdrPtr_SCVec) XdrMarshalValue(x XDR, name string) { + if *v.p != nil { + XDR_SCVec(*v.p).XdrMarshal(x, name) + } } -var _XdrValues_SCAddressType = map[string]int32{ - "SC_ADDRESS_TYPE_ACCOUNT": int32(SC_ADDRESS_TYPE_ACCOUNT), - "SC_ADDRESS_TYPE_CONTRACT": int32(SC_ADDRESS_TYPE_CONTRACT), +func (v _XdrPtr_SCVec) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (v _XdrPtr_SCVec) XdrRecurse(x XDR, name string) { + x.Marshal(name, _ptrflag_SCVec(v)) + v.XdrMarshalValue(x, name) } +func (_XdrPtr_SCVec) XdrTypeName() string { return "SCVec*" } +func (v _XdrPtr_SCVec) XdrPointer() interface{} { return v.p } +func (v _XdrPtr_SCVec) XdrValue() interface{} { return *v.p } -func (SCAddressType) XdrEnumNames() map[int32]string { - return _XdrNames_SCAddressType +type _XdrPtr_SCMap struct { + p **SCMap } -func (v SCAddressType) String() string { - if s, ok := _XdrNames_SCAddressType[int32(v)]; ok { - return s +type _ptrflag_SCMap _XdrPtr_SCMap + +func (v _ptrflag_SCMap) String() string { + if *v.p == nil { + return "nil" } - return fmt.Sprintf("SCAddressType#%d", v) + return "non-nil" } -func (v *SCAddressType) Scan(ss fmt.ScanState, _ rune) error { - if tok, err := ss.Token(true, XdrSymChar); err != nil { +func (v _ptrflag_SCMap) Scan(ss fmt.ScanState, r rune) error { + tok, err := ss.Token(true, func(c rune) bool { + return c == '-' || (c >= 'a' && c <= 'z') + }) + if err != nil { return err - } else { - stok := string(tok) - if val, ok := _XdrValues_SCAddressType[stok]; ok { - *v = SCAddressType(val) - return nil - } else if stok == "SCAddressType" { - if n, err := fmt.Fscanf(ss, "#%d", (*int32)(v)); n == 1 && err == nil { - return nil - } + } + switch string(tok) { + case "nil": + v.SetU32(0) + case "non-nil": + v.SetU32(1) + default: + return XdrError("SCMap flag should be \"nil\" or \"non-nil\"") + } + return nil +} +func (v _ptrflag_SCMap) GetU32() uint32 { + if *v.p == nil { + return 0 + } + return 1 +} +func (v _ptrflag_SCMap) SetU32(nv uint32) { + switch nv { + case 0: + *v.p = nil + case 1: + if *v.p == nil { + *v.p = new(SCMap) } - return XdrError(fmt.Sprintf("%s is not a valid SCAddressType.", stok)) + default: + XdrPanic("*SCMap present flag value %d should be 0 or 1", nv) + } +} +func (_ptrflag_SCMap) XdrTypeName() string { return "SCMap?" } +func (v _ptrflag_SCMap) XdrPointer() interface{} { return nil } +func (v _ptrflag_SCMap) XdrValue() interface{} { return v.GetU32() != 0 } +func (v _ptrflag_SCMap) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (v _ptrflag_SCMap) XdrBound() uint32 { return 1 } +func (v _XdrPtr_SCMap) GetPresent() bool { return *v.p != nil } +func (v _XdrPtr_SCMap) SetPresent(present bool) { + if !present { + *v.p = nil + } else if *v.p == nil { + *v.p = new(SCMap) } } -func (v SCAddressType) GetU32() uint32 { return uint32(v) } -func (v *SCAddressType) SetU32(n uint32) { *v = SCAddressType(n) } -func (v *SCAddressType) XdrPointer() interface{} { return v } -func (SCAddressType) XdrTypeName() string { return "SCAddressType" } -func (v SCAddressType) XdrValue() interface{} { return v } -func (v *SCAddressType) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } - -type XdrType_SCAddressType = *SCAddressType - -func XDR_SCAddressType(v *SCAddressType) *SCAddressType { return v } +func (v _XdrPtr_SCMap) XdrMarshalValue(x XDR, name string) { + if *v.p != nil { + XDR_SCMap(*v.p).XdrMarshal(x, name) + } +} +func (v _XdrPtr_SCMap) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (v _XdrPtr_SCMap) XdrRecurse(x XDR, name string) { + x.Marshal(name, _ptrflag_SCMap(v)) + v.XdrMarshalValue(x, name) +} +func (_XdrPtr_SCMap) XdrTypeName() string { return "SCMap*" } +func (v _XdrPtr_SCMap) XdrPointer() interface{} { return v.p } +func (v _XdrPtr_SCMap) XdrValue() interface{} { return *v.p } -var _XdrTags_SCAddress = map[int32]bool{ - XdrToI32(SC_ADDRESS_TYPE_ACCOUNT): true, - XdrToI32(SC_ADDRESS_TYPE_CONTRACT): true, +var _XdrTags_SCVal = map[int32]bool{ + XdrToI32(SCV_BOOL): true, + XdrToI32(SCV_VOID): true, + XdrToI32(SCV_STATUS): true, + XdrToI32(SCV_U32): true, + XdrToI32(SCV_I32): true, + XdrToI32(SCV_U64): true, + XdrToI32(SCV_I64): true, + XdrToI32(SCV_TIMEPOINT): true, + XdrToI32(SCV_DURATION): true, + XdrToI32(SCV_U128): true, + XdrToI32(SCV_I128): true, + XdrToI32(SCV_U256): true, + XdrToI32(SCV_I256): true, + XdrToI32(SCV_BYTES): true, + XdrToI32(SCV_STRING): true, + XdrToI32(SCV_SYMBOL): true, + XdrToI32(SCV_VEC): true, + XdrToI32(SCV_MAP): true, + XdrToI32(SCV_CONTRACT_EXECUTABLE): true, + XdrToI32(SCV_ADDRESS): true, + XdrToI32(SCV_LEDGER_KEY_CONTRACT_EXECUTABLE): true, + XdrToI32(SCV_LEDGER_KEY_NONCE): true, } -func (_ SCAddress) XdrValidTags() map[int32]bool { - return _XdrTags_SCAddress +func (_ SCVal) XdrValidTags() map[int32]bool { + return _XdrTags_SCVal } -func (u *SCAddress) AccountId() *AccountID { +func (u *SCVal) B() *bool { switch u.Type { - case SC_ADDRESS_TYPE_ACCOUNT: - if v, ok := u._u.(*AccountID); ok { + case SCV_BOOL: + if v, ok := u._u.(*bool); ok { return v } else { - var zero AccountID + var zero bool u._u = &zero return &zero } default: - XdrPanic("SCAddress.AccountId accessed when Type == %v", u.Type) + XdrPanic("SCVal.B accessed when Type == %v", u.Type) return nil } } -func (u *SCAddress) ContractId() *Hash { +func (u *SCVal) Error() *SCStatus { switch u.Type { - case SC_ADDRESS_TYPE_CONTRACT: - if v, ok := u._u.(*Hash); ok { + case SCV_STATUS: + if v, ok := u._u.(*SCStatus); ok { return v } else { - var zero Hash + var zero SCStatus u._u = &zero return &zero } default: - XdrPanic("SCAddress.ContractId accessed when Type == %v", u.Type) + XdrPanic("SCVal.Error accessed when Type == %v", u.Type) return nil } } -func (u SCAddress) XdrValid() bool { +func (u *SCVal) U32() *Uint32 { switch u.Type { - case SC_ADDRESS_TYPE_ACCOUNT, SC_ADDRESS_TYPE_CONTRACT: - return true + case SCV_U32: + if v, ok := u._u.(*Uint32); ok { + return v + } else { + var zero Uint32 + u._u = &zero + return &zero + } + default: + XdrPanic("SCVal.U32 accessed when Type == %v", u.Type) + return nil } - return false -} -func (u *SCAddress) XdrUnionTag() XdrNum32 { - return XDR_SCAddressType(&u.Type) } -func (u *SCAddress) XdrUnionTagName() string { - return "Type" +func (u *SCVal) I32() *Int32 { + switch u.Type { + case SCV_I32: + if v, ok := u._u.(*Int32); ok { + return v + } else { + var zero Int32 + u._u = &zero + return &zero + } + default: + XdrPanic("SCVal.I32 accessed when Type == %v", u.Type) + return nil + } } -func (u *SCAddress) XdrUnionBody() XdrType { +func (u *SCVal) U64() *Uint64 { switch u.Type { - case SC_ADDRESS_TYPE_ACCOUNT: - return XDR_AccountID(u.AccountId()) - case SC_ADDRESS_TYPE_CONTRACT: - return XDR_Hash(u.ContractId()) + case SCV_U64: + if v, ok := u._u.(*Uint64); ok { + return v + } else { + var zero Uint64 + u._u = &zero + return &zero + } + default: + XdrPanic("SCVal.U64 accessed when Type == %v", u.Type) + return nil } - return nil } -func (u *SCAddress) XdrUnionBodyName() string { +func (u *SCVal) I64() *Int64 { switch u.Type { - case SC_ADDRESS_TYPE_ACCOUNT: - return "AccountId" - case SC_ADDRESS_TYPE_CONTRACT: - return "ContractId" + case SCV_I64: + if v, ok := u._u.(*Int64); ok { + return v + } else { + var zero Int64 + u._u = &zero + return &zero + } + default: + XdrPanic("SCVal.I64 accessed when Type == %v", u.Type) + return nil } - return "" } - -type XdrType_SCAddress = *SCAddress - -func (v *SCAddress) XdrPointer() interface{} { return v } -func (SCAddress) XdrTypeName() string { return "SCAddress" } -func (v SCAddress) XdrValue() interface{} { return v } -func (v *SCAddress) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } -func (u *SCAddress) XdrRecurse(x XDR, name string) { - if name != "" { - name = x.Sprintf("%s.", name) +func (u *SCVal) Timepoint() *TimePoint { + switch u.Type { + case SCV_TIMEPOINT: + if v, ok := u._u.(*TimePoint); ok { + return v + } else { + var zero TimePoint + u._u = &zero + return &zero + } + default: + XdrPanic("SCVal.Timepoint accessed when Type == %v", u.Type) + return nil } - XDR_SCAddressType(&u.Type).XdrMarshal(x, x.Sprintf("%stype", name)) +} +func (u *SCVal) Duration() *Duration { switch u.Type { - case SC_ADDRESS_TYPE_ACCOUNT: - x.Marshal(x.Sprintf("%saccountId", name), XDR_AccountID(u.AccountId())) - return - case SC_ADDRESS_TYPE_CONTRACT: - x.Marshal(x.Sprintf("%scontractId", name), XDR_Hash(u.ContractId())) - return + case SCV_DURATION: + if v, ok := u._u.(*Duration); ok { + return v + } else { + var zero Duration + u._u = &zero + return &zero + } + default: + XdrPanic("SCVal.Duration accessed when Type == %v", u.Type) + return nil } - XdrPanic("invalid Type (%v) in SCAddress", u.Type) } -func XDR_SCAddress(v *SCAddress) *SCAddress { return v } - -var _XdrTags_SCObject = map[int32]bool{ - XdrToI32(SCO_VEC): true, - XdrToI32(SCO_MAP): true, - XdrToI32(SCO_U64): true, - XdrToI32(SCO_I64): true, - XdrToI32(SCO_U128): true, - XdrToI32(SCO_I128): true, - XdrToI32(SCO_BYTES): true, - XdrToI32(SCO_CONTRACT_CODE): true, - XdrToI32(SCO_ADDRESS): true, - XdrToI32(SCO_NONCE_KEY): true, +func (u *SCVal) U128() *Int128Parts { + switch u.Type { + case SCV_U128: + if v, ok := u._u.(*Int128Parts); ok { + return v + } else { + var zero Int128Parts + u._u = &zero + return &zero + } + default: + XdrPanic("SCVal.U128 accessed when Type == %v", u.Type) + return nil + } } - -func (_ SCObject) XdrValidTags() map[int32]bool { - return _XdrTags_SCObject +func (u *SCVal) I128() *Int128Parts { + switch u.Type { + case SCV_I128: + if v, ok := u._u.(*Int128Parts); ok { + return v + } else { + var zero Int128Parts + u._u = &zero + return &zero + } + default: + XdrPanic("SCVal.I128 accessed when Type == %v", u.Type) + return nil + } } -func (u *SCObject) Vec() *SCVec { +func (u *SCVal) U256() *Uint256 { switch u.Type { - case SCO_VEC: - if v, ok := u._u.(*SCVec); ok { + case SCV_U256: + if v, ok := u._u.(*Uint256); ok { return v } else { - var zero SCVec + var zero Uint256 u._u = &zero return &zero } default: - XdrPanic("SCObject.Vec accessed when Type == %v", u.Type) + XdrPanic("SCVal.U256 accessed when Type == %v", u.Type) return nil } } -func (u *SCObject) Map() *SCMap { +func (u *SCVal) I256() *Uint256 { switch u.Type { - case SCO_MAP: - if v, ok := u._u.(*SCMap); ok { + case SCV_I256: + if v, ok := u._u.(*Uint256); ok { return v } else { - var zero SCMap + var zero Uint256 u._u = &zero return &zero } default: - XdrPanic("SCObject.Map accessed when Type == %v", u.Type) + XdrPanic("SCVal.I256 accessed when Type == %v", u.Type) return nil } } -func (u *SCObject) U64() *Uint64 { +func (u *SCVal) Bytes() *SCBytes { switch u.Type { - case SCO_U64: - if v, ok := u._u.(*Uint64); ok { + case SCV_BYTES: + if v, ok := u._u.(*SCBytes); ok { return v } else { - var zero Uint64 + var zero SCBytes u._u = &zero return &zero } default: - XdrPanic("SCObject.U64 accessed when Type == %v", u.Type) + XdrPanic("SCVal.Bytes accessed when Type == %v", u.Type) return nil } } -func (u *SCObject) I64() *Int64 { +func (u *SCVal) Str() *SCString { switch u.Type { - case SCO_I64: - if v, ok := u._u.(*Int64); ok { + case SCV_STRING: + if v, ok := u._u.(*SCString); ok { return v } else { - var zero Int64 + var zero SCString u._u = &zero return &zero } default: - XdrPanic("SCObject.I64 accessed when Type == %v", u.Type) + XdrPanic("SCVal.Str accessed when Type == %v", u.Type) return nil } } -func (u *SCObject) U128() *Int128Parts { +func (u *SCVal) Sym() *SCSymbol { switch u.Type { - case SCO_U128: - if v, ok := u._u.(*Int128Parts); ok { + case SCV_SYMBOL: + if v, ok := u._u.(*SCSymbol); ok { return v } else { - var zero Int128Parts + var zero SCSymbol u._u = &zero return &zero } default: - XdrPanic("SCObject.U128 accessed when Type == %v", u.Type) + XdrPanic("SCVal.Sym accessed when Type == %v", u.Type) return nil } } -func (u *SCObject) I128() *Int128Parts { +func (u *SCVal) Vec() **SCVec { switch u.Type { - case SCO_I128: - if v, ok := u._u.(*Int128Parts); ok { + case SCV_VEC: + if v, ok := u._u.(**SCVec); ok { return v } else { - var zero Int128Parts + var zero *SCVec u._u = &zero return &zero } default: - XdrPanic("SCObject.I128 accessed when Type == %v", u.Type) + XdrPanic("SCVal.Vec accessed when Type == %v", u.Type) return nil } } -func (u *SCObject) Bin() *[]byte { +func (u *SCVal) Map() **SCMap { switch u.Type { - case SCO_BYTES: - if v, ok := u._u.(*[]byte); ok { + case SCV_MAP: + if v, ok := u._u.(**SCMap); ok { return v } else { - var zero []byte + var zero *SCMap u._u = &zero return &zero } default: - XdrPanic("SCObject.Bin accessed when Type == %v", u.Type) + XdrPanic("SCVal.Map accessed when Type == %v", u.Type) return nil } } -func (u *SCObject) ContractCode() *SCContractCode { +func (u *SCVal) Exec() *SCContractExecutable { switch u.Type { - case SCO_CONTRACT_CODE: - if v, ok := u._u.(*SCContractCode); ok { + case SCV_CONTRACT_EXECUTABLE: + if v, ok := u._u.(*SCContractExecutable); ok { return v } else { - var zero SCContractCode + var zero SCContractExecutable u._u = &zero return &zero } default: - XdrPanic("SCObject.ContractCode accessed when Type == %v", u.Type) + XdrPanic("SCVal.Exec accessed when Type == %v", u.Type) return nil } } -func (u *SCObject) Address() *SCAddress { +func (u *SCVal) Address() *SCAddress { switch u.Type { - case SCO_ADDRESS: + case SCV_ADDRESS: if v, ok := u._u.(*SCAddress); ok { return v } else { @@ -27569,135 +27727,232 @@ func (u *SCObject) Address() *SCAddress { return &zero } default: - XdrPanic("SCObject.Address accessed when Type == %v", u.Type) + XdrPanic("SCVal.Address accessed when Type == %v", u.Type) return nil } } -func (u *SCObject) NonceAddress() *SCAddress { +func (u *SCVal) Nonce_key() *SCNonceKey { switch u.Type { - case SCO_NONCE_KEY: - if v, ok := u._u.(*SCAddress); ok { + case SCV_LEDGER_KEY_NONCE: + if v, ok := u._u.(*SCNonceKey); ok { return v } else { - var zero SCAddress + var zero SCNonceKey u._u = &zero return &zero } default: - XdrPanic("SCObject.NonceAddress accessed when Type == %v", u.Type) + XdrPanic("SCVal.Nonce_key accessed when Type == %v", u.Type) return nil } } -func (u SCObject) XdrValid() bool { +func (u SCVal) XdrValid() bool { switch u.Type { - case SCO_VEC, SCO_MAP, SCO_U64, SCO_I64, SCO_U128, SCO_I128, SCO_BYTES, SCO_CONTRACT_CODE, SCO_ADDRESS, SCO_NONCE_KEY: + case SCV_BOOL, SCV_VOID, SCV_STATUS, SCV_U32, SCV_I32, SCV_U64, SCV_I64, SCV_TIMEPOINT, SCV_DURATION, SCV_U128, SCV_I128, SCV_U256, SCV_I256, SCV_BYTES, SCV_STRING, SCV_SYMBOL, SCV_VEC, SCV_MAP, SCV_CONTRACT_EXECUTABLE, SCV_ADDRESS, SCV_LEDGER_KEY_CONTRACT_EXECUTABLE, SCV_LEDGER_KEY_NONCE: return true } return false } -func (u *SCObject) XdrUnionTag() XdrNum32 { - return XDR_SCObjectType(&u.Type) +func (u *SCVal) XdrUnionTag() XdrNum32 { + return XDR_SCValType(&u.Type) } -func (u *SCObject) XdrUnionTagName() string { +func (u *SCVal) XdrUnionTagName() string { return "Type" } -func (u *SCObject) XdrUnionBody() XdrType { +func (u *SCVal) XdrUnionBody() XdrType { switch u.Type { - case SCO_VEC: - return XDR_SCVec(u.Vec()) - case SCO_MAP: - return XDR_SCMap(u.Map()) - case SCO_U64: + case SCV_BOOL: + return XDR_bool(u.B()) + case SCV_VOID: + return nil + case SCV_STATUS: + return XDR_SCStatus(u.Error()) + case SCV_U32: + return XDR_Uint32(u.U32()) + case SCV_I32: + return XDR_Int32(u.I32()) + case SCV_U64: return XDR_Uint64(u.U64()) - case SCO_I64: + case SCV_I64: return XDR_Int64(u.I64()) - case SCO_U128: + case SCV_TIMEPOINT: + return XDR_TimePoint(u.Timepoint()) + case SCV_DURATION: + return XDR_Duration(u.Duration()) + case SCV_U128: return XDR_Int128Parts(u.U128()) - case SCO_I128: + case SCV_I128: return XDR_Int128Parts(u.I128()) - case SCO_BYTES: - return XdrVecOpaque{u.Bin(), SCVAL_LIMIT} - case SCO_CONTRACT_CODE: - return XDR_SCContractCode(u.ContractCode()) - case SCO_ADDRESS: + case SCV_U256: + return XDR_Uint256(u.U256()) + case SCV_I256: + return XDR_Uint256(u.I256()) + case SCV_BYTES: + return XDR_SCBytes(u.Bytes()) + case SCV_STRING: + return XDR_SCString(u.Str()) + case SCV_SYMBOL: + return XDR_SCSymbol(u.Sym()) + case SCV_VEC: + return _XdrPtr_SCVec{u.Vec()} + case SCV_MAP: + return _XdrPtr_SCMap{u.Map()} + case SCV_CONTRACT_EXECUTABLE: + return XDR_SCContractExecutable(u.Exec()) + case SCV_ADDRESS: return XDR_SCAddress(u.Address()) - case SCO_NONCE_KEY: - return XDR_SCAddress(u.NonceAddress()) + case SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: + return nil + case SCV_LEDGER_KEY_NONCE: + return XDR_SCNonceKey(u.Nonce_key()) } return nil } -func (u *SCObject) XdrUnionBodyName() string { +func (u *SCVal) XdrUnionBodyName() string { switch u.Type { - case SCO_VEC: - return "Vec" - case SCO_MAP: - return "Map" - case SCO_U64: + case SCV_BOOL: + return "B" + case SCV_VOID: + return "" + case SCV_STATUS: + return "Error" + case SCV_U32: + return "U32" + case SCV_I32: + return "I32" + case SCV_U64: return "U64" - case SCO_I64: + case SCV_I64: return "I64" - case SCO_U128: + case SCV_TIMEPOINT: + return "Timepoint" + case SCV_DURATION: + return "Duration" + case SCV_U128: return "U128" - case SCO_I128: + case SCV_I128: return "I128" - case SCO_BYTES: - return "Bin" - case SCO_CONTRACT_CODE: - return "ContractCode" - case SCO_ADDRESS: + case SCV_U256: + return "U256" + case SCV_I256: + return "I256" + case SCV_BYTES: + return "Bytes" + case SCV_STRING: + return "Str" + case SCV_SYMBOL: + return "Sym" + case SCV_VEC: + return "Vec" + case SCV_MAP: + return "Map" + case SCV_CONTRACT_EXECUTABLE: + return "Exec" + case SCV_ADDRESS: return "Address" - case SCO_NONCE_KEY: - return "NonceAddress" + case SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: + return "" + case SCV_LEDGER_KEY_NONCE: + return "Nonce_key" } return "" } -type XdrType_SCObject = *SCObject +type XdrType_SCVal = *SCVal -func (v *SCObject) XdrPointer() interface{} { return v } -func (SCObject) XdrTypeName() string { return "SCObject" } -func (v SCObject) XdrValue() interface{} { return v } -func (v *SCObject) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } -func (u *SCObject) XdrRecurse(x XDR, name string) { +func (v *SCVal) XdrPointer() interface{} { return v } +func (SCVal) XdrTypeName() string { return "SCVal" } +func (v SCVal) XdrValue() interface{} { return v } +func (v *SCVal) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (u *SCVal) XdrRecurse(x XDR, name string) { if name != "" { name = x.Sprintf("%s.", name) } - XDR_SCObjectType(&u.Type).XdrMarshal(x, x.Sprintf("%stype", name)) + XDR_SCValType(&u.Type).XdrMarshal(x, x.Sprintf("%stype", name)) switch u.Type { - case SCO_VEC: - x.Marshal(x.Sprintf("%svec", name), XDR_SCVec(u.Vec())) + case SCV_BOOL: + x.Marshal(x.Sprintf("%sb", name), XDR_bool(u.B())) + return + case SCV_VOID: + return + case SCV_STATUS: + x.Marshal(x.Sprintf("%serror", name), XDR_SCStatus(u.Error())) + return + case SCV_U32: + x.Marshal(x.Sprintf("%su32", name), XDR_Uint32(u.U32())) return - case SCO_MAP: - x.Marshal(x.Sprintf("%smap", name), XDR_SCMap(u.Map())) + case SCV_I32: + x.Marshal(x.Sprintf("%si32", name), XDR_Int32(u.I32())) return - case SCO_U64: + case SCV_U64: x.Marshal(x.Sprintf("%su64", name), XDR_Uint64(u.U64())) return - case SCO_I64: + case SCV_I64: x.Marshal(x.Sprintf("%si64", name), XDR_Int64(u.I64())) return - case SCO_U128: + case SCV_TIMEPOINT: + x.Marshal(x.Sprintf("%stimepoint", name), XDR_TimePoint(u.Timepoint())) + return + case SCV_DURATION: + x.Marshal(x.Sprintf("%sduration", name), XDR_Duration(u.Duration())) + return + case SCV_U128: x.Marshal(x.Sprintf("%su128", name), XDR_Int128Parts(u.U128())) return - case SCO_I128: + case SCV_I128: x.Marshal(x.Sprintf("%si128", name), XDR_Int128Parts(u.I128())) return - case SCO_BYTES: - x.Marshal(x.Sprintf("%sbin", name), XdrVecOpaque{u.Bin(), SCVAL_LIMIT}) + case SCV_U256: + x.Marshal(x.Sprintf("%su256", name), XDR_Uint256(u.U256())) + return + case SCV_I256: + x.Marshal(x.Sprintf("%si256", name), XDR_Uint256(u.I256())) + return + case SCV_BYTES: + x.Marshal(x.Sprintf("%sbytes", name), XDR_SCBytes(u.Bytes())) return - case SCO_CONTRACT_CODE: - x.Marshal(x.Sprintf("%scontractCode", name), XDR_SCContractCode(u.ContractCode())) + case SCV_STRING: + x.Marshal(x.Sprintf("%sstr", name), XDR_SCString(u.Str())) return - case SCO_ADDRESS: + case SCV_SYMBOL: + x.Marshal(x.Sprintf("%ssym", name), XDR_SCSymbol(u.Sym())) + return + case SCV_VEC: + x.Marshal(x.Sprintf("%svec", name), _XdrPtr_SCVec{u.Vec()}) + return + case SCV_MAP: + x.Marshal(x.Sprintf("%smap", name), _XdrPtr_SCMap{u.Map()}) + return + case SCV_CONTRACT_EXECUTABLE: + x.Marshal(x.Sprintf("%sexec", name), XDR_SCContractExecutable(u.Exec())) + return + case SCV_ADDRESS: x.Marshal(x.Sprintf("%saddress", name), XDR_SCAddress(u.Address())) return - case SCO_NONCE_KEY: - x.Marshal(x.Sprintf("%snonceAddress", name), XDR_SCAddress(u.NonceAddress())) + case SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: return + case SCV_LEDGER_KEY_NONCE: + x.Marshal(x.Sprintf("%snonce_key", name), XDR_SCNonceKey(u.Nonce_key())) + return + } + XdrPanic("invalid Type (%v) in SCVal", u.Type) +} +func XDR_SCVal(v *SCVal) *SCVal { return v } + +type XdrType_SCMapEntry = *SCMapEntry + +func (v *SCMapEntry) XdrPointer() interface{} { return v } +func (SCMapEntry) XdrTypeName() string { return "SCMapEntry" } +func (v SCMapEntry) XdrValue() interface{} { return v } +func (v *SCMapEntry) XdrMarshal(x XDR, name string) { x.Marshal(name, v) } +func (v *SCMapEntry) XdrRecurse(x XDR, name string) { + if name != "" { + name = x.Sprintf("%s.", name) } - XdrPanic("invalid Type (%v) in SCObject", u.Type) + x.Marshal(x.Sprintf("%skey", name), XDR_SCVal(&v.Key)) + x.Marshal(x.Sprintf("%sval", name), XDR_SCVal(&v.Val)) } -func XDR_SCObject(v *SCObject) *SCObject { return v } +func XDR_SCMapEntry(v *SCMapEntry) *SCMapEntry { return v } var _XdrTags_StoredTransactionSet = map[int32]bool{ XdrToI32(0): true, diff --git a/ingest/ledger_transaction.go b/ingest/ledger_transaction.go index 5438b6f787..1a348f9683 100644 --- a/ingest/ledger_transaction.go +++ b/ingest/ledger_transaction.go @@ -153,7 +153,7 @@ func operationChanges(ops []xdr.OperationMeta, index uint32) []Change { } // GetOperationEvents returns all contract events emitted by a given operation. -func (t *LedgerTransaction) GetOperationEvents(operationIndex uint32) ([]xdr.ContractEvent, error) { +func (t *LedgerTransaction) GetOperationEvents(operationIndex uint32) ([]xdr.DiagnosticEvent, error) { // Ignore operations meta if txInternalError https://github.com/stellar/go/issues/2111 if t.txInternalError() { return nil, nil @@ -165,11 +165,23 @@ func (t *LedgerTransaction) GetOperationEvents(operationIndex uint32) ([]xdr.Con case 2: return nil, nil case 3: + diagnosticEventsByOperation := t.UnsafeMeta.MustV3().DiagnosticEvents + if int(operationIndex) < len(diagnosticEventsByOperation) { + return diagnosticEventsByOperation[operationIndex].Events, nil + } eventsByOperation := t.UnsafeMeta.MustV3().Events if int(operationIndex) >= len(eventsByOperation) { return nil, nil } - return eventsByOperation[operationIndex].Events, nil + events := eventsByOperation[operationIndex].Events + diagnosticEvents := make([]xdr.DiagnosticEvent, len(events)) + for i, event := range events { + diagnosticEvents[i] = xdr.DiagnosticEvent{ + InSuccessfulContractCall: true, + Event: event, + } + } + return diagnosticEvents, nil default: return nil, fmt.Errorf("unsupported TransactionMeta version: %v", t.UnsafeMeta.V) } diff --git a/ingest/ledger_transaction_test.go b/ingest/ledger_transaction_test.go index aa00660798..630a341022 100644 --- a/ingest/ledger_transaction_test.go +++ b/ingest/ledger_transaction_test.go @@ -70,7 +70,8 @@ func TestGetOperationEvents(t *testing.T) { events, err := tx.GetOperationEvents(0) assert.NoError(t, err) assert.Len(t, events, 1) - assert.Equal(t, *events[0].Body.V0.Data.U32, values[0]) + assert.True(t, events[0].InSuccessfulContractCall) + assert.Equal(t, *events[0].Event.Body.V0.Data.U32, values[0]) events, err = tx.GetOperationEvents(1) assert.NoError(t, err) @@ -79,8 +80,105 @@ func TestGetOperationEvents(t *testing.T) { events, err = tx.GetOperationEvents(2) assert.NoError(t, err) assert.Len(t, events, 2) - assert.Equal(t, *events[0].Body.V0.Data.U32, values[1]) - assert.Equal(t, *events[1].Body.V0.Data.U32, values[2]) + assert.True(t, events[0].InSuccessfulContractCall) + assert.Equal(t, *events[0].Event.Body.V0.Data.U32, values[1]) + assert.True(t, events[1].InSuccessfulContractCall) + assert.Equal(t, *events[1].Event.Body.V0.Data.U32, values[2]) + + events, err = tx.GetOperationEvents(3) + assert.NoError(t, err) + assert.Empty(t, events) + + tx.UnsafeMeta.V = 0 + _, err = tx.GetOperationEvents(0) + assert.EqualError(t, err, "unsupported TransactionMeta version: 0") + + tx.UnsafeMeta.V = 4 + _, err = tx.GetOperationEvents(0) + assert.EqualError(t, err, "unsupported TransactionMeta version: 4") + + tx.UnsafeMeta.V = 1 + events, err = tx.GetOperationEvents(0) + assert.NoError(t, err) + assert.Empty(t, events) + + tx.UnsafeMeta.V = 2 + events, err = tx.GetOperationEvents(0) + assert.NoError(t, err) + assert.Empty(t, events) +} + +func TestGetDiagnosticEvents(t *testing.T) { + values := make([]xdr.Uint32, 3) + for i := range values { + values[i] = xdr.Uint32(i) + } + tx := LedgerTransaction{ + FeeChanges: xdr.LedgerEntryChanges{}, + UnsafeMeta: xdr.TransactionMeta{ + V: 3, + V3: &xdr.TransactionMetaV3{ + DiagnosticEvents: []xdr.OperationDiagnosticEvents{ + {Events: []xdr.DiagnosticEvent{ + { + InSuccessfulContractCall: false, + Event: xdr.ContractEvent{ + Type: xdr.ContractEventTypeSystem, + Body: xdr.ContractEventBody{ + V: 0, + V0: &xdr.ContractEventV0{ + Data: xdr.ScVal{Type: xdr.ScValTypeScvU32, U32: &values[0]}, + }, + }, + }, + }, + }}, + {Events: []xdr.DiagnosticEvent{}}, + {Events: []xdr.DiagnosticEvent{ + { + InSuccessfulContractCall: true, + + Event: xdr.ContractEvent{ + Type: xdr.ContractEventTypeSystem, + Body: xdr.ContractEventBody{ + V: 0, + V0: &xdr.ContractEventV0{ + Data: xdr.ScVal{Type: xdr.ScValTypeScvU32, U32: &values[1]}, + }, + }, + }}, + { + InSuccessfulContractCall: true, + Event: xdr.ContractEvent{ + Type: xdr.ContractEventTypeSystem, + Body: xdr.ContractEventBody{ + V: 0, + V0: &xdr.ContractEventV0{ + Data: xdr.ScVal{Type: xdr.ScValTypeScvU32, U32: &values[2]}, + }, + }, + }}, + }}, + }, + }, + }} + events, err := tx.GetOperationEvents(0) + assert.NoError(t, err) + assert.Len(t, events, 1) + assert.False(t, events[0].InSuccessfulContractCall) + assert.Equal(t, *events[0].Event.Body.V0.Data.U32, values[0]) + + events, err = tx.GetOperationEvents(1) + assert.NoError(t, err) + assert.Empty(t, events) + + events, err = tx.GetOperationEvents(2) + assert.NoError(t, err) + assert.Len(t, events, 2) + assert.True(t, events[0].InSuccessfulContractCall) + assert.Equal(t, *events[0].Event.Body.V0.Data.U32, values[1]) + assert.True(t, events[1].InSuccessfulContractCall) + assert.Equal(t, *events[1].Event.Body.V0.Data.U32, values[2]) events, err = tx.GetOperationEvents(3) assert.NoError(t, err) diff --git a/services/horizon/internal/ingest/processors/contract_data.go b/services/horizon/internal/ingest/processors/contract_data.go index 80c4d9c058..3b7b26c6bf 100644 --- a/services/horizon/internal/ingest/processors/contract_data.go +++ b/services/horizon/internal/ingest/processors/contract_data.go @@ -8,34 +8,51 @@ import ( ) var ( + nativeAssetSym = xdr.ScSymbol("Native") balanceMetadataSym = xdr.ScSymbol("Balance") assetMetadataSym = xdr.ScSymbol("Metadata") - assetMetadataObj = &xdr.ScObject{ - Type: xdr.ScObjectTypeScoVec, - Vec: &xdr.ScVec{ - xdr.ScVal{ - Type: xdr.ScValTypeScvSymbol, - Sym: &assetMetadataSym, - }, + assetMetadataVec = &xdr.ScVec{ + xdr.ScVal{ + Type: xdr.ScValTypeScvSymbol, + Sym: &assetMetadataSym, }, } assetMetadataKey = xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &assetMetadataObj, + Type: xdr.ScValTypeScvVec, + Vec: &assetMetadataVec, } ) -// AssetFromContractData takes a ledger entry and verifies if the ledger entry corresponds -// to the asset metadata written to contract storage by the Stellar Asset Contract upon -// initialization. See: -// https://github.com/stellar/rs-soroban-env/blob/5695440da452837555d8f7f259cc33341fdf07b0/soroban-env-host/src/native_contract/token/public_types.rs#L21 -// https://github.com/stellar/rs-soroban-env/blob/5695440da452837555d8f7f259cc33341fdf07b0/soroban-env-host/src/native_contract/token/metadata.rs#L8 -// https://github.com/stellar/rs-soroban-env/blob/5695440da452837555d8f7f259cc33341fdf07b0/soroban-env-host/src/native_contract/token/contract.rs#L108 -// Note that AssetFromContractData will ignore forged asset metadata entries by deriving -// the Stellar Asset Contract id from the asset metadata and comparing it to the contract -// id found in the ledger entry. -// If the given ledger entry is a verified asset metadata entry AssetFromContractData will -// return the corresponding Stellar asset. Otherwise, AssetFromContractData will return nil. +// AssetFromContractData takes a ledger entry and verifies if the ledger entry +// corresponds to the asset metadata written to contract storage by the Stellar +// Asset Contract upon initialization. +// +// Note that AssetFromContractData will ignore forged asset metadata entries by +// deriving the Stellar Asset Contract ID from the asset metadata and comparing +// it to the contract ID found in the ledger entry. +// +// If the given ledger entry is a verified asset metadata entry, +// AssetFromContractData will return the corresponding Stellar asset. Otherwise, +// it returns nil. +// +// References: +// +// https://github.com/stellar/rs-soroban-env/blob/da325551829d31dcbfa71427d51c18e71a121c5f/soroban-env-host/src/native_contract/token/public_types.rs#L21 +// https://github.com/stellar/rs-soroban-env/blob/da325551829d31dcbfa71427d51c18e71a121c5f/soroban-env-host/src/native_contract/token/metadata.rs#L8 +// https://github.com/stellar/rs-soroban-env/blob/da325551829d31dcbfa71427d51c18e71a121c5f/soroban-env-host/src/native_contract/token/contract.rs#L108 +// +// The `ContractData` entry takes the following form: +// +// - Key: a vector with one element, which is the symbol "Metadata" +// +// ScVal{ Vec: ScVec({ ScVal{ Sym: ScSymbol("metadata") }})} +// +// - Value: a map with two key-value pairs: code and issuer +// +// ScVal{ Map: ScMap( +// { ScVal{ Sym: ScSymbol("asset_code") } -> ScVal{ Bytes: ScBytes(...) } }, +// { ScVal{ Sym: ScSymbol("asset_code") } -> ScVal{ Bytes: ScBytes(...) } } +// )} func AssetFromContractData(ledgerEntry xdr.LedgerEntry, passphrase string) *xdr.Asset { contractData, ok := ledgerEntry.Data.GetContractData() if !ok { @@ -51,15 +68,12 @@ func AssetFromContractData(ledgerEntry xdr.LedgerEntry, passphrase string) *xdr. if !contractData.Key.Equals(assetMetadataKey) { return nil } - obj, ok := contractData.Val.GetObj() - if !ok || obj == nil { - return nil - } - vec, ok := obj.GetVec() - if !ok || len(vec) <= 0 { + vecPtr, ok := contractData.Val.GetVec() + if !ok || vecPtr == nil || len(*vecPtr) != 2 { return nil } + vec := *vecPtr sym, ok := vec[0].GetSym() if !ok { @@ -71,28 +85,20 @@ func AssetFromContractData(ledgerEntry xdr.LedgerEntry, passphrase string) *xdr. default: return nil } - if len(vec) != 2 { - return nil - } var assetCode, assetIssuer string - obj, ok = vec[1].GetObj() - if !ok || obj == nil { - return nil - } - assetMap, ok := obj.GetMap() - if !ok || len(assetMap) != 2 { + assetMapPtr, ok := vec[1].GetMap() + if !ok || assetMapPtr == nil || len(*assetMapPtr) != 2 { return nil } + assetMap := *assetMapPtr + assetCodeEntry, assetIssuerEntry := assetMap[0], assetMap[1] if sym, ok = assetCodeEntry.Key.GetSym(); !ok || sym != "asset_code" { return nil } - if obj, ok = assetCodeEntry.Val.GetObj(); !ok || obj == nil { - return nil - } - bin, ok := obj.GetBin() - if !ok { + bin, ok := assetCodeEntry.Val.GetBytes() + if !ok || bin == nil { return nil } assetCode = string(bin) @@ -100,11 +106,8 @@ func AssetFromContractData(ledgerEntry xdr.LedgerEntry, passphrase string) *xdr. if sym, ok = assetIssuerEntry.Key.GetSym(); !ok || sym != "issuer" { return nil } - if obj, ok = assetIssuerEntry.Val.GetObj(); !ok || obj == nil { - return nil - } - bin, ok = obj.GetBin() - if !ok { + bin, ok = assetIssuerEntry.Val.GetBytes() + if !ok || bin == nil { return nil } assetIssuer, err = strkey.Encode(strkey.VersionByteAccountID, bin) @@ -128,9 +131,13 @@ func AssetFromContractData(ledgerEntry xdr.LedgerEntry, passphrase string) *xdr. return &asset } -// ContractBalanceFromContractData takes a ledger entry and verifies if the ledger entry corresponds -// to the balance entry written to contract storage by the Stellar Asset Contract. See: -// https://github.com/stellar/rs-soroban-env/blob/5695440da452837555d8f7f259cc33341fdf07b0/soroban-env-host/src/native_contract/token/storage_types.rs#L11-L24 +// ContractBalanceFromContractData takes a ledger entry and verifies that the +// ledger entry corresponds to the balance entry written to contract storage by +// the Stellar Asset Contract. +// +// Reference: +// +// https://github.com/stellar/rs-soroban-env/blob/da325551829d31dcbfa71427d51c18e71a121c5f/soroban-env-host/src/native_contract/token/storage_types.rs#L11-L24 func ContractBalanceFromContractData(ledgerEntry xdr.LedgerEntry, passphrase string) ([32]byte, *big.Int, bool) { contractData, ok := ledgerEntry.Data.GetContractData() if !ok { @@ -143,34 +150,35 @@ func ContractBalanceFromContractData(ledgerEntry xdr.LedgerEntry, passphrase str return [32]byte{}, nil, false } - keyObj, ok := contractData.Key.GetObj() - if !ok || keyObj == nil { + keyEnumVecPtr, ok := contractData.Key.GetVec() + if !ok || keyEnumVecPtr == nil { return [32]byte{}, nil, false } - keyEnumVec, ok := keyObj.GetVec() - if !ok || len(keyEnumVec) != 2 || !keyEnumVec[0].Equals( - xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &balanceMetadataSym}, + keyEnumVec := *keyEnumVecPtr + if len(keyEnumVec) != 2 || !keyEnumVec[0].Equals( + xdr.ScVal{ + Type: xdr.ScValTypeScvSymbol, + Sym: &balanceMetadataSym, + }, ) { return [32]byte{}, nil, false } - addressObj, ok := keyEnumVec[1].GetObj() - if !ok || addressObj == nil { - return [32]byte{}, nil, false - } - scAddress, ok := addressObj.GetAddress() + + scAddress, ok := keyEnumVec[1].GetAddress() if !ok { return [32]byte{}, nil, false } + holder, ok := scAddress.GetContractId() if !ok { return [32]byte{}, nil, false } - obj, ok := contractData.Val.GetObj() - if !ok || obj == nil { + balanceMapPtr, ok := contractData.Val.GetMap() + if !ok || balanceMapPtr == nil { return [32]byte{}, nil, false } - balanceMap, ok := obj.GetMap() + balanceMap := *balanceMapPtr if !ok || len(balanceMap) != 3 { return [32]byte{}, nil, false } @@ -187,14 +195,11 @@ func ContractBalanceFromContractData(ledgerEntry xdr.LedgerEntry, passphrase str !balanceMap[2].Val.IsBool() { return [32]byte{}, nil, false } - amountObj, ok := balanceMap[0].Val.GetObj() - if !ok || amountObj == nil { - return [32]byte{}, nil, false - } - amount, ok := amountObj.GetI128() + amount, ok := balanceMap[0].Val.GetI128() if !ok { return [32]byte{}, nil, false } + // amount cannot be negative // https://github.com/stellar/rs-soroban-env/blob/a66f0815ba06a2f5328ac420950690fd1642f887/soroban-env-host/src/native_contract/token/balance.rs#L92-L93 if int64(amount.Hi) < 0 { @@ -205,19 +210,14 @@ func ContractBalanceFromContractData(ledgerEntry xdr.LedgerEntry, passphrase str return holder, amt, true } -func metadataObjFromAsset(isNative bool, code, issuer string) (*xdr.ScObject, error) { +func metadataObjFromAsset(isNative bool, code, issuer string) (*xdr.ScVec, error) { if isNative { - symbol := xdr.ScSymbol("Native") - metadataObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoVec, - Vec: &xdr.ScVec{ - xdr.ScVal{ - Type: xdr.ScValTypeScvSymbol, - Sym: &symbol, - }, + return &xdr.ScVec{ + xdr.ScVal{ + Type: xdr.ScValTypeScvSymbol, + Sym: &nativeAssetSym, }, - } - return metadataObj, nil + }, nil } var assetCodeLength int @@ -229,69 +229,57 @@ func metadataObjFromAsset(isNative bool, code, issuer string) (*xdr.ScObject, er symbol = "AlphaNum12" assetCodeLength = 12 } + + assetCodeSymbol := xdr.ScSymbol("asset_code") assetCodeBytes := make([]byte, assetCodeLength) copy(assetCodeBytes, code) - assetCodeSymbol := xdr.ScSymbol("asset_code") - issuerSymbol := xdr.ScSymbol("issuer") - assetCodeObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoBytes, - Bin: &assetCodeBytes, - } + issuerSymbol := xdr.ScSymbol("issuer") issuerBytes, err := strkey.Decode(strkey.VersionByteAccountID, issuer) if err != nil { return nil, err } - issuerObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoBytes, - Bin: &issuerBytes, - } - - mapObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoMap, - Map: &xdr.ScMap{ - xdr.ScMapEntry{ - Key: xdr.ScVal{ - Type: xdr.ScValTypeScvSymbol, - Sym: &assetCodeSymbol, - }, - Val: xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &assetCodeObj, - }, + + mapObj := &xdr.ScMap{ + xdr.ScMapEntry{ + Key: xdr.ScVal{ + Type: xdr.ScValTypeScvSymbol, + Sym: &assetCodeSymbol, }, - xdr.ScMapEntry{ - Key: xdr.ScVal{ - Type: xdr.ScValTypeScvSymbol, - Sym: &issuerSymbol, - }, - Val: xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &issuerObj, - }, + Val: xdr.ScVal{ + Type: xdr.ScValTypeScvBytes, + Bytes: (*xdr.ScBytes)(&assetCodeBytes), }, }, - } - metadataObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoVec, - Vec: &xdr.ScVec{ - xdr.ScVal{ + xdr.ScMapEntry{ + Key: xdr.ScVal{ Type: xdr.ScValTypeScvSymbol, - Sym: &symbol, + Sym: &issuerSymbol, }, - xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &mapObj, + Val: xdr.ScVal{ + Type: xdr.ScValTypeScvBytes, + Bytes: (*xdr.ScBytes)(&issuerBytes), }, }, } - return metadataObj, nil + + return &xdr.ScVec{ + xdr.ScVal{ + Type: xdr.ScValTypeScvSymbol, + Sym: &symbol, + }, + xdr.ScVal{ + Type: xdr.ScValTypeScvMap, + Map: &mapObj, + }, + }, nil } -// AssetToContractData is the inverse of AssetFromContractData. It creates a ledger entry -// containing the asset metadata written to contract storage by the Stellar Asset Contract. +// AssetToContractData is the inverse of AssetFromContractData. It creates a +// ledger entry containing the asset metadata written to contract storage by the +// Stellar Asset Contract. func AssetToContractData(isNative bool, code, issuer string, contractID [32]byte) (xdr.LedgerEntryData, error) { - obj, err := metadataObjFromAsset(isNative, code, issuer) + vec, err := metadataObjFromAsset(isNative, code, issuer) if err != nil { return xdr.LedgerEntryData{}, err } @@ -301,15 +289,16 @@ func AssetToContractData(isNative bool, code, issuer string, contractID [32]byte ContractId: contractID, Key: assetMetadataKey, Val: xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &obj, + Type: xdr.ScValTypeScvVec, + Vec: &vec, }, }, }, nil } -// BalanceToContractData is the inverse of ContractBalanceFromContractData. It creates a ledger entry -// containing the asset balance of a contract holder written to contract storage by the Stellar Asset Contract. +// BalanceToContractData is the inverse of ContractBalanceFromContractData. It +// creates a ledger entry containing the asset balance of a contract holder +// written to contract storage by the Stellar Asset Contract. func BalanceToContractData(assetContractId, holderID [32]byte, amt uint64) xdr.LedgerEntryData { return balanceToContractData(assetContractId, holderID, xdr.Int128Parts{ Lo: xdr.Uint64(amt), @@ -319,64 +308,48 @@ func BalanceToContractData(assetContractId, holderID [32]byte, amt uint64) xdr.L func balanceToContractData(assetContractId, holderID [32]byte, amt xdr.Int128Parts) xdr.LedgerEntryData { holder := xdr.Hash(holderID) - addressObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoAddress, - Address: &xdr.ScAddress{ - Type: xdr.ScAddressTypeScAddressTypeContract, - ContractId: &holder, - }, + scAddress := &xdr.ScAddress{ + Type: xdr.ScAddressTypeScAddressTypeContract, + ContractId: &holder, } - keyObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoVec, - Vec: &xdr.ScVec{ - xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &balanceMetadataSym}, - xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &addressObj, - }, - }, + keyVec := &xdr.ScVec{ + xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &balanceMetadataSym}, + xdr.ScVal{Type: xdr.ScValTypeScvAddress, Address: scAddress}, } - amountObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoI128, - I128: &amt, - } amountSym := xdr.ScSymbol("amount") authorizedSym := xdr.ScSymbol("authorized") clawbackSym := xdr.ScSymbol("clawback") - trueIc := xdr.ScStaticScsTrue - dataObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoMap, - Map: &xdr.ScMap{ - xdr.ScMapEntry{ - Key: xdr.ScVal{ - Type: xdr.ScValTypeScvSymbol, - Sym: &amountSym, - }, - Val: xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &amountObj, - }, + trueIc := true + dataMap := &xdr.ScMap{ + xdr.ScMapEntry{ + Key: xdr.ScVal{ + Type: xdr.ScValTypeScvSymbol, + Sym: &amountSym, + }, + Val: xdr.ScVal{ + Type: xdr.ScValTypeScvI128, + I128: &amt, + }, + }, + xdr.ScMapEntry{ + Key: xdr.ScVal{ + Type: xdr.ScValTypeScvSymbol, + Sym: &authorizedSym, + }, + Val: xdr.ScVal{ + Type: xdr.ScValTypeScvBool, + B: &trueIc, }, - xdr.ScMapEntry{ - Key: xdr.ScVal{ - Type: xdr.ScValTypeScvSymbol, - Sym: &authorizedSym, - }, - Val: xdr.ScVal{ - Type: xdr.ScValTypeScvStatic, - Ic: &trueIc, - }, + }, + xdr.ScMapEntry{ + Key: xdr.ScVal{ + Type: xdr.ScValTypeScvSymbol, + Sym: &clawbackSym, }, - xdr.ScMapEntry{ - Key: xdr.ScVal{ - Type: xdr.ScValTypeScvSymbol, - Sym: &clawbackSym, - }, - Val: xdr.ScVal{ - Type: xdr.ScValTypeScvStatic, - Ic: &trueIc, - }, + Val: xdr.ScVal{ + Type: xdr.ScValTypeScvBool, + B: &trueIc, }, }, } @@ -386,12 +359,12 @@ func balanceToContractData(assetContractId, holderID [32]byte, amt xdr.Int128Par ContractData: &xdr.ContractDataEntry{ ContractId: assetContractId, Key: xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &keyObj, + Type: xdr.ScValTypeScvVec, + Vec: &keyVec, }, Val: xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &dataObj, + Type: xdr.ScValTypeScvMap, + Map: &dataMap, }, }, } diff --git a/services/horizon/internal/ingest/processors/effects_processor.go b/services/horizon/internal/ingest/processors/effects_processor.go index 096111decd..07135dc456 100644 --- a/services/horizon/internal/ingest/processors/effects_processor.go +++ b/services/horizon/internal/ingest/processors/effects_processor.go @@ -236,14 +236,14 @@ func (operation *transactionOperationWrapper) effects() ([]effect, error) { case xdr.OperationTypeInvokeHostFunction: // If there's an invokeHostFunction operation, there's definitely V3 // meta in the transaction, which means this error is real. - events, innerErr := operation.transaction.GetOperationEvents(operation.index) + diagnosticEvents, innerErr := operation.transaction.GetOperationEvents(operation.index) if innerErr != nil { return nil, innerErr } // For now, the only effects are related to the events themselves. // Possible add'l work: https://github.com/stellar/go/issues/4585 - err = wrapper.addInvokeHostFunctionEffects(events) + err = wrapper.addInvokeHostFunctionEffects(filterEvents(diagnosticEvents)) default: return nil, fmt.Errorf("unknown operation type: %s", op.Body.Type) @@ -274,6 +274,17 @@ func (operation *transactionOperationWrapper) effects() ([]effect, error) { return wrapper.effects, nil } +func filterEvents(diagnosticEvents []xdr.DiagnosticEvent) []xdr.ContractEvent { + var filtered []xdr.ContractEvent + for _, diagnosticEvent := range diagnosticEvents { + if !diagnosticEvent.InSuccessfulContractCall || diagnosticEvent.Event.Type != xdr.ContractEventTypeContract { + continue + } + filtered = append(filtered, diagnosticEvent.Event) + } + return filtered +} + type effectsWrapper struct { effects []effect operation *transactionOperationWrapper diff --git a/services/horizon/internal/ingest/processors/operations_processor.go b/services/horizon/internal/ingest/processors/operations_processor.go index ac52f9c068..2d669732ca 100644 --- a/services/horizon/internal/ingest/processors/operations_processor.go +++ b/services/horizon/internal/ingest/processors/operations_processor.go @@ -268,13 +268,13 @@ func (operation *transactionOperationWrapper) IsPayment() bool { case xdr.OperationTypeAccountMerge: return true case xdr.OperationTypeInvokeHostFunction: - events, err := operation.transaction.GetOperationEvents(0) + diagnosticEvents, err := operation.transaction.GetOperationEvents(operation.index) if err != nil { return false } // scan all the contract events for at least one SAC event, qualified to be a payment // in horizon - for _, contractEvent := range events { + for _, contractEvent := range filterEvents(diagnosticEvents) { if sacEvent, err := contractevents.NewStellarAssetContractEvent(&contractEvent, operation.network); err == nil { switch sacEvent.GetType() { case contractevents.EventTypeTransfer: @@ -719,14 +719,14 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{}, func (operation *transactionOperationWrapper) parseAssetBalanceChangesFromContractEvents() ([]map[string]interface{}, error) { balanceChanges := []map[string]interface{}{} - events, err := operation.transaction.GetOperationEvents(0) + diagnosticEvents, err := operation.transaction.GetOperationEvents(operation.index) if err != nil { // this operation in this context must be an InvokeHostFunctionOp, therefore V3Meta should be present // as it's in same soroban model, so if any err, it's real, return nil, err } - for _, contractEvent := range events { + for _, contractEvent := range filterEvents(diagnosticEvents) { // Parse the xdr contract event to contractevents.StellarAssetContractEvent model // has some convenience like to/from attributes are expressed in strkey format for accounts(G...) and contracts(C...) diff --git a/services/horizon/internal/ingest/processors/operations_processor_test.go b/services/horizon/internal/ingest/processors/operations_processor_test.go index 7ea8e21153..116acd1fb0 100644 --- a/services/horizon/internal/ingest/processors/operations_processor_test.go +++ b/services/horizon/internal/ingest/processors/operations_processor_test.go @@ -106,13 +106,8 @@ func (s *OperationsProcessorTestSuiteLedger) TestInvokeFunctionDetails() { contractParamVal2 := xdr.Int32(-5) contractParamVal3 := xdr.Uint32(6) contractParamVal4 := xdr.Uint64(3) - scoObjectBytes := []byte{0, 1, 2} - contractParamVal5 := xdr.ScObject{ - Type: xdr.ScObjectTypeScoBytes, - Bin: &scoObjectBytes, - } - contractParamVal5Addr := &contractParamVal5 - contractParamVal6 := xdr.ScStaticScsTrue + contractParamVal5 := xdr.ScBytes([]byte{0, 1, 2}) + contractParamVal6 := true ledgerKeyAccount := xdr.LedgerKeyAccount{ AccountId: source.ToAccountId(), @@ -149,16 +144,16 @@ func (s *OperationsProcessorTestSuiteLedger) TestInvokeFunctionDetails() { U32: &contractParamVal3, }, { - Type: xdr.ScValTypeScvBitset, - Bits: &contractParamVal4, + Type: xdr.ScValTypeScvU64, + U64: &contractParamVal4, }, { - Type: xdr.ScValTypeScvObject, - Obj: &contractParamVal5Addr, + Type: xdr.ScValTypeScvBytes, + Bytes: &contractParamVal5, }, { - Type: xdr.ScValTypeScvStatic, - Ic: &contractParamVal6, + Type: xdr.ScValTypeScvBool, + B: &contractParamVal6, }, { // invalid ScVal @@ -192,9 +187,9 @@ func (s *OperationsProcessorTestSuiteLedger) TestInvokeFunctionDetails() { s.assertInvokeHostFunctionParameter(serializedParams, 0, "Sym", args[0]) s.assertInvokeHostFunctionParameter(serializedParams, 1, "I32", args[1]) s.assertInvokeHostFunctionParameter(serializedParams, 2, "U32", args[2]) - s.assertInvokeHostFunctionParameter(serializedParams, 3, "Bits", args[3]) - s.assertInvokeHostFunctionParameter(serializedParams, 4, "Obj", args[4]) - s.assertInvokeHostFunctionParameter(serializedParams, 5, "Ic", args[5]) + s.assertInvokeHostFunctionParameter(serializedParams, 3, "U64", args[3]) + s.assertInvokeHostFunctionParameter(serializedParams, 4, "Bytes", args[4]) + s.assertInvokeHostFunctionParameter(serializedParams, 5, "B", args[5]) s.assertInvokeHostFunctionParameter(serializedParams, 6, "n/a", args[6]) }) @@ -325,8 +320,8 @@ func (s *OperationsProcessorTestSuiteLedger) TestInvokeFunctionDetails() { Salt: salt, }, }, - Source: xdr.ScContractCode{ - Type: xdr.ScContractCodeTypeSccontractCodeToken, + Source: xdr.ScContractExecutable{ + Type: xdr.ScContractExecutableTypeSccontractExecutableToken, }, }, }, diff --git a/services/horizon/internal/integration/contracts/Cargo.lock b/services/horizon/internal/integration/contracts/Cargo.lock index 646d4c6836..d4f261066c 100644 --- a/services/horizon/internal/integration/contracts/Cargo.lock +++ b/services/horizon/internal/integration/contracts/Cargo.lock @@ -324,6 +324,12 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +[[package]] +name = "ethnum" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0198b9d0078e0f30dedc7acbb21c974e838fc8fae3ee170128658a98cb2c1c04" + [[package]] name = "fnv" version = "1.0.7" @@ -793,10 +799,11 @@ checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" [[package]] name = "soroban-env-common" -version = "0.0.14" -source = "git+https://github.com/stellar/rs-soroban-env?rev=5695440da452837555d8f7f259cc33341fdf07b0#5695440da452837555d8f7f259cc33341fdf07b0" +version = "0.0.15" +source = "git+https://github.com/stellar/rs-soroban-env?rev=cf83838ae8a07a00224f0a5a3500eb7969bac7cf#cf83838ae8a07a00224f0a5a3500eb7969bac7cf" dependencies = [ "crate-git-revision", + "ethnum", "serde", "soroban-env-macros", "soroban-wasmi", @@ -806,8 +813,8 @@ dependencies = [ [[package]] name = "soroban-env-guest" -version = "0.0.14" -source = "git+https://github.com/stellar/rs-soroban-env?rev=5695440da452837555d8f7f259cc33341fdf07b0#5695440da452837555d8f7f259cc33341fdf07b0" +version = "0.0.15" +source = "git+https://github.com/stellar/rs-soroban-env?rev=cf83838ae8a07a00224f0a5a3500eb7969bac7cf#cf83838ae8a07a00224f0a5a3500eb7969bac7cf" dependencies = [ "soroban-env-common", "static_assertions", @@ -815,8 +822,8 @@ dependencies = [ [[package]] name = "soroban-env-host" -version = "0.0.14" -source = "git+https://github.com/stellar/rs-soroban-env?rev=5695440da452837555d8f7f259cc33341fdf07b0#5695440da452837555d8f7f259cc33341fdf07b0" +version = "0.0.15" +source = "git+https://github.com/stellar/rs-soroban-env?rev=cf83838ae8a07a00224f0a5a3500eb7969bac7cf#cf83838ae8a07a00224f0a5a3500eb7969bac7cf" dependencies = [ "backtrace", "curve25519-dalek", @@ -837,8 +844,8 @@ dependencies = [ [[package]] name = "soroban-env-macros" -version = "0.0.14" -source = "git+https://github.com/stellar/rs-soroban-env?rev=5695440da452837555d8f7f259cc33341fdf07b0#5695440da452837555d8f7f259cc33341fdf07b0" +version = "0.0.15" +source = "git+https://github.com/stellar/rs-soroban-env?rev=cf83838ae8a07a00224f0a5a3500eb7969bac7cf#cf83838ae8a07a00224f0a5a3500eb7969bac7cf" dependencies = [ "itertools", "proc-macro2", @@ -859,8 +866,8 @@ dependencies = [ [[package]] name = "soroban-ledger-snapshot" -version = "0.6.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=4fdb7e903f76e547b7699e554f6f536794f69b6c#4fdb7e903f76e547b7699e554f6f536794f69b6c" +version = "0.7.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=8abd3353c728f09ee1c8a2544f67a853e915afc2#8abd3353c728f09ee1c8a2544f67a853e915afc2" dependencies = [ "serde", "serde_json", @@ -870,8 +877,8 @@ dependencies = [ [[package]] name = "soroban-native-sdk-macros" -version = "0.0.14" -source = "git+https://github.com/stellar/rs-soroban-env?rev=5695440da452837555d8f7f259cc33341fdf07b0#5695440da452837555d8f7f259cc33341fdf07b0" +version = "0.0.15" +source = "git+https://github.com/stellar/rs-soroban-env?rev=cf83838ae8a07a00224f0a5a3500eb7969bac7cf#cf83838ae8a07a00224f0a5a3500eb7969bac7cf" dependencies = [ "itertools", "proc-macro2", @@ -888,8 +895,8 @@ dependencies = [ [[package]] name = "soroban-sdk" -version = "0.6.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=4fdb7e903f76e547b7699e554f6f536794f69b6c#4fdb7e903f76e547b7699e554f6f536794f69b6c" +version = "0.7.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=8abd3353c728f09ee1c8a2544f67a853e915afc2#8abd3353c728f09ee1c8a2544f67a853e915afc2" dependencies = [ "bytes-lit", "ed25519-dalek", @@ -903,8 +910,8 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" -version = "0.6.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=4fdb7e903f76e547b7699e554f6f536794f69b6c#4fdb7e903f76e547b7699e554f6f536794f69b6c" +version = "0.7.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=8abd3353c728f09ee1c8a2544f67a853e915afc2#8abd3353c728f09ee1c8a2544f67a853e915afc2" dependencies = [ "darling", "itertools", @@ -919,8 +926,8 @@ dependencies = [ [[package]] name = "soroban-spec" -version = "0.6.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=4fdb7e903f76e547b7699e554f6f536794f69b6c#4fdb7e903f76e547b7699e554f6f536794f69b6c" +version = "0.7.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=8abd3353c728f09ee1c8a2544f67a853e915afc2#8abd3353c728f09ee1c8a2544f67a853e915afc2" dependencies = [ "base64", "darling", @@ -990,8 +997,8 @@ dependencies = [ [[package]] name = "stellar-xdr" -version = "0.0.14" -source = "git+https://github.com/stellar/rs-stellar-xdr?rev=55f47d302a3bbcd34cf32bfcd28abccfaeffc5e0#55f47d302a3bbcd34cf32bfcd28abccfaeffc5e0" +version = "0.0.15" +source = "git+https://github.com/stellar/rs-stellar-xdr?rev=4655b635c698bb3bbc628bdba456df627c42ee3a#4655b635c698bb3bbc628bdba456df627c42ee3a" dependencies = [ "base64", "crate-git-revision", diff --git a/services/horizon/internal/integration/contracts/Cargo.toml b/services/horizon/internal/integration/contracts/Cargo.toml index a3153831f6..1cdfa2f1a1 100644 --- a/services/horizon/internal/integration/contracts/Cargo.toml +++ b/services/horizon/internal/integration/contracts/Cargo.toml @@ -22,11 +22,11 @@ codegen-units = 1 lto = true [workspace.dependencies.soroban-sdk] -version = "0.6.0" +version = "0.7.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "4fdb7e903f76e547b7699e554f6f536794f69b6c" +rev = "8abd3353c728f09ee1c8a2544f67a853e915afc2" [workspace.dependencies.soroban-auth] -version = "0.6.0" +version = "0.7.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "4fdb7e903f76e547b7699e554f6f536794f69b6c" \ No newline at end of file +rev = "8abd3353c728f09ee1c8a2544f67a853e915afc2" \ No newline at end of file diff --git a/services/horizon/internal/integration/contracts/increment/src/lib.rs b/services/horizon/internal/integration/contracts/increment/src/lib.rs index 13e4c7c3cf..7f01b275a6 100644 --- a/services/horizon/internal/integration/contracts/increment/src/lib.rs +++ b/services/horizon/internal/integration/contracts/increment/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] -use soroban_sdk::{contractimpl, log, symbol, Env, Symbol}; +use soroban_sdk::{contractimpl, log, Env, Symbol}; -const COUNTER: Symbol = symbol!("COUNTER"); +const COUNTER: Symbol = Symbol::short("COUNTER"); pub struct IncrementContract; diff --git a/services/horizon/internal/integration/contracts/soroban_token_spec.wasm b/services/horizon/internal/integration/contracts/soroban_token_spec.wasm index 3cd0012d8d64a91b22f395891ed95154ee6cc129..acac38f5eadf3ccb3ba18a6ebde5698efda1e44a 100755 GIT binary patch delta 1158 zcmb7BO=uHQ5PtLCX0y#EahtyiHO)(EYf5Y*4H|zCo5l8^AS!yW6tT7`w6#tDEJ86U z6sZOj!-FDt5)aX;fhu?r#EW;2o;`T*AmUBX)_EJZHW~{)*x7GpzM1*no0ZNFdv!86 zI{}0cmJRX6CC2grIPSy7cs{CF`g9YyDat7)d;&yi+?ql7W8NW>6XQbapVLs?v; z5wv+a4HfZ)9!GrNEhDeo-C~&y)QK)AGP>aCMpnfU5>dy6Eq)Ghi<-pTDRr_=^*N`k zUUQyA#t)~Q6xPCMk7&2Gio6NY$Hf^>3PVc6tvU_bTmv@onkc#?@wF=)C|BPqPBjnV z)Le(9)4k%mD_f_-H~sHx-9g?7&*6yGMlK^xcgjZi_Gk`Dvv15Oi-(>o$TYk|Xy+{Z z-aFL$OSnQ%JtaB^$m7dfYi89gFmnTz%y;DMGhBl1#*J_=R;6a!c_P4Q4u-6Zd2G2_ z2BwBcM2zzdA6M@dpWhJoZoar~6al!6|? zb#Nkgb#hKZWWV$!|AX!ICmMcFGHbl~Egpzfe`}kqg3jfvX|`Xh;Hy8i-_9r_Gr0-m z+Wz*H{ee9}n_1g)C6L;j{%6lx=I21N(e6P%k%M5`kIbmX(1IN0xb%ym2;c)8~NoYf`(K3IBAE_PGb0z;E(V@iam}b+%O7P404(!mCQPM_V{=M)g$U) zF_l}V)csK3E43czXLSTD-L?Hd7abb(_ZP|)3JCfkNNK~kpc8GOv?5pyUu$Ve6eQ!v z%E}5fKSD{1xyknyob0CxFGPm(-_pr7=YsGML!w{s@D4D+gFt-`KM`v@`4?t7Gg+uFAIcQD{(ijtuGv}AUCdHDV*5sb|IUY si)YdUxgoQZQDtOPQzzf6`vfzcE0^Q!TX8>td&Vy1`mB+Ph5ISL0Z-!sRR910 diff --git a/services/horizon/internal/integration/invokehostfunction_test.go b/services/horizon/internal/integration/invokehostfunction_test.go index 0846ca2e79..541a6f3d5d 100644 --- a/services/horizon/internal/integration/invokehostfunction_test.go +++ b/services/horizon/internal/integration/invokehostfunction_test.go @@ -201,13 +201,9 @@ func TestContractInvokeHostFunctionInvokeStatelessContractFn(t *testing.T) { contractCodeLedgerKey := createContractOp.Footprint.ReadOnly[0] contractIdBytes := contractID[:] - contractIdParameterObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoBytes, - Bin: &contractIdBytes, - } contractIdParameter := xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &contractIdParameterObj, + Type: xdr.ScValTypeScvBytes, + Bytes: (*xdr.ScBytes)(&contractIdBytes), } contractFnParameterSym := xdr.ScSymbol("add") @@ -217,18 +213,7 @@ func TestContractInvokeHostFunctionInvokeStatelessContractFn(t *testing.T) { } firstParamValue := xdr.Uint64(4) - firstParamValueObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoU64, - U64: &firstParamValue, - } - secondParamValue := xdr.Uint64(5) - secondParamValueObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoU64, - U64: &secondParamValue, - } - - contractCodeLedgerkeyAddr := xdr.ScStaticScsLedgerKeyContractCode invokeHostFunctionOp := &txnbuild.InvokeHostFunction{ Function: xdr.HostFunction{ @@ -237,12 +222,12 @@ func TestContractInvokeHostFunctionInvokeStatelessContractFn(t *testing.T) { contractIdParameter, contractFnParameter, xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &firstParamValueObj, + Type: xdr.ScValTypeScvU64, + U64: &firstParamValue, }, xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &secondParamValueObj, + Type: xdr.ScValTypeScvU64, + U64: &secondParamValue, }, }, }, @@ -253,8 +238,8 @@ func TestContractInvokeHostFunctionInvokeStatelessContractFn(t *testing.T) { ContractData: &xdr.LedgerKeyContractData{ ContractId: contractID, Key: xdr.ScVal{ - Type: xdr.ScValTypeScvStatic, - Ic: &contractCodeLedgerkeyAddr, + Type: xdr.ScValTypeScvLedgerKeyContractExecutable, + // symbolic: no value }, }, }, @@ -285,7 +270,7 @@ func TestContractInvokeHostFunctionInvokeStatelessContractFn(t *testing.T) { // check the function response, should have summed the two input numbers scval := invokeHostFunctionResult.MustSuccess() - assert.Equal(t, xdr.Uint64(9), scval.MustObj().MustU64()) + assert.Equal(t, xdr.Uint64(9), scval.MustU64()) } func TestContractInvokeHostFunctionInvokeStatefulContractFn(t *testing.T) { @@ -319,13 +304,9 @@ func TestContractInvokeHostFunctionInvokeStatefulContractFn(t *testing.T) { contractCodeLedgerKey := createContractOp.Footprint.ReadOnly[0] contractIdBytes := contractID[:] - contractIdParameterObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoBytes, - Bin: &contractIdBytes, - } contractIdParameter := xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &contractIdParameterObj, + Type: xdr.ScValTypeScvBytes, + Bytes: (*xdr.ScBytes)(&contractIdBytes), } contractFnParameterSym := xdr.ScSymbol("increment") @@ -335,8 +316,6 @@ func TestContractInvokeHostFunctionInvokeStatefulContractFn(t *testing.T) { } contractStateFootprintSym := xdr.ScSymbol("COUNTER") - contractCodeLedgerkeyAddr := xdr.ScStaticScsLedgerKeyContractCode - invokeHostFunctionOp := &txnbuild.InvokeHostFunction{ Function: xdr.HostFunction{ Type: xdr.HostFunctionTypeHostFunctionTypeInvokeContract, @@ -352,8 +331,8 @@ func TestContractInvokeHostFunctionInvokeStatefulContractFn(t *testing.T) { ContractData: &xdr.LedgerKeyContractData{ ContractId: contractID, Key: xdr.ScVal{ - Type: xdr.ScValTypeScvStatic, - Ic: &contractCodeLedgerkeyAddr, + Type: xdr.ScValTypeScvLedgerKeyContractExecutable, + // symbolic: no value }, }, }, @@ -460,12 +439,11 @@ func assembleCreateContractOp(t *testing.T, sourceAccount string, wasmFileName s assert.NoError(t, err) contractHash := xdr.Hash(sha256.Sum256(installContractCodeArgs)) - ledgerKeyContractCodeAddr := xdr.ScStaticScsLedgerKeyContractCode ledgerKey := xdr.LedgerKeyContractData{ ContractId: xdr.Hash(hashedContractID), Key: xdr.ScVal{ - Type: xdr.ScValTypeScvStatic, - Ic: &ledgerKeyContractCodeAddr, + Type: xdr.ScValTypeScvLedgerKeyContractExecutable, + // symbolic: no value }, } @@ -477,8 +455,8 @@ func assembleCreateContractOp(t *testing.T, sourceAccount string, wasmFileName s Type: xdr.ContractIdTypeContractIdFromSourceAccount, Salt: &saltParameter, }, - Source: xdr.ScContractCode{ - Type: xdr.ScContractCodeTypeSccontractCodeWasmRef, + Source: xdr.ScContractExecutable{ + Type: xdr.ScContractExecutableTypeSccontractExecutableWasmRef, WasmId: &contractHash, }, }, diff --git a/services/horizon/internal/integration/sac_test.go b/services/horizon/internal/integration/sac_test.go index fe8ef8f576..12506f87ca 100644 --- a/services/horizon/internal/integration/sac_test.go +++ b/services/horizon/internal/integration/sac_test.go @@ -140,11 +140,9 @@ func TestContractMintToContract(t *testing.T) { itest.Master(), balance(itest, issuer, asset, contractAddressParam(recipientContractID)), ) - assert.Equal(itest.CurrentTest(), xdr.ScValTypeScvObject, balanceAmount.Type) - assert.Equal(itest.CurrentTest(), xdr.ScObjectTypeScoI128, (*balanceAmount.Obj).Type) - - assert.Equal(itest.CurrentTest(), xdr.Uint64(math.MaxUint64-3), (*balanceAmount.Obj).I128.Lo) - assert.Equal(itest.CurrentTest(), xdr.Uint64(math.MaxInt64), (*balanceAmount.Obj).I128.Hi) + assert.Equal(itest.CurrentTest(), xdr.ScValTypeScvI128, balanceAmount.Type) + assert.Equal(itest.CurrentTest(), xdr.Uint64(math.MaxUint64-3), (*balanceAmount.I128).Lo) + assert.Equal(itest.CurrentTest(), xdr.Uint64(math.MaxInt64), (*balanceAmount.I128).Hi) assertEventPayments(itest, mintTx, asset, issuer, strkeyRecipientContractID, "mint", amount.String128(mintAmount)) // calling xfer from the issuer account will also mint the asset @@ -164,10 +162,11 @@ func TestContractMintToContract(t *testing.T) { itest.Master(), balance(itest, issuer, asset, contractAddressParam(recipientContractID)), ) + assert.Equal(itest.CurrentTest(), xdr.ScValTypeScvI128, balanceAmount.Type) + assert.Equal(itest.CurrentTest(), xdr.Uint64(math.MaxUint64), (*balanceAmount.I128).Lo) + assert.Equal(itest.CurrentTest(), xdr.Uint64(math.MaxInt64), (*balanceAmount.I128).Hi) - assert.Equal(itest.CurrentTest(), xdr.Uint64(math.MaxUint64), (*balanceAmount.Obj).I128.Lo) - assert.Equal(itest.CurrentTest(), xdr.Uint64(math.MaxInt64), (*balanceAmount.Obj).I128.Hi) - // balanceContracts = 2^127 - 1 + // 2^127 - 1 balanceContracts := new(big.Int).Lsh(big.NewInt(1), 127) balanceContracts.Sub(balanceContracts, big.NewInt(1)) assertAssetStats(itest, assetStats{ @@ -364,8 +363,9 @@ func TestContractTransferBetweenAccountAndContract(t *testing.T) { itest.Master(), balance(itest, issuer, asset, contractAddressParam(recipientContractID)), ) - assert.Equal(itest.CurrentTest(), xdr.Uint64(5300000000), (*balanceAmount.Obj).I128.Lo) - assert.Equal(itest.CurrentTest(), xdr.Uint64(0), (*balanceAmount.Obj).I128.Hi) + assert.Equal(itest.CurrentTest(), xdr.ScValTypeScvI128, balanceAmount.Type) + assert.Equal(itest.CurrentTest(), xdr.Uint64(5300000000), (*balanceAmount.I128).Lo) + assert.Equal(itest.CurrentTest(), xdr.Uint64(0), (*balanceAmount.I128).Hi) } func TestContractTransferBetweenContracts(t *testing.T) { @@ -422,9 +422,9 @@ func TestContractTransferBetweenContracts(t *testing.T) { itest.Master(), balance(itest, issuer, asset, contractAddressParam(emitterContractID)), ) - - assert.Equal(itest.CurrentTest(), xdr.Uint64(9900000000), (*emitterBalanceAmount.Obj).I128.Lo) - assert.Equal(itest.CurrentTest(), xdr.Uint64(0), (*emitterBalanceAmount.Obj).I128.Hi) + assert.Equal(itest.CurrentTest(), xdr.ScValTypeScvI128, emitterBalanceAmount.Type) + assert.Equal(itest.CurrentTest(), xdr.Uint64(9900000000), (*emitterBalanceAmount.I128).Lo) + assert.Equal(itest.CurrentTest(), xdr.Uint64(0), (*emitterBalanceAmount.I128).Hi) recipientBalanceAmount, _ := assertInvokeHostFnSucceeds( itest, @@ -432,8 +432,9 @@ func TestContractTransferBetweenContracts(t *testing.T) { balance(itest, issuer, asset, contractAddressParam(recipientContractID)), ) - assert.Equal(itest.CurrentTest(), xdr.Uint64(100000000), (*recipientBalanceAmount.Obj).I128.Lo) - assert.Equal(itest.CurrentTest(), xdr.Uint64(0), (*recipientBalanceAmount.Obj).I128.Hi) + assert.Equal(itest.CurrentTest(), xdr.ScValTypeScvI128, recipientBalanceAmount.Type) + assert.Equal(itest.CurrentTest(), xdr.Uint64(100000000), (*recipientBalanceAmount.I128).Lo) + assert.Equal(itest.CurrentTest(), xdr.Uint64(0), (*recipientBalanceAmount.I128).Hi) assertAssetStats(itest, assetStats{ code: code, @@ -565,8 +566,9 @@ func TestContractBurnFromContract(t *testing.T) { balance(itest, issuer, asset, contractAddressParam(recipientContractID)), ) - assert.Equal(itest.CurrentTest(), xdr.Uint64(9900000000), (*balanceAmount.Obj).I128.Lo) - assert.Equal(itest.CurrentTest(), xdr.Uint64(0), (*balanceAmount.Obj).I128.Hi) + assert.Equal(itest.CurrentTest(), xdr.ScValTypeScvI128, balanceAmount.Type) + assert.Equal(itest.CurrentTest(), xdr.Uint64(9900000000), (*balanceAmount.I128).Lo) + assert.Equal(itest.CurrentTest(), xdr.Uint64(0), (*balanceAmount.I128).Hi) // Burn transactions across contracts generate burn events, but these // shouldn't be included as account-related effects. @@ -708,8 +710,9 @@ func TestContractClawbackFromContract(t *testing.T) { balance(itest, issuer, asset, contractAddressParam(recipientContractID)), ) - assert.Equal(itest.CurrentTest(), xdr.Uint64(9900000000), (*balanceAmount.Obj).I128.Lo) - assert.Equal(itest.CurrentTest(), xdr.Uint64(0), (*balanceAmount.Obj).I128.Hi) + assert.Equal(itest.CurrentTest(), xdr.ScValTypeScvI128, balanceAmount.Type) + assert.Equal(itest.CurrentTest(), xdr.Uint64(9900000000), (*balanceAmount.I128).Lo) + assert.Equal(itest.CurrentTest(), xdr.Uint64(0), (*balanceAmount.I128).Hi) // clawbacks between contracts generate events but not effects assert.Empty(t, getTxEffects(itest, clawTx, asset)) @@ -842,56 +845,43 @@ func functionNameParam(name string) xdr.ScVal { } func contractIDParam(contractID xdr.Hash) xdr.ScVal { - contractIdBytes := contractID[:] - contractIdParameterObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoBytes, - Bin: &contractIdBytes, - } + contractBytes := contractID[:] return xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &contractIdParameterObj, + Type: xdr.ScValTypeScvBytes, + Bytes: (*xdr.ScBytes)(&contractBytes), } } func accountAddressParam(accountID string) xdr.ScVal { - accountObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoAddress, - Address: &xdr.ScAddress{ - Type: xdr.ScAddressTypeScAddressTypeAccount, - AccountId: xdr.MustAddressPtr(accountID), - }, + address := xdr.ScAddress{ + Type: xdr.ScAddressTypeScAddressTypeAccount, + AccountId: xdr.MustAddressPtr(accountID), } return xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &accountObj, + Type: xdr.ScValTypeScvAddress, + Address: &address, } } func contractAddressParam(contractID xdr.Hash) xdr.ScVal { - contractObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoAddress, - Address: &xdr.ScAddress{ - Type: xdr.ScAddressTypeScAddressTypeContract, - ContractId: &contractID, - }, + address := xdr.ScAddress{ + Type: xdr.ScAddressTypeScAddressTypeContract, + ContractId: &contractID, } return xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &contractObj, + Type: xdr.ScValTypeScvAddress, + Address: &address, } } func i128Param(hi, lo uint64) xdr.ScVal { - i128Obj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoI128, - I128: &xdr.Int128Parts{ - Hi: xdr.Uint64(hi), - Lo: xdr.Uint64(lo), - }, + i128 := &xdr.Int128Parts{ + Hi: xdr.Uint64(hi), + Lo: xdr.Uint64(lo), } return xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &i128Obj, + Type: xdr.ScValTypeScvI128, + I128: i128, } } @@ -904,8 +894,8 @@ func createSAC(itest *integration.Test, sourceAccount string, asset xdr.Asset) * Type: xdr.ContractIdTypeContractIdFromAsset, Asset: &asset, }, - Source: xdr.ScContractCode{ - Type: xdr.ScContractCodeTypeSccontractCodeToken, + Source: xdr.ScContractExecutable{ + Type: xdr.ScContractExecutableTypeSccontractExecutableToken, }, }, }, diff --git a/services/horizon/internal/integration/testdata/soroban_add_u64.wasm b/services/horizon/internal/integration/testdata/soroban_add_u64.wasm index a32ff9cecf069441f786fe7506e2836ef34adf46..dfb30d037269c66954074d621bbff05202965526 100755 GIT binary patch delta 180 zcmdna{F8Y?dsH(MYX}o#J!2h{1CxUS<8sIUjD<=}jt3arco~2KOpa_oh7+SAGY=ED z0;3a0ha#gB1CYna4Wbkn1sZ^WL6MPLfkA=MoS6eiF`F|paL;6%cpyX@VyM%9C}0TV v1*&r5Xmes~QDgv`0o30J*3ZB_S&q@0QDJfxqlqLN0|YQ8L1+-45s29UrnMtH delta 114 zcmey#yq$SMyX8SfRue|XIwl7u2L;CEj_Pi_3{H%SOgxO-P7I1n3XB2`K)|5L$gRMj yz-Z3Q0i>ABnHjh%CO!<|0!lZ6r5PqCFnTk}OC&c+}lSJzG$Xn?l_X%nrMwSPW`l!w;{2`XFa0}06ZW2SjMT*z>eOT6D zQT&7#N%JCq40#c=#M^v_lpZ%hSW!BPbU>P_s#Xg%(|F~&?z7w3Ii|Qz?qxZ?k}$Szlo9*USw)TkL2%bF3Ht8)K;Cj8;TyAw+ z&8)qwIc_$;%vu}G#nx7)RsGMp=_u~&o|;v&mJi)2e>JJxA2i<}7?g`4q@3t66uv`k} zK=J?!=UZCbwz6>p72KUMTBh*X@p z(;!jRtoADU3A;??wvuDCGGaG*=PKAcsYoHMwg?O-r;5fk-${I!j;REnDl|bECl!t( z%fV?(3KtY_LHt5p2p7C81((QkiQKhu;BvkkTmr&F0r8tm#iiYln^$h)PyMa@_V`k#-Q8?0b+h*Nde&`iPhrXMXX!v) z89HojWJ`Wl4W}_iw{dsh%btpfN9Z1U5Ur}7kG026+5ts|L+CL%#1aSRvYSXC?Ti9QaNt9nxQxg41ib6rjqHh) zTxJc1IN|%kZ}183xgd)_z%Ak*AcR0%Q4a9BXU1NWK6F=CzkXG(YNjdQ8!-{_YG<7* zuGUpm*+tw;)|yu2ytK|!S|^g%=6RcM;?6ebn7241hJAyC_hA#}F6e^0vp@B`wW;RFqjc z85U!@G`Degcbx4NJGbdM@80cVm!3z&%kx>bm6v%|jJFg=S@v;}-^n)ey+X6HXK`f6sGjOzk)9$$i5?h+74?~?FFSmq zhb!u;Gr>%Tjp$G9_0&fIqms@*e`WU+VWS5%G@2v*eeGQUFG3#LU38h!CHziV{}79<2E@13h~7O{18!0Ry>7GMRYf)ns~vVH zraD>A}l@(7_C2fh3>L4amf>6;#D2nYAbr(0L89JRWE=)vxrQAN;s9mv z5w30xcziS=_7^BZgVV=9{qYN`uD`V5z_!*@I`uC`D8rxsQ+7hb6{#yH=-P2|#I^wf zN_4>qHDY_|oXbuo61II*jZCkR=^Ojy)-u(pOn?*Bl~+*%e93FJ6g_nfi*H2>zJwU6 z;?SuL6VIv@6L#f>39Z`DYCltpja3^swO;zqlOLZ#WusP-6FM)~BWMrN_`@A6M37{%Qh*Aa?Ak7cN z93@4GdBtg|ML@PNRF2{IwuIv?$-f`EdB5cOk=&;EICg{HX}cqKo^qOt8<|Z{Bdb+V zZ|++EB5uyrh_xQG4)MjXt_l+0Zl|BVa?-ZlS0D9O0@d;Yv1(|r3xid0+20p^KG$Rp p{MPgmZ`=IwLgLp?A5Vq5#jl#IB)HS<8pHuyAWHDzVh9gN0ssTZNm&2@ literal 0 HcmV?d00001 diff --git a/support/contractevents/generate.go b/support/contractevents/generate.go index b1e42c7341..e2d8254e51 100644 --- a/support/contractevents/generate.go +++ b/support/contractevents/generate.go @@ -127,26 +127,17 @@ func makeBigAmount(amount *big.Int) xdr.ScVal { hi := new(big.Int).Rsh(amount, 64) lo := amount.And(amount, keepLower) - amountObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoI128, + return xdr.ScVal{ + Type: xdr.ScValTypeScvI128, I128: &xdr.Int128Parts{ Lo: xdr.Uint64(lo.Uint64()), Hi: xdr.Uint64(hi.Uint64()), }, } - - return xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &amountObj, - } } func makeAddress(address string) xdr.ScVal { scAddress := xdr.ScAddress{} - scObject := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoAddress, - Address: &scAddress, - } switch address[0] { case 'C': @@ -163,8 +154,8 @@ func makeAddress(address string) xdr.ScVal { } return xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &scObject, + Type: xdr.ScValTypeScvAddress, + Address: &scAddress, } } @@ -212,14 +203,9 @@ func makeAsset(asset xdr.Asset) xdr.ScVal { panic("unexpected asset type") } - slice := buffer.Bytes() - scObject := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoBytes, - Bin: &slice, - } - + slice := xdr.ScBytes(buffer.Bytes()) return xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &scObject, + Type: xdr.ScValTypeScvBytes, + Bytes: &slice, } } diff --git a/support/contractevents/utils.go b/support/contractevents/utils.go index 1769137beb..afd0da86f7 100644 --- a/support/contractevents/utils.go +++ b/support/contractevents/utils.go @@ -7,61 +7,46 @@ import ( var ErrNotBalanceChangeEvent = errors.New("event doesn't represent a balance change") -func parseAddress(val *xdr.ScVal) *xdr.ScAddress { - if val == nil { - return nil - } - - address, ok := val.GetObj() - if !ok || address == nil || address.Type != xdr.ScObjectTypeScoAddress { - return nil - } - - return address.Address -} - -func parseAmount(val *xdr.ScVal) *xdr.Int128Parts { - valueObj, ok := val.GetObj() - if !ok || valueObj == nil || valueObj.Type != xdr.ScObjectTypeScoI128 { - return nil - } - - return valueObj.I128 -} - // parseBalanceChangeEvent is a generalization of a subset of the Stellar Asset // Contract events. Transfer, mint, clawback, and burn events all have two // addresses and an amount involved. The addresses represent different things in // different event types (e.g. "from" or "admin"), but the parsing is identical. // This helper extracts all three parts or returns a generic error if it can't. -func parseBalanceChangeEvent(topics xdr.ScVec, value xdr.ScVal) (string, string, xdr.Int128Parts, error) { - first, second, amount := "", "", xdr.Int128Parts{} - +func parseBalanceChangeEvent(topics xdr.ScVec, value xdr.ScVal) ( + first string, + second string, + amount xdr.Int128Parts, + err error, +) { + err = ErrNotBalanceChangeEvent if len(topics) != 4 { - return first, second, amount, ErrNotBalanceChangeEvent + return } - rawFirst, rawSecond := topics[1], topics[2] - firstSc, secondSc := parseAddress(&rawFirst), parseAddress(&rawSecond) - if firstSc == nil || secondSc == nil { - return first, second, amount, ErrNotBalanceChangeEvent + firstSc, ok := topics[1].GetAddress() + if !ok { + return } - - first, err := firstSc.String() + first, err = firstSc.String() if err != nil { - return first, second, amount, errors.Wrap(err, ErrNotBalanceChangeEvent.Error()) + err = errors.Wrap(err, ErrNotBalanceChangeEvent.Error()) + return } + secondSc, ok := topics[2].GetAddress() + if !ok { + return + } second, err = secondSc.String() if err != nil { - return first, second, amount, errors.Wrap(err, ErrNotBalanceChangeEvent.Error()) + err = errors.Wrap(err, ErrNotBalanceChangeEvent.Error()) + return } - amountPtr := parseAmount(&value) - if amountPtr == nil { - return first, second, amount, ErrNotBalanceChangeEvent + amount, ok = value.GetI128() + if !ok { + return } - amount = *amountPtr return first, second, amount, nil } diff --git a/txnbuild/invoke_host_function_test.go b/txnbuild/invoke_host_function_test.go index 266028d88c..4b753f5208 100644 --- a/txnbuild/invoke_host_function_test.go +++ b/txnbuild/invoke_host_function_test.go @@ -40,18 +40,7 @@ func TestCreateInvokeHostFunctionInvalid(t *testing.T) { func TestInvokeHostFunctionRoundTrip(t *testing.T) { val := xdr.Int32(4) wasmId := xdr.Hash{1, 2, 3, 4} - obj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoContractCode, - ContractCode: &xdr.ScContractCode{ - Type: xdr.ScContractCodeTypeSccontractCodeWasmRef, - WasmId: &wasmId, - }, - } i64 := xdr.Int64(45) - rwObj := &xdr.ScObject{ - Type: xdr.ScObjectTypeScoI64, - I64: &i64, - } accountId := xdr.MustAddress("GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H") invokeHostFunctionOp := &InvokeHostFunction{ Function: xdr.HostFunction{ @@ -88,8 +77,11 @@ func TestInvokeHostFunctionRoundTrip(t *testing.T) { ContractData: &xdr.LedgerKeyContractData{ ContractId: xdr.Hash{1, 2, 3}, Key: xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &obj, + Type: xdr.ScValTypeScvContractExecutable, + Exec: &xdr.ScContractExecutable{ + Type: xdr.ScContractExecutableTypeSccontractExecutableWasmRef, + WasmId: &wasmId, + }, }, }, }, @@ -100,8 +92,8 @@ func TestInvokeHostFunctionRoundTrip(t *testing.T) { ContractData: &xdr.LedgerKeyContractData{ ContractId: xdr.Hash{1, 2, 3}, Key: xdr.ScVal{ - Type: xdr.ScValTypeScvObject, - Obj: &rwObj, + Type: xdr.ScValTypeScvI64, + I64: &i64, }, }, }, diff --git a/xdr/Stellar-contract-spec.x b/xdr/Stellar-contract-spec.x index 47647a13d1..8431e226f8 100644 --- a/xdr/Stellar-contract-spec.x +++ b/xdr/Stellar-contract-spec.x @@ -17,19 +17,23 @@ enum SCSpecType SC_SPEC_TYPE_VAL = 0, // Types with no parameters. - SC_SPEC_TYPE_U32 = 1, - SC_SPEC_TYPE_I32 = 2, - SC_SPEC_TYPE_U64 = 3, - SC_SPEC_TYPE_I64 = 4, - SC_SPEC_TYPE_U128 = 5, - SC_SPEC_TYPE_I128 = 6, - SC_SPEC_TYPE_BOOL = 7, - SC_SPEC_TYPE_SYMBOL = 8, - SC_SPEC_TYPE_BITSET = 9, - SC_SPEC_TYPE_STATUS = 10, - SC_SPEC_TYPE_BYTES = 11, - SC_SPEC_TYPE_INVOKER = 12, - SC_SPEC_TYPE_ADDRESS = 13, + SC_SPEC_TYPE_BOOL = 1, + SC_SPEC_TYPE_VOID = 2, + SC_SPEC_TYPE_STATUS = 3, + SC_SPEC_TYPE_U32 = 4, + SC_SPEC_TYPE_I32 = 5, + SC_SPEC_TYPE_U64 = 6, + SC_SPEC_TYPE_I64 = 7, + SC_SPEC_TYPE_TIMEPOINT = 8, + SC_SPEC_TYPE_DURATION = 9, + SC_SPEC_TYPE_U128 = 10, + SC_SPEC_TYPE_I128 = 11, + SC_SPEC_TYPE_U256 = 12, + SC_SPEC_TYPE_I256 = 13, + SC_SPEC_TYPE_BYTES = 14, + SC_SPEC_TYPE_STRING = 16, + SC_SPEC_TYPE_SYMBOL = 17, + SC_SPEC_TYPE_ADDRESS = 19, // Types with parameters. SC_SPEC_TYPE_OPTION = 1000, @@ -89,17 +93,22 @@ struct SCSpecTypeUDT union SCSpecTypeDef switch (SCSpecType type) { case SC_SPEC_TYPE_VAL: +case SC_SPEC_TYPE_BOOL: +case SC_SPEC_TYPE_VOID: +case SC_SPEC_TYPE_STATUS: +case SC_SPEC_TYPE_U32: +case SC_SPEC_TYPE_I32: case SC_SPEC_TYPE_U64: case SC_SPEC_TYPE_I64: +case SC_SPEC_TYPE_TIMEPOINT: +case SC_SPEC_TYPE_DURATION: case SC_SPEC_TYPE_U128: case SC_SPEC_TYPE_I128: -case SC_SPEC_TYPE_U32: -case SC_SPEC_TYPE_I32: -case SC_SPEC_TYPE_BOOL: -case SC_SPEC_TYPE_SYMBOL: -case SC_SPEC_TYPE_BITSET: -case SC_SPEC_TYPE_STATUS: +case SC_SPEC_TYPE_U256: +case SC_SPEC_TYPE_I256: case SC_SPEC_TYPE_BYTES: +case SC_SPEC_TYPE_STRING: +case SC_SPEC_TYPE_SYMBOL: case SC_SPEC_TYPE_ADDRESS: void; case SC_SPEC_TYPE_OPTION: diff --git a/xdr/Stellar-contract.x b/xdr/Stellar-contract.x index 6a0bc7ad36..66040e257e 100644 --- a/xdr/Stellar-contract.x +++ b/xdr/Stellar-contract.x @@ -5,67 +5,73 @@ % #include "xdr/Stellar-types.h" namespace stellar { -/* - * Smart Contracts deal in SCVals. These are a (dynamic) disjoint union - * between several possible variants, to allow storing generic SCVals in - * generic data structures and passing them in and out of languages that - * have simple or dynamic type systems. - * - * SCVals are (in WASM's case) stored in a tagged 64-bit word encoding. Most - * signed 64-bit values in Stellar are actually signed positive values - * (sequence numbers, timestamps, amounts), so we don't need the high bit - * and can get away with 1-bit tagging and store them as "unsigned 63bit", - * (u63) separate from everything else. - * - * We actually reserve the low _four_ bits, leaving 3 bits for 8 cases of - * "non-u63 values", some of which have substructure of their own. - * - * 0x_NNNN_NNNN_NNNN_NNNX - u63, for any even X - * 0x_0000_000N_NNNN_NNN1 - u32 - * 0x_0000_000N_NNNN_NNN3 - i32 - * 0x_NNNN_NNNN_NNNN_NNN5 - static: void, true, false, ... (SCS_*) - * 0x_IIII_IIII_TTTT_TTT7 - object: 32-bit index I, 28-bit type code T - * 0x_NNNN_NNNN_NNNN_NNN9 - symbol: up to 10 6-bit identifier characters - * 0x_NNNN_NNNN_NNNN_NNNb - bitset: up to 60 bits - * 0x_CCCC_CCCC_TTTT_TTTd - status: 32-bit code C, 28-bit type code T - * 0x_NNNN_NNNN_NNNN_NNNf - reserved - * - * Up here in XDR we have variable-length tagged disjoint unions but no - * bit-level packing, so we can be more explicit in their structure, at the - * cost of spending more than 64 bits to encode many cases, and also having - * to convert. It's a little non-obvious at the XDR level why there's a - * split between SCVal and SCObject given that they are both immutable types - * with value semantics; but the split reflects the split that happens in - * the implementation, and marks a place where different implementations of - * immutability (CoW, structural sharing, etc.) will likely occur. - */ - -// A symbol is up to 10 chars drawn from [a-zA-Z0-9_], which can be packed -// into 60 bits with a 6-bit-per-character code, usable as a small key type -// to specify function, argument, tx-local environment and map entries -// efficiently. -typedef string SCSymbol<10>; + +// We fix a maximum of 128 value types in the system for two reasons: we want to +// keep the codes relatively small (<= 8 bits) when bit-packing values into a +// u64 at the environment interface level, so that we keep many bits for +// payloads (small strings, small numeric values, object handles); and then we +// actually want to go one step further and ensure (for code-size) that our +// codes fit in a single ULEB128-code byte, which means we can only use 7 bits. +// +// We also reserve several type codes from this space because we want to _reuse_ +// the SCValType codes at the environment interface level (or at least not +// exceed its number-space) but there are more types at that level, assigned to +// optimizations/special case representations of values abstract at this level. enum SCValType { - SCV_U63 = 0, - SCV_U32 = 1, - SCV_I32 = 2, - SCV_STATIC = 3, - SCV_OBJECT = 4, - SCV_SYMBOL = 5, - SCV_BITSET = 6, - SCV_STATUS = 7 -}; + SCV_BOOL = 0, + SCV_VOID = 1, + SCV_STATUS = 2, -% struct SCObject; + // 32 bits is the smallest type in WASM or XDR; no need for u8/u16. + SCV_U32 = 3, + SCV_I32 = 4, -enum SCStatic -{ - SCS_VOID = 0, - SCS_TRUE = 1, - SCS_FALSE = 2, - SCS_LEDGER_KEY_CONTRACT_CODE = 3 + // 64 bits is naturally supported by both WASM and XDR also. + SCV_U64 = 5, + SCV_I64 = 6, + + // Time-related u64 subtypes with their own functions and formatting. + SCV_TIMEPOINT = 7, + SCV_DURATION = 8, + + // 128 bits is naturally supported by Rust and we use it for Soroban + // fixed-point arithmetic prices / balances / similar "quantities". These + // are represented in XDR as a pair of 2 u64s, unlike {u,i}256 which is + // represented as an array of 32 bytes. + SCV_U128 = 9, + SCV_I128 = 10, + + // 256 bits is the size of sha256 output, ed25519 keys, and the EVM machine + // word, so for interop use we include this even though it requires a small + // amount of Rust guest and/or host library code. + SCV_U256 = 11, + SCV_I256 = 12, + + // TODO: possibly allocate subtypes of i64, i128 and/or u256 for + // fixed-precision with a specific number of decimals. + + // Bytes come in 3 flavors, 2 of which have meaningfully different + // formatting and validity-checking / domain-restriction. + SCV_BYTES = 13, + SCV_STRING = 14, + SCV_SYMBOL = 15, + + // Vecs and maps are just polymorphic containers of other ScVals. + SCV_VEC = 16, + SCV_MAP = 17, + + // SCContractExecutable and SCAddressType are types that gets used separately from + // SCVal so we do not flatten their structures into separate SCVal cases. + SCV_CONTRACT_EXECUTABLE = 18, + SCV_ADDRESS = 19, + + // SCV_LEDGER_KEY_CONTRACT_EXECUTABLE and SCV_LEDGER_KEY_NONCE are unique + // symbolic SCVals used as the key for ledger entries for a contract's code + // and an address' nonce, respectively. + SCV_LEDGER_KEY_CONTRACT_EXECUTABLE = 20, + SCV_LEDGER_KEY_NONCE = 21 }; enum SCStatusType @@ -195,78 +201,28 @@ case SST_HOST_AUTH_ERROR: SCHostAuthErrorCode authCode; }; -union SCVal switch (SCValType type) -{ -case SCV_U63: - int64 u63; -case SCV_U32: - uint32 u32; -case SCV_I32: - int32 i32; -case SCV_STATIC: - SCStatic ic; -case SCV_OBJECT: - SCObject* obj; -case SCV_SYMBOL: - SCSymbol sym; -case SCV_BITSET: - uint64 bits; -case SCV_STATUS: - SCStatus status; -}; - -enum SCObjectType -{ - // We have a few objects that represent non-stellar-specific concepts - // like general-purpose maps, vectors, numbers, blobs. - - SCO_VEC = 0, - SCO_MAP = 1, - SCO_U64 = 2, - SCO_I64 = 3, - SCO_U128 = 4, - SCO_I128 = 5, - SCO_BYTES = 6, - SCO_CONTRACT_CODE = 7, - SCO_ADDRESS = 8, - SCO_NONCE_KEY = 9 - - // TODO: add more -}; - -struct SCMapEntry -{ - SCVal key; - SCVal val; +struct Int128Parts { + // Both signed and unsigned 128-bit ints + // are transported in a pair of uint64s + // to reduce the risk of sign-extension. + uint64 lo; + uint64 hi; }; -const SCVAL_LIMIT = 256000; - -typedef SCVal SCVec; -typedef SCMapEntry SCMap; - -enum SCContractCodeType +enum SCContractExecutableType { - SCCONTRACT_CODE_WASM_REF = 0, - SCCONTRACT_CODE_TOKEN = 1 + SCCONTRACT_EXECUTABLE_WASM_REF = 0, + SCCONTRACT_EXECUTABLE_TOKEN = 1 }; -union SCContractCode switch (SCContractCodeType type) +union SCContractExecutable switch (SCContractExecutableType type) { -case SCCONTRACT_CODE_WASM_REF: +case SCCONTRACT_EXECUTABLE_WASM_REF: Hash wasm_id; -case SCCONTRACT_CODE_TOKEN: +case SCCONTRACT_EXECUTABLE_TOKEN: void; }; -struct Int128Parts { - // Both signed and unsigned 128-bit ints - // are transported in a pair of uint64s - // to reduce the risk of sign-extension. - uint64 lo; - uint64 hi; -}; - enum SCAddressType { SC_ADDRESS_TYPE_ACCOUNT = 0, @@ -281,27 +237,88 @@ case SC_ADDRESS_TYPE_CONTRACT: Hash contractId; }; -union SCObject switch (SCObjectType type) +%struct SCVal; +%struct SCMapEntry; + +const SCVAL_LIMIT = 256000; +const SCSYMBOL_LIMIT = 32; + +typedef SCVal SCVec; +typedef SCMapEntry SCMap; + +typedef opaque SCBytes; +typedef string SCString; +typedef string SCSymbol; + +struct SCNonceKey { + SCAddress nonce_address; +}; + +union SCVal switch (SCValType type) { -case SCO_VEC: - SCVec vec; -case SCO_MAP: - SCMap map; -case SCO_U64: + +case SCV_BOOL: + bool b; +case SCV_VOID: + void; +case SCV_STATUS: + SCStatus error; + +case SCV_U32: + uint32 u32; +case SCV_I32: + int32 i32; + +case SCV_U64: uint64 u64; -case SCO_I64: +case SCV_I64: int64 i64; -case SCO_U128: +case SCV_TIMEPOINT: + TimePoint timepoint; +case SCV_DURATION: + Duration duration; + +case SCV_U128: Int128Parts u128; -case SCO_I128: +case SCV_I128: Int128Parts i128; -case SCO_BYTES: - opaque bin; -case SCO_CONTRACT_CODE: - SCContractCode contractCode; -case SCO_ADDRESS: + +case SCV_U256: + uint256 u256; +case SCV_I256: + uint256 i256; + +case SCV_BYTES: + SCBytes bytes; +case SCV_STRING: + SCString str; +case SCV_SYMBOL: + SCSymbol sym; + +// Vec and Map are recursive so need to live +// behind an option, due to xdrpp limitations. +case SCV_VEC: + SCVec *vec; +case SCV_MAP: + SCMap *map; + +case SCV_CONTRACT_EXECUTABLE: + SCContractExecutable exec; +case SCV_ADDRESS: SCAddress address; -case SCO_NONCE_KEY: - SCAddress nonceAddress; + +// Special SCVals reserved for system-constructed contract-data +// ledger keys, not generally usable elsewhere. +case SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: + void; +case SCV_LEDGER_KEY_NONCE: + SCNonceKey nonce_key; +}; + +struct SCMapEntry +{ + SCVal key; + SCVal val; }; + } diff --git a/xdr/Stellar-ledger-entries.x b/xdr/Stellar-ledger-entries.x index 55bdfe80c4..d8f1b737fe 100644 --- a/xdr/Stellar-ledger-entries.x +++ b/xdr/Stellar-ledger-entries.x @@ -12,8 +12,6 @@ typedef opaque Thresholds[4]; typedef string string32<32>; typedef string string64<64>; typedef int64 SequenceNumber; -typedef uint64 TimePoint; -typedef uint64 Duration; typedef opaque DataValue<64>; typedef Hash PoolID; // SHA256(LiquidityPoolParameters) diff --git a/xdr/Stellar-ledger.x b/xdr/Stellar-ledger.x index eaf1e89be6..1563fb9a0f 100644 --- a/xdr/Stellar-ledger.x +++ b/xdr/Stellar-ledger.x @@ -388,7 +388,8 @@ struct TransactionMetaV2 enum ContractEventType { SYSTEM = 0, - CONTRACT = 1 + CONTRACT = 1, + DIAGNOSTIC = 2 }; struct ContractEvent @@ -412,6 +413,17 @@ struct ContractEvent body; }; +struct DiagnosticEvent +{ + bool inSuccessfulContractCall; + ContractEvent event; +}; + +struct OperationDiagnosticEvents +{ + DiagnosticEvent events<>; +}; + struct OperationEvents { ContractEvent events<>; @@ -430,6 +442,11 @@ struct TransactionMetaV3 Hash hashes[3]; // stores sha256(txChangesBefore, operations, txChangesAfter), // sha256(events), and sha256(txResult) + + // Diagnostics events that are not hashed. One list per operation. + // This will contain all contract and diagnostic events. Even ones + // that were emitted in a failed contract call. + OperationDiagnosticEvents diagnosticEvents<>; }; // this is the meta produced when applying transactions diff --git a/xdr/Stellar-transaction.x b/xdr/Stellar-transaction.x index 3c98faa545..2b0b05872e 100644 --- a/xdr/Stellar-transaction.x +++ b/xdr/Stellar-transaction.x @@ -517,7 +517,7 @@ case CONTRACT_ID_FROM_ASSET: struct CreateContractArgs { ContractID contractID; - SCContractCode source; + SCContractExecutable source; }; union HostFunction switch (HostFunctionType type) @@ -675,7 +675,7 @@ case ENVELOPE_TYPE_CREATE_CONTRACT_ARGS: struct { Hash networkID; - SCContractCode source; + SCContractExecutable source; uint256 salt; } createContractArgs; case ENVELOPE_TYPE_CONTRACT_AUTH: diff --git a/xdr/Stellar-types.x b/xdr/Stellar-types.x index a6f9bf9c99..d71bf0d49d 100644 --- a/xdr/Stellar-types.x +++ b/xdr/Stellar-types.x @@ -14,6 +14,9 @@ typedef int int32; typedef unsigned hyper uint64; typedef hyper int64; +typedef uint64 TimePoint; +typedef uint64 Duration; + // An ExtensionPoint is always marshaled as a 32-bit 0 value. At a // later point, it can be replaced by a different union so as to // extend a structure. diff --git a/xdr/scval.go b/xdr/scval.go index 0758445d3f..97e2380853 100644 --- a/xdr/scval.go +++ b/xdr/scval.go @@ -7,10 +7,6 @@ import ( "github.com/stellar/go/strkey" ) -func (s Int128Parts) Equals(o Int128Parts) bool { - return s.Lo == o.Lo && s.Hi == o.Hi -} - func (address ScAddress) String() (string, error) { var result string var err error @@ -20,8 +16,8 @@ func (address ScAddress) String() (string, error) { pubkey := address.MustAccountId().Ed25519 result, err = strkey.Encode(strkey.VersionByteAccountID, pubkey[:]) case ScAddressTypeScAddressTypeContract: - contractId := *address.ContractId - result, err = strkey.Encode(strkey.VersionByteContract, contractId[:]) + contractID := *address.ContractId + result, err = strkey.Encode(strkey.VersionByteContract, contractID[:]) default: return "", fmt.Errorf("unfamiliar address type: %v", address.Type) } @@ -33,79 +29,17 @@ func (address ScAddress) String() (string, error) { return result, nil } -func (s ScContractCode) Equals(o ScContractCode) bool { +func (s ScContractExecutable) Equals(o ScContractExecutable) bool { if s.Type != o.Type { return false } switch s.Type { - case ScContractCodeTypeSccontractCodeToken: + case ScContractExecutableTypeSccontractExecutableToken: return true - case ScContractCodeTypeSccontractCodeWasmRef: + case ScContractExecutableTypeSccontractExecutableWasmRef: return s.MustWasmId().Equals(o.MustWasmId()) default: - panic("unknown ScContractCode type: " + s.Type.String()) - } -} - -func (s *ScObject) Equals(o *ScObject) bool { - if (s == nil) != (o == nil) { - return false - } - if s == nil { - return true - } - if s.Type != o.Type { - return false - } - - switch s.Type { - case ScObjectTypeScoI64: - return s.MustI64() == o.MustI64() - case ScObjectTypeScoContractCode: - return s.MustContractCode().Equals(o.MustContractCode()) - case ScObjectTypeScoU128: - return s.MustU128().Equals(o.MustU128()) - case ScObjectTypeScoI128: - return s.MustI128().Equals(o.MustI128()) - case ScObjectTypeScoBytes: - return bytes.Equal(s.MustBin(), o.MustBin()) - case ScObjectTypeScoMap: - myMap := s.MustMap() - otherMap := o.MustMap() - if len(myMap) != len(otherMap) { - return false - } - for i := range myMap { - if !myMap[i].Key.Equals(otherMap[i].Key) || - !myMap[i].Val.Equals(otherMap[i].Val) { - return false - } - } - return true - case ScObjectTypeScoU64: - return s.MustU64() == o.MustU64() - case ScObjectTypeScoVec: - myVec := s.MustVec() - otherVec := o.MustVec() - if len(myVec) != len(otherVec) { - return false - } - for i := range myVec { - if !myVec[i].Equals(otherVec[i]) { - return false - } - } - return true - case ScObjectTypeScoAddress: - myAddr := s.MustAddress() - otherAddr := o.MustAddress() - return myAddr.Equals(otherAddr) - case ScObjectTypeScoNonceKey: - myAddr := s.MustNonceAddress() - otherAddr := o.MustNonceAddress() - return myAddr.Equals(otherAddr) - default: - panic("unknown ScObject type: " + s.Type.String()) + panic("unknown ScContractExecutable type: " + s.Type.String()) } } @@ -146,27 +80,59 @@ func (s ScVal) Equals(o ScVal) bool { } switch s.Type { - case ScValTypeScvObject: - return s.MustObj().Equals(o.MustObj()) - case ScValTypeScvBitset: - return s.MustBits() == o.MustBits() - case ScValTypeScvStatic: - return s.MustIc() == o.MustIc() + case ScValTypeScvBool: + return s.MustB() == o.MustB() + case ScValTypeScvVoid: + return true case ScValTypeScvStatus: - return s.MustStatus().Equals(o.MustStatus()) - case ScValTypeScvSymbol: - return s.MustSym() == o.MustSym() - case ScValTypeScvI32: - return s.MustI32() == o.MustI32() + return s.MustError().Equals(o.MustError()) case ScValTypeScvU32: return s.MustU32() == o.MustU32() - case ScValTypeScvU63: - return s.MustU63() == o.MustU63() + case ScValTypeScvI32: + return s.MustI32() == o.MustI32() + case ScValTypeScvU64: + return s.MustU64() == o.MustU64() + case ScValTypeScvI64: + return s.MustI64() == o.MustI64() + case ScValTypeScvTimepoint: + return s.MustTimepoint() == o.MustTimepoint() + case ScValTypeScvDuration: + return s.MustDuration() == o.MustDuration() + case ScValTypeScvU128: + return s.MustU128() == o.MustU128() + case ScValTypeScvI128: + return s.MustI128() == o.MustI128() + case ScValTypeScvU256: + return s.MustU256() == o.MustU256() + case ScValTypeScvI256: + return s.MustI256() == o.MustI256() + case ScValTypeScvBytes: + return s.MustBytes().Equals(o.MustBytes()) + case ScValTypeScvString: + return s.MustStr() == o.MustStr() + case ScValTypeScvSymbol: + return s.MustSym() == o.MustSym() + case ScValTypeScvVec: + return s.MustVec().Equals(o.MustVec()) + case ScValTypeScvMap: + return s.MustMap().Equals(o.MustMap()) + case ScValTypeScvContractExecutable: + return s.MustExec().Equals(o.MustExec()) + case ScValTypeScvAddress: + return s.MustAddress().Equals(o.MustAddress()) + case ScValTypeScvLedgerKeyContractExecutable: + return true + case ScValTypeScvLedgerKeyNonce: + return s.MustNonceKey().Equals(o.MustNonceKey()) default: panic("unknown ScVal type: " + s.Type.String()) } } +func (s ScBytes) Equals(o ScBytes) bool { + return bytes.Equal([]byte(s), []byte(o)) +} + func (s ScAddress) Equals(o ScAddress) bool { if s.Type != o.Type { return false @@ -185,6 +151,49 @@ func (s ScAddress) Equals(o ScAddress) bool { // IsBool returns true if the given ScVal is a boolean func (s ScVal) IsBool() bool { - ic, ok := s.GetIc() - return ok && (ic == ScStaticScsTrue || ic == ScStaticScsFalse) + return s.Type == ScValTypeScvBool +} + +func (s *ScVec) Equals(o *ScVec) bool { + if s == nil && o == nil { + return true + } + if s == nil || o == nil { + return false + } + if len(*s) != len(*o) { + return false + } + for i := range *s { + if !(*s)[i].Equals((*o)[i]) { + return false + } + } + return true +} + +func (s *ScMap) Equals(o *ScMap) bool { + if s == nil && o == nil { + return true + } + if s == nil || o == nil { + return false + } + if len(*s) != len(*o) { + return false + } + for i, entry := range *s { + if !entry.Equals((*o)[i]) { + return false + } + } + return true +} + +func (s ScMapEntry) Equals(o ScMapEntry) bool { + return s.Key.Equals(o.Key) && s.Val.Equals(o.Val) +} + +func (s ScNonceKey) Equals(o ScNonceKey) bool { + return s.NonceAddress.Equals(o.NonceAddress) } diff --git a/xdr/scval_test.go b/xdr/scval_test.go index f237c42884..812a12942b 100644 --- a/xdr/scval_test.go +++ b/xdr/scval_test.go @@ -23,6 +23,6 @@ func TestScValEqualsCoverage(t *testing.T) { clonedScVal := ScVal{} assert.NoError(t, gxdr.Convert(shape, &clonedScVal)) - assert.True(t, scVal.Equals(clonedScVal)) + assert.True(t, scVal.Equals(clonedScVal), "scVal: %#v, clonedScVal: %#v", scVal, clonedScVal) } } diff --git a/xdr/xdr_generated.go b/xdr/xdr_generated.go index 2fb18d9101..4feb1150c7 100644 --- a/xdr/xdr_generated.go +++ b/xdr/xdr_generated.go @@ -30,14 +30,14 @@ import ( var XdrFilesSHA256 = map[string]string{ "xdr/Stellar-SCP.x": "8f32b04d008f8bc33b8843d075e69837231a673691ee41d8b821ca229a6e802a", "xdr/Stellar-contract-env-meta.x": "928a30de814ee589bc1d2aadd8dd81c39f71b7e6f430f56974505ccb1f49654b", - "xdr/Stellar-contract-spec.x": "83f5adc57ccaea49a67063352b869641049c4caf198a3070c4825c5f6e82802a", - "xdr/Stellar-contract.x": "99696979513d389fabe843874b84dd75a7fec8f8f329ca9ae833c600850dee2d", + "xdr/Stellar-contract-spec.x": "6268629577238adf6210d6e919e41375a3b380e941d0c7acb662013c6f8aa575", + "xdr/Stellar-contract.x": "7ec20def7e005a7d90357ac7b39d616435ab5835dc806989515faecdb506f51d", "xdr/Stellar-internal.x": "368706dd6e2efafd16a8f63daf3374845b791d097b15c502aa7653a412b68b68", - "xdr/Stellar-ledger-entries.x": "dae8eead47f2ce6b74b87fc196080cde2b432eedba9e58893f1d5ad315155e4e", - "xdr/Stellar-ledger.x": "b19c10a07c9775594723ad12927259dd4bbd9ed9dfd0e70078662ec2e90e130d", + "xdr/Stellar-ledger-entries.x": "40ea6015526933dfa49a459b62e1f0f1fbd950ef95949f7faabec4b89d5a9241", + "xdr/Stellar-ledger.x": "968fff69d58c70dbd27edf4635c4d7f99f7667981076ce29548e6ef289de3df5", "xdr/Stellar-overlay.x": "972f38a9d4a064273f3362cbfa7d3c563293fd5396d5f0774ce6cc690e27645d", - "xdr/Stellar-transaction.x": "0ab9890a6ffbe3a7f0b4496f7f531606812c1207b862a0a7bc03b70e83dbdf72", - "xdr/Stellar-types.x": "7b3e5470c4bcf7c19f9cc8f8bf81a494b540fc2157476329cf19863afab2343b", + "xdr/Stellar-transaction.x": "4fee5c1982810aa1746dbaf81dd6d84f1fe8193cb535bf0839da3509e7907547", + "xdr/Stellar-types.x": "6e3b13f0d3e360b09fa5e2b0e55d43f4d974a769df66afb34e8aecbb329d3f15", } type xdrType interface { @@ -1558,116 +1558,6 @@ func (s SequenceNumber) xdrType() {} var _ xdrType = (*SequenceNumber)(nil) -// TimePoint is an XDR Typedef defines as: -// -// typedef uint64 TimePoint; -type TimePoint Uint64 - -// EncodeTo encodes this value using the Encoder. -func (s TimePoint) EncodeTo(e *xdr.Encoder) error { - var err error - if err = Uint64(s).EncodeTo(e); err != nil { - return err - } - return nil -} - -var _ decoderFrom = (*TimePoint)(nil) - -// DecodeFrom decodes this value using the Decoder. -func (s *TimePoint) DecodeFrom(d *xdr.Decoder) (int, error) { - var err error - var n, nTmp int - nTmp, err = (*Uint64)(s).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding Uint64: %s", err) - } - return n, nil -} - -// MarshalBinary implements encoding.BinaryMarshaler. -func (s TimePoint) MarshalBinary() ([]byte, error) { - b := bytes.Buffer{} - e := xdr.NewEncoder(&b) - err := s.EncodeTo(e) - return b.Bytes(), err -} - -// UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *TimePoint) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - d := xdr.NewDecoder(r) - _, err := s.DecodeFrom(d) - return err -} - -var ( - _ encoding.BinaryMarshaler = (*TimePoint)(nil) - _ encoding.BinaryUnmarshaler = (*TimePoint)(nil) -) - -// xdrType signals that this type is an type representing -// representing XDR values defined by this package. -func (s TimePoint) xdrType() {} - -var _ xdrType = (*TimePoint)(nil) - -// Duration is an XDR Typedef defines as: -// -// typedef uint64 Duration; -type Duration Uint64 - -// EncodeTo encodes this value using the Encoder. -func (s Duration) EncodeTo(e *xdr.Encoder) error { - var err error - if err = Uint64(s).EncodeTo(e); err != nil { - return err - } - return nil -} - -var _ decoderFrom = (*Duration)(nil) - -// DecodeFrom decodes this value using the Decoder. -func (s *Duration) DecodeFrom(d *xdr.Decoder) (int, error) { - var err error - var n, nTmp int - nTmp, err = (*Uint64)(s).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding Uint64: %s", err) - } - return n, nil -} - -// MarshalBinary implements encoding.BinaryMarshaler. -func (s Duration) MarshalBinary() ([]byte, error) { - b := bytes.Buffer{} - e := xdr.NewEncoder(&b) - err := s.EncodeTo(e) - return b.Bytes(), err -} - -// UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *Duration) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - d := xdr.NewDecoder(r) - _, err := s.DecodeFrom(d) - return err -} - -var ( - _ encoding.BinaryMarshaler = (*Duration)(nil) - _ encoding.BinaryUnmarshaler = (*Duration)(nil) -) - -// xdrType signals that this type is an type representing -// representing XDR values defined by this package. -func (s Duration) xdrType() {} - -var _ xdrType = (*Duration)(nil) - // DataValue is an XDR Typedef defines as: // // typedef opaque DataValue<64>; @@ -15560,18 +15450,21 @@ var _ xdrType = (*TransactionMetaV2)(nil) // enum ContractEventType // { // SYSTEM = 0, -// CONTRACT = 1 +// CONTRACT = 1, +// DIAGNOSTIC = 2 // }; type ContractEventType int32 const ( - ContractEventTypeSystem ContractEventType = 0 - ContractEventTypeContract ContractEventType = 1 + ContractEventTypeSystem ContractEventType = 0 + ContractEventTypeContract ContractEventType = 1 + ContractEventTypeDiagnostic ContractEventType = 2 ) var contractEventTypeMap = map[int32]string{ 0: "ContractEventTypeSystem", 1: "ContractEventTypeContract", + 2: "ContractEventTypeDiagnostic", } // ValidEnum validates a proposed value for this enum. Implements @@ -15965,6 +15858,153 @@ func (s ContractEvent) xdrType() {} var _ xdrType = (*ContractEvent)(nil) +// DiagnosticEvent is an XDR Struct defines as: +// +// struct DiagnosticEvent +// { +// bool inSuccessfulContractCall; +// ContractEvent event; +// }; +type DiagnosticEvent struct { + InSuccessfulContractCall bool + Event ContractEvent +} + +// EncodeTo encodes this value using the Encoder. +func (s *DiagnosticEvent) EncodeTo(e *xdr.Encoder) error { + var err error + if _, err = e.EncodeBool(bool(s.InSuccessfulContractCall)); err != nil { + return err + } + if err = s.Event.EncodeTo(e); err != nil { + return err + } + return nil +} + +var _ decoderFrom = (*DiagnosticEvent)(nil) + +// DecodeFrom decodes this value using the Decoder. +func (s *DiagnosticEvent) DecodeFrom(d *xdr.Decoder) (int, error) { + var err error + var n, nTmp int + s.InSuccessfulContractCall, nTmp, err = d.DecodeBool() + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding Bool: %s", err) + } + nTmp, err = s.Event.DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding ContractEvent: %s", err) + } + return n, nil +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s DiagnosticEvent) MarshalBinary() ([]byte, error) { + b := bytes.Buffer{} + e := xdr.NewEncoder(&b) + err := s.EncodeTo(e) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *DiagnosticEvent) UnmarshalBinary(inp []byte) error { + r := bytes.NewReader(inp) + d := xdr.NewDecoder(r) + _, err := s.DecodeFrom(d) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*DiagnosticEvent)(nil) + _ encoding.BinaryUnmarshaler = (*DiagnosticEvent)(nil) +) + +// xdrType signals that this type is an type representing +// representing XDR values defined by this package. +func (s DiagnosticEvent) xdrType() {} + +var _ xdrType = (*DiagnosticEvent)(nil) + +// OperationDiagnosticEvents is an XDR Struct defines as: +// +// struct OperationDiagnosticEvents +// { +// DiagnosticEvent events<>; +// }; +type OperationDiagnosticEvents struct { + Events []DiagnosticEvent +} + +// EncodeTo encodes this value using the Encoder. +func (s *OperationDiagnosticEvents) EncodeTo(e *xdr.Encoder) error { + var err error + if _, err = e.EncodeUint(uint32(len(s.Events))); err != nil { + return err + } + for i := 0; i < len(s.Events); i++ { + if err = s.Events[i].EncodeTo(e); err != nil { + return err + } + } + return nil +} + +var _ decoderFrom = (*OperationDiagnosticEvents)(nil) + +// DecodeFrom decodes this value using the Decoder. +func (s *OperationDiagnosticEvents) DecodeFrom(d *xdr.Decoder) (int, error) { + var err error + var n, nTmp int + var l uint32 + l, nTmp, err = d.DecodeUint() + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding DiagnosticEvent: %s", err) + } + s.Events = nil + if l > 0 { + s.Events = make([]DiagnosticEvent, l) + for i := uint32(0); i < l; i++ { + nTmp, err = s.Events[i].DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding DiagnosticEvent: %s", err) + } + } + } + return n, nil +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s OperationDiagnosticEvents) MarshalBinary() ([]byte, error) { + b := bytes.Buffer{} + e := xdr.NewEncoder(&b) + err := s.EncodeTo(e) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *OperationDiagnosticEvents) UnmarshalBinary(inp []byte) error { + r := bytes.NewReader(inp) + d := xdr.NewDecoder(r) + _, err := s.DecodeFrom(d) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*OperationDiagnosticEvents)(nil) + _ encoding.BinaryUnmarshaler = (*OperationDiagnosticEvents)(nil) +) + +// xdrType signals that this type is an type representing +// representing XDR values defined by this package. +func (s OperationDiagnosticEvents) xdrType() {} + +var _ xdrType = (*OperationDiagnosticEvents)(nil) + // OperationEvents is an XDR Struct defines as: // // struct OperationEvents @@ -16057,14 +16097,20 @@ var _ xdrType = (*OperationEvents)(nil) // // Hash hashes[3]; // stores sha256(txChangesBefore, operations, txChangesAfter), // // sha256(events), and sha256(txResult) +// +// // Diagnostics events that are not hashed. One list per operation. +// // This will contain all contract and diagnostic events. Even ones +// // that were emitted in a failed contract call. +// OperationDiagnosticEvents diagnosticEvents<>; // }; type TransactionMetaV3 struct { - TxChangesBefore LedgerEntryChanges - Operations []OperationMeta - TxChangesAfter LedgerEntryChanges - Events []OperationEvents - TxResult TransactionResult - Hashes [3]Hash + TxChangesBefore LedgerEntryChanges + Operations []OperationMeta + TxChangesAfter LedgerEntryChanges + Events []OperationEvents + TxResult TransactionResult + Hashes [3]Hash + DiagnosticEvents []OperationDiagnosticEvents } // EncodeTo encodes this value using the Encoder. @@ -16100,6 +16146,14 @@ func (s *TransactionMetaV3) EncodeTo(e *xdr.Encoder) error { return err } } + if _, err = e.EncodeUint(uint32(len(s.DiagnosticEvents))); err != nil { + return err + } + for i := 0; i < len(s.DiagnosticEvents); i++ { + if err = s.DiagnosticEvents[i].EncodeTo(e); err != nil { + return err + } + } return nil } @@ -16164,6 +16218,22 @@ func (s *TransactionMetaV3) DecodeFrom(d *xdr.Decoder) (int, error) { return n, fmt.Errorf("decoding Hash: %s", err) } } + l, nTmp, err = d.DecodeUint() + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding OperationDiagnosticEvents: %s", err) + } + s.DiagnosticEvents = nil + if l > 0 { + s.DiagnosticEvents = make([]OperationDiagnosticEvents, l) + for i := uint32(0); i < l; i++ { + nTmp, err = s.DiagnosticEvents[i].DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding OperationDiagnosticEvents: %s", err) + } + } + } return n, nil } @@ -25163,11 +25233,11 @@ var _ xdrType = (*ContractId)(nil) // struct CreateContractArgs // { // ContractID contractID; -// SCContractCode source; +// SCContractExecutable source; // }; type CreateContractArgs struct { ContractId ContractId - Source ScContractCode + Source ScContractExecutable } // EncodeTo encodes this value using the Encoder. @@ -25196,7 +25266,7 @@ func (s *CreateContractArgs) DecodeFrom(d *xdr.Decoder) (int, error) { nTmp, err = s.Source.DecodeFrom(d) n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScContractCode: %s", err) + return n, fmt.Errorf("decoding ScContractExecutable: %s", err) } return n, nil } @@ -27732,12 +27802,12 @@ var _ xdrType = (*HashIdPreimageSourceAccountContractId)(nil) // struct // { // Hash networkID; -// SCContractCode source; +// SCContractExecutable source; // uint256 salt; // } type HashIdPreimageCreateContractArgs struct { NetworkId Hash - Source ScContractCode + Source ScContractExecutable Salt Uint256 } @@ -27770,7 +27840,7 @@ func (s *HashIdPreimageCreateContractArgs) DecodeFrom(d *xdr.Decoder) (int, erro nTmp, err = s.Source.DecodeFrom(d) n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScContractCode: %s", err) + return n, fmt.Errorf("decoding ScContractExecutable: %s", err) } nTmp, err = s.Salt.DecodeFrom(d) n += nTmp @@ -27938,7 +28008,7 @@ var _ xdrType = (*HashIdPreimageContractAuth)(nil) // struct // { // Hash networkID; -// SCContractCode source; +// SCContractExecutable source; // uint256 salt; // } createContractArgs; // case ENVELOPE_TYPE_CONTRACT_AUTH: @@ -42601,6 +42671,116 @@ func (s Int64) xdrType() {} var _ xdrType = (*Int64)(nil) +// TimePoint is an XDR Typedef defines as: +// +// typedef uint64 TimePoint; +type TimePoint Uint64 + +// EncodeTo encodes this value using the Encoder. +func (s TimePoint) EncodeTo(e *xdr.Encoder) error { + var err error + if err = Uint64(s).EncodeTo(e); err != nil { + return err + } + return nil +} + +var _ decoderFrom = (*TimePoint)(nil) + +// DecodeFrom decodes this value using the Decoder. +func (s *TimePoint) DecodeFrom(d *xdr.Decoder) (int, error) { + var err error + var n, nTmp int + nTmp, err = (*Uint64)(s).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding Uint64: %s", err) + } + return n, nil +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s TimePoint) MarshalBinary() ([]byte, error) { + b := bytes.Buffer{} + e := xdr.NewEncoder(&b) + err := s.EncodeTo(e) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *TimePoint) UnmarshalBinary(inp []byte) error { + r := bytes.NewReader(inp) + d := xdr.NewDecoder(r) + _, err := s.DecodeFrom(d) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*TimePoint)(nil) + _ encoding.BinaryUnmarshaler = (*TimePoint)(nil) +) + +// xdrType signals that this type is an type representing +// representing XDR values defined by this package. +func (s TimePoint) xdrType() {} + +var _ xdrType = (*TimePoint)(nil) + +// Duration is an XDR Typedef defines as: +// +// typedef uint64 Duration; +type Duration Uint64 + +// EncodeTo encodes this value using the Encoder. +func (s Duration) EncodeTo(e *xdr.Encoder) error { + var err error + if err = Uint64(s).EncodeTo(e); err != nil { + return err + } + return nil +} + +var _ decoderFrom = (*Duration)(nil) + +// DecodeFrom decodes this value using the Decoder. +func (s *Duration) DecodeFrom(d *xdr.Decoder) (int, error) { + var err error + var n, nTmp int + nTmp, err = (*Uint64)(s).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding Uint64: %s", err) + } + return n, nil +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s Duration) MarshalBinary() ([]byte, error) { + b := bytes.Buffer{} + e := xdr.NewEncoder(&b) + err := s.EncodeTo(e) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *Duration) UnmarshalBinary(inp []byte) error { + r := bytes.NewReader(inp) + d := xdr.NewDecoder(r) + _, err := s.DecodeFrom(d) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*Duration)(nil) + _ encoding.BinaryUnmarshaler = (*Duration)(nil) +) + +// xdrType signals that this type is an type representing +// representing XDR values defined by this package. +func (s Duration) xdrType() {} + +var _ xdrType = (*Duration)(nil) + // ExtensionPoint is an XDR Union defines as: // // union ExtensionPoint switch (int v) @@ -44220,19 +44400,23 @@ const ScSpecDocLimit = 1024 // SC_SPEC_TYPE_VAL = 0, // // // Types with no parameters. -// SC_SPEC_TYPE_U32 = 1, -// SC_SPEC_TYPE_I32 = 2, -// SC_SPEC_TYPE_U64 = 3, -// SC_SPEC_TYPE_I64 = 4, -// SC_SPEC_TYPE_U128 = 5, -// SC_SPEC_TYPE_I128 = 6, -// SC_SPEC_TYPE_BOOL = 7, -// SC_SPEC_TYPE_SYMBOL = 8, -// SC_SPEC_TYPE_BITSET = 9, -// SC_SPEC_TYPE_STATUS = 10, -// SC_SPEC_TYPE_BYTES = 11, -// SC_SPEC_TYPE_INVOKER = 12, -// SC_SPEC_TYPE_ADDRESS = 13, +// SC_SPEC_TYPE_BOOL = 1, +// SC_SPEC_TYPE_VOID = 2, +// SC_SPEC_TYPE_STATUS = 3, +// SC_SPEC_TYPE_U32 = 4, +// SC_SPEC_TYPE_I32 = 5, +// SC_SPEC_TYPE_U64 = 6, +// SC_SPEC_TYPE_I64 = 7, +// SC_SPEC_TYPE_TIMEPOINT = 8, +// SC_SPEC_TYPE_DURATION = 9, +// SC_SPEC_TYPE_U128 = 10, +// SC_SPEC_TYPE_I128 = 11, +// SC_SPEC_TYPE_U256 = 12, +// SC_SPEC_TYPE_I256 = 13, +// SC_SPEC_TYPE_BYTES = 14, +// SC_SPEC_TYPE_STRING = 16, +// SC_SPEC_TYPE_SYMBOL = 17, +// SC_SPEC_TYPE_ADDRESS = 19, // // // Types with parameters. // SC_SPEC_TYPE_OPTION = 1000, @@ -44249,45 +44433,53 @@ const ScSpecDocLimit = 1024 type ScSpecType int32 const ( - ScSpecTypeScSpecTypeVal ScSpecType = 0 - ScSpecTypeScSpecTypeU32 ScSpecType = 1 - ScSpecTypeScSpecTypeI32 ScSpecType = 2 - ScSpecTypeScSpecTypeU64 ScSpecType = 3 - ScSpecTypeScSpecTypeI64 ScSpecType = 4 - ScSpecTypeScSpecTypeU128 ScSpecType = 5 - ScSpecTypeScSpecTypeI128 ScSpecType = 6 - ScSpecTypeScSpecTypeBool ScSpecType = 7 - ScSpecTypeScSpecTypeSymbol ScSpecType = 8 - ScSpecTypeScSpecTypeBitset ScSpecType = 9 - ScSpecTypeScSpecTypeStatus ScSpecType = 10 - ScSpecTypeScSpecTypeBytes ScSpecType = 11 - ScSpecTypeScSpecTypeInvoker ScSpecType = 12 - ScSpecTypeScSpecTypeAddress ScSpecType = 13 - ScSpecTypeScSpecTypeOption ScSpecType = 1000 - ScSpecTypeScSpecTypeResult ScSpecType = 1001 - ScSpecTypeScSpecTypeVec ScSpecType = 1002 - ScSpecTypeScSpecTypeSet ScSpecType = 1003 - ScSpecTypeScSpecTypeMap ScSpecType = 1004 - ScSpecTypeScSpecTypeTuple ScSpecType = 1005 - ScSpecTypeScSpecTypeBytesN ScSpecType = 1006 - ScSpecTypeScSpecTypeUdt ScSpecType = 2000 + ScSpecTypeScSpecTypeVal ScSpecType = 0 + ScSpecTypeScSpecTypeBool ScSpecType = 1 + ScSpecTypeScSpecTypeVoid ScSpecType = 2 + ScSpecTypeScSpecTypeStatus ScSpecType = 3 + ScSpecTypeScSpecTypeU32 ScSpecType = 4 + ScSpecTypeScSpecTypeI32 ScSpecType = 5 + ScSpecTypeScSpecTypeU64 ScSpecType = 6 + ScSpecTypeScSpecTypeI64 ScSpecType = 7 + ScSpecTypeScSpecTypeTimepoint ScSpecType = 8 + ScSpecTypeScSpecTypeDuration ScSpecType = 9 + ScSpecTypeScSpecTypeU128 ScSpecType = 10 + ScSpecTypeScSpecTypeI128 ScSpecType = 11 + ScSpecTypeScSpecTypeU256 ScSpecType = 12 + ScSpecTypeScSpecTypeI256 ScSpecType = 13 + ScSpecTypeScSpecTypeBytes ScSpecType = 14 + ScSpecTypeScSpecTypeString ScSpecType = 16 + ScSpecTypeScSpecTypeSymbol ScSpecType = 17 + ScSpecTypeScSpecTypeAddress ScSpecType = 19 + ScSpecTypeScSpecTypeOption ScSpecType = 1000 + ScSpecTypeScSpecTypeResult ScSpecType = 1001 + ScSpecTypeScSpecTypeVec ScSpecType = 1002 + ScSpecTypeScSpecTypeSet ScSpecType = 1003 + ScSpecTypeScSpecTypeMap ScSpecType = 1004 + ScSpecTypeScSpecTypeTuple ScSpecType = 1005 + ScSpecTypeScSpecTypeBytesN ScSpecType = 1006 + ScSpecTypeScSpecTypeUdt ScSpecType = 2000 ) var scSpecTypeMap = map[int32]string{ 0: "ScSpecTypeScSpecTypeVal", - 1: "ScSpecTypeScSpecTypeU32", - 2: "ScSpecTypeScSpecTypeI32", - 3: "ScSpecTypeScSpecTypeU64", - 4: "ScSpecTypeScSpecTypeI64", - 5: "ScSpecTypeScSpecTypeU128", - 6: "ScSpecTypeScSpecTypeI128", - 7: "ScSpecTypeScSpecTypeBool", - 8: "ScSpecTypeScSpecTypeSymbol", - 9: "ScSpecTypeScSpecTypeBitset", - 10: "ScSpecTypeScSpecTypeStatus", - 11: "ScSpecTypeScSpecTypeBytes", - 12: "ScSpecTypeScSpecTypeInvoker", - 13: "ScSpecTypeScSpecTypeAddress", + 1: "ScSpecTypeScSpecTypeBool", + 2: "ScSpecTypeScSpecTypeVoid", + 3: "ScSpecTypeScSpecTypeStatus", + 4: "ScSpecTypeScSpecTypeU32", + 5: "ScSpecTypeScSpecTypeI32", + 6: "ScSpecTypeScSpecTypeU64", + 7: "ScSpecTypeScSpecTypeI64", + 8: "ScSpecTypeScSpecTypeTimepoint", + 9: "ScSpecTypeScSpecTypeDuration", + 10: "ScSpecTypeScSpecTypeU128", + 11: "ScSpecTypeScSpecTypeI128", + 12: "ScSpecTypeScSpecTypeU256", + 13: "ScSpecTypeScSpecTypeI256", + 14: "ScSpecTypeScSpecTypeBytes", + 16: "ScSpecTypeScSpecTypeString", + 17: "ScSpecTypeScSpecTypeSymbol", + 19: "ScSpecTypeScSpecTypeAddress", 1000: "ScSpecTypeScSpecTypeOption", 1001: "ScSpecTypeScSpecTypeResult", 1002: "ScSpecTypeScSpecTypeVec", @@ -44887,17 +45079,22 @@ var _ xdrType = (*ScSpecTypeUdt)(nil) // union SCSpecTypeDef switch (SCSpecType type) // { // case SC_SPEC_TYPE_VAL: +// case SC_SPEC_TYPE_BOOL: +// case SC_SPEC_TYPE_VOID: +// case SC_SPEC_TYPE_STATUS: +// case SC_SPEC_TYPE_U32: +// case SC_SPEC_TYPE_I32: // case SC_SPEC_TYPE_U64: // case SC_SPEC_TYPE_I64: +// case SC_SPEC_TYPE_TIMEPOINT: +// case SC_SPEC_TYPE_DURATION: // case SC_SPEC_TYPE_U128: // case SC_SPEC_TYPE_I128: -// case SC_SPEC_TYPE_U32: -// case SC_SPEC_TYPE_I32: -// case SC_SPEC_TYPE_BOOL: -// case SC_SPEC_TYPE_SYMBOL: -// case SC_SPEC_TYPE_BITSET: -// case SC_SPEC_TYPE_STATUS: +// case SC_SPEC_TYPE_U256: +// case SC_SPEC_TYPE_I256: // case SC_SPEC_TYPE_BYTES: +// case SC_SPEC_TYPE_STRING: +// case SC_SPEC_TYPE_SYMBOL: // case SC_SPEC_TYPE_ADDRESS: // void; // case SC_SPEC_TYPE_OPTION: @@ -44941,28 +45138,38 @@ func (u ScSpecTypeDef) ArmForSwitch(sw int32) (string, bool) { switch ScSpecType(sw) { case ScSpecTypeScSpecTypeVal: return "", true - case ScSpecTypeScSpecTypeU64: - return "", true - case ScSpecTypeScSpecTypeI64: + case ScSpecTypeScSpecTypeBool: return "", true - case ScSpecTypeScSpecTypeU128: + case ScSpecTypeScSpecTypeVoid: return "", true - case ScSpecTypeScSpecTypeI128: + case ScSpecTypeScSpecTypeStatus: return "", true case ScSpecTypeScSpecTypeU32: return "", true case ScSpecTypeScSpecTypeI32: return "", true - case ScSpecTypeScSpecTypeBool: + case ScSpecTypeScSpecTypeU64: return "", true - case ScSpecTypeScSpecTypeSymbol: + case ScSpecTypeScSpecTypeI64: return "", true - case ScSpecTypeScSpecTypeBitset: + case ScSpecTypeScSpecTypeTimepoint: return "", true - case ScSpecTypeScSpecTypeStatus: + case ScSpecTypeScSpecTypeDuration: + return "", true + case ScSpecTypeScSpecTypeU128: + return "", true + case ScSpecTypeScSpecTypeI128: + return "", true + case ScSpecTypeScSpecTypeU256: + return "", true + case ScSpecTypeScSpecTypeI256: return "", true case ScSpecTypeScSpecTypeBytes: return "", true + case ScSpecTypeScSpecTypeString: + return "", true + case ScSpecTypeScSpecTypeSymbol: + return "", true case ScSpecTypeScSpecTypeAddress: return "", true case ScSpecTypeScSpecTypeOption: @@ -44991,28 +45198,38 @@ func NewScSpecTypeDef(aType ScSpecType, value interface{}) (result ScSpecTypeDef switch ScSpecType(aType) { case ScSpecTypeScSpecTypeVal: // void - case ScSpecTypeScSpecTypeU64: - // void - case ScSpecTypeScSpecTypeI64: + case ScSpecTypeScSpecTypeBool: // void - case ScSpecTypeScSpecTypeU128: + case ScSpecTypeScSpecTypeVoid: // void - case ScSpecTypeScSpecTypeI128: + case ScSpecTypeScSpecTypeStatus: // void case ScSpecTypeScSpecTypeU32: // void case ScSpecTypeScSpecTypeI32: // void - case ScSpecTypeScSpecTypeBool: + case ScSpecTypeScSpecTypeU64: // void - case ScSpecTypeScSpecTypeSymbol: + case ScSpecTypeScSpecTypeI64: // void - case ScSpecTypeScSpecTypeBitset: + case ScSpecTypeScSpecTypeTimepoint: // void - case ScSpecTypeScSpecTypeStatus: + case ScSpecTypeScSpecTypeDuration: + // void + case ScSpecTypeScSpecTypeU128: + // void + case ScSpecTypeScSpecTypeI128: + // void + case ScSpecTypeScSpecTypeU256: + // void + case ScSpecTypeScSpecTypeI256: // void case ScSpecTypeScSpecTypeBytes: // void + case ScSpecTypeScSpecTypeString: + // void + case ScSpecTypeScSpecTypeSymbol: + // void case ScSpecTypeScSpecTypeAddress: // void case ScSpecTypeScSpecTypeOption: @@ -45285,37 +45502,52 @@ func (u ScSpecTypeDef) EncodeTo(e *xdr.Encoder) error { case ScSpecTypeScSpecTypeVal: // Void return nil + case ScSpecTypeScSpecTypeBool: + // Void + return nil + case ScSpecTypeScSpecTypeVoid: + // Void + return nil + case ScSpecTypeScSpecTypeStatus: + // Void + return nil + case ScSpecTypeScSpecTypeU32: + // Void + return nil + case ScSpecTypeScSpecTypeI32: + // Void + return nil case ScSpecTypeScSpecTypeU64: // Void return nil case ScSpecTypeScSpecTypeI64: // Void return nil - case ScSpecTypeScSpecTypeU128: + case ScSpecTypeScSpecTypeTimepoint: // Void return nil - case ScSpecTypeScSpecTypeI128: + case ScSpecTypeScSpecTypeDuration: // Void return nil - case ScSpecTypeScSpecTypeU32: + case ScSpecTypeScSpecTypeU128: // Void return nil - case ScSpecTypeScSpecTypeI32: + case ScSpecTypeScSpecTypeI128: // Void return nil - case ScSpecTypeScSpecTypeBool: + case ScSpecTypeScSpecTypeU256: // Void return nil - case ScSpecTypeScSpecTypeSymbol: + case ScSpecTypeScSpecTypeI256: // Void return nil - case ScSpecTypeScSpecTypeBitset: + case ScSpecTypeScSpecTypeBytes: // Void return nil - case ScSpecTypeScSpecTypeStatus: + case ScSpecTypeScSpecTypeString: // Void return nil - case ScSpecTypeScSpecTypeBytes: + case ScSpecTypeScSpecTypeSymbol: // Void return nil case ScSpecTypeScSpecTypeAddress: @@ -45380,37 +45612,52 @@ func (u *ScSpecTypeDef) DecodeFrom(d *xdr.Decoder) (int, error) { case ScSpecTypeScSpecTypeVal: // Void return n, nil + case ScSpecTypeScSpecTypeBool: + // Void + return n, nil + case ScSpecTypeScSpecTypeVoid: + // Void + return n, nil + case ScSpecTypeScSpecTypeStatus: + // Void + return n, nil + case ScSpecTypeScSpecTypeU32: + // Void + return n, nil + case ScSpecTypeScSpecTypeI32: + // Void + return n, nil case ScSpecTypeScSpecTypeU64: // Void return n, nil case ScSpecTypeScSpecTypeI64: // Void return n, nil - case ScSpecTypeScSpecTypeU128: + case ScSpecTypeScSpecTypeTimepoint: // Void return n, nil - case ScSpecTypeScSpecTypeI128: + case ScSpecTypeScSpecTypeDuration: // Void return n, nil - case ScSpecTypeScSpecTypeU32: + case ScSpecTypeScSpecTypeU128: // Void return n, nil - case ScSpecTypeScSpecTypeI32: + case ScSpecTypeScSpecTypeI128: // Void return n, nil - case ScSpecTypeScSpecTypeBool: + case ScSpecTypeScSpecTypeU256: // Void return n, nil - case ScSpecTypeScSpecTypeSymbol: + case ScSpecTypeScSpecTypeI256: // Void return n, nil - case ScSpecTypeScSpecTypeBitset: + case ScSpecTypeScSpecTypeBytes: // Void return n, nil - case ScSpecTypeScSpecTypeStatus: + case ScSpecTypeScSpecTypeString: // Void return n, nil - case ScSpecTypeScSpecTypeBytes: + case ScSpecTypeScSpecTypeSymbol: // Void return n, nil case ScSpecTypeScSpecTypeAddress: @@ -47265,103 +47512,113 @@ func (s ScSpecEntry) xdrType() {} var _ xdrType = (*ScSpecEntry)(nil) -// ScSymbol is an XDR Typedef defines as: -// -// typedef string SCSymbol<10>; -type ScSymbol string - -// XDRMaxSize implements the Sized interface for ScSymbol -func (e ScSymbol) XDRMaxSize() int { - return 10 -} - -// EncodeTo encodes this value using the Encoder. -func (s ScSymbol) EncodeTo(e *xdr.Encoder) error { - var err error - if _, err = e.EncodeString(string(s)); err != nil { - return err - } - return nil -} - -var _ decoderFrom = (*ScSymbol)(nil) - -// DecodeFrom decodes this value using the Decoder. -func (s *ScSymbol) DecodeFrom(d *xdr.Decoder) (int, error) { - var err error - var n, nTmp int - var v string - v, nTmp, err = d.DecodeString(10) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding ScSymbol: %s", err) - } - *s = ScSymbol(v) - return n, nil -} - -// MarshalBinary implements encoding.BinaryMarshaler. -func (s ScSymbol) MarshalBinary() ([]byte, error) { - b := bytes.Buffer{} - e := xdr.NewEncoder(&b) - err := s.EncodeTo(e) - return b.Bytes(), err -} - -// UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ScSymbol) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - d := xdr.NewDecoder(r) - _, err := s.DecodeFrom(d) - return err -} - -var ( - _ encoding.BinaryMarshaler = (*ScSymbol)(nil) - _ encoding.BinaryUnmarshaler = (*ScSymbol)(nil) -) - -// xdrType signals that this type is an type representing -// representing XDR values defined by this package. -func (s ScSymbol) xdrType() {} - -var _ xdrType = (*ScSymbol)(nil) - // ScValType is an XDR Enum defines as: // // enum SCValType // { -// SCV_U63 = 0, -// SCV_U32 = 1, -// SCV_I32 = 2, -// SCV_STATIC = 3, -// SCV_OBJECT = 4, -// SCV_SYMBOL = 5, -// SCV_BITSET = 6, -// SCV_STATUS = 7 +// SCV_BOOL = 0, +// SCV_VOID = 1, +// SCV_STATUS = 2, +// +// // 32 bits is the smallest type in WASM or XDR; no need for u8/u16. +// SCV_U32 = 3, +// SCV_I32 = 4, +// +// // 64 bits is naturally supported by both WASM and XDR also. +// SCV_U64 = 5, +// SCV_I64 = 6, +// +// // Time-related u64 subtypes with their own functions and formatting. +// SCV_TIMEPOINT = 7, +// SCV_DURATION = 8, +// +// // 128 bits is naturally supported by Rust and we use it for Soroban +// // fixed-point arithmetic prices / balances / similar "quantities". These +// // are represented in XDR as a pair of 2 u64s, unlike {u,i}256 which is +// // represented as an array of 32 bytes. +// SCV_U128 = 9, +// SCV_I128 = 10, +// +// // 256 bits is the size of sha256 output, ed25519 keys, and the EVM machine +// // word, so for interop use we include this even though it requires a small +// // amount of Rust guest and/or host library code. +// SCV_U256 = 11, +// SCV_I256 = 12, +// +// // TODO: possibly allocate subtypes of i64, i128 and/or u256 for +// // fixed-precision with a specific number of decimals. +// +// // Bytes come in 3 flavors, 2 of which have meaningfully different +// // formatting and validity-checking / domain-restriction. +// SCV_BYTES = 13, +// SCV_STRING = 14, +// SCV_SYMBOL = 15, +// +// // Vecs and maps are just polymorphic containers of other ScVals. +// SCV_VEC = 16, +// SCV_MAP = 17, +// +// // SCContractExecutable and SCAddressType are types that gets used separately from +// // SCVal so we do not flatten their structures into separate SCVal cases. +// SCV_CONTRACT_EXECUTABLE = 18, +// SCV_ADDRESS = 19, +// +// // SCV_LEDGER_KEY_CONTRACT_EXECUTABLE and SCV_LEDGER_KEY_NONCE are unique +// // symbolic SCVals used as the key for ledger entries for a contract's code +// // and an address' nonce, respectively. +// SCV_LEDGER_KEY_CONTRACT_EXECUTABLE = 20, +// SCV_LEDGER_KEY_NONCE = 21 // }; type ScValType int32 const ( - ScValTypeScvU63 ScValType = 0 - ScValTypeScvU32 ScValType = 1 - ScValTypeScvI32 ScValType = 2 - ScValTypeScvStatic ScValType = 3 - ScValTypeScvObject ScValType = 4 - ScValTypeScvSymbol ScValType = 5 - ScValTypeScvBitset ScValType = 6 - ScValTypeScvStatus ScValType = 7 + ScValTypeScvBool ScValType = 0 + ScValTypeScvVoid ScValType = 1 + ScValTypeScvStatus ScValType = 2 + ScValTypeScvU32 ScValType = 3 + ScValTypeScvI32 ScValType = 4 + ScValTypeScvU64 ScValType = 5 + ScValTypeScvI64 ScValType = 6 + ScValTypeScvTimepoint ScValType = 7 + ScValTypeScvDuration ScValType = 8 + ScValTypeScvU128 ScValType = 9 + ScValTypeScvI128 ScValType = 10 + ScValTypeScvU256 ScValType = 11 + ScValTypeScvI256 ScValType = 12 + ScValTypeScvBytes ScValType = 13 + ScValTypeScvString ScValType = 14 + ScValTypeScvSymbol ScValType = 15 + ScValTypeScvVec ScValType = 16 + ScValTypeScvMap ScValType = 17 + ScValTypeScvContractExecutable ScValType = 18 + ScValTypeScvAddress ScValType = 19 + ScValTypeScvLedgerKeyContractExecutable ScValType = 20 + ScValTypeScvLedgerKeyNonce ScValType = 21 ) var scValTypeMap = map[int32]string{ - 0: "ScValTypeScvU63", - 1: "ScValTypeScvU32", - 2: "ScValTypeScvI32", - 3: "ScValTypeScvStatic", - 4: "ScValTypeScvObject", - 5: "ScValTypeScvSymbol", - 6: "ScValTypeScvBitset", - 7: "ScValTypeScvStatus", + 0: "ScValTypeScvBool", + 1: "ScValTypeScvVoid", + 2: "ScValTypeScvStatus", + 3: "ScValTypeScvU32", + 4: "ScValTypeScvI32", + 5: "ScValTypeScvU64", + 6: "ScValTypeScvI64", + 7: "ScValTypeScvTimepoint", + 8: "ScValTypeScvDuration", + 9: "ScValTypeScvU128", + 10: "ScValTypeScvI128", + 11: "ScValTypeScvU256", + 12: "ScValTypeScvI256", + 13: "ScValTypeScvBytes", + 14: "ScValTypeScvString", + 15: "ScValTypeScvSymbol", + 16: "ScValTypeScvVec", + 17: "ScValTypeScvMap", + 18: "ScValTypeScvContractExecutable", + 19: "ScValTypeScvAddress", + 20: "ScValTypeScvLedgerKeyContractExecutable", + 21: "ScValTypeScvLedgerKeyNonce", } // ValidEnum validates a proposed value for this enum. Implements @@ -47428,95 +47685,6 @@ func (s ScValType) xdrType() {} var _ xdrType = (*ScValType)(nil) -// ScStatic is an XDR Enum defines as: -// -// enum SCStatic -// { -// SCS_VOID = 0, -// SCS_TRUE = 1, -// SCS_FALSE = 2, -// SCS_LEDGER_KEY_CONTRACT_CODE = 3 -// }; -type ScStatic int32 - -const ( - ScStaticScsVoid ScStatic = 0 - ScStaticScsTrue ScStatic = 1 - ScStaticScsFalse ScStatic = 2 - ScStaticScsLedgerKeyContractCode ScStatic = 3 -) - -var scStaticMap = map[int32]string{ - 0: "ScStaticScsVoid", - 1: "ScStaticScsTrue", - 2: "ScStaticScsFalse", - 3: "ScStaticScsLedgerKeyContractCode", -} - -// ValidEnum validates a proposed value for this enum. Implements -// the Enum interface for ScStatic -func (e ScStatic) ValidEnum(v int32) bool { - _, ok := scStaticMap[v] - return ok -} - -// String returns the name of `e` -func (e ScStatic) String() string { - name, _ := scStaticMap[int32(e)] - return name -} - -// EncodeTo encodes this value using the Encoder. -func (e ScStatic) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scStaticMap[int32(e)]; !ok { - return fmt.Errorf("'%d' is not a valid ScStatic enum value", e) - } - _, err := enc.EncodeInt(int32(e)) - return err -} - -var _ decoderFrom = (*ScStatic)(nil) - -// DecodeFrom decodes this value using the Decoder. -func (e *ScStatic) DecodeFrom(d *xdr.Decoder) (int, error) { - v, n, err := d.DecodeInt() - if err != nil { - return n, fmt.Errorf("decoding ScStatic: %s", err) - } - if _, ok := scStaticMap[v]; !ok { - return n, fmt.Errorf("'%d' is not a valid ScStatic enum value", v) - } - *e = ScStatic(v) - return n, nil -} - -// MarshalBinary implements encoding.BinaryMarshaler. -func (s ScStatic) MarshalBinary() ([]byte, error) { - b := bytes.Buffer{} - e := xdr.NewEncoder(&b) - err := s.EncodeTo(e) - return b.Bytes(), err -} - -// UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ScStatic) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - d := xdr.NewDecoder(r) - _, err := s.DecodeFrom(d) - return err -} - -var ( - _ encoding.BinaryMarshaler = (*ScStatic)(nil) - _ encoding.BinaryUnmarshaler = (*ScStatic)(nil) -) - -// xdrType signals that this type is an type representing -// representing XDR values defined by this package. -func (s ScStatic) xdrType() {} - -var _ xdrType = (*ScStatic)(nil) - // ScStatusType is an XDR Enum defines as: // // enum SCStatusType @@ -48958,327 +49126,229 @@ func (s ScStatus) xdrType() {} var _ xdrType = (*ScStatus)(nil) -// ScVal is an XDR Union defines as: +// Int128Parts is an XDR Struct defines as: // -// union SCVal switch (SCValType type) -// { -// case SCV_U63: -// int64 u63; -// case SCV_U32: -// uint32 u32; -// case SCV_I32: -// int32 i32; -// case SCV_STATIC: -// SCStatic ic; -// case SCV_OBJECT: -// SCObject* obj; -// case SCV_SYMBOL: -// SCSymbol sym; -// case SCV_BITSET: -// uint64 bits; -// case SCV_STATUS: -// SCStatus status; +// struct Int128Parts { +// // Both signed and unsigned 128-bit ints +// // are transported in a pair of uint64s +// // to reduce the risk of sign-extension. +// uint64 lo; +// uint64 hi; // }; -type ScVal struct { - Type ScValType - U63 *Int64 - U32 *Uint32 - I32 *Int32 - Ic *ScStatic - Obj **ScObject - Sym *ScSymbol - Bits *Uint64 - Status *ScStatus -} - -// SwitchFieldName returns the field name in which this union's -// discriminant is stored -func (u ScVal) SwitchFieldName() string { - return "Type" +type Int128Parts struct { + Lo Uint64 + Hi Uint64 } -// ArmForSwitch returns which field name should be used for storing -// the value for an instance of ScVal -func (u ScVal) ArmForSwitch(sw int32) (string, bool) { - switch ScValType(sw) { - case ScValTypeScvU63: - return "U63", true - case ScValTypeScvU32: - return "U32", true - case ScValTypeScvI32: - return "I32", true - case ScValTypeScvStatic: - return "Ic", true - case ScValTypeScvObject: - return "Obj", true - case ScValTypeScvSymbol: - return "Sym", true - case ScValTypeScvBitset: - return "Bits", true - case ScValTypeScvStatus: - return "Status", true +// EncodeTo encodes this value using the Encoder. +func (s *Int128Parts) EncodeTo(e *xdr.Encoder) error { + var err error + if err = s.Lo.EncodeTo(e); err != nil { + return err } - return "-", false -} - -// NewScVal creates a new ScVal. -func NewScVal(aType ScValType, value interface{}) (result ScVal, err error) { - result.Type = aType - switch ScValType(aType) { - case ScValTypeScvU63: - tv, ok := value.(Int64) - if !ok { - err = fmt.Errorf("invalid value, must be Int64") - return - } - result.U63 = &tv - case ScValTypeScvU32: - tv, ok := value.(Uint32) - if !ok { - err = fmt.Errorf("invalid value, must be Uint32") - return - } - result.U32 = &tv - case ScValTypeScvI32: - tv, ok := value.(Int32) - if !ok { - err = fmt.Errorf("invalid value, must be Int32") - return - } - result.I32 = &tv - case ScValTypeScvStatic: - tv, ok := value.(ScStatic) - if !ok { - err = fmt.Errorf("invalid value, must be ScStatic") - return - } - result.Ic = &tv - case ScValTypeScvObject: - tv, ok := value.(*ScObject) - if !ok { - err = fmt.Errorf("invalid value, must be *ScObject") - return - } - result.Obj = &tv - case ScValTypeScvSymbol: - tv, ok := value.(ScSymbol) - if !ok { - err = fmt.Errorf("invalid value, must be ScSymbol") - return - } - result.Sym = &tv - case ScValTypeScvBitset: - tv, ok := value.(Uint64) - if !ok { - err = fmt.Errorf("invalid value, must be Uint64") - return - } - result.Bits = &tv - case ScValTypeScvStatus: - tv, ok := value.(ScStatus) - if !ok { - err = fmt.Errorf("invalid value, must be ScStatus") - return - } - result.Status = &tv + if err = s.Hi.EncodeTo(e); err != nil { + return err } - return + return nil } -// MustU63 retrieves the U63 value from the union, -// panicing if the value is not set. -func (u ScVal) MustU63() Int64 { - val, ok := u.GetU63() +var _ decoderFrom = (*Int128Parts)(nil) - if !ok { - panic("arm U63 is not set") +// DecodeFrom decodes this value using the Decoder. +func (s *Int128Parts) DecodeFrom(d *xdr.Decoder) (int, error) { + var err error + var n, nTmp int + nTmp, err = s.Lo.DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding Uint64: %s", err) } - - return val -} - -// GetU63 retrieves the U63 value from the union, -// returning ok if the union's switch indicated the value is valid. -func (u ScVal) GetU63() (result Int64, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "U63" { - result = *u.U63 - ok = true + nTmp, err = s.Hi.DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding Uint64: %s", err) } - - return + return n, nil } -// MustU32 retrieves the U32 value from the union, -// panicing if the value is not set. -func (u ScVal) MustU32() Uint32 { - val, ok := u.GetU32() - - if !ok { - panic("arm U32 is not set") - } - - return val +// MarshalBinary implements encoding.BinaryMarshaler. +func (s Int128Parts) MarshalBinary() ([]byte, error) { + b := bytes.Buffer{} + e := xdr.NewEncoder(&b) + err := s.EncodeTo(e) + return b.Bytes(), err } -// GetU32 retrieves the U32 value from the union, -// returning ok if the union's switch indicated the value is valid. -func (u ScVal) GetU32() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "U32" { - result = *u.U32 - ok = true - } - - return +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *Int128Parts) UnmarshalBinary(inp []byte) error { + r := bytes.NewReader(inp) + d := xdr.NewDecoder(r) + _, err := s.DecodeFrom(d) + return err } -// MustI32 retrieves the I32 value from the union, -// panicing if the value is not set. -func (u ScVal) MustI32() Int32 { - val, ok := u.GetI32() +var ( + _ encoding.BinaryMarshaler = (*Int128Parts)(nil) + _ encoding.BinaryUnmarshaler = (*Int128Parts)(nil) +) - if !ok { - panic("arm I32 is not set") - } +// xdrType signals that this type is an type representing +// representing XDR values defined by this package. +func (s Int128Parts) xdrType() {} - return val -} +var _ xdrType = (*Int128Parts)(nil) -// GetI32 retrieves the I32 value from the union, -// returning ok if the union's switch indicated the value is valid. -func (u ScVal) GetI32() (result Int32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) +// ScContractExecutableType is an XDR Enum defines as: +// +// enum SCContractExecutableType +// { +// SCCONTRACT_EXECUTABLE_WASM_REF = 0, +// SCCONTRACT_EXECUTABLE_TOKEN = 1 +// }; +type ScContractExecutableType int32 - if armName == "I32" { - result = *u.I32 - ok = true - } +const ( + ScContractExecutableTypeSccontractExecutableWasmRef ScContractExecutableType = 0 + ScContractExecutableTypeSccontractExecutableToken ScContractExecutableType = 1 +) - return +var scContractExecutableTypeMap = map[int32]string{ + 0: "ScContractExecutableTypeSccontractExecutableWasmRef", + 1: "ScContractExecutableTypeSccontractExecutableToken", } -// MustIc retrieves the Ic value from the union, -// panicing if the value is not set. -func (u ScVal) MustIc() ScStatic { - val, ok := u.GetIc() - - if !ok { - panic("arm Ic is not set") - } - - return val +// ValidEnum validates a proposed value for this enum. Implements +// the Enum interface for ScContractExecutableType +func (e ScContractExecutableType) ValidEnum(v int32) bool { + _, ok := scContractExecutableTypeMap[v] + return ok } -// GetIc retrieves the Ic value from the union, -// returning ok if the union's switch indicated the value is valid. -func (u ScVal) GetIc() (result ScStatic, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Ic" { - result = *u.Ic - ok = true - } - - return +// String returns the name of `e` +func (e ScContractExecutableType) String() string { + name, _ := scContractExecutableTypeMap[int32(e)] + return name } -// MustObj retrieves the Obj value from the union, -// panicing if the value is not set. -func (u ScVal) MustObj() *ScObject { - val, ok := u.GetObj() - - if !ok { - panic("arm Obj is not set") +// EncodeTo encodes this value using the Encoder. +func (e ScContractExecutableType) EncodeTo(enc *xdr.Encoder) error { + if _, ok := scContractExecutableTypeMap[int32(e)]; !ok { + return fmt.Errorf("'%d' is not a valid ScContractExecutableType enum value", e) } - - return val + _, err := enc.EncodeInt(int32(e)) + return err } -// GetObj retrieves the Obj value from the union, -// returning ok if the union's switch indicated the value is valid. -func (u ScVal) GetObj() (result *ScObject, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) +var _ decoderFrom = (*ScContractExecutableType)(nil) - if armName == "Obj" { - result = *u.Obj - ok = true +// DecodeFrom decodes this value using the Decoder. +func (e *ScContractExecutableType) DecodeFrom(d *xdr.Decoder) (int, error) { + v, n, err := d.DecodeInt() + if err != nil { + return n, fmt.Errorf("decoding ScContractExecutableType: %s", err) } - - return + if _, ok := scContractExecutableTypeMap[v]; !ok { + return n, fmt.Errorf("'%d' is not a valid ScContractExecutableType enum value", v) + } + *e = ScContractExecutableType(v) + return n, nil } -// MustSym retrieves the Sym value from the union, -// panicing if the value is not set. -func (u ScVal) MustSym() ScSymbol { - val, ok := u.GetSym() - - if !ok { - panic("arm Sym is not set") - } +// MarshalBinary implements encoding.BinaryMarshaler. +func (s ScContractExecutableType) MarshalBinary() ([]byte, error) { + b := bytes.Buffer{} + e := xdr.NewEncoder(&b) + err := s.EncodeTo(e) + return b.Bytes(), err +} - return val +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *ScContractExecutableType) UnmarshalBinary(inp []byte) error { + r := bytes.NewReader(inp) + d := xdr.NewDecoder(r) + _, err := s.DecodeFrom(d) + return err } -// GetSym retrieves the Sym value from the union, -// returning ok if the union's switch indicated the value is valid. -func (u ScVal) GetSym() (result ScSymbol, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) +var ( + _ encoding.BinaryMarshaler = (*ScContractExecutableType)(nil) + _ encoding.BinaryUnmarshaler = (*ScContractExecutableType)(nil) +) - if armName == "Sym" { - result = *u.Sym - ok = true - } +// xdrType signals that this type is an type representing +// representing XDR values defined by this package. +func (s ScContractExecutableType) xdrType() {} - return +var _ xdrType = (*ScContractExecutableType)(nil) + +// ScContractExecutable is an XDR Union defines as: +// +// union SCContractExecutable switch (SCContractExecutableType type) +// { +// case SCCONTRACT_EXECUTABLE_WASM_REF: +// Hash wasm_id; +// case SCCONTRACT_EXECUTABLE_TOKEN: +// void; +// }; +type ScContractExecutable struct { + Type ScContractExecutableType + WasmId *Hash } -// MustBits retrieves the Bits value from the union, -// panicing if the value is not set. -func (u ScVal) MustBits() Uint64 { - val, ok := u.GetBits() +// SwitchFieldName returns the field name in which this union's +// discriminant is stored +func (u ScContractExecutable) SwitchFieldName() string { + return "Type" +} - if !ok { - panic("arm Bits is not set") +// ArmForSwitch returns which field name should be used for storing +// the value for an instance of ScContractExecutable +func (u ScContractExecutable) ArmForSwitch(sw int32) (string, bool) { + switch ScContractExecutableType(sw) { + case ScContractExecutableTypeSccontractExecutableWasmRef: + return "WasmId", true + case ScContractExecutableTypeSccontractExecutableToken: + return "", true } - - return val + return "-", false } -// GetBits retrieves the Bits value from the union, -// returning ok if the union's switch indicated the value is valid. -func (u ScVal) GetBits() (result Uint64, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Bits" { - result = *u.Bits - ok = true +// NewScContractExecutable creates a new ScContractExecutable. +func NewScContractExecutable(aType ScContractExecutableType, value interface{}) (result ScContractExecutable, err error) { + result.Type = aType + switch ScContractExecutableType(aType) { + case ScContractExecutableTypeSccontractExecutableWasmRef: + tv, ok := value.(Hash) + if !ok { + err = fmt.Errorf("invalid value, must be Hash") + return + } + result.WasmId = &tv + case ScContractExecutableTypeSccontractExecutableToken: + // void } - return } -// MustStatus retrieves the Status value from the union, +// MustWasmId retrieves the WasmId value from the union, // panicing if the value is not set. -func (u ScVal) MustStatus() ScStatus { - val, ok := u.GetStatus() +func (u ScContractExecutable) MustWasmId() Hash { + val, ok := u.GetWasmId() if !ok { - panic("arm Status is not set") + panic("arm WasmId is not set") } return val } -// GetStatus retrieves the Status value from the union, +// GetWasmId retrieves the WasmId value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ScVal) GetStatus() (result ScStatus, ok bool) { +func (u ScContractExecutable) GetWasmId() (result Hash, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) - if armName == "Status" { - result = *u.Status + if armName == "WasmId" { + result = *u.WasmId ok = true } @@ -49286,153 +49356,53 @@ func (u ScVal) GetStatus() (result ScStatus, ok bool) { } // EncodeTo encodes this value using the Encoder. -func (u ScVal) EncodeTo(e *xdr.Encoder) error { +func (u ScContractExecutable) EncodeTo(e *xdr.Encoder) error { var err error if err = u.Type.EncodeTo(e); err != nil { return err } - switch ScValType(u.Type) { - case ScValTypeScvU63: - if err = (*u.U63).EncodeTo(e); err != nil { + switch ScContractExecutableType(u.Type) { + case ScContractExecutableTypeSccontractExecutableWasmRef: + if err = (*u.WasmId).EncodeTo(e); err != nil { return err } return nil - case ScValTypeScvU32: - if err = (*u.U32).EncodeTo(e); err != nil { - return err - } - return nil - case ScValTypeScvI32: - if err = (*u.I32).EncodeTo(e); err != nil { - return err - } - return nil - case ScValTypeScvStatic: - if err = (*u.Ic).EncodeTo(e); err != nil { - return err - } - return nil - case ScValTypeScvObject: - if _, err = e.EncodeBool((*u.Obj) != nil); err != nil { - return err - } - if (*u.Obj) != nil { - if err = (*(*u.Obj)).EncodeTo(e); err != nil { - return err - } - } - return nil - case ScValTypeScvSymbol: - if err = (*u.Sym).EncodeTo(e); err != nil { - return err - } - return nil - case ScValTypeScvBitset: - if err = (*u.Bits).EncodeTo(e); err != nil { - return err - } - return nil - case ScValTypeScvStatus: - if err = (*u.Status).EncodeTo(e); err != nil { - return err - } + case ScContractExecutableTypeSccontractExecutableToken: + // Void return nil } - return fmt.Errorf("Type (ScValType) switch value '%d' is not valid for union ScVal", u.Type) + return fmt.Errorf("Type (ScContractExecutableType) switch value '%d' is not valid for union ScContractExecutable", u.Type) } -var _ decoderFrom = (*ScVal)(nil) +var _ decoderFrom = (*ScContractExecutable)(nil) // DecodeFrom decodes this value using the Decoder. -func (u *ScVal) DecodeFrom(d *xdr.Decoder) (int, error) { +func (u *ScContractExecutable) DecodeFrom(d *xdr.Decoder) (int, error) { var err error var n, nTmp int nTmp, err = u.Type.DecodeFrom(d) n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScValType: %s", err) + return n, fmt.Errorf("decoding ScContractExecutableType: %s", err) } - switch ScValType(u.Type) { - case ScValTypeScvU63: - u.U63 = new(Int64) - nTmp, err = (*u.U63).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding Int64: %s", err) - } - return n, nil - case ScValTypeScvU32: - u.U32 = new(Uint32) - nTmp, err = (*u.U32).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding Uint32: %s", err) - } - return n, nil - case ScValTypeScvI32: - u.I32 = new(Int32) - nTmp, err = (*u.I32).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding Int32: %s", err) - } - return n, nil - case ScValTypeScvStatic: - u.Ic = new(ScStatic) - nTmp, err = (*u.Ic).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding ScStatic: %s", err) - } - return n, nil - case ScValTypeScvObject: - u.Obj = new(*ScObject) - var b bool - b, nTmp, err = d.DecodeBool() - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding ScObject: %s", err) - } - (*u.Obj) = nil - if b { - (*u.Obj) = new(ScObject) - nTmp, err = (*u.Obj).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding ScObject: %s", err) - } - } - return n, nil - case ScValTypeScvSymbol: - u.Sym = new(ScSymbol) - nTmp, err = (*u.Sym).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding ScSymbol: %s", err) - } - return n, nil - case ScValTypeScvBitset: - u.Bits = new(Uint64) - nTmp, err = (*u.Bits).DecodeFrom(d) + switch ScContractExecutableType(u.Type) { + case ScContractExecutableTypeSccontractExecutableWasmRef: + u.WasmId = new(Hash) + nTmp, err = (*u.WasmId).DecodeFrom(d) n += nTmp if err != nil { - return n, fmt.Errorf("decoding Uint64: %s", err) + return n, fmt.Errorf("decoding Hash: %s", err) } return n, nil - case ScValTypeScvStatus: - u.Status = new(ScStatus) - nTmp, err = (*u.Status).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding ScStatus: %s", err) - } + case ScContractExecutableTypeSccontractExecutableToken: + // Void return n, nil } - return n, fmt.Errorf("union ScVal has invalid Type (ScValType) switch value '%d'", u.Type) + return n, fmt.Errorf("union ScContractExecutable has invalid Type (ScContractExecutableType) switch value '%d'", u.Type) } // MarshalBinary implements encoding.BinaryMarshaler. -func (s ScVal) MarshalBinary() ([]byte, error) { +func (s ScContractExecutable) MarshalBinary() ([]byte, error) { b := bytes.Buffer{} e := xdr.NewEncoder(&b) err := s.EncodeTo(e) @@ -49440,7 +49410,7 @@ func (s ScVal) MarshalBinary() ([]byte, error) { } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ScVal) UnmarshalBinary(inp []byte) error { +func (s *ScContractExecutable) UnmarshalBinary(inp []byte) error { r := bytes.NewReader(inp) d := xdr.NewDecoder(r) _, err := s.DecodeFrom(d) @@ -49448,103 +49418,74 @@ func (s *ScVal) UnmarshalBinary(inp []byte) error { } var ( - _ encoding.BinaryMarshaler = (*ScVal)(nil) - _ encoding.BinaryUnmarshaler = (*ScVal)(nil) + _ encoding.BinaryMarshaler = (*ScContractExecutable)(nil) + _ encoding.BinaryUnmarshaler = (*ScContractExecutable)(nil) ) // xdrType signals that this type is an type representing // representing XDR values defined by this package. -func (s ScVal) xdrType() {} +func (s ScContractExecutable) xdrType() {} -var _ xdrType = (*ScVal)(nil) +var _ xdrType = (*ScContractExecutable)(nil) -// ScObjectType is an XDR Enum defines as: +// ScAddressType is an XDR Enum defines as: // -// enum SCObjectType +// enum SCAddressType // { -// // We have a few objects that represent non-stellar-specific concepts -// // like general-purpose maps, vectors, numbers, blobs. -// -// SCO_VEC = 0, -// SCO_MAP = 1, -// SCO_U64 = 2, -// SCO_I64 = 3, -// SCO_U128 = 4, -// SCO_I128 = 5, -// SCO_BYTES = 6, -// SCO_CONTRACT_CODE = 7, -// SCO_ADDRESS = 8, -// SCO_NONCE_KEY = 9 -// -// // TODO: add more +// SC_ADDRESS_TYPE_ACCOUNT = 0, +// SC_ADDRESS_TYPE_CONTRACT = 1 // }; -type ScObjectType int32 +type ScAddressType int32 const ( - ScObjectTypeScoVec ScObjectType = 0 - ScObjectTypeScoMap ScObjectType = 1 - ScObjectTypeScoU64 ScObjectType = 2 - ScObjectTypeScoI64 ScObjectType = 3 - ScObjectTypeScoU128 ScObjectType = 4 - ScObjectTypeScoI128 ScObjectType = 5 - ScObjectTypeScoBytes ScObjectType = 6 - ScObjectTypeScoContractCode ScObjectType = 7 - ScObjectTypeScoAddress ScObjectType = 8 - ScObjectTypeScoNonceKey ScObjectType = 9 -) - -var scObjectTypeMap = map[int32]string{ - 0: "ScObjectTypeScoVec", - 1: "ScObjectTypeScoMap", - 2: "ScObjectTypeScoU64", - 3: "ScObjectTypeScoI64", - 4: "ScObjectTypeScoU128", - 5: "ScObjectTypeScoI128", - 6: "ScObjectTypeScoBytes", - 7: "ScObjectTypeScoContractCode", - 8: "ScObjectTypeScoAddress", - 9: "ScObjectTypeScoNonceKey", + ScAddressTypeScAddressTypeAccount ScAddressType = 0 + ScAddressTypeScAddressTypeContract ScAddressType = 1 +) + +var scAddressTypeMap = map[int32]string{ + 0: "ScAddressTypeScAddressTypeAccount", + 1: "ScAddressTypeScAddressTypeContract", } // ValidEnum validates a proposed value for this enum. Implements -// the Enum interface for ScObjectType -func (e ScObjectType) ValidEnum(v int32) bool { - _, ok := scObjectTypeMap[v] +// the Enum interface for ScAddressType +func (e ScAddressType) ValidEnum(v int32) bool { + _, ok := scAddressTypeMap[v] return ok } // String returns the name of `e` -func (e ScObjectType) String() string { - name, _ := scObjectTypeMap[int32(e)] +func (e ScAddressType) String() string { + name, _ := scAddressTypeMap[int32(e)] return name } // EncodeTo encodes this value using the Encoder. -func (e ScObjectType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scObjectTypeMap[int32(e)]; !ok { - return fmt.Errorf("'%d' is not a valid ScObjectType enum value", e) +func (e ScAddressType) EncodeTo(enc *xdr.Encoder) error { + if _, ok := scAddressTypeMap[int32(e)]; !ok { + return fmt.Errorf("'%d' is not a valid ScAddressType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScObjectType)(nil) +var _ decoderFrom = (*ScAddressType)(nil) // DecodeFrom decodes this value using the Decoder. -func (e *ScObjectType) DecodeFrom(d *xdr.Decoder) (int, error) { +func (e *ScAddressType) DecodeFrom(d *xdr.Decoder) (int, error) { v, n, err := d.DecodeInt() if err != nil { - return n, fmt.Errorf("decoding ScObjectType: %s", err) + return n, fmt.Errorf("decoding ScAddressType: %s", err) } - if _, ok := scObjectTypeMap[v]; !ok { - return n, fmt.Errorf("'%d' is not a valid ScObjectType enum value", v) + if _, ok := scAddressTypeMap[v]; !ok { + return n, fmt.Errorf("'%d' is not a valid ScAddressType enum value", v) } - *e = ScObjectType(v) + *e = ScAddressType(v) return n, nil } // MarshalBinary implements encoding.BinaryMarshaler. -func (s ScObjectType) MarshalBinary() ([]byte, error) { +func (s ScAddressType) MarshalBinary() ([]byte, error) { b := bytes.Buffer{} e := xdr.NewEncoder(&b) err := s.EncodeTo(e) @@ -49552,7 +49493,7 @@ func (s ScObjectType) MarshalBinary() ([]byte, error) { } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ScObjectType) UnmarshalBinary(inp []byte) error { +func (s *ScAddressType) UnmarshalBinary(inp []byte) error { r := bytes.NewReader(inp) d := xdr.NewDecoder(r) _, err := s.DecodeFrom(d) @@ -49560,61 +49501,176 @@ func (s *ScObjectType) UnmarshalBinary(inp []byte) error { } var ( - _ encoding.BinaryMarshaler = (*ScObjectType)(nil) - _ encoding.BinaryUnmarshaler = (*ScObjectType)(nil) + _ encoding.BinaryMarshaler = (*ScAddressType)(nil) + _ encoding.BinaryUnmarshaler = (*ScAddressType)(nil) ) // xdrType signals that this type is an type representing // representing XDR values defined by this package. -func (s ScObjectType) xdrType() {} +func (s ScAddressType) xdrType() {} -var _ xdrType = (*ScObjectType)(nil) +var _ xdrType = (*ScAddressType)(nil) -// ScMapEntry is an XDR Struct defines as: +// ScAddress is an XDR Union defines as: // -// struct SCMapEntry +// union SCAddress switch (SCAddressType type) // { -// SCVal key; -// SCVal val; +// case SC_ADDRESS_TYPE_ACCOUNT: +// AccountID accountId; +// case SC_ADDRESS_TYPE_CONTRACT: +// Hash contractId; // }; -type ScMapEntry struct { - Key ScVal - Val ScVal +type ScAddress struct { + Type ScAddressType + AccountId *AccountId + ContractId *Hash +} + +// SwitchFieldName returns the field name in which this union's +// discriminant is stored +func (u ScAddress) SwitchFieldName() string { + return "Type" +} + +// ArmForSwitch returns which field name should be used for storing +// the value for an instance of ScAddress +func (u ScAddress) ArmForSwitch(sw int32) (string, bool) { + switch ScAddressType(sw) { + case ScAddressTypeScAddressTypeAccount: + return "AccountId", true + case ScAddressTypeScAddressTypeContract: + return "ContractId", true + } + return "-", false +} + +// NewScAddress creates a new ScAddress. +func NewScAddress(aType ScAddressType, value interface{}) (result ScAddress, err error) { + result.Type = aType + switch ScAddressType(aType) { + case ScAddressTypeScAddressTypeAccount: + tv, ok := value.(AccountId) + if !ok { + err = fmt.Errorf("invalid value, must be AccountId") + return + } + result.AccountId = &tv + case ScAddressTypeScAddressTypeContract: + tv, ok := value.(Hash) + if !ok { + err = fmt.Errorf("invalid value, must be Hash") + return + } + result.ContractId = &tv + } + return +} + +// MustAccountId retrieves the AccountId value from the union, +// panicing if the value is not set. +func (u ScAddress) MustAccountId() AccountId { + val, ok := u.GetAccountId() + + if !ok { + panic("arm AccountId is not set") + } + + return val +} + +// GetAccountId retrieves the AccountId value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScAddress) GetAccountId() (result AccountId, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "AccountId" { + result = *u.AccountId + ok = true + } + + return +} + +// MustContractId retrieves the ContractId value from the union, +// panicing if the value is not set. +func (u ScAddress) MustContractId() Hash { + val, ok := u.GetContractId() + + if !ok { + panic("arm ContractId is not set") + } + + return val +} + +// GetContractId retrieves the ContractId value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScAddress) GetContractId() (result Hash, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "ContractId" { + result = *u.ContractId + ok = true + } + + return } // EncodeTo encodes this value using the Encoder. -func (s *ScMapEntry) EncodeTo(e *xdr.Encoder) error { +func (u ScAddress) EncodeTo(e *xdr.Encoder) error { var err error - if err = s.Key.EncodeTo(e); err != nil { + if err = u.Type.EncodeTo(e); err != nil { return err } - if err = s.Val.EncodeTo(e); err != nil { - return err + switch ScAddressType(u.Type) { + case ScAddressTypeScAddressTypeAccount: + if err = (*u.AccountId).EncodeTo(e); err != nil { + return err + } + return nil + case ScAddressTypeScAddressTypeContract: + if err = (*u.ContractId).EncodeTo(e); err != nil { + return err + } + return nil } - return nil + return fmt.Errorf("Type (ScAddressType) switch value '%d' is not valid for union ScAddress", u.Type) } -var _ decoderFrom = (*ScMapEntry)(nil) +var _ decoderFrom = (*ScAddress)(nil) // DecodeFrom decodes this value using the Decoder. -func (s *ScMapEntry) DecodeFrom(d *xdr.Decoder) (int, error) { +func (u *ScAddress) DecodeFrom(d *xdr.Decoder) (int, error) { var err error var n, nTmp int - nTmp, err = s.Key.DecodeFrom(d) + nTmp, err = u.Type.DecodeFrom(d) n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScVal: %s", err) + return n, fmt.Errorf("decoding ScAddressType: %s", err) } - nTmp, err = s.Val.DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding ScVal: %s", err) + switch ScAddressType(u.Type) { + case ScAddressTypeScAddressTypeAccount: + u.AccountId = new(AccountId) + nTmp, err = (*u.AccountId).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding AccountId: %s", err) + } + return n, nil + case ScAddressTypeScAddressTypeContract: + u.ContractId = new(Hash) + nTmp, err = (*u.ContractId).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding Hash: %s", err) + } + return n, nil } - return n, nil + return n, fmt.Errorf("union ScAddress has invalid Type (ScAddressType) switch value '%d'", u.Type) } // MarshalBinary implements encoding.BinaryMarshaler. -func (s ScMapEntry) MarshalBinary() ([]byte, error) { +func (s ScAddress) MarshalBinary() ([]byte, error) { b := bytes.Buffer{} e := xdr.NewEncoder(&b) err := s.EncodeTo(e) @@ -49622,7 +49678,7 @@ func (s ScMapEntry) MarshalBinary() ([]byte, error) { } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ScMapEntry) UnmarshalBinary(inp []byte) error { +func (s *ScAddress) UnmarshalBinary(inp []byte) error { r := bytes.NewReader(inp) d := xdr.NewDecoder(r) _, err := s.DecodeFrom(d) @@ -49630,21 +49686,26 @@ func (s *ScMapEntry) UnmarshalBinary(inp []byte) error { } var ( - _ encoding.BinaryMarshaler = (*ScMapEntry)(nil) - _ encoding.BinaryUnmarshaler = (*ScMapEntry)(nil) + _ encoding.BinaryMarshaler = (*ScAddress)(nil) + _ encoding.BinaryUnmarshaler = (*ScAddress)(nil) ) // xdrType signals that this type is an type representing // representing XDR values defined by this package. -func (s ScMapEntry) xdrType() {} +func (s ScAddress) xdrType() {} -var _ xdrType = (*ScMapEntry)(nil) +var _ xdrType = (*ScAddress)(nil) // ScvalLimit is an XDR Const defines as: // // const SCVAL_LIMIT = 256000; const ScvalLimit = 256000 +// ScsymbolLimit is an XDR Const defines as: +// +// const SCSYMBOL_LIMIT = 32; +const ScsymbolLimit = 32 + // ScVec is an XDR Typedef defines as: // // typedef SCVal SCVec; @@ -49805,64 +49866,41 @@ func (s ScMap) xdrType() {} var _ xdrType = (*ScMap)(nil) -// ScContractCodeType is an XDR Enum defines as: +// ScBytes is an XDR Typedef defines as: // -// enum SCContractCodeType -// { -// SCCONTRACT_CODE_WASM_REF = 0, -// SCCONTRACT_CODE_TOKEN = 1 -// }; -type ScContractCodeType int32 - -const ( - ScContractCodeTypeSccontractCodeWasmRef ScContractCodeType = 0 - ScContractCodeTypeSccontractCodeToken ScContractCodeType = 1 -) - -var scContractCodeTypeMap = map[int32]string{ - 0: "ScContractCodeTypeSccontractCodeWasmRef", - 1: "ScContractCodeTypeSccontractCodeToken", -} - -// ValidEnum validates a proposed value for this enum. Implements -// the Enum interface for ScContractCodeType -func (e ScContractCodeType) ValidEnum(v int32) bool { - _, ok := scContractCodeTypeMap[v] - return ok -} +// typedef opaque SCBytes; +type ScBytes []byte -// String returns the name of `e` -func (e ScContractCodeType) String() string { - name, _ := scContractCodeTypeMap[int32(e)] - return name +// XDRMaxSize implements the Sized interface for ScBytes +func (e ScBytes) XDRMaxSize() int { + return 256000 } // EncodeTo encodes this value using the Encoder. -func (e ScContractCodeType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scContractCodeTypeMap[int32(e)]; !ok { - return fmt.Errorf("'%d' is not a valid ScContractCodeType enum value", e) +func (s ScBytes) EncodeTo(e *xdr.Encoder) error { + var err error + if _, err = e.EncodeOpaque(s[:]); err != nil { + return err } - _, err := enc.EncodeInt(int32(e)) - return err + return nil } -var _ decoderFrom = (*ScContractCodeType)(nil) +var _ decoderFrom = (*ScBytes)(nil) // DecodeFrom decodes this value using the Decoder. -func (e *ScContractCodeType) DecodeFrom(d *xdr.Decoder) (int, error) { - v, n, err := d.DecodeInt() +func (s *ScBytes) DecodeFrom(d *xdr.Decoder) (int, error) { + var err error + var n, nTmp int + (*s), nTmp, err = d.DecodeOpaque(256000) + n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScContractCodeType: %s", err) - } - if _, ok := scContractCodeTypeMap[v]; !ok { - return n, fmt.Errorf("'%d' is not a valid ScContractCodeType enum value", v) + return n, fmt.Errorf("decoding ScBytes: %s", err) } - *e = ScContractCodeType(v) return n, nil } // MarshalBinary implements encoding.BinaryMarshaler. -func (s ScContractCodeType) MarshalBinary() ([]byte, error) { +func (s ScBytes) MarshalBinary() ([]byte, error) { b := bytes.Buffer{} e := xdr.NewEncoder(&b) err := s.EncodeTo(e) @@ -49870,7 +49908,7 @@ func (s ScContractCodeType) MarshalBinary() ([]byte, error) { } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ScContractCodeType) UnmarshalBinary(inp []byte) error { +func (s *ScBytes) UnmarshalBinary(inp []byte) error { r := bytes.NewReader(inp) d := xdr.NewDecoder(r) _, err := s.DecodeFrom(d) @@ -49878,138 +49916,53 @@ func (s *ScContractCodeType) UnmarshalBinary(inp []byte) error { } var ( - _ encoding.BinaryMarshaler = (*ScContractCodeType)(nil) - _ encoding.BinaryUnmarshaler = (*ScContractCodeType)(nil) + _ encoding.BinaryMarshaler = (*ScBytes)(nil) + _ encoding.BinaryUnmarshaler = (*ScBytes)(nil) ) // xdrType signals that this type is an type representing // representing XDR values defined by this package. -func (s ScContractCodeType) xdrType() {} +func (s ScBytes) xdrType() {} -var _ xdrType = (*ScContractCodeType)(nil) +var _ xdrType = (*ScBytes)(nil) -// ScContractCode is an XDR Union defines as: +// ScString is an XDR Typedef defines as: // -// union SCContractCode switch (SCContractCodeType type) -// { -// case SCCONTRACT_CODE_WASM_REF: -// Hash wasm_id; -// case SCCONTRACT_CODE_TOKEN: -// void; -// }; -type ScContractCode struct { - Type ScContractCodeType - WasmId *Hash -} - -// SwitchFieldName returns the field name in which this union's -// discriminant is stored -func (u ScContractCode) SwitchFieldName() string { - return "Type" -} - -// ArmForSwitch returns which field name should be used for storing -// the value for an instance of ScContractCode -func (u ScContractCode) ArmForSwitch(sw int32) (string, bool) { - switch ScContractCodeType(sw) { - case ScContractCodeTypeSccontractCodeWasmRef: - return "WasmId", true - case ScContractCodeTypeSccontractCodeToken: - return "", true - } - return "-", false -} - -// NewScContractCode creates a new ScContractCode. -func NewScContractCode(aType ScContractCodeType, value interface{}) (result ScContractCode, err error) { - result.Type = aType - switch ScContractCodeType(aType) { - case ScContractCodeTypeSccontractCodeWasmRef: - tv, ok := value.(Hash) - if !ok { - err = fmt.Errorf("invalid value, must be Hash") - return - } - result.WasmId = &tv - case ScContractCodeTypeSccontractCodeToken: - // void - } - return -} - -// MustWasmId retrieves the WasmId value from the union, -// panicing if the value is not set. -func (u ScContractCode) MustWasmId() Hash { - val, ok := u.GetWasmId() - - if !ok { - panic("arm WasmId is not set") - } - - return val -} - -// GetWasmId retrieves the WasmId value from the union, -// returning ok if the union's switch indicated the value is valid. -func (u ScContractCode) GetWasmId() (result Hash, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "WasmId" { - result = *u.WasmId - ok = true - } +// typedef string SCString; +type ScString string - return +// XDRMaxSize implements the Sized interface for ScString +func (e ScString) XDRMaxSize() int { + return 256000 } // EncodeTo encodes this value using the Encoder. -func (u ScContractCode) EncodeTo(e *xdr.Encoder) error { +func (s ScString) EncodeTo(e *xdr.Encoder) error { var err error - if err = u.Type.EncodeTo(e); err != nil { + if _, err = e.EncodeString(string(s)); err != nil { return err } - switch ScContractCodeType(u.Type) { - case ScContractCodeTypeSccontractCodeWasmRef: - if err = (*u.WasmId).EncodeTo(e); err != nil { - return err - } - return nil - case ScContractCodeTypeSccontractCodeToken: - // Void - return nil - } - return fmt.Errorf("Type (ScContractCodeType) switch value '%d' is not valid for union ScContractCode", u.Type) + return nil } -var _ decoderFrom = (*ScContractCode)(nil) +var _ decoderFrom = (*ScString)(nil) // DecodeFrom decodes this value using the Decoder. -func (u *ScContractCode) DecodeFrom(d *xdr.Decoder) (int, error) { +func (s *ScString) DecodeFrom(d *xdr.Decoder) (int, error) { var err error var n, nTmp int - nTmp, err = u.Type.DecodeFrom(d) + var v string + v, nTmp, err = d.DecodeString(256000) n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScContractCodeType: %s", err) - } - switch ScContractCodeType(u.Type) { - case ScContractCodeTypeSccontractCodeWasmRef: - u.WasmId = new(Hash) - nTmp, err = (*u.WasmId).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding Hash: %s", err) - } - return n, nil - case ScContractCodeTypeSccontractCodeToken: - // Void - return n, nil + return n, fmt.Errorf("decoding ScString: %s", err) } - return n, fmt.Errorf("union ScContractCode has invalid Type (ScContractCodeType) switch value '%d'", u.Type) + *s = ScString(v) + return n, nil } // MarshalBinary implements encoding.BinaryMarshaler. -func (s ScContractCode) MarshalBinary() ([]byte, error) { +func (s ScString) MarshalBinary() ([]byte, error) { b := bytes.Buffer{} e := xdr.NewEncoder(&b) err := s.EncodeTo(e) @@ -50017,7 +49970,7 @@ func (s ScContractCode) MarshalBinary() ([]byte, error) { } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ScContractCode) UnmarshalBinary(inp []byte) error { +func (s *ScString) UnmarshalBinary(inp []byte) error { r := bytes.NewReader(inp) d := xdr.NewDecoder(r) _, err := s.DecodeFrom(d) @@ -50025,63 +49978,53 @@ func (s *ScContractCode) UnmarshalBinary(inp []byte) error { } var ( - _ encoding.BinaryMarshaler = (*ScContractCode)(nil) - _ encoding.BinaryUnmarshaler = (*ScContractCode)(nil) + _ encoding.BinaryMarshaler = (*ScString)(nil) + _ encoding.BinaryUnmarshaler = (*ScString)(nil) ) // xdrType signals that this type is an type representing // representing XDR values defined by this package. -func (s ScContractCode) xdrType() {} +func (s ScString) xdrType() {} -var _ xdrType = (*ScContractCode)(nil) +var _ xdrType = (*ScString)(nil) -// Int128Parts is an XDR Struct defines as: +// ScSymbol is an XDR Typedef defines as: // -// struct Int128Parts { -// // Both signed and unsigned 128-bit ints -// // are transported in a pair of uint64s -// // to reduce the risk of sign-extension. -// uint64 lo; -// uint64 hi; -// }; -type Int128Parts struct { - Lo Uint64 - Hi Uint64 +// typedef string SCSymbol; +type ScSymbol string + +// XDRMaxSize implements the Sized interface for ScSymbol +func (e ScSymbol) XDRMaxSize() int { + return 32 } // EncodeTo encodes this value using the Encoder. -func (s *Int128Parts) EncodeTo(e *xdr.Encoder) error { +func (s ScSymbol) EncodeTo(e *xdr.Encoder) error { var err error - if err = s.Lo.EncodeTo(e); err != nil { - return err - } - if err = s.Hi.EncodeTo(e); err != nil { + if _, err = e.EncodeString(string(s)); err != nil { return err } return nil } -var _ decoderFrom = (*Int128Parts)(nil) +var _ decoderFrom = (*ScSymbol)(nil) // DecodeFrom decodes this value using the Decoder. -func (s *Int128Parts) DecodeFrom(d *xdr.Decoder) (int, error) { +func (s *ScSymbol) DecodeFrom(d *xdr.Decoder) (int, error) { var err error var n, nTmp int - nTmp, err = s.Lo.DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding Uint64: %s", err) - } - nTmp, err = s.Hi.DecodeFrom(d) + var v string + v, nTmp, err = d.DecodeString(32) n += nTmp if err != nil { - return n, fmt.Errorf("decoding Uint64: %s", err) + return n, fmt.Errorf("decoding ScSymbol: %s", err) } + *s = ScSymbol(v) return n, nil } // MarshalBinary implements encoding.BinaryMarshaler. -func (s Int128Parts) MarshalBinary() ([]byte, error) { +func (s ScSymbol) MarshalBinary() ([]byte, error) { b := bytes.Buffer{} e := xdr.NewEncoder(&b) err := s.EncodeTo(e) @@ -50089,7 +50032,7 @@ func (s Int128Parts) MarshalBinary() ([]byte, error) { } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *Int128Parts) UnmarshalBinary(inp []byte) error { +func (s *ScSymbol) UnmarshalBinary(inp []byte) error { r := bytes.NewReader(inp) d := xdr.NewDecoder(r) _, err := s.DecodeFrom(d) @@ -50097,74 +50040,50 @@ func (s *Int128Parts) UnmarshalBinary(inp []byte) error { } var ( - _ encoding.BinaryMarshaler = (*Int128Parts)(nil) - _ encoding.BinaryUnmarshaler = (*Int128Parts)(nil) + _ encoding.BinaryMarshaler = (*ScSymbol)(nil) + _ encoding.BinaryUnmarshaler = (*ScSymbol)(nil) ) // xdrType signals that this type is an type representing // representing XDR values defined by this package. -func (s Int128Parts) xdrType() {} +func (s ScSymbol) xdrType() {} -var _ xdrType = (*Int128Parts)(nil) +var _ xdrType = (*ScSymbol)(nil) -// ScAddressType is an XDR Enum defines as: +// ScNonceKey is an XDR Struct defines as: // -// enum SCAddressType -// { -// SC_ADDRESS_TYPE_ACCOUNT = 0, -// SC_ADDRESS_TYPE_CONTRACT = 1 +// struct SCNonceKey { +// SCAddress nonce_address; // }; -type ScAddressType int32 - -const ( - ScAddressTypeScAddressTypeAccount ScAddressType = 0 - ScAddressTypeScAddressTypeContract ScAddressType = 1 -) - -var scAddressTypeMap = map[int32]string{ - 0: "ScAddressTypeScAddressTypeAccount", - 1: "ScAddressTypeScAddressTypeContract", -} - -// ValidEnum validates a proposed value for this enum. Implements -// the Enum interface for ScAddressType -func (e ScAddressType) ValidEnum(v int32) bool { - _, ok := scAddressTypeMap[v] - return ok -} - -// String returns the name of `e` -func (e ScAddressType) String() string { - name, _ := scAddressTypeMap[int32(e)] - return name +type ScNonceKey struct { + NonceAddress ScAddress } // EncodeTo encodes this value using the Encoder. -func (e ScAddressType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scAddressTypeMap[int32(e)]; !ok { - return fmt.Errorf("'%d' is not a valid ScAddressType enum value", e) +func (s *ScNonceKey) EncodeTo(e *xdr.Encoder) error { + var err error + if err = s.NonceAddress.EncodeTo(e); err != nil { + return err } - _, err := enc.EncodeInt(int32(e)) - return err + return nil } -var _ decoderFrom = (*ScAddressType)(nil) +var _ decoderFrom = (*ScNonceKey)(nil) // DecodeFrom decodes this value using the Decoder. -func (e *ScAddressType) DecodeFrom(d *xdr.Decoder) (int, error) { - v, n, err := d.DecodeInt() +func (s *ScNonceKey) DecodeFrom(d *xdr.Decoder) (int, error) { + var err error + var n, nTmp int + nTmp, err = s.NonceAddress.DecodeFrom(d) + n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScAddressType: %s", err) - } - if _, ok := scAddressTypeMap[v]; !ok { - return n, fmt.Errorf("'%d' is not a valid ScAddressType enum value", v) + return n, fmt.Errorf("decoding ScAddress: %s", err) } - *e = ScAddressType(v) return n, nil } // MarshalBinary implements encoding.BinaryMarshaler. -func (s ScAddressType) MarshalBinary() ([]byte, error) { +func (s ScNonceKey) MarshalBinary() ([]byte, error) { b := bytes.Buffer{} e := xdr.NewEncoder(&b) err := s.EncodeTo(e) @@ -50172,7 +50091,7 @@ func (s ScAddressType) MarshalBinary() ([]byte, error) { } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ScAddressType) UnmarshalBinary(inp []byte) error { +func (s *ScNonceKey) UnmarshalBinary(inp []byte) error { r := bytes.NewReader(inp) d := xdr.NewDecoder(r) _, err := s.DecodeFrom(d) @@ -50180,396 +50099,406 @@ func (s *ScAddressType) UnmarshalBinary(inp []byte) error { } var ( - _ encoding.BinaryMarshaler = (*ScAddressType)(nil) - _ encoding.BinaryUnmarshaler = (*ScAddressType)(nil) + _ encoding.BinaryMarshaler = (*ScNonceKey)(nil) + _ encoding.BinaryUnmarshaler = (*ScNonceKey)(nil) ) // xdrType signals that this type is an type representing // representing XDR values defined by this package. -func (s ScAddressType) xdrType() {} +func (s ScNonceKey) xdrType() {} -var _ xdrType = (*ScAddressType)(nil) +var _ xdrType = (*ScNonceKey)(nil) -// ScAddress is an XDR Union defines as: +// ScVal is an XDR Union defines as: // -// union SCAddress switch (SCAddressType type) +// union SCVal switch (SCValType type) // { -// case SC_ADDRESS_TYPE_ACCOUNT: -// AccountID accountId; -// case SC_ADDRESS_TYPE_CONTRACT: -// Hash contractId; -// }; -type ScAddress struct { - Type ScAddressType - AccountId *AccountId - ContractId *Hash -} - -// SwitchFieldName returns the field name in which this union's -// discriminant is stored -func (u ScAddress) SwitchFieldName() string { - return "Type" -} - -// ArmForSwitch returns which field name should be used for storing -// the value for an instance of ScAddress -func (u ScAddress) ArmForSwitch(sw int32) (string, bool) { - switch ScAddressType(sw) { - case ScAddressTypeScAddressTypeAccount: - return "AccountId", true - case ScAddressTypeScAddressTypeContract: - return "ContractId", true - } - return "-", false -} - -// NewScAddress creates a new ScAddress. -func NewScAddress(aType ScAddressType, value interface{}) (result ScAddress, err error) { - result.Type = aType - switch ScAddressType(aType) { - case ScAddressTypeScAddressTypeAccount: - tv, ok := value.(AccountId) - if !ok { - err = fmt.Errorf("invalid value, must be AccountId") - return - } - result.AccountId = &tv - case ScAddressTypeScAddressTypeContract: - tv, ok := value.(Hash) - if !ok { - err = fmt.Errorf("invalid value, must be Hash") - return - } - result.ContractId = &tv - } - return -} - -// MustAccountId retrieves the AccountId value from the union, -// panicing if the value is not set. -func (u ScAddress) MustAccountId() AccountId { - val, ok := u.GetAccountId() - - if !ok { - panic("arm AccountId is not set") - } - - return val -} - -// GetAccountId retrieves the AccountId value from the union, -// returning ok if the union's switch indicated the value is valid. -func (u ScAddress) GetAccountId() (result AccountId, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AccountId" { - result = *u.AccountId - ok = true - } - - return -} - -// MustContractId retrieves the ContractId value from the union, -// panicing if the value is not set. -func (u ScAddress) MustContractId() Hash { - val, ok := u.GetContractId() - - if !ok { - panic("arm ContractId is not set") - } - - return val -} - -// GetContractId retrieves the ContractId value from the union, -// returning ok if the union's switch indicated the value is valid. -func (u ScAddress) GetContractId() (result Hash, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ContractId" { - result = *u.ContractId - ok = true - } - - return -} - -// EncodeTo encodes this value using the Encoder. -func (u ScAddress) EncodeTo(e *xdr.Encoder) error { - var err error - if err = u.Type.EncodeTo(e); err != nil { - return err - } - switch ScAddressType(u.Type) { - case ScAddressTypeScAddressTypeAccount: - if err = (*u.AccountId).EncodeTo(e); err != nil { - return err - } - return nil - case ScAddressTypeScAddressTypeContract: - if err = (*u.ContractId).EncodeTo(e); err != nil { - return err - } - return nil - } - return fmt.Errorf("Type (ScAddressType) switch value '%d' is not valid for union ScAddress", u.Type) -} - -var _ decoderFrom = (*ScAddress)(nil) - -// DecodeFrom decodes this value using the Decoder. -func (u *ScAddress) DecodeFrom(d *xdr.Decoder) (int, error) { - var err error - var n, nTmp int - nTmp, err = u.Type.DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding ScAddressType: %s", err) - } - switch ScAddressType(u.Type) { - case ScAddressTypeScAddressTypeAccount: - u.AccountId = new(AccountId) - nTmp, err = (*u.AccountId).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding AccountId: %s", err) - } - return n, nil - case ScAddressTypeScAddressTypeContract: - u.ContractId = new(Hash) - nTmp, err = (*u.ContractId).DecodeFrom(d) - n += nTmp - if err != nil { - return n, fmt.Errorf("decoding Hash: %s", err) - } - return n, nil - } - return n, fmt.Errorf("union ScAddress has invalid Type (ScAddressType) switch value '%d'", u.Type) -} - -// MarshalBinary implements encoding.BinaryMarshaler. -func (s ScAddress) MarshalBinary() ([]byte, error) { - b := bytes.Buffer{} - e := xdr.NewEncoder(&b) - err := s.EncodeTo(e) - return b.Bytes(), err -} - -// UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ScAddress) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - d := xdr.NewDecoder(r) - _, err := s.DecodeFrom(d) - return err -} - -var ( - _ encoding.BinaryMarshaler = (*ScAddress)(nil) - _ encoding.BinaryUnmarshaler = (*ScAddress)(nil) -) - -// xdrType signals that this type is an type representing -// representing XDR values defined by this package. -func (s ScAddress) xdrType() {} - -var _ xdrType = (*ScAddress)(nil) - -// ScObject is an XDR Union defines as: // -// union SCObject switch (SCObjectType type) -// { -// case SCO_VEC: -// SCVec vec; -// case SCO_MAP: -// SCMap map; -// case SCO_U64: +// case SCV_BOOL: +// bool b; +// case SCV_VOID: +// void; +// case SCV_STATUS: +// SCStatus error; +// +// case SCV_U32: +// uint32 u32; +// case SCV_I32: +// int32 i32; +// +// case SCV_U64: // uint64 u64; -// case SCO_I64: +// case SCV_I64: // int64 i64; -// case SCO_U128: +// case SCV_TIMEPOINT: +// TimePoint timepoint; +// case SCV_DURATION: +// Duration duration; +// +// case SCV_U128: // Int128Parts u128; -// case SCO_I128: +// case SCV_I128: // Int128Parts i128; -// case SCO_BYTES: -// opaque bin; -// case SCO_CONTRACT_CODE: -// SCContractCode contractCode; -// case SCO_ADDRESS: +// +// case SCV_U256: +// uint256 u256; +// case SCV_I256: +// uint256 i256; +// +// case SCV_BYTES: +// SCBytes bytes; +// case SCV_STRING: +// SCString str; +// case SCV_SYMBOL: +// SCSymbol sym; +// +// // Vec and Map are recursive so need to live +// // behind an option, due to xdrpp limitations. +// case SCV_VEC: +// SCVec *vec; +// case SCV_MAP: +// SCMap *map; +// +// case SCV_CONTRACT_EXECUTABLE: +// SCContractExecutable exec; +// case SCV_ADDRESS: // SCAddress address; -// case SCO_NONCE_KEY: -// SCAddress nonceAddress; -// }; -type ScObject struct { - Type ScObjectType - Vec *ScVec - Map *ScMap - U64 *Uint64 - I64 *Int64 - U128 *Int128Parts - I128 *Int128Parts - Bin *[]byte `xdrmaxsize:"256000"` - ContractCode *ScContractCode - Address *ScAddress - NonceAddress *ScAddress +// +// // Special SCVals reserved for system-constructed contract-data +// // ledger keys, not generally usable elsewhere. +// case SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: +// void; +// case SCV_LEDGER_KEY_NONCE: +// SCNonceKey nonce_key; +// }; +type ScVal struct { + Type ScValType + B *bool + Error *ScStatus + U32 *Uint32 + I32 *Int32 + U64 *Uint64 + I64 *Int64 + Timepoint *TimePoint + Duration *Duration + U128 *Int128Parts + I128 *Int128Parts + U256 *Uint256 + I256 *Uint256 + Bytes *ScBytes + Str *ScString + Sym *ScSymbol + Vec **ScVec + Map **ScMap + Exec *ScContractExecutable + Address *ScAddress + NonceKey *ScNonceKey } // SwitchFieldName returns the field name in which this union's // discriminant is stored -func (u ScObject) SwitchFieldName() string { +func (u ScVal) SwitchFieldName() string { return "Type" } // ArmForSwitch returns which field name should be used for storing -// the value for an instance of ScObject -func (u ScObject) ArmForSwitch(sw int32) (string, bool) { - switch ScObjectType(sw) { - case ScObjectTypeScoVec: - return "Vec", true - case ScObjectTypeScoMap: - return "Map", true - case ScObjectTypeScoU64: +// the value for an instance of ScVal +func (u ScVal) ArmForSwitch(sw int32) (string, bool) { + switch ScValType(sw) { + case ScValTypeScvBool: + return "B", true + case ScValTypeScvVoid: + return "", true + case ScValTypeScvStatus: + return "Error", true + case ScValTypeScvU32: + return "U32", true + case ScValTypeScvI32: + return "I32", true + case ScValTypeScvU64: return "U64", true - case ScObjectTypeScoI64: + case ScValTypeScvI64: return "I64", true - case ScObjectTypeScoU128: + case ScValTypeScvTimepoint: + return "Timepoint", true + case ScValTypeScvDuration: + return "Duration", true + case ScValTypeScvU128: return "U128", true - case ScObjectTypeScoI128: + case ScValTypeScvI128: return "I128", true - case ScObjectTypeScoBytes: - return "Bin", true - case ScObjectTypeScoContractCode: - return "ContractCode", true - case ScObjectTypeScoAddress: + case ScValTypeScvU256: + return "U256", true + case ScValTypeScvI256: + return "I256", true + case ScValTypeScvBytes: + return "Bytes", true + case ScValTypeScvString: + return "Str", true + case ScValTypeScvSymbol: + return "Sym", true + case ScValTypeScvVec: + return "Vec", true + case ScValTypeScvMap: + return "Map", true + case ScValTypeScvContractExecutable: + return "Exec", true + case ScValTypeScvAddress: return "Address", true - case ScObjectTypeScoNonceKey: - return "NonceAddress", true + case ScValTypeScvLedgerKeyContractExecutable: + return "", true + case ScValTypeScvLedgerKeyNonce: + return "NonceKey", true } return "-", false } -// NewScObject creates a new ScObject. -func NewScObject(aType ScObjectType, value interface{}) (result ScObject, err error) { +// NewScVal creates a new ScVal. +func NewScVal(aType ScValType, value interface{}) (result ScVal, err error) { result.Type = aType - switch ScObjectType(aType) { - case ScObjectTypeScoVec: - tv, ok := value.(ScVec) + switch ScValType(aType) { + case ScValTypeScvBool: + tv, ok := value.(bool) if !ok { - err = fmt.Errorf("invalid value, must be ScVec") + err = fmt.Errorf("invalid value, must be bool") return } - result.Vec = &tv - case ScObjectTypeScoMap: - tv, ok := value.(ScMap) + result.B = &tv + case ScValTypeScvVoid: + // void + case ScValTypeScvStatus: + tv, ok := value.(ScStatus) if !ok { - err = fmt.Errorf("invalid value, must be ScMap") + err = fmt.Errorf("invalid value, must be ScStatus") return } - result.Map = &tv - case ScObjectTypeScoU64: + result.Error = &tv + case ScValTypeScvU32: + tv, ok := value.(Uint32) + if !ok { + err = fmt.Errorf("invalid value, must be Uint32") + return + } + result.U32 = &tv + case ScValTypeScvI32: + tv, ok := value.(Int32) + if !ok { + err = fmt.Errorf("invalid value, must be Int32") + return + } + result.I32 = &tv + case ScValTypeScvU64: tv, ok := value.(Uint64) if !ok { err = fmt.Errorf("invalid value, must be Uint64") return } result.U64 = &tv - case ScObjectTypeScoI64: + case ScValTypeScvI64: tv, ok := value.(Int64) if !ok { err = fmt.Errorf("invalid value, must be Int64") return } result.I64 = &tv - case ScObjectTypeScoU128: + case ScValTypeScvTimepoint: + tv, ok := value.(TimePoint) + if !ok { + err = fmt.Errorf("invalid value, must be TimePoint") + return + } + result.Timepoint = &tv + case ScValTypeScvDuration: + tv, ok := value.(Duration) + if !ok { + err = fmt.Errorf("invalid value, must be Duration") + return + } + result.Duration = &tv + case ScValTypeScvU128: tv, ok := value.(Int128Parts) if !ok { err = fmt.Errorf("invalid value, must be Int128Parts") return } result.U128 = &tv - case ScObjectTypeScoI128: + case ScValTypeScvI128: tv, ok := value.(Int128Parts) if !ok { err = fmt.Errorf("invalid value, must be Int128Parts") return } result.I128 = &tv - case ScObjectTypeScoBytes: - tv, ok := value.([]byte) + case ScValTypeScvU256: + tv, ok := value.(Uint256) if !ok { - err = fmt.Errorf("invalid value, must be []byte") + err = fmt.Errorf("invalid value, must be Uint256") return } - result.Bin = &tv - case ScObjectTypeScoContractCode: - tv, ok := value.(ScContractCode) + result.U256 = &tv + case ScValTypeScvI256: + tv, ok := value.(Uint256) if !ok { - err = fmt.Errorf("invalid value, must be ScContractCode") + err = fmt.Errorf("invalid value, must be Uint256") return } - result.ContractCode = &tv - case ScObjectTypeScoAddress: + result.I256 = &tv + case ScValTypeScvBytes: + tv, ok := value.(ScBytes) + if !ok { + err = fmt.Errorf("invalid value, must be ScBytes") + return + } + result.Bytes = &tv + case ScValTypeScvString: + tv, ok := value.(ScString) + if !ok { + err = fmt.Errorf("invalid value, must be ScString") + return + } + result.Str = &tv + case ScValTypeScvSymbol: + tv, ok := value.(ScSymbol) + if !ok { + err = fmt.Errorf("invalid value, must be ScSymbol") + return + } + result.Sym = &tv + case ScValTypeScvVec: + tv, ok := value.(*ScVec) + if !ok { + err = fmt.Errorf("invalid value, must be *ScVec") + return + } + result.Vec = &tv + case ScValTypeScvMap: + tv, ok := value.(*ScMap) + if !ok { + err = fmt.Errorf("invalid value, must be *ScMap") + return + } + result.Map = &tv + case ScValTypeScvContractExecutable: + tv, ok := value.(ScContractExecutable) + if !ok { + err = fmt.Errorf("invalid value, must be ScContractExecutable") + return + } + result.Exec = &tv + case ScValTypeScvAddress: tv, ok := value.(ScAddress) if !ok { err = fmt.Errorf("invalid value, must be ScAddress") return } result.Address = &tv - case ScObjectTypeScoNonceKey: - tv, ok := value.(ScAddress) + case ScValTypeScvLedgerKeyContractExecutable: + // void + case ScValTypeScvLedgerKeyNonce: + tv, ok := value.(ScNonceKey) if !ok { - err = fmt.Errorf("invalid value, must be ScAddress") + err = fmt.Errorf("invalid value, must be ScNonceKey") return } - result.NonceAddress = &tv + result.NonceKey = &tv } return } -// MustVec retrieves the Vec value from the union, +// MustB retrieves the B value from the union, // panicing if the value is not set. -func (u ScObject) MustVec() ScVec { - val, ok := u.GetVec() +func (u ScVal) MustB() bool { + val, ok := u.GetB() if !ok { - panic("arm Vec is not set") + panic("arm B is not set") } return val } -// GetVec retrieves the Vec value from the union, +// GetB retrieves the B value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ScObject) GetVec() (result ScVec, ok bool) { +func (u ScVal) GetB() (result bool, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) - if armName == "Vec" { - result = *u.Vec + if armName == "B" { + result = *u.B ok = true } return } -// MustMap retrieves the Map value from the union, +// MustError retrieves the Error value from the union, // panicing if the value is not set. -func (u ScObject) MustMap() ScMap { - val, ok := u.GetMap() +func (u ScVal) MustError() ScStatus { + val, ok := u.GetError() if !ok { - panic("arm Map is not set") + panic("arm Error is not set") } return val } -// GetMap retrieves the Map value from the union, +// GetError retrieves the Error value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ScObject) GetMap() (result ScMap, ok bool) { +func (u ScVal) GetError() (result ScStatus, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) - if armName == "Map" { - result = *u.Map + if armName == "Error" { + result = *u.Error + ok = true + } + + return +} + +// MustU32 retrieves the U32 value from the union, +// panicing if the value is not set. +func (u ScVal) MustU32() Uint32 { + val, ok := u.GetU32() + + if !ok { + panic("arm U32 is not set") + } + + return val +} + +// GetU32 retrieves the U32 value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScVal) GetU32() (result Uint32, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "U32" { + result = *u.U32 + ok = true + } + + return +} + +// MustI32 retrieves the I32 value from the union, +// panicing if the value is not set. +func (u ScVal) MustI32() Int32 { + val, ok := u.GetI32() + + if !ok { + panic("arm I32 is not set") + } + + return val +} + +// GetI32 retrieves the I32 value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScVal) GetI32() (result Int32, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "I32" { + result = *u.I32 ok = true } @@ -50578,7 +50507,7 @@ func (u ScObject) GetMap() (result ScMap, ok bool) { // MustU64 retrieves the U64 value from the union, // panicing if the value is not set. -func (u ScObject) MustU64() Uint64 { +func (u ScVal) MustU64() Uint64 { val, ok := u.GetU64() if !ok { @@ -50590,7 +50519,7 @@ func (u ScObject) MustU64() Uint64 { // GetU64 retrieves the U64 value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ScObject) GetU64() (result Uint64, ok bool) { +func (u ScVal) GetU64() (result Uint64, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "U64" { @@ -50603,7 +50532,7 @@ func (u ScObject) GetU64() (result Uint64, ok bool) { // MustI64 retrieves the I64 value from the union, // panicing if the value is not set. -func (u ScObject) MustI64() Int64 { +func (u ScVal) MustI64() Int64 { val, ok := u.GetI64() if !ok { @@ -50615,7 +50544,7 @@ func (u ScObject) MustI64() Int64 { // GetI64 retrieves the I64 value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ScObject) GetI64() (result Int64, ok bool) { +func (u ScVal) GetI64() (result Int64, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "I64" { @@ -50626,9 +50555,59 @@ func (u ScObject) GetI64() (result Int64, ok bool) { return } +// MustTimepoint retrieves the Timepoint value from the union, +// panicing if the value is not set. +func (u ScVal) MustTimepoint() TimePoint { + val, ok := u.GetTimepoint() + + if !ok { + panic("arm Timepoint is not set") + } + + return val +} + +// GetTimepoint retrieves the Timepoint value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScVal) GetTimepoint() (result TimePoint, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "Timepoint" { + result = *u.Timepoint + ok = true + } + + return +} + +// MustDuration retrieves the Duration value from the union, +// panicing if the value is not set. +func (u ScVal) MustDuration() Duration { + val, ok := u.GetDuration() + + if !ok { + panic("arm Duration is not set") + } + + return val +} + +// GetDuration retrieves the Duration value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScVal) GetDuration() (result Duration, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "Duration" { + result = *u.Duration + ok = true + } + + return +} + // MustU128 retrieves the U128 value from the union, // panicing if the value is not set. -func (u ScObject) MustU128() Int128Parts { +func (u ScVal) MustU128() Int128Parts { val, ok := u.GetU128() if !ok { @@ -50640,7 +50619,7 @@ func (u ScObject) MustU128() Int128Parts { // GetU128 retrieves the U128 value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ScObject) GetU128() (result Int128Parts, ok bool) { +func (u ScVal) GetU128() (result Int128Parts, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "U128" { @@ -50653,7 +50632,7 @@ func (u ScObject) GetU128() (result Int128Parts, ok bool) { // MustI128 retrieves the I128 value from the union, // panicing if the value is not set. -func (u ScObject) MustI128() Int128Parts { +func (u ScVal) MustI128() Int128Parts { val, ok := u.GetI128() if !ok { @@ -50665,7 +50644,7 @@ func (u ScObject) MustI128() Int128Parts { // GetI128 retrieves the I128 value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ScObject) GetI128() (result Int128Parts, ok bool) { +func (u ScVal) GetI128() (result Int128Parts, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "I128" { @@ -50676,50 +50655,200 @@ func (u ScObject) GetI128() (result Int128Parts, ok bool) { return } -// MustBin retrieves the Bin value from the union, +// MustU256 retrieves the U256 value from the union, // panicing if the value is not set. -func (u ScObject) MustBin() []byte { - val, ok := u.GetBin() +func (u ScVal) MustU256() Uint256 { + val, ok := u.GetU256() if !ok { - panic("arm Bin is not set") + panic("arm U256 is not set") } return val } -// GetBin retrieves the Bin value from the union, +// GetU256 retrieves the U256 value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ScObject) GetBin() (result []byte, ok bool) { +func (u ScVal) GetU256() (result Uint256, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) - if armName == "Bin" { - result = *u.Bin + if armName == "U256" { + result = *u.U256 ok = true } return } -// MustContractCode retrieves the ContractCode value from the union, +// MustI256 retrieves the I256 value from the union, // panicing if the value is not set. -func (u ScObject) MustContractCode() ScContractCode { - val, ok := u.GetContractCode() +func (u ScVal) MustI256() Uint256 { + val, ok := u.GetI256() if !ok { - panic("arm ContractCode is not set") + panic("arm I256 is not set") } return val } -// GetContractCode retrieves the ContractCode value from the union, +// GetI256 retrieves the I256 value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ScObject) GetContractCode() (result ScContractCode, ok bool) { +func (u ScVal) GetI256() (result Uint256, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) - if armName == "ContractCode" { - result = *u.ContractCode + if armName == "I256" { + result = *u.I256 + ok = true + } + + return +} + +// MustBytes retrieves the Bytes value from the union, +// panicing if the value is not set. +func (u ScVal) MustBytes() ScBytes { + val, ok := u.GetBytes() + + if !ok { + panic("arm Bytes is not set") + } + + return val +} + +// GetBytes retrieves the Bytes value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScVal) GetBytes() (result ScBytes, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "Bytes" { + result = *u.Bytes + ok = true + } + + return +} + +// MustStr retrieves the Str value from the union, +// panicing if the value is not set. +func (u ScVal) MustStr() ScString { + val, ok := u.GetStr() + + if !ok { + panic("arm Str is not set") + } + + return val +} + +// GetStr retrieves the Str value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScVal) GetStr() (result ScString, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "Str" { + result = *u.Str + ok = true + } + + return +} + +// MustSym retrieves the Sym value from the union, +// panicing if the value is not set. +func (u ScVal) MustSym() ScSymbol { + val, ok := u.GetSym() + + if !ok { + panic("arm Sym is not set") + } + + return val +} + +// GetSym retrieves the Sym value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScVal) GetSym() (result ScSymbol, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "Sym" { + result = *u.Sym + ok = true + } + + return +} + +// MustVec retrieves the Vec value from the union, +// panicing if the value is not set. +func (u ScVal) MustVec() *ScVec { + val, ok := u.GetVec() + + if !ok { + panic("arm Vec is not set") + } + + return val +} + +// GetVec retrieves the Vec value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScVal) GetVec() (result *ScVec, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "Vec" { + result = *u.Vec + ok = true + } + + return +} + +// MustMap retrieves the Map value from the union, +// panicing if the value is not set. +func (u ScVal) MustMap() *ScMap { + val, ok := u.GetMap() + + if !ok { + panic("arm Map is not set") + } + + return val +} + +// GetMap retrieves the Map value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScVal) GetMap() (result *ScMap, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "Map" { + result = *u.Map + ok = true + } + + return +} + +// MustExec retrieves the Exec value from the union, +// panicing if the value is not set. +func (u ScVal) MustExec() ScContractExecutable { + val, ok := u.GetExec() + + if !ok { + panic("arm Exec is not set") + } + + return val +} + +// GetExec retrieves the Exec value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ScVal) GetExec() (result ScContractExecutable, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "Exec" { + result = *u.Exec ok = true } @@ -50728,7 +50857,7 @@ func (u ScObject) GetContractCode() (result ScContractCode, ok bool) { // MustAddress retrieves the Address value from the union, // panicing if the value is not set. -func (u ScObject) MustAddress() ScAddress { +func (u ScVal) MustAddress() ScAddress { val, ok := u.GetAddress() if !ok { @@ -50740,7 +50869,7 @@ func (u ScObject) MustAddress() ScAddress { // GetAddress retrieves the Address value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ScObject) GetAddress() (result ScAddress, ok bool) { +func (u ScVal) GetAddress() (result ScAddress, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Address" { @@ -50751,25 +50880,25 @@ func (u ScObject) GetAddress() (result ScAddress, ok bool) { return } -// MustNonceAddress retrieves the NonceAddress value from the union, +// MustNonceKey retrieves the NonceKey value from the union, // panicing if the value is not set. -func (u ScObject) MustNonceAddress() ScAddress { - val, ok := u.GetNonceAddress() +func (u ScVal) MustNonceKey() ScNonceKey { + val, ok := u.GetNonceKey() if !ok { - panic("arm NonceAddress is not set") + panic("arm NonceKey is not set") } return val } -// GetNonceAddress retrieves the NonceAddress value from the union, +// GetNonceKey retrieves the NonceKey value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ScObject) GetNonceAddress() (result ScAddress, ok bool) { +func (u ScVal) GetNonceKey() (result ScNonceKey, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) - if armName == "NonceAddress" { - result = *u.NonceAddress + if armName == "NonceKey" { + result = *u.NonceKey ok = true } @@ -50777,95 +50906,180 @@ func (u ScObject) GetNonceAddress() (result ScAddress, ok bool) { } // EncodeTo encodes this value using the Encoder. -func (u ScObject) EncodeTo(e *xdr.Encoder) error { +func (u ScVal) EncodeTo(e *xdr.Encoder) error { var err error if err = u.Type.EncodeTo(e); err != nil { return err } - switch ScObjectType(u.Type) { - case ScObjectTypeScoVec: - if err = (*u.Vec).EncodeTo(e); err != nil { + switch ScValType(u.Type) { + case ScValTypeScvBool: + if _, err = e.EncodeBool(bool((*u.B))); err != nil { return err } return nil - case ScObjectTypeScoMap: - if err = (*u.Map).EncodeTo(e); err != nil { + case ScValTypeScvVoid: + // Void + return nil + case ScValTypeScvStatus: + if err = (*u.Error).EncodeTo(e); err != nil { + return err + } + return nil + case ScValTypeScvU32: + if err = (*u.U32).EncodeTo(e); err != nil { return err } return nil - case ScObjectTypeScoU64: + case ScValTypeScvI32: + if err = (*u.I32).EncodeTo(e); err != nil { + return err + } + return nil + case ScValTypeScvU64: if err = (*u.U64).EncodeTo(e); err != nil { return err } return nil - case ScObjectTypeScoI64: + case ScValTypeScvI64: if err = (*u.I64).EncodeTo(e); err != nil { return err } return nil - case ScObjectTypeScoU128: + case ScValTypeScvTimepoint: + if err = (*u.Timepoint).EncodeTo(e); err != nil { + return err + } + return nil + case ScValTypeScvDuration: + if err = (*u.Duration).EncodeTo(e); err != nil { + return err + } + return nil + case ScValTypeScvU128: if err = (*u.U128).EncodeTo(e); err != nil { return err } return nil - case ScObjectTypeScoI128: + case ScValTypeScvI128: if err = (*u.I128).EncodeTo(e); err != nil { return err } return nil - case ScObjectTypeScoBytes: - if _, err = e.EncodeOpaque((*u.Bin)[:]); err != nil { + case ScValTypeScvU256: + if err = (*u.U256).EncodeTo(e); err != nil { return err } return nil - case ScObjectTypeScoContractCode: - if err = (*u.ContractCode).EncodeTo(e); err != nil { + case ScValTypeScvI256: + if err = (*u.I256).EncodeTo(e); err != nil { + return err + } + return nil + case ScValTypeScvBytes: + if err = (*u.Bytes).EncodeTo(e); err != nil { + return err + } + return nil + case ScValTypeScvString: + if err = (*u.Str).EncodeTo(e); err != nil { + return err + } + return nil + case ScValTypeScvSymbol: + if err = (*u.Sym).EncodeTo(e); err != nil { + return err + } + return nil + case ScValTypeScvVec: + if _, err = e.EncodeBool((*u.Vec) != nil); err != nil { return err } + if (*u.Vec) != nil { + if err = (*(*u.Vec)).EncodeTo(e); err != nil { + return err + } + } return nil - case ScObjectTypeScoAddress: + case ScValTypeScvMap: + if _, err = e.EncodeBool((*u.Map) != nil); err != nil { + return err + } + if (*u.Map) != nil { + if err = (*(*u.Map)).EncodeTo(e); err != nil { + return err + } + } + return nil + case ScValTypeScvContractExecutable: + if err = (*u.Exec).EncodeTo(e); err != nil { + return err + } + return nil + case ScValTypeScvAddress: if err = (*u.Address).EncodeTo(e); err != nil { return err } return nil - case ScObjectTypeScoNonceKey: - if err = (*u.NonceAddress).EncodeTo(e); err != nil { + case ScValTypeScvLedgerKeyContractExecutable: + // Void + return nil + case ScValTypeScvLedgerKeyNonce: + if err = (*u.NonceKey).EncodeTo(e); err != nil { return err } return nil } - return fmt.Errorf("Type (ScObjectType) switch value '%d' is not valid for union ScObject", u.Type) + return fmt.Errorf("Type (ScValType) switch value '%d' is not valid for union ScVal", u.Type) } -var _ decoderFrom = (*ScObject)(nil) +var _ decoderFrom = (*ScVal)(nil) // DecodeFrom decodes this value using the Decoder. -func (u *ScObject) DecodeFrom(d *xdr.Decoder) (int, error) { +func (u *ScVal) DecodeFrom(d *xdr.Decoder) (int, error) { var err error var n, nTmp int nTmp, err = u.Type.DecodeFrom(d) n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScObjectType: %s", err) + return n, fmt.Errorf("decoding ScValType: %s", err) } - switch ScObjectType(u.Type) { - case ScObjectTypeScoVec: - u.Vec = new(ScVec) - nTmp, err = (*u.Vec).DecodeFrom(d) + switch ScValType(u.Type) { + case ScValTypeScvBool: + u.B = new(bool) + (*u.B), nTmp, err = d.DecodeBool() n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScVec: %s", err) + return n, fmt.Errorf("decoding Bool: %s", err) } return n, nil - case ScObjectTypeScoMap: - u.Map = new(ScMap) - nTmp, err = (*u.Map).DecodeFrom(d) + case ScValTypeScvVoid: + // Void + return n, nil + case ScValTypeScvStatus: + u.Error = new(ScStatus) + nTmp, err = (*u.Error).DecodeFrom(d) n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScMap: %s", err) + return n, fmt.Errorf("decoding ScStatus: %s", err) + } + return n, nil + case ScValTypeScvU32: + u.U32 = new(Uint32) + nTmp, err = (*u.U32).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding Uint32: %s", err) + } + return n, nil + case ScValTypeScvI32: + u.I32 = new(Int32) + nTmp, err = (*u.I32).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding Int32: %s", err) } return n, nil - case ScObjectTypeScoU64: + case ScValTypeScvU64: u.U64 = new(Uint64) nTmp, err = (*u.U64).DecodeFrom(d) n += nTmp @@ -50873,7 +51087,7 @@ func (u *ScObject) DecodeFrom(d *xdr.Decoder) (int, error) { return n, fmt.Errorf("decoding Uint64: %s", err) } return n, nil - case ScObjectTypeScoI64: + case ScValTypeScvI64: u.I64 = new(Int64) nTmp, err = (*u.I64).DecodeFrom(d) n += nTmp @@ -50881,7 +51095,23 @@ func (u *ScObject) DecodeFrom(d *xdr.Decoder) (int, error) { return n, fmt.Errorf("decoding Int64: %s", err) } return n, nil - case ScObjectTypeScoU128: + case ScValTypeScvTimepoint: + u.Timepoint = new(TimePoint) + nTmp, err = (*u.Timepoint).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding TimePoint: %s", err) + } + return n, nil + case ScValTypeScvDuration: + u.Duration = new(Duration) + nTmp, err = (*u.Duration).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding Duration: %s", err) + } + return n, nil + case ScValTypeScvU128: u.U128 = new(Int128Parts) nTmp, err = (*u.U128).DecodeFrom(d) n += nTmp @@ -50889,7 +51119,7 @@ func (u *ScObject) DecodeFrom(d *xdr.Decoder) (int, error) { return n, fmt.Errorf("decoding Int128Parts: %s", err) } return n, nil - case ScObjectTypeScoI128: + case ScValTypeScvI128: u.I128 = new(Int128Parts) nTmp, err = (*u.I128).DecodeFrom(d) n += nTmp @@ -50897,23 +51127,91 @@ func (u *ScObject) DecodeFrom(d *xdr.Decoder) (int, error) { return n, fmt.Errorf("decoding Int128Parts: %s", err) } return n, nil - case ScObjectTypeScoBytes: - u.Bin = new([]byte) - (*u.Bin), nTmp, err = d.DecodeOpaque(256000) + case ScValTypeScvU256: + u.U256 = new(Uint256) + nTmp, err = (*u.U256).DecodeFrom(d) n += nTmp if err != nil { - return n, fmt.Errorf("decoding Bin: %s", err) + return n, fmt.Errorf("decoding Uint256: %s", err) } return n, nil - case ScObjectTypeScoContractCode: - u.ContractCode = new(ScContractCode) - nTmp, err = (*u.ContractCode).DecodeFrom(d) + case ScValTypeScvI256: + u.I256 = new(Uint256) + nTmp, err = (*u.I256).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding Uint256: %s", err) + } + return n, nil + case ScValTypeScvBytes: + u.Bytes = new(ScBytes) + nTmp, err = (*u.Bytes).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding ScBytes: %s", err) + } + return n, nil + case ScValTypeScvString: + u.Str = new(ScString) + nTmp, err = (*u.Str).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding ScString: %s", err) + } + return n, nil + case ScValTypeScvSymbol: + u.Sym = new(ScSymbol) + nTmp, err = (*u.Sym).DecodeFrom(d) n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScContractCode: %s", err) + return n, fmt.Errorf("decoding ScSymbol: %s", err) } return n, nil - case ScObjectTypeScoAddress: + case ScValTypeScvVec: + u.Vec = new(*ScVec) + var b bool + b, nTmp, err = d.DecodeBool() + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding ScVec: %s", err) + } + (*u.Vec) = nil + if b { + (*u.Vec) = new(ScVec) + nTmp, err = (*u.Vec).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding ScVec: %s", err) + } + } + return n, nil + case ScValTypeScvMap: + u.Map = new(*ScMap) + var b bool + b, nTmp, err = d.DecodeBool() + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding ScMap: %s", err) + } + (*u.Map) = nil + if b { + (*u.Map) = new(ScMap) + nTmp, err = (*u.Map).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding ScMap: %s", err) + } + } + return n, nil + case ScValTypeScvContractExecutable: + u.Exec = new(ScContractExecutable) + nTmp, err = (*u.Exec).DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding ScContractExecutable: %s", err) + } + return n, nil + case ScValTypeScvAddress: u.Address = new(ScAddress) nTmp, err = (*u.Address).DecodeFrom(d) n += nTmp @@ -50921,20 +51219,23 @@ func (u *ScObject) DecodeFrom(d *xdr.Decoder) (int, error) { return n, fmt.Errorf("decoding ScAddress: %s", err) } return n, nil - case ScObjectTypeScoNonceKey: - u.NonceAddress = new(ScAddress) - nTmp, err = (*u.NonceAddress).DecodeFrom(d) + case ScValTypeScvLedgerKeyContractExecutable: + // Void + return n, nil + case ScValTypeScvLedgerKeyNonce: + u.NonceKey = new(ScNonceKey) + nTmp, err = (*u.NonceKey).DecodeFrom(d) n += nTmp if err != nil { - return n, fmt.Errorf("decoding ScAddress: %s", err) + return n, fmt.Errorf("decoding ScNonceKey: %s", err) } return n, nil } - return n, fmt.Errorf("union ScObject has invalid Type (ScObjectType) switch value '%d'", u.Type) + return n, fmt.Errorf("union ScVal has invalid Type (ScValType) switch value '%d'", u.Type) } // MarshalBinary implements encoding.BinaryMarshaler. -func (s ScObject) MarshalBinary() ([]byte, error) { +func (s ScVal) MarshalBinary() ([]byte, error) { b := bytes.Buffer{} e := xdr.NewEncoder(&b) err := s.EncodeTo(e) @@ -50942,7 +51243,7 @@ func (s ScObject) MarshalBinary() ([]byte, error) { } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ScObject) UnmarshalBinary(inp []byte) error { +func (s *ScVal) UnmarshalBinary(inp []byte) error { r := bytes.NewReader(inp) d := xdr.NewDecoder(r) _, err := s.DecodeFrom(d) @@ -50950,15 +51251,85 @@ func (s *ScObject) UnmarshalBinary(inp []byte) error { } var ( - _ encoding.BinaryMarshaler = (*ScObject)(nil) - _ encoding.BinaryUnmarshaler = (*ScObject)(nil) + _ encoding.BinaryMarshaler = (*ScVal)(nil) + _ encoding.BinaryUnmarshaler = (*ScVal)(nil) ) // xdrType signals that this type is an type representing // representing XDR values defined by this package. -func (s ScObject) xdrType() {} +func (s ScVal) xdrType() {} + +var _ xdrType = (*ScVal)(nil) + +// ScMapEntry is an XDR Struct defines as: +// +// struct SCMapEntry +// { +// SCVal key; +// SCVal val; +// }; +type ScMapEntry struct { + Key ScVal + Val ScVal +} + +// EncodeTo encodes this value using the Encoder. +func (s *ScMapEntry) EncodeTo(e *xdr.Encoder) error { + var err error + if err = s.Key.EncodeTo(e); err != nil { + return err + } + if err = s.Val.EncodeTo(e); err != nil { + return err + } + return nil +} -var _ xdrType = (*ScObject)(nil) +var _ decoderFrom = (*ScMapEntry)(nil) + +// DecodeFrom decodes this value using the Decoder. +func (s *ScMapEntry) DecodeFrom(d *xdr.Decoder) (int, error) { + var err error + var n, nTmp int + nTmp, err = s.Key.DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding ScVal: %s", err) + } + nTmp, err = s.Val.DecodeFrom(d) + n += nTmp + if err != nil { + return n, fmt.Errorf("decoding ScVal: %s", err) + } + return n, nil +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s ScMapEntry) MarshalBinary() ([]byte, error) { + b := bytes.Buffer{} + e := xdr.NewEncoder(&b) + err := s.EncodeTo(e) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *ScMapEntry) UnmarshalBinary(inp []byte) error { + r := bytes.NewReader(inp) + d := xdr.NewDecoder(r) + _, err := s.DecodeFrom(d) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*ScMapEntry)(nil) + _ encoding.BinaryUnmarshaler = (*ScMapEntry)(nil) +) + +// xdrType signals that this type is an type representing +// representing XDR values defined by this package. +func (s ScMapEntry) xdrType() {} + +var _ xdrType = (*ScMapEntry)(nil) // StoredTransactionSet is an XDR Union defines as: //