diff --git a/.gitignore b/.gitignore index 7f54dd7162..853f99066a 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ debug *.index *.xdr *.db +xdr/testdata/benchmark-ledgers.xdr.zst *.conf *.lock .proto_checksums diff --git a/benchmarks/xdr_test.go b/benchmarks/xdr_test.go index f911d4d557..8c257def63 100644 --- a/benchmarks/xdr_test.go +++ b/benchmarks/xdr_test.go @@ -37,14 +37,10 @@ var gxdrInput = func() gxdr.TransactionEnvelope { }() func BenchmarkXDRUnmarshalWithReflection(b *testing.B) { - var ( - r bytes.Reader - te xdr.TransactionEnvelope - ) + var te xdr.TransactionEnvelope b.ReportAllocs() for i := 0; i < b.N; i++ { - r.Reset(input) - _, _ = xdr3.Unmarshal(&r, &te) + _, _ = xdr3.Unmarshal(input, &te) } } diff --git a/go.mod b/go.mod index 07fd6e1dba..712ff726ba 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/stellar/go-stellar-sdk go 1.24.0 +toolchain go1.24.9 + require ( cloud.google.com/go/storage v1.42.0 github.com/BurntSushi/toml v1.3.2 @@ -35,7 +37,7 @@ require ( github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.17.0 - github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2 + github.com/stellar/go-xdr v0.0.0-20260106211653-82e681bfd3f3 github.com/stretchr/testify v1.10.0 github.com/tyler-smith/go-bip39 v0.0.0-20180618194314-52158e4697b8 github.com/xdrpp/goxdr v0.1.1 diff --git a/go.sum b/go.sum index f927405c02..1a8e6225eb 100644 --- a/go.sum +++ b/go.sum @@ -453,8 +453,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI= github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI= -github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2 h1:OzCVd0SV5qE3ZcDeSFCmOWLZfEWZ3Oe8KtmSOYKEVWE= -github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps= +github.com/stellar/go-xdr v0.0.0-20260106211653-82e681bfd3f3 h1:uPJuFJUZl57C0I9/3ZPKXl5q6G8SskeVt9H5mJkaXXg= +github.com/stellar/go-xdr v0.0.0-20260106211653-82e681bfd3f3/go.mod h1:ZSIhPj0Ya41YoY0K4msNqwEQyJW/kCzjNAcZJH+uQO0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= diff --git a/historyarchive/archive_test.go b/historyarchive/archive_test.go index e3fbe50aa0..fce0402456 100644 --- a/historyarchive/archive_test.go +++ b/historyarchive/archive_test.go @@ -517,7 +517,7 @@ func TestXdrDecode(t *testing.T) { assert.Equal(t, len(xdrbytes), 152) var tmp xdr.BucketEntry - n, err := xdr.Unmarshal(bytes.NewReader(xdrbytes[:]), &tmp) + n, err := xdr.Unmarshal(xdrbytes[:], &tmp) fmt.Printf("Decoded %d bytes\n", n) if err != nil { panic(err) diff --git a/ingest/change_compactor_test.go b/ingest/change_compactor_test.go index 5e964109e9..926b2f97c6 100644 --- a/ingest/change_compactor_test.go +++ b/ingest/change_compactor_test.go @@ -428,9 +428,9 @@ func (s *TestChangeCompactorExistingRestoredSuite) SetupTest() { Type: xdr.ScAddressTypeScAddressTypeContract, ContractId: &xdr.ContractId{0xca, 0xfe}, }, - Key: xdr.ScVal{Type: xdr.ScValTypeScvBool, B: &val}, + Key: xdr.ScVal{Type: xdr.ScValTypeScvBool, B: val}, Durability: xdr.ContractDataDurabilityPersistent, - Val: xdr.ScVal{Type: xdr.ScValTypeScvBool, B: &val}, + Val: xdr.ScVal{Type: xdr.ScValTypeScvBool, B: val}, }, }, } diff --git a/ingest/change_test.go b/ingest/change_test.go index 9740fbfcfa..9271b1b76b 100644 --- a/ingest/change_test.go +++ b/ingest/change_test.go @@ -216,7 +216,6 @@ func TestSortChanges(t *testing.T) { } func createContractDataEntry() *xdr.ContractDataEntry { - scVal := true return &xdr.ContractDataEntry{ Contract: xdr.ScAddress{ Type: xdr.ScAddressTypeScAddressTypeContract, @@ -224,7 +223,7 @@ func createContractDataEntry() *xdr.ContractDataEntry { }, Key: xdr.ScVal{ Type: xdr.ScValTypeScvBool, - B: &scVal, + B: true, }, } } diff --git a/ingest/checkpoint_change_reader_test.go b/ingest/checkpoint_change_reader_test.go index e2f7993a42..1de115f437 100644 --- a/ingest/checkpoint_change_reader_test.go +++ b/ingest/checkpoint_change_reader_test.go @@ -79,10 +79,9 @@ func (s *CheckpointChangeReaderTestSuite) TearDownTest() { // TestSimple test reading buckets with a single live entry. func (s *CheckpointChangeReaderTestSuite) TestSimple() { meta := metaEntry(23) - liveType := xdr.BucketListTypeLive meta.MetaEntry.Ext = xdr.BucketMetadataExt{ V: 1, - BucketListType: &liveType, + BucketListType: xdr.BucketListTypeLive, } curr1 := createXdrStream( meta, @@ -117,10 +116,9 @@ func (s *CheckpointChangeReaderTestSuite) TestSimple() { func (s *CheckpointChangeReaderTestSuite) TestReadAfterClose() { meta := metaEntry(23) - liveType := xdr.BucketListTypeLive meta.MetaEntry.Ext = xdr.BucketMetadataExt{ V: 1, - BucketListType: &liveType, + BucketListType: xdr.BucketListTypeLive, } curr1 := createXdrStream( meta, @@ -169,10 +167,9 @@ func (s *CheckpointChangeReaderTestSuite) TestReadAfterClose() { func (s *CheckpointChangeReaderTestSuite) TestContextCanceled() { meta := metaEntry(23) - liveType := xdr.BucketListTypeLive meta.MetaEntry.Ext = xdr.BucketMetadataExt{ V: 1, - BucketListType: &liveType, + BucketListType: xdr.BucketListTypeLive, } curr1 := createXdrStream( meta, @@ -513,10 +510,9 @@ func (s *CheckpointChangeReaderTestSuite) TestMalformedProtocol11BucketNoMeta() // TestMalformedBucketListType ensures the checkpoint change reader asserts its reading from the live bucketlist func (s *CheckpointChangeReaderTestSuite) TestMalformedBucketListType() { meta := metaEntry(23) - hotArchiveType := xdr.BucketListTypeHotArchive meta.MetaEntry.Ext = xdr.BucketMetadataExt{ V: 1, - BucketListType: &hotArchiveType, + BucketListType: xdr.BucketListTypeHotArchive, } curr1 := createXdrStream( meta, diff --git a/ingest/hot_archive_iterator_test.go b/ingest/hot_archive_iterator_test.go index 858b3b3773..25dfe79ff0 100644 --- a/ingest/hot_archive_iterator_test.go +++ b/ingest/hot_archive_iterator_test.go @@ -109,14 +109,13 @@ var hasWithHotArchiveExample = `{ }` func hotArchiveMetaEntry(version uint32) xdr.HotArchiveBucketEntry { - listType := xdr.BucketListTypeHotArchive return xdr.HotArchiveBucketEntry{ Type: xdr.HotArchiveBucketEntryTypeHotArchiveMetaentry, MetaEntry: &xdr.BucketMetadata{ LedgerVersion: xdr.Uint32(version), Ext: xdr.BucketMetadataExt{ V: 1, - BucketListType: &listType, + BucketListType: xdr.BucketListTypeHotArchive, }, }, } @@ -383,7 +382,6 @@ func (h *HotArchiveIteratorTestSuite) TestMissingBucketListType() { } func (h *HotArchiveIteratorTestSuite) TestInvalidBucketListType() { - listType := xdr.BucketListTypeLive curr1 := createXdrStream( xdr.HotArchiveBucketEntry{ Type: xdr.HotArchiveBucketEntryTypeHotArchiveMetaentry, @@ -391,7 +389,7 @@ func (h *HotArchiveIteratorTestSuite) TestInvalidBucketListType() { LedgerVersion: xdr.Uint32(24), Ext: xdr.BucketMetadataExt{ V: 1, - BucketListType: &listType, + BucketListType: xdr.BucketListTypeLive, }, }, }, diff --git a/ingest/ledgerbackend/buffered_meta_pipe_reader.go b/ingest/ledgerbackend/buffered_meta_pipe_reader.go index f042f7aecc..d3ef2c8fe4 100644 --- a/ingest/ledgerbackend/buffered_meta_pipe_reader.go +++ b/ingest/ledgerbackend/buffered_meta_pipe_reader.go @@ -1,7 +1,7 @@ package ledgerbackend import ( - "bufio" + "bytes" "io" "time" @@ -54,29 +54,28 @@ type metaResult struct { // while previous ledger are being processed. // - Limits memory usage in case of large ledgers are closed by the network. // -// Internally, it keeps two buffers: bufio.Reader with binary ledger data and -// buffered channel with unmarshaled xdr.LedgerCloseMeta objects ready for -// processing. The first buffer removes overhead time connected to reading from -// a file. The second buffer allows unmarshaling binary data into XDR objects -// (which can be a bottleneck) while clients are processing previous ledgers. +// Internally, it reads framed XDR data directly into a reusable buffer and uses +// a reusable Decoder for optimized decoding. The buffered channel stores unmarshaled +// xdr.LedgerCloseMeta objects ready for processing, allowing unmarshaling to +// proceed while clients process previous ledgers. // // Finally, when a large ledger (larger than binary buffer) is closed it waits // until xdr.LedgerCloseMeta objects channel is empty. This prevents memory // exhaustion when network closes a series a large ledgers. type bufferedLedgerMetaReader struct { - r *bufio.Reader - c chan metaResult - decoder *xdr3.Decoder + r io.Reader + c chan metaResult + decoder *xdr3.Decoder + frameBuffer bytes.Buffer } // newBufferedLedgerMetaReader creates a new meta reader that will shutdown // when stellar-core terminates. func newBufferedLedgerMetaReader(reader io.Reader) *bufferedLedgerMetaReader { - r := bufio.NewReaderSize(reader, metaPipeBufferSize) return &bufferedLedgerMetaReader{ c: make(chan metaResult, ledgerReadAheadBufferSize), - r: r, - decoder: xdr3.NewDecoder(r), + r: reader, + decoder: xdr3.NewDecoder(nil), } } @@ -86,9 +85,12 @@ func newBufferedLedgerMetaReader(reader io.Reader) *bufferedLedgerMetaReader { // - The next ledger available in the buffer exceeds the meta pipe buffer size. // In such case the method will block until LedgerCloseMeta buffer is empty. func (b *bufferedLedgerMetaReader) readLedgerMetaFromPipe() (*xdr.LedgerCloseMeta, error) { - frameLength, err := xdr.ReadFrameLength(b.decoder) + frameLength, err := xdr.ReadFrameLength(b.r) if err != nil { - return nil, errors.Wrap(err, "error reading frame length") + if err == io.EOF { + return nil, err + } + return nil, errors.Wrap(err, "reading frame length") } for frameLength > metaPipeBufferSize && len(b.c) > 0 { @@ -96,11 +98,28 @@ func (b *bufferedLedgerMetaReader) readLedgerMetaFromPipe() (*xdr.LedgerCloseMet <-time.After(time.Second) } + // Read frame data directly into reusable buffer + b.frameBuffer.Reset() + b.frameBuffer.Grow(int(frameLength)) + n, err := b.frameBuffer.ReadFrom(io.LimitReader(b.r, int64(frameLength))) + if err != nil { + return nil, errors.Wrap(err, "reading frame data") + } + if n != int64(frameLength) { + return nil, errors.Errorf("read %d bytes, expected %d", n, frameLength) + } + + // Decode using reusable Decoder for optimized performance var xlcm xdr.LedgerCloseMeta - _, err = xlcm.DecodeFrom(b.decoder, xdr3.DecodeDefaultMaxDepth) + b.decoder.Reset(b.frameBuffer.Bytes()) + bytesRead, err := b.decoder.Decode(&xlcm) if err != nil { return nil, errors.Wrap(err, "unmarshaling framed LedgerCloseMeta") } + if bytesRead != int(frameLength) { + return nil, errors.Errorf("unmarshaled %d bytes, expected %d", bytesRead, frameLength) + } + return &xlcm, nil } diff --git a/ingest/sac/contract_data.go b/ingest/sac/contract_data.go index cb51b0c84d..60fe4cc728 100644 --- a/ingest/sac/contract_data.go +++ b/ingest/sac/contract_data.go @@ -340,7 +340,7 @@ func metadataObjFromAsset(isNative bool, code, issuer string) (*xdr.ScMap, error }, Val: xdr.ScVal{ Type: xdr.ScValTypeScvU32, - U32: &decimalVal, + U32: decimalVal, }, }, xdr.ScMapEntry{ @@ -576,7 +576,7 @@ func BalanceInt128ToContractData(assetContractId, holderID [32]byte, amt xdr.Int }, Val: xdr.ScVal{ Type: xdr.ScValTypeScvBool, - B: &trueIc, + B: trueIc, }, }, xdr.ScMapEntry{ @@ -586,7 +586,7 @@ func BalanceInt128ToContractData(assetContractId, holderID [32]byte, amt xdr.Int }, Val: xdr.ScVal{ Type: xdr.ScValTypeScvBool, - B: &trueIc, + B: trueIc, }, }, } diff --git a/processors/token_transfer/contract_events_test.go b/processors/token_transfer/contract_events_test.go index 7a9d460f8d..2125426d0d 100644 --- a/processors/token_transfer/contract_events_test.go +++ b/processors/token_transfer/contract_events_test.go @@ -4,9 +4,10 @@ import ( "fmt" "testing" + "google.golang.org/protobuf/proto" + "github.com/stellar/go-stellar-sdk/keypair" "github.com/stellar/go-stellar-sdk/strkey" - "google.golang.org/protobuf/proto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -136,7 +137,7 @@ func createScMap(keyValuePairs ...interface{}) xdr.ScVal { val := xdr.Uint64(v) valueScVal = xdr.ScVal{ Type: xdr.ScValTypeScvU64, - U64: &val, + U64: val, } default: panic(fmt.Sprintf("unsupported value type: %T", value)) @@ -1715,7 +1716,7 @@ func TestValidContractEventsV4(t *testing.T) { val := xdr.Uint64(id) muxedIdVal = xdr.ScVal{ Type: xdr.ScValTypeScvU64, - U64: &val, + U64: val, } case "text": text := tc.memoValue.(string) @@ -2009,7 +2010,7 @@ func TestV4InvalidEvents(t *testing.T) { mapEntries := xdr.ScMap{ { Key: createSymbol("to_muxed_id"), - Val: xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &[]xdr.Uint64{12345}[0]}, + Val: xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: xdr.Uint64(12345)}, }, } diff --git a/processors/token_transfer/muxed_info.go b/processors/token_transfer/muxed_info.go index 8e3c7469c4..a51974d6ca 100644 --- a/processors/token_transfer/muxed_info.go +++ b/processors/token_transfer/muxed_info.go @@ -13,7 +13,7 @@ func NewMuxedInfoFromMemo(m xdr.Memo) *MuxedInfo { case xdr.MemoTypeMemoNone: return nil case xdr.MemoTypeMemoId: - id := uint64(*m.Id) + id := uint64(m.Id) return NewMuxedInfoFromId(id) case xdr.MemoTypeMemoText: protoMemo.Content = &MuxedInfo_Text{ diff --git a/processors/token_transfer/token_transfer_processor.go b/processors/token_transfer/token_transfer_processor.go index 51959549b2..5dafa74444 100644 --- a/processors/token_transfer/token_transfer_processor.go +++ b/processors/token_transfer/token_transfer_processor.go @@ -535,12 +535,13 @@ func (p *EventsProcessor) accountCreateEvents(tx ingest.LedgerTransaction, opInd func (p *EventsProcessor) mergeAccountEvents(tx ingest.LedgerTransaction, opIndex uint32, op xdr.Operation, result xdr.OperationResult) ([]*TokenTransferEvent, error) { res := result.Tr.MustAccountMergeResult() // If there is no transfer of XLM from source account to destination (i.e. src account is empty), then no need to generate a transfer event - if res.SourceAccountBalance == nil { + sourceBalance, ok := res.GetSourceAccountBalance() + if !ok { return nil, nil } opSrcAcc := operationSourceAccount(tx, op) destAcc := op.Body.MustDestination() - amt := amount.String64Raw(*res.SourceAccountBalance) + amt := amount.String64Raw(sourceBalance) event, err := p.mintOrBurnOrTransferEvent(tx, &opIndex, xlmAsset, opSrcAcc.Address(), destAcc.Address(), amt, true) if err != nil { return nil, err diff --git a/processors/token_transfer/token_transfer_processor_test.go b/processors/token_transfer/token_transfer_processor_test.go index 39b5ef1608..2242b2586a 100644 --- a/processors/token_transfer/token_transfer_processor_test.go +++ b/processors/token_transfer/token_transfer_processor_test.go @@ -954,7 +954,7 @@ func TestMergeAccountEvents(t *testing.T) { }, } - mergedAccountResultWithBalance := func(balance *xdr.Int64) xdr.OperationResult { + mergedAccountResultWithBalance := func(balance xdr.Int64) xdr.OperationResult { return xdr.OperationResult{ Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ @@ -966,13 +966,24 @@ func TestMergeAccountEvents(t *testing.T) { }, } } + mergedAccountResultNoBalance := func() xdr.OperationResult { + return xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeAccountMerge, + AccountMergeResult: &xdr.AccountMergeResult{ + Code: xdr.AccountMergeResultCodeAccountMergeNoAccount, + }, + }, + } + } hundredUnits := 100 * oneUnit tests := []testFixture{ { name: "successful account merge", tx: someTxV3(), op: mergeAccountOp, - opResult: mergedAccountResultWithBalance(&hundredUnits), + opResult: mergedAccountResultWithBalance(hundredUnits), expected: []*TokenTransferEvent{ transferEvent(protoAddressFromAccount(accountA), protoAddressFromAccount(accountB), unitsToStr(hundredUnits), xlmProtoAsset), }, @@ -981,7 +992,7 @@ func TestMergeAccountEvents(t *testing.T) { name: "empty account merge - no events", tx: someTxV3(), op: mergeAccountOp, - opResult: mergedAccountResultWithBalance(nil), + opResult: mergedAccountResultNoBalance(), expected: nil, }, } diff --git a/protocols/rpc/get_events_test.go b/protocols/rpc/get_events_test.go index 754a54124f..531030d5b3 100644 --- a/protocols/rpc/get_events_test.go +++ b/protocols/rpc/get_events_test.go @@ -189,10 +189,9 @@ func TestTopicFilterMatches(t *testing.T) { Type: xdr.ScValTypeScvSymbol, Sym: &transferSym, } - sixtyfour := xdr.Uint64(64) number := xdr.ScVal{ Type: xdr.ScValTypeScvU64, - U64: &sixtyfour, + U64: 64, } wildCardExactOne := WildCardExactOne for _, tc := range []struct { @@ -355,10 +354,9 @@ func TestTopicFilterMatchesFlexibleTopicLength(t *testing.T) { Type: xdr.ScValTypeScvSymbol, Sym: &transferSym, } - sixtyfour := xdr.Uint64(64) number := xdr.ScVal{ Type: xdr.ScValTypeScvU64, - U64: &sixtyfour, + U64: 64, } wildCardExactOne := WildCardExactOne wildCardZeroOrMore := WildCardZeroOrMore @@ -532,8 +530,7 @@ func TestTopicFilterJSON(t *testing.T) { require.NoError(t, json.Unmarshal([]byte("[\"**\"]"), &got)) require.Equal(t, TopicFilter{{Wildcard: &wildCardZeroOrMore}}, got) - sixtyfour := xdr.Uint64(64) - scval := xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &sixtyfour} + scval := xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: 64} scvalstr, err := xdr.MarshalBase64(scval) require.NoError(t, err) diff --git a/strkey/muxed_account.go b/strkey/muxed_account.go index 0460842a1a..a47d3e0321 100644 --- a/strkey/muxed_account.go +++ b/strkey/muxed_account.go @@ -84,10 +84,14 @@ func DecodeMuxedAccount(address string) (*MuxedAccount, error) { var muxed MuxedAccount copy(muxed.ed25519[:], raw[:32]) - _, err = xdr.Unmarshal(bytes.NewReader(raw[32:]), &muxed.id) + + // Decode uint64 using Decoder + d := xdr.NewDecoder(raw[32:]) + id, _, err := d.DecodeUhyper() if err != nil { - return nil, errors.Wrap(err, "can't marshall binary") + return nil, errors.Wrap(err, "can't unmarshal muxed id") } + muxed.id = id return &muxed, nil } diff --git a/strkey/signed_payload.go b/strkey/signed_payload.go index d51f5572b2..63f95ea757 100644 --- a/strkey/signed_payload.go +++ b/strkey/signed_payload.go @@ -66,15 +66,16 @@ func DecodeSignedPayload(address string) (*SignedPayload, error) { return nil, errors.Wrap(err, "invalid signed payload signer") } - payload := []byte{} - reader := bytes.NewBuffer(raw) - readBytes, err := xdr.Unmarshal(reader, &payload) + // Decode variable-length opaque using Decoder + d := xdr.NewDecoder(raw) + payload, _, err := d.DecodeOpaque(maxPayloadLen) if err != nil { return nil, errors.Wrap(err, "invalid signed payload") } - if len(raw) != readBytes || reader.Len() > 0 { - return nil, errors.New("invalid signed payload padding") + // Ensure all bytes were consumed + if d.Remaining() != 0 { + return nil, errors.Errorf("invalid signed payload: %d trailing bytes", d.Remaining()) } return NewSignedPayload(signer, payload) diff --git a/support/compressxdr/compress_xdr.go b/support/compressxdr/compress_xdr.go index 696dbf0800..5cfa8903f6 100644 --- a/support/compressxdr/compress_xdr.go +++ b/support/compressxdr/compress_xdr.go @@ -47,6 +47,12 @@ func (d XDRDecoder) ReadFrom(r io.Reader) (int64, error) { } defer zr.Close() - n, err := xdr.Unmarshal(zr, d.XdrPayload) - return int64(n), err + // Decompress to buffer first, then unmarshal + data, err := io.ReadAll(zr) + if err != nil { + return 0, err + } + + err = xdr.SafeUnmarshal(data, d.XdrPayload) + return int64(len(data)), err } diff --git a/txnbuild/create_claimable_balance.go b/txnbuild/create_claimable_balance.go index 5b59f2d039..8cb0b348b3 100644 --- a/txnbuild/create_claimable_balance.go +++ b/txnbuild/create_claimable_balance.go @@ -78,7 +78,7 @@ func BeforeAbsoluteTimePredicate(epochSeconds int64) xdr.ClaimPredicate { absBefore := xdr.Int64(epochSeconds) return xdr.ClaimPredicate{ Type: xdr.ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime, - AbsBefore: &absBefore, + AbsBefore: absBefore, } } @@ -91,7 +91,7 @@ func BeforeRelativeTimePredicate(secondsBefore int64) xdr.ClaimPredicate { relBefore := xdr.Int64(secondsBefore) return xdr.ClaimPredicate{ Type: xdr.ClaimPredicateTypeClaimPredicateBeforeRelativeTime, - RelBefore: &relBefore, + RelBefore: relBefore, } } diff --git a/txnbuild/invoke_host_function_test.go b/txnbuild/invoke_host_function_test.go index 72c841d72b..ce6b1b9e8b 100644 --- a/txnbuild/invoke_host_function_test.go +++ b/txnbuild/invoke_host_function_test.go @@ -105,7 +105,7 @@ func TestInvokeHostFunctionRoundTrip(t *testing.T) { Args: xdr.ScVec{ xdr.ScVal{ Type: xdr.ScValTypeScvI32, - I32: &val, + I32: val, }, }, }, @@ -123,7 +123,7 @@ func TestInvokeHostFunctionRoundTrip(t *testing.T) { SignatureExpirationLedger: 0, Signature: xdr.ScVal{ Type: xdr.ScValTypeScvI64, - I64: &i64, + I64: i64, }, }, }, @@ -139,7 +139,7 @@ func TestInvokeHostFunctionRoundTrip(t *testing.T) { Args: xdr.ScVec{ xdr.ScVal{ Type: xdr.ScValTypeScvI32, - I32: &val, + I32: val, }, }, }, @@ -184,7 +184,7 @@ func TestInvokeHostFunctionRoundTrip(t *testing.T) { }, Key: xdr.ScVal{ Type: xdr.ScValTypeScvI64, - I64: &i64, + I64: i64, }, }, }, diff --git a/xdr/account_id.go b/xdr/account_id.go index 3dd0abc6ab..e798deb2c9 100644 --- a/xdr/account_id.go +++ b/xdr/account_id.go @@ -122,12 +122,11 @@ func (aid *AccountId) SetAddress(address string) error { // ToMuxedAccount transforms an AccountId into a MuxedAccount with // a zero memo id func (aid *AccountId) ToMuxedAccount() MuxedAccount { - result := MuxedAccount{Type: CryptoKeyTypeKeyTypeEd25519} switch aid.Type { case PublicKeyTypePublicKeyTypeEd25519: - result.Ed25519 = aid.Ed25519 + result, _ := NewMuxedAccount(CryptoKeyTypeKeyTypeEd25519, *aid.Ed25519) + return result default: panic(fmt.Errorf("Unknown account id type: %v", aid.Type)) } - return result } diff --git a/xdr/asset.go b/xdr/asset.go index 5931b276af..ca74d5375e 100644 --- a/xdr/asset.go +++ b/xdr/asset.go @@ -47,24 +47,19 @@ func MustNewCreditAsset(code string, issuer string) Asset { // NewAssetCodeFromString returns a new credit asset, erroring if it can't. func NewAssetCodeFromString(code string) (AssetCode, error) { - a := AssetCode{} length := len(code) switch { case length >= 1 && length <= 4: var newCode AssetCode4 copy(newCode[:], []byte(code)[:length]) - a.Type = AssetTypeAssetTypeCreditAlphanum4 - a.AssetCode4 = &newCode + return NewAssetCode(AssetTypeAssetTypeCreditAlphanum4, newCode) case length >= 5 && length <= 12: var newCode AssetCode12 copy(newCode[:], []byte(code)[:length]) - a.Type = AssetTypeAssetTypeCreditAlphanum12 - a.AssetCode12 = &newCode + return NewAssetCode(AssetTypeAssetTypeCreditAlphanum12, newCode) default: - return a, errors.New("Asset code length is invalid") + return AssetCode{}, errors.New("Asset code length is invalid") } - - return a, nil } // MustNewAssetCodeFromString returns a new allow trust asset, panicking if it can't. diff --git a/xdr/claim_atom.go b/xdr/claim_atom.go index 2d29142217..2aafe8cee8 100644 --- a/xdr/claim_atom.go +++ b/xdr/claim_atom.go @@ -22,10 +22,8 @@ func (a ClaimAtom) OfferId() Int64 { func (a ClaimAtom) SellerId() AccountId { switch a.Type { case ClaimAtomTypeClaimAtomTypeV0: - return AccountId{ - Type: PublicKeyTypePublicKeyTypeEd25519, - Ed25519: &a.V0.SellerEd25519, - } + aid, _ := NewAccountId(PublicKeyTypePublicKeyTypeEd25519, a.V0.SellerEd25519) + return aid case ClaimAtomTypeClaimAtomTypeOrderBook: return a.OrderBook.SellerId case ClaimAtomTypeClaimAtomTypeLiquidityPool: diff --git a/xdr/claimable_balance_id.go b/xdr/claimable_balance_id.go index 53154d1a63..ada6ba04b7 100644 --- a/xdr/claimable_balance_id.go +++ b/xdr/claimable_balance_id.go @@ -59,8 +59,8 @@ func (c *ClaimableBalanceId) DecodeFromStrkey(address string) error { if ClaimableBalanceIdType(payload[0]) != ClaimableBalanceIdTypeClaimableBalanceIdTypeV0 { return fmt.Errorf("invalid claimable balance id type: %v", payload[0]) } - c.Type = ClaimableBalanceIdTypeClaimableBalanceIdTypeV0 - c.V0 = &Hash{} - copy(c.V0[:], payload[1:]) - return nil + var h Hash + copy(h[:], payload[1:]) + *c, err = NewClaimableBalanceId(ClaimableBalanceIdTypeClaimableBalanceIdTypeV0, h) + return err } diff --git a/xdr/go_string.go b/xdr/go_string.go index aab6204adf..cc68b8ff2e 100644 --- a/xdr/go_string.go +++ b/xdr/go_string.go @@ -67,7 +67,7 @@ func (m Memo) GoString() string { case MemoTypeMemoText: return fmt.Sprintf(`xdr.MemoText(%#v)`, *m.Text) case MemoTypeMemoId: - return fmt.Sprintf(`xdr.MemoID(%d)`, *m.Id) + return fmt.Sprintf(`xdr.MemoID(%d)`, m.Id) case MemoTypeMemoHash: return fmt.Sprintf(`xdr.MemoHash(%#v)`, *m.Hash) case MemoTypeMemoReturn: diff --git a/xdr/go_string_test.go b/xdr/go_string_test.go index 3ad09a73b4..2b1ba6fd5f 100644 --- a/xdr/go_string_test.go +++ b/xdr/go_string_test.go @@ -45,14 +45,12 @@ func TestMemoGoStringerText(t *testing.T) { } func TestMemoGoStringerID(t *testing.T) { - id := xdr.Uint64(123) - memo := xdr.Memo{Type: xdr.MemoTypeMemoId, Id: &id} + memo := xdr.MemoID(123) assert.Equal(t, `xdr.MemoID(123)`, fmt.Sprintf("%#v", memo)) } func TestMemoGoStringerHash(t *testing.T) { - hash := xdr.Hash{0x7b} - memo := xdr.Memo{Type: xdr.MemoTypeMemoHash, Hash: &hash} + memo := xdr.MemoHash(xdr.Hash{0x7b}) assert.Equal( t, `xdr.MemoHash(xdr.Hash{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0})`, @@ -61,8 +59,7 @@ func TestMemoGoStringerHash(t *testing.T) { } func TestMemoGoStringerRetHash(t *testing.T) { - hash := xdr.Hash{0x7b} - memo := xdr.Memo{Type: xdr.MemoTypeMemoReturn, RetHash: &hash} + memo := xdr.MemoRetHash(xdr.Hash{0x7b}) assert.Equal( t, `xdr.MemoRetHash(xdr.Hash{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0})`, diff --git a/xdr/json.go b/xdr/json.go index 8e3ddc6cc9..7a779f8ef2 100644 --- a/xdr/json.go +++ b/xdr/json.go @@ -94,13 +94,15 @@ func (c claimPredicateJSON) toXDR() (ClaimPredicate, error) { case c.Unconditional: result.Type = ClaimPredicateTypeClaimPredicateUnconditional case c.RelBefore != nil: - relBefore := Int64(*c.RelBefore) - result.Type = ClaimPredicateTypeClaimPredicateBeforeRelativeTime - result.RelBefore = &relBefore + result, err = NewClaimPredicate(ClaimPredicateTypeClaimPredicateBeforeRelativeTime, Int64(*c.RelBefore)) + if err != nil { + return result, err + } case c.AbsBefore != nil: - absBefore := Int64(c.AbsBefore.UTC().Unix()) - result.Type = ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime - result.AbsBefore = &absBefore + result, err = NewClaimPredicate(ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime, Int64(c.AbsBefore.UTC().Unix())) + if err != nil { + return result, err + } case c.Not != nil: if inner, innerErr := c.Not.toXDR(); innerErr != nil { err = innerErr diff --git a/xdr/json_test.go b/xdr/json_test.go index 80b3e9bf5e..ce463a2a52 100644 --- a/xdr/json_test.go +++ b/xdr/json_test.go @@ -19,20 +19,17 @@ func TestClaimPredicateJSON(t *testing.T) { relBefore := Int64(12) absBefore := Int64(1598440539) + relBeforePred, _ := NewClaimPredicate(ClaimPredicateTypeClaimPredicateBeforeRelativeTime, relBefore) + absBeforePred, _ := NewClaimPredicate(ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime, absBefore) + source := ClaimPredicate{ Type: ClaimPredicateTypeClaimPredicateAnd, AndPredicates: &[]ClaimPredicate{ { Type: ClaimPredicateTypeClaimPredicateOr, OrPredicates: &[]ClaimPredicate{ - { - Type: ClaimPredicateTypeClaimPredicateBeforeRelativeTime, - RelBefore: &relBefore, - }, - { - Type: ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime, - AbsBefore: &absBefore, - }, + relBeforePred, + absBeforePred, }, }, { @@ -124,10 +121,7 @@ func TestAbsBeforeTimestamps(t *testing.T) { }, } { xdrSec := Int64(testCase.unix) - source := ClaimPredicate{ - Type: ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime, - AbsBefore: &xdrSec, - } + source, _ := NewClaimPredicate(ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime, xdrSec) serialized, err := json.Marshal(source) assert.NoError(t, err) @@ -135,7 +129,7 @@ func TestAbsBeforeTimestamps(t *testing.T) { var parsed ClaimPredicate assert.NoError(t, json.Unmarshal(serialized, &parsed)) - assert.Equal(t, *parsed.AbsBefore, *source.AbsBefore) + assert.Equal(t, parsed.AbsBefore, source.AbsBefore) } } diff --git a/xdr/main.go b/xdr/main.go index e0ea11bde1..ff7bb629c4 100644 --- a/xdr/main.go +++ b/xdr/main.go @@ -12,7 +12,7 @@ import ( "io" "strings" - xdr "github.com/stellar/go-xdr/xdr3" + xdr3 "github.com/stellar/go-xdr/xdr3" "github.com/stellar/go-stellar-sdk/support/errors" ) @@ -36,39 +36,25 @@ var OperationTypeToStringMap = operationTypeMap var LedgerEntryTypeMap = ledgerEntryTypeMap -func safeUnmarshalString(decoder func(reader io.Reader) io.Reader, options xdr.DecodeOptions, data string, dest interface{}) error { - count := &countWriter{} - l := len(data) - - _, err := UnmarshalWithOptions(decoder(io.TeeReader(strings.NewReader(data), count)), dest, options) +func safeUnmarshalString(decoder func(reader io.Reader) io.Reader, data string, dest interface{}) error { + // Decode the data using the provided decoder (base64 or hex) + decoded, err := io.ReadAll(decoder(strings.NewReader(data))) if err != nil { return err } - if count.Count != l { - return fmt.Errorf("input not fully consumed. expected to read: %d, actual: %d", l, count.Count) - } - - return nil -} - -func decodeOptionsWithMaxInputLen(maxInputLen int) xdr.DecodeOptions { - options := xdr.DefaultDecodeOptions - options.MaxInputLen = maxInputLen - return options + // Unmarshal and verify all bytes consumed + return SafeUnmarshal(decoded, dest) } // SafeUnmarshalBase64 first decodes the provided reader from base64 before // decoding the xdr into the provided destination. Also ensures that the reader // is fully consumed. func SafeUnmarshalBase64(data string, dest interface{}) error { - decodedLen := base64.StdEncoding.DecodedLen(len(data)) - options := decodeOptionsWithMaxInputLen(decodedLen) return safeUnmarshalString( func(r io.Reader) io.Reader { return base64.NewDecoder(base64.StdEncoding, r) }, - options, data, dest, ) @@ -78,16 +64,14 @@ func SafeUnmarshalBase64(data string, dest interface{}) error { // decoding the xdr into the provided destination. Also ensures that the reader // is fully consumed. func SafeUnmarshalHex(data string, dest interface{}) error { - decodedLen := hex.DecodedLen(len(data)) - options := decodeOptionsWithMaxInputLen(decodedLen) - return safeUnmarshalString(hex.NewDecoder, options, data, dest) + return safeUnmarshalString(hex.NewDecoder, data, dest) } // SafeUnmarshal decodes the provided reader into the destination and verifies // that provided bytes are all consumed by the unmarshaling process. +// Uses BufferDecoder for optimized decoding when the type supports it. func SafeUnmarshal(data []byte, dest interface{}) error { - r := bytes.NewReader(data) - n, err := Unmarshal(r, dest) + n, err := xdr3.Unmarshal(data, dest) if err != nil { return err @@ -100,31 +84,8 @@ func SafeUnmarshal(data []byte, dest interface{}) error { return nil } -type DecoderFrom interface { - decoderFrom -} - -// BytesDecoder efficiently manages a byte reader and an -// xdr decoder so that they don't need to be allocated in -// every decoding call. -type BytesDecoder struct { - decoder *xdr.Decoder - reader *bytes.Reader -} - -func NewBytesDecoder() *BytesDecoder { - reader := bytes.NewReader(nil) - decoder := xdr.NewDecoder(reader) - return &BytesDecoder{ - decoder: decoder, - reader: reader, - } -} - -func (d *BytesDecoder) DecodeBytes(v DecoderFrom, b []byte) (int, error) { - d.reader.Reset(b) - return v.DecodeFrom(d.decoder, xdr.DecodeDefaultMaxDepth) -} +// DecoderFrom is re-exported from go-xdr for convenience. +type DecoderFrom = xdr3.DecoderFrom func marshalString(encoder func([]byte) string, v interface{}) (string, error) { var raw bytes.Buffer @@ -150,7 +111,7 @@ func MarshalHex(v interface{}) (string, error) { // For that reason, it is not thread-safe. // It intentionally only allows EncodeTo method arguments, to guarantee high performance encoding. type EncodingBuffer struct { - encoder *xdr.Encoder + encoder *xdr3.Encoder xdrEncoderBuf bytes.Buffer scratchBuf []byte } @@ -166,12 +127,12 @@ func growSlice(old []byte, newSize int) []byte { } type EncoderTo interface { - EncodeTo(e *xdr.Encoder) error + EncodeTo(e *xdr3.Encoder) error } func NewEncodingBuffer() *EncodingBuffer { var ret EncodingBuffer - ret.encoder = xdr.NewEncoder(&ret.xdrEncoderBuf) + ret.encoder = xdr3.NewEncoder(&ret.xdrEncoderBuf) return &ret } @@ -293,28 +254,19 @@ func MarshalFramed(w io.Writer, v interface{}) error { return err } -// ReadFrameLength returns a length of a framed XDR object. -func ReadFrameLength(d *xdr.Decoder) (uint32, error) { - frameLen, n, e := d.DecodeUint() - if e != nil { - return 0, errors.Wrap(e, "unmarshaling XDR frame header") - } - if n != 4 { - return 0, errors.New("bad length of XDR frame header") +// ReadFrameLength reads and returns the length of a framed XDR object from the reader. +// The frame header is a 4-byte big-endian uint32 with the high bit set. +// Returns io.EOF directly (unwrapped) when end of stream is reached. +func ReadFrameLength(r io.Reader) (uint32, error) { + var frameHeader uint32 + if err := binary.Read(r, binary.BigEndian, &frameHeader); err != nil { + if err == io.EOF { + return 0, io.EOF + } + return 0, errors.Wrap(err, "reading XDR frame header") } - if (frameLen & 0x80000000) != 0x80000000 { + if (frameHeader & 0x80000000) != 0x80000000 { return 0, errors.New("malformed XDR frame header") } - frameLen &= 0x7fffffff - return frameLen, nil -} - -type countWriter struct { - Count int -} - -func (w *countWriter) Write(d []byte) (int, error) { - l := len(d) - w.Count += l - return l, nil + return frameHeader & 0x7fffffff, nil } diff --git a/xdr/main_test.go b/xdr/main_test.go index 3ee8c236b7..d6095f4cc7 100644 --- a/xdr/main_test.go +++ b/xdr/main_test.go @@ -4,7 +4,6 @@ import ( "encoding/base64" "fmt" "log" - "strings" "testing" "github.com/stellar/go-stellar-sdk/gxdr" @@ -21,11 +20,14 @@ import ( func ExampleUnmarshal() { data := "AAAAAgAAAABi/B0L0JGythwN1lY0aypo19NHxvLCyO5tBEcCVvwF9wAAAAoAAAAAAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAK6jei3jmoI8TGlD/egc37PXtHKKzWV8wViZBaCu5L5MAAAAADuaygAAAAAAAAAAAVb8BfcAAABACmeyD4/+Oj7llOmTrcjKLHLTQJF0TV/VggCOUZ30ZPgMsQy6A2T//Zdzb7MULVo/Y7kDrqAZRS51rvIp7YMUAA==" - rawr := strings.NewReader(data) - b64r := base64.NewDecoder(base64.StdEncoding, rawr) + // Decode base64 to bytes first + decoded, err := base64.StdEncoding.DecodeString(data) + if err != nil { + log.Fatal(err) + } var tx TransactionEnvelope - bytesRead, err := Unmarshal(b64r, &tx) + bytesRead, err := Unmarshal(decoded, &tx) fmt.Printf("read %d bytes\n", bytesRead) @@ -52,7 +54,7 @@ func TestSafeUnmarshalHex(t *testing.T) { var _ = Describe("xdr.SafeUnmarshal", func() { var ( - result int32 + result Int32 data []byte err error ) @@ -71,7 +73,7 @@ var _ = Describe("xdr.SafeUnmarshal", func() { }) It("decodes the data correctly", func() { - Expect(result).To(Equal(int32(1))) + Expect(result).To(Equal(Int32(1))) }) }) @@ -90,7 +92,7 @@ var _ = Describe("xdr.SafeUnmarshal", func() { var _ = Describe("xdr.SafeUnmarshalBase64", func() { var ( - result int32 + result Int32 data string err error ) @@ -109,7 +111,7 @@ var _ = Describe("xdr.SafeUnmarshalBase64", func() { }) It("decodes the data correctly", func() { - Expect(result).To(Equal(int32(1))) + Expect(result).To(Equal(Int32(1))) }) }) @@ -168,15 +170,15 @@ func TestLedgerKeyBinaryCompress(t *testing.T) { expectedOut: []byte{0x3, 0x0, 0x1d, 0x4, 0x9a, 0x80, 0xf, 0xda, 0x8f, 0xab, 0xe8, 0xf6, 0x9d, 0x10, 0xdd, 0x8d, 0xda, 0x79, 0x29, 0x5a, 0x14, 0x87, 0xca, 0xe2, 0x3e, 0x43, 0x4e, 0xf5, 0xab, 0x68, 0xec, 0x13, 0x6c, 0xf3, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72}, }, { - key: LedgerKey{ - Type: LedgerEntryTypeClaimableBalance, - ClaimableBalance: &LedgerKeyClaimableBalance{ - BalanceId: ClaimableBalanceId{ - Type: 0, - V0: &Hash{0xca, 0xfe, 0xba, 0xbe}, + key: func() LedgerKey { + cbId, _ := NewClaimableBalanceId(ClaimableBalanceIdTypeClaimableBalanceIdTypeV0, Hash{0xca, 0xfe, 0xba, 0xbe}) + return LedgerKey{ + Type: LedgerEntryTypeClaimableBalance, + ClaimableBalance: &LedgerKeyClaimableBalance{ + BalanceId: cbId, }, - }, - }, + } + }(), expectedOut: []byte{0x4, 0x0, 0xca, 0xfe, 0xba, 0xbe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, }, { diff --git a/xdr/memo.go b/xdr/memo.go index a412b73b2f..dec50581cc 100644 --- a/xdr/memo.go +++ b/xdr/memo.go @@ -1,18 +1,21 @@ package xdr func MemoText(text string) Memo { - return Memo{Type: MemoTypeMemoText, Text: &text} + m, _ := NewMemo(MemoTypeMemoText, text) + return m } func MemoID(id uint64) Memo { - idObj := Uint64(id) - return Memo{Type: MemoTypeMemoId, Id: &idObj} + m, _ := NewMemo(MemoTypeMemoId, Uint64(id)) + return m } func MemoHash(hash Hash) Memo { - return Memo{Type: MemoTypeMemoHash, Hash: &hash} + m, _ := NewMemo(MemoTypeMemoHash, hash) + return m } func MemoRetHash(hash Hash) Memo { - return Memo{Type: MemoTypeMemoReturn, RetHash: &hash} + m, _ := NewMemo(MemoTypeMemoReturn, hash) + return m } diff --git a/xdr/muxed_account.go b/xdr/muxed_account.go index 50aa0b7caa..dc0538d70b 100644 --- a/xdr/muxed_account.go +++ b/xdr/muxed_account.go @@ -177,16 +177,14 @@ func (m *MuxedAccount) GetId() (uint64, error) { // ToAccountId transforms a MuxedAccount to an AccountId, dropping the // memo Id if necessary func (m MuxedAccount) ToAccountId() AccountId { - result := AccountId{Type: PublicKeyTypePublicKeyTypeEd25519} switch m.Type { case CryptoKeyTypeKeyTypeEd25519: - ed := m.MustEd25519() - result.Ed25519 = &ed + result, _ := NewAccountId(PublicKeyTypePublicKeyTypeEd25519, m.MustEd25519()) + return result case CryptoKeyTypeKeyTypeMuxedEd25519: - ed := m.MustMed25519().Ed25519 - result.Ed25519 = &ed + result, _ := NewAccountId(PublicKeyTypePublicKeyTypeEd25519, m.MustMed25519().Ed25519) + return result default: panic(fmt.Errorf("Unknown muxed account type: %v", m.Type)) } - return result } diff --git a/xdr/pool.go b/xdr/pool.go new file mode 100644 index 0000000000..d28c98b41d --- /dev/null +++ b/xdr/pool.go @@ -0,0 +1,61 @@ +package xdr + +import "sync" + +// Pool provides type-safe object pooling for XDR types. +// +// Objects retrieved from the pool may contain data from previous use. +// The next decode operation will overwrite all fields, so explicit +// clearing is not required. +// +// Thread Safety: +// - Pool.Get() and Pool.Put() are safe for concurrent use +// - However, the objects themselves are NOT thread-safe +// - Do not access an object after calling Put() +// - Do not call Put() while another goroutine is using the object +// +// Example usage: +// +// var lcmPool = xdr.NewPool[LedgerCloseMeta]() +// +// func HandleRequest(data []byte) (*Result, error) { +// lcm := lcmPool.Get() +// defer lcmPool.Put(lcm) +// +// if _, err := xdr.SafeUnmarshal(data, lcm); err != nil { +// return nil, err +// } +// return process(lcm), nil +// } +type Pool[T any] struct { + pool sync.Pool +} + +// NewPool creates a new pool for type T. +func NewPool[T any]() *Pool[T] { + return &Pool[T]{ + pool: sync.Pool{ + New: func() any { return new(T) }, + }, + } +} + +// Get retrieves an object from the pool. +// +// The returned object may contain data from previous use. The caller +// should decode into it, which will overwrite all fields. +// +// The caller is responsible for calling Put() when done, unless +// ownership is transferred to another goroutine (in which case that +// goroutine must call Put()). +func (p *Pool[T]) Get() *T { + return p.pool.Get().(*T) +} + +// Put returns an object to the pool for reuse. +// +// WARNING: Do not use the object after calling Put(). +// WARNING: Do not call Put() if the object is being used by another goroutine. +func (p *Pool[T]) Put(v *T) { + p.pool.Put(v) +} diff --git a/xdr/pool_benchmark_test.go b/xdr/pool_benchmark_test.go new file mode 100644 index 0000000000..6459ed5379 --- /dev/null +++ b/xdr/pool_benchmark_test.go @@ -0,0 +1,429 @@ +package xdr + +import ( + "bytes" + "encoding/base64" + "encoding/json" + "fmt" + "io" + "net/http" + "os" + "runtime" + "sync/atomic" + "testing" + "time" + + "github.com/klauspost/compress/zstd" +) + +const ( + // testLedgersPath is the path to the cached multi-ledger test fixture. + testLedgersPath = "testdata/benchmark-ledgers.xdr.zst" + // defaultRPCURL is used to fetch ledgers if no fixture exists. + defaultRPCURL = "https://rpc.lightsail.network/" + // numLedgersToFetch is the number of ledgers to download from RPC. + numLedgersToFetch = 100 +) + +// loadTestLedgers loads multiple LedgerCloseMeta from test files. +// If no multi-ledger fixture exists and XDR_BENCHMARK_DOWNLOAD=1 is set, +// it downloads ledgers from a public RPC. Otherwise falls back to single ledger. +func loadTestLedgers(tb testing.TB) [][]byte { + // Try to load from cached zstd file + ledgers := loadLedgersFromZstd(tb, testLedgersPath) + if len(ledgers) > 0 { + return ledgers + } + + // No fixture found - check if download is enabled + if os.Getenv("XDR_BENCHMARK_DOWNLOAD") == "1" { + tb.Logf("no fixture at %s, downloading from RPC...", testLedgersPath) + if err := downloadLedgersFixture(tb, testLedgersPath); err != nil { + tb.Logf("failed to download ledgers: %v", err) + } else { + // Try loading again after download + ledgers = loadLedgersFromZstd(tb, testLedgersPath) + if len(ledgers) > 0 { + return ledgers + } + } + } + + // Fall back to single ledger file + data, err := os.ReadFile("testdata/ledger_close_meta.xdr") + if err != nil { + tb.Skipf("no test data available (set XDR_BENCHMARK_DOWNLOAD=1 to fetch from RPC)") + } + return [][]byte{data} +} + +// rpcRequest is a JSON-RPC 2.0 request. +type rpcRequest struct { + JSONRPC string `json:"jsonrpc"` + ID int `json:"id"` + Method string `json:"method"` + Params any `json:"params,omitempty"` +} + +// rpcResponse is a JSON-RPC 2.0 response. +type rpcResponse struct { + JSONRPC string `json:"jsonrpc"` + ID int `json:"id"` + Result json.RawMessage `json:"result,omitempty"` + Error *rpcError `json:"error,omitempty"` +} + +type rpcError struct { + Code int `json:"code"` + Message string `json:"message"` +} + +// getLedgersParams are the parameters for getLedgers RPC method. +type getLedgersParams struct { + StartLedger uint32 `json:"startLedger,omitempty"` + Pagination *ledgerPaginationOpts `json:"pagination,omitempty"` + Format string `json:"xdrFormat,omitempty"` +} + +type ledgerPaginationOpts struct { + Cursor string `json:"cursor,omitempty"` + Limit uint `json:"limit,omitempty"` +} + +// getLedgersResult is the result of getLedgers RPC method. +type getLedgersResult struct { + Ledgers []ledgerInfo `json:"ledgers"` + Cursor string `json:"cursor"` +} + +type ledgerInfo struct { + Sequence uint32 `json:"sequence"` + LedgerMetadata string `json:"metadataXdr"` +} + +// getLatestLedgerResult is the result of getLatestLedger RPC method. +type getLatestLedgerResult struct { + Sequence uint32 `json:"sequence"` +} + +// callRPC makes a JSON-RPC call to the given URL. +func callRPC(url, method string, params any, result any) error { + reqBody, err := json.Marshal(rpcRequest{ + JSONRPC: "2.0", + ID: 1, + Method: method, + Params: params, + }) + if err != nil { + return err + } + + client := &http.Client{Timeout: 30 * time.Second} + resp, err := client.Post(url, "application/json", bytes.NewReader(reqBody)) + if err != nil { + return err + } + defer resp.Body.Close() + + var rpcResp rpcResponse + if err := json.NewDecoder(resp.Body).Decode(&rpcResp); err != nil { + return err + } + + if rpcResp.Error != nil { + return fmt.Errorf("RPC error %d: %s", rpcResp.Error.Code, rpcResp.Error.Message) + } + + return json.Unmarshal(rpcResp.Result, result) +} + +// downloadLedgersFixture fetches ledgers from a public RPC and saves them +// as a compressed LedgerCloseMetaBatch fixture. +func downloadLedgersFixture(tb testing.TB, path string) error { + // Get latest ledger + var latest getLatestLedgerResult + if err := callRPC(defaultRPCURL, "getLatestLedger", nil, &latest); err != nil { + return err + } + tb.Logf("latest ledger: %d", latest.Sequence) + + // Calculate start ledger + startLedger := latest.Sequence - uint32(numLedgersToFetch) + + // Fetch ledgers in batches + var allMetas []LedgerCloseMeta + cursor := "" + + for len(allMetas) < numLedgersToFetch { + params := getLedgersParams{ + Format: "base64", + Pagination: &ledgerPaginationOpts{ + Limit: 20, + }, + } + if cursor != "" { + params.Pagination.Cursor = cursor + } else { + params.StartLedger = startLedger + } + + var result getLedgersResult + if err := callRPC(defaultRPCURL, "getLedgers", params, &result); err != nil { + return err + } + + if len(result.Ledgers) == 0 { + break + } + + for _, ledger := range result.Ledgers { + metaBytes, err := base64.StdEncoding.DecodeString(ledger.LedgerMetadata) + if err != nil { + return err + } + + var lcm LedgerCloseMeta + if err := SafeUnmarshal(metaBytes, &lcm); err != nil { + return err + } + + allMetas = append(allMetas, lcm) + } + + cursor = result.Cursor + if cursor == "" { + break + } + } + + tb.Logf("fetched %d ledgers", len(allMetas)) + + if len(allMetas) == 0 { + return fmt.Errorf("no ledgers fetched from RPC") + } + + // Create LedgerCloseMetaBatch + batch := LedgerCloseMetaBatch{ + StartSequence: Uint32(allMetas[0].LedgerSequence()), + EndSequence: Uint32(allMetas[len(allMetas)-1].LedgerSequence()), + LedgerCloseMetas: allMetas, + } + + // Marshal and compress + batchBytes, err := batch.MarshalBinary() + if err != nil { + return err + } + + f, err := os.Create(path) + if err != nil { + return err + } + defer f.Close() + + encoder, err := zstd.NewWriter(f, zstd.WithEncoderLevel(zstd.SpeedBestCompression)) + if err != nil { + return err + } + + if _, err := encoder.Write(batchBytes); err != nil { + encoder.Close() + return err + } + + return encoder.Close() +} + +// loadLedgersFromZstd reads LedgerCloseMetaBatch from a zstd file and +// returns individual ledgers as serialized bytes. +func loadLedgersFromZstd(tb testing.TB, path string) [][]byte { + f, err := os.Open(path) + if err != nil { + return nil + } + defer f.Close() + + decoder, err := zstd.NewReader(f) + if err != nil { + return nil + } + defer decoder.Close() + + data, err := io.ReadAll(decoder) + if err != nil { + tb.Logf("error reading zstd data: %v", err) + return nil + } + + var batch LedgerCloseMetaBatch + if err = SafeUnmarshal(data, &batch); err != nil { + tb.Logf("error unmarshaling batch: %v", err) + return nil + } + + // Limit to numLedgersToFetch ledgers for benchmarks + metas := batch.LedgerCloseMetas + if len(metas) > numLedgersToFetch { + metas = metas[:numLedgersToFetch] + } + + ledgers := make([][]byte, len(metas)) + for i, lcm := range metas { + ledgers[i], err = lcm.MarshalBinary() + if err != nil { + tb.Logf("error marshaling ledger %d: %v", i, err) + return nil + } + } + + return ledgers +} + +// BenchmarkDecodeWithoutPool measures allocations without pooling. +func BenchmarkDecodeWithoutPool(b *testing.B) { + ledgers := loadTestLedgers(b) + b.Logf("loaded %d ledgers for benchmark", len(ledgers)) + + var totalBytes int64 + for _, data := range ledgers { + totalBytes += int64(len(data)) + } + avgBytes := totalBytes / int64(len(ledgers)) + + b.ResetTimer() + b.ReportAllocs() + b.SetBytes(avgBytes) + + for i := 0; i < b.N; i++ { + data := ledgers[i%len(ledgers)] + var lcm LedgerCloseMeta + if err := SafeUnmarshal(data, &lcm); err != nil { + b.Fatalf("decode failed: %v", err) + } + } +} + +// BenchmarkDecodeWithPool measures allocations with pooling. +func BenchmarkDecodeWithPool(b *testing.B) { + ledgers := loadTestLedgers(b) + b.Logf("loaded %d ledgers for benchmark", len(ledgers)) + + pool := NewPool[LedgerCloseMeta]() + + // Warmup - cycle through different ledgers to populate internal structures + for i := 0; i < len(ledgers)*2; i++ { + obj := pool.Get() + data := ledgers[i%len(ledgers)] + if err := SafeUnmarshal(data, obj); err != nil { + b.Fatalf("warmup decode failed: %v", err) + } + pool.Put(obj) + } + + var totalBytes int64 + for _, data := range ledgers { + totalBytes += int64(len(data)) + } + avgBytes := totalBytes / int64(len(ledgers)) + + b.ResetTimer() + b.ReportAllocs() + b.SetBytes(avgBytes) + + for i := 0; i < b.N; i++ { + data := ledgers[i%len(ledgers)] + lcm := pool.Get() + if err := SafeUnmarshal(data, lcm); err != nil { + b.Fatalf("decode failed: %v", err) + } + pool.Put(lcm) + } +} + +// BenchmarkDecodeWithPoolParallel measures concurrent pooled decoding. +func BenchmarkDecodeWithPoolParallel(b *testing.B) { + ledgers := loadTestLedgers(b) + b.Logf("loaded %d ledgers for benchmark", len(ledgers)) + + pool := NewPool[LedgerCloseMeta]() + + var totalBytes int64 + for _, data := range ledgers { + totalBytes += int64(len(data)) + } + avgBytes := totalBytes / int64(len(ledgers)) + + b.ResetTimer() + b.ReportAllocs() + b.SetBytes(avgBytes) + + var idx atomic.Int64 + b.RunParallel(func(pb *testing.PB) { + // Per-goroutine warmup with varied ledgers + for i := 0; i < len(ledgers); i++ { + obj := pool.Get() + data := ledgers[i%len(ledgers)] + if err := SafeUnmarshal(data, obj); err != nil { + b.Errorf("warmup decode failed: %v", err) + return + } + pool.Put(obj) + } + + localIdx := idx.Add(1) + for pb.Next() { + data := ledgers[localIdx%int64(len(ledgers))] + localIdx++ + lcm := pool.Get() + if err := SafeUnmarshal(data, lcm); err != nil { + b.Errorf("decode failed: %v", err) + return + } + pool.Put(lcm) + } + }) +} + +// TestMemoryStabilityWithPool verifies memory doesn't grow unbounded +// when decoding varied ledgers. +func TestMemoryStabilityWithPool(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running memory test") + } + + ledgers := loadTestLedgers(t) + if len(ledgers) == 0 { + t.Skip("no test data found") + } + t.Logf("loaded %d ledgers for memory test", len(ledgers)) + + pool := NewPool[LedgerCloseMeta]() + + runtime.GC() + var m runtime.MemStats + runtime.ReadMemStats(&m) + initialAlloc := m.Alloc + + for i := 0; i < 10000; i++ { + data := ledgers[i%len(ledgers)] + lcm := pool.Get() + if err := SafeUnmarshal(data, lcm); err != nil { + t.Fatalf("decode failed: %v", err) + } + pool.Put(lcm) + + if i%1000 == 0 { + runtime.GC() + } + } + + runtime.GC() + runtime.ReadMemStats(&m) + finalAlloc := m.Alloc + + // Memory should not grow significantly (allow 50MB variance) + growth := int64(finalAlloc) - int64(initialAlloc) + if growth > 50*1024*1024 { + t.Errorf("memory grew by %d bytes, expected stable", growth) + } +} diff --git a/xdr/pool_test.go b/xdr/pool_test.go new file mode 100644 index 0000000000..51644fe60c --- /dev/null +++ b/xdr/pool_test.go @@ -0,0 +1,42 @@ +package xdr + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestPoolBasicUsage(t *testing.T) { + pool := NewPool[LedgerCloseMeta]() + + // Get object + obj1 := pool.Get() + require.NotNil(t, obj1) + + // Return to pool + pool.Put(obj1) + + // Get again - may or may not be same object (GC can clear pool) + obj2 := pool.Get() + require.NotNil(t, obj2) + pool.Put(obj2) +} + +func TestPoolWithDecode(t *testing.T) { + pool := NewPool[ScVal]() + + // Create test data + original, _ := NewScVal(ScValTypeScvU32, Uint32(12345)) + data, err := original.MarshalBinary() + require.NoError(t, err) + + // Get from pool, decode, verify, return + for i := 0; i < 10; i++ { + obj := pool.Get() + err := SafeUnmarshal(data, obj) + require.NoError(t, err) + require.Equal(t, ScValTypeScvU32, obj.Type) + require.Equal(t, Uint32(12345), obj.U32) + pool.Put(obj) + } +} diff --git a/xdr/scval.go b/xdr/scval.go index 0e65132b6e..5de3c957b1 100644 --- a/xdr/scval.go +++ b/xdr/scval.go @@ -16,7 +16,7 @@ func (address ScAddress) String() (string, error) { switch address.Type { case ScAddressTypeScAddressTypeAccount: - pubkey := address.MustAccountId().Ed25519 + pubkey := address.MustAccountId().MustEd25519() result, err = strkey.Encode(strkey.VersionByteAccountID, pubkey[:]) case ScAddressTypeScAddressTypeContract: contractID := address.MustContractId() @@ -68,10 +68,10 @@ func (s ScError) Equals(o ScError) bool { } switch s.Type { case ScErrorTypeSceContract: - return *s.ContractCode == *o.ContractCode + return s.MustContractCode() == o.MustContractCode() case ScErrorTypeSceWasmVm, ScErrorTypeSceContext, ScErrorTypeSceStorage, ScErrorTypeSceObject, ScErrorTypeSceCrypto, ScErrorTypeSceEvents, ScErrorTypeSceBudget, ScErrorTypeSceValue, ScErrorTypeSceAuth: - return *s.Code == *o.Code + return s.MustCode() == o.MustCode() default: panic("unknown ScError type: " + s.Type.String()) } @@ -232,37 +232,42 @@ func bigUIntFromParts(hi Uint64, lowerParts ...Uint64) *big.Int { func (s ScVal) String() string { switch s.Type { case ScValTypeScvBool: - return fmt.Sprintf("%t", *s.B) + return fmt.Sprintf("%t", s.MustB()) case ScValTypeScvVoid: return "(void)" case ScValTypeScvError: - switch s.Error.Type { + err := s.MustError() + switch err.Type { case ScErrorTypeSceContract: - return fmt.Sprintf("%s(%d)", s.Error.Type, *s.Error.ContractCode) + return fmt.Sprintf("%s(%d)", err.Type, err.MustContractCode()) case ScErrorTypeSceWasmVm, ScErrorTypeSceContext, ScErrorTypeSceStorage, ScErrorTypeSceObject, ScErrorTypeSceCrypto, ScErrorTypeSceEvents, ScErrorTypeSceBudget, ScErrorTypeSceValue, ScErrorTypeSceAuth: - return fmt.Sprintf("%s(%s)", s.Error.Type, *s.Error.Code) + return fmt.Sprintf("%s(%s)", err.Type, err.MustCode()) } case ScValTypeScvU32: - return fmt.Sprintf("%d", *s.U32) + return fmt.Sprintf("%d", s.MustU32()) case ScValTypeScvI32: - return fmt.Sprintf("%d", *s.I32) + return fmt.Sprintf("%d", s.MustI32()) case ScValTypeScvU64: - return fmt.Sprintf("%d", *s.U64) + return fmt.Sprintf("%d", s.MustU64()) case ScValTypeScvI64: - return fmt.Sprintf("%d", *s.I64) + return fmt.Sprintf("%d", s.MustI64()) case ScValTypeScvTimepoint: - return time.Unix(int64(*s.Timepoint), 0).String() + return time.Unix(int64(s.MustTimepoint()), 0).String() case ScValTypeScvDuration: - return fmt.Sprintf("%d", *s.Duration) + return fmt.Sprintf("%d", s.MustDuration()) case ScValTypeScvU128: - return bigUIntFromParts(s.U128.Hi, s.U128.Lo).String() + u128 := s.MustU128() + return bigUIntFromParts(u128.Hi, u128.Lo).String() case ScValTypeScvI128: - return bigIntFromParts(s.I128.Hi, s.I128.Lo).String() + i128 := s.MustI128() + return bigIntFromParts(i128.Hi, i128.Lo).String() case ScValTypeScvU256: - return bigUIntFromParts(s.U256.HiHi, s.U256.HiLo, s.U256.LoHi, s.U256.LoLo).String() + u256 := s.MustU256() + return bigUIntFromParts(u256.HiHi, u256.HiLo, u256.LoHi, u256.LoLo).String() case ScValTypeScvI256: - return bigIntFromParts(s.I256.HiHi, s.I256.HiLo, s.I256.LoHi, s.I256.LoLo).String() + i256 := s.MustI256() + return bigIntFromParts(i256.HiHi, i256.HiLo, i256.LoHi, i256.LoLo).String() case ScValTypeScvBytes: return hex.EncodeToString(*s.Bytes) case ScValTypeScvString: @@ -291,7 +296,8 @@ func (s ScVal) String() string { case ContractExecutableTypeContractExecutableStellarAsset: result = "(StellarAssetContract)" case ContractExecutableTypeContractExecutableWasm: - result = hex.EncodeToString(s.Instance.Executable.WasmHash[:]) + wasmHash := s.Instance.Executable.MustWasmHash() + result = hex.EncodeToString(wasmHash[:]) } if s.Instance.Storage != nil && len(*s.Instance.Storage) > 0 { result += fmt.Sprintf(": %v", *s.Instance.Storage) diff --git a/xdr/scval_test.go b/xdr/scval_test.go index c2b562fd2b..0e47b0b9bb 100644 --- a/xdr/scval_test.go +++ b/xdr/scval_test.go @@ -58,17 +58,17 @@ func TestScAddressString(t *testing.T) { expected string }{ { - address: ScAddress{ - Type: ScAddressTypeScAddressTypeAccount, - AccountId: &AccountId{ - Type: PublicKeyTypePublicKeyTypeEd25519, - Ed25519: &Uint256{1}, - }, - }, - expected: AccountId{ - Type: PublicKeyTypePublicKeyTypeEd25519, - Ed25519: &Uint256{1}, - }.Address(), + address: func() ScAddress { + aid, _ := NewAccountId(PublicKeyTypePublicKeyTypeEd25519, Uint256{1}) + return ScAddress{ + Type: ScAddressTypeScAddressTypeAccount, + AccountId: &aid, + } + }(), + expected: func() string { + aid, _ := NewAccountId(PublicKeyTypePublicKeyTypeEd25519, Uint256{1}) + return aid.Address() + }(), }, { address: ScAddress{ @@ -78,36 +78,36 @@ func TestScAddressString(t *testing.T) { Ed25519: Uint256{2}, }, }, - expected: (&MuxedAccount{ - Type: CryptoKeyTypeKeyTypeMuxedEd25519, - Med25519: &MuxedAccountMed25519{ + expected: func() string { + muxed, _ := NewMuxedAccount(CryptoKeyTypeKeyTypeMuxedEd25519, MuxedAccountMed25519{ Id: 1, Ed25519: Uint256{2}, - }, - }).Address(), + }) + return muxed.Address() + }(), }, { - address: ScAddress{ - Type: ScAddressTypeScAddressTypeContract, - ContractId: &ContractId{1}, - }, + address: func() ScAddress { + addr, _ := NewScAddress(ScAddressTypeScAddressTypeContract, ContractId{1}) + return addr + }(), expected: strkey.MustEncode(strkey.VersionByteContract, contractID[:]), }, { - address: ScAddress{ - Type: ScAddressTypeScAddressTypeClaimableBalance, - ClaimableBalanceId: &ClaimableBalanceId{ - Type: ClaimableBalanceIdTypeClaimableBalanceIdTypeV0, - V0: &Hash{1}, - }, - }, + address: func() ScAddress { + cbId, _ := NewClaimableBalanceId(ClaimableBalanceIdTypeClaimableBalanceIdTypeV0, Hash{1}) + return ScAddress{ + Type: ScAddressTypeScAddressTypeClaimableBalance, + ClaimableBalanceId: &cbId, + } + }(), expected: strkey.MustEncode(strkey.VersionByteClaimableBalance, append([]byte{0}, cbID[:]...)), // The Cb type is included when encoding in strkey }, { - address: ScAddress{ - Type: ScAddressTypeScAddressTypeLiquidityPool, - LiquidityPoolId: &PoolId{1}, - }, + address: func() ScAddress { + addr, _ := NewScAddress(ScAddressTypeScAddressTypeLiquidityPool, PoolId{1}) + return addr + }(), expected: strkey.MustEncode(strkey.VersionByteLiquidityPool, poolID[:]), }, } { diff --git a/xdr/transaction_envelope.go b/xdr/transaction_envelope.go index d48c052ea4..77b3565e9c 100644 --- a/xdr/transaction_envelope.go +++ b/xdr/transaction_envelope.go @@ -30,10 +30,8 @@ func (e TransactionEnvelope) SourceAccount() MuxedAccount { case EnvelopeTypeEnvelopeTypeTx: return e.V1.Tx.SourceAccount case EnvelopeTypeEnvelopeTypeTxV0: - return MuxedAccount{ - Type: CryptoKeyTypeKeyTypeEd25519, - Ed25519: &e.V0.Tx.SourceAccountEd25519, - } + result, _ := NewMuxedAccount(CryptoKeyTypeKeyTypeEd25519, e.V0.Tx.SourceAccountEd25519) + return result default: panic("unsupported transaction type: " + e.Type.String()) } diff --git a/xdr/transaction_envelope_test.go b/xdr/transaction_envelope_test.go index 935179f4d8..a9f83c496c 100644 --- a/xdr/transaction_envelope_test.go +++ b/xdr/transaction_envelope_test.go @@ -42,22 +42,16 @@ func createLegacyTx() TransactionEnvelope { } func createTx() TransactionEnvelope { + sourceAccount, _ := NewMuxedAccount(CryptoKeyTypeKeyTypeEd25519, Uint256{3, 3, 3}) + memo := MemoHash(Hash{1, 1, 1}) return TransactionEnvelope{ Type: EnvelopeTypeEnvelopeTypeTx, V1: &TransactionV1Envelope{ Tx: Transaction{ - SourceAccount: MuxedAccount{ - Type: CryptoKeyTypeKeyTypeEd25519, - Ed25519: &Uint256{ - 3, 3, 3, - }, - }, - Fee: 99, - Memo: Memo{ - Type: MemoTypeMemoHash, - Hash: &Hash{1, 1, 1}, - }, - SeqNum: 97, + SourceAccount: sourceAccount, + Fee: 99, + Memo: memo, + SeqNum: 97, Cond: Preconditions{ Type: PreconditionTypePrecondTime, TimeBounds: &TimeBounds{ @@ -87,22 +81,17 @@ func createTx() TransactionEnvelope { func createCondV2Tx() TransactionEnvelope { minSeqNum := SequenceNumber(7) + sourceAccount, _ := NewMuxedAccount(CryptoKeyTypeKeyTypeEd25519, Uint256{3, 3, 3}) + memo := MemoHash(Hash{1, 1, 1}) + extraSigner, _ := NewSignerKey(SignerKeyTypeSignerKeyTypeEd25519, Uint256{3, 3, 3}) return TransactionEnvelope{ Type: EnvelopeTypeEnvelopeTypeTx, V1: &TransactionV1Envelope{ Tx: Transaction{ - SourceAccount: MuxedAccount{ - Type: CryptoKeyTypeKeyTypeEd25519, - Ed25519: &Uint256{ - 3, 3, 3, - }, - }, - Fee: 99, - Memo: Memo{ - Type: MemoTypeMemoHash, - Hash: &Hash{1, 1, 1}, - }, - SeqNum: 97, + SourceAccount: sourceAccount, + Fee: 99, + Memo: memo, + SeqNum: 97, Cond: Preconditions{ Type: PreconditionTypePrecondV2, V2: &PreconditionsV2{ @@ -117,12 +106,7 @@ func createCondV2Tx() TransactionEnvelope { MinSeqNum: &minSeqNum, MinSeqAge: Duration(8), MinSeqLedgerGap: Uint32(9), - ExtraSigners: []SignerKey{ - { - Type: SignerKeyTypeSignerKeyTypeEd25519, - Ed25519: &Uint256{3, 3, 3}, - }, - }, + ExtraSigners: []SignerKey{extraSigner}, }, }, Operations: []Operation{ @@ -146,15 +130,13 @@ func createCondV2Tx() TransactionEnvelope { } func createFeeBumpTx() TransactionEnvelope { + feeSource, _ := NewMuxedAccount(CryptoKeyTypeKeyTypeEd25519, Uint256{2, 2, 2}) return TransactionEnvelope{ Type: EnvelopeTypeEnvelopeTypeTxFeeBump, FeeBump: &FeeBumpTransactionEnvelope{ Tx: FeeBumpTransaction{ - FeeSource: MuxedAccount{ - Type: CryptoKeyTypeKeyTypeEd25519, - Ed25519: &Uint256{2, 2, 2}, - }, - Fee: 776, + FeeSource: feeSource, + Fee: 776, InnerTx: FeeBumpTransactionInnerTx{ Type: EnvelopeTypeEnvelopeTypeTx, V1: createTx().V1, @@ -239,10 +221,11 @@ func TestSourceAccount(t *testing.T) { CryptoKeyTypeKeyTypeEd25519, legacyTx.SourceAccount().Type, ) + sourceAccount := legacyTx.SourceAccount() assert.Equal( t, legacyTx.V0.Tx.SourceAccountEd25519, - *legacyTx.SourceAccount().Ed25519, + *sourceAccount.Ed25519, ) assert.Equal( diff --git a/xdr/trust_line_asset.go b/xdr/trust_line_asset.go index d9eb9d4f6a..4950184c66 100644 --- a/xdr/trust_line_asset.go +++ b/xdr/trust_line_asset.go @@ -76,7 +76,7 @@ func (e *EncodingBuffer) assetTrustlineCompressEncodeTo(a TrustLineAsset) error } return e.accountIdCompressEncodeTo(a.AlphaNum12.Issuer) case AssetTypeAssetTypePoolShare: - _, err := e.xdrEncoderBuf.Write(a.LiquidityPoolId[:]) + _, err := e.xdrEncoderBuf.Write((*a.LiquidityPoolId)[:]) return err default: panic(fmt.Errorf("Unknown asset type: %v", a.Type)) diff --git a/xdr/xdr_generated.go b/xdr/xdr_generated.go index be639585fe..2a77e4e7a1 100644 --- a/xdr/xdr_generated.go +++ b/xdr/xdr_generated.go @@ -53,23 +53,14 @@ type xdrType interface { xdrType() } -type decoderFrom interface { - DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) -} - -// Unmarshal reads an xdr element from `r` into `v`. -func Unmarshal(r io.Reader, v interface{}) (int, error) { - return UnmarshalWithOptions(r, v, xdr.DefaultDecodeOptions) -} - -// UnmarshalWithOptions works like Unmarshal but uses decoding options. -func UnmarshalWithOptions(r io.Reader, v interface{}, options xdr.DecodeOptions) (int, error) { - if decodable, ok := v.(decoderFrom); ok { - d := xdr.NewDecoderWithOptions(r, options) - return decodable.DecodeFrom(d, options.MaxDepth) +// Unmarshal reads an xdr element from `data` into `v`. +func Unmarshal(data []byte, v interface{}) (int, error) { + if decodable, ok := v.(xdr.DecoderFrom); ok { + d := xdr.NewDecoder(data) + return d.Decode(decodable) } // delegate to xdr package's Unmarshal - return xdr.UnmarshalWithOptions(r, v, options) + return xdr.Unmarshal(data, v) } // Marshal writes an xdr element `v` into `w`. @@ -101,9 +92,9 @@ func (s Value) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Value)(nil) +var _ xdr.DecoderFrom = (*Value)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Value) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Value: %w", ErrMaxDecodingDepthReached) @@ -129,11 +120,8 @@ func (s Value) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Value) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -171,9 +159,9 @@ func (s *ScpBallot) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScpBallot)(nil) +var _ xdr.DecoderFrom = (*ScpBallot)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScpBallot) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpBallot: %w", ErrMaxDecodingDepthReached) @@ -204,11 +192,8 @@ func (s ScpBallot) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpBallot) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -239,6 +224,10 @@ const ( ScpStatementTypeScpStExternalize ScpStatementType = 2 ScpStatementTypeScpStNominate ScpStatementType = 3 ) +const ( + _ScpStatementType_Min int32 = 0 + _ScpStatementType_Max int32 = 3 +) var scpStatementTypeMap = map[int32]string{ 0: "ScpStatementTypeScpStPrepare", @@ -250,8 +239,7 @@ var scpStatementTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScpStatementType func (e ScpStatementType) ValidEnum(v int32) bool { - _, ok := scpStatementTypeMap[v] - return ok + return v >= _ScpStatementType_Min && v <= _ScpStatementType_Max } // String returns the name of `e` @@ -262,16 +250,16 @@ func (e ScpStatementType) String() string { // EncodeTo encodes this value using the Encoder. func (e ScpStatementType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scpStatementTypeMap[int32(e)]; !ok { + if int32(e) < _ScpStatementType_Min || int32(e) > _ScpStatementType_Max { return fmt.Errorf("'%d' is not a valid ScpStatementType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScpStatementType)(nil) +var _ xdr.DecoderFrom = (*ScpStatementType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScpStatementType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpStatementType: %w", ErrMaxDecodingDepthReached) @@ -281,7 +269,7 @@ func (e *ScpStatementType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error if err != nil { return n, fmt.Errorf("decoding ScpStatementType: %w", err) } - if _, ok := scpStatementTypeMap[v]; !ok { + if v < _ScpStatementType_Min || v > _ScpStatementType_Max { return n, fmt.Errorf("'%d' is not a valid ScpStatementType enum value", v) } *e = ScpStatementType(v) @@ -298,11 +286,8 @@ func (s ScpStatementType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpStatementType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -355,9 +340,9 @@ func (s *ScpNomination) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScpNomination)(nil) +var _ xdr.DecoderFrom = (*ScpNomination)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScpNomination) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpNomination: %w", ErrMaxDecodingDepthReached) @@ -376,12 +361,17 @@ func (s *ScpNomination) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding Value: %w", err) } - s.Votes = nil - if l > 0 { + if l == 0 { + s.Votes = s.Votes[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Value: length (%d) exceeds remaining input length (%d)", l, il) } - s.Votes = make([]Value, l) + if cap(s.Votes) >= int(l) { + s.Votes = s.Votes[:l] + } else { + s.Votes = make([]Value, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Votes[i].DecodeFrom(d, maxDepth) n += nTmp @@ -395,12 +385,17 @@ func (s *ScpNomination) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding Value: %w", err) } - s.Accepted = nil - if l > 0 { + if l == 0 { + s.Accepted = s.Accepted[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Value: length (%d) exceeds remaining input length (%d)", l, il) } - s.Accepted = make([]Value, l) + if cap(s.Accepted) >= int(l) { + s.Accepted = s.Accepted[:l] + } else { + s.Accepted = make([]Value, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Accepted[i].DecodeFrom(d, maxDepth) n += nTmp @@ -422,11 +417,8 @@ func (s ScpNomination) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpNomination) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -494,9 +486,9 @@ func (s *ScpStatementPrepare) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScpStatementPrepare)(nil) +var _ xdr.DecoderFrom = (*ScpStatementPrepare)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScpStatementPrepare) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpStatementPrepare: %w", ErrMaxDecodingDepthReached) @@ -566,11 +558,8 @@ func (s ScpStatementPrepare) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpStatementPrepare) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -623,9 +612,9 @@ func (s *ScpStatementConfirm) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScpStatementConfirm)(nil) +var _ xdr.DecoderFrom = (*ScpStatementConfirm)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScpStatementConfirm) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpStatementConfirm: %w", ErrMaxDecodingDepthReached) @@ -671,11 +660,8 @@ func (s ScpStatementConfirm) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpStatementConfirm) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -718,9 +704,9 @@ func (s *ScpStatementExternalize) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScpStatementExternalize)(nil) +var _ xdr.DecoderFrom = (*ScpStatementExternalize)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScpStatementExternalize) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpStatementExternalize: %w", ErrMaxDecodingDepthReached) @@ -756,11 +742,8 @@ func (s ScpStatementExternalize) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpStatementExternalize) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -876,100 +859,76 @@ func NewScpStatementPledges(aType ScpStatementType, value interface{}) (result S // MustPrepare retrieves the Prepare value from the union, // panicing if the value is not set. func (u ScpStatementPledges) MustPrepare() ScpStatementPrepare { - val, ok := u.GetPrepare() - - if !ok { - panic("arm Prepare is not set") + if ScpStatementType(u.Type) == ScpStatementTypeScpStPrepare { + return *u.Prepare } - - return val + panic("arm Prepare is not set") } // GetPrepare retrieves the Prepare value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScpStatementPledges) GetPrepare() (result ScpStatementPrepare, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Prepare" { + if ScpStatementType(u.Type) == ScpStatementTypeScpStPrepare { result = *u.Prepare ok = true } - return } // MustConfirm retrieves the Confirm value from the union, // panicing if the value is not set. func (u ScpStatementPledges) MustConfirm() ScpStatementConfirm { - val, ok := u.GetConfirm() - - if !ok { - panic("arm Confirm is not set") + if ScpStatementType(u.Type) == ScpStatementTypeScpStConfirm { + return *u.Confirm } - - return val + panic("arm Confirm is not set") } // GetConfirm retrieves the Confirm value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScpStatementPledges) GetConfirm() (result ScpStatementConfirm, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Confirm" { + if ScpStatementType(u.Type) == ScpStatementTypeScpStConfirm { result = *u.Confirm ok = true } - return } // MustExternalize retrieves the Externalize value from the union, // panicing if the value is not set. func (u ScpStatementPledges) MustExternalize() ScpStatementExternalize { - val, ok := u.GetExternalize() - - if !ok { - panic("arm Externalize is not set") + if ScpStatementType(u.Type) == ScpStatementTypeScpStExternalize { + return *u.Externalize } - - return val + panic("arm Externalize is not set") } // GetExternalize retrieves the Externalize value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScpStatementPledges) GetExternalize() (result ScpStatementExternalize, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Externalize" { + if ScpStatementType(u.Type) == ScpStatementTypeScpStExternalize { result = *u.Externalize ok = true } - return } // MustNominate retrieves the Nominate value from the union, // panicing if the value is not set. func (u ScpStatementPledges) MustNominate() ScpNomination { - val, ok := u.GetNominate() - - if !ok { - panic("arm Nominate is not set") + if ScpStatementType(u.Type) == ScpStatementTypeScpStNominate { + return *u.Nominate } - - return val + panic("arm Nominate is not set") } // GetNominate retrieves the Nominate value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScpStatementPledges) GetNominate() (result ScpNomination, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Nominate" { + if ScpStatementType(u.Type) == ScpStatementTypeScpStNominate { result = *u.Nominate ok = true } - return } @@ -1004,9 +963,9 @@ func (u ScpStatementPledges) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (ScpStatementType) switch value '%d' is not valid for union ScpStatementPledges", u.Type) } -var _ decoderFrom = (*ScpStatementPledges)(nil) +var _ xdr.DecoderFrom = (*ScpStatementPledges)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ScpStatementPledges) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpStatementPledges: %w", ErrMaxDecodingDepthReached) @@ -1021,7 +980,9 @@ func (u *ScpStatementPledges) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er } switch ScpStatementType(u.Type) { case ScpStatementTypeScpStPrepare: - u.Prepare = new(ScpStatementPrepare) + if u.Prepare == nil { + u.Prepare = new(ScpStatementPrepare) + } nTmp, err = (*u.Prepare).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -1029,7 +990,9 @@ func (u *ScpStatementPledges) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er } return n, nil case ScpStatementTypeScpStConfirm: - u.Confirm = new(ScpStatementConfirm) + if u.Confirm == nil { + u.Confirm = new(ScpStatementConfirm) + } nTmp, err = (*u.Confirm).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -1037,7 +1000,9 @@ func (u *ScpStatementPledges) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er } return n, nil case ScpStatementTypeScpStExternalize: - u.Externalize = new(ScpStatementExternalize) + if u.Externalize == nil { + u.Externalize = new(ScpStatementExternalize) + } nTmp, err = (*u.Externalize).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -1045,7 +1010,9 @@ func (u *ScpStatementPledges) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er } return n, nil case ScpStatementTypeScpStNominate: - u.Nominate = new(ScpNomination) + if u.Nominate == nil { + u.Nominate = new(ScpNomination) + } nTmp, err = (*u.Nominate).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -1066,11 +1033,8 @@ func (s ScpStatementPledges) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpStatementPledges) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -1145,9 +1109,9 @@ func (s *ScpStatement) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScpStatement)(nil) +var _ xdr.DecoderFrom = (*ScpStatement)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScpStatement) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpStatement: %w", ErrMaxDecodingDepthReached) @@ -1183,11 +1147,8 @@ func (s ScpStatement) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpStatement) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -1225,9 +1186,9 @@ func (s *ScpEnvelope) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScpEnvelope)(nil) +var _ xdr.DecoderFrom = (*ScpEnvelope)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScpEnvelope) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpEnvelope: %w", ErrMaxDecodingDepthReached) @@ -1258,11 +1219,8 @@ func (s ScpEnvelope) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpEnvelope) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -1315,9 +1273,9 @@ func (s *ScpQuorumSet) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScpQuorumSet)(nil) +var _ xdr.DecoderFrom = (*ScpQuorumSet)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScpQuorumSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpQuorumSet: %w", ErrMaxDecodingDepthReached) @@ -1336,12 +1294,17 @@ func (s *ScpQuorumSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding NodeId: %w", err) } - s.Validators = nil - if l > 0 { + if l == 0 { + s.Validators = s.Validators[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding NodeId: length (%d) exceeds remaining input length (%d)", l, il) } - s.Validators = make([]NodeId, l) + if cap(s.Validators) >= int(l) { + s.Validators = s.Validators[:l] + } else { + s.Validators = make([]NodeId, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Validators[i].DecodeFrom(d, maxDepth) n += nTmp @@ -1355,12 +1318,17 @@ func (s *ScpQuorumSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ScpQuorumSet: %w", err) } - s.InnerSets = nil - if l > 0 { + if l == 0 { + s.InnerSets = s.InnerSets[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScpQuorumSet: length (%d) exceeds remaining input length (%d)", l, il) } - s.InnerSets = make([]ScpQuorumSet, l) + if cap(s.InnerSets) >= int(l) { + s.InnerSets = s.InnerSets[:l] + } else { + s.InnerSets = make([]ScpQuorumSet, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.InnerSets[i].DecodeFrom(d, maxDepth) n += nTmp @@ -1382,11 +1350,8 @@ func (s ScpQuorumSet) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpQuorumSet) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -1419,9 +1384,9 @@ func (s *Thresholds) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Thresholds)(nil) +var _ xdr.DecoderFrom = (*Thresholds)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Thresholds) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Thresholds: %w", ErrMaxDecodingDepthReached) @@ -1447,11 +1412,8 @@ func (s Thresholds) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Thresholds) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -1484,9 +1446,9 @@ func (s String32) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*String32)(nil) +var _ xdr.DecoderFrom = (*String32)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *String32) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding String32: %w", ErrMaxDecodingDepthReached) @@ -1514,11 +1476,8 @@ func (s String32) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *String32) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -1551,9 +1510,9 @@ func (s String64) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*String64)(nil) +var _ xdr.DecoderFrom = (*String64)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *String64) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding String64: %w", ErrMaxDecodingDepthReached) @@ -1581,11 +1540,8 @@ func (s String64) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *String64) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -1613,9 +1569,9 @@ func (s SequenceNumber) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SequenceNumber)(nil) +var _ xdr.DecoderFrom = (*SequenceNumber)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SequenceNumber) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SequenceNumber: %w", ErrMaxDecodingDepthReached) @@ -1641,11 +1597,8 @@ func (s SequenceNumber) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SequenceNumber) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -1678,9 +1631,9 @@ func (s DataValue) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*DataValue)(nil) +var _ xdr.DecoderFrom = (*DataValue)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *DataValue) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding DataValue: %w", ErrMaxDecodingDepthReached) @@ -1706,11 +1659,8 @@ func (s DataValue) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *DataValue) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -1743,9 +1693,9 @@ func (s *AssetCode4) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AssetCode4)(nil) +var _ xdr.DecoderFrom = (*AssetCode4)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AssetCode4) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AssetCode4: %w", ErrMaxDecodingDepthReached) @@ -1771,11 +1721,8 @@ func (s AssetCode4) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AssetCode4) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -1808,9 +1755,9 @@ func (s *AssetCode12) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AssetCode12)(nil) +var _ xdr.DecoderFrom = (*AssetCode12)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AssetCode12) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AssetCode12: %w", ErrMaxDecodingDepthReached) @@ -1836,11 +1783,8 @@ func (s AssetCode12) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AssetCode12) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -1871,6 +1815,10 @@ const ( AssetTypeAssetTypeCreditAlphanum12 AssetType = 2 AssetTypeAssetTypePoolShare AssetType = 3 ) +const ( + _AssetType_Min int32 = 0 + _AssetType_Max int32 = 3 +) var assetTypeMap = map[int32]string{ 0: "AssetTypeAssetTypeNative", @@ -1882,8 +1830,7 @@ var assetTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for AssetType func (e AssetType) ValidEnum(v int32) bool { - _, ok := assetTypeMap[v] - return ok + return v >= _AssetType_Min && v <= _AssetType_Max } // String returns the name of `e` @@ -1894,16 +1841,16 @@ func (e AssetType) String() string { // EncodeTo encodes this value using the Encoder. func (e AssetType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := assetTypeMap[int32(e)]; !ok { + if int32(e) < _AssetType_Min || int32(e) > _AssetType_Max { return fmt.Errorf("'%d' is not a valid AssetType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*AssetType)(nil) +var _ xdr.DecoderFrom = (*AssetType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *AssetType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AssetType: %w", ErrMaxDecodingDepthReached) @@ -1913,7 +1860,7 @@ func (e *AssetType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding AssetType: %w", err) } - if _, ok := assetTypeMap[v]; !ok { + if v < _AssetType_Min || v > _AssetType_Max { return n, fmt.Errorf("'%d' is not a valid AssetType enum value", v) } *e = AssetType(v) @@ -1930,11 +1877,8 @@ func (s AssetType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AssetType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -2009,50 +1953,38 @@ func NewAssetCode(aType AssetType, value interface{}) (result AssetCode, err err // MustAssetCode4 retrieves the AssetCode4 value from the union, // panicing if the value is not set. func (u AssetCode) MustAssetCode4() AssetCode4 { - val, ok := u.GetAssetCode4() - - if !ok { - panic("arm AssetCode4 is not set") + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum4 { + return *u.AssetCode4 } - - return val + panic("arm AssetCode4 is not set") } // GetAssetCode4 retrieves the AssetCode4 value from the union, // returning ok if the union's switch indicated the value is valid. func (u AssetCode) GetAssetCode4() (result AssetCode4, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AssetCode4" { + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum4 { result = *u.AssetCode4 ok = true } - return } // MustAssetCode12 retrieves the AssetCode12 value from the union, // panicing if the value is not set. func (u AssetCode) MustAssetCode12() AssetCode12 { - val, ok := u.GetAssetCode12() - - if !ok { - panic("arm AssetCode12 is not set") + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum12 { + return *u.AssetCode12 } - - return val + panic("arm AssetCode12 is not set") } // GetAssetCode12 retrieves the AssetCode12 value from the union, // returning ok if the union's switch indicated the value is valid. func (u AssetCode) GetAssetCode12() (result AssetCode12, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AssetCode12" { + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum12 { result = *u.AssetCode12 ok = true } - return } @@ -2077,9 +2009,9 @@ func (u AssetCode) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (AssetType) switch value '%d' is not valid for union AssetCode", u.Type) } -var _ decoderFrom = (*AssetCode)(nil) +var _ xdr.DecoderFrom = (*AssetCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *AssetCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AssetCode: %w", ErrMaxDecodingDepthReached) @@ -2094,7 +2026,9 @@ func (u *AssetCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch AssetType(u.Type) { case AssetTypeAssetTypeCreditAlphanum4: - u.AssetCode4 = new(AssetCode4) + if u.AssetCode4 == nil { + u.AssetCode4 = new(AssetCode4) + } nTmp, err = (*u.AssetCode4).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -2102,7 +2036,9 @@ func (u *AssetCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case AssetTypeAssetTypeCreditAlphanum12: - u.AssetCode12 = new(AssetCode12) + if u.AssetCode12 == nil { + u.AssetCode12 = new(AssetCode12) + } nTmp, err = (*u.AssetCode12).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -2123,11 +2059,8 @@ func (s AssetCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AssetCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -2165,9 +2098,9 @@ func (s *AlphaNum4) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AlphaNum4)(nil) +var _ xdr.DecoderFrom = (*AlphaNum4)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AlphaNum4) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AlphaNum4: %w", ErrMaxDecodingDepthReached) @@ -2198,11 +2131,8 @@ func (s AlphaNum4) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AlphaNum4) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -2240,9 +2170,9 @@ func (s *AlphaNum12) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AlphaNum12)(nil) +var _ xdr.DecoderFrom = (*AlphaNum12)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AlphaNum12) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AlphaNum12: %w", ErrMaxDecodingDepthReached) @@ -2273,11 +2203,8 @@ func (s AlphaNum12) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AlphaNum12) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -2359,50 +2286,38 @@ func NewAsset(aType AssetType, value interface{}) (result Asset, err error) { // MustAlphaNum4 retrieves the AlphaNum4 value from the union, // panicing if the value is not set. func (u Asset) MustAlphaNum4() AlphaNum4 { - val, ok := u.GetAlphaNum4() - - if !ok { - panic("arm AlphaNum4 is not set") + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum4 { + return *u.AlphaNum4 } - - return val + panic("arm AlphaNum4 is not set") } // GetAlphaNum4 retrieves the AlphaNum4 value from the union, // returning ok if the union's switch indicated the value is valid. func (u Asset) GetAlphaNum4() (result AlphaNum4, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AlphaNum4" { + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum4 { result = *u.AlphaNum4 ok = true } - return } // MustAlphaNum12 retrieves the AlphaNum12 value from the union, // panicing if the value is not set. func (u Asset) MustAlphaNum12() AlphaNum12 { - val, ok := u.GetAlphaNum12() - - if !ok { - panic("arm AlphaNum12 is not set") + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum12 { + return *u.AlphaNum12 } - - return val + panic("arm AlphaNum12 is not set") } // GetAlphaNum12 retrieves the AlphaNum12 value from the union, // returning ok if the union's switch indicated the value is valid. func (u Asset) GetAlphaNum12() (result AlphaNum12, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AlphaNum12" { + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum12 { result = *u.AlphaNum12 ok = true } - return } @@ -2430,9 +2345,9 @@ func (u Asset) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (AssetType) switch value '%d' is not valid for union Asset", u.Type) } -var _ decoderFrom = (*Asset)(nil) +var _ xdr.DecoderFrom = (*Asset)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *Asset) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Asset: %w", ErrMaxDecodingDepthReached) @@ -2450,7 +2365,9 @@ func (u *Asset) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { // Void return n, nil case AssetTypeAssetTypeCreditAlphanum4: - u.AlphaNum4 = new(AlphaNum4) + if u.AlphaNum4 == nil { + u.AlphaNum4 = new(AlphaNum4) + } nTmp, err = (*u.AlphaNum4).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -2458,7 +2375,9 @@ func (u *Asset) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case AssetTypeAssetTypeCreditAlphanum12: - u.AlphaNum12 = new(AlphaNum12) + if u.AlphaNum12 == nil { + u.AlphaNum12 = new(AlphaNum12) + } nTmp, err = (*u.AlphaNum12).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -2479,11 +2398,8 @@ func (s Asset) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Asset) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -2521,9 +2437,9 @@ func (s *Price) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Price)(nil) +var _ xdr.DecoderFrom = (*Price)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Price) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Price: %w", ErrMaxDecodingDepthReached) @@ -2554,11 +2470,8 @@ func (s Price) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Price) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -2596,9 +2509,9 @@ func (s *Liabilities) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Liabilities)(nil) +var _ xdr.DecoderFrom = (*Liabilities)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Liabilities) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Liabilities: %w", ErrMaxDecodingDepthReached) @@ -2629,11 +2542,8 @@ func (s Liabilities) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Liabilities) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -2664,6 +2574,10 @@ const ( ThresholdIndexesThresholdMed ThresholdIndexes = 2 ThresholdIndexesThresholdHigh ThresholdIndexes = 3 ) +const ( + _ThresholdIndexes_Min int32 = 0 + _ThresholdIndexes_Max int32 = 3 +) var thresholdIndexesMap = map[int32]string{ 0: "ThresholdIndexesThresholdMasterWeight", @@ -2675,8 +2589,7 @@ var thresholdIndexesMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ThresholdIndexes func (e ThresholdIndexes) ValidEnum(v int32) bool { - _, ok := thresholdIndexesMap[v] - return ok + return v >= _ThresholdIndexes_Min && v <= _ThresholdIndexes_Max } // String returns the name of `e` @@ -2687,16 +2600,16 @@ func (e ThresholdIndexes) String() string { // EncodeTo encodes this value using the Encoder. func (e ThresholdIndexes) EncodeTo(enc *xdr.Encoder) error { - if _, ok := thresholdIndexesMap[int32(e)]; !ok { + if int32(e) < _ThresholdIndexes_Min || int32(e) > _ThresholdIndexes_Max { return fmt.Errorf("'%d' is not a valid ThresholdIndexes enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ThresholdIndexes)(nil) +var _ xdr.DecoderFrom = (*ThresholdIndexes)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ThresholdIndexes) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ThresholdIndexes: %w", ErrMaxDecodingDepthReached) @@ -2706,7 +2619,7 @@ func (e *ThresholdIndexes) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error if err != nil { return n, fmt.Errorf("decoding ThresholdIndexes: %w", err) } - if _, ok := thresholdIndexesMap[v]; !ok { + if v < _ThresholdIndexes_Min || v > _ThresholdIndexes_Max { return n, fmt.Errorf("'%d' is not a valid ThresholdIndexes enum value", v) } *e = ThresholdIndexes(v) @@ -2723,11 +2636,8 @@ func (s ThresholdIndexes) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ThresholdIndexes) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -2770,6 +2680,10 @@ const ( LedgerEntryTypeConfigSetting LedgerEntryType = 8 LedgerEntryTypeTtl LedgerEntryType = 9 ) +const ( + _LedgerEntryType_Min int32 = 0 + _LedgerEntryType_Max int32 = 9 +) var ledgerEntryTypeMap = map[int32]string{ 0: "LedgerEntryTypeAccount", @@ -2787,8 +2701,7 @@ var ledgerEntryTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for LedgerEntryType func (e LedgerEntryType) ValidEnum(v int32) bool { - _, ok := ledgerEntryTypeMap[v] - return ok + return v >= _LedgerEntryType_Min && v <= _LedgerEntryType_Max } // String returns the name of `e` @@ -2799,16 +2712,16 @@ func (e LedgerEntryType) String() string { // EncodeTo encodes this value using the Encoder. func (e LedgerEntryType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := ledgerEntryTypeMap[int32(e)]; !ok { + if int32(e) < _LedgerEntryType_Min || int32(e) > _LedgerEntryType_Max { return fmt.Errorf("'%d' is not a valid LedgerEntryType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*LedgerEntryType)(nil) +var _ xdr.DecoderFrom = (*LedgerEntryType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *LedgerEntryType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerEntryType: %w", ErrMaxDecodingDepthReached) @@ -2818,7 +2731,7 @@ func (e *LedgerEntryType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding LedgerEntryType: %w", err) } - if _, ok := ledgerEntryTypeMap[v]; !ok { + if v < _LedgerEntryType_Min || v > _LedgerEntryType_Max { return n, fmt.Errorf("'%d' is not a valid LedgerEntryType enum value", v) } *e = LedgerEntryType(v) @@ -2835,11 +2748,8 @@ func (s LedgerEntryType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerEntryType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -2877,9 +2787,9 @@ func (s *Signer) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Signer)(nil) +var _ xdr.DecoderFrom = (*Signer)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Signer) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Signer: %w", ErrMaxDecodingDepthReached) @@ -2910,11 +2820,8 @@ func (s Signer) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Signer) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -2966,8 +2873,12 @@ var accountFlagsMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for AccountFlags func (e AccountFlags) ValidEnum(v int32) bool { - _, ok := accountFlagsMap[v] - return ok + switch v { + case 1, 2, 4, 8: + return true + default: + return false + } } // String returns the name of `e` @@ -2978,16 +2889,19 @@ func (e AccountFlags) String() string { // EncodeTo encodes this value using the Encoder. func (e AccountFlags) EncodeTo(enc *xdr.Encoder) error { - if _, ok := accountFlagsMap[int32(e)]; !ok { + switch int32(e) { + case 1, 2, 4, 8: + // valid + default: return fmt.Errorf("'%d' is not a valid AccountFlags enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*AccountFlags)(nil) +var _ xdr.DecoderFrom = (*AccountFlags)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *AccountFlags) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AccountFlags: %w", ErrMaxDecodingDepthReached) @@ -2997,7 +2911,10 @@ func (e *AccountFlags) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding AccountFlags: %w", err) } - if _, ok := accountFlagsMap[v]; !ok { + switch v { + case 1, 2, 4, 8: + // valid + default: return n, fmt.Errorf("'%d' is not a valid AccountFlags enum value", v) } *e = AccountFlags(v) @@ -3014,11 +2931,8 @@ func (s AccountFlags) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AccountFlags) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -3087,9 +3001,9 @@ func (s *AccountEntryExtensionV3) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AccountEntryExtensionV3)(nil) +var _ xdr.DecoderFrom = (*AccountEntryExtensionV3)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AccountEntryExtensionV3) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AccountEntryExtensionV3: %w", ErrMaxDecodingDepthReached) @@ -3125,11 +3039,8 @@ func (s AccountEntryExtensionV3) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AccountEntryExtensionV3) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -3195,25 +3106,19 @@ func NewAccountEntryExtensionV2Ext(v int32, value interface{}) (result AccountEn // MustV3 retrieves the V3 value from the union, // panicing if the value is not set. func (u AccountEntryExtensionV2Ext) MustV3() AccountEntryExtensionV3 { - val, ok := u.GetV3() - - if !ok { - panic("arm V3 is not set") + if int32(u.V) == 3 { + return *u.V3 } - - return val + panic("arm V3 is not set") } // GetV3 retrieves the V3 value from the union, // returning ok if the union's switch indicated the value is valid. func (u AccountEntryExtensionV2Ext) GetV3() (result AccountEntryExtensionV3, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V3" { + if int32(u.V) == 3 { result = *u.V3 ok = true } - return } @@ -3236,9 +3141,9 @@ func (u AccountEntryExtensionV2Ext) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union AccountEntryExtensionV2Ext", u.V) } -var _ decoderFrom = (*AccountEntryExtensionV2Ext)(nil) +var _ xdr.DecoderFrom = (*AccountEntryExtensionV2Ext)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *AccountEntryExtensionV2Ext) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AccountEntryExtensionV2Ext: %w", ErrMaxDecodingDepthReached) @@ -3256,7 +3161,9 @@ func (u *AccountEntryExtensionV2Ext) DecodeFrom(d *xdr.Decoder, maxDepth uint) ( // Void return n, nil case 3: - u.V3 = new(AccountEntryExtensionV3) + if u.V3 == nil { + u.V3 = new(AccountEntryExtensionV3) + } nTmp, err = (*u.V3).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -3277,11 +3184,8 @@ func (s AccountEntryExtensionV2Ext) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AccountEntryExtensionV2Ext) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -3347,9 +3251,9 @@ func (s *AccountEntryExtensionV2) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AccountEntryExtensionV2)(nil) +var _ xdr.DecoderFrom = (*AccountEntryExtensionV2)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AccountEntryExtensionV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AccountEntryExtensionV2: %w", ErrMaxDecodingDepthReached) @@ -3376,12 +3280,17 @@ func (s *AccountEntryExtensionV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int if l > 20 { return n, fmt.Errorf("decoding SponsorshipDescriptor: data size (%d) exceeds size limit (20)", l) } - s.SignerSponsoringIDs = nil - if l > 0 { + if l == 0 { + s.SignerSponsoringIDs = s.SignerSponsoringIDs[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding SponsorshipDescriptor: length (%d) exceeds remaining input length (%d)", l, il) } - s.SignerSponsoringIDs = make([]SponsorshipDescriptor, l) + if cap(s.SignerSponsoringIDs) >= int(l) { + s.SignerSponsoringIDs = s.SignerSponsoringIDs[:l] + } else { + s.SignerSponsoringIDs = make([]SponsorshipDescriptor, l) + } for i := uint32(0); i < l; i++ { var eb bool eb, nTmp, err = d.DecodeBool() @@ -3418,11 +3327,8 @@ func (s AccountEntryExtensionV2) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AccountEntryExtensionV2) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -3488,25 +3394,19 @@ func NewAccountEntryExtensionV1Ext(v int32, value interface{}) (result AccountEn // MustV2 retrieves the V2 value from the union, // panicing if the value is not set. func (u AccountEntryExtensionV1Ext) MustV2() AccountEntryExtensionV2 { - val, ok := u.GetV2() - - if !ok { - panic("arm V2 is not set") + if int32(u.V) == 2 { + return *u.V2 } - - return val + panic("arm V2 is not set") } // GetV2 retrieves the V2 value from the union, // returning ok if the union's switch indicated the value is valid. func (u AccountEntryExtensionV1Ext) GetV2() (result AccountEntryExtensionV2, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V2" { + if int32(u.V) == 2 { result = *u.V2 ok = true } - return } @@ -3529,9 +3429,9 @@ func (u AccountEntryExtensionV1Ext) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union AccountEntryExtensionV1Ext", u.V) } -var _ decoderFrom = (*AccountEntryExtensionV1Ext)(nil) +var _ xdr.DecoderFrom = (*AccountEntryExtensionV1Ext)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *AccountEntryExtensionV1Ext) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AccountEntryExtensionV1Ext: %w", ErrMaxDecodingDepthReached) @@ -3549,7 +3449,9 @@ func (u *AccountEntryExtensionV1Ext) DecodeFrom(d *xdr.Decoder, maxDepth uint) ( // Void return n, nil case 2: - u.V2 = new(AccountEntryExtensionV2) + if u.V2 == nil { + u.V2 = new(AccountEntryExtensionV2) + } nTmp, err = (*u.V2).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -3570,11 +3472,8 @@ func (s AccountEntryExtensionV1Ext) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AccountEntryExtensionV1Ext) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -3620,9 +3519,9 @@ func (s *AccountEntryExtensionV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AccountEntryExtensionV1)(nil) +var _ xdr.DecoderFrom = (*AccountEntryExtensionV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AccountEntryExtensionV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AccountEntryExtensionV1: %w", ErrMaxDecodingDepthReached) @@ -3653,11 +3552,8 @@ func (s AccountEntryExtensionV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AccountEntryExtensionV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -3723,25 +3619,19 @@ func NewAccountEntryExt(v int32, value interface{}) (result AccountEntryExt, err // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u AccountEntryExt) MustV1() AccountEntryExtensionV1 { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if int32(u.V) == 1 { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u AccountEntryExt) GetV1() (result AccountEntryExtensionV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1" { + if int32(u.V) == 1 { result = *u.V1 ok = true } - return } @@ -3764,9 +3654,9 @@ func (u AccountEntryExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union AccountEntryExt", u.V) } -var _ decoderFrom = (*AccountEntryExt)(nil) +var _ xdr.DecoderFrom = (*AccountEntryExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *AccountEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AccountEntryExt: %w", ErrMaxDecodingDepthReached) @@ -3784,7 +3674,9 @@ func (u *AccountEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) // Void return n, nil case 1: - u.V1 = new(AccountEntryExtensionV1) + if u.V1 == nil { + u.V1 = new(AccountEntryExtensionV1) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -3805,11 +3697,8 @@ func (s AccountEntryExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AccountEntryExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -3912,9 +3801,9 @@ func (s *AccountEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AccountEntry)(nil) +var _ xdr.DecoderFrom = (*AccountEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AccountEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AccountEntry: %w", ErrMaxDecodingDepthReached) @@ -3981,12 +3870,17 @@ func (s *AccountEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if l > 20 { return n, fmt.Errorf("decoding Signer: data size (%d) exceeds size limit (20)", l) } - s.Signers = nil - if l > 0 { + if l == 0 { + s.Signers = s.Signers[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Signer: length (%d) exceeds remaining input length (%d)", l, il) } - s.Signers = make([]Signer, l) + if cap(s.Signers) >= int(l) { + s.Signers = s.Signers[:l] + } else { + s.Signers = make([]Signer, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Signers[i].DecodeFrom(d, maxDepth) n += nTmp @@ -4013,11 +3907,8 @@ func (s AccountEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AccountEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -4061,8 +3952,12 @@ var trustLineFlagsMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for TrustLineFlags func (e TrustLineFlags) ValidEnum(v int32) bool { - _, ok := trustLineFlagsMap[v] - return ok + switch v { + case 1, 2, 4: + return true + default: + return false + } } // String returns the name of `e` @@ -4073,16 +3968,19 @@ func (e TrustLineFlags) String() string { // EncodeTo encodes this value using the Encoder. func (e TrustLineFlags) EncodeTo(enc *xdr.Encoder) error { - if _, ok := trustLineFlagsMap[int32(e)]; !ok { + switch int32(e) { + case 1, 2, 4: + // valid + default: return fmt.Errorf("'%d' is not a valid TrustLineFlags enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*TrustLineFlags)(nil) +var _ xdr.DecoderFrom = (*TrustLineFlags)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *TrustLineFlags) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TrustLineFlags: %w", ErrMaxDecodingDepthReached) @@ -4092,7 +3990,10 @@ func (e *TrustLineFlags) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding TrustLineFlags: %w", err) } - if _, ok := trustLineFlagsMap[v]; !ok { + switch v { + case 1, 2, 4: + // valid + default: return n, fmt.Errorf("'%d' is not a valid TrustLineFlags enum value", v) } *e = TrustLineFlags(v) @@ -4109,11 +4010,8 @@ func (s TrustLineFlags) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TrustLineFlags) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -4153,6 +4051,10 @@ type LiquidityPoolType int32 const ( LiquidityPoolTypeLiquidityPoolConstantProduct LiquidityPoolType = 0 ) +const ( + _LiquidityPoolType_Min int32 = 0 + _LiquidityPoolType_Max int32 = 0 +) var liquidityPoolTypeMap = map[int32]string{ 0: "LiquidityPoolTypeLiquidityPoolConstantProduct", @@ -4161,8 +4063,7 @@ var liquidityPoolTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for LiquidityPoolType func (e LiquidityPoolType) ValidEnum(v int32) bool { - _, ok := liquidityPoolTypeMap[v] - return ok + return v >= _LiquidityPoolType_Min && v <= _LiquidityPoolType_Max } // String returns the name of `e` @@ -4173,16 +4074,16 @@ func (e LiquidityPoolType) String() string { // EncodeTo encodes this value using the Encoder. func (e LiquidityPoolType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := liquidityPoolTypeMap[int32(e)]; !ok { + if int32(e) < _LiquidityPoolType_Min || int32(e) > _LiquidityPoolType_Max { return fmt.Errorf("'%d' is not a valid LiquidityPoolType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*LiquidityPoolType)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *LiquidityPoolType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolType: %w", ErrMaxDecodingDepthReached) @@ -4192,7 +4093,7 @@ func (e *LiquidityPoolType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding LiquidityPoolType: %w", err) } - if _, ok := liquidityPoolTypeMap[v]; !ok { + if v < _LiquidityPoolType_Min || v > _LiquidityPoolType_Max { return n, fmt.Errorf("'%d' is not a valid LiquidityPoolType enum value", v) } *e = LiquidityPoolType(v) @@ -4209,11 +4110,8 @@ func (s LiquidityPoolType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -4308,75 +4206,57 @@ func NewTrustLineAsset(aType AssetType, value interface{}) (result TrustLineAsse // MustAlphaNum4 retrieves the AlphaNum4 value from the union, // panicing if the value is not set. func (u TrustLineAsset) MustAlphaNum4() AlphaNum4 { - val, ok := u.GetAlphaNum4() - - if !ok { - panic("arm AlphaNum4 is not set") + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum4 { + return *u.AlphaNum4 } - - return val + panic("arm AlphaNum4 is not set") } // GetAlphaNum4 retrieves the AlphaNum4 value from the union, // returning ok if the union's switch indicated the value is valid. func (u TrustLineAsset) GetAlphaNum4() (result AlphaNum4, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AlphaNum4" { + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum4 { result = *u.AlphaNum4 ok = true } - return } // MustAlphaNum12 retrieves the AlphaNum12 value from the union, // panicing if the value is not set. func (u TrustLineAsset) MustAlphaNum12() AlphaNum12 { - val, ok := u.GetAlphaNum12() - - if !ok { - panic("arm AlphaNum12 is not set") + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum12 { + return *u.AlphaNum12 } - - return val + panic("arm AlphaNum12 is not set") } // GetAlphaNum12 retrieves the AlphaNum12 value from the union, // returning ok if the union's switch indicated the value is valid. func (u TrustLineAsset) GetAlphaNum12() (result AlphaNum12, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AlphaNum12" { + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum12 { result = *u.AlphaNum12 ok = true } - return } // MustLiquidityPoolId retrieves the LiquidityPoolId value from the union, // panicing if the value is not set. func (u TrustLineAsset) MustLiquidityPoolId() PoolId { - val, ok := u.GetLiquidityPoolId() - - if !ok { - panic("arm LiquidityPoolId is not set") + if AssetType(u.Type) == AssetTypeAssetTypePoolShare { + return *u.LiquidityPoolId } - - return val + panic("arm LiquidityPoolId is not set") } // GetLiquidityPoolId retrieves the LiquidityPoolId value from the union, // returning ok if the union's switch indicated the value is valid. func (u TrustLineAsset) GetLiquidityPoolId() (result PoolId, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LiquidityPoolId" { + if AssetType(u.Type) == AssetTypeAssetTypePoolShare { result = *u.LiquidityPoolId ok = true } - return } @@ -4409,9 +4289,9 @@ func (u TrustLineAsset) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (AssetType) switch value '%d' is not valid for union TrustLineAsset", u.Type) } -var _ decoderFrom = (*TrustLineAsset)(nil) +var _ xdr.DecoderFrom = (*TrustLineAsset)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TrustLineAsset) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TrustLineAsset: %w", ErrMaxDecodingDepthReached) @@ -4429,7 +4309,9 @@ func (u *TrustLineAsset) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) // Void return n, nil case AssetTypeAssetTypeCreditAlphanum4: - u.AlphaNum4 = new(AlphaNum4) + if u.AlphaNum4 == nil { + u.AlphaNum4 = new(AlphaNum4) + } nTmp, err = (*u.AlphaNum4).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -4437,7 +4319,9 @@ func (u *TrustLineAsset) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case AssetTypeAssetTypeCreditAlphanum12: - u.AlphaNum12 = new(AlphaNum12) + if u.AlphaNum12 == nil { + u.AlphaNum12 = new(AlphaNum12) + } nTmp, err = (*u.AlphaNum12).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -4445,7 +4329,9 @@ func (u *TrustLineAsset) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case AssetTypeAssetTypePoolShare: - u.LiquidityPoolId = new(PoolId) + if u.LiquidityPoolId == nil { + u.LiquidityPoolId = new(PoolId) + } nTmp, err = (*u.LiquidityPoolId).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -4466,11 +4352,8 @@ func (s TrustLineAsset) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TrustLineAsset) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -4535,9 +4418,9 @@ func (u TrustLineEntryExtensionV2Ext) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union TrustLineEntryExtensionV2Ext", u.V) } -var _ decoderFrom = (*TrustLineEntryExtensionV2Ext)(nil) +var _ xdr.DecoderFrom = (*TrustLineEntryExtensionV2Ext)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TrustLineEntryExtensionV2Ext) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TrustLineEntryExtensionV2Ext: %w", ErrMaxDecodingDepthReached) @@ -4568,11 +4451,8 @@ func (s TrustLineEntryExtensionV2Ext) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TrustLineEntryExtensionV2Ext) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -4616,9 +4496,9 @@ func (s *TrustLineEntryExtensionV2) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TrustLineEntryExtensionV2)(nil) +var _ xdr.DecoderFrom = (*TrustLineEntryExtensionV2)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TrustLineEntryExtensionV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TrustLineEntryExtensionV2: %w", ErrMaxDecodingDepthReached) @@ -4649,11 +4529,8 @@ func (s TrustLineEntryExtensionV2) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TrustLineEntryExtensionV2) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -4719,25 +4596,19 @@ func NewTrustLineEntryV1Ext(v int32, value interface{}) (result TrustLineEntryV1 // MustV2 retrieves the V2 value from the union, // panicing if the value is not set. func (u TrustLineEntryV1Ext) MustV2() TrustLineEntryExtensionV2 { - val, ok := u.GetV2() - - if !ok { - panic("arm V2 is not set") + if int32(u.V) == 2 { + return *u.V2 } - - return val + panic("arm V2 is not set") } // GetV2 retrieves the V2 value from the union, // returning ok if the union's switch indicated the value is valid. func (u TrustLineEntryV1Ext) GetV2() (result TrustLineEntryExtensionV2, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V2" { + if int32(u.V) == 2 { result = *u.V2 ok = true } - return } @@ -4760,9 +4631,9 @@ func (u TrustLineEntryV1Ext) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union TrustLineEntryV1Ext", u.V) } -var _ decoderFrom = (*TrustLineEntryV1Ext)(nil) +var _ xdr.DecoderFrom = (*TrustLineEntryV1Ext)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TrustLineEntryV1Ext) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TrustLineEntryV1Ext: %w", ErrMaxDecodingDepthReached) @@ -4780,7 +4651,9 @@ func (u *TrustLineEntryV1Ext) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er // Void return n, nil case 2: - u.V2 = new(TrustLineEntryExtensionV2) + if u.V2 == nil { + u.V2 = new(TrustLineEntryExtensionV2) + } nTmp, err = (*u.V2).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -4801,11 +4674,8 @@ func (s TrustLineEntryV1Ext) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TrustLineEntryV1Ext) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -4851,9 +4721,9 @@ func (s *TrustLineEntryV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TrustLineEntryV1)(nil) +var _ xdr.DecoderFrom = (*TrustLineEntryV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TrustLineEntryV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TrustLineEntryV1: %w", ErrMaxDecodingDepthReached) @@ -4884,11 +4754,8 @@ func (s TrustLineEntryV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TrustLineEntryV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -4966,25 +4833,19 @@ func NewTrustLineEntryExt(v int32, value interface{}) (result TrustLineEntryExt, // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u TrustLineEntryExt) MustV1() TrustLineEntryV1 { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if int32(u.V) == 1 { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u TrustLineEntryExt) GetV1() (result TrustLineEntryV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1" { + if int32(u.V) == 1 { result = *u.V1 ok = true } - return } @@ -5007,9 +4868,9 @@ func (u TrustLineEntryExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union TrustLineEntryExt", u.V) } -var _ decoderFrom = (*TrustLineEntryExt)(nil) +var _ xdr.DecoderFrom = (*TrustLineEntryExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TrustLineEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TrustLineEntryExt: %w", ErrMaxDecodingDepthReached) @@ -5027,7 +4888,9 @@ func (u *TrustLineEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro // Void return n, nil case 1: - u.V1 = new(TrustLineEntryV1) + if u.V1 == nil { + u.V1 = new(TrustLineEntryV1) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -5048,11 +4911,8 @@ func (s TrustLineEntryExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TrustLineEntryExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -5133,9 +4993,9 @@ func (s *TrustLineEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TrustLineEntry)(nil) +var _ xdr.DecoderFrom = (*TrustLineEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TrustLineEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TrustLineEntry: %w", ErrMaxDecodingDepthReached) @@ -5186,11 +5046,8 @@ func (s TrustLineEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TrustLineEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -5217,6 +5074,10 @@ type OfferEntryFlags int32 const ( OfferEntryFlagsPassiveFlag OfferEntryFlags = 1 ) +const ( + _OfferEntryFlags_Min int32 = 1 + _OfferEntryFlags_Max int32 = 1 +) var offerEntryFlagsMap = map[int32]string{ 1: "OfferEntryFlagsPassiveFlag", @@ -5225,8 +5086,7 @@ var offerEntryFlagsMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for OfferEntryFlags func (e OfferEntryFlags) ValidEnum(v int32) bool { - _, ok := offerEntryFlagsMap[v] - return ok + return v >= _OfferEntryFlags_Min && v <= _OfferEntryFlags_Max } // String returns the name of `e` @@ -5237,16 +5097,16 @@ func (e OfferEntryFlags) String() string { // EncodeTo encodes this value using the Encoder. func (e OfferEntryFlags) EncodeTo(enc *xdr.Encoder) error { - if _, ok := offerEntryFlagsMap[int32(e)]; !ok { + if int32(e) < _OfferEntryFlags_Min || int32(e) > _OfferEntryFlags_Max { return fmt.Errorf("'%d' is not a valid OfferEntryFlags enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*OfferEntryFlags)(nil) +var _ xdr.DecoderFrom = (*OfferEntryFlags)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *OfferEntryFlags) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding OfferEntryFlags: %w", ErrMaxDecodingDepthReached) @@ -5256,7 +5116,7 @@ func (e *OfferEntryFlags) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding OfferEntryFlags: %w", err) } - if _, ok := offerEntryFlagsMap[v]; !ok { + if v < _OfferEntryFlags_Min || v > _OfferEntryFlags_Max { return n, fmt.Errorf("'%d' is not a valid OfferEntryFlags enum value", v) } *e = OfferEntryFlags(v) @@ -5273,11 +5133,8 @@ func (s OfferEntryFlags) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *OfferEntryFlags) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -5347,9 +5204,9 @@ func (u OfferEntryExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union OfferEntryExt", u.V) } -var _ decoderFrom = (*OfferEntryExt)(nil) +var _ xdr.DecoderFrom = (*OfferEntryExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *OfferEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding OfferEntryExt: %w", ErrMaxDecodingDepthReached) @@ -5380,11 +5237,8 @@ func (s OfferEntryExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *OfferEntryExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -5465,9 +5319,9 @@ func (s *OfferEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*OfferEntry)(nil) +var _ xdr.DecoderFrom = (*OfferEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *OfferEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding OfferEntry: %w", ErrMaxDecodingDepthReached) @@ -5528,11 +5382,8 @@ func (s OfferEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *OfferEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -5597,9 +5448,9 @@ func (u DataEntryExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union DataEntryExt", u.V) } -var _ decoderFrom = (*DataEntryExt)(nil) +var _ xdr.DecoderFrom = (*DataEntryExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *DataEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding DataEntryExt: %w", ErrMaxDecodingDepthReached) @@ -5630,11 +5481,8 @@ func (s DataEntryExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *DataEntryExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -5689,9 +5537,9 @@ func (s *DataEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*DataEntry)(nil) +var _ xdr.DecoderFrom = (*DataEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *DataEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding DataEntry: %w", ErrMaxDecodingDepthReached) @@ -5732,11 +5580,8 @@ func (s DataEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *DataEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -5771,6 +5616,10 @@ const ( ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime ClaimPredicateType = 4 ClaimPredicateTypeClaimPredicateBeforeRelativeTime ClaimPredicateType = 5 ) +const ( + _ClaimPredicateType_Min int32 = 0 + _ClaimPredicateType_Max int32 = 5 +) var claimPredicateTypeMap = map[int32]string{ 0: "ClaimPredicateTypeClaimPredicateUnconditional", @@ -5784,8 +5633,7 @@ var claimPredicateTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ClaimPredicateType func (e ClaimPredicateType) ValidEnum(v int32) bool { - _, ok := claimPredicateTypeMap[v] - return ok + return v >= _ClaimPredicateType_Min && v <= _ClaimPredicateType_Max } // String returns the name of `e` @@ -5796,16 +5644,16 @@ func (e ClaimPredicateType) String() string { // EncodeTo encodes this value using the Encoder. func (e ClaimPredicateType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := claimPredicateTypeMap[int32(e)]; !ok { + if int32(e) < _ClaimPredicateType_Min || int32(e) > _ClaimPredicateType_Max { return fmt.Errorf("'%d' is not a valid ClaimPredicateType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ClaimPredicateType)(nil) +var _ xdr.DecoderFrom = (*ClaimPredicateType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ClaimPredicateType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimPredicateType: %w", ErrMaxDecodingDepthReached) @@ -5815,7 +5663,7 @@ func (e *ClaimPredicateType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err if err != nil { return n, fmt.Errorf("decoding ClaimPredicateType: %w", err) } - if _, ok := claimPredicateTypeMap[v]; !ok { + if v < _ClaimPredicateType_Min || v > _ClaimPredicateType_Max { return n, fmt.Errorf("'%d' is not a valid ClaimPredicateType enum value", v) } *e = ClaimPredicateType(v) @@ -5832,11 +5680,8 @@ func (s ClaimPredicateType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimPredicateType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -5873,8 +5718,8 @@ type ClaimPredicate struct { AndPredicates *[]ClaimPredicate `xdrmaxsize:"2"` OrPredicates *[]ClaimPredicate `xdrmaxsize:"2"` NotPredicate **ClaimPredicate - AbsBefore *Int64 - RelBefore *Int64 + AbsBefore Int64 + RelBefore Int64 } // SwitchFieldName returns the field name in which this union's @@ -5936,14 +5781,14 @@ func NewClaimPredicate(aType ClaimPredicateType, value interface{}) (result Clai err = errors.New("invalid value, must be Int64") return } - result.AbsBefore = &tv + result.AbsBefore = tv case ClaimPredicateTypeClaimPredicateBeforeRelativeTime: tv, ok := value.(Int64) if !ok { err = errors.New("invalid value, must be Int64") return } - result.RelBefore = &tv + result.RelBefore = tv } return } @@ -5951,125 +5796,95 @@ func NewClaimPredicate(aType ClaimPredicateType, value interface{}) (result Clai // MustAndPredicates retrieves the AndPredicates value from the union, // panicing if the value is not set. func (u ClaimPredicate) MustAndPredicates() []ClaimPredicate { - val, ok := u.GetAndPredicates() - - if !ok { - panic("arm AndPredicates is not set") + if ClaimPredicateType(u.Type) == ClaimPredicateTypeClaimPredicateAnd { + return *u.AndPredicates } - - return val + panic("arm AndPredicates is not set") } // GetAndPredicates retrieves the AndPredicates value from the union, // returning ok if the union's switch indicated the value is valid. func (u ClaimPredicate) GetAndPredicates() (result []ClaimPredicate, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AndPredicates" { + if ClaimPredicateType(u.Type) == ClaimPredicateTypeClaimPredicateAnd { result = *u.AndPredicates ok = true } - return } // MustOrPredicates retrieves the OrPredicates value from the union, // panicing if the value is not set. func (u ClaimPredicate) MustOrPredicates() []ClaimPredicate { - val, ok := u.GetOrPredicates() - - if !ok { - panic("arm OrPredicates is not set") + if ClaimPredicateType(u.Type) == ClaimPredicateTypeClaimPredicateOr { + return *u.OrPredicates } - - return val + panic("arm OrPredicates is not set") } // GetOrPredicates retrieves the OrPredicates value from the union, // returning ok if the union's switch indicated the value is valid. func (u ClaimPredicate) GetOrPredicates() (result []ClaimPredicate, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "OrPredicates" { + if ClaimPredicateType(u.Type) == ClaimPredicateTypeClaimPredicateOr { result = *u.OrPredicates ok = true } - return } // MustNotPredicate retrieves the NotPredicate value from the union, // panicing if the value is not set. func (u ClaimPredicate) MustNotPredicate() *ClaimPredicate { - val, ok := u.GetNotPredicate() - - if !ok { - panic("arm NotPredicate is not set") + if ClaimPredicateType(u.Type) == ClaimPredicateTypeClaimPredicateNot { + return *u.NotPredicate } - - return val + panic("arm NotPredicate is not set") } // GetNotPredicate retrieves the NotPredicate value from the union, // returning ok if the union's switch indicated the value is valid. func (u ClaimPredicate) GetNotPredicate() (result *ClaimPredicate, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "NotPredicate" { + if ClaimPredicateType(u.Type) == ClaimPredicateTypeClaimPredicateNot { result = *u.NotPredicate ok = true } - return } // MustAbsBefore retrieves the AbsBefore value from the union, // panicing if the value is not set. func (u ClaimPredicate) MustAbsBefore() Int64 { - val, ok := u.GetAbsBefore() - - if !ok { - panic("arm AbsBefore is not set") + if ClaimPredicateType(u.Type) == ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime { + return u.AbsBefore } - - return val + panic("arm AbsBefore is not set") } // GetAbsBefore retrieves the AbsBefore value from the union, // returning ok if the union's switch indicated the value is valid. func (u ClaimPredicate) GetAbsBefore() (result Int64, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AbsBefore" { - result = *u.AbsBefore + if ClaimPredicateType(u.Type) == ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime { + result = u.AbsBefore ok = true } - return } // MustRelBefore retrieves the RelBefore value from the union, // panicing if the value is not set. func (u ClaimPredicate) MustRelBefore() Int64 { - val, ok := u.GetRelBefore() - - if !ok { - panic("arm RelBefore is not set") + if ClaimPredicateType(u.Type) == ClaimPredicateTypeClaimPredicateBeforeRelativeTime { + return u.RelBefore } - - return val + panic("arm RelBefore is not set") } // GetRelBefore retrieves the RelBefore value from the union, // returning ok if the union's switch indicated the value is valid. func (u ClaimPredicate) GetRelBefore() (result Int64, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "RelBefore" { - result = *u.RelBefore + if ClaimPredicateType(u.Type) == ClaimPredicateTypeClaimPredicateBeforeRelativeTime { + result = u.RelBefore ok = true } - return } @@ -6114,12 +5929,12 @@ func (u ClaimPredicate) EncodeTo(e *xdr.Encoder) error { } return nil case ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime: - if err = (*u.AbsBefore).EncodeTo(e); err != nil { + if err = u.AbsBefore.EncodeTo(e); err != nil { return err } return nil case ClaimPredicateTypeClaimPredicateBeforeRelativeTime: - if err = (*u.RelBefore).EncodeTo(e); err != nil { + if err = u.RelBefore.EncodeTo(e); err != nil { return err } return nil @@ -6127,9 +5942,9 @@ func (u ClaimPredicate) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (ClaimPredicateType) switch value '%d' is not valid for union ClaimPredicate", u.Type) } -var _ decoderFrom = (*ClaimPredicate)(nil) +var _ xdr.DecoderFrom = (*ClaimPredicate)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ClaimPredicate) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimPredicate: %w", ErrMaxDecodingDepthReached) @@ -6147,7 +5962,9 @@ func (u *ClaimPredicate) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) // Void return n, nil case ClaimPredicateTypeClaimPredicateAnd: - u.AndPredicates = new([]ClaimPredicate) + if u.AndPredicates == nil { + u.AndPredicates = new([]ClaimPredicate) + } var l uint32 l, nTmp, err = d.DecodeUint() n += nTmp @@ -6157,12 +5974,17 @@ func (u *ClaimPredicate) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if l > 2 { return n, fmt.Errorf("decoding ClaimPredicate: data size (%d) exceeds size limit (2)", l) } - (*u.AndPredicates) = nil - if l > 0 { + if l == 0 { + (*u.AndPredicates) = (*u.AndPredicates)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ClaimPredicate: length (%d) exceeds remaining input length (%d)", l, il) } - (*u.AndPredicates) = make([]ClaimPredicate, l) + if cap((*u.AndPredicates)) >= int(l) { + (*u.AndPredicates) = (*u.AndPredicates)[:l] + } else { + (*u.AndPredicates) = make([]ClaimPredicate, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*u.AndPredicates)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -6173,7 +5995,9 @@ func (u *ClaimPredicate) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case ClaimPredicateTypeClaimPredicateOr: - u.OrPredicates = new([]ClaimPredicate) + if u.OrPredicates == nil { + u.OrPredicates = new([]ClaimPredicate) + } var l uint32 l, nTmp, err = d.DecodeUint() n += nTmp @@ -6183,12 +6007,17 @@ func (u *ClaimPredicate) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if l > 2 { return n, fmt.Errorf("decoding ClaimPredicate: data size (%d) exceeds size limit (2)", l) } - (*u.OrPredicates) = nil - if l > 0 { + if l == 0 { + (*u.OrPredicates) = (*u.OrPredicates)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ClaimPredicate: length (%d) exceeds remaining input length (%d)", l, il) } - (*u.OrPredicates) = make([]ClaimPredicate, l) + if cap((*u.OrPredicates)) >= int(l) { + (*u.OrPredicates) = (*u.OrPredicates)[:l] + } else { + (*u.OrPredicates) = make([]ClaimPredicate, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*u.OrPredicates)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -6199,7 +6028,9 @@ func (u *ClaimPredicate) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case ClaimPredicateTypeClaimPredicateNot: - u.NotPredicate = new(*ClaimPredicate) + if u.NotPredicate == nil { + u.NotPredicate = new(*ClaimPredicate) + } var b bool b, nTmp, err = d.DecodeBool() n += nTmp @@ -6217,16 +6048,14 @@ func (u *ClaimPredicate) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime: - u.AbsBefore = new(Int64) - nTmp, err = (*u.AbsBefore).DecodeFrom(d, maxDepth) + nTmp, err = u.AbsBefore.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Int64: %w", err) } return n, nil case ClaimPredicateTypeClaimPredicateBeforeRelativeTime: - u.RelBefore = new(Int64) - nTmp, err = (*u.RelBefore).DecodeFrom(d, maxDepth) + nTmp, err = u.RelBefore.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Int64: %w", err) @@ -6246,11 +6075,8 @@ func (s ClaimPredicate) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimPredicate) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -6275,6 +6101,10 @@ type ClaimantType int32 const ( ClaimantTypeClaimantTypeV0 ClaimantType = 0 ) +const ( + _ClaimantType_Min int32 = 0 + _ClaimantType_Max int32 = 0 +) var claimantTypeMap = map[int32]string{ 0: "ClaimantTypeClaimantTypeV0", @@ -6283,8 +6113,7 @@ var claimantTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ClaimantType func (e ClaimantType) ValidEnum(v int32) bool { - _, ok := claimantTypeMap[v] - return ok + return v >= _ClaimantType_Min && v <= _ClaimantType_Max } // String returns the name of `e` @@ -6295,16 +6124,16 @@ func (e ClaimantType) String() string { // EncodeTo encodes this value using the Encoder. func (e ClaimantType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := claimantTypeMap[int32(e)]; !ok { + if int32(e) < _ClaimantType_Min || int32(e) > _ClaimantType_Max { return fmt.Errorf("'%d' is not a valid ClaimantType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ClaimantType)(nil) +var _ xdr.DecoderFrom = (*ClaimantType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ClaimantType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimantType: %w", ErrMaxDecodingDepthReached) @@ -6314,7 +6143,7 @@ func (e *ClaimantType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ClaimantType: %w", err) } - if _, ok := claimantTypeMap[v]; !ok { + if v < _ClaimantType_Min || v > _ClaimantType_Max { return n, fmt.Errorf("'%d' is not a valid ClaimantType enum value", v) } *e = ClaimantType(v) @@ -6331,11 +6160,8 @@ func (s ClaimantType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimantType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -6373,9 +6199,9 @@ func (s *ClaimantV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ClaimantV0)(nil) +var _ xdr.DecoderFrom = (*ClaimantV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ClaimantV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimantV0: %w", ErrMaxDecodingDepthReached) @@ -6406,11 +6232,8 @@ func (s ClaimantV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimantV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -6474,25 +6297,19 @@ func NewClaimant(aType ClaimantType, value interface{}) (result Claimant, err er // MustV0 retrieves the V0 value from the union, // panicing if the value is not set. func (u Claimant) MustV0() ClaimantV0 { - val, ok := u.GetV0() - - if !ok { - panic("arm V0 is not set") + if ClaimantType(u.Type) == ClaimantTypeClaimantTypeV0 { + return *u.V0 } - - return val + panic("arm V0 is not set") } // GetV0 retrieves the V0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u Claimant) GetV0() (result ClaimantV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "V0" { + if ClaimantType(u.Type) == ClaimantTypeClaimantTypeV0 { result = *u.V0 ok = true } - return } @@ -6512,9 +6329,9 @@ func (u Claimant) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (ClaimantType) switch value '%d' is not valid for union Claimant", u.Type) } -var _ decoderFrom = (*Claimant)(nil) +var _ xdr.DecoderFrom = (*Claimant)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *Claimant) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Claimant: %w", ErrMaxDecodingDepthReached) @@ -6529,7 +6346,9 @@ func (u *Claimant) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch ClaimantType(u.Type) { case ClaimantTypeClaimantTypeV0: - u.V0 = new(ClaimantV0) + if u.V0 == nil { + u.V0 = new(ClaimantV0) + } nTmp, err = (*u.V0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -6550,11 +6369,8 @@ func (s Claimant) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Claimant) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -6581,6 +6397,10 @@ type ClaimableBalanceFlags int32 const ( ClaimableBalanceFlagsClaimableBalanceClawbackEnabledFlag ClaimableBalanceFlags = 1 ) +const ( + _ClaimableBalanceFlags_Min int32 = 1 + _ClaimableBalanceFlags_Max int32 = 1 +) var claimableBalanceFlagsMap = map[int32]string{ 1: "ClaimableBalanceFlagsClaimableBalanceClawbackEnabledFlag", @@ -6589,8 +6409,7 @@ var claimableBalanceFlagsMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ClaimableBalanceFlags func (e ClaimableBalanceFlags) ValidEnum(v int32) bool { - _, ok := claimableBalanceFlagsMap[v] - return ok + return v >= _ClaimableBalanceFlags_Min && v <= _ClaimableBalanceFlags_Max } // String returns the name of `e` @@ -6601,16 +6420,16 @@ func (e ClaimableBalanceFlags) String() string { // EncodeTo encodes this value using the Encoder. func (e ClaimableBalanceFlags) EncodeTo(enc *xdr.Encoder) error { - if _, ok := claimableBalanceFlagsMap[int32(e)]; !ok { + if int32(e) < _ClaimableBalanceFlags_Min || int32(e) > _ClaimableBalanceFlags_Max { return fmt.Errorf("'%d' is not a valid ClaimableBalanceFlags enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ClaimableBalanceFlags)(nil) +var _ xdr.DecoderFrom = (*ClaimableBalanceFlags)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ClaimableBalanceFlags) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimableBalanceFlags: %w", ErrMaxDecodingDepthReached) @@ -6620,7 +6439,7 @@ func (e *ClaimableBalanceFlags) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding ClaimableBalanceFlags: %w", err) } - if _, ok := claimableBalanceFlagsMap[v]; !ok { + if v < _ClaimableBalanceFlags_Min || v > _ClaimableBalanceFlags_Max { return n, fmt.Errorf("'%d' is not a valid ClaimableBalanceFlags enum value", v) } *e = ClaimableBalanceFlags(v) @@ -6637,11 +6456,8 @@ func (s ClaimableBalanceFlags) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimableBalanceFlags) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -6711,9 +6527,9 @@ func (u ClaimableBalanceEntryExtensionV1Ext) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union ClaimableBalanceEntryExtensionV1Ext", u.V) } -var _ decoderFrom = (*ClaimableBalanceEntryExtensionV1Ext)(nil) +var _ xdr.DecoderFrom = (*ClaimableBalanceEntryExtensionV1Ext)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ClaimableBalanceEntryExtensionV1Ext) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimableBalanceEntryExtensionV1Ext: %w", ErrMaxDecodingDepthReached) @@ -6744,11 +6560,8 @@ func (s ClaimableBalanceEntryExtensionV1Ext) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimableBalanceEntryExtensionV1Ext) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -6792,9 +6605,9 @@ func (s *ClaimableBalanceEntryExtensionV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ClaimableBalanceEntryExtensionV1)(nil) +var _ xdr.DecoderFrom = (*ClaimableBalanceEntryExtensionV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ClaimableBalanceEntryExtensionV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimableBalanceEntryExtensionV1: %w", ErrMaxDecodingDepthReached) @@ -6825,11 +6638,8 @@ func (s ClaimableBalanceEntryExtensionV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimableBalanceEntryExtensionV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -6895,25 +6705,19 @@ func NewClaimableBalanceEntryExt(v int32, value interface{}) (result ClaimableBa // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u ClaimableBalanceEntryExt) MustV1() ClaimableBalanceEntryExtensionV1 { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if int32(u.V) == 1 { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ClaimableBalanceEntryExt) GetV1() (result ClaimableBalanceEntryExtensionV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1" { + if int32(u.V) == 1 { result = *u.V1 ok = true } - return } @@ -6936,9 +6740,9 @@ func (u ClaimableBalanceEntryExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union ClaimableBalanceEntryExt", u.V) } -var _ decoderFrom = (*ClaimableBalanceEntryExt)(nil) +var _ xdr.DecoderFrom = (*ClaimableBalanceEntryExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ClaimableBalanceEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimableBalanceEntryExt: %w", ErrMaxDecodingDepthReached) @@ -6956,7 +6760,9 @@ func (u *ClaimableBalanceEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (in // Void return n, nil case 1: - u.V1 = new(ClaimableBalanceEntryExtensionV1) + if u.V1 == nil { + u.V1 = new(ClaimableBalanceEntryExtensionV1) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -6977,11 +6783,8 @@ func (s ClaimableBalanceEntryExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimableBalanceEntryExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -7055,9 +6858,9 @@ func (s *ClaimableBalanceEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ClaimableBalanceEntry)(nil) +var _ xdr.DecoderFrom = (*ClaimableBalanceEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ClaimableBalanceEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimableBalanceEntry: %w", ErrMaxDecodingDepthReached) @@ -7079,12 +6882,17 @@ func (s *ClaimableBalanceEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if l > 10 { return n, fmt.Errorf("decoding Claimant: data size (%d) exceeds size limit (10)", l) } - s.Claimants = nil - if l > 0 { + if l == 0 { + s.Claimants = s.Claimants[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Claimant: length (%d) exceeds remaining input length (%d)", l, il) } - s.Claimants = make([]Claimant, l) + if cap(s.Claimants) >= int(l) { + s.Claimants = s.Claimants[:l] + } else { + s.Claimants = make([]Claimant, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Claimants[i].DecodeFrom(d, maxDepth) n += nTmp @@ -7121,11 +6929,8 @@ func (s ClaimableBalanceEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimableBalanceEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -7168,9 +6973,9 @@ func (s *LiquidityPoolConstantProductParameters) EncodeTo(e *xdr.Encoder) error return nil } -var _ decoderFrom = (*LiquidityPoolConstantProductParameters)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolConstantProductParameters)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LiquidityPoolConstantProductParameters) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolConstantProductParameters: %w", ErrMaxDecodingDepthReached) @@ -7206,11 +7011,8 @@ func (s LiquidityPoolConstantProductParameters) MarshalBinary() ([]byte, error) // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolConstantProductParameters) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -7265,9 +7067,9 @@ func (s *LiquidityPoolEntryConstantProduct) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LiquidityPoolEntryConstantProduct)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolEntryConstantProduct)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LiquidityPoolEntryConstantProduct) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolEntryConstantProduct: %w", ErrMaxDecodingDepthReached) @@ -7313,11 +7115,8 @@ func (s LiquidityPoolEntryConstantProduct) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolEntryConstantProduct) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -7386,25 +7185,19 @@ func NewLiquidityPoolEntryBody(aType LiquidityPoolType, value interface{}) (resu // MustConstantProduct retrieves the ConstantProduct value from the union, // panicing if the value is not set. func (u LiquidityPoolEntryBody) MustConstantProduct() LiquidityPoolEntryConstantProduct { - val, ok := u.GetConstantProduct() - - if !ok { - panic("arm ConstantProduct is not set") + if LiquidityPoolType(u.Type) == LiquidityPoolTypeLiquidityPoolConstantProduct { + return *u.ConstantProduct } - - return val + panic("arm ConstantProduct is not set") } // GetConstantProduct retrieves the ConstantProduct value from the union, // returning ok if the union's switch indicated the value is valid. func (u LiquidityPoolEntryBody) GetConstantProduct() (result LiquidityPoolEntryConstantProduct, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ConstantProduct" { + if LiquidityPoolType(u.Type) == LiquidityPoolTypeLiquidityPoolConstantProduct { result = *u.ConstantProduct ok = true } - return } @@ -7424,9 +7217,9 @@ func (u LiquidityPoolEntryBody) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (LiquidityPoolType) switch value '%d' is not valid for union LiquidityPoolEntryBody", u.Type) } -var _ decoderFrom = (*LiquidityPoolEntryBody)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolEntryBody)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LiquidityPoolEntryBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolEntryBody: %w", ErrMaxDecodingDepthReached) @@ -7441,7 +7234,9 @@ func (u *LiquidityPoolEntryBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, } switch LiquidityPoolType(u.Type) { case LiquidityPoolTypeLiquidityPoolConstantProduct: - u.ConstantProduct = new(LiquidityPoolEntryConstantProduct) + if u.ConstantProduct == nil { + u.ConstantProduct = new(LiquidityPoolEntryConstantProduct) + } nTmp, err = (*u.ConstantProduct).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -7462,11 +7257,8 @@ func (s LiquidityPoolEntryBody) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolEntryBody) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -7519,9 +7311,9 @@ func (s *LiquidityPoolEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LiquidityPoolEntry)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LiquidityPoolEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolEntry: %w", ErrMaxDecodingDepthReached) @@ -7552,11 +7344,8 @@ func (s LiquidityPoolEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -7582,6 +7371,10 @@ const ( ContractDataDurabilityTemporary ContractDataDurability = 0 ContractDataDurabilityPersistent ContractDataDurability = 1 ) +const ( + _ContractDataDurability_Min int32 = 0 + _ContractDataDurability_Max int32 = 1 +) var contractDataDurabilityMap = map[int32]string{ 0: "ContractDataDurabilityTemporary", @@ -7591,8 +7384,7 @@ var contractDataDurabilityMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ContractDataDurability func (e ContractDataDurability) ValidEnum(v int32) bool { - _, ok := contractDataDurabilityMap[v] - return ok + return v >= _ContractDataDurability_Min && v <= _ContractDataDurability_Max } // String returns the name of `e` @@ -7603,16 +7395,16 @@ func (e ContractDataDurability) String() string { // EncodeTo encodes this value using the Encoder. func (e ContractDataDurability) EncodeTo(enc *xdr.Encoder) error { - if _, ok := contractDataDurabilityMap[int32(e)]; !ok { + if int32(e) < _ContractDataDurability_Min || int32(e) > _ContractDataDurability_Max { return fmt.Errorf("'%d' is not a valid ContractDataDurability enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ContractDataDurability)(nil) +var _ xdr.DecoderFrom = (*ContractDataDurability)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ContractDataDurability) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractDataDurability: %w", ErrMaxDecodingDepthReached) @@ -7622,7 +7414,7 @@ func (e *ContractDataDurability) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding ContractDataDurability: %w", err) } - if _, ok := contractDataDurabilityMap[v]; !ok { + if v < _ContractDataDurability_Min || v > _ContractDataDurability_Max { return n, fmt.Errorf("'%d' is not a valid ContractDataDurability enum value", v) } *e = ContractDataDurability(v) @@ -7639,11 +7431,8 @@ func (s ContractDataDurability) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractDataDurability) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -7696,9 +7485,9 @@ func (s *ContractDataEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ContractDataEntry)(nil) +var _ xdr.DecoderFrom = (*ContractDataEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ContractDataEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractDataEntry: %w", ErrMaxDecodingDepthReached) @@ -7744,11 +7533,8 @@ func (s ContractDataEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractDataEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -7830,9 +7616,9 @@ func (s *ContractCodeCostInputs) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ContractCodeCostInputs)(nil) +var _ xdr.DecoderFrom = (*ContractCodeCostInputs)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ContractCodeCostInputs) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractCodeCostInputs: %w", ErrMaxDecodingDepthReached) @@ -7908,11 +7694,8 @@ func (s ContractCodeCostInputs) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractCodeCostInputs) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -7950,9 +7733,9 @@ func (s *ContractCodeEntryV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ContractCodeEntryV1)(nil) +var _ xdr.DecoderFrom = (*ContractCodeEntryV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ContractCodeEntryV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractCodeEntryV1: %w", ErrMaxDecodingDepthReached) @@ -7983,11 +7766,8 @@ func (s ContractCodeEntryV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractCodeEntryV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -8057,25 +7837,19 @@ func NewContractCodeEntryExt(v int32, value interface{}) (result ContractCodeEnt // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u ContractCodeEntryExt) MustV1() ContractCodeEntryV1 { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if int32(u.V) == 1 { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ContractCodeEntryExt) GetV1() (result ContractCodeEntryV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1" { + if int32(u.V) == 1 { result = *u.V1 ok = true } - return } @@ -8098,9 +7872,9 @@ func (u ContractCodeEntryExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union ContractCodeEntryExt", u.V) } -var _ decoderFrom = (*ContractCodeEntryExt)(nil) +var _ xdr.DecoderFrom = (*ContractCodeEntryExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ContractCodeEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractCodeEntryExt: %w", ErrMaxDecodingDepthReached) @@ -8118,7 +7892,9 @@ func (u *ContractCodeEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e // Void return n, nil case 1: - u.V1 = new(ContractCodeEntryV1) + if u.V1 == nil { + u.V1 = new(ContractCodeEntryV1) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -8139,11 +7915,8 @@ func (s ContractCodeEntryExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractCodeEntryExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -8196,9 +7969,9 @@ func (s *ContractCodeEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ContractCodeEntry)(nil) +var _ xdr.DecoderFrom = (*ContractCodeEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ContractCodeEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractCodeEntry: %w", ErrMaxDecodingDepthReached) @@ -8234,11 +8007,8 @@ func (s ContractCodeEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractCodeEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -8276,9 +8046,9 @@ func (s *TtlEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TtlEntry)(nil) +var _ xdr.DecoderFrom = (*TtlEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TtlEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TtlEntry: %w", ErrMaxDecodingDepthReached) @@ -8309,11 +8079,8 @@ func (s TtlEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TtlEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -8378,9 +8145,9 @@ func (u LedgerEntryExtensionV1Ext) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union LedgerEntryExtensionV1Ext", u.V) } -var _ decoderFrom = (*LedgerEntryExtensionV1Ext)(nil) +var _ xdr.DecoderFrom = (*LedgerEntryExtensionV1Ext)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LedgerEntryExtensionV1Ext) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerEntryExtensionV1Ext: %w", ErrMaxDecodingDepthReached) @@ -8411,11 +8178,8 @@ func (s LedgerEntryExtensionV1Ext) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerEntryExtensionV1Ext) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -8464,9 +8228,9 @@ func (s *LedgerEntryExtensionV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerEntryExtensionV1)(nil) +var _ xdr.DecoderFrom = (*LedgerEntryExtensionV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerEntryExtensionV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerEntryExtensionV1: %w", ErrMaxDecodingDepthReached) @@ -8507,11 +8271,8 @@ func (s LedgerEntryExtensionV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerEntryExtensionV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -8679,250 +8440,190 @@ func NewLedgerEntryData(aType LedgerEntryType, value interface{}) (result Ledger // MustAccount retrieves the Account value from the union, // panicing if the value is not set. func (u LedgerEntryData) MustAccount() AccountEntry { - val, ok := u.GetAccount() - - if !ok { - panic("arm Account is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeAccount { + return *u.Account } - - return val + panic("arm Account is not set") } // GetAccount retrieves the Account value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryData) GetAccount() (result AccountEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Account" { + if LedgerEntryType(u.Type) == LedgerEntryTypeAccount { result = *u.Account ok = true } - return } // MustTrustLine retrieves the TrustLine value from the union, // panicing if the value is not set. func (u LedgerEntryData) MustTrustLine() TrustLineEntry { - val, ok := u.GetTrustLine() - - if !ok { - panic("arm TrustLine is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeTrustline { + return *u.TrustLine } - - return val + panic("arm TrustLine is not set") } // GetTrustLine retrieves the TrustLine value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryData) GetTrustLine() (result TrustLineEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "TrustLine" { + if LedgerEntryType(u.Type) == LedgerEntryTypeTrustline { result = *u.TrustLine ok = true } - return } // MustOffer retrieves the Offer value from the union, // panicing if the value is not set. func (u LedgerEntryData) MustOffer() OfferEntry { - val, ok := u.GetOffer() - - if !ok { - panic("arm Offer is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeOffer { + return *u.Offer } - - return val + panic("arm Offer is not set") } // GetOffer retrieves the Offer value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryData) GetOffer() (result OfferEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Offer" { + if LedgerEntryType(u.Type) == LedgerEntryTypeOffer { result = *u.Offer ok = true } - return } // MustData retrieves the Data value from the union, // panicing if the value is not set. func (u LedgerEntryData) MustData() DataEntry { - val, ok := u.GetData() - - if !ok { - panic("arm Data is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeData { + return *u.Data } - - return val + panic("arm Data is not set") } // GetData retrieves the Data value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryData) GetData() (result DataEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Data" { + if LedgerEntryType(u.Type) == LedgerEntryTypeData { result = *u.Data ok = true } - return } // MustClaimableBalance retrieves the ClaimableBalance value from the union, // panicing if the value is not set. func (u LedgerEntryData) MustClaimableBalance() ClaimableBalanceEntry { - val, ok := u.GetClaimableBalance() - - if !ok { - panic("arm ClaimableBalance is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeClaimableBalance { + return *u.ClaimableBalance } - - return val + panic("arm ClaimableBalance is not set") } // GetClaimableBalance retrieves the ClaimableBalance value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryData) GetClaimableBalance() (result ClaimableBalanceEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ClaimableBalance" { + if LedgerEntryType(u.Type) == LedgerEntryTypeClaimableBalance { result = *u.ClaimableBalance ok = true } - return } // MustLiquidityPool retrieves the LiquidityPool value from the union, // panicing if the value is not set. func (u LedgerEntryData) MustLiquidityPool() LiquidityPoolEntry { - val, ok := u.GetLiquidityPool() - - if !ok { - panic("arm LiquidityPool is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeLiquidityPool { + return *u.LiquidityPool } - - return val + panic("arm LiquidityPool is not set") } // GetLiquidityPool retrieves the LiquidityPool value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryData) GetLiquidityPool() (result LiquidityPoolEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LiquidityPool" { + if LedgerEntryType(u.Type) == LedgerEntryTypeLiquidityPool { result = *u.LiquidityPool ok = true } - return } // MustContractData retrieves the ContractData value from the union, // panicing if the value is not set. func (u LedgerEntryData) MustContractData() ContractDataEntry { - val, ok := u.GetContractData() - - if !ok { - panic("arm ContractData is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeContractData { + return *u.ContractData } - - return val + panic("arm ContractData is not set") } // GetContractData retrieves the ContractData value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryData) GetContractData() (result ContractDataEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ContractData" { + if LedgerEntryType(u.Type) == LedgerEntryTypeContractData { result = *u.ContractData ok = true } - return } // MustContractCode retrieves the ContractCode value from the union, // panicing if the value is not set. func (u LedgerEntryData) MustContractCode() ContractCodeEntry { - val, ok := u.GetContractCode() - - if !ok { - panic("arm ContractCode is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeContractCode { + return *u.ContractCode } - - return val + panic("arm ContractCode is not set") } // GetContractCode retrieves the ContractCode value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryData) GetContractCode() (result ContractCodeEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ContractCode" { + if LedgerEntryType(u.Type) == LedgerEntryTypeContractCode { result = *u.ContractCode ok = true } - return } // MustConfigSetting retrieves the ConfigSetting value from the union, // panicing if the value is not set. func (u LedgerEntryData) MustConfigSetting() ConfigSettingEntry { - val, ok := u.GetConfigSetting() - - if !ok { - panic("arm ConfigSetting is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeConfigSetting { + return *u.ConfigSetting } - - return val + panic("arm ConfigSetting is not set") } // GetConfigSetting retrieves the ConfigSetting value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryData) GetConfigSetting() (result ConfigSettingEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ConfigSetting" { + if LedgerEntryType(u.Type) == LedgerEntryTypeConfigSetting { result = *u.ConfigSetting ok = true } - return } // MustTtl retrieves the Ttl value from the union, // panicing if the value is not set. func (u LedgerEntryData) MustTtl() TtlEntry { - val, ok := u.GetTtl() - - if !ok { - panic("arm Ttl is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeTtl { + return *u.Ttl } - - return val + panic("arm Ttl is not set") } // GetTtl retrieves the Ttl value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryData) GetTtl() (result TtlEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Ttl" { + if LedgerEntryType(u.Type) == LedgerEntryTypeTtl { result = *u.Ttl ok = true } - return } @@ -8987,9 +8688,9 @@ func (u LedgerEntryData) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (LedgerEntryType) switch value '%d' is not valid for union LedgerEntryData", u.Type) } -var _ decoderFrom = (*LedgerEntryData)(nil) +var _ xdr.DecoderFrom = (*LedgerEntryData)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LedgerEntryData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerEntryData: %w", ErrMaxDecodingDepthReached) @@ -9004,7 +8705,9 @@ func (u *LedgerEntryData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } switch LedgerEntryType(u.Type) { case LedgerEntryTypeAccount: - u.Account = new(AccountEntry) + if u.Account == nil { + u.Account = new(AccountEntry) + } nTmp, err = (*u.Account).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -9012,7 +8715,9 @@ func (u *LedgerEntryData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case LedgerEntryTypeTrustline: - u.TrustLine = new(TrustLineEntry) + if u.TrustLine == nil { + u.TrustLine = new(TrustLineEntry) + } nTmp, err = (*u.TrustLine).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -9020,7 +8725,9 @@ func (u *LedgerEntryData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case LedgerEntryTypeOffer: - u.Offer = new(OfferEntry) + if u.Offer == nil { + u.Offer = new(OfferEntry) + } nTmp, err = (*u.Offer).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -9028,7 +8735,9 @@ func (u *LedgerEntryData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case LedgerEntryTypeData: - u.Data = new(DataEntry) + if u.Data == nil { + u.Data = new(DataEntry) + } nTmp, err = (*u.Data).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -9036,7 +8745,9 @@ func (u *LedgerEntryData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case LedgerEntryTypeClaimableBalance: - u.ClaimableBalance = new(ClaimableBalanceEntry) + if u.ClaimableBalance == nil { + u.ClaimableBalance = new(ClaimableBalanceEntry) + } nTmp, err = (*u.ClaimableBalance).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -9044,7 +8755,9 @@ func (u *LedgerEntryData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case LedgerEntryTypeLiquidityPool: - u.LiquidityPool = new(LiquidityPoolEntry) + if u.LiquidityPool == nil { + u.LiquidityPool = new(LiquidityPoolEntry) + } nTmp, err = (*u.LiquidityPool).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -9052,7 +8765,9 @@ func (u *LedgerEntryData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case LedgerEntryTypeContractData: - u.ContractData = new(ContractDataEntry) + if u.ContractData == nil { + u.ContractData = new(ContractDataEntry) + } nTmp, err = (*u.ContractData).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -9060,7 +8775,9 @@ func (u *LedgerEntryData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case LedgerEntryTypeContractCode: - u.ContractCode = new(ContractCodeEntry) + if u.ContractCode == nil { + u.ContractCode = new(ContractCodeEntry) + } nTmp, err = (*u.ContractCode).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -9068,7 +8785,9 @@ func (u *LedgerEntryData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case LedgerEntryTypeConfigSetting: - u.ConfigSetting = new(ConfigSettingEntry) + if u.ConfigSetting == nil { + u.ConfigSetting = new(ConfigSettingEntry) + } nTmp, err = (*u.ConfigSetting).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -9076,7 +8795,9 @@ func (u *LedgerEntryData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case LedgerEntryTypeTtl: - u.Ttl = new(TtlEntry) + if u.Ttl == nil { + u.Ttl = new(TtlEntry) + } nTmp, err = (*u.Ttl).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -9097,11 +8818,8 @@ func (s LedgerEntryData) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerEntryData) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -9167,25 +8885,19 @@ func NewLedgerEntryExt(v int32, value interface{}) (result LedgerEntryExt, err e // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u LedgerEntryExt) MustV1() LedgerEntryExtensionV1 { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if int32(u.V) == 1 { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryExt) GetV1() (result LedgerEntryExtensionV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1" { + if int32(u.V) == 1 { result = *u.V1 ok = true } - return } @@ -9208,9 +8920,9 @@ func (u LedgerEntryExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union LedgerEntryExt", u.V) } -var _ decoderFrom = (*LedgerEntryExt)(nil) +var _ xdr.DecoderFrom = (*LedgerEntryExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LedgerEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerEntryExt: %w", ErrMaxDecodingDepthReached) @@ -9228,7 +8940,9 @@ func (u *LedgerEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) // Void return n, nil case 1: - u.V1 = new(LedgerEntryExtensionV1) + if u.V1 == nil { + u.V1 = new(LedgerEntryExtensionV1) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -9249,11 +8963,8 @@ func (s LedgerEntryExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerEntryExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -9329,9 +9040,9 @@ func (s *LedgerEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerEntry)(nil) +var _ xdr.DecoderFrom = (*LedgerEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerEntry: %w", ErrMaxDecodingDepthReached) @@ -9367,11 +9078,8 @@ func (s LedgerEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -9404,9 +9112,9 @@ func (s *LedgerKeyAccount) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerKeyAccount)(nil) +var _ xdr.DecoderFrom = (*LedgerKeyAccount)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerKeyAccount) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerKeyAccount: %w", ErrMaxDecodingDepthReached) @@ -9432,11 +9140,8 @@ func (s LedgerKeyAccount) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerKeyAccount) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -9474,9 +9179,9 @@ func (s *LedgerKeyTrustLine) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerKeyTrustLine)(nil) +var _ xdr.DecoderFrom = (*LedgerKeyTrustLine)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerKeyTrustLine) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerKeyTrustLine: %w", ErrMaxDecodingDepthReached) @@ -9507,11 +9212,8 @@ func (s LedgerKeyTrustLine) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerKeyTrustLine) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -9549,9 +9251,9 @@ func (s *LedgerKeyOffer) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerKeyOffer)(nil) +var _ xdr.DecoderFrom = (*LedgerKeyOffer)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerKeyOffer) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerKeyOffer: %w", ErrMaxDecodingDepthReached) @@ -9582,11 +9284,8 @@ func (s LedgerKeyOffer) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerKeyOffer) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -9624,9 +9323,9 @@ func (s *LedgerKeyData) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerKeyData)(nil) +var _ xdr.DecoderFrom = (*LedgerKeyData)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerKeyData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerKeyData: %w", ErrMaxDecodingDepthReached) @@ -9657,11 +9356,8 @@ func (s LedgerKeyData) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerKeyData) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -9694,9 +9390,9 @@ func (s *LedgerKeyClaimableBalance) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerKeyClaimableBalance)(nil) +var _ xdr.DecoderFrom = (*LedgerKeyClaimableBalance)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerKeyClaimableBalance) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerKeyClaimableBalance: %w", ErrMaxDecodingDepthReached) @@ -9722,11 +9418,8 @@ func (s LedgerKeyClaimableBalance) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerKeyClaimableBalance) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -9759,9 +9452,9 @@ func (s *LedgerKeyLiquidityPool) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerKeyLiquidityPool)(nil) +var _ xdr.DecoderFrom = (*LedgerKeyLiquidityPool)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerKeyLiquidityPool) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerKeyLiquidityPool: %w", ErrMaxDecodingDepthReached) @@ -9787,11 +9480,8 @@ func (s LedgerKeyLiquidityPool) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerKeyLiquidityPool) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -9834,9 +9524,9 @@ func (s *LedgerKeyContractData) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerKeyContractData)(nil) +var _ xdr.DecoderFrom = (*LedgerKeyContractData)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerKeyContractData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerKeyContractData: %w", ErrMaxDecodingDepthReached) @@ -9872,11 +9562,8 @@ func (s LedgerKeyContractData) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerKeyContractData) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -9909,9 +9596,9 @@ func (s *LedgerKeyContractCode) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerKeyContractCode)(nil) +var _ xdr.DecoderFrom = (*LedgerKeyContractCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerKeyContractCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerKeyContractCode: %w", ErrMaxDecodingDepthReached) @@ -9937,11 +9624,8 @@ func (s LedgerKeyContractCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerKeyContractCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -9974,9 +9658,9 @@ func (s *LedgerKeyConfigSetting) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerKeyConfigSetting)(nil) +var _ xdr.DecoderFrom = (*LedgerKeyConfigSetting)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerKeyConfigSetting) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerKeyConfigSetting: %w", ErrMaxDecodingDepthReached) @@ -10002,11 +9686,8 @@ func (s LedgerKeyConfigSetting) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerKeyConfigSetting) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -10040,9 +9721,9 @@ func (s *LedgerKeyTtl) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerKeyTtl)(nil) +var _ xdr.DecoderFrom = (*LedgerKeyTtl)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerKeyTtl) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerKeyTtl: %w", ErrMaxDecodingDepthReached) @@ -10068,11 +9749,8 @@ func (s LedgerKeyTtl) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerKeyTtl) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -10281,250 +9959,190 @@ func NewLedgerKey(aType LedgerEntryType, value interface{}) (result LedgerKey, e // MustAccount retrieves the Account value from the union, // panicing if the value is not set. func (u LedgerKey) MustAccount() LedgerKeyAccount { - val, ok := u.GetAccount() - - if !ok { - panic("arm Account is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeAccount { + return *u.Account } - - return val + panic("arm Account is not set") } // GetAccount retrieves the Account value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerKey) GetAccount() (result LedgerKeyAccount, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Account" { + if LedgerEntryType(u.Type) == LedgerEntryTypeAccount { result = *u.Account ok = true } - return } // MustTrustLine retrieves the TrustLine value from the union, // panicing if the value is not set. func (u LedgerKey) MustTrustLine() LedgerKeyTrustLine { - val, ok := u.GetTrustLine() - - if !ok { - panic("arm TrustLine is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeTrustline { + return *u.TrustLine } - - return val + panic("arm TrustLine is not set") } // GetTrustLine retrieves the TrustLine value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerKey) GetTrustLine() (result LedgerKeyTrustLine, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "TrustLine" { + if LedgerEntryType(u.Type) == LedgerEntryTypeTrustline { result = *u.TrustLine ok = true } - return } // MustOffer retrieves the Offer value from the union, // panicing if the value is not set. func (u LedgerKey) MustOffer() LedgerKeyOffer { - val, ok := u.GetOffer() - - if !ok { - panic("arm Offer is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeOffer { + return *u.Offer } - - return val + panic("arm Offer is not set") } // GetOffer retrieves the Offer value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerKey) GetOffer() (result LedgerKeyOffer, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Offer" { + if LedgerEntryType(u.Type) == LedgerEntryTypeOffer { result = *u.Offer ok = true } - return } // MustData retrieves the Data value from the union, // panicing if the value is not set. func (u LedgerKey) MustData() LedgerKeyData { - val, ok := u.GetData() - - if !ok { - panic("arm Data is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeData { + return *u.Data } - - return val + panic("arm Data is not set") } // GetData retrieves the Data value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerKey) GetData() (result LedgerKeyData, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Data" { + if LedgerEntryType(u.Type) == LedgerEntryTypeData { result = *u.Data ok = true } - return } // MustClaimableBalance retrieves the ClaimableBalance value from the union, // panicing if the value is not set. func (u LedgerKey) MustClaimableBalance() LedgerKeyClaimableBalance { - val, ok := u.GetClaimableBalance() - - if !ok { - panic("arm ClaimableBalance is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeClaimableBalance { + return *u.ClaimableBalance } - - return val + panic("arm ClaimableBalance is not set") } // GetClaimableBalance retrieves the ClaimableBalance value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerKey) GetClaimableBalance() (result LedgerKeyClaimableBalance, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ClaimableBalance" { + if LedgerEntryType(u.Type) == LedgerEntryTypeClaimableBalance { result = *u.ClaimableBalance ok = true } - return } // MustLiquidityPool retrieves the LiquidityPool value from the union, // panicing if the value is not set. func (u LedgerKey) MustLiquidityPool() LedgerKeyLiquidityPool { - val, ok := u.GetLiquidityPool() - - if !ok { - panic("arm LiquidityPool is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeLiquidityPool { + return *u.LiquidityPool } - - return val + panic("arm LiquidityPool is not set") } // GetLiquidityPool retrieves the LiquidityPool value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerKey) GetLiquidityPool() (result LedgerKeyLiquidityPool, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LiquidityPool" { + if LedgerEntryType(u.Type) == LedgerEntryTypeLiquidityPool { result = *u.LiquidityPool ok = true } - return } // MustContractData retrieves the ContractData value from the union, // panicing if the value is not set. func (u LedgerKey) MustContractData() LedgerKeyContractData { - val, ok := u.GetContractData() - - if !ok { - panic("arm ContractData is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeContractData { + return *u.ContractData } - - return val + panic("arm ContractData is not set") } // GetContractData retrieves the ContractData value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerKey) GetContractData() (result LedgerKeyContractData, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ContractData" { + if LedgerEntryType(u.Type) == LedgerEntryTypeContractData { result = *u.ContractData ok = true } - return } // MustContractCode retrieves the ContractCode value from the union, // panicing if the value is not set. func (u LedgerKey) MustContractCode() LedgerKeyContractCode { - val, ok := u.GetContractCode() - - if !ok { - panic("arm ContractCode is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeContractCode { + return *u.ContractCode } - - return val + panic("arm ContractCode is not set") } // GetContractCode retrieves the ContractCode value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerKey) GetContractCode() (result LedgerKeyContractCode, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ContractCode" { + if LedgerEntryType(u.Type) == LedgerEntryTypeContractCode { result = *u.ContractCode ok = true } - return } // MustConfigSetting retrieves the ConfigSetting value from the union, // panicing if the value is not set. func (u LedgerKey) MustConfigSetting() LedgerKeyConfigSetting { - val, ok := u.GetConfigSetting() - - if !ok { - panic("arm ConfigSetting is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeConfigSetting { + return *u.ConfigSetting } - - return val + panic("arm ConfigSetting is not set") } // GetConfigSetting retrieves the ConfigSetting value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerKey) GetConfigSetting() (result LedgerKeyConfigSetting, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ConfigSetting" { + if LedgerEntryType(u.Type) == LedgerEntryTypeConfigSetting { result = *u.ConfigSetting ok = true } - return } // MustTtl retrieves the Ttl value from the union, // panicing if the value is not set. func (u LedgerKey) MustTtl() LedgerKeyTtl { - val, ok := u.GetTtl() - - if !ok { - panic("arm Ttl is not set") + if LedgerEntryType(u.Type) == LedgerEntryTypeTtl { + return *u.Ttl } - - return val + panic("arm Ttl is not set") } // GetTtl retrieves the Ttl value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerKey) GetTtl() (result LedgerKeyTtl, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Ttl" { + if LedgerEntryType(u.Type) == LedgerEntryTypeTtl { result = *u.Ttl ok = true } - return } @@ -10589,9 +10207,9 @@ func (u LedgerKey) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (LedgerEntryType) switch value '%d' is not valid for union LedgerKey", u.Type) } -var _ decoderFrom = (*LedgerKey)(nil) +var _ xdr.DecoderFrom = (*LedgerKey)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LedgerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerKey: %w", ErrMaxDecodingDepthReached) @@ -10606,7 +10224,9 @@ func (u *LedgerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch LedgerEntryType(u.Type) { case LedgerEntryTypeAccount: - u.Account = new(LedgerKeyAccount) + if u.Account == nil { + u.Account = new(LedgerKeyAccount) + } nTmp, err = (*u.Account).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -10614,7 +10234,9 @@ func (u *LedgerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case LedgerEntryTypeTrustline: - u.TrustLine = new(LedgerKeyTrustLine) + if u.TrustLine == nil { + u.TrustLine = new(LedgerKeyTrustLine) + } nTmp, err = (*u.TrustLine).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -10622,7 +10244,9 @@ func (u *LedgerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case LedgerEntryTypeOffer: - u.Offer = new(LedgerKeyOffer) + if u.Offer == nil { + u.Offer = new(LedgerKeyOffer) + } nTmp, err = (*u.Offer).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -10630,7 +10254,9 @@ func (u *LedgerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case LedgerEntryTypeData: - u.Data = new(LedgerKeyData) + if u.Data == nil { + u.Data = new(LedgerKeyData) + } nTmp, err = (*u.Data).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -10638,7 +10264,9 @@ func (u *LedgerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case LedgerEntryTypeClaimableBalance: - u.ClaimableBalance = new(LedgerKeyClaimableBalance) + if u.ClaimableBalance == nil { + u.ClaimableBalance = new(LedgerKeyClaimableBalance) + } nTmp, err = (*u.ClaimableBalance).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -10646,7 +10274,9 @@ func (u *LedgerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case LedgerEntryTypeLiquidityPool: - u.LiquidityPool = new(LedgerKeyLiquidityPool) + if u.LiquidityPool == nil { + u.LiquidityPool = new(LedgerKeyLiquidityPool) + } nTmp, err = (*u.LiquidityPool).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -10654,7 +10284,9 @@ func (u *LedgerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case LedgerEntryTypeContractData: - u.ContractData = new(LedgerKeyContractData) + if u.ContractData == nil { + u.ContractData = new(LedgerKeyContractData) + } nTmp, err = (*u.ContractData).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -10662,7 +10294,9 @@ func (u *LedgerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case LedgerEntryTypeContractCode: - u.ContractCode = new(LedgerKeyContractCode) + if u.ContractCode == nil { + u.ContractCode = new(LedgerKeyContractCode) + } nTmp, err = (*u.ContractCode).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -10670,7 +10304,9 @@ func (u *LedgerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case LedgerEntryTypeConfigSetting: - u.ConfigSetting = new(LedgerKeyConfigSetting) + if u.ConfigSetting == nil { + u.ConfigSetting = new(LedgerKeyConfigSetting) + } nTmp, err = (*u.ConfigSetting).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -10678,7 +10314,9 @@ func (u *LedgerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case LedgerEntryTypeTtl: - u.Ttl = new(LedgerKeyTtl) + if u.Ttl == nil { + u.Ttl = new(LedgerKeyTtl) + } nTmp, err = (*u.Ttl).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -10699,11 +10337,8 @@ func (s LedgerKey) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerKey) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -10746,6 +10381,10 @@ const ( EnvelopeTypeEnvelopeTypeContractId EnvelopeType = 8 EnvelopeTypeEnvelopeTypeSorobanAuthorization EnvelopeType = 9 ) +const ( + _EnvelopeType_Min int32 = 0 + _EnvelopeType_Max int32 = 9 +) var envelopeTypeMap = map[int32]string{ 0: "EnvelopeTypeEnvelopeTypeTxV0", @@ -10763,8 +10402,7 @@ var envelopeTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for EnvelopeType func (e EnvelopeType) ValidEnum(v int32) bool { - _, ok := envelopeTypeMap[v] - return ok + return v >= _EnvelopeType_Min && v <= _EnvelopeType_Max } // String returns the name of `e` @@ -10775,16 +10413,16 @@ func (e EnvelopeType) String() string { // EncodeTo encodes this value using the Encoder. func (e EnvelopeType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := envelopeTypeMap[int32(e)]; !ok { + if int32(e) < _EnvelopeType_Min || int32(e) > _EnvelopeType_Max { return fmt.Errorf("'%d' is not a valid EnvelopeType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*EnvelopeType)(nil) +var _ xdr.DecoderFrom = (*EnvelopeType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *EnvelopeType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding EnvelopeType: %w", ErrMaxDecodingDepthReached) @@ -10794,7 +10432,7 @@ func (e *EnvelopeType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding EnvelopeType: %w", err) } - if _, ok := envelopeTypeMap[v]; !ok { + if v < _EnvelopeType_Min || v > _EnvelopeType_Max { return n, fmt.Errorf("'%d' is not a valid EnvelopeType enum value", v) } *e = EnvelopeType(v) @@ -10811,11 +10449,8 @@ func (s EnvelopeType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *EnvelopeType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -10842,6 +10477,10 @@ const ( BucketListTypeLive BucketListType = 0 BucketListTypeHotArchive BucketListType = 1 ) +const ( + _BucketListType_Min int32 = 0 + _BucketListType_Max int32 = 1 +) var bucketListTypeMap = map[int32]string{ 0: "BucketListTypeLive", @@ -10851,8 +10490,7 @@ var bucketListTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for BucketListType func (e BucketListType) ValidEnum(v int32) bool { - _, ok := bucketListTypeMap[v] - return ok + return v >= _BucketListType_Min && v <= _BucketListType_Max } // String returns the name of `e` @@ -10863,16 +10501,16 @@ func (e BucketListType) String() string { // EncodeTo encodes this value using the Encoder. func (e BucketListType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := bucketListTypeMap[int32(e)]; !ok { + if int32(e) < _BucketListType_Min || int32(e) > _BucketListType_Max { return fmt.Errorf("'%d' is not a valid BucketListType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*BucketListType)(nil) +var _ xdr.DecoderFrom = (*BucketListType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *BucketListType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BucketListType: %w", ErrMaxDecodingDepthReached) @@ -10882,7 +10520,7 @@ func (e *BucketListType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding BucketListType: %w", err) } - if _, ok := bucketListTypeMap[v]; !ok { + if v < _BucketListType_Min || v > _BucketListType_Max { return n, fmt.Errorf("'%d' is not a valid BucketListType enum value", v) } *e = BucketListType(v) @@ -10899,11 +10537,8 @@ func (s BucketListType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BucketListType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -10936,6 +10571,10 @@ const ( BucketEntryTypeDeadentry BucketEntryType = 1 BucketEntryTypeInitentry BucketEntryType = 2 ) +const ( + _BucketEntryType_Min int32 = -1 + _BucketEntryType_Max int32 = 2 +) var bucketEntryTypeMap = map[int32]string{ -1: "BucketEntryTypeMetaentry", @@ -10947,8 +10586,7 @@ var bucketEntryTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for BucketEntryType func (e BucketEntryType) ValidEnum(v int32) bool { - _, ok := bucketEntryTypeMap[v] - return ok + return v >= _BucketEntryType_Min && v <= _BucketEntryType_Max } // String returns the name of `e` @@ -10959,16 +10597,16 @@ func (e BucketEntryType) String() string { // EncodeTo encodes this value using the Encoder. func (e BucketEntryType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := bucketEntryTypeMap[int32(e)]; !ok { + if int32(e) < _BucketEntryType_Min || int32(e) > _BucketEntryType_Max { return fmt.Errorf("'%d' is not a valid BucketEntryType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*BucketEntryType)(nil) +var _ xdr.DecoderFrom = (*BucketEntryType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *BucketEntryType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BucketEntryType: %w", ErrMaxDecodingDepthReached) @@ -10978,7 +10616,7 @@ func (e *BucketEntryType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding BucketEntryType: %w", err) } - if _, ok := bucketEntryTypeMap[v]; !ok { + if v < _BucketEntryType_Min || v > _BucketEntryType_Max { return n, fmt.Errorf("'%d' is not a valid BucketEntryType enum value", v) } *e = BucketEntryType(v) @@ -10995,11 +10633,8 @@ func (s BucketEntryType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BucketEntryType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -11030,6 +10665,10 @@ const ( HotArchiveBucketEntryTypeHotArchiveArchived HotArchiveBucketEntryType = 0 HotArchiveBucketEntryTypeHotArchiveLive HotArchiveBucketEntryType = 1 ) +const ( + _HotArchiveBucketEntryType_Min int32 = -1 + _HotArchiveBucketEntryType_Max int32 = 1 +) var hotArchiveBucketEntryTypeMap = map[int32]string{ -1: "HotArchiveBucketEntryTypeHotArchiveMetaentry", @@ -11040,8 +10679,7 @@ var hotArchiveBucketEntryTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for HotArchiveBucketEntryType func (e HotArchiveBucketEntryType) ValidEnum(v int32) bool { - _, ok := hotArchiveBucketEntryTypeMap[v] - return ok + return v >= _HotArchiveBucketEntryType_Min && v <= _HotArchiveBucketEntryType_Max } // String returns the name of `e` @@ -11052,16 +10690,16 @@ func (e HotArchiveBucketEntryType) String() string { // EncodeTo encodes this value using the Encoder. func (e HotArchiveBucketEntryType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := hotArchiveBucketEntryTypeMap[int32(e)]; !ok { + if int32(e) < _HotArchiveBucketEntryType_Min || int32(e) > _HotArchiveBucketEntryType_Max { return fmt.Errorf("'%d' is not a valid HotArchiveBucketEntryType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*HotArchiveBucketEntryType)(nil) +var _ xdr.DecoderFrom = (*HotArchiveBucketEntryType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *HotArchiveBucketEntryType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding HotArchiveBucketEntryType: %w", ErrMaxDecodingDepthReached) @@ -11071,7 +10709,7 @@ func (e *HotArchiveBucketEntryType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (i if err != nil { return n, fmt.Errorf("decoding HotArchiveBucketEntryType: %w", err) } - if _, ok := hotArchiveBucketEntryTypeMap[v]; !ok { + if v < _HotArchiveBucketEntryType_Min || v > _HotArchiveBucketEntryType_Max { return n, fmt.Errorf("'%d' is not a valid HotArchiveBucketEntryType enum value", v) } *e = HotArchiveBucketEntryType(v) @@ -11088,11 +10726,8 @@ func (s HotArchiveBucketEntryType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *HotArchiveBucketEntryType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -11117,7 +10752,7 @@ var _ xdrType = (*HotArchiveBucketEntryType)(nil) // } type BucketMetadataExt struct { V int32 - BucketListType *BucketListType + BucketListType BucketListType } // SwitchFieldName returns the field name in which this union's @@ -11150,7 +10785,7 @@ func NewBucketMetadataExt(v int32, value interface{}) (result BucketMetadataExt, err = errors.New("invalid value, must be BucketListType") return } - result.BucketListType = &tv + result.BucketListType = tv } return } @@ -11158,25 +10793,19 @@ func NewBucketMetadataExt(v int32, value interface{}) (result BucketMetadataExt, // MustBucketListType retrieves the BucketListType value from the union, // panicing if the value is not set. func (u BucketMetadataExt) MustBucketListType() BucketListType { - val, ok := u.GetBucketListType() - - if !ok { - panic("arm BucketListType is not set") + if int32(u.V) == 1 { + return u.BucketListType } - - return val + panic("arm BucketListType is not set") } // GetBucketListType retrieves the BucketListType value from the union, // returning ok if the union's switch indicated the value is valid. func (u BucketMetadataExt) GetBucketListType() (result BucketListType, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "BucketListType" { - result = *u.BucketListType + if int32(u.V) == 1 { + result = u.BucketListType ok = true } - return } @@ -11191,7 +10820,7 @@ func (u BucketMetadataExt) EncodeTo(e *xdr.Encoder) error { // Void return nil case 1: - if err = (*u.BucketListType).EncodeTo(e); err != nil { + if err = u.BucketListType.EncodeTo(e); err != nil { return err } return nil @@ -11199,9 +10828,9 @@ func (u BucketMetadataExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union BucketMetadataExt", u.V) } -var _ decoderFrom = (*BucketMetadataExt)(nil) +var _ xdr.DecoderFrom = (*BucketMetadataExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *BucketMetadataExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BucketMetadataExt: %w", ErrMaxDecodingDepthReached) @@ -11219,8 +10848,7 @@ func (u *BucketMetadataExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro // Void return n, nil case 1: - u.BucketListType = new(BucketListType) - nTmp, err = (*u.BucketListType).DecodeFrom(d, maxDepth) + nTmp, err = u.BucketListType.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding BucketListType: %w", err) @@ -11240,11 +10868,8 @@ func (s BucketMetadataExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BucketMetadataExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -11292,9 +10917,9 @@ func (s *BucketMetadata) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*BucketMetadata)(nil) +var _ xdr.DecoderFrom = (*BucketMetadata)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *BucketMetadata) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BucketMetadata: %w", ErrMaxDecodingDepthReached) @@ -11325,11 +10950,8 @@ func (s BucketMetadata) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BucketMetadata) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -11424,75 +11046,57 @@ func NewBucketEntry(aType BucketEntryType, value interface{}) (result BucketEntr // MustLiveEntry retrieves the LiveEntry value from the union, // panicing if the value is not set. func (u BucketEntry) MustLiveEntry() LedgerEntry { - val, ok := u.GetLiveEntry() - - if !ok { - panic("arm LiveEntry is not set") + if BucketEntryType(u.Type) == BucketEntryTypeLiveentry || BucketEntryType(u.Type) == BucketEntryTypeInitentry { + return *u.LiveEntry } - - return val + panic("arm LiveEntry is not set") } // GetLiveEntry retrieves the LiveEntry value from the union, // returning ok if the union's switch indicated the value is valid. func (u BucketEntry) GetLiveEntry() (result LedgerEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LiveEntry" { + if BucketEntryType(u.Type) == BucketEntryTypeLiveentry || BucketEntryType(u.Type) == BucketEntryTypeInitentry { result = *u.LiveEntry ok = true } - return } // MustDeadEntry retrieves the DeadEntry value from the union, // panicing if the value is not set. func (u BucketEntry) MustDeadEntry() LedgerKey { - val, ok := u.GetDeadEntry() - - if !ok { - panic("arm DeadEntry is not set") + if BucketEntryType(u.Type) == BucketEntryTypeDeadentry { + return *u.DeadEntry } - - return val + panic("arm DeadEntry is not set") } // GetDeadEntry retrieves the DeadEntry value from the union, // returning ok if the union's switch indicated the value is valid. func (u BucketEntry) GetDeadEntry() (result LedgerKey, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "DeadEntry" { + if BucketEntryType(u.Type) == BucketEntryTypeDeadentry { result = *u.DeadEntry ok = true } - return } // MustMetaEntry retrieves the MetaEntry value from the union, // panicing if the value is not set. func (u BucketEntry) MustMetaEntry() BucketMetadata { - val, ok := u.GetMetaEntry() - - if !ok { - panic("arm MetaEntry is not set") + if BucketEntryType(u.Type) == BucketEntryTypeMetaentry { + return *u.MetaEntry } - - return val + panic("arm MetaEntry is not set") } // GetMetaEntry retrieves the MetaEntry value from the union, // returning ok if the union's switch indicated the value is valid. func (u BucketEntry) GetMetaEntry() (result BucketMetadata, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "MetaEntry" { + if BucketEntryType(u.Type) == BucketEntryTypeMetaentry { result = *u.MetaEntry ok = true } - return } @@ -11527,9 +11131,9 @@ func (u BucketEntry) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (BucketEntryType) switch value '%d' is not valid for union BucketEntry", u.Type) } -var _ decoderFrom = (*BucketEntry)(nil) +var _ xdr.DecoderFrom = (*BucketEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *BucketEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BucketEntry: %w", ErrMaxDecodingDepthReached) @@ -11544,7 +11148,9 @@ func (u *BucketEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch BucketEntryType(u.Type) { case BucketEntryTypeLiveentry: - u.LiveEntry = new(LedgerEntry) + if u.LiveEntry == nil { + u.LiveEntry = new(LedgerEntry) + } nTmp, err = (*u.LiveEntry).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -11552,7 +11158,9 @@ func (u *BucketEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case BucketEntryTypeInitentry: - u.LiveEntry = new(LedgerEntry) + if u.LiveEntry == nil { + u.LiveEntry = new(LedgerEntry) + } nTmp, err = (*u.LiveEntry).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -11560,7 +11168,9 @@ func (u *BucketEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case BucketEntryTypeDeadentry: - u.DeadEntry = new(LedgerKey) + if u.DeadEntry == nil { + u.DeadEntry = new(LedgerKey) + } nTmp, err = (*u.DeadEntry).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -11568,7 +11178,9 @@ func (u *BucketEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case BucketEntryTypeMetaentry: - u.MetaEntry = new(BucketMetadata) + if u.MetaEntry == nil { + u.MetaEntry = new(BucketMetadata) + } nTmp, err = (*u.MetaEntry).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -11589,11 +11201,8 @@ func (s BucketEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BucketEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -11678,75 +11287,57 @@ func NewHotArchiveBucketEntry(aType HotArchiveBucketEntryType, value interface{} // MustArchivedEntry retrieves the ArchivedEntry value from the union, // panicing if the value is not set. func (u HotArchiveBucketEntry) MustArchivedEntry() LedgerEntry { - val, ok := u.GetArchivedEntry() - - if !ok { - panic("arm ArchivedEntry is not set") + if HotArchiveBucketEntryType(u.Type) == HotArchiveBucketEntryTypeHotArchiveArchived { + return *u.ArchivedEntry } - - return val + panic("arm ArchivedEntry is not set") } // GetArchivedEntry retrieves the ArchivedEntry value from the union, // returning ok if the union's switch indicated the value is valid. func (u HotArchiveBucketEntry) GetArchivedEntry() (result LedgerEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ArchivedEntry" { + if HotArchiveBucketEntryType(u.Type) == HotArchiveBucketEntryTypeHotArchiveArchived { result = *u.ArchivedEntry ok = true } - return } // MustKey retrieves the Key value from the union, // panicing if the value is not set. func (u HotArchiveBucketEntry) MustKey() LedgerKey { - val, ok := u.GetKey() - - if !ok { - panic("arm Key is not set") + if HotArchiveBucketEntryType(u.Type) == HotArchiveBucketEntryTypeHotArchiveLive { + return *u.Key } - - return val + panic("arm Key is not set") } // GetKey retrieves the Key value from the union, // returning ok if the union's switch indicated the value is valid. func (u HotArchiveBucketEntry) GetKey() (result LedgerKey, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Key" { + if HotArchiveBucketEntryType(u.Type) == HotArchiveBucketEntryTypeHotArchiveLive { result = *u.Key ok = true } - return } // MustMetaEntry retrieves the MetaEntry value from the union, // panicing if the value is not set. func (u HotArchiveBucketEntry) MustMetaEntry() BucketMetadata { - val, ok := u.GetMetaEntry() - - if !ok { - panic("arm MetaEntry is not set") + if HotArchiveBucketEntryType(u.Type) == HotArchiveBucketEntryTypeHotArchiveMetaentry { + return *u.MetaEntry } - - return val + panic("arm MetaEntry is not set") } // GetMetaEntry retrieves the MetaEntry value from the union, // returning ok if the union's switch indicated the value is valid. func (u HotArchiveBucketEntry) GetMetaEntry() (result BucketMetadata, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "MetaEntry" { + if HotArchiveBucketEntryType(u.Type) == HotArchiveBucketEntryTypeHotArchiveMetaentry { result = *u.MetaEntry ok = true } - return } @@ -11776,9 +11367,9 @@ func (u HotArchiveBucketEntry) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (HotArchiveBucketEntryType) switch value '%d' is not valid for union HotArchiveBucketEntry", u.Type) } -var _ decoderFrom = (*HotArchiveBucketEntry)(nil) +var _ xdr.DecoderFrom = (*HotArchiveBucketEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *HotArchiveBucketEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding HotArchiveBucketEntry: %w", ErrMaxDecodingDepthReached) @@ -11793,7 +11384,9 @@ func (u *HotArchiveBucketEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, } switch HotArchiveBucketEntryType(u.Type) { case HotArchiveBucketEntryTypeHotArchiveArchived: - u.ArchivedEntry = new(LedgerEntry) + if u.ArchivedEntry == nil { + u.ArchivedEntry = new(LedgerEntry) + } nTmp, err = (*u.ArchivedEntry).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -11801,7 +11394,9 @@ func (u *HotArchiveBucketEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, } return n, nil case HotArchiveBucketEntryTypeHotArchiveLive: - u.Key = new(LedgerKey) + if u.Key == nil { + u.Key = new(LedgerKey) + } nTmp, err = (*u.Key).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -11809,7 +11404,9 @@ func (u *HotArchiveBucketEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, } return n, nil case HotArchiveBucketEntryTypeHotArchiveMetaentry: - u.MetaEntry = new(BucketMetadata) + if u.MetaEntry == nil { + u.MetaEntry = new(BucketMetadata) + } nTmp, err = (*u.MetaEntry).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -11830,11 +11427,8 @@ func (s HotArchiveBucketEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *HotArchiveBucketEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -11867,9 +11461,9 @@ func (s UpgradeType) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*UpgradeType)(nil) +var _ xdr.DecoderFrom = (*UpgradeType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *UpgradeType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding UpgradeType: %w", ErrMaxDecodingDepthReached) @@ -11895,11 +11489,8 @@ func (s UpgradeType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *UpgradeType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -11926,6 +11517,10 @@ const ( StellarValueTypeStellarValueBasic StellarValueType = 0 StellarValueTypeStellarValueSigned StellarValueType = 1 ) +const ( + _StellarValueType_Min int32 = 0 + _StellarValueType_Max int32 = 1 +) var stellarValueTypeMap = map[int32]string{ 0: "StellarValueTypeStellarValueBasic", @@ -11935,8 +11530,7 @@ var stellarValueTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for StellarValueType func (e StellarValueType) ValidEnum(v int32) bool { - _, ok := stellarValueTypeMap[v] - return ok + return v >= _StellarValueType_Min && v <= _StellarValueType_Max } // String returns the name of `e` @@ -11947,16 +11541,16 @@ func (e StellarValueType) String() string { // EncodeTo encodes this value using the Encoder. func (e StellarValueType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := stellarValueTypeMap[int32(e)]; !ok { + if int32(e) < _StellarValueType_Min || int32(e) > _StellarValueType_Max { return fmt.Errorf("'%d' is not a valid StellarValueType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*StellarValueType)(nil) +var _ xdr.DecoderFrom = (*StellarValueType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *StellarValueType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding StellarValueType: %w", ErrMaxDecodingDepthReached) @@ -11966,7 +11560,7 @@ func (e *StellarValueType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error if err != nil { return n, fmt.Errorf("decoding StellarValueType: %w", err) } - if _, ok := stellarValueTypeMap[v]; !ok { + if v < _StellarValueType_Min || v > _StellarValueType_Max { return n, fmt.Errorf("'%d' is not a valid StellarValueType enum value", v) } *e = StellarValueType(v) @@ -11983,11 +11577,8 @@ func (s StellarValueType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *StellarValueType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -12025,9 +11616,9 @@ func (s *LedgerCloseValueSignature) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerCloseValueSignature)(nil) +var _ xdr.DecoderFrom = (*LedgerCloseValueSignature)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerCloseValueSignature) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerCloseValueSignature: %w", ErrMaxDecodingDepthReached) @@ -12058,11 +11649,8 @@ func (s LedgerCloseValueSignature) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerCloseValueSignature) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -12128,25 +11716,19 @@ func NewStellarValueExt(v StellarValueType, value interface{}) (result StellarVa // MustLcValueSignature retrieves the LcValueSignature value from the union, // panicing if the value is not set. func (u StellarValueExt) MustLcValueSignature() LedgerCloseValueSignature { - val, ok := u.GetLcValueSignature() - - if !ok { - panic("arm LcValueSignature is not set") + if StellarValueType(u.V) == StellarValueTypeStellarValueSigned { + return *u.LcValueSignature } - - return val + panic("arm LcValueSignature is not set") } // GetLcValueSignature retrieves the LcValueSignature value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarValueExt) GetLcValueSignature() (result LedgerCloseValueSignature, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "LcValueSignature" { + if StellarValueType(u.V) == StellarValueTypeStellarValueSigned { result = *u.LcValueSignature ok = true } - return } @@ -12169,9 +11751,9 @@ func (u StellarValueExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (StellarValueType) switch value '%d' is not valid for union StellarValueExt", u.V) } -var _ decoderFrom = (*StellarValueExt)(nil) +var _ xdr.DecoderFrom = (*StellarValueExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *StellarValueExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding StellarValueExt: %w", ErrMaxDecodingDepthReached) @@ -12189,7 +11771,9 @@ func (u *StellarValueExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) // Void return n, nil case StellarValueTypeStellarValueSigned: - u.LcValueSignature = new(LedgerCloseValueSignature) + if u.LcValueSignature == nil { + u.LcValueSignature = new(LedgerCloseValueSignature) + } nTmp, err = (*u.LcValueSignature).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -12210,11 +11794,8 @@ func (s StellarValueExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *StellarValueExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -12282,9 +11863,9 @@ func (s *StellarValue) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*StellarValue)(nil) +var _ xdr.DecoderFrom = (*StellarValue)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *StellarValue) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding StellarValue: %w", ErrMaxDecodingDepthReached) @@ -12311,12 +11892,17 @@ func (s *StellarValue) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if l > 6 { return n, fmt.Errorf("decoding UpgradeType: data size (%d) exceeds size limit (6)", l) } - s.Upgrades = nil - if l > 0 { + if l == 0 { + s.Upgrades = s.Upgrades[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding UpgradeType: length (%d) exceeds remaining input length (%d)", l, il) } - s.Upgrades = make([]UpgradeType, l) + if cap(s.Upgrades) >= int(l) { + s.Upgrades = s.Upgrades[:l] + } else { + s.Upgrades = make([]UpgradeType, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Upgrades[i].DecodeFrom(d, maxDepth) n += nTmp @@ -12343,11 +11929,8 @@ func (s StellarValue) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *StellarValue) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -12391,8 +11974,12 @@ var ledgerHeaderFlagsMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for LedgerHeaderFlags func (e LedgerHeaderFlags) ValidEnum(v int32) bool { - _, ok := ledgerHeaderFlagsMap[v] - return ok + switch v { + case 1, 2, 4: + return true + default: + return false + } } // String returns the name of `e` @@ -12403,16 +11990,19 @@ func (e LedgerHeaderFlags) String() string { // EncodeTo encodes this value using the Encoder. func (e LedgerHeaderFlags) EncodeTo(enc *xdr.Encoder) error { - if _, ok := ledgerHeaderFlagsMap[int32(e)]; !ok { + switch int32(e) { + case 1, 2, 4: + // valid + default: return fmt.Errorf("'%d' is not a valid LedgerHeaderFlags enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*LedgerHeaderFlags)(nil) +var _ xdr.DecoderFrom = (*LedgerHeaderFlags)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *LedgerHeaderFlags) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerHeaderFlags: %w", ErrMaxDecodingDepthReached) @@ -12422,7 +12012,10 @@ func (e *LedgerHeaderFlags) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding LedgerHeaderFlags: %w", err) } - if _, ok := ledgerHeaderFlagsMap[v]; !ok { + switch v { + case 1, 2, 4: + // valid + default: return n, fmt.Errorf("'%d' is not a valid LedgerHeaderFlags enum value", v) } *e = LedgerHeaderFlags(v) @@ -12439,11 +12032,8 @@ func (s LedgerHeaderFlags) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerHeaderFlags) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -12508,9 +12098,9 @@ func (u LedgerHeaderExtensionV1Ext) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union LedgerHeaderExtensionV1Ext", u.V) } -var _ decoderFrom = (*LedgerHeaderExtensionV1Ext)(nil) +var _ xdr.DecoderFrom = (*LedgerHeaderExtensionV1Ext)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LedgerHeaderExtensionV1Ext) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerHeaderExtensionV1Ext: %w", ErrMaxDecodingDepthReached) @@ -12541,11 +12131,8 @@ func (s LedgerHeaderExtensionV1Ext) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerHeaderExtensionV1Ext) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -12589,9 +12176,9 @@ func (s *LedgerHeaderExtensionV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerHeaderExtensionV1)(nil) +var _ xdr.DecoderFrom = (*LedgerHeaderExtensionV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerHeaderExtensionV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerHeaderExtensionV1: %w", ErrMaxDecodingDepthReached) @@ -12622,11 +12209,8 @@ func (s LedgerHeaderExtensionV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerHeaderExtensionV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -12692,25 +12276,19 @@ func NewLedgerHeaderExt(v int32, value interface{}) (result LedgerHeaderExt, err // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u LedgerHeaderExt) MustV1() LedgerHeaderExtensionV1 { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if int32(u.V) == 1 { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerHeaderExt) GetV1() (result LedgerHeaderExtensionV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1" { + if int32(u.V) == 1 { result = *u.V1 ok = true } - return } @@ -12733,9 +12311,9 @@ func (u LedgerHeaderExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union LedgerHeaderExt", u.V) } -var _ decoderFrom = (*LedgerHeaderExt)(nil) +var _ xdr.DecoderFrom = (*LedgerHeaderExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LedgerHeaderExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerHeaderExt: %w", ErrMaxDecodingDepthReached) @@ -12753,7 +12331,9 @@ func (u *LedgerHeaderExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) // Void return n, nil case 1: - u.V1 = new(LedgerHeaderExtensionV1) + if u.V1 == nil { + u.V1 = new(LedgerHeaderExtensionV1) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -12774,11 +12354,8 @@ func (s LedgerHeaderExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerHeaderExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -12904,9 +12481,9 @@ func (s *LedgerHeader) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerHeader)(nil) +var _ xdr.DecoderFrom = (*LedgerHeader)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerHeader) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerHeader: %w", ErrMaxDecodingDepthReached) @@ -13004,11 +12581,8 @@ func (s LedgerHeader) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerHeader) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -13045,6 +12619,10 @@ const ( LedgerUpgradeTypeLedgerUpgradeConfig LedgerUpgradeType = 6 LedgerUpgradeTypeLedgerUpgradeMaxSorobanTxSetSize LedgerUpgradeType = 7 ) +const ( + _LedgerUpgradeType_Min int32 = 1 + _LedgerUpgradeType_Max int32 = 7 +) var ledgerUpgradeTypeMap = map[int32]string{ 1: "LedgerUpgradeTypeLedgerUpgradeVersion", @@ -13059,8 +12637,7 @@ var ledgerUpgradeTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for LedgerUpgradeType func (e LedgerUpgradeType) ValidEnum(v int32) bool { - _, ok := ledgerUpgradeTypeMap[v] - return ok + return v >= _LedgerUpgradeType_Min && v <= _LedgerUpgradeType_Max } // String returns the name of `e` @@ -13071,16 +12648,16 @@ func (e LedgerUpgradeType) String() string { // EncodeTo encodes this value using the Encoder. func (e LedgerUpgradeType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := ledgerUpgradeTypeMap[int32(e)]; !ok { + if int32(e) < _LedgerUpgradeType_Min || int32(e) > _LedgerUpgradeType_Max { return fmt.Errorf("'%d' is not a valid LedgerUpgradeType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*LedgerUpgradeType)(nil) +var _ xdr.DecoderFrom = (*LedgerUpgradeType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *LedgerUpgradeType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerUpgradeType: %w", ErrMaxDecodingDepthReached) @@ -13090,7 +12667,7 @@ func (e *LedgerUpgradeType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding LedgerUpgradeType: %w", err) } - if _, ok := ledgerUpgradeTypeMap[v]; !ok { + if v < _LedgerUpgradeType_Min || v > _LedgerUpgradeType_Max { return n, fmt.Errorf("'%d' is not a valid LedgerUpgradeType enum value", v) } *e = LedgerUpgradeType(v) @@ -13107,11 +12684,8 @@ func (s LedgerUpgradeType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerUpgradeType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -13148,9 +12722,9 @@ func (s *ConfigUpgradeSetKey) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ConfigUpgradeSetKey)(nil) +var _ xdr.DecoderFrom = (*ConfigUpgradeSetKey)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ConfigUpgradeSetKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigUpgradeSetKey: %w", ErrMaxDecodingDepthReached) @@ -13181,11 +12755,8 @@ func (s ConfigUpgradeSetKey) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigUpgradeSetKey) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -13223,13 +12794,13 @@ var _ xdrType = (*ConfigUpgradeSetKey)(nil) // }; type LedgerUpgrade struct { Type LedgerUpgradeType - NewLedgerVersion *Uint32 - NewBaseFee *Uint32 - NewMaxTxSetSize *Uint32 - NewBaseReserve *Uint32 - NewFlags *Uint32 + NewLedgerVersion Uint32 + NewBaseFee Uint32 + NewMaxTxSetSize Uint32 + NewBaseReserve Uint32 + NewFlags Uint32 NewConfig *ConfigUpgradeSetKey - NewMaxSorobanTxSetSize *Uint32 + NewMaxSorobanTxSetSize Uint32 } // SwitchFieldName returns the field name in which this union's @@ -13270,35 +12841,35 @@ func NewLedgerUpgrade(aType LedgerUpgradeType, value interface{}) (result Ledger err = errors.New("invalid value, must be Uint32") return } - result.NewLedgerVersion = &tv + result.NewLedgerVersion = tv case LedgerUpgradeTypeLedgerUpgradeBaseFee: tv, ok := value.(Uint32) if !ok { err = errors.New("invalid value, must be Uint32") return } - result.NewBaseFee = &tv + result.NewBaseFee = tv case LedgerUpgradeTypeLedgerUpgradeMaxTxSetSize: tv, ok := value.(Uint32) if !ok { err = errors.New("invalid value, must be Uint32") return } - result.NewMaxTxSetSize = &tv + result.NewMaxTxSetSize = tv case LedgerUpgradeTypeLedgerUpgradeBaseReserve: tv, ok := value.(Uint32) if !ok { err = errors.New("invalid value, must be Uint32") return } - result.NewBaseReserve = &tv + result.NewBaseReserve = tv case LedgerUpgradeTypeLedgerUpgradeFlags: tv, ok := value.(Uint32) if !ok { err = errors.New("invalid value, must be Uint32") return } - result.NewFlags = &tv + result.NewFlags = tv case LedgerUpgradeTypeLedgerUpgradeConfig: tv, ok := value.(ConfigUpgradeSetKey) if !ok { @@ -13312,7 +12883,7 @@ func NewLedgerUpgrade(aType LedgerUpgradeType, value interface{}) (result Ledger err = errors.New("invalid value, must be Uint32") return } - result.NewMaxSorobanTxSetSize = &tv + result.NewMaxSorobanTxSetSize = tv } return } @@ -13320,175 +12891,133 @@ func NewLedgerUpgrade(aType LedgerUpgradeType, value interface{}) (result Ledger // MustNewLedgerVersion retrieves the NewLedgerVersion value from the union, // panicing if the value is not set. func (u LedgerUpgrade) MustNewLedgerVersion() Uint32 { - val, ok := u.GetNewLedgerVersion() - - if !ok { - panic("arm NewLedgerVersion is not set") + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeVersion { + return u.NewLedgerVersion } - - return val + panic("arm NewLedgerVersion is not set") } // GetNewLedgerVersion retrieves the NewLedgerVersion value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerUpgrade) GetNewLedgerVersion() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "NewLedgerVersion" { - result = *u.NewLedgerVersion + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeVersion { + result = u.NewLedgerVersion ok = true } - return } // MustNewBaseFee retrieves the NewBaseFee value from the union, // panicing if the value is not set. func (u LedgerUpgrade) MustNewBaseFee() Uint32 { - val, ok := u.GetNewBaseFee() - - if !ok { - panic("arm NewBaseFee is not set") + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeBaseFee { + return u.NewBaseFee } - - return val + panic("arm NewBaseFee is not set") } // GetNewBaseFee retrieves the NewBaseFee value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerUpgrade) GetNewBaseFee() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "NewBaseFee" { - result = *u.NewBaseFee + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeBaseFee { + result = u.NewBaseFee ok = true } - return } // MustNewMaxTxSetSize retrieves the NewMaxTxSetSize value from the union, // panicing if the value is not set. func (u LedgerUpgrade) MustNewMaxTxSetSize() Uint32 { - val, ok := u.GetNewMaxTxSetSize() - - if !ok { - panic("arm NewMaxTxSetSize is not set") + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeMaxTxSetSize { + return u.NewMaxTxSetSize } - - return val + panic("arm NewMaxTxSetSize is not set") } // GetNewMaxTxSetSize retrieves the NewMaxTxSetSize value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerUpgrade) GetNewMaxTxSetSize() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "NewMaxTxSetSize" { - result = *u.NewMaxTxSetSize + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeMaxTxSetSize { + result = u.NewMaxTxSetSize ok = true } - return } // MustNewBaseReserve retrieves the NewBaseReserve value from the union, // panicing if the value is not set. func (u LedgerUpgrade) MustNewBaseReserve() Uint32 { - val, ok := u.GetNewBaseReserve() - - if !ok { - panic("arm NewBaseReserve is not set") + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeBaseReserve { + return u.NewBaseReserve } - - return val + panic("arm NewBaseReserve is not set") } // GetNewBaseReserve retrieves the NewBaseReserve value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerUpgrade) GetNewBaseReserve() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "NewBaseReserve" { - result = *u.NewBaseReserve + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeBaseReserve { + result = u.NewBaseReserve ok = true } - return } // MustNewFlags retrieves the NewFlags value from the union, // panicing if the value is not set. func (u LedgerUpgrade) MustNewFlags() Uint32 { - val, ok := u.GetNewFlags() - - if !ok { - panic("arm NewFlags is not set") + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeFlags { + return u.NewFlags } - - return val + panic("arm NewFlags is not set") } // GetNewFlags retrieves the NewFlags value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerUpgrade) GetNewFlags() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "NewFlags" { - result = *u.NewFlags + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeFlags { + result = u.NewFlags ok = true } - return } // MustNewConfig retrieves the NewConfig value from the union, // panicing if the value is not set. func (u LedgerUpgrade) MustNewConfig() ConfigUpgradeSetKey { - val, ok := u.GetNewConfig() - - if !ok { - panic("arm NewConfig is not set") + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeConfig { + return *u.NewConfig } - - return val + panic("arm NewConfig is not set") } // GetNewConfig retrieves the NewConfig value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerUpgrade) GetNewConfig() (result ConfigUpgradeSetKey, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "NewConfig" { + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeConfig { result = *u.NewConfig ok = true } - return } // MustNewMaxSorobanTxSetSize retrieves the NewMaxSorobanTxSetSize value from the union, // panicing if the value is not set. func (u LedgerUpgrade) MustNewMaxSorobanTxSetSize() Uint32 { - val, ok := u.GetNewMaxSorobanTxSetSize() - - if !ok { - panic("arm NewMaxSorobanTxSetSize is not set") + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeMaxSorobanTxSetSize { + return u.NewMaxSorobanTxSetSize } - - return val + panic("arm NewMaxSorobanTxSetSize is not set") } // GetNewMaxSorobanTxSetSize retrieves the NewMaxSorobanTxSetSize value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerUpgrade) GetNewMaxSorobanTxSetSize() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "NewMaxSorobanTxSetSize" { - result = *u.NewMaxSorobanTxSetSize + if LedgerUpgradeType(u.Type) == LedgerUpgradeTypeLedgerUpgradeMaxSorobanTxSetSize { + result = u.NewMaxSorobanTxSetSize ok = true } - return } @@ -13500,27 +13029,27 @@ func (u LedgerUpgrade) EncodeTo(e *xdr.Encoder) error { } switch LedgerUpgradeType(u.Type) { case LedgerUpgradeTypeLedgerUpgradeVersion: - if err = (*u.NewLedgerVersion).EncodeTo(e); err != nil { + if err = u.NewLedgerVersion.EncodeTo(e); err != nil { return err } return nil case LedgerUpgradeTypeLedgerUpgradeBaseFee: - if err = (*u.NewBaseFee).EncodeTo(e); err != nil { + if err = u.NewBaseFee.EncodeTo(e); err != nil { return err } return nil case LedgerUpgradeTypeLedgerUpgradeMaxTxSetSize: - if err = (*u.NewMaxTxSetSize).EncodeTo(e); err != nil { + if err = u.NewMaxTxSetSize.EncodeTo(e); err != nil { return err } return nil case LedgerUpgradeTypeLedgerUpgradeBaseReserve: - if err = (*u.NewBaseReserve).EncodeTo(e); err != nil { + if err = u.NewBaseReserve.EncodeTo(e); err != nil { return err } return nil case LedgerUpgradeTypeLedgerUpgradeFlags: - if err = (*u.NewFlags).EncodeTo(e); err != nil { + if err = u.NewFlags.EncodeTo(e); err != nil { return err } return nil @@ -13530,7 +13059,7 @@ func (u LedgerUpgrade) EncodeTo(e *xdr.Encoder) error { } return nil case LedgerUpgradeTypeLedgerUpgradeMaxSorobanTxSetSize: - if err = (*u.NewMaxSorobanTxSetSize).EncodeTo(e); err != nil { + if err = u.NewMaxSorobanTxSetSize.EncodeTo(e); err != nil { return err } return nil @@ -13538,9 +13067,9 @@ func (u LedgerUpgrade) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (LedgerUpgradeType) switch value '%d' is not valid for union LedgerUpgrade", u.Type) } -var _ decoderFrom = (*LedgerUpgrade)(nil) +var _ xdr.DecoderFrom = (*LedgerUpgrade)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LedgerUpgrade) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerUpgrade: %w", ErrMaxDecodingDepthReached) @@ -13555,47 +13084,44 @@ func (u *LedgerUpgrade) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch LedgerUpgradeType(u.Type) { case LedgerUpgradeTypeLedgerUpgradeVersion: - u.NewLedgerVersion = new(Uint32) - nTmp, err = (*u.NewLedgerVersion).DecodeFrom(d, maxDepth) + nTmp, err = u.NewLedgerVersion.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } return n, nil case LedgerUpgradeTypeLedgerUpgradeBaseFee: - u.NewBaseFee = new(Uint32) - nTmp, err = (*u.NewBaseFee).DecodeFrom(d, maxDepth) + nTmp, err = u.NewBaseFee.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } return n, nil case LedgerUpgradeTypeLedgerUpgradeMaxTxSetSize: - u.NewMaxTxSetSize = new(Uint32) - nTmp, err = (*u.NewMaxTxSetSize).DecodeFrom(d, maxDepth) + nTmp, err = u.NewMaxTxSetSize.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } return n, nil case LedgerUpgradeTypeLedgerUpgradeBaseReserve: - u.NewBaseReserve = new(Uint32) - nTmp, err = (*u.NewBaseReserve).DecodeFrom(d, maxDepth) + nTmp, err = u.NewBaseReserve.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } return n, nil case LedgerUpgradeTypeLedgerUpgradeFlags: - u.NewFlags = new(Uint32) - nTmp, err = (*u.NewFlags).DecodeFrom(d, maxDepth) + nTmp, err = u.NewFlags.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } return n, nil case LedgerUpgradeTypeLedgerUpgradeConfig: - u.NewConfig = new(ConfigUpgradeSetKey) + if u.NewConfig == nil { + u.NewConfig = new(ConfigUpgradeSetKey) + } nTmp, err = (*u.NewConfig).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -13603,8 +13129,7 @@ func (u *LedgerUpgrade) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case LedgerUpgradeTypeLedgerUpgradeMaxSorobanTxSetSize: - u.NewMaxSorobanTxSetSize = new(Uint32) - nTmp, err = (*u.NewMaxSorobanTxSetSize).DecodeFrom(d, maxDepth) + nTmp, err = u.NewMaxSorobanTxSetSize.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) @@ -13624,11 +13149,8 @@ func (s LedgerUpgrade) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerUpgrade) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -13665,9 +13187,9 @@ func (s *ConfigUpgradeSet) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ConfigUpgradeSet)(nil) +var _ xdr.DecoderFrom = (*ConfigUpgradeSet)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ConfigUpgradeSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigUpgradeSet: %w", ErrMaxDecodingDepthReached) @@ -13681,12 +13203,17 @@ func (s *ConfigUpgradeSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error if err != nil { return n, fmt.Errorf("decoding ConfigSettingEntry: %w", err) } - s.UpdatedEntry = nil - if l > 0 { + if l == 0 { + s.UpdatedEntry = s.UpdatedEntry[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ConfigSettingEntry: length (%d) exceeds remaining input length (%d)", l, il) } - s.UpdatedEntry = make([]ConfigSettingEntry, l) + if cap(s.UpdatedEntry) >= int(l) { + s.UpdatedEntry = s.UpdatedEntry[:l] + } else { + s.UpdatedEntry = make([]ConfigSettingEntry, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.UpdatedEntry[i].DecodeFrom(d, maxDepth) n += nTmp @@ -13708,11 +13235,8 @@ func (s ConfigUpgradeSet) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigUpgradeSet) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -13739,6 +13263,10 @@ type TxSetComponentType int32 const ( TxSetComponentTypeTxsetCompTxsMaybeDiscountedFee TxSetComponentType = 0 ) +const ( + _TxSetComponentType_Min int32 = 0 + _TxSetComponentType_Max int32 = 0 +) var txSetComponentTypeMap = map[int32]string{ 0: "TxSetComponentTypeTxsetCompTxsMaybeDiscountedFee", @@ -13747,8 +13275,7 @@ var txSetComponentTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for TxSetComponentType func (e TxSetComponentType) ValidEnum(v int32) bool { - _, ok := txSetComponentTypeMap[v] - return ok + return v >= _TxSetComponentType_Min && v <= _TxSetComponentType_Max } // String returns the name of `e` @@ -13759,16 +13286,16 @@ func (e TxSetComponentType) String() string { // EncodeTo encodes this value using the Encoder. func (e TxSetComponentType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := txSetComponentTypeMap[int32(e)]; !ok { + if int32(e) < _TxSetComponentType_Min || int32(e) > _TxSetComponentType_Max { return fmt.Errorf("'%d' is not a valid TxSetComponentType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*TxSetComponentType)(nil) +var _ xdr.DecoderFrom = (*TxSetComponentType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *TxSetComponentType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TxSetComponentType: %w", ErrMaxDecodingDepthReached) @@ -13778,7 +13305,7 @@ func (e *TxSetComponentType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err if err != nil { return n, fmt.Errorf("decoding TxSetComponentType: %w", err) } - if _, ok := txSetComponentTypeMap[v]; !ok { + if v < _TxSetComponentType_Min || v > _TxSetComponentType_Max { return n, fmt.Errorf("'%d' is not a valid TxSetComponentType enum value", v) } *e = TxSetComponentType(v) @@ -13795,11 +13322,8 @@ func (s TxSetComponentType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TxSetComponentType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -13832,9 +13356,9 @@ func (s DependentTxCluster) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*DependentTxCluster)(nil) +var _ xdr.DecoderFrom = (*DependentTxCluster)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *DependentTxCluster) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding DependentTxCluster: %w", ErrMaxDecodingDepthReached) @@ -13848,12 +13372,17 @@ func (s *DependentTxCluster) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err if err != nil { return n, fmt.Errorf("decoding TransactionEnvelope: %w", err) } - (*s) = nil - if l > 0 { + if l == 0 { + (*s) = (*s)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding TransactionEnvelope: length (%d) exceeds remaining input length (%d)", l, il) } - (*s) = make([]TransactionEnvelope, l) + if cap((*s)) >= int(l) { + (*s) = (*s)[:l] + } else { + (*s) = make([]TransactionEnvelope, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*s)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -13875,11 +13404,8 @@ func (s DependentTxCluster) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *DependentTxCluster) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -13912,9 +13438,9 @@ func (s ParallelTxExecutionStage) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ParallelTxExecutionStage)(nil) +var _ xdr.DecoderFrom = (*ParallelTxExecutionStage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ParallelTxExecutionStage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ParallelTxExecutionStage: %w", ErrMaxDecodingDepthReached) @@ -13928,12 +13454,17 @@ func (s *ParallelTxExecutionStage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (in if err != nil { return n, fmt.Errorf("decoding DependentTxCluster: %w", err) } - (*s) = nil - if l > 0 { + if l == 0 { + (*s) = (*s)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding DependentTxCluster: length (%d) exceeds remaining input length (%d)", l, il) } - (*s) = make([]DependentTxCluster, l) + if cap((*s)) >= int(l) { + (*s) = (*s)[:l] + } else { + (*s) = make([]DependentTxCluster, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*s)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -13955,11 +13486,8 @@ func (s ParallelTxExecutionStage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ParallelTxExecutionStage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -14010,9 +13538,9 @@ func (s *ParallelTxsComponent) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ParallelTxsComponent)(nil) +var _ xdr.DecoderFrom = (*ParallelTxsComponent)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ParallelTxsComponent) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ParallelTxsComponent: %w", ErrMaxDecodingDepthReached) @@ -14041,12 +13569,17 @@ func (s *ParallelTxsComponent) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e if err != nil { return n, fmt.Errorf("decoding ParallelTxExecutionStage: %w", err) } - s.ExecutionStages = nil - if l > 0 { + if l == 0 { + s.ExecutionStages = s.ExecutionStages[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ParallelTxExecutionStage: length (%d) exceeds remaining input length (%d)", l, il) } - s.ExecutionStages = make([]ParallelTxExecutionStage, l) + if cap(s.ExecutionStages) >= int(l) { + s.ExecutionStages = s.ExecutionStages[:l] + } else { + s.ExecutionStages = make([]ParallelTxExecutionStage, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ExecutionStages[i].DecodeFrom(d, maxDepth) n += nTmp @@ -14068,11 +13601,8 @@ func (s ParallelTxsComponent) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ParallelTxsComponent) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -14120,9 +13650,9 @@ func (s *TxSetComponentTxsMaybeDiscountedFee) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TxSetComponentTxsMaybeDiscountedFee)(nil) +var _ xdr.DecoderFrom = (*TxSetComponentTxsMaybeDiscountedFee)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TxSetComponentTxsMaybeDiscountedFee) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TxSetComponentTxsMaybeDiscountedFee: %w", ErrMaxDecodingDepthReached) @@ -14151,12 +13681,17 @@ func (s *TxSetComponentTxsMaybeDiscountedFee) DecodeFrom(d *xdr.Decoder, maxDept if err != nil { return n, fmt.Errorf("decoding TransactionEnvelope: %w", err) } - s.Txs = nil - if l > 0 { + if l == 0 { + s.Txs = s.Txs[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding TransactionEnvelope: length (%d) exceeds remaining input length (%d)", l, il) } - s.Txs = make([]TransactionEnvelope, l) + if cap(s.Txs) >= int(l) { + s.Txs = s.Txs[:l] + } else { + s.Txs = make([]TransactionEnvelope, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Txs[i].DecodeFrom(d, maxDepth) n += nTmp @@ -14178,11 +13713,8 @@ func (s TxSetComponentTxsMaybeDiscountedFee) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TxSetComponentTxsMaybeDiscountedFee) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -14246,25 +13778,19 @@ func NewTxSetComponent(aType TxSetComponentType, value interface{}) (result TxSe // MustTxsMaybeDiscountedFee retrieves the TxsMaybeDiscountedFee value from the union, // panicing if the value is not set. func (u TxSetComponent) MustTxsMaybeDiscountedFee() TxSetComponentTxsMaybeDiscountedFee { - val, ok := u.GetTxsMaybeDiscountedFee() - - if !ok { - panic("arm TxsMaybeDiscountedFee is not set") + if TxSetComponentType(u.Type) == TxSetComponentTypeTxsetCompTxsMaybeDiscountedFee { + return *u.TxsMaybeDiscountedFee } - - return val + panic("arm TxsMaybeDiscountedFee is not set") } // GetTxsMaybeDiscountedFee retrieves the TxsMaybeDiscountedFee value from the union, // returning ok if the union's switch indicated the value is valid. func (u TxSetComponent) GetTxsMaybeDiscountedFee() (result TxSetComponentTxsMaybeDiscountedFee, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "TxsMaybeDiscountedFee" { + if TxSetComponentType(u.Type) == TxSetComponentTypeTxsetCompTxsMaybeDiscountedFee { result = *u.TxsMaybeDiscountedFee ok = true } - return } @@ -14284,9 +13810,9 @@ func (u TxSetComponent) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (TxSetComponentType) switch value '%d' is not valid for union TxSetComponent", u.Type) } -var _ decoderFrom = (*TxSetComponent)(nil) +var _ xdr.DecoderFrom = (*TxSetComponent)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TxSetComponent) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TxSetComponent: %w", ErrMaxDecodingDepthReached) @@ -14301,7 +13827,9 @@ func (u *TxSetComponent) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } switch TxSetComponentType(u.Type) { case TxSetComponentTypeTxsetCompTxsMaybeDiscountedFee: - u.TxsMaybeDiscountedFee = new(TxSetComponentTxsMaybeDiscountedFee) + if u.TxsMaybeDiscountedFee == nil { + u.TxsMaybeDiscountedFee = new(TxSetComponentTxsMaybeDiscountedFee) + } nTmp, err = (*u.TxsMaybeDiscountedFee).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -14322,11 +13850,8 @@ func (s TxSetComponent) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TxSetComponent) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -14398,50 +13923,38 @@ func NewTransactionPhase(v int32, value interface{}) (result TransactionPhase, e // MustV0Components retrieves the V0Components value from the union, // panicing if the value is not set. func (u TransactionPhase) MustV0Components() []TxSetComponent { - val, ok := u.GetV0Components() - - if !ok { - panic("arm V0Components is not set") + if int32(u.V) == 0 { + return *u.V0Components } - - return val + panic("arm V0Components is not set") } // GetV0Components retrieves the V0Components value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionPhase) GetV0Components() (result []TxSetComponent, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V0Components" { + if int32(u.V) == 0 { result = *u.V0Components ok = true } - return } // MustParallelTxsComponent retrieves the ParallelTxsComponent value from the union, // panicing if the value is not set. func (u TransactionPhase) MustParallelTxsComponent() ParallelTxsComponent { - val, ok := u.GetParallelTxsComponent() - - if !ok { - panic("arm ParallelTxsComponent is not set") + if int32(u.V) == 1 { + return *u.ParallelTxsComponent } - - return val + panic("arm ParallelTxsComponent is not set") } // GetParallelTxsComponent retrieves the ParallelTxsComponent value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionPhase) GetParallelTxsComponent() (result ParallelTxsComponent, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "ParallelTxsComponent" { + if int32(u.V) == 1 { result = *u.ParallelTxsComponent ok = true } - return } @@ -14471,9 +13984,9 @@ func (u TransactionPhase) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union TransactionPhase", u.V) } -var _ decoderFrom = (*TransactionPhase)(nil) +var _ xdr.DecoderFrom = (*TransactionPhase)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TransactionPhase) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionPhase: %w", ErrMaxDecodingDepthReached) @@ -14488,19 +14001,26 @@ func (u *TransactionPhase) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error } switch int32(u.V) { case 0: - u.V0Components = new([]TxSetComponent) + if u.V0Components == nil { + u.V0Components = new([]TxSetComponent) + } var l uint32 l, nTmp, err = d.DecodeUint() n += nTmp if err != nil { return n, fmt.Errorf("decoding TxSetComponent: %w", err) } - (*u.V0Components) = nil - if l > 0 { + if l == 0 { + (*u.V0Components) = (*u.V0Components)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding TxSetComponent: length (%d) exceeds remaining input length (%d)", l, il) } - (*u.V0Components) = make([]TxSetComponent, l) + if cap((*u.V0Components)) >= int(l) { + (*u.V0Components) = (*u.V0Components)[:l] + } else { + (*u.V0Components) = make([]TxSetComponent, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*u.V0Components)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -14511,7 +14031,9 @@ func (u *TransactionPhase) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error } return n, nil case 1: - u.ParallelTxsComponent = new(ParallelTxsComponent) + if u.ParallelTxsComponent == nil { + u.ParallelTxsComponent = new(ParallelTxsComponent) + } nTmp, err = (*u.ParallelTxsComponent).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -14532,11 +14054,8 @@ func (s TransactionPhase) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionPhase) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -14579,9 +14098,9 @@ func (s *TransactionSet) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionSet)(nil) +var _ xdr.DecoderFrom = (*TransactionSet)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionSet: %w", ErrMaxDecodingDepthReached) @@ -14600,12 +14119,17 @@ func (s *TransactionSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding TransactionEnvelope: %w", err) } - s.Txs = nil - if l > 0 { + if l == 0 { + s.Txs = s.Txs[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding TransactionEnvelope: length (%d) exceeds remaining input length (%d)", l, il) } - s.Txs = make([]TransactionEnvelope, l) + if cap(s.Txs) >= int(l) { + s.Txs = s.Txs[:l] + } else { + s.Txs = make([]TransactionEnvelope, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Txs[i].DecodeFrom(d, maxDepth) n += nTmp @@ -14627,11 +14151,8 @@ func (s TransactionSet) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionSet) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -14674,9 +14195,9 @@ func (s *TransactionSetV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionSetV1)(nil) +var _ xdr.DecoderFrom = (*TransactionSetV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionSetV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionSetV1: %w", ErrMaxDecodingDepthReached) @@ -14695,12 +14216,17 @@ func (s *TransactionSetV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error if err != nil { return n, fmt.Errorf("decoding TransactionPhase: %w", err) } - s.Phases = nil - if l > 0 { + if l == 0 { + s.Phases = s.Phases[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding TransactionPhase: length (%d) exceeds remaining input length (%d)", l, il) } - s.Phases = make([]TransactionPhase, l) + if cap(s.Phases) >= int(l) { + s.Phases = s.Phases[:l] + } else { + s.Phases = make([]TransactionPhase, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Phases[i].DecodeFrom(d, maxDepth) n += nTmp @@ -14722,11 +14248,8 @@ func (s TransactionSetV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionSetV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -14787,25 +14310,19 @@ func NewGeneralizedTransactionSet(v int32, value interface{}) (result Generalize // MustV1TxSet retrieves the V1TxSet value from the union, // panicing if the value is not set. func (u GeneralizedTransactionSet) MustV1TxSet() TransactionSetV1 { - val, ok := u.GetV1TxSet() - - if !ok { - panic("arm V1TxSet is not set") + if int32(u.V) == 1 { + return *u.V1TxSet } - - return val + panic("arm V1TxSet is not set") } // GetV1TxSet retrieves the V1TxSet value from the union, // returning ok if the union's switch indicated the value is valid. func (u GeneralizedTransactionSet) GetV1TxSet() (result TransactionSetV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1TxSet" { + if int32(u.V) == 1 { result = *u.V1TxSet ok = true } - return } @@ -14825,9 +14342,9 @@ func (u GeneralizedTransactionSet) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union GeneralizedTransactionSet", u.V) } -var _ decoderFrom = (*GeneralizedTransactionSet)(nil) +var _ xdr.DecoderFrom = (*GeneralizedTransactionSet)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *GeneralizedTransactionSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding GeneralizedTransactionSet: %w", ErrMaxDecodingDepthReached) @@ -14842,7 +14359,9 @@ func (u *GeneralizedTransactionSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (i } switch int32(u.V) { case 1: - u.V1TxSet = new(TransactionSetV1) + if u.V1TxSet == nil { + u.V1TxSet = new(TransactionSetV1) + } nTmp, err = (*u.V1TxSet).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -14863,11 +14382,8 @@ func (s GeneralizedTransactionSet) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *GeneralizedTransactionSet) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -14905,9 +14421,9 @@ func (s *TransactionResultPair) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionResultPair)(nil) +var _ xdr.DecoderFrom = (*TransactionResultPair)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionResultPair) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionResultPair: %w", ErrMaxDecodingDepthReached) @@ -14938,11 +14454,8 @@ func (s TransactionResultPair) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionResultPair) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -14980,9 +14493,9 @@ func (s *TransactionResultSet) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionResultSet)(nil) +var _ xdr.DecoderFrom = (*TransactionResultSet)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionResultSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionResultSet: %w", ErrMaxDecodingDepthReached) @@ -14996,12 +14509,17 @@ func (s *TransactionResultSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e if err != nil { return n, fmt.Errorf("decoding TransactionResultPair: %w", err) } - s.Results = nil - if l > 0 { + if l == 0 { + s.Results = s.Results[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding TransactionResultPair: length (%d) exceeds remaining input length (%d)", l, il) } - s.Results = make([]TransactionResultPair, l) + if cap(s.Results) >= int(l) { + s.Results = s.Results[:l] + } else { + s.Results = make([]TransactionResultPair, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Results[i].DecodeFrom(d, maxDepth) n += nTmp @@ -15023,11 +14541,8 @@ func (s TransactionResultSet) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionResultSet) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -15093,25 +14608,19 @@ func NewTransactionHistoryEntryExt(v int32, value interface{}) (result Transacti // MustGeneralizedTxSet retrieves the GeneralizedTxSet value from the union, // panicing if the value is not set. func (u TransactionHistoryEntryExt) MustGeneralizedTxSet() GeneralizedTransactionSet { - val, ok := u.GetGeneralizedTxSet() - - if !ok { - panic("arm GeneralizedTxSet is not set") + if int32(u.V) == 1 { + return *u.GeneralizedTxSet } - - return val + panic("arm GeneralizedTxSet is not set") } // GetGeneralizedTxSet retrieves the GeneralizedTxSet value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionHistoryEntryExt) GetGeneralizedTxSet() (result GeneralizedTransactionSet, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "GeneralizedTxSet" { + if int32(u.V) == 1 { result = *u.GeneralizedTxSet ok = true } - return } @@ -15134,9 +14643,9 @@ func (u TransactionHistoryEntryExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union TransactionHistoryEntryExt", u.V) } -var _ decoderFrom = (*TransactionHistoryEntryExt)(nil) +var _ xdr.DecoderFrom = (*TransactionHistoryEntryExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TransactionHistoryEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionHistoryEntryExt: %w", ErrMaxDecodingDepthReached) @@ -15154,7 +14663,9 @@ func (u *TransactionHistoryEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) ( // Void return n, nil case 1: - u.GeneralizedTxSet = new(GeneralizedTransactionSet) + if u.GeneralizedTxSet == nil { + u.GeneralizedTxSet = new(GeneralizedTransactionSet) + } nTmp, err = (*u.GeneralizedTxSet).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -15175,11 +14686,8 @@ func (s TransactionHistoryEntryExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionHistoryEntryExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -15231,9 +14739,9 @@ func (s *TransactionHistoryEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionHistoryEntry)(nil) +var _ xdr.DecoderFrom = (*TransactionHistoryEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionHistoryEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionHistoryEntry: %w", ErrMaxDecodingDepthReached) @@ -15269,11 +14777,8 @@ func (s TransactionHistoryEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionHistoryEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -15338,9 +14843,9 @@ func (u TransactionHistoryResultEntryExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union TransactionHistoryResultEntryExt", u.V) } -var _ decoderFrom = (*TransactionHistoryResultEntryExt)(nil) +var _ xdr.DecoderFrom = (*TransactionHistoryResultEntryExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TransactionHistoryResultEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionHistoryResultEntryExt: %w", ErrMaxDecodingDepthReached) @@ -15371,11 +14876,8 @@ func (s TransactionHistoryResultEntryExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionHistoryResultEntryExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -15425,9 +14927,9 @@ func (s *TransactionHistoryResultEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionHistoryResultEntry)(nil) +var _ xdr.DecoderFrom = (*TransactionHistoryResultEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionHistoryResultEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionHistoryResultEntry: %w", ErrMaxDecodingDepthReached) @@ -15463,11 +14965,8 @@ func (s TransactionHistoryResultEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionHistoryResultEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -15532,9 +15031,9 @@ func (u LedgerHeaderHistoryEntryExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union LedgerHeaderHistoryEntryExt", u.V) } -var _ decoderFrom = (*LedgerHeaderHistoryEntryExt)(nil) +var _ xdr.DecoderFrom = (*LedgerHeaderHistoryEntryExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LedgerHeaderHistoryEntryExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerHeaderHistoryEntryExt: %w", ErrMaxDecodingDepthReached) @@ -15565,11 +15064,8 @@ func (s LedgerHeaderHistoryEntryExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerHeaderHistoryEntryExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -15619,9 +15115,9 @@ func (s *LedgerHeaderHistoryEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerHeaderHistoryEntry)(nil) +var _ xdr.DecoderFrom = (*LedgerHeaderHistoryEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerHeaderHistoryEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerHeaderHistoryEntry: %w", ErrMaxDecodingDepthReached) @@ -15657,11 +15153,8 @@ func (s LedgerHeaderHistoryEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerHeaderHistoryEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -15704,9 +15197,9 @@ func (s *LedgerScpMessages) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerScpMessages)(nil) +var _ xdr.DecoderFrom = (*LedgerScpMessages)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerScpMessages) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerScpMessages: %w", ErrMaxDecodingDepthReached) @@ -15725,12 +15218,17 @@ func (s *LedgerScpMessages) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding ScpEnvelope: %w", err) } - s.Messages = nil - if l > 0 { + if l == 0 { + s.Messages = s.Messages[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScpEnvelope: length (%d) exceeds remaining input length (%d)", l, il) } - s.Messages = make([]ScpEnvelope, l) + if cap(s.Messages) >= int(l) { + s.Messages = s.Messages[:l] + } else { + s.Messages = make([]ScpEnvelope, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Messages[i].DecodeFrom(d, maxDepth) n += nTmp @@ -15752,11 +15250,8 @@ func (s LedgerScpMessages) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerScpMessages) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -15799,9 +15294,9 @@ func (s *ScpHistoryEntryV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScpHistoryEntryV0)(nil) +var _ xdr.DecoderFrom = (*ScpHistoryEntryV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScpHistoryEntryV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpHistoryEntryV0: %w", ErrMaxDecodingDepthReached) @@ -15815,12 +15310,17 @@ func (s *ScpHistoryEntryV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding ScpQuorumSet: %w", err) } - s.QuorumSets = nil - if l > 0 { + if l == 0 { + s.QuorumSets = s.QuorumSets[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScpQuorumSet: length (%d) exceeds remaining input length (%d)", l, il) } - s.QuorumSets = make([]ScpQuorumSet, l) + if cap(s.QuorumSets) >= int(l) { + s.QuorumSets = s.QuorumSets[:l] + } else { + s.QuorumSets = make([]ScpQuorumSet, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.QuorumSets[i].DecodeFrom(d, maxDepth) n += nTmp @@ -15847,11 +15347,8 @@ func (s ScpHistoryEntryV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpHistoryEntryV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -15911,25 +15408,19 @@ func NewScpHistoryEntry(v int32, value interface{}) (result ScpHistoryEntry, err // MustV0 retrieves the V0 value from the union, // panicing if the value is not set. func (u ScpHistoryEntry) MustV0() ScpHistoryEntryV0 { - val, ok := u.GetV0() - - if !ok { - panic("arm V0 is not set") + if int32(u.V) == 0 { + return *u.V0 } - - return val + panic("arm V0 is not set") } // GetV0 retrieves the V0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScpHistoryEntry) GetV0() (result ScpHistoryEntryV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V0" { + if int32(u.V) == 0 { result = *u.V0 ok = true } - return } @@ -15949,9 +15440,9 @@ func (u ScpHistoryEntry) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union ScpHistoryEntry", u.V) } -var _ decoderFrom = (*ScpHistoryEntry)(nil) +var _ xdr.DecoderFrom = (*ScpHistoryEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ScpHistoryEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScpHistoryEntry: %w", ErrMaxDecodingDepthReached) @@ -15966,7 +15457,9 @@ func (u *ScpHistoryEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } switch int32(u.V) { case 0: - u.V0 = new(ScpHistoryEntryV0) + if u.V0 == nil { + u.V0 = new(ScpHistoryEntryV0) + } nTmp, err = (*u.V0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -15987,11 +15480,8 @@ func (s ScpHistoryEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScpHistoryEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -16024,6 +15514,10 @@ const ( LedgerEntryChangeTypeLedgerEntryState LedgerEntryChangeType = 3 LedgerEntryChangeTypeLedgerEntryRestored LedgerEntryChangeType = 4 ) +const ( + _LedgerEntryChangeType_Min int32 = 0 + _LedgerEntryChangeType_Max int32 = 4 +) var ledgerEntryChangeTypeMap = map[int32]string{ 0: "LedgerEntryChangeTypeLedgerEntryCreated", @@ -16036,8 +15530,7 @@ var ledgerEntryChangeTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for LedgerEntryChangeType func (e LedgerEntryChangeType) ValidEnum(v int32) bool { - _, ok := ledgerEntryChangeTypeMap[v] - return ok + return v >= _LedgerEntryChangeType_Min && v <= _LedgerEntryChangeType_Max } // String returns the name of `e` @@ -16048,16 +15541,16 @@ func (e LedgerEntryChangeType) String() string { // EncodeTo encodes this value using the Encoder. func (e LedgerEntryChangeType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := ledgerEntryChangeTypeMap[int32(e)]; !ok { + if int32(e) < _LedgerEntryChangeType_Min || int32(e) > _LedgerEntryChangeType_Max { return fmt.Errorf("'%d' is not a valid LedgerEntryChangeType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*LedgerEntryChangeType)(nil) +var _ xdr.DecoderFrom = (*LedgerEntryChangeType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *LedgerEntryChangeType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerEntryChangeType: %w", ErrMaxDecodingDepthReached) @@ -16067,7 +15560,7 @@ func (e *LedgerEntryChangeType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding LedgerEntryChangeType: %w", err) } - if _, ok := ledgerEntryChangeTypeMap[v]; !ok { + if v < _LedgerEntryChangeType_Min || v > _LedgerEntryChangeType_Max { return n, fmt.Errorf("'%d' is not a valid LedgerEntryChangeType enum value", v) } *e = LedgerEntryChangeType(v) @@ -16084,11 +15577,8 @@ func (s LedgerEntryChangeType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerEntryChangeType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -16196,125 +15686,95 @@ func NewLedgerEntryChange(aType LedgerEntryChangeType, value interface{}) (resul // MustCreated retrieves the Created value from the union, // panicing if the value is not set. func (u LedgerEntryChange) MustCreated() LedgerEntry { - val, ok := u.GetCreated() - - if !ok { - panic("arm Created is not set") + if LedgerEntryChangeType(u.Type) == LedgerEntryChangeTypeLedgerEntryCreated { + return *u.Created } - - return val + panic("arm Created is not set") } // GetCreated retrieves the Created value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryChange) GetCreated() (result LedgerEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Created" { + if LedgerEntryChangeType(u.Type) == LedgerEntryChangeTypeLedgerEntryCreated { result = *u.Created ok = true } - return } // MustUpdated retrieves the Updated value from the union, // panicing if the value is not set. func (u LedgerEntryChange) MustUpdated() LedgerEntry { - val, ok := u.GetUpdated() - - if !ok { - panic("arm Updated is not set") + if LedgerEntryChangeType(u.Type) == LedgerEntryChangeTypeLedgerEntryUpdated { + return *u.Updated } - - return val + panic("arm Updated is not set") } // GetUpdated retrieves the Updated value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryChange) GetUpdated() (result LedgerEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Updated" { + if LedgerEntryChangeType(u.Type) == LedgerEntryChangeTypeLedgerEntryUpdated { result = *u.Updated ok = true } - return } // MustRemoved retrieves the Removed value from the union, // panicing if the value is not set. func (u LedgerEntryChange) MustRemoved() LedgerKey { - val, ok := u.GetRemoved() - - if !ok { - panic("arm Removed is not set") + if LedgerEntryChangeType(u.Type) == LedgerEntryChangeTypeLedgerEntryRemoved { + return *u.Removed } - - return val + panic("arm Removed is not set") } // GetRemoved retrieves the Removed value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryChange) GetRemoved() (result LedgerKey, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Removed" { + if LedgerEntryChangeType(u.Type) == LedgerEntryChangeTypeLedgerEntryRemoved { result = *u.Removed ok = true } - return } // MustState retrieves the State value from the union, // panicing if the value is not set. func (u LedgerEntryChange) MustState() LedgerEntry { - val, ok := u.GetState() - - if !ok { - panic("arm State is not set") + if LedgerEntryChangeType(u.Type) == LedgerEntryChangeTypeLedgerEntryState { + return *u.State } - - return val + panic("arm State is not set") } // GetState retrieves the State value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryChange) GetState() (result LedgerEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "State" { + if LedgerEntryChangeType(u.Type) == LedgerEntryChangeTypeLedgerEntryState { result = *u.State ok = true } - return } // MustRestored retrieves the Restored value from the union, // panicing if the value is not set. func (u LedgerEntryChange) MustRestored() LedgerEntry { - val, ok := u.GetRestored() - - if !ok { - panic("arm Restored is not set") + if LedgerEntryChangeType(u.Type) == LedgerEntryChangeTypeLedgerEntryRestored { + return *u.Restored } - - return val + panic("arm Restored is not set") } // GetRestored retrieves the Restored value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerEntryChange) GetRestored() (result LedgerEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Restored" { + if LedgerEntryChangeType(u.Type) == LedgerEntryChangeTypeLedgerEntryRestored { result = *u.Restored ok = true } - return } @@ -16354,9 +15814,9 @@ func (u LedgerEntryChange) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (LedgerEntryChangeType) switch value '%d' is not valid for union LedgerEntryChange", u.Type) } -var _ decoderFrom = (*LedgerEntryChange)(nil) +var _ xdr.DecoderFrom = (*LedgerEntryChange)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LedgerEntryChange) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerEntryChange: %w", ErrMaxDecodingDepthReached) @@ -16371,7 +15831,9 @@ func (u *LedgerEntryChange) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } switch LedgerEntryChangeType(u.Type) { case LedgerEntryChangeTypeLedgerEntryCreated: - u.Created = new(LedgerEntry) + if u.Created == nil { + u.Created = new(LedgerEntry) + } nTmp, err = (*u.Created).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -16379,7 +15841,9 @@ func (u *LedgerEntryChange) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case LedgerEntryChangeTypeLedgerEntryUpdated: - u.Updated = new(LedgerEntry) + if u.Updated == nil { + u.Updated = new(LedgerEntry) + } nTmp, err = (*u.Updated).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -16387,7 +15851,9 @@ func (u *LedgerEntryChange) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case LedgerEntryChangeTypeLedgerEntryRemoved: - u.Removed = new(LedgerKey) + if u.Removed == nil { + u.Removed = new(LedgerKey) + } nTmp, err = (*u.Removed).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -16395,7 +15861,9 @@ func (u *LedgerEntryChange) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case LedgerEntryChangeTypeLedgerEntryState: - u.State = new(LedgerEntry) + if u.State == nil { + u.State = new(LedgerEntry) + } nTmp, err = (*u.State).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -16403,7 +15871,9 @@ func (u *LedgerEntryChange) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case LedgerEntryChangeTypeLedgerEntryRestored: - u.Restored = new(LedgerEntry) + if u.Restored == nil { + u.Restored = new(LedgerEntry) + } nTmp, err = (*u.Restored).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -16424,11 +15894,8 @@ func (s LedgerEntryChange) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerEntryChange) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -16461,9 +15928,9 @@ func (s LedgerEntryChanges) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerEntryChanges)(nil) +var _ xdr.DecoderFrom = (*LedgerEntryChanges)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerEntryChanges) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerEntryChanges: %w", ErrMaxDecodingDepthReached) @@ -16477,12 +15944,17 @@ func (s *LedgerEntryChanges) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err if err != nil { return n, fmt.Errorf("decoding LedgerEntryChange: %w", err) } - (*s) = nil - if l > 0 { + if l == 0 { + (*s) = (*s)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding LedgerEntryChange: length (%d) exceeds remaining input length (%d)", l, il) } - (*s) = make([]LedgerEntryChange, l) + if cap((*s)) >= int(l) { + (*s) = (*s)[:l] + } else { + (*s) = make([]LedgerEntryChange, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*s)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -16504,11 +15976,8 @@ func (s LedgerEntryChanges) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerEntryChanges) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -16541,9 +16010,9 @@ func (s *OperationMeta) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*OperationMeta)(nil) +var _ xdr.DecoderFrom = (*OperationMeta)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *OperationMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding OperationMeta: %w", ErrMaxDecodingDepthReached) @@ -16569,11 +16038,8 @@ func (s OperationMeta) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *OperationMeta) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -16616,9 +16082,9 @@ func (s *TransactionMetaV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionMetaV1)(nil) +var _ xdr.DecoderFrom = (*TransactionMetaV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionMetaV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionMetaV1: %w", ErrMaxDecodingDepthReached) @@ -16637,12 +16103,17 @@ func (s *TransactionMetaV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding OperationMeta: %w", err) } - s.Operations = nil - if l > 0 { + if l == 0 { + s.Operations = s.Operations[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding OperationMeta: length (%d) exceeds remaining input length (%d)", l, il) } - s.Operations = make([]OperationMeta, l) + if cap(s.Operations) >= int(l) { + s.Operations = s.Operations[:l] + } else { + s.Operations = make([]OperationMeta, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Operations[i].DecodeFrom(d, maxDepth) n += nTmp @@ -16664,11 +16135,8 @@ func (s TransactionMetaV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionMetaV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -16718,9 +16186,9 @@ func (s *TransactionMetaV2) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionMetaV2)(nil) +var _ xdr.DecoderFrom = (*TransactionMetaV2)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionMetaV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionMetaV2: %w", ErrMaxDecodingDepthReached) @@ -16739,12 +16207,17 @@ func (s *TransactionMetaV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding OperationMeta: %w", err) } - s.Operations = nil - if l > 0 { + if l == 0 { + s.Operations = s.Operations[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding OperationMeta: length (%d) exceeds remaining input length (%d)", l, il) } - s.Operations = make([]OperationMeta, l) + if cap(s.Operations) >= int(l) { + s.Operations = s.Operations[:l] + } else { + s.Operations = make([]OperationMeta, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Operations[i].DecodeFrom(d, maxDepth) n += nTmp @@ -16771,11 +16244,8 @@ func (s TransactionMetaV2) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionMetaV2) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -16804,6 +16274,10 @@ const ( ContractEventTypeContract ContractEventType = 1 ContractEventTypeDiagnostic ContractEventType = 2 ) +const ( + _ContractEventType_Min int32 = 0 + _ContractEventType_Max int32 = 2 +) var contractEventTypeMap = map[int32]string{ 0: "ContractEventTypeSystem", @@ -16814,8 +16288,7 @@ var contractEventTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ContractEventType func (e ContractEventType) ValidEnum(v int32) bool { - _, ok := contractEventTypeMap[v] - return ok + return v >= _ContractEventType_Min && v <= _ContractEventType_Max } // String returns the name of `e` @@ -16826,16 +16299,16 @@ func (e ContractEventType) String() string { // EncodeTo encodes this value using the Encoder. func (e ContractEventType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := contractEventTypeMap[int32(e)]; !ok { + if int32(e) < _ContractEventType_Min || int32(e) > _ContractEventType_Max { return fmt.Errorf("'%d' is not a valid ContractEventType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ContractEventType)(nil) +var _ xdr.DecoderFrom = (*ContractEventType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ContractEventType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractEventType: %w", ErrMaxDecodingDepthReached) @@ -16845,7 +16318,7 @@ func (e *ContractEventType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding ContractEventType: %w", err) } - if _, ok := contractEventTypeMap[v]; !ok { + if v < _ContractEventType_Min || v > _ContractEventType_Max { return n, fmt.Errorf("'%d' is not a valid ContractEventType enum value", v) } *e = ContractEventType(v) @@ -16862,11 +16335,8 @@ func (s ContractEventType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractEventType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -16909,9 +16379,9 @@ func (s *ContractEventV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ContractEventV0)(nil) +var _ xdr.DecoderFrom = (*ContractEventV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ContractEventV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractEventV0: %w", ErrMaxDecodingDepthReached) @@ -16925,12 +16395,17 @@ func (s *ContractEventV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding ScVal: %w", err) } - s.Topics = nil - if l > 0 { + if l == 0 { + s.Topics = s.Topics[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScVal: length (%d) exceeds remaining input length (%d)", l, il) } - s.Topics = make([]ScVal, l) + if cap(s.Topics) >= int(l) { + s.Topics = s.Topics[:l] + } else { + s.Topics = make([]ScVal, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Topics[i].DecodeFrom(d, maxDepth) n += nTmp @@ -16957,11 +16432,8 @@ func (s ContractEventV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractEventV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -17025,25 +16497,19 @@ func NewContractEventBody(v int32, value interface{}) (result ContractEventBody, // MustV0 retrieves the V0 value from the union, // panicing if the value is not set. func (u ContractEventBody) MustV0() ContractEventV0 { - val, ok := u.GetV0() - - if !ok { - panic("arm V0 is not set") + if int32(u.V) == 0 { + return *u.V0 } - - return val + panic("arm V0 is not set") } // GetV0 retrieves the V0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ContractEventBody) GetV0() (result ContractEventV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V0" { + if int32(u.V) == 0 { result = *u.V0 ok = true } - return } @@ -17063,9 +16529,9 @@ func (u ContractEventBody) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union ContractEventBody", u.V) } -var _ decoderFrom = (*ContractEventBody)(nil) +var _ xdr.DecoderFrom = (*ContractEventBody)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ContractEventBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractEventBody: %w", ErrMaxDecodingDepthReached) @@ -17080,7 +16546,9 @@ func (u *ContractEventBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } switch int32(u.V) { case 0: - u.V0 = new(ContractEventV0) + if u.V0 == nil { + u.V0 = new(ContractEventV0) + } nTmp, err = (*u.V0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -17101,11 +16569,8 @@ func (s ContractEventBody) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractEventBody) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -17171,9 +16636,9 @@ func (s *ContractEvent) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ContractEvent)(nil) +var _ xdr.DecoderFrom = (*ContractEvent)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ContractEvent) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractEvent: %w", ErrMaxDecodingDepthReached) @@ -17224,11 +16689,8 @@ func (s ContractEvent) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractEvent) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -17266,9 +16728,9 @@ func (s *DiagnosticEvent) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*DiagnosticEvent)(nil) +var _ xdr.DecoderFrom = (*DiagnosticEvent)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *DiagnosticEvent) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding DiagnosticEvent: %w", ErrMaxDecodingDepthReached) @@ -17299,11 +16761,8 @@ func (s DiagnosticEvent) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *DiagnosticEvent) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -17377,9 +16836,9 @@ func (s *SorobanTransactionMetaExtV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SorobanTransactionMetaExtV1)(nil) +var _ xdr.DecoderFrom = (*SorobanTransactionMetaExtV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SorobanTransactionMetaExtV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanTransactionMetaExtV1: %w", ErrMaxDecodingDepthReached) @@ -17420,11 +16879,8 @@ func (s SorobanTransactionMetaExtV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanTransactionMetaExtV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -17490,25 +16946,19 @@ func NewSorobanTransactionMetaExt(v int32, value interface{}) (result SorobanTra // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u SorobanTransactionMetaExt) MustV1() SorobanTransactionMetaExtV1 { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if int32(u.V) == 1 { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u SorobanTransactionMetaExt) GetV1() (result SorobanTransactionMetaExtV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1" { + if int32(u.V) == 1 { result = *u.V1 ok = true } - return } @@ -17531,9 +16981,9 @@ func (u SorobanTransactionMetaExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union SorobanTransactionMetaExt", u.V) } -var _ decoderFrom = (*SorobanTransactionMetaExt)(nil) +var _ xdr.DecoderFrom = (*SorobanTransactionMetaExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *SorobanTransactionMetaExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanTransactionMetaExt: %w", ErrMaxDecodingDepthReached) @@ -17551,7 +17001,9 @@ func (u *SorobanTransactionMetaExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (i // Void return n, nil case 1: - u.V1 = new(SorobanTransactionMetaExtV1) + if u.V1 == nil { + u.V1 = new(SorobanTransactionMetaExtV1) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -17572,11 +17024,8 @@ func (s SorobanTransactionMetaExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanTransactionMetaExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -17640,9 +17089,9 @@ func (s *SorobanTransactionMeta) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SorobanTransactionMeta)(nil) +var _ xdr.DecoderFrom = (*SorobanTransactionMeta)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SorobanTransactionMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanTransactionMeta: %w", ErrMaxDecodingDepthReached) @@ -17661,12 +17110,17 @@ func (s *SorobanTransactionMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding ContractEvent: %w", err) } - s.Events = nil - if l > 0 { + if l == 0 { + s.Events = s.Events[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ContractEvent: length (%d) exceeds remaining input length (%d)", l, il) } - s.Events = make([]ContractEvent, l) + if cap(s.Events) >= int(l) { + s.Events = s.Events[:l] + } else { + s.Events = make([]ContractEvent, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Events[i].DecodeFrom(d, maxDepth) n += nTmp @@ -17685,12 +17139,17 @@ func (s *SorobanTransactionMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding DiagnosticEvent: %w", err) } - s.DiagnosticEvents = nil - if l > 0 { + if l == 0 { + s.DiagnosticEvents = s.DiagnosticEvents[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding DiagnosticEvent: length (%d) exceeds remaining input length (%d)", l, il) } - s.DiagnosticEvents = make([]DiagnosticEvent, l) + if cap(s.DiagnosticEvents) >= int(l) { + s.DiagnosticEvents = s.DiagnosticEvents[:l] + } else { + s.DiagnosticEvents = make([]DiagnosticEvent, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.DiagnosticEvents[i].DecodeFrom(d, maxDepth) n += nTmp @@ -17712,11 +17171,8 @@ func (s SorobanTransactionMeta) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanTransactionMeta) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -17783,9 +17239,9 @@ func (s *TransactionMetaV3) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionMetaV3)(nil) +var _ xdr.DecoderFrom = (*TransactionMetaV3)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionMetaV3) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionMetaV3: %w", ErrMaxDecodingDepthReached) @@ -17809,12 +17265,17 @@ func (s *TransactionMetaV3) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding OperationMeta: %w", err) } - s.Operations = nil - if l > 0 { + if l == 0 { + s.Operations = s.Operations[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding OperationMeta: length (%d) exceeds remaining input length (%d)", l, il) } - s.Operations = make([]OperationMeta, l) + if cap(s.Operations) >= int(l) { + s.Operations = s.Operations[:l] + } else { + s.Operations = make([]OperationMeta, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Operations[i].DecodeFrom(d, maxDepth) n += nTmp @@ -17856,11 +17317,8 @@ func (s TransactionMetaV3) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionMetaV3) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -17910,9 +17368,9 @@ func (s *OperationMetaV2) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*OperationMetaV2)(nil) +var _ xdr.DecoderFrom = (*OperationMetaV2)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *OperationMetaV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding OperationMetaV2: %w", ErrMaxDecodingDepthReached) @@ -17936,12 +17394,17 @@ func (s *OperationMetaV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding ContractEvent: %w", err) } - s.Events = nil - if l > 0 { + if l == 0 { + s.Events = s.Events[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ContractEvent: length (%d) exceeds remaining input length (%d)", l, il) } - s.Events = make([]ContractEvent, l) + if cap(s.Events) >= int(l) { + s.Events = s.Events[:l] + } else { + s.Events = make([]ContractEvent, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Events[i].DecodeFrom(d, maxDepth) n += nTmp @@ -17963,11 +17426,8 @@ func (s OperationMetaV2) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *OperationMetaV2) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -18011,9 +17471,9 @@ func (s *SorobanTransactionMetaV2) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SorobanTransactionMetaV2)(nil) +var _ xdr.DecoderFrom = (*SorobanTransactionMetaV2)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SorobanTransactionMetaV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanTransactionMetaV2: %w", ErrMaxDecodingDepthReached) @@ -18054,11 +17514,8 @@ func (s SorobanTransactionMetaV2) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanTransactionMetaV2) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -18092,6 +17549,10 @@ const ( TransactionEventStageTransactionEventStageAfterTx TransactionEventStage = 1 TransactionEventStageTransactionEventStageAfterAllTxs TransactionEventStage = 2 ) +const ( + _TransactionEventStage_Min int32 = 0 + _TransactionEventStage_Max int32 = 2 +) var transactionEventStageMap = map[int32]string{ 0: "TransactionEventStageTransactionEventStageBeforeAllTxs", @@ -18102,8 +17563,7 @@ var transactionEventStageMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for TransactionEventStage func (e TransactionEventStage) ValidEnum(v int32) bool { - _, ok := transactionEventStageMap[v] - return ok + return v >= _TransactionEventStage_Min && v <= _TransactionEventStage_Max } // String returns the name of `e` @@ -18114,16 +17574,16 @@ func (e TransactionEventStage) String() string { // EncodeTo encodes this value using the Encoder. func (e TransactionEventStage) EncodeTo(enc *xdr.Encoder) error { - if _, ok := transactionEventStageMap[int32(e)]; !ok { + if int32(e) < _TransactionEventStage_Min || int32(e) > _TransactionEventStage_Max { return fmt.Errorf("'%d' is not a valid TransactionEventStage enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*TransactionEventStage)(nil) +var _ xdr.DecoderFrom = (*TransactionEventStage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *TransactionEventStage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionEventStage: %w", ErrMaxDecodingDepthReached) @@ -18133,7 +17593,7 @@ func (e *TransactionEventStage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding TransactionEventStage: %w", err) } - if _, ok := transactionEventStageMap[v]; !ok { + if v < _TransactionEventStage_Min || v > _TransactionEventStage_Max { return n, fmt.Errorf("'%d' is not a valid TransactionEventStage enum value", v) } *e = TransactionEventStage(v) @@ -18150,11 +17610,8 @@ func (s TransactionEventStage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionEventStage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -18191,9 +17648,9 @@ func (s *TransactionEvent) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionEvent)(nil) +var _ xdr.DecoderFrom = (*TransactionEvent)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionEvent) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionEvent: %w", ErrMaxDecodingDepthReached) @@ -18224,11 +17681,8 @@ func (s TransactionEvent) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionEvent) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -18316,9 +17770,9 @@ func (s *TransactionMetaV4) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionMetaV4)(nil) +var _ xdr.DecoderFrom = (*TransactionMetaV4)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionMetaV4) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionMetaV4: %w", ErrMaxDecodingDepthReached) @@ -18342,12 +17796,17 @@ func (s *TransactionMetaV4) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding OperationMetaV2: %w", err) } - s.Operations = nil - if l > 0 { + if l == 0 { + s.Operations = s.Operations[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding OperationMetaV2: length (%d) exceeds remaining input length (%d)", l, il) } - s.Operations = make([]OperationMetaV2, l) + if cap(s.Operations) >= int(l) { + s.Operations = s.Operations[:l] + } else { + s.Operations = make([]OperationMetaV2, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Operations[i].DecodeFrom(d, maxDepth) n += nTmp @@ -18381,12 +17840,17 @@ func (s *TransactionMetaV4) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding TransactionEvent: %w", err) } - s.Events = nil - if l > 0 { + if l == 0 { + s.Events = s.Events[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding TransactionEvent: length (%d) exceeds remaining input length (%d)", l, il) } - s.Events = make([]TransactionEvent, l) + if cap(s.Events) >= int(l) { + s.Events = s.Events[:l] + } else { + s.Events = make([]TransactionEvent, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Events[i].DecodeFrom(d, maxDepth) n += nTmp @@ -18400,12 +17864,17 @@ func (s *TransactionMetaV4) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding DiagnosticEvent: %w", err) } - s.DiagnosticEvents = nil - if l > 0 { + if l == 0 { + s.DiagnosticEvents = s.DiagnosticEvents[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding DiagnosticEvent: length (%d) exceeds remaining input length (%d)", l, il) } - s.DiagnosticEvents = make([]DiagnosticEvent, l) + if cap(s.DiagnosticEvents) >= int(l) { + s.DiagnosticEvents = s.DiagnosticEvents[:l] + } else { + s.DiagnosticEvents = make([]DiagnosticEvent, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.DiagnosticEvents[i].DecodeFrom(d, maxDepth) n += nTmp @@ -18427,11 +17896,8 @@ func (s TransactionMetaV4) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionMetaV4) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -18474,9 +17940,9 @@ func (s *InvokeHostFunctionSuccessPreImage) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*InvokeHostFunctionSuccessPreImage)(nil) +var _ xdr.DecoderFrom = (*InvokeHostFunctionSuccessPreImage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *InvokeHostFunctionSuccessPreImage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InvokeHostFunctionSuccessPreImage: %w", ErrMaxDecodingDepthReached) @@ -18495,12 +17961,17 @@ func (s *InvokeHostFunctionSuccessPreImage) DecodeFrom(d *xdr.Decoder, maxDepth if err != nil { return n, fmt.Errorf("decoding ContractEvent: %w", err) } - s.Events = nil - if l > 0 { + if l == 0 { + s.Events = s.Events[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ContractEvent: length (%d) exceeds remaining input length (%d)", l, il) } - s.Events = make([]ContractEvent, l) + if cap(s.Events) >= int(l) { + s.Events = s.Events[:l] + } else { + s.Events = make([]ContractEvent, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Events[i].DecodeFrom(d, maxDepth) n += nTmp @@ -18522,11 +17993,8 @@ func (s InvokeHostFunctionSuccessPreImage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InvokeHostFunctionSuccessPreImage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -18634,125 +18102,95 @@ func NewTransactionMeta(v int32, value interface{}) (result TransactionMeta, err // MustOperations retrieves the Operations value from the union, // panicing if the value is not set. func (u TransactionMeta) MustOperations() []OperationMeta { - val, ok := u.GetOperations() - - if !ok { - panic("arm Operations is not set") + if int32(u.V) == 0 { + return *u.Operations } - - return val + panic("arm Operations is not set") } // GetOperations retrieves the Operations value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionMeta) GetOperations() (result []OperationMeta, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "Operations" { + if int32(u.V) == 0 { result = *u.Operations ok = true } - return } // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u TransactionMeta) MustV1() TransactionMetaV1 { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if int32(u.V) == 1 { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionMeta) GetV1() (result TransactionMetaV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1" { + if int32(u.V) == 1 { result = *u.V1 ok = true } - return } // MustV2 retrieves the V2 value from the union, // panicing if the value is not set. func (u TransactionMeta) MustV2() TransactionMetaV2 { - val, ok := u.GetV2() - - if !ok { - panic("arm V2 is not set") + if int32(u.V) == 2 { + return *u.V2 } - - return val + panic("arm V2 is not set") } // GetV2 retrieves the V2 value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionMeta) GetV2() (result TransactionMetaV2, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V2" { + if int32(u.V) == 2 { result = *u.V2 ok = true } - return } // MustV3 retrieves the V3 value from the union, // panicing if the value is not set. func (u TransactionMeta) MustV3() TransactionMetaV3 { - val, ok := u.GetV3() - - if !ok { - panic("arm V3 is not set") + if int32(u.V) == 3 { + return *u.V3 } - - return val + panic("arm V3 is not set") } // GetV3 retrieves the V3 value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionMeta) GetV3() (result TransactionMetaV3, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V3" { + if int32(u.V) == 3 { result = *u.V3 ok = true } - return } // MustV4 retrieves the V4 value from the union, // panicing if the value is not set. func (u TransactionMeta) MustV4() TransactionMetaV4 { - val, ok := u.GetV4() - - if !ok { - panic("arm V4 is not set") + if int32(u.V) == 4 { + return *u.V4 } - - return val + panic("arm V4 is not set") } // GetV4 retrieves the V4 value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionMeta) GetV4() (result TransactionMetaV4, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V4" { + if int32(u.V) == 4 { result = *u.V4 ok = true } - return } @@ -18797,9 +18235,9 @@ func (u TransactionMeta) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union TransactionMeta", u.V) } -var _ decoderFrom = (*TransactionMeta)(nil) +var _ xdr.DecoderFrom = (*TransactionMeta)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TransactionMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionMeta: %w", ErrMaxDecodingDepthReached) @@ -18814,19 +18252,26 @@ func (u *TransactionMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } switch int32(u.V) { case 0: - u.Operations = new([]OperationMeta) + if u.Operations == nil { + u.Operations = new([]OperationMeta) + } var l uint32 l, nTmp, err = d.DecodeUint() n += nTmp if err != nil { return n, fmt.Errorf("decoding OperationMeta: %w", err) } - (*u.Operations) = nil - if l > 0 { + if l == 0 { + (*u.Operations) = (*u.Operations)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding OperationMeta: length (%d) exceeds remaining input length (%d)", l, il) } - (*u.Operations) = make([]OperationMeta, l) + if cap((*u.Operations)) >= int(l) { + (*u.Operations) = (*u.Operations)[:l] + } else { + (*u.Operations) = make([]OperationMeta, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*u.Operations)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -18837,7 +18282,9 @@ func (u *TransactionMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case 1: - u.V1 = new(TransactionMetaV1) + if u.V1 == nil { + u.V1 = new(TransactionMetaV1) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -18845,7 +18292,9 @@ func (u *TransactionMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case 2: - u.V2 = new(TransactionMetaV2) + if u.V2 == nil { + u.V2 = new(TransactionMetaV2) + } nTmp, err = (*u.V2).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -18853,7 +18302,9 @@ func (u *TransactionMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case 3: - u.V3 = new(TransactionMetaV3) + if u.V3 == nil { + u.V3 = new(TransactionMetaV3) + } nTmp, err = (*u.V3).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -18861,7 +18312,9 @@ func (u *TransactionMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case 4: - u.V4 = new(TransactionMetaV4) + if u.V4 == nil { + u.V4 = new(TransactionMetaV4) + } nTmp, err = (*u.V4).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -18882,11 +18335,8 @@ func (s TransactionMeta) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionMeta) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -18929,9 +18379,9 @@ func (s *TransactionResultMeta) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionResultMeta)(nil) +var _ xdr.DecoderFrom = (*TransactionResultMeta)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionResultMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionResultMeta: %w", ErrMaxDecodingDepthReached) @@ -18967,11 +18417,8 @@ func (s TransactionResultMeta) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionResultMeta) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -19026,9 +18473,9 @@ func (s *TransactionResultMetaV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionResultMetaV1)(nil) +var _ xdr.DecoderFrom = (*TransactionResultMetaV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionResultMetaV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionResultMetaV1: %w", ErrMaxDecodingDepthReached) @@ -19074,11 +18521,8 @@ func (s TransactionResultMetaV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionResultMetaV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -19116,9 +18560,9 @@ func (s *UpgradeEntryMeta) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*UpgradeEntryMeta)(nil) +var _ xdr.DecoderFrom = (*UpgradeEntryMeta)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *UpgradeEntryMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding UpgradeEntryMeta: %w", ErrMaxDecodingDepthReached) @@ -19149,11 +18593,8 @@ func (s UpgradeEntryMeta) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *UpgradeEntryMeta) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -19230,9 +18671,9 @@ func (s *LedgerCloseMetaV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerCloseMetaV0)(nil) +var _ xdr.DecoderFrom = (*LedgerCloseMetaV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerCloseMetaV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerCloseMetaV0: %w", ErrMaxDecodingDepthReached) @@ -19256,12 +18697,17 @@ func (s *LedgerCloseMetaV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding TransactionResultMeta: %w", err) } - s.TxProcessing = nil - if l > 0 { + if l == 0 { + s.TxProcessing = s.TxProcessing[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding TransactionResultMeta: length (%d) exceeds remaining input length (%d)", l, il) } - s.TxProcessing = make([]TransactionResultMeta, l) + if cap(s.TxProcessing) >= int(l) { + s.TxProcessing = s.TxProcessing[:l] + } else { + s.TxProcessing = make([]TransactionResultMeta, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.TxProcessing[i].DecodeFrom(d, maxDepth) n += nTmp @@ -19275,12 +18721,17 @@ func (s *LedgerCloseMetaV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding UpgradeEntryMeta: %w", err) } - s.UpgradesProcessing = nil - if l > 0 { + if l == 0 { + s.UpgradesProcessing = s.UpgradesProcessing[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding UpgradeEntryMeta: length (%d) exceeds remaining input length (%d)", l, il) } - s.UpgradesProcessing = make([]UpgradeEntryMeta, l) + if cap(s.UpgradesProcessing) >= int(l) { + s.UpgradesProcessing = s.UpgradesProcessing[:l] + } else { + s.UpgradesProcessing = make([]UpgradeEntryMeta, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.UpgradesProcessing[i].DecodeFrom(d, maxDepth) n += nTmp @@ -19294,12 +18745,17 @@ func (s *LedgerCloseMetaV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding ScpHistoryEntry: %w", err) } - s.ScpInfo = nil - if l > 0 { + if l == 0 { + s.ScpInfo = s.ScpInfo[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScpHistoryEntry: length (%d) exceeds remaining input length (%d)", l, il) } - s.ScpInfo = make([]ScpHistoryEntry, l) + if cap(s.ScpInfo) >= int(l) { + s.ScpInfo = s.ScpInfo[:l] + } else { + s.ScpInfo = make([]ScpHistoryEntry, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ScpInfo[i].DecodeFrom(d, maxDepth) n += nTmp @@ -19321,11 +18777,8 @@ func (s LedgerCloseMetaV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerCloseMetaV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -19363,9 +18816,9 @@ func (s *LedgerCloseMetaExtV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerCloseMetaExtV1)(nil) +var _ xdr.DecoderFrom = (*LedgerCloseMetaExtV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerCloseMetaExtV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerCloseMetaExtV1: %w", ErrMaxDecodingDepthReached) @@ -19396,11 +18849,8 @@ func (s LedgerCloseMetaExtV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerCloseMetaExtV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -19466,25 +18916,19 @@ func NewLedgerCloseMetaExt(v int32, value interface{}) (result LedgerCloseMetaEx // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u LedgerCloseMetaExt) MustV1() LedgerCloseMetaExtV1 { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if int32(u.V) == 1 { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerCloseMetaExt) GetV1() (result LedgerCloseMetaExtV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1" { + if int32(u.V) == 1 { result = *u.V1 ok = true } - return } @@ -19507,9 +18951,9 @@ func (u LedgerCloseMetaExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union LedgerCloseMetaExt", u.V) } -var _ decoderFrom = (*LedgerCloseMetaExt)(nil) +var _ xdr.DecoderFrom = (*LedgerCloseMetaExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LedgerCloseMetaExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerCloseMetaExt: %w", ErrMaxDecodingDepthReached) @@ -19527,7 +18971,9 @@ func (u *LedgerCloseMetaExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err // Void return n, nil case 1: - u.V1 = new(LedgerCloseMetaExtV1) + if u.V1 == nil { + u.V1 = new(LedgerCloseMetaExtV1) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -19548,11 +18994,8 @@ func (s LedgerCloseMetaExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerCloseMetaExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -19667,9 +19110,9 @@ func (s *LedgerCloseMetaV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerCloseMetaV1)(nil) +var _ xdr.DecoderFrom = (*LedgerCloseMetaV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerCloseMetaV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerCloseMetaV1: %w", ErrMaxDecodingDepthReached) @@ -19698,12 +19141,17 @@ func (s *LedgerCloseMetaV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding TransactionResultMeta: %w", err) } - s.TxProcessing = nil - if l > 0 { + if l == 0 { + s.TxProcessing = s.TxProcessing[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding TransactionResultMeta: length (%d) exceeds remaining input length (%d)", l, il) } - s.TxProcessing = make([]TransactionResultMeta, l) + if cap(s.TxProcessing) >= int(l) { + s.TxProcessing = s.TxProcessing[:l] + } else { + s.TxProcessing = make([]TransactionResultMeta, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.TxProcessing[i].DecodeFrom(d, maxDepth) n += nTmp @@ -19717,12 +19165,17 @@ func (s *LedgerCloseMetaV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding UpgradeEntryMeta: %w", err) } - s.UpgradesProcessing = nil - if l > 0 { + if l == 0 { + s.UpgradesProcessing = s.UpgradesProcessing[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding UpgradeEntryMeta: length (%d) exceeds remaining input length (%d)", l, il) } - s.UpgradesProcessing = make([]UpgradeEntryMeta, l) + if cap(s.UpgradesProcessing) >= int(l) { + s.UpgradesProcessing = s.UpgradesProcessing[:l] + } else { + s.UpgradesProcessing = make([]UpgradeEntryMeta, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.UpgradesProcessing[i].DecodeFrom(d, maxDepth) n += nTmp @@ -19736,12 +19189,17 @@ func (s *LedgerCloseMetaV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding ScpHistoryEntry: %w", err) } - s.ScpInfo = nil - if l > 0 { + if l == 0 { + s.ScpInfo = s.ScpInfo[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScpHistoryEntry: length (%d) exceeds remaining input length (%d)", l, il) } - s.ScpInfo = make([]ScpHistoryEntry, l) + if cap(s.ScpInfo) >= int(l) { + s.ScpInfo = s.ScpInfo[:l] + } else { + s.ScpInfo = make([]ScpHistoryEntry, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ScpInfo[i].DecodeFrom(d, maxDepth) n += nTmp @@ -19760,12 +19218,17 @@ func (s *LedgerCloseMetaV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding LedgerKey: %w", err) } - s.EvictedKeys = nil - if l > 0 { + if l == 0 { + s.EvictedKeys = s.EvictedKeys[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding LedgerKey: length (%d) exceeds remaining input length (%d)", l, il) } - s.EvictedKeys = make([]LedgerKey, l) + if cap(s.EvictedKeys) >= int(l) { + s.EvictedKeys = s.EvictedKeys[:l] + } else { + s.EvictedKeys = make([]LedgerKey, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.EvictedKeys[i].DecodeFrom(d, maxDepth) n += nTmp @@ -19779,12 +19242,17 @@ func (s *LedgerCloseMetaV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding LedgerEntry: %w", err) } - s.Unused = nil - if l > 0 { + if l == 0 { + s.Unused = s.Unused[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding LedgerEntry: length (%d) exceeds remaining input length (%d)", l, il) } - s.Unused = make([]LedgerEntry, l) + if cap(s.Unused) >= int(l) { + s.Unused = s.Unused[:l] + } else { + s.Unused = make([]LedgerEntry, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Unused[i].DecodeFrom(d, maxDepth) n += nTmp @@ -19806,11 +19274,8 @@ func (s LedgerCloseMetaV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerCloseMetaV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -19913,9 +19378,9 @@ func (s *LedgerCloseMetaV2) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerCloseMetaV2)(nil) +var _ xdr.DecoderFrom = (*LedgerCloseMetaV2)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerCloseMetaV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerCloseMetaV2: %w", ErrMaxDecodingDepthReached) @@ -19944,12 +19409,17 @@ func (s *LedgerCloseMetaV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding TransactionResultMetaV1: %w", err) } - s.TxProcessing = nil - if l > 0 { + if l == 0 { + s.TxProcessing = s.TxProcessing[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding TransactionResultMetaV1: length (%d) exceeds remaining input length (%d)", l, il) } - s.TxProcessing = make([]TransactionResultMetaV1, l) + if cap(s.TxProcessing) >= int(l) { + s.TxProcessing = s.TxProcessing[:l] + } else { + s.TxProcessing = make([]TransactionResultMetaV1, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.TxProcessing[i].DecodeFrom(d, maxDepth) n += nTmp @@ -19963,12 +19433,17 @@ func (s *LedgerCloseMetaV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding UpgradeEntryMeta: %w", err) } - s.UpgradesProcessing = nil - if l > 0 { + if l == 0 { + s.UpgradesProcessing = s.UpgradesProcessing[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding UpgradeEntryMeta: length (%d) exceeds remaining input length (%d)", l, il) } - s.UpgradesProcessing = make([]UpgradeEntryMeta, l) + if cap(s.UpgradesProcessing) >= int(l) { + s.UpgradesProcessing = s.UpgradesProcessing[:l] + } else { + s.UpgradesProcessing = make([]UpgradeEntryMeta, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.UpgradesProcessing[i].DecodeFrom(d, maxDepth) n += nTmp @@ -19982,12 +19457,17 @@ func (s *LedgerCloseMetaV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding ScpHistoryEntry: %w", err) } - s.ScpInfo = nil - if l > 0 { + if l == 0 { + s.ScpInfo = s.ScpInfo[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScpHistoryEntry: length (%d) exceeds remaining input length (%d)", l, il) } - s.ScpInfo = make([]ScpHistoryEntry, l) + if cap(s.ScpInfo) >= int(l) { + s.ScpInfo = s.ScpInfo[:l] + } else { + s.ScpInfo = make([]ScpHistoryEntry, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ScpInfo[i].DecodeFrom(d, maxDepth) n += nTmp @@ -20006,12 +19486,17 @@ func (s *LedgerCloseMetaV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding LedgerKey: %w", err) } - s.EvictedKeys = nil - if l > 0 { + if l == 0 { + s.EvictedKeys = s.EvictedKeys[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding LedgerKey: length (%d) exceeds remaining input length (%d)", l, il) } - s.EvictedKeys = make([]LedgerKey, l) + if cap(s.EvictedKeys) >= int(l) { + s.EvictedKeys = s.EvictedKeys[:l] + } else { + s.EvictedKeys = make([]LedgerKey, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.EvictedKeys[i].DecodeFrom(d, maxDepth) n += nTmp @@ -20033,11 +19518,8 @@ func (s LedgerCloseMetaV2) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerCloseMetaV2) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -20121,75 +19603,57 @@ func NewLedgerCloseMeta(v int32, value interface{}) (result LedgerCloseMeta, err // MustV0 retrieves the V0 value from the union, // panicing if the value is not set. func (u LedgerCloseMeta) MustV0() LedgerCloseMetaV0 { - val, ok := u.GetV0() - - if !ok { - panic("arm V0 is not set") + if int32(u.V) == 0 { + return *u.V0 } - - return val + panic("arm V0 is not set") } // GetV0 retrieves the V0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerCloseMeta) GetV0() (result LedgerCloseMetaV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V0" { + if int32(u.V) == 0 { result = *u.V0 ok = true } - return } // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u LedgerCloseMeta) MustV1() LedgerCloseMetaV1 { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if int32(u.V) == 1 { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerCloseMeta) GetV1() (result LedgerCloseMetaV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1" { + if int32(u.V) == 1 { result = *u.V1 ok = true } - return } // MustV2 retrieves the V2 value from the union, // panicing if the value is not set. func (u LedgerCloseMeta) MustV2() LedgerCloseMetaV2 { - val, ok := u.GetV2() - - if !ok { - panic("arm V2 is not set") + if int32(u.V) == 2 { + return *u.V2 } - - return val + panic("arm V2 is not set") } // GetV2 retrieves the V2 value from the union, // returning ok if the union's switch indicated the value is valid. func (u LedgerCloseMeta) GetV2() (result LedgerCloseMetaV2, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V2" { + if int32(u.V) == 2 { result = *u.V2 ok = true } - return } @@ -20219,9 +19683,9 @@ func (u LedgerCloseMeta) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union LedgerCloseMeta", u.V) } -var _ decoderFrom = (*LedgerCloseMeta)(nil) +var _ xdr.DecoderFrom = (*LedgerCloseMeta)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LedgerCloseMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerCloseMeta: %w", ErrMaxDecodingDepthReached) @@ -20236,7 +19700,9 @@ func (u *LedgerCloseMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } switch int32(u.V) { case 0: - u.V0 = new(LedgerCloseMetaV0) + if u.V0 == nil { + u.V0 = new(LedgerCloseMetaV0) + } nTmp, err = (*u.V0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -20244,7 +19710,9 @@ func (u *LedgerCloseMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case 1: - u.V1 = new(LedgerCloseMetaV1) + if u.V1 == nil { + u.V1 = new(LedgerCloseMetaV1) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -20252,7 +19720,9 @@ func (u *LedgerCloseMeta) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case 2: - u.V2 = new(LedgerCloseMetaV2) + if u.V2 == nil { + u.V2 = new(LedgerCloseMetaV2) + } nTmp, err = (*u.V2).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -20273,11 +19743,8 @@ func (s LedgerCloseMeta) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerCloseMeta) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -20310,6 +19777,10 @@ const ( ErrorCodeErrAuth ErrorCode = 3 ErrorCodeErrLoad ErrorCode = 4 ) +const ( + _ErrorCode_Min int32 = 0 + _ErrorCode_Max int32 = 4 +) var errorCodeMap = map[int32]string{ 0: "ErrorCodeErrMisc", @@ -20322,8 +19793,7 @@ var errorCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ErrorCode func (e ErrorCode) ValidEnum(v int32) bool { - _, ok := errorCodeMap[v] - return ok + return v >= _ErrorCode_Min && v <= _ErrorCode_Max } // String returns the name of `e` @@ -20334,16 +19804,16 @@ func (e ErrorCode) String() string { // EncodeTo encodes this value using the Encoder. func (e ErrorCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := errorCodeMap[int32(e)]; !ok { + if int32(e) < _ErrorCode_Min || int32(e) > _ErrorCode_Max { return fmt.Errorf("'%d' is not a valid ErrorCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ErrorCode)(nil) +var _ xdr.DecoderFrom = (*ErrorCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ErrorCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ErrorCode: %w", ErrMaxDecodingDepthReached) @@ -20353,7 +19823,7 @@ func (e *ErrorCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ErrorCode: %w", err) } - if _, ok := errorCodeMap[v]; !ok { + if v < _ErrorCode_Min || v > _ErrorCode_Max { return n, fmt.Errorf("'%d' is not a valid ErrorCode enum value", v) } *e = ErrorCode(v) @@ -20370,11 +19840,8 @@ func (s ErrorCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ErrorCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -20412,9 +19879,9 @@ func (s *Error) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Error)(nil) +var _ xdr.DecoderFrom = (*Error)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Error) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Error: %w", ErrMaxDecodingDepthReached) @@ -20445,11 +19912,8 @@ func (s Error) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Error) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -20482,9 +19946,9 @@ func (s *SendMore) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SendMore)(nil) +var _ xdr.DecoderFrom = (*SendMore)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SendMore) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SendMore: %w", ErrMaxDecodingDepthReached) @@ -20510,11 +19974,8 @@ func (s SendMore) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SendMore) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -20552,9 +20013,9 @@ func (s *SendMoreExtended) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SendMoreExtended)(nil) +var _ xdr.DecoderFrom = (*SendMoreExtended)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SendMoreExtended) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SendMoreExtended: %w", ErrMaxDecodingDepthReached) @@ -20585,11 +20046,8 @@ func (s SendMoreExtended) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SendMoreExtended) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -20632,9 +20090,9 @@ func (s *AuthCert) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AuthCert)(nil) +var _ xdr.DecoderFrom = (*AuthCert)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AuthCert) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AuthCert: %w", ErrMaxDecodingDepthReached) @@ -20670,11 +20128,8 @@ func (s AuthCert) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AuthCert) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -20747,9 +20202,9 @@ func (s *Hello) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Hello)(nil) +var _ xdr.DecoderFrom = (*Hello)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Hello) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Hello: %w", ErrMaxDecodingDepthReached) @@ -20815,11 +20270,8 @@ func (s Hello) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Hello) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -20857,9 +20309,9 @@ func (s *Auth) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Auth)(nil) +var _ xdr.DecoderFrom = (*Auth)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Auth) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Auth: %w", ErrMaxDecodingDepthReached) @@ -20885,11 +20337,8 @@ func (s Auth) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Auth) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -20916,6 +20365,10 @@ const ( IpAddrTypeIPv4 IpAddrType = 0 IpAddrTypeIPv6 IpAddrType = 1 ) +const ( + _IpAddrType_Min int32 = 0 + _IpAddrType_Max int32 = 1 +) var ipAddrTypeMap = map[int32]string{ 0: "IpAddrTypeIPv4", @@ -20925,8 +20378,7 @@ var ipAddrTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for IpAddrType func (e IpAddrType) ValidEnum(v int32) bool { - _, ok := ipAddrTypeMap[v] - return ok + return v >= _IpAddrType_Min && v <= _IpAddrType_Max } // String returns the name of `e` @@ -20937,16 +20389,16 @@ func (e IpAddrType) String() string { // EncodeTo encodes this value using the Encoder. func (e IpAddrType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := ipAddrTypeMap[int32(e)]; !ok { + if int32(e) < _IpAddrType_Min || int32(e) > _IpAddrType_Max { return fmt.Errorf("'%d' is not a valid IpAddrType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*IpAddrType)(nil) +var _ xdr.DecoderFrom = (*IpAddrType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *IpAddrType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding IpAddrType: %w", ErrMaxDecodingDepthReached) @@ -20956,7 +20408,7 @@ func (e *IpAddrType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding IpAddrType: %w", err) } - if _, ok := ipAddrTypeMap[v]; !ok { + if v < _IpAddrType_Min || v > _IpAddrType_Max { return n, fmt.Errorf("'%d' is not a valid IpAddrType enum value", v) } *e = IpAddrType(v) @@ -20973,11 +20425,8 @@ func (s IpAddrType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *IpAddrType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -21049,50 +20498,38 @@ func NewPeerAddressIp(aType IpAddrType, value interface{}) (result PeerAddressIp // MustIpv4 retrieves the Ipv4 value from the union, // panicing if the value is not set. func (u PeerAddressIp) MustIpv4() [4]byte { - val, ok := u.GetIpv4() - - if !ok { - panic("arm Ipv4 is not set") + if IpAddrType(u.Type) == IpAddrTypeIPv4 { + return *u.Ipv4 } - - return val + panic("arm Ipv4 is not set") } // GetIpv4 retrieves the Ipv4 value from the union, // returning ok if the union's switch indicated the value is valid. func (u PeerAddressIp) GetIpv4() (result [4]byte, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Ipv4" { + if IpAddrType(u.Type) == IpAddrTypeIPv4 { result = *u.Ipv4 ok = true } - return } // MustIpv6 retrieves the Ipv6 value from the union, // panicing if the value is not set. func (u PeerAddressIp) MustIpv6() [16]byte { - val, ok := u.GetIpv6() - - if !ok { - panic("arm Ipv6 is not set") + if IpAddrType(u.Type) == IpAddrTypeIPv6 { + return *u.Ipv6 } - - return val + panic("arm Ipv6 is not set") } // GetIpv6 retrieves the Ipv6 value from the union, // returning ok if the union's switch indicated the value is valid. func (u PeerAddressIp) GetIpv6() (result [16]byte, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Ipv6" { + if IpAddrType(u.Type) == IpAddrTypeIPv6 { result = *u.Ipv6 ok = true } - return } @@ -21117,9 +20554,9 @@ func (u PeerAddressIp) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (IpAddrType) switch value '%d' is not valid for union PeerAddressIp", u.Type) } -var _ decoderFrom = (*PeerAddressIp)(nil) +var _ xdr.DecoderFrom = (*PeerAddressIp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *PeerAddressIp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PeerAddressIp: %w", ErrMaxDecodingDepthReached) @@ -21134,7 +20571,9 @@ func (u *PeerAddressIp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch IpAddrType(u.Type) { case IpAddrTypeIPv4: - u.Ipv4 = new([4]byte) + if u.Ipv4 == nil { + u.Ipv4 = new([4]byte) + } nTmp, err = d.DecodeFixedOpaqueInplace((*u.Ipv4)[:]) n += nTmp if err != nil { @@ -21142,7 +20581,9 @@ func (u *PeerAddressIp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case IpAddrTypeIPv6: - u.Ipv6 = new([16]byte) + if u.Ipv6 == nil { + u.Ipv6 = new([16]byte) + } nTmp, err = d.DecodeFixedOpaqueInplace((*u.Ipv6)[:]) n += nTmp if err != nil { @@ -21163,11 +20604,8 @@ func (s PeerAddressIp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PeerAddressIp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -21217,9 +20655,9 @@ func (s *PeerAddress) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*PeerAddress)(nil) +var _ xdr.DecoderFrom = (*PeerAddress)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *PeerAddress) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PeerAddress: %w", ErrMaxDecodingDepthReached) @@ -21255,11 +20693,8 @@ func (s PeerAddress) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PeerAddress) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -21366,8 +20801,12 @@ var messageTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for MessageType func (e MessageType) ValidEnum(v int32) bool { - _, ok := messageTypeMap[v] - return ok + switch v { + case 0, 2, 3, 5, 6, 7, 17, 8, 9, 10, 11, 12, 13, 16, 20, 18, 19, 21, 22, 23, 24: + return true + default: + return false + } } // String returns the name of `e` @@ -21378,16 +20817,19 @@ func (e MessageType) String() string { // EncodeTo encodes this value using the Encoder. func (e MessageType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := messageTypeMap[int32(e)]; !ok { + switch int32(e) { + case 0, 2, 3, 5, 6, 7, 17, 8, 9, 10, 11, 12, 13, 16, 20, 18, 19, 21, 22, 23, 24: + // valid + default: return fmt.Errorf("'%d' is not a valid MessageType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*MessageType)(nil) +var _ xdr.DecoderFrom = (*MessageType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *MessageType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding MessageType: %w", ErrMaxDecodingDepthReached) @@ -21397,7 +20839,10 @@ func (e *MessageType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding MessageType: %w", err) } - if _, ok := messageTypeMap[v]; !ok { + switch v { + case 0, 2, 3, 5, 6, 7, 17, 8, 9, 10, 11, 12, 13, 16, 20, 18, 19, 21, 22, 23, 24: + // valid + default: return n, fmt.Errorf("'%d' is not a valid MessageType enum value", v) } *e = MessageType(v) @@ -21414,11 +20859,8 @@ func (s MessageType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *MessageType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -21456,9 +20898,9 @@ func (s *DontHave) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*DontHave)(nil) +var _ xdr.DecoderFrom = (*DontHave)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *DontHave) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding DontHave: %w", ErrMaxDecodingDepthReached) @@ -21489,11 +20931,8 @@ func (s DontHave) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *DontHave) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -21518,6 +20957,10 @@ type SurveyMessageCommandType int32 const ( SurveyMessageCommandTypeTimeSlicedSurveyTopology SurveyMessageCommandType = 1 ) +const ( + _SurveyMessageCommandType_Min int32 = 1 + _SurveyMessageCommandType_Max int32 = 1 +) var surveyMessageCommandTypeMap = map[int32]string{ 1: "SurveyMessageCommandTypeTimeSlicedSurveyTopology", @@ -21526,8 +20969,7 @@ var surveyMessageCommandTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for SurveyMessageCommandType func (e SurveyMessageCommandType) ValidEnum(v int32) bool { - _, ok := surveyMessageCommandTypeMap[v] - return ok + return v >= _SurveyMessageCommandType_Min && v <= _SurveyMessageCommandType_Max } // String returns the name of `e` @@ -21538,16 +20980,16 @@ func (e SurveyMessageCommandType) String() string { // EncodeTo encodes this value using the Encoder. func (e SurveyMessageCommandType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := surveyMessageCommandTypeMap[int32(e)]; !ok { + if int32(e) < _SurveyMessageCommandType_Min || int32(e) > _SurveyMessageCommandType_Max { return fmt.Errorf("'%d' is not a valid SurveyMessageCommandType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*SurveyMessageCommandType)(nil) +var _ xdr.DecoderFrom = (*SurveyMessageCommandType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *SurveyMessageCommandType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SurveyMessageCommandType: %w", ErrMaxDecodingDepthReached) @@ -21557,7 +20999,7 @@ func (e *SurveyMessageCommandType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (in if err != nil { return n, fmt.Errorf("decoding SurveyMessageCommandType: %w", err) } - if _, ok := surveyMessageCommandTypeMap[v]; !ok { + if v < _SurveyMessageCommandType_Min || v > _SurveyMessageCommandType_Max { return n, fmt.Errorf("'%d' is not a valid SurveyMessageCommandType enum value", v) } *e = SurveyMessageCommandType(v) @@ -21574,11 +21016,8 @@ func (s SurveyMessageCommandType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SurveyMessageCommandType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -21603,6 +21042,10 @@ type SurveyMessageResponseType int32 const ( SurveyMessageResponseTypeSurveyTopologyResponseV2 SurveyMessageResponseType = 2 ) +const ( + _SurveyMessageResponseType_Min int32 = 2 + _SurveyMessageResponseType_Max int32 = 2 +) var surveyMessageResponseTypeMap = map[int32]string{ 2: "SurveyMessageResponseTypeSurveyTopologyResponseV2", @@ -21611,8 +21054,7 @@ var surveyMessageResponseTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for SurveyMessageResponseType func (e SurveyMessageResponseType) ValidEnum(v int32) bool { - _, ok := surveyMessageResponseTypeMap[v] - return ok + return v >= _SurveyMessageResponseType_Min && v <= _SurveyMessageResponseType_Max } // String returns the name of `e` @@ -21623,16 +21065,16 @@ func (e SurveyMessageResponseType) String() string { // EncodeTo encodes this value using the Encoder. func (e SurveyMessageResponseType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := surveyMessageResponseTypeMap[int32(e)]; !ok { + if int32(e) < _SurveyMessageResponseType_Min || int32(e) > _SurveyMessageResponseType_Max { return fmt.Errorf("'%d' is not a valid SurveyMessageResponseType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*SurveyMessageResponseType)(nil) +var _ xdr.DecoderFrom = (*SurveyMessageResponseType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *SurveyMessageResponseType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SurveyMessageResponseType: %w", ErrMaxDecodingDepthReached) @@ -21642,7 +21084,7 @@ func (e *SurveyMessageResponseType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (i if err != nil { return n, fmt.Errorf("decoding SurveyMessageResponseType: %w", err) } - if _, ok := surveyMessageResponseTypeMap[v]; !ok { + if v < _SurveyMessageResponseType_Min || v > _SurveyMessageResponseType_Max { return n, fmt.Errorf("'%d' is not a valid SurveyMessageResponseType enum value", v) } *e = SurveyMessageResponseType(v) @@ -21659,11 +21101,8 @@ func (s SurveyMessageResponseType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SurveyMessageResponseType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -21706,9 +21145,9 @@ func (s *TimeSlicedSurveyStartCollectingMessage) EncodeTo(e *xdr.Encoder) error return nil } -var _ decoderFrom = (*TimeSlicedSurveyStartCollectingMessage)(nil) +var _ xdr.DecoderFrom = (*TimeSlicedSurveyStartCollectingMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TimeSlicedSurveyStartCollectingMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TimeSlicedSurveyStartCollectingMessage: %w", ErrMaxDecodingDepthReached) @@ -21744,11 +21183,8 @@ func (s TimeSlicedSurveyStartCollectingMessage) MarshalBinary() ([]byte, error) // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TimeSlicedSurveyStartCollectingMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -21786,9 +21222,9 @@ func (s *SignedTimeSlicedSurveyStartCollectingMessage) EncodeTo(e *xdr.Encoder) return nil } -var _ decoderFrom = (*SignedTimeSlicedSurveyStartCollectingMessage)(nil) +var _ xdr.DecoderFrom = (*SignedTimeSlicedSurveyStartCollectingMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SignedTimeSlicedSurveyStartCollectingMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SignedTimeSlicedSurveyStartCollectingMessage: %w", ErrMaxDecodingDepthReached) @@ -21819,11 +21255,8 @@ func (s SignedTimeSlicedSurveyStartCollectingMessage) MarshalBinary() ([]byte, e // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SignedTimeSlicedSurveyStartCollectingMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -21866,9 +21299,9 @@ func (s *TimeSlicedSurveyStopCollectingMessage) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TimeSlicedSurveyStopCollectingMessage)(nil) +var _ xdr.DecoderFrom = (*TimeSlicedSurveyStopCollectingMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TimeSlicedSurveyStopCollectingMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TimeSlicedSurveyStopCollectingMessage: %w", ErrMaxDecodingDepthReached) @@ -21904,11 +21337,8 @@ func (s TimeSlicedSurveyStopCollectingMessage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TimeSlicedSurveyStopCollectingMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -21946,9 +21376,9 @@ func (s *SignedTimeSlicedSurveyStopCollectingMessage) EncodeTo(e *xdr.Encoder) e return nil } -var _ decoderFrom = (*SignedTimeSlicedSurveyStopCollectingMessage)(nil) +var _ xdr.DecoderFrom = (*SignedTimeSlicedSurveyStopCollectingMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SignedTimeSlicedSurveyStopCollectingMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SignedTimeSlicedSurveyStopCollectingMessage: %w", ErrMaxDecodingDepthReached) @@ -21979,11 +21409,8 @@ func (s SignedTimeSlicedSurveyStopCollectingMessage) MarshalBinary() ([]byte, er // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SignedTimeSlicedSurveyStopCollectingMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -22036,9 +21463,9 @@ func (s *SurveyRequestMessage) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SurveyRequestMessage)(nil) +var _ xdr.DecoderFrom = (*SurveyRequestMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SurveyRequestMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SurveyRequestMessage: %w", ErrMaxDecodingDepthReached) @@ -22084,11 +21511,8 @@ func (s SurveyRequestMessage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SurveyRequestMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -22136,9 +21560,9 @@ func (s *TimeSlicedSurveyRequestMessage) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TimeSlicedSurveyRequestMessage)(nil) +var _ xdr.DecoderFrom = (*TimeSlicedSurveyRequestMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TimeSlicedSurveyRequestMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TimeSlicedSurveyRequestMessage: %w", ErrMaxDecodingDepthReached) @@ -22179,11 +21603,8 @@ func (s TimeSlicedSurveyRequestMessage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TimeSlicedSurveyRequestMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -22221,9 +21642,9 @@ func (s *SignedTimeSlicedSurveyRequestMessage) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SignedTimeSlicedSurveyRequestMessage)(nil) +var _ xdr.DecoderFrom = (*SignedTimeSlicedSurveyRequestMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SignedTimeSlicedSurveyRequestMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SignedTimeSlicedSurveyRequestMessage: %w", ErrMaxDecodingDepthReached) @@ -22254,11 +21675,8 @@ func (s SignedTimeSlicedSurveyRequestMessage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SignedTimeSlicedSurveyRequestMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -22291,9 +21709,9 @@ func (s EncryptedBody) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*EncryptedBody)(nil) +var _ xdr.DecoderFrom = (*EncryptedBody)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *EncryptedBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding EncryptedBody: %w", ErrMaxDecodingDepthReached) @@ -22319,11 +21737,8 @@ func (s EncryptedBody) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *EncryptedBody) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -22376,9 +21791,9 @@ func (s *SurveyResponseMessage) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SurveyResponseMessage)(nil) +var _ xdr.DecoderFrom = (*SurveyResponseMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SurveyResponseMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SurveyResponseMessage: %w", ErrMaxDecodingDepthReached) @@ -22424,11 +21839,8 @@ func (s SurveyResponseMessage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SurveyResponseMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -22466,9 +21878,9 @@ func (s *TimeSlicedSurveyResponseMessage) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TimeSlicedSurveyResponseMessage)(nil) +var _ xdr.DecoderFrom = (*TimeSlicedSurveyResponseMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TimeSlicedSurveyResponseMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TimeSlicedSurveyResponseMessage: %w", ErrMaxDecodingDepthReached) @@ -22499,11 +21911,8 @@ func (s TimeSlicedSurveyResponseMessage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TimeSlicedSurveyResponseMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -22541,9 +21950,9 @@ func (s *SignedTimeSlicedSurveyResponseMessage) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SignedTimeSlicedSurveyResponseMessage)(nil) +var _ xdr.DecoderFrom = (*SignedTimeSlicedSurveyResponseMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SignedTimeSlicedSurveyResponseMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SignedTimeSlicedSurveyResponseMessage: %w", ErrMaxDecodingDepthReached) @@ -22574,11 +21983,8 @@ func (s SignedTimeSlicedSurveyResponseMessage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SignedTimeSlicedSurveyResponseMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -22683,9 +22089,9 @@ func (s *PeerStats) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*PeerStats)(nil) +var _ xdr.DecoderFrom = (*PeerStats)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *PeerStats) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PeerStats: %w", ErrMaxDecodingDepthReached) @@ -22781,11 +22187,8 @@ func (s PeerStats) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PeerStats) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -22869,9 +22272,9 @@ func (s *TimeSlicedNodeData) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TimeSlicedNodeData)(nil) +var _ xdr.DecoderFrom = (*TimeSlicedNodeData)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TimeSlicedNodeData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TimeSlicedNodeData: %w", ErrMaxDecodingDepthReached) @@ -22942,11 +22345,8 @@ func (s TimeSlicedNodeData) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TimeSlicedNodeData) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -22984,9 +22384,9 @@ func (s *TimeSlicedPeerData) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TimeSlicedPeerData)(nil) +var _ xdr.DecoderFrom = (*TimeSlicedPeerData)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TimeSlicedPeerData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TimeSlicedPeerData: %w", ErrMaxDecodingDepthReached) @@ -23017,11 +22417,8 @@ func (s TimeSlicedPeerData) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TimeSlicedPeerData) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -23059,9 +22456,9 @@ func (s TimeSlicedPeerDataList) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TimeSlicedPeerDataList)(nil) +var _ xdr.DecoderFrom = (*TimeSlicedPeerDataList)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TimeSlicedPeerDataList) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TimeSlicedPeerDataList: %w", ErrMaxDecodingDepthReached) @@ -23078,12 +22475,17 @@ func (s *TimeSlicedPeerDataList) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if l > 25 { return n, fmt.Errorf("decoding TimeSlicedPeerData: data size (%d) exceeds size limit (25)", l) } - (*s) = nil - if l > 0 { + if l == 0 { + (*s) = (*s)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding TimeSlicedPeerData: length (%d) exceeds remaining input length (%d)", l, il) } - (*s) = make([]TimeSlicedPeerData, l) + if cap((*s)) >= int(l) { + (*s) = (*s)[:l] + } else { + (*s) = make([]TimeSlicedPeerData, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*s)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -23105,11 +22507,8 @@ func (s TimeSlicedPeerDataList) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TimeSlicedPeerDataList) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -23152,9 +22551,9 @@ func (s *TopologyResponseBodyV2) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TopologyResponseBodyV2)(nil) +var _ xdr.DecoderFrom = (*TopologyResponseBodyV2)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TopologyResponseBodyV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TopologyResponseBodyV2: %w", ErrMaxDecodingDepthReached) @@ -23190,11 +22589,8 @@ func (s TopologyResponseBodyV2) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TopologyResponseBodyV2) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -23254,25 +22650,19 @@ func NewSurveyResponseBody(aType SurveyMessageResponseType, value interface{}) ( // MustTopologyResponseBodyV2 retrieves the TopologyResponseBodyV2 value from the union, // panicing if the value is not set. func (u SurveyResponseBody) MustTopologyResponseBodyV2() TopologyResponseBodyV2 { - val, ok := u.GetTopologyResponseBodyV2() - - if !ok { - panic("arm TopologyResponseBodyV2 is not set") + if SurveyMessageResponseType(u.Type) == SurveyMessageResponseTypeSurveyTopologyResponseV2 { + return *u.TopologyResponseBodyV2 } - - return val + panic("arm TopologyResponseBodyV2 is not set") } // GetTopologyResponseBodyV2 retrieves the TopologyResponseBodyV2 value from the union, // returning ok if the union's switch indicated the value is valid. func (u SurveyResponseBody) GetTopologyResponseBodyV2() (result TopologyResponseBodyV2, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "TopologyResponseBodyV2" { + if SurveyMessageResponseType(u.Type) == SurveyMessageResponseTypeSurveyTopologyResponseV2 { result = *u.TopologyResponseBodyV2 ok = true } - return } @@ -23292,9 +22682,9 @@ func (u SurveyResponseBody) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (SurveyMessageResponseType) switch value '%d' is not valid for union SurveyResponseBody", u.Type) } -var _ decoderFrom = (*SurveyResponseBody)(nil) +var _ xdr.DecoderFrom = (*SurveyResponseBody)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *SurveyResponseBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SurveyResponseBody: %w", ErrMaxDecodingDepthReached) @@ -23309,7 +22699,9 @@ func (u *SurveyResponseBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } switch SurveyMessageResponseType(u.Type) { case SurveyMessageResponseTypeSurveyTopologyResponseV2: - u.TopologyResponseBodyV2 = new(TopologyResponseBodyV2) + if u.TopologyResponseBodyV2 == nil { + u.TopologyResponseBodyV2 = new(TopologyResponseBodyV2) + } nTmp, err = (*u.TopologyResponseBodyV2).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -23330,11 +22722,8 @@ func (s SurveyResponseBody) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SurveyResponseBody) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -23377,9 +22766,9 @@ func (s TxAdvertVector) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TxAdvertVector)(nil) +var _ xdr.DecoderFrom = (*TxAdvertVector)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TxAdvertVector) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TxAdvertVector: %w", ErrMaxDecodingDepthReached) @@ -23396,12 +22785,17 @@ func (s *TxAdvertVector) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if l > 1000 { return n, fmt.Errorf("decoding Hash: data size (%d) exceeds size limit (1000)", l) } - (*s) = nil - if l > 0 { + if l == 0 { + (*s) = (*s)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Hash: length (%d) exceeds remaining input length (%d)", l, il) } - (*s) = make([]Hash, l) + if cap((*s)) >= int(l) { + (*s) = (*s)[:l] + } else { + (*s) = make([]Hash, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*s)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -23423,11 +22817,8 @@ func (s TxAdvertVector) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TxAdvertVector) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -23460,9 +22851,9 @@ func (s *FloodAdvert) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*FloodAdvert)(nil) +var _ xdr.DecoderFrom = (*FloodAdvert)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *FloodAdvert) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding FloodAdvert: %w", ErrMaxDecodingDepthReached) @@ -23488,11 +22879,8 @@ func (s FloodAdvert) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *FloodAdvert) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -23535,9 +22923,9 @@ func (s TxDemandVector) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TxDemandVector)(nil) +var _ xdr.DecoderFrom = (*TxDemandVector)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TxDemandVector) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TxDemandVector: %w", ErrMaxDecodingDepthReached) @@ -23554,12 +22942,17 @@ func (s *TxDemandVector) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if l > 1000 { return n, fmt.Errorf("decoding Hash: data size (%d) exceeds size limit (1000)", l) } - (*s) = nil - if l > 0 { + if l == 0 { + (*s) = (*s)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Hash: length (%d) exceeds remaining input length (%d)", l, il) } - (*s) = make([]Hash, l) + if cap((*s)) >= int(l) { + (*s) = (*s)[:l] + } else { + (*s) = make([]Hash, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*s)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -23581,11 +22974,8 @@ func (s TxDemandVector) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TxDemandVector) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -23618,9 +23008,9 @@ func (s *FloodDemand) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*FloodDemand)(nil) +var _ xdr.DecoderFrom = (*FloodDemand)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *FloodDemand) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding FloodDemand: %w", ErrMaxDecodingDepthReached) @@ -23646,11 +23036,8 @@ func (s FloodDemand) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *FloodDemand) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -23740,7 +23127,7 @@ type StellarMessage struct { QSetHash *Uint256 QSet *ScpQuorumSet Envelope *ScpEnvelope - GetScpLedgerSeq *Uint32 + GetScpLedgerSeq Uint32 SendMoreMessage *SendMore SendMoreExtendedMessage *SendMoreExtended FloodAdvert *FloodAdvert @@ -23925,7 +23312,7 @@ func NewStellarMessage(aType MessageType, value interface{}) (result StellarMess err = errors.New("invalid value, must be Uint32") return } - result.GetScpLedgerSeq = &tv + result.GetScpLedgerSeq = tv case MessageTypeSendMore: tv, ok := value.(SendMore) if !ok { @@ -23961,525 +23348,399 @@ func NewStellarMessage(aType MessageType, value interface{}) (result StellarMess // MustError retrieves the Error value from the union, // panicing if the value is not set. func (u StellarMessage) MustError() Error { - val, ok := u.GetError() - - if !ok { - panic("arm Error is not set") + if MessageType(u.Type) == MessageTypeErrorMsg { + return *u.Error } - - return val + panic("arm Error is not set") } // GetError retrieves the Error value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetError() (result Error, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Error" { + if MessageType(u.Type) == MessageTypeErrorMsg { result = *u.Error ok = true } - return } // MustHello retrieves the Hello value from the union, // panicing if the value is not set. func (u StellarMessage) MustHello() Hello { - val, ok := u.GetHello() - - if !ok { - panic("arm Hello is not set") + if MessageType(u.Type) == MessageTypeHello { + return *u.Hello } - - return val + panic("arm Hello is not set") } // GetHello retrieves the Hello value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetHello() (result Hello, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Hello" { + if MessageType(u.Type) == MessageTypeHello { result = *u.Hello ok = true } - return } // MustAuth retrieves the Auth value from the union, // panicing if the value is not set. func (u StellarMessage) MustAuth() Auth { - val, ok := u.GetAuth() - - if !ok { - panic("arm Auth is not set") + if MessageType(u.Type) == MessageTypeAuth { + return *u.Auth } - - return val + panic("arm Auth is not set") } // GetAuth retrieves the Auth value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetAuth() (result Auth, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Auth" { + if MessageType(u.Type) == MessageTypeAuth { result = *u.Auth ok = true } - return } // MustDontHave retrieves the DontHave value from the union, // panicing if the value is not set. func (u StellarMessage) MustDontHave() DontHave { - val, ok := u.GetDontHave() - - if !ok { - panic("arm DontHave is not set") + if MessageType(u.Type) == MessageTypeDontHave { + return *u.DontHave } - - return val + panic("arm DontHave is not set") } // GetDontHave retrieves the DontHave value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetDontHave() (result DontHave, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "DontHave" { + if MessageType(u.Type) == MessageTypeDontHave { result = *u.DontHave ok = true } - return } // MustPeers retrieves the Peers value from the union, // panicing if the value is not set. func (u StellarMessage) MustPeers() []PeerAddress { - val, ok := u.GetPeers() - - if !ok { - panic("arm Peers is not set") + if MessageType(u.Type) == MessageTypePeers { + return *u.Peers } - - return val + panic("arm Peers is not set") } // GetPeers retrieves the Peers value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetPeers() (result []PeerAddress, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Peers" { + if MessageType(u.Type) == MessageTypePeers { result = *u.Peers ok = true } - return } // MustTxSetHash retrieves the TxSetHash value from the union, // panicing if the value is not set. func (u StellarMessage) MustTxSetHash() Uint256 { - val, ok := u.GetTxSetHash() - - if !ok { - panic("arm TxSetHash is not set") + if MessageType(u.Type) == MessageTypeGetTxSet { + return *u.TxSetHash } - - return val + panic("arm TxSetHash is not set") } // GetTxSetHash retrieves the TxSetHash value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetTxSetHash() (result Uint256, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "TxSetHash" { + if MessageType(u.Type) == MessageTypeGetTxSet { result = *u.TxSetHash ok = true } - return } // MustTxSet retrieves the TxSet value from the union, // panicing if the value is not set. func (u StellarMessage) MustTxSet() TransactionSet { - val, ok := u.GetTxSet() - - if !ok { - panic("arm TxSet is not set") + if MessageType(u.Type) == MessageTypeTxSet { + return *u.TxSet } - - return val + panic("arm TxSet is not set") } // GetTxSet retrieves the TxSet value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetTxSet() (result TransactionSet, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "TxSet" { + if MessageType(u.Type) == MessageTypeTxSet { result = *u.TxSet ok = true } - return } // MustGeneralizedTxSet retrieves the GeneralizedTxSet value from the union, // panicing if the value is not set. func (u StellarMessage) MustGeneralizedTxSet() GeneralizedTransactionSet { - val, ok := u.GetGeneralizedTxSet() - - if !ok { - panic("arm GeneralizedTxSet is not set") + if MessageType(u.Type) == MessageTypeGeneralizedTxSet { + return *u.GeneralizedTxSet } - - return val + panic("arm GeneralizedTxSet is not set") } // GetGeneralizedTxSet retrieves the GeneralizedTxSet value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetGeneralizedTxSet() (result GeneralizedTransactionSet, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "GeneralizedTxSet" { + if MessageType(u.Type) == MessageTypeGeneralizedTxSet { result = *u.GeneralizedTxSet ok = true } - return } // MustTransaction retrieves the Transaction value from the union, // panicing if the value is not set. func (u StellarMessage) MustTransaction() TransactionEnvelope { - val, ok := u.GetTransaction() - - if !ok { - panic("arm Transaction is not set") + if MessageType(u.Type) == MessageTypeTransaction { + return *u.Transaction } - - return val + panic("arm Transaction is not set") } // GetTransaction retrieves the Transaction value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetTransaction() (result TransactionEnvelope, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Transaction" { + if MessageType(u.Type) == MessageTypeTransaction { result = *u.Transaction ok = true } - return } // MustSignedTimeSlicedSurveyRequestMessage retrieves the SignedTimeSlicedSurveyRequestMessage value from the union, // panicing if the value is not set. func (u StellarMessage) MustSignedTimeSlicedSurveyRequestMessage() SignedTimeSlicedSurveyRequestMessage { - val, ok := u.GetSignedTimeSlicedSurveyRequestMessage() - - if !ok { - panic("arm SignedTimeSlicedSurveyRequestMessage is not set") + if MessageType(u.Type) == MessageTypeTimeSlicedSurveyRequest { + return *u.SignedTimeSlicedSurveyRequestMessage } - - return val + panic("arm SignedTimeSlicedSurveyRequestMessage is not set") } // GetSignedTimeSlicedSurveyRequestMessage retrieves the SignedTimeSlicedSurveyRequestMessage value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetSignedTimeSlicedSurveyRequestMessage() (result SignedTimeSlicedSurveyRequestMessage, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "SignedTimeSlicedSurveyRequestMessage" { + if MessageType(u.Type) == MessageTypeTimeSlicedSurveyRequest { result = *u.SignedTimeSlicedSurveyRequestMessage ok = true } - return } // MustSignedTimeSlicedSurveyResponseMessage retrieves the SignedTimeSlicedSurveyResponseMessage value from the union, // panicing if the value is not set. func (u StellarMessage) MustSignedTimeSlicedSurveyResponseMessage() SignedTimeSlicedSurveyResponseMessage { - val, ok := u.GetSignedTimeSlicedSurveyResponseMessage() - - if !ok { - panic("arm SignedTimeSlicedSurveyResponseMessage is not set") + if MessageType(u.Type) == MessageTypeTimeSlicedSurveyResponse { + return *u.SignedTimeSlicedSurveyResponseMessage } - - return val + panic("arm SignedTimeSlicedSurveyResponseMessage is not set") } // GetSignedTimeSlicedSurveyResponseMessage retrieves the SignedTimeSlicedSurveyResponseMessage value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetSignedTimeSlicedSurveyResponseMessage() (result SignedTimeSlicedSurveyResponseMessage, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "SignedTimeSlicedSurveyResponseMessage" { + if MessageType(u.Type) == MessageTypeTimeSlicedSurveyResponse { result = *u.SignedTimeSlicedSurveyResponseMessage ok = true } - return } // MustSignedTimeSlicedSurveyStartCollectingMessage retrieves the SignedTimeSlicedSurveyStartCollectingMessage value from the union, // panicing if the value is not set. func (u StellarMessage) MustSignedTimeSlicedSurveyStartCollectingMessage() SignedTimeSlicedSurveyStartCollectingMessage { - val, ok := u.GetSignedTimeSlicedSurveyStartCollectingMessage() - - if !ok { - panic("arm SignedTimeSlicedSurveyStartCollectingMessage is not set") + if MessageType(u.Type) == MessageTypeTimeSlicedSurveyStartCollecting { + return *u.SignedTimeSlicedSurveyStartCollectingMessage } - - return val + panic("arm SignedTimeSlicedSurveyStartCollectingMessage is not set") } // GetSignedTimeSlicedSurveyStartCollectingMessage retrieves the SignedTimeSlicedSurveyStartCollectingMessage value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetSignedTimeSlicedSurveyStartCollectingMessage() (result SignedTimeSlicedSurveyStartCollectingMessage, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "SignedTimeSlicedSurveyStartCollectingMessage" { + if MessageType(u.Type) == MessageTypeTimeSlicedSurveyStartCollecting { result = *u.SignedTimeSlicedSurveyStartCollectingMessage ok = true } - return } // MustSignedTimeSlicedSurveyStopCollectingMessage retrieves the SignedTimeSlicedSurveyStopCollectingMessage value from the union, // panicing if the value is not set. func (u StellarMessage) MustSignedTimeSlicedSurveyStopCollectingMessage() SignedTimeSlicedSurveyStopCollectingMessage { - val, ok := u.GetSignedTimeSlicedSurveyStopCollectingMessage() - - if !ok { - panic("arm SignedTimeSlicedSurveyStopCollectingMessage is not set") + if MessageType(u.Type) == MessageTypeTimeSlicedSurveyStopCollecting { + return *u.SignedTimeSlicedSurveyStopCollectingMessage } - - return val + panic("arm SignedTimeSlicedSurveyStopCollectingMessage is not set") } // GetSignedTimeSlicedSurveyStopCollectingMessage retrieves the SignedTimeSlicedSurveyStopCollectingMessage value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetSignedTimeSlicedSurveyStopCollectingMessage() (result SignedTimeSlicedSurveyStopCollectingMessage, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "SignedTimeSlicedSurveyStopCollectingMessage" { + if MessageType(u.Type) == MessageTypeTimeSlicedSurveyStopCollecting { result = *u.SignedTimeSlicedSurveyStopCollectingMessage ok = true } - return } // MustQSetHash retrieves the QSetHash value from the union, // panicing if the value is not set. func (u StellarMessage) MustQSetHash() Uint256 { - val, ok := u.GetQSetHash() - - if !ok { - panic("arm QSetHash is not set") + if MessageType(u.Type) == MessageTypeGetScpQuorumset { + return *u.QSetHash } - - return val + panic("arm QSetHash is not set") } // GetQSetHash retrieves the QSetHash value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetQSetHash() (result Uint256, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "QSetHash" { + if MessageType(u.Type) == MessageTypeGetScpQuorumset { result = *u.QSetHash ok = true } - return } // MustQSet retrieves the QSet value from the union, // panicing if the value is not set. func (u StellarMessage) MustQSet() ScpQuorumSet { - val, ok := u.GetQSet() - - if !ok { - panic("arm QSet is not set") + if MessageType(u.Type) == MessageTypeScpQuorumset { + return *u.QSet } - - return val + panic("arm QSet is not set") } // GetQSet retrieves the QSet value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetQSet() (result ScpQuorumSet, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "QSet" { + if MessageType(u.Type) == MessageTypeScpQuorumset { result = *u.QSet ok = true } - return } // MustEnvelope retrieves the Envelope value from the union, // panicing if the value is not set. func (u StellarMessage) MustEnvelope() ScpEnvelope { - val, ok := u.GetEnvelope() - - if !ok { - panic("arm Envelope is not set") + if MessageType(u.Type) == MessageTypeScpMessage { + return *u.Envelope } - - return val + panic("arm Envelope is not set") } // GetEnvelope retrieves the Envelope value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetEnvelope() (result ScpEnvelope, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Envelope" { + if MessageType(u.Type) == MessageTypeScpMessage { result = *u.Envelope ok = true } - return } // MustGetScpLedgerSeq retrieves the GetScpLedgerSeq value from the union, // panicing if the value is not set. func (u StellarMessage) MustGetScpLedgerSeq() Uint32 { - val, ok := u.GetGetScpLedgerSeq() - - if !ok { - panic("arm GetScpLedgerSeq is not set") + if MessageType(u.Type) == MessageTypeGetScpState { + return u.GetScpLedgerSeq } - - return val + panic("arm GetScpLedgerSeq is not set") } // GetGetScpLedgerSeq retrieves the GetScpLedgerSeq value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetGetScpLedgerSeq() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "GetScpLedgerSeq" { - result = *u.GetScpLedgerSeq + if MessageType(u.Type) == MessageTypeGetScpState { + result = u.GetScpLedgerSeq ok = true } - return } // MustSendMoreMessage retrieves the SendMoreMessage value from the union, // panicing if the value is not set. func (u StellarMessage) MustSendMoreMessage() SendMore { - val, ok := u.GetSendMoreMessage() - - if !ok { - panic("arm SendMoreMessage is not set") + if MessageType(u.Type) == MessageTypeSendMore { + return *u.SendMoreMessage } - - return val + panic("arm SendMoreMessage is not set") } // GetSendMoreMessage retrieves the SendMoreMessage value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetSendMoreMessage() (result SendMore, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "SendMoreMessage" { + if MessageType(u.Type) == MessageTypeSendMore { result = *u.SendMoreMessage ok = true } - return } // MustSendMoreExtendedMessage retrieves the SendMoreExtendedMessage value from the union, // panicing if the value is not set. func (u StellarMessage) MustSendMoreExtendedMessage() SendMoreExtended { - val, ok := u.GetSendMoreExtendedMessage() - - if !ok { - panic("arm SendMoreExtendedMessage is not set") + if MessageType(u.Type) == MessageTypeSendMoreExtended { + return *u.SendMoreExtendedMessage } - - return val + panic("arm SendMoreExtendedMessage is not set") } // GetSendMoreExtendedMessage retrieves the SendMoreExtendedMessage value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetSendMoreExtendedMessage() (result SendMoreExtended, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "SendMoreExtendedMessage" { + if MessageType(u.Type) == MessageTypeSendMoreExtended { result = *u.SendMoreExtendedMessage ok = true } - return } // MustFloodAdvert retrieves the FloodAdvert value from the union, // panicing if the value is not set. func (u StellarMessage) MustFloodAdvert() FloodAdvert { - val, ok := u.GetFloodAdvert() - - if !ok { - panic("arm FloodAdvert is not set") + if MessageType(u.Type) == MessageTypeFloodAdvert { + return *u.FloodAdvert } - - return val + panic("arm FloodAdvert is not set") } // GetFloodAdvert retrieves the FloodAdvert value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetFloodAdvert() (result FloodAdvert, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "FloodAdvert" { + if MessageType(u.Type) == MessageTypeFloodAdvert { result = *u.FloodAdvert ok = true } - return } // MustFloodDemand retrieves the FloodDemand value from the union, // panicing if the value is not set. func (u StellarMessage) MustFloodDemand() FloodDemand { - val, ok := u.GetFloodDemand() - - if !ok { - panic("arm FloodDemand is not set") + if MessageType(u.Type) == MessageTypeFloodDemand { + return *u.FloodDemand } - - return val + panic("arm FloodDemand is not set") } // GetFloodDemand retrieves the FloodDemand value from the union, // returning ok if the union's switch indicated the value is valid. func (u StellarMessage) GetFloodDemand() (result FloodDemand, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "FloodDemand" { + if MessageType(u.Type) == MessageTypeFloodDemand { result = *u.FloodDemand ok = true } - return } @@ -24576,7 +23837,7 @@ func (u StellarMessage) EncodeTo(e *xdr.Encoder) error { } return nil case MessageTypeGetScpState: - if err = (*u.GetScpLedgerSeq).EncodeTo(e); err != nil { + if err = u.GetScpLedgerSeq.EncodeTo(e); err != nil { return err } return nil @@ -24604,9 +23865,9 @@ func (u StellarMessage) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (MessageType) switch value '%d' is not valid for union StellarMessage", u.Type) } -var _ decoderFrom = (*StellarMessage)(nil) +var _ xdr.DecoderFrom = (*StellarMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding StellarMessage: %w", ErrMaxDecodingDepthReached) @@ -24621,7 +23882,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } switch MessageType(u.Type) { case MessageTypeErrorMsg: - u.Error = new(Error) + if u.Error == nil { + u.Error = new(Error) + } nTmp, err = (*u.Error).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24629,7 +23892,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeHello: - u.Hello = new(Hello) + if u.Hello == nil { + u.Hello = new(Hello) + } nTmp, err = (*u.Hello).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24637,7 +23902,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeAuth: - u.Auth = new(Auth) + if u.Auth == nil { + u.Auth = new(Auth) + } nTmp, err = (*u.Auth).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24645,7 +23912,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeDontHave: - u.DontHave = new(DontHave) + if u.DontHave == nil { + u.DontHave = new(DontHave) + } nTmp, err = (*u.DontHave).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24653,7 +23922,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypePeers: - u.Peers = new([]PeerAddress) + if u.Peers == nil { + u.Peers = new([]PeerAddress) + } var l uint32 l, nTmp, err = d.DecodeUint() n += nTmp @@ -24663,12 +23934,17 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if l > 100 { return n, fmt.Errorf("decoding PeerAddress: data size (%d) exceeds size limit (100)", l) } - (*u.Peers) = nil - if l > 0 { + if l == 0 { + (*u.Peers) = (*u.Peers)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding PeerAddress: length (%d) exceeds remaining input length (%d)", l, il) } - (*u.Peers) = make([]PeerAddress, l) + if cap((*u.Peers)) >= int(l) { + (*u.Peers) = (*u.Peers)[:l] + } else { + (*u.Peers) = make([]PeerAddress, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*u.Peers)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -24679,7 +23955,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeGetTxSet: - u.TxSetHash = new(Uint256) + if u.TxSetHash == nil { + u.TxSetHash = new(Uint256) + } nTmp, err = (*u.TxSetHash).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24687,7 +23965,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeTxSet: - u.TxSet = new(TransactionSet) + if u.TxSet == nil { + u.TxSet = new(TransactionSet) + } nTmp, err = (*u.TxSet).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24695,7 +23975,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeGeneralizedTxSet: - u.GeneralizedTxSet = new(GeneralizedTransactionSet) + if u.GeneralizedTxSet == nil { + u.GeneralizedTxSet = new(GeneralizedTransactionSet) + } nTmp, err = (*u.GeneralizedTxSet).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24703,7 +23985,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeTransaction: - u.Transaction = new(TransactionEnvelope) + if u.Transaction == nil { + u.Transaction = new(TransactionEnvelope) + } nTmp, err = (*u.Transaction).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24711,7 +23995,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeTimeSlicedSurveyRequest: - u.SignedTimeSlicedSurveyRequestMessage = new(SignedTimeSlicedSurveyRequestMessage) + if u.SignedTimeSlicedSurveyRequestMessage == nil { + u.SignedTimeSlicedSurveyRequestMessage = new(SignedTimeSlicedSurveyRequestMessage) + } nTmp, err = (*u.SignedTimeSlicedSurveyRequestMessage).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24719,7 +24005,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeTimeSlicedSurveyResponse: - u.SignedTimeSlicedSurveyResponseMessage = new(SignedTimeSlicedSurveyResponseMessage) + if u.SignedTimeSlicedSurveyResponseMessage == nil { + u.SignedTimeSlicedSurveyResponseMessage = new(SignedTimeSlicedSurveyResponseMessage) + } nTmp, err = (*u.SignedTimeSlicedSurveyResponseMessage).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24727,7 +24015,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeTimeSlicedSurveyStartCollecting: - u.SignedTimeSlicedSurveyStartCollectingMessage = new(SignedTimeSlicedSurveyStartCollectingMessage) + if u.SignedTimeSlicedSurveyStartCollectingMessage == nil { + u.SignedTimeSlicedSurveyStartCollectingMessage = new(SignedTimeSlicedSurveyStartCollectingMessage) + } nTmp, err = (*u.SignedTimeSlicedSurveyStartCollectingMessage).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24735,7 +24025,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeTimeSlicedSurveyStopCollecting: - u.SignedTimeSlicedSurveyStopCollectingMessage = new(SignedTimeSlicedSurveyStopCollectingMessage) + if u.SignedTimeSlicedSurveyStopCollectingMessage == nil { + u.SignedTimeSlicedSurveyStopCollectingMessage = new(SignedTimeSlicedSurveyStopCollectingMessage) + } nTmp, err = (*u.SignedTimeSlicedSurveyStopCollectingMessage).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24743,7 +24035,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeGetScpQuorumset: - u.QSetHash = new(Uint256) + if u.QSetHash == nil { + u.QSetHash = new(Uint256) + } nTmp, err = (*u.QSetHash).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24751,7 +24045,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeScpQuorumset: - u.QSet = new(ScpQuorumSet) + if u.QSet == nil { + u.QSet = new(ScpQuorumSet) + } nTmp, err = (*u.QSet).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24759,7 +24055,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeScpMessage: - u.Envelope = new(ScpEnvelope) + if u.Envelope == nil { + u.Envelope = new(ScpEnvelope) + } nTmp, err = (*u.Envelope).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24767,15 +24065,16 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeGetScpState: - u.GetScpLedgerSeq = new(Uint32) - nTmp, err = (*u.GetScpLedgerSeq).DecodeFrom(d, maxDepth) + nTmp, err = u.GetScpLedgerSeq.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } return n, nil case MessageTypeSendMore: - u.SendMoreMessage = new(SendMore) + if u.SendMoreMessage == nil { + u.SendMoreMessage = new(SendMore) + } nTmp, err = (*u.SendMoreMessage).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24783,7 +24082,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeSendMoreExtended: - u.SendMoreExtendedMessage = new(SendMoreExtended) + if u.SendMoreExtendedMessage == nil { + u.SendMoreExtendedMessage = new(SendMoreExtended) + } nTmp, err = (*u.SendMoreExtendedMessage).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24791,7 +24092,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeFloodAdvert: - u.FloodAdvert = new(FloodAdvert) + if u.FloodAdvert == nil { + u.FloodAdvert = new(FloodAdvert) + } nTmp, err = (*u.FloodAdvert).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24799,7 +24102,9 @@ func (u *StellarMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case MessageTypeFloodDemand: - u.FloodDemand = new(FloodDemand) + if u.FloodDemand == nil { + u.FloodDemand = new(FloodDemand) + } nTmp, err = (*u.FloodDemand).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -24820,11 +24125,8 @@ func (s StellarMessage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *StellarMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -24867,9 +24169,9 @@ func (s *AuthenticatedMessageV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AuthenticatedMessageV0)(nil) +var _ xdr.DecoderFrom = (*AuthenticatedMessageV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AuthenticatedMessageV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AuthenticatedMessageV0: %w", ErrMaxDecodingDepthReached) @@ -24905,11 +24207,8 @@ func (s AuthenticatedMessageV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AuthenticatedMessageV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -24974,25 +24273,19 @@ func NewAuthenticatedMessage(v Uint32, value interface{}) (result AuthenticatedM // MustV0 retrieves the V0 value from the union, // panicing if the value is not set. func (u AuthenticatedMessage) MustV0() AuthenticatedMessageV0 { - val, ok := u.GetV0() - - if !ok { - panic("arm V0 is not set") + if Uint32(u.V) == 0 { + return *u.V0 } - - return val + panic("arm V0 is not set") } // GetV0 retrieves the V0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u AuthenticatedMessage) GetV0() (result AuthenticatedMessageV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V0" { + if Uint32(u.V) == 0 { result = *u.V0 ok = true } - return } @@ -25012,9 +24305,9 @@ func (u AuthenticatedMessage) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (Uint32) switch value '%d' is not valid for union AuthenticatedMessage", u.V) } -var _ decoderFrom = (*AuthenticatedMessage)(nil) +var _ xdr.DecoderFrom = (*AuthenticatedMessage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *AuthenticatedMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AuthenticatedMessage: %w", ErrMaxDecodingDepthReached) @@ -25029,7 +24322,9 @@ func (u *AuthenticatedMessage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e } switch Uint32(u.V) { case 0: - u.V0 = new(AuthenticatedMessageV0) + if u.V0 == nil { + u.V0 = new(AuthenticatedMessageV0) + } nTmp, err = (*u.V0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -25050,11 +24345,8 @@ func (s AuthenticatedMessage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AuthenticatedMessage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -25119,25 +24411,19 @@ func NewLiquidityPoolParameters(aType LiquidityPoolType, value interface{}) (res // MustConstantProduct retrieves the ConstantProduct value from the union, // panicing if the value is not set. func (u LiquidityPoolParameters) MustConstantProduct() LiquidityPoolConstantProductParameters { - val, ok := u.GetConstantProduct() - - if !ok { - panic("arm ConstantProduct is not set") + if LiquidityPoolType(u.Type) == LiquidityPoolTypeLiquidityPoolConstantProduct { + return *u.ConstantProduct } - - return val + panic("arm ConstantProduct is not set") } // GetConstantProduct retrieves the ConstantProduct value from the union, // returning ok if the union's switch indicated the value is valid. func (u LiquidityPoolParameters) GetConstantProduct() (result LiquidityPoolConstantProductParameters, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ConstantProduct" { + if LiquidityPoolType(u.Type) == LiquidityPoolTypeLiquidityPoolConstantProduct { result = *u.ConstantProduct ok = true } - return } @@ -25157,9 +24443,9 @@ func (u LiquidityPoolParameters) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (LiquidityPoolType) switch value '%d' is not valid for union LiquidityPoolParameters", u.Type) } -var _ decoderFrom = (*LiquidityPoolParameters)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolParameters)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LiquidityPoolParameters) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolParameters: %w", ErrMaxDecodingDepthReached) @@ -25174,7 +24460,9 @@ func (u *LiquidityPoolParameters) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int } switch LiquidityPoolType(u.Type) { case LiquidityPoolTypeLiquidityPoolConstantProduct: - u.ConstantProduct = new(LiquidityPoolConstantProductParameters) + if u.ConstantProduct == nil { + u.ConstantProduct = new(LiquidityPoolConstantProductParameters) + } nTmp, err = (*u.ConstantProduct).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -25195,11 +24483,8 @@ func (s LiquidityPoolParameters) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolParameters) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -25237,9 +24522,9 @@ func (s *MuxedAccountMed25519) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*MuxedAccountMed25519)(nil) +var _ xdr.DecoderFrom = (*MuxedAccountMed25519)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *MuxedAccountMed25519) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding MuxedAccountMed25519: %w", ErrMaxDecodingDepthReached) @@ -25270,11 +24555,8 @@ func (s MuxedAccountMed25519) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *MuxedAccountMed25519) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -25350,50 +24632,38 @@ func NewMuxedAccount(aType CryptoKeyType, value interface{}) (result MuxedAccoun // MustEd25519 retrieves the Ed25519 value from the union, // panicing if the value is not set. func (u MuxedAccount) MustEd25519() Uint256 { - val, ok := u.GetEd25519() - - if !ok { - panic("arm Ed25519 is not set") + if CryptoKeyType(u.Type) == CryptoKeyTypeKeyTypeEd25519 { + return *u.Ed25519 } - - return val + panic("arm Ed25519 is not set") } // GetEd25519 retrieves the Ed25519 value from the union, // returning ok if the union's switch indicated the value is valid. func (u MuxedAccount) GetEd25519() (result Uint256, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Ed25519" { + if CryptoKeyType(u.Type) == CryptoKeyTypeKeyTypeEd25519 { result = *u.Ed25519 ok = true } - return } // MustMed25519 retrieves the Med25519 value from the union, // panicing if the value is not set. func (u MuxedAccount) MustMed25519() MuxedAccountMed25519 { - val, ok := u.GetMed25519() - - if !ok { - panic("arm Med25519 is not set") + if CryptoKeyType(u.Type) == CryptoKeyTypeKeyTypeMuxedEd25519 { + return *u.Med25519 } - - return val + panic("arm Med25519 is not set") } // GetMed25519 retrieves the Med25519 value from the union, // returning ok if the union's switch indicated the value is valid. func (u MuxedAccount) GetMed25519() (result MuxedAccountMed25519, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Med25519" { + if CryptoKeyType(u.Type) == CryptoKeyTypeKeyTypeMuxedEd25519 { result = *u.Med25519 ok = true } - return } @@ -25418,9 +24688,9 @@ func (u MuxedAccount) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (CryptoKeyType) switch value '%d' is not valid for union MuxedAccount", u.Type) } -var _ decoderFrom = (*MuxedAccount)(nil) +var _ xdr.DecoderFrom = (*MuxedAccount)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *MuxedAccount) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding MuxedAccount: %w", ErrMaxDecodingDepthReached) @@ -25435,7 +24705,9 @@ func (u *MuxedAccount) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch CryptoKeyType(u.Type) { case CryptoKeyTypeKeyTypeEd25519: - u.Ed25519 = new(Uint256) + if u.Ed25519 == nil { + u.Ed25519 = new(Uint256) + } nTmp, err = (*u.Ed25519).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -25443,7 +24715,9 @@ func (u *MuxedAccount) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case CryptoKeyTypeKeyTypeMuxedEd25519: - u.Med25519 = new(MuxedAccountMed25519) + if u.Med25519 == nil { + u.Med25519 = new(MuxedAccountMed25519) + } nTmp, err = (*u.Med25519).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -25464,11 +24738,8 @@ func (s MuxedAccount) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *MuxedAccount) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -25506,9 +24777,9 @@ func (s *DecoratedSignature) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*DecoratedSignature)(nil) +var _ xdr.DecoderFrom = (*DecoratedSignature)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *DecoratedSignature) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding DecoratedSignature: %w", ErrMaxDecodingDepthReached) @@ -25539,11 +24810,8 @@ func (s DecoratedSignature) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *DecoratedSignature) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -25620,6 +24888,10 @@ const ( OperationTypeExtendFootprintTtl OperationType = 25 OperationTypeRestoreFootprint OperationType = 26 ) +const ( + _OperationType_Min int32 = 0 + _OperationType_Max int32 = 26 +) var operationTypeMap = map[int32]string{ 0: "OperationTypeCreateAccount", @@ -25654,8 +24926,7 @@ var operationTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for OperationType func (e OperationType) ValidEnum(v int32) bool { - _, ok := operationTypeMap[v] - return ok + return v >= _OperationType_Min && v <= _OperationType_Max } // String returns the name of `e` @@ -25666,16 +24937,16 @@ func (e OperationType) String() string { // EncodeTo encodes this value using the Encoder. func (e OperationType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := operationTypeMap[int32(e)]; !ok { + if int32(e) < _OperationType_Min || int32(e) > _OperationType_Max { return fmt.Errorf("'%d' is not a valid OperationType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*OperationType)(nil) +var _ xdr.DecoderFrom = (*OperationType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *OperationType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding OperationType: %w", ErrMaxDecodingDepthReached) @@ -25685,7 +24956,7 @@ func (e *OperationType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding OperationType: %w", err) } - if _, ok := operationTypeMap[v]; !ok { + if v < _OperationType_Min || v > _OperationType_Max { return n, fmt.Errorf("'%d' is not a valid OperationType enum value", v) } *e = OperationType(v) @@ -25702,11 +24973,8 @@ func (s OperationType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *OperationType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -25744,9 +25012,9 @@ func (s *CreateAccountOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*CreateAccountOp)(nil) +var _ xdr.DecoderFrom = (*CreateAccountOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *CreateAccountOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding CreateAccountOp: %w", ErrMaxDecodingDepthReached) @@ -25777,11 +25045,8 @@ func (s CreateAccountOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *CreateAccountOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -25824,9 +25089,9 @@ func (s *PaymentOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*PaymentOp)(nil) +var _ xdr.DecoderFrom = (*PaymentOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *PaymentOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PaymentOp: %w", ErrMaxDecodingDepthReached) @@ -25862,11 +25127,8 @@ func (s PaymentOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PaymentOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -25933,9 +25195,9 @@ func (s *PathPaymentStrictReceiveOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*PathPaymentStrictReceiveOp)(nil) +var _ xdr.DecoderFrom = (*PathPaymentStrictReceiveOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *PathPaymentStrictReceiveOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PathPaymentStrictReceiveOp: %w", ErrMaxDecodingDepthReached) @@ -25977,12 +25239,17 @@ func (s *PathPaymentStrictReceiveOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) ( if l > 5 { return n, fmt.Errorf("decoding Asset: data size (%d) exceeds size limit (5)", l) } - s.Path = nil - if l > 0 { + if l == 0 { + s.Path = s.Path[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Asset: length (%d) exceeds remaining input length (%d)", l, il) } - s.Path = make([]Asset, l) + if cap(s.Path) >= int(l) { + s.Path = s.Path[:l] + } else { + s.Path = make([]Asset, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Path[i].DecodeFrom(d, maxDepth) n += nTmp @@ -26004,11 +25271,8 @@ func (s PathPaymentStrictReceiveOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PathPaymentStrictReceiveOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -26075,9 +25339,9 @@ func (s *PathPaymentStrictSendOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*PathPaymentStrictSendOp)(nil) +var _ xdr.DecoderFrom = (*PathPaymentStrictSendOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *PathPaymentStrictSendOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PathPaymentStrictSendOp: %w", ErrMaxDecodingDepthReached) @@ -26119,12 +25383,17 @@ func (s *PathPaymentStrictSendOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int if l > 5 { return n, fmt.Errorf("decoding Asset: data size (%d) exceeds size limit (5)", l) } - s.Path = nil - if l > 0 { + if l == 0 { + s.Path = s.Path[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Asset: length (%d) exceeds remaining input length (%d)", l, il) } - s.Path = make([]Asset, l) + if cap(s.Path) >= int(l) { + s.Path = s.Path[:l] + } else { + s.Path = make([]Asset, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Path[i].DecodeFrom(d, maxDepth) n += nTmp @@ -26146,11 +25415,8 @@ func (s PathPaymentStrictSendOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PathPaymentStrictSendOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -26205,9 +25471,9 @@ func (s *ManageSellOfferOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ManageSellOfferOp)(nil) +var _ xdr.DecoderFrom = (*ManageSellOfferOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ManageSellOfferOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageSellOfferOp: %w", ErrMaxDecodingDepthReached) @@ -26253,11 +25519,8 @@ func (s ManageSellOfferOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageSellOfferOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -26313,9 +25576,9 @@ func (s *ManageBuyOfferOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ManageBuyOfferOp)(nil) +var _ xdr.DecoderFrom = (*ManageBuyOfferOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ManageBuyOfferOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageBuyOfferOp: %w", ErrMaxDecodingDepthReached) @@ -26361,11 +25624,8 @@ func (s ManageBuyOfferOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageBuyOfferOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -26413,9 +25673,9 @@ func (s *CreatePassiveSellOfferOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*CreatePassiveSellOfferOp)(nil) +var _ xdr.DecoderFrom = (*CreatePassiveSellOfferOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *CreatePassiveSellOfferOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding CreatePassiveSellOfferOp: %w", ErrMaxDecodingDepthReached) @@ -26456,11 +25716,8 @@ func (s CreatePassiveSellOfferOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *CreatePassiveSellOfferOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -26585,9 +25842,9 @@ func (s *SetOptionsOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SetOptionsOp)(nil) +var _ xdr.DecoderFrom = (*SetOptionsOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SetOptionsOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SetOptionsOp: %w", ErrMaxDecodingDepthReached) @@ -26735,11 +25992,8 @@ func (s SetOptionsOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SetOptionsOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -26834,75 +26088,57 @@ func NewChangeTrustAsset(aType AssetType, value interface{}) (result ChangeTrust // MustAlphaNum4 retrieves the AlphaNum4 value from the union, // panicing if the value is not set. func (u ChangeTrustAsset) MustAlphaNum4() AlphaNum4 { - val, ok := u.GetAlphaNum4() - - if !ok { - panic("arm AlphaNum4 is not set") + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum4 { + return *u.AlphaNum4 } - - return val + panic("arm AlphaNum4 is not set") } // GetAlphaNum4 retrieves the AlphaNum4 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ChangeTrustAsset) GetAlphaNum4() (result AlphaNum4, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AlphaNum4" { + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum4 { result = *u.AlphaNum4 ok = true } - return } // MustAlphaNum12 retrieves the AlphaNum12 value from the union, // panicing if the value is not set. func (u ChangeTrustAsset) MustAlphaNum12() AlphaNum12 { - val, ok := u.GetAlphaNum12() - - if !ok { - panic("arm AlphaNum12 is not set") + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum12 { + return *u.AlphaNum12 } - - return val + panic("arm AlphaNum12 is not set") } // GetAlphaNum12 retrieves the AlphaNum12 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ChangeTrustAsset) GetAlphaNum12() (result AlphaNum12, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AlphaNum12" { + if AssetType(u.Type) == AssetTypeAssetTypeCreditAlphanum12 { result = *u.AlphaNum12 ok = true } - return } // MustLiquidityPool retrieves the LiquidityPool value from the union, // panicing if the value is not set. func (u ChangeTrustAsset) MustLiquidityPool() LiquidityPoolParameters { - val, ok := u.GetLiquidityPool() - - if !ok { - panic("arm LiquidityPool is not set") + if AssetType(u.Type) == AssetTypeAssetTypePoolShare { + return *u.LiquidityPool } - - return val + panic("arm LiquidityPool is not set") } // GetLiquidityPool retrieves the LiquidityPool value from the union, // returning ok if the union's switch indicated the value is valid. func (u ChangeTrustAsset) GetLiquidityPool() (result LiquidityPoolParameters, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LiquidityPool" { + if AssetType(u.Type) == AssetTypeAssetTypePoolShare { result = *u.LiquidityPool ok = true } - return } @@ -26935,9 +26171,9 @@ func (u ChangeTrustAsset) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (AssetType) switch value '%d' is not valid for union ChangeTrustAsset", u.Type) } -var _ decoderFrom = (*ChangeTrustAsset)(nil) +var _ xdr.DecoderFrom = (*ChangeTrustAsset)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ChangeTrustAsset) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ChangeTrustAsset: %w", ErrMaxDecodingDepthReached) @@ -26955,7 +26191,9 @@ func (u *ChangeTrustAsset) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error // Void return n, nil case AssetTypeAssetTypeCreditAlphanum4: - u.AlphaNum4 = new(AlphaNum4) + if u.AlphaNum4 == nil { + u.AlphaNum4 = new(AlphaNum4) + } nTmp, err = (*u.AlphaNum4).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -26963,7 +26201,9 @@ func (u *ChangeTrustAsset) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error } return n, nil case AssetTypeAssetTypeCreditAlphanum12: - u.AlphaNum12 = new(AlphaNum12) + if u.AlphaNum12 == nil { + u.AlphaNum12 = new(AlphaNum12) + } nTmp, err = (*u.AlphaNum12).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -26971,7 +26211,9 @@ func (u *ChangeTrustAsset) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error } return n, nil case AssetTypeAssetTypePoolShare: - u.LiquidityPool = new(LiquidityPoolParameters) + if u.LiquidityPool == nil { + u.LiquidityPool = new(LiquidityPoolParameters) + } nTmp, err = (*u.LiquidityPool).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -26992,11 +26234,8 @@ func (s ChangeTrustAsset) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ChangeTrustAsset) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -27036,9 +26275,9 @@ func (s *ChangeTrustOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ChangeTrustOp)(nil) +var _ xdr.DecoderFrom = (*ChangeTrustOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ChangeTrustOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ChangeTrustOp: %w", ErrMaxDecodingDepthReached) @@ -27069,11 +26308,8 @@ func (s ChangeTrustOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ChangeTrustOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -27118,9 +26354,9 @@ func (s *AllowTrustOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AllowTrustOp)(nil) +var _ xdr.DecoderFrom = (*AllowTrustOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AllowTrustOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AllowTrustOp: %w", ErrMaxDecodingDepthReached) @@ -27156,11 +26392,8 @@ func (s AllowTrustOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AllowTrustOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -27203,9 +26436,9 @@ func (s *ManageDataOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ManageDataOp)(nil) +var _ xdr.DecoderFrom = (*ManageDataOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ManageDataOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageDataOp: %w", ErrMaxDecodingDepthReached) @@ -27246,11 +26479,8 @@ func (s ManageDataOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageDataOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -27283,9 +26513,9 @@ func (s *BumpSequenceOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*BumpSequenceOp)(nil) +var _ xdr.DecoderFrom = (*BumpSequenceOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *BumpSequenceOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BumpSequenceOp: %w", ErrMaxDecodingDepthReached) @@ -27311,11 +26541,8 @@ func (s BumpSequenceOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BumpSequenceOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -27363,9 +26590,9 @@ func (s *CreateClaimableBalanceOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*CreateClaimableBalanceOp)(nil) +var _ xdr.DecoderFrom = (*CreateClaimableBalanceOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *CreateClaimableBalanceOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding CreateClaimableBalanceOp: %w", ErrMaxDecodingDepthReached) @@ -27392,12 +26619,17 @@ func (s *CreateClaimableBalanceOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (in if l > 10 { return n, fmt.Errorf("decoding Claimant: data size (%d) exceeds size limit (10)", l) } - s.Claimants = nil - if l > 0 { + if l == 0 { + s.Claimants = s.Claimants[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Claimant: length (%d) exceeds remaining input length (%d)", l, il) } - s.Claimants = make([]Claimant, l) + if cap(s.Claimants) >= int(l) { + s.Claimants = s.Claimants[:l] + } else { + s.Claimants = make([]Claimant, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Claimants[i].DecodeFrom(d, maxDepth) n += nTmp @@ -27419,11 +26651,8 @@ func (s CreateClaimableBalanceOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *CreateClaimableBalanceOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -27456,9 +26685,9 @@ func (s *ClaimClaimableBalanceOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ClaimClaimableBalanceOp)(nil) +var _ xdr.DecoderFrom = (*ClaimClaimableBalanceOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ClaimClaimableBalanceOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimClaimableBalanceOp: %w", ErrMaxDecodingDepthReached) @@ -27484,11 +26713,8 @@ func (s ClaimClaimableBalanceOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimClaimableBalanceOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -27521,9 +26747,9 @@ func (s *BeginSponsoringFutureReservesOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*BeginSponsoringFutureReservesOp)(nil) +var _ xdr.DecoderFrom = (*BeginSponsoringFutureReservesOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *BeginSponsoringFutureReservesOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BeginSponsoringFutureReservesOp: %w", ErrMaxDecodingDepthReached) @@ -27549,11 +26775,8 @@ func (s BeginSponsoringFutureReservesOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BeginSponsoringFutureReservesOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -27580,6 +26803,10 @@ const ( RevokeSponsorshipTypeRevokeSponsorshipLedgerEntry RevokeSponsorshipType = 0 RevokeSponsorshipTypeRevokeSponsorshipSigner RevokeSponsorshipType = 1 ) +const ( + _RevokeSponsorshipType_Min int32 = 0 + _RevokeSponsorshipType_Max int32 = 1 +) var revokeSponsorshipTypeMap = map[int32]string{ 0: "RevokeSponsorshipTypeRevokeSponsorshipLedgerEntry", @@ -27589,8 +26816,7 @@ var revokeSponsorshipTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for RevokeSponsorshipType func (e RevokeSponsorshipType) ValidEnum(v int32) bool { - _, ok := revokeSponsorshipTypeMap[v] - return ok + return v >= _RevokeSponsorshipType_Min && v <= _RevokeSponsorshipType_Max } // String returns the name of `e` @@ -27601,16 +26827,16 @@ func (e RevokeSponsorshipType) String() string { // EncodeTo encodes this value using the Encoder. func (e RevokeSponsorshipType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := revokeSponsorshipTypeMap[int32(e)]; !ok { + if int32(e) < _RevokeSponsorshipType_Min || int32(e) > _RevokeSponsorshipType_Max { return fmt.Errorf("'%d' is not a valid RevokeSponsorshipType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*RevokeSponsorshipType)(nil) +var _ xdr.DecoderFrom = (*RevokeSponsorshipType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *RevokeSponsorshipType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding RevokeSponsorshipType: %w", ErrMaxDecodingDepthReached) @@ -27620,7 +26846,7 @@ func (e *RevokeSponsorshipType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding RevokeSponsorshipType: %w", err) } - if _, ok := revokeSponsorshipTypeMap[v]; !ok { + if v < _RevokeSponsorshipType_Min || v > _RevokeSponsorshipType_Max { return n, fmt.Errorf("'%d' is not a valid RevokeSponsorshipType enum value", v) } *e = RevokeSponsorshipType(v) @@ -27637,11 +26863,8 @@ func (s RevokeSponsorshipType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *RevokeSponsorshipType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -27679,9 +26902,9 @@ func (s *RevokeSponsorshipOpSigner) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*RevokeSponsorshipOpSigner)(nil) +var _ xdr.DecoderFrom = (*RevokeSponsorshipOpSigner)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *RevokeSponsorshipOpSigner) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding RevokeSponsorshipOpSigner: %w", ErrMaxDecodingDepthReached) @@ -27712,11 +26935,8 @@ func (s RevokeSponsorshipOpSigner) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *RevokeSponsorshipOpSigner) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -27792,50 +27012,38 @@ func NewRevokeSponsorshipOp(aType RevokeSponsorshipType, value interface{}) (res // MustLedgerKey retrieves the LedgerKey value from the union, // panicing if the value is not set. func (u RevokeSponsorshipOp) MustLedgerKey() LedgerKey { - val, ok := u.GetLedgerKey() - - if !ok { - panic("arm LedgerKey is not set") + if RevokeSponsorshipType(u.Type) == RevokeSponsorshipTypeRevokeSponsorshipLedgerEntry { + return *u.LedgerKey } - - return val + panic("arm LedgerKey is not set") } // GetLedgerKey retrieves the LedgerKey value from the union, // returning ok if the union's switch indicated the value is valid. func (u RevokeSponsorshipOp) GetLedgerKey() (result LedgerKey, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LedgerKey" { + if RevokeSponsorshipType(u.Type) == RevokeSponsorshipTypeRevokeSponsorshipLedgerEntry { result = *u.LedgerKey ok = true } - return } // MustSigner retrieves the Signer value from the union, // panicing if the value is not set. func (u RevokeSponsorshipOp) MustSigner() RevokeSponsorshipOpSigner { - val, ok := u.GetSigner() - - if !ok { - panic("arm Signer is not set") + if RevokeSponsorshipType(u.Type) == RevokeSponsorshipTypeRevokeSponsorshipSigner { + return *u.Signer } - - return val + panic("arm Signer is not set") } // GetSigner retrieves the Signer value from the union, // returning ok if the union's switch indicated the value is valid. func (u RevokeSponsorshipOp) GetSigner() (result RevokeSponsorshipOpSigner, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Signer" { + if RevokeSponsorshipType(u.Type) == RevokeSponsorshipTypeRevokeSponsorshipSigner { result = *u.Signer ok = true } - return } @@ -27860,9 +27068,9 @@ func (u RevokeSponsorshipOp) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (RevokeSponsorshipType) switch value '%d' is not valid for union RevokeSponsorshipOp", u.Type) } -var _ decoderFrom = (*RevokeSponsorshipOp)(nil) +var _ xdr.DecoderFrom = (*RevokeSponsorshipOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *RevokeSponsorshipOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding RevokeSponsorshipOp: %w", ErrMaxDecodingDepthReached) @@ -27877,7 +27085,9 @@ func (u *RevokeSponsorshipOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er } switch RevokeSponsorshipType(u.Type) { case RevokeSponsorshipTypeRevokeSponsorshipLedgerEntry: - u.LedgerKey = new(LedgerKey) + if u.LedgerKey == nil { + u.LedgerKey = new(LedgerKey) + } nTmp, err = (*u.LedgerKey).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -27885,7 +27095,9 @@ func (u *RevokeSponsorshipOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er } return n, nil case RevokeSponsorshipTypeRevokeSponsorshipSigner: - u.Signer = new(RevokeSponsorshipOpSigner) + if u.Signer == nil { + u.Signer = new(RevokeSponsorshipOpSigner) + } nTmp, err = (*u.Signer).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -27906,11 +27118,8 @@ func (s RevokeSponsorshipOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *RevokeSponsorshipOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -27953,9 +27162,9 @@ func (s *ClawbackOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ClawbackOp)(nil) +var _ xdr.DecoderFrom = (*ClawbackOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ClawbackOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClawbackOp: %w", ErrMaxDecodingDepthReached) @@ -27991,11 +27200,8 @@ func (s ClawbackOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClawbackOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -28028,9 +27234,9 @@ func (s *ClawbackClaimableBalanceOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ClawbackClaimableBalanceOp)(nil) +var _ xdr.DecoderFrom = (*ClawbackClaimableBalanceOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ClawbackClaimableBalanceOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClawbackClaimableBalanceOp: %w", ErrMaxDecodingDepthReached) @@ -28056,11 +27262,8 @@ func (s ClawbackClaimableBalanceOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClawbackClaimableBalanceOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -28109,9 +27312,9 @@ func (s *SetTrustLineFlagsOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SetTrustLineFlagsOp)(nil) +var _ xdr.DecoderFrom = (*SetTrustLineFlagsOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SetTrustLineFlagsOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SetTrustLineFlagsOp: %w", ErrMaxDecodingDepthReached) @@ -28152,11 +27355,8 @@ func (s SetTrustLineFlagsOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SetTrustLineFlagsOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -28214,9 +27414,9 @@ func (s *LiquidityPoolDepositOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LiquidityPoolDepositOp)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolDepositOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LiquidityPoolDepositOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolDepositOp: %w", ErrMaxDecodingDepthReached) @@ -28262,11 +27462,8 @@ func (s LiquidityPoolDepositOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolDepositOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -28314,9 +27511,9 @@ func (s *LiquidityPoolWithdrawOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LiquidityPoolWithdrawOp)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolWithdrawOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LiquidityPoolWithdrawOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolWithdrawOp: %w", ErrMaxDecodingDepthReached) @@ -28357,11 +27554,8 @@ func (s LiquidityPoolWithdrawOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolWithdrawOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -28392,6 +27586,10 @@ const ( HostFunctionTypeHostFunctionTypeUploadContractWasm HostFunctionType = 2 HostFunctionTypeHostFunctionTypeCreateContractV2 HostFunctionType = 3 ) +const ( + _HostFunctionType_Min int32 = 0 + _HostFunctionType_Max int32 = 3 +) var hostFunctionTypeMap = map[int32]string{ 0: "HostFunctionTypeHostFunctionTypeInvokeContract", @@ -28403,8 +27601,7 @@ var hostFunctionTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for HostFunctionType func (e HostFunctionType) ValidEnum(v int32) bool { - _, ok := hostFunctionTypeMap[v] - return ok + return v >= _HostFunctionType_Min && v <= _HostFunctionType_Max } // String returns the name of `e` @@ -28415,16 +27612,16 @@ func (e HostFunctionType) String() string { // EncodeTo encodes this value using the Encoder. func (e HostFunctionType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := hostFunctionTypeMap[int32(e)]; !ok { + if int32(e) < _HostFunctionType_Min || int32(e) > _HostFunctionType_Max { return fmt.Errorf("'%d' is not a valid HostFunctionType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*HostFunctionType)(nil) +var _ xdr.DecoderFrom = (*HostFunctionType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *HostFunctionType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding HostFunctionType: %w", ErrMaxDecodingDepthReached) @@ -28434,7 +27631,7 @@ func (e *HostFunctionType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error if err != nil { return n, fmt.Errorf("decoding HostFunctionType: %w", err) } - if _, ok := hostFunctionTypeMap[v]; !ok { + if v < _HostFunctionType_Min || v > _HostFunctionType_Max { return n, fmt.Errorf("'%d' is not a valid HostFunctionType enum value", v) } *e = HostFunctionType(v) @@ -28451,11 +27648,8 @@ func (s HostFunctionType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *HostFunctionType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -28482,6 +27676,10 @@ const ( ContractIdPreimageTypeContractIdPreimageFromAddress ContractIdPreimageType = 0 ContractIdPreimageTypeContractIdPreimageFromAsset ContractIdPreimageType = 1 ) +const ( + _ContractIdPreimageType_Min int32 = 0 + _ContractIdPreimageType_Max int32 = 1 +) var contractIdPreimageTypeMap = map[int32]string{ 0: "ContractIdPreimageTypeContractIdPreimageFromAddress", @@ -28491,8 +27689,7 @@ var contractIdPreimageTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ContractIdPreimageType func (e ContractIdPreimageType) ValidEnum(v int32) bool { - _, ok := contractIdPreimageTypeMap[v] - return ok + return v >= _ContractIdPreimageType_Min && v <= _ContractIdPreimageType_Max } // String returns the name of `e` @@ -28503,16 +27700,16 @@ func (e ContractIdPreimageType) String() string { // EncodeTo encodes this value using the Encoder. func (e ContractIdPreimageType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := contractIdPreimageTypeMap[int32(e)]; !ok { + if int32(e) < _ContractIdPreimageType_Min || int32(e) > _ContractIdPreimageType_Max { return fmt.Errorf("'%d' is not a valid ContractIdPreimageType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ContractIdPreimageType)(nil) +var _ xdr.DecoderFrom = (*ContractIdPreimageType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ContractIdPreimageType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractIdPreimageType: %w", ErrMaxDecodingDepthReached) @@ -28522,7 +27719,7 @@ func (e *ContractIdPreimageType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding ContractIdPreimageType: %w", err) } - if _, ok := contractIdPreimageTypeMap[v]; !ok { + if v < _ContractIdPreimageType_Min || v > _ContractIdPreimageType_Max { return n, fmt.Errorf("'%d' is not a valid ContractIdPreimageType enum value", v) } *e = ContractIdPreimageType(v) @@ -28539,11 +27736,8 @@ func (s ContractIdPreimageType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractIdPreimageType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -28581,9 +27775,9 @@ func (s *ContractIdPreimageFromAddress) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ContractIdPreimageFromAddress)(nil) +var _ xdr.DecoderFrom = (*ContractIdPreimageFromAddress)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ContractIdPreimageFromAddress) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractIdPreimageFromAddress: %w", ErrMaxDecodingDepthReached) @@ -28614,11 +27808,8 @@ func (s ContractIdPreimageFromAddress) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractIdPreimageFromAddress) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -28694,50 +27885,38 @@ func NewContractIdPreimage(aType ContractIdPreimageType, value interface{}) (res // MustFromAddress retrieves the FromAddress value from the union, // panicing if the value is not set. func (u ContractIdPreimage) MustFromAddress() ContractIdPreimageFromAddress { - val, ok := u.GetFromAddress() - - if !ok { - panic("arm FromAddress is not set") + if ContractIdPreimageType(u.Type) == ContractIdPreimageTypeContractIdPreimageFromAddress { + return *u.FromAddress } - - return val + panic("arm FromAddress is not set") } // GetFromAddress retrieves the FromAddress value from the union, // returning ok if the union's switch indicated the value is valid. func (u ContractIdPreimage) GetFromAddress() (result ContractIdPreimageFromAddress, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "FromAddress" { + if ContractIdPreimageType(u.Type) == ContractIdPreimageTypeContractIdPreimageFromAddress { result = *u.FromAddress ok = true } - return } // MustFromAsset retrieves the FromAsset value from the union, // panicing if the value is not set. func (u ContractIdPreimage) MustFromAsset() Asset { - val, ok := u.GetFromAsset() - - if !ok { - panic("arm FromAsset is not set") + if ContractIdPreimageType(u.Type) == ContractIdPreimageTypeContractIdPreimageFromAsset { + return *u.FromAsset } - - return val + panic("arm FromAsset is not set") } // GetFromAsset retrieves the FromAsset value from the union, // returning ok if the union's switch indicated the value is valid. func (u ContractIdPreimage) GetFromAsset() (result Asset, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "FromAsset" { + if ContractIdPreimageType(u.Type) == ContractIdPreimageTypeContractIdPreimageFromAsset { result = *u.FromAsset ok = true } - return } @@ -28762,9 +27941,9 @@ func (u ContractIdPreimage) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (ContractIdPreimageType) switch value '%d' is not valid for union ContractIdPreimage", u.Type) } -var _ decoderFrom = (*ContractIdPreimage)(nil) +var _ xdr.DecoderFrom = (*ContractIdPreimage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ContractIdPreimage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractIdPreimage: %w", ErrMaxDecodingDepthReached) @@ -28779,7 +27958,9 @@ func (u *ContractIdPreimage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } switch ContractIdPreimageType(u.Type) { case ContractIdPreimageTypeContractIdPreimageFromAddress: - u.FromAddress = new(ContractIdPreimageFromAddress) + if u.FromAddress == nil { + u.FromAddress = new(ContractIdPreimageFromAddress) + } nTmp, err = (*u.FromAddress).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -28787,7 +27968,9 @@ func (u *ContractIdPreimage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ContractIdPreimageTypeContractIdPreimageFromAsset: - u.FromAsset = new(Asset) + if u.FromAsset == nil { + u.FromAsset = new(Asset) + } nTmp, err = (*u.FromAsset).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -28808,11 +27991,8 @@ func (s ContractIdPreimage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractIdPreimage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -28850,9 +28030,9 @@ func (s *CreateContractArgs) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*CreateContractArgs)(nil) +var _ xdr.DecoderFrom = (*CreateContractArgs)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *CreateContractArgs) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding CreateContractArgs: %w", ErrMaxDecodingDepthReached) @@ -28883,11 +28063,8 @@ func (s CreateContractArgs) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *CreateContractArgs) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -28936,9 +28113,9 @@ func (s *CreateContractArgsV2) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*CreateContractArgsV2)(nil) +var _ xdr.DecoderFrom = (*CreateContractArgsV2)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *CreateContractArgsV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding CreateContractArgsV2: %w", ErrMaxDecodingDepthReached) @@ -28962,12 +28139,17 @@ func (s *CreateContractArgsV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e if err != nil { return n, fmt.Errorf("decoding ScVal: %w", err) } - s.ConstructorArgs = nil - if l > 0 { + if l == 0 { + s.ConstructorArgs = s.ConstructorArgs[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScVal: length (%d) exceeds remaining input length (%d)", l, il) } - s.ConstructorArgs = make([]ScVal, l) + if cap(s.ConstructorArgs) >= int(l) { + s.ConstructorArgs = s.ConstructorArgs[:l] + } else { + s.ConstructorArgs = make([]ScVal, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ConstructorArgs[i].DecodeFrom(d, maxDepth) n += nTmp @@ -28989,11 +28171,8 @@ func (s CreateContractArgsV2) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *CreateContractArgsV2) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -29040,9 +28219,9 @@ func (s *InvokeContractArgs) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*InvokeContractArgs)(nil) +var _ xdr.DecoderFrom = (*InvokeContractArgs)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *InvokeContractArgs) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InvokeContractArgs: %w", ErrMaxDecodingDepthReached) @@ -29066,12 +28245,17 @@ func (s *InvokeContractArgs) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err if err != nil { return n, fmt.Errorf("decoding ScVal: %w", err) } - s.Args = nil - if l > 0 { + if l == 0 { + s.Args = s.Args[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScVal: length (%d) exceeds remaining input length (%d)", l, il) } - s.Args = make([]ScVal, l) + if cap(s.Args) >= int(l) { + s.Args = s.Args[:l] + } else { + s.Args = make([]ScVal, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Args[i].DecodeFrom(d, maxDepth) n += nTmp @@ -29093,11 +28277,8 @@ func (s InvokeContractArgs) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InvokeContractArgs) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -29193,100 +28374,76 @@ func NewHostFunction(aType HostFunctionType, value interface{}) (result HostFunc // MustInvokeContract retrieves the InvokeContract value from the union, // panicing if the value is not set. func (u HostFunction) MustInvokeContract() InvokeContractArgs { - val, ok := u.GetInvokeContract() - - if !ok { - panic("arm InvokeContract is not set") + if HostFunctionType(u.Type) == HostFunctionTypeHostFunctionTypeInvokeContract { + return *u.InvokeContract } - - return val + panic("arm InvokeContract is not set") } // GetInvokeContract retrieves the InvokeContract value from the union, // returning ok if the union's switch indicated the value is valid. func (u HostFunction) GetInvokeContract() (result InvokeContractArgs, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "InvokeContract" { + if HostFunctionType(u.Type) == HostFunctionTypeHostFunctionTypeInvokeContract { result = *u.InvokeContract ok = true } - return } // MustCreateContract retrieves the CreateContract value from the union, // panicing if the value is not set. func (u HostFunction) MustCreateContract() CreateContractArgs { - val, ok := u.GetCreateContract() - - if !ok { - panic("arm CreateContract is not set") + if HostFunctionType(u.Type) == HostFunctionTypeHostFunctionTypeCreateContract { + return *u.CreateContract } - - return val + panic("arm CreateContract is not set") } // GetCreateContract retrieves the CreateContract value from the union, // returning ok if the union's switch indicated the value is valid. func (u HostFunction) GetCreateContract() (result CreateContractArgs, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "CreateContract" { + if HostFunctionType(u.Type) == HostFunctionTypeHostFunctionTypeCreateContract { result = *u.CreateContract ok = true } - return } // MustWasm retrieves the Wasm value from the union, // panicing if the value is not set. func (u HostFunction) MustWasm() []byte { - val, ok := u.GetWasm() - - if !ok { - panic("arm Wasm is not set") + if HostFunctionType(u.Type) == HostFunctionTypeHostFunctionTypeUploadContractWasm { + return *u.Wasm } - - return val + panic("arm Wasm is not set") } // GetWasm retrieves the Wasm value from the union, // returning ok if the union's switch indicated the value is valid. func (u HostFunction) GetWasm() (result []byte, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Wasm" { + if HostFunctionType(u.Type) == HostFunctionTypeHostFunctionTypeUploadContractWasm { result = *u.Wasm ok = true } - return } // MustCreateContractV2 retrieves the CreateContractV2 value from the union, // panicing if the value is not set. func (u HostFunction) MustCreateContractV2() CreateContractArgsV2 { - val, ok := u.GetCreateContractV2() - - if !ok { - panic("arm CreateContractV2 is not set") + if HostFunctionType(u.Type) == HostFunctionTypeHostFunctionTypeCreateContractV2 { + return *u.CreateContractV2 } - - return val + panic("arm CreateContractV2 is not set") } // GetCreateContractV2 retrieves the CreateContractV2 value from the union, // returning ok if the union's switch indicated the value is valid. func (u HostFunction) GetCreateContractV2() (result CreateContractArgsV2, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "CreateContractV2" { + if HostFunctionType(u.Type) == HostFunctionTypeHostFunctionTypeCreateContractV2 { result = *u.CreateContractV2 ok = true } - return } @@ -29321,9 +28478,9 @@ func (u HostFunction) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (HostFunctionType) switch value '%d' is not valid for union HostFunction", u.Type) } -var _ decoderFrom = (*HostFunction)(nil) +var _ xdr.DecoderFrom = (*HostFunction)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *HostFunction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding HostFunction: %w", ErrMaxDecodingDepthReached) @@ -29338,7 +28495,9 @@ func (u *HostFunction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch HostFunctionType(u.Type) { case HostFunctionTypeHostFunctionTypeInvokeContract: - u.InvokeContract = new(InvokeContractArgs) + if u.InvokeContract == nil { + u.InvokeContract = new(InvokeContractArgs) + } nTmp, err = (*u.InvokeContract).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -29346,7 +28505,9 @@ func (u *HostFunction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case HostFunctionTypeHostFunctionTypeCreateContract: - u.CreateContract = new(CreateContractArgs) + if u.CreateContract == nil { + u.CreateContract = new(CreateContractArgs) + } nTmp, err = (*u.CreateContract).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -29354,7 +28515,9 @@ func (u *HostFunction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case HostFunctionTypeHostFunctionTypeUploadContractWasm: - u.Wasm = new([]byte) + if u.Wasm == nil { + u.Wasm = new([]byte) + } (*u.Wasm), nTmp, err = d.DecodeOpaque(0) n += nTmp if err != nil { @@ -29362,7 +28525,9 @@ func (u *HostFunction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case HostFunctionTypeHostFunctionTypeCreateContractV2: - u.CreateContractV2 = new(CreateContractArgsV2) + if u.CreateContractV2 == nil { + u.CreateContractV2 = new(CreateContractArgsV2) + } nTmp, err = (*u.CreateContractV2).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -29383,11 +28548,8 @@ func (s HostFunction) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *HostFunction) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -29416,6 +28578,10 @@ const ( SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeCreateContractHostFn SorobanAuthorizedFunctionType = 1 SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeCreateContractV2HostFn SorobanAuthorizedFunctionType = 2 ) +const ( + _SorobanAuthorizedFunctionType_Min int32 = 0 + _SorobanAuthorizedFunctionType_Max int32 = 2 +) var sorobanAuthorizedFunctionTypeMap = map[int32]string{ 0: "SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeContractFn", @@ -29426,8 +28592,7 @@ var sorobanAuthorizedFunctionTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for SorobanAuthorizedFunctionType func (e SorobanAuthorizedFunctionType) ValidEnum(v int32) bool { - _, ok := sorobanAuthorizedFunctionTypeMap[v] - return ok + return v >= _SorobanAuthorizedFunctionType_Min && v <= _SorobanAuthorizedFunctionType_Max } // String returns the name of `e` @@ -29438,16 +28603,16 @@ func (e SorobanAuthorizedFunctionType) String() string { // EncodeTo encodes this value using the Encoder. func (e SorobanAuthorizedFunctionType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := sorobanAuthorizedFunctionTypeMap[int32(e)]; !ok { + if int32(e) < _SorobanAuthorizedFunctionType_Min || int32(e) > _SorobanAuthorizedFunctionType_Max { return fmt.Errorf("'%d' is not a valid SorobanAuthorizedFunctionType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*SorobanAuthorizedFunctionType)(nil) +var _ xdr.DecoderFrom = (*SorobanAuthorizedFunctionType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *SorobanAuthorizedFunctionType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanAuthorizedFunctionType: %w", ErrMaxDecodingDepthReached) @@ -29457,7 +28622,7 @@ func (e *SorobanAuthorizedFunctionType) DecodeFrom(d *xdr.Decoder, maxDepth uint if err != nil { return n, fmt.Errorf("decoding SorobanAuthorizedFunctionType: %w", err) } - if _, ok := sorobanAuthorizedFunctionTypeMap[v]; !ok { + if v < _SorobanAuthorizedFunctionType_Min || v > _SorobanAuthorizedFunctionType_Max { return n, fmt.Errorf("'%d' is not a valid SorobanAuthorizedFunctionType enum value", v) } *e = SorobanAuthorizedFunctionType(v) @@ -29474,11 +28639,8 @@ func (s SorobanAuthorizedFunctionType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanAuthorizedFunctionType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -29570,75 +28732,57 @@ func NewSorobanAuthorizedFunction(aType SorobanAuthorizedFunctionType, value int // MustContractFn retrieves the ContractFn value from the union, // panicing if the value is not set. func (u SorobanAuthorizedFunction) MustContractFn() InvokeContractArgs { - val, ok := u.GetContractFn() - - if !ok { - panic("arm ContractFn is not set") + if SorobanAuthorizedFunctionType(u.Type) == SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeContractFn { + return *u.ContractFn } - - return val + panic("arm ContractFn is not set") } // GetContractFn retrieves the ContractFn value from the union, // returning ok if the union's switch indicated the value is valid. func (u SorobanAuthorizedFunction) GetContractFn() (result InvokeContractArgs, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ContractFn" { + if SorobanAuthorizedFunctionType(u.Type) == SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeContractFn { result = *u.ContractFn ok = true } - return } // MustCreateContractHostFn retrieves the CreateContractHostFn value from the union, // panicing if the value is not set. func (u SorobanAuthorizedFunction) MustCreateContractHostFn() CreateContractArgs { - val, ok := u.GetCreateContractHostFn() - - if !ok { - panic("arm CreateContractHostFn is not set") + if SorobanAuthorizedFunctionType(u.Type) == SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeCreateContractHostFn { + return *u.CreateContractHostFn } - - return val + panic("arm CreateContractHostFn is not set") } // GetCreateContractHostFn retrieves the CreateContractHostFn value from the union, // returning ok if the union's switch indicated the value is valid. func (u SorobanAuthorizedFunction) GetCreateContractHostFn() (result CreateContractArgs, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "CreateContractHostFn" { + if SorobanAuthorizedFunctionType(u.Type) == SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeCreateContractHostFn { result = *u.CreateContractHostFn ok = true } - return } // MustCreateContractV2HostFn retrieves the CreateContractV2HostFn value from the union, // panicing if the value is not set. func (u SorobanAuthorizedFunction) MustCreateContractV2HostFn() CreateContractArgsV2 { - val, ok := u.GetCreateContractV2HostFn() - - if !ok { - panic("arm CreateContractV2HostFn is not set") + if SorobanAuthorizedFunctionType(u.Type) == SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeCreateContractV2HostFn { + return *u.CreateContractV2HostFn } - - return val + panic("arm CreateContractV2HostFn is not set") } // GetCreateContractV2HostFn retrieves the CreateContractV2HostFn value from the union, // returning ok if the union's switch indicated the value is valid. func (u SorobanAuthorizedFunction) GetCreateContractV2HostFn() (result CreateContractArgsV2, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "CreateContractV2HostFn" { + if SorobanAuthorizedFunctionType(u.Type) == SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeCreateContractV2HostFn { result = *u.CreateContractV2HostFn ok = true } - return } @@ -29668,9 +28812,9 @@ func (u SorobanAuthorizedFunction) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (SorobanAuthorizedFunctionType) switch value '%d' is not valid for union SorobanAuthorizedFunction", u.Type) } -var _ decoderFrom = (*SorobanAuthorizedFunction)(nil) +var _ xdr.DecoderFrom = (*SorobanAuthorizedFunction)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *SorobanAuthorizedFunction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanAuthorizedFunction: %w", ErrMaxDecodingDepthReached) @@ -29685,7 +28829,9 @@ func (u *SorobanAuthorizedFunction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (i } switch SorobanAuthorizedFunctionType(u.Type) { case SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeContractFn: - u.ContractFn = new(InvokeContractArgs) + if u.ContractFn == nil { + u.ContractFn = new(InvokeContractArgs) + } nTmp, err = (*u.ContractFn).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -29693,7 +28839,9 @@ func (u *SorobanAuthorizedFunction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (i } return n, nil case SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeCreateContractHostFn: - u.CreateContractHostFn = new(CreateContractArgs) + if u.CreateContractHostFn == nil { + u.CreateContractHostFn = new(CreateContractArgs) + } nTmp, err = (*u.CreateContractHostFn).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -29701,7 +28849,9 @@ func (u *SorobanAuthorizedFunction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (i } return n, nil case SorobanAuthorizedFunctionTypeSorobanAuthorizedFunctionTypeCreateContractV2HostFn: - u.CreateContractV2HostFn = new(CreateContractArgsV2) + if u.CreateContractV2HostFn == nil { + u.CreateContractV2HostFn = new(CreateContractArgsV2) + } nTmp, err = (*u.CreateContractV2HostFn).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -29722,11 +28872,8 @@ func (s SorobanAuthorizedFunction) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanAuthorizedFunction) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -29769,9 +28916,9 @@ func (s *SorobanAuthorizedInvocation) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SorobanAuthorizedInvocation)(nil) +var _ xdr.DecoderFrom = (*SorobanAuthorizedInvocation)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SorobanAuthorizedInvocation) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanAuthorizedInvocation: %w", ErrMaxDecodingDepthReached) @@ -29790,12 +28937,17 @@ func (s *SorobanAuthorizedInvocation) DecodeFrom(d *xdr.Decoder, maxDepth uint) if err != nil { return n, fmt.Errorf("decoding SorobanAuthorizedInvocation: %w", err) } - s.SubInvocations = nil - if l > 0 { + if l == 0 { + s.SubInvocations = s.SubInvocations[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding SorobanAuthorizedInvocation: length (%d) exceeds remaining input length (%d)", l, il) } - s.SubInvocations = make([]SorobanAuthorizedInvocation, l) + if cap(s.SubInvocations) >= int(l) { + s.SubInvocations = s.SubInvocations[:l] + } else { + s.SubInvocations = make([]SorobanAuthorizedInvocation, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.SubInvocations[i].DecodeFrom(d, maxDepth) n += nTmp @@ -29817,11 +28969,8 @@ func (s SorobanAuthorizedInvocation) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanAuthorizedInvocation) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -29869,9 +29018,9 @@ func (s *SorobanAddressCredentials) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SorobanAddressCredentials)(nil) +var _ xdr.DecoderFrom = (*SorobanAddressCredentials)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SorobanAddressCredentials) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanAddressCredentials: %w", ErrMaxDecodingDepthReached) @@ -29912,11 +29061,8 @@ func (s SorobanAddressCredentials) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanAddressCredentials) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -29943,6 +29089,10 @@ const ( SorobanCredentialsTypeSorobanCredentialsSourceAccount SorobanCredentialsType = 0 SorobanCredentialsTypeSorobanCredentialsAddress SorobanCredentialsType = 1 ) +const ( + _SorobanCredentialsType_Min int32 = 0 + _SorobanCredentialsType_Max int32 = 1 +) var sorobanCredentialsTypeMap = map[int32]string{ 0: "SorobanCredentialsTypeSorobanCredentialsSourceAccount", @@ -29952,8 +29102,7 @@ var sorobanCredentialsTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for SorobanCredentialsType func (e SorobanCredentialsType) ValidEnum(v int32) bool { - _, ok := sorobanCredentialsTypeMap[v] - return ok + return v >= _SorobanCredentialsType_Min && v <= _SorobanCredentialsType_Max } // String returns the name of `e` @@ -29964,16 +29113,16 @@ func (e SorobanCredentialsType) String() string { // EncodeTo encodes this value using the Encoder. func (e SorobanCredentialsType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := sorobanCredentialsTypeMap[int32(e)]; !ok { + if int32(e) < _SorobanCredentialsType_Min || int32(e) > _SorobanCredentialsType_Max { return fmt.Errorf("'%d' is not a valid SorobanCredentialsType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*SorobanCredentialsType)(nil) +var _ xdr.DecoderFrom = (*SorobanCredentialsType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *SorobanCredentialsType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanCredentialsType: %w", ErrMaxDecodingDepthReached) @@ -29983,7 +29132,7 @@ func (e *SorobanCredentialsType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding SorobanCredentialsType: %w", err) } - if _, ok := sorobanCredentialsTypeMap[v]; !ok { + if v < _SorobanCredentialsType_Min || v > _SorobanCredentialsType_Max { return n, fmt.Errorf("'%d' is not a valid SorobanCredentialsType enum value", v) } *e = SorobanCredentialsType(v) @@ -30000,11 +29149,8 @@ func (s SorobanCredentialsType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanCredentialsType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -30070,25 +29216,19 @@ func NewSorobanCredentials(aType SorobanCredentialsType, value interface{}) (res // MustAddress retrieves the Address value from the union, // panicing if the value is not set. func (u SorobanCredentials) MustAddress() SorobanAddressCredentials { - val, ok := u.GetAddress() - - if !ok { - panic("arm Address is not set") + if SorobanCredentialsType(u.Type) == SorobanCredentialsTypeSorobanCredentialsAddress { + return *u.Address } - - return val + panic("arm Address is not set") } // GetAddress retrieves the Address value from the union, // returning ok if the union's switch indicated the value is valid. func (u SorobanCredentials) GetAddress() (result SorobanAddressCredentials, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Address" { + if SorobanCredentialsType(u.Type) == SorobanCredentialsTypeSorobanCredentialsAddress { result = *u.Address ok = true } - return } @@ -30111,9 +29251,9 @@ func (u SorobanCredentials) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (SorobanCredentialsType) switch value '%d' is not valid for union SorobanCredentials", u.Type) } -var _ decoderFrom = (*SorobanCredentials)(nil) +var _ xdr.DecoderFrom = (*SorobanCredentials)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *SorobanCredentials) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanCredentials: %w", ErrMaxDecodingDepthReached) @@ -30131,7 +29271,9 @@ func (u *SorobanCredentials) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err // Void return n, nil case SorobanCredentialsTypeSorobanCredentialsAddress: - u.Address = new(SorobanAddressCredentials) + if u.Address == nil { + u.Address = new(SorobanAddressCredentials) + } nTmp, err = (*u.Address).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -30152,11 +29294,8 @@ func (s SorobanCredentials) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanCredentials) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -30194,9 +29333,9 @@ func (s *SorobanAuthorizationEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SorobanAuthorizationEntry)(nil) +var _ xdr.DecoderFrom = (*SorobanAuthorizationEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SorobanAuthorizationEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanAuthorizationEntry: %w", ErrMaxDecodingDepthReached) @@ -30227,11 +29366,8 @@ func (s SorobanAuthorizationEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanAuthorizationEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -30264,9 +29400,9 @@ func (s SorobanAuthorizationEntries) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SorobanAuthorizationEntries)(nil) +var _ xdr.DecoderFrom = (*SorobanAuthorizationEntries)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SorobanAuthorizationEntries) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanAuthorizationEntries: %w", ErrMaxDecodingDepthReached) @@ -30280,12 +29416,17 @@ func (s *SorobanAuthorizationEntries) DecodeFrom(d *xdr.Decoder, maxDepth uint) if err != nil { return n, fmt.Errorf("decoding SorobanAuthorizationEntry: %w", err) } - (*s) = nil - if l > 0 { + if l == 0 { + (*s) = (*s)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding SorobanAuthorizationEntry: length (%d) exceeds remaining input length (%d)", l, il) } - (*s) = make([]SorobanAuthorizationEntry, l) + if cap((*s)) >= int(l) { + (*s) = (*s)[:l] + } else { + (*s) = make([]SorobanAuthorizationEntry, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*s)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -30307,11 +29448,8 @@ func (s SorobanAuthorizationEntries) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanAuthorizationEntries) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -30356,9 +29494,9 @@ func (s *InvokeHostFunctionOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*InvokeHostFunctionOp)(nil) +var _ xdr.DecoderFrom = (*InvokeHostFunctionOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *InvokeHostFunctionOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InvokeHostFunctionOp: %w", ErrMaxDecodingDepthReached) @@ -30377,12 +29515,17 @@ func (s *InvokeHostFunctionOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e if err != nil { return n, fmt.Errorf("decoding SorobanAuthorizationEntry: %w", err) } - s.Auth = nil - if l > 0 { + if l == 0 { + s.Auth = s.Auth[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding SorobanAuthorizationEntry: length (%d) exceeds remaining input length (%d)", l, il) } - s.Auth = make([]SorobanAuthorizationEntry, l) + if cap(s.Auth) >= int(l) { + s.Auth = s.Auth[:l] + } else { + s.Auth = make([]SorobanAuthorizationEntry, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Auth[i].DecodeFrom(d, maxDepth) n += nTmp @@ -30404,11 +29547,8 @@ func (s InvokeHostFunctionOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InvokeHostFunctionOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -30446,9 +29586,9 @@ func (s *ExtendFootprintTtlOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ExtendFootprintTtlOp)(nil) +var _ xdr.DecoderFrom = (*ExtendFootprintTtlOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ExtendFootprintTtlOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ExtendFootprintTtlOp: %w", ErrMaxDecodingDepthReached) @@ -30479,11 +29619,8 @@ func (s ExtendFootprintTtlOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ExtendFootprintTtlOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -30516,9 +29653,9 @@ func (s *RestoreFootprintOp) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*RestoreFootprintOp)(nil) +var _ xdr.DecoderFrom = (*RestoreFootprintOp)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *RestoreFootprintOp) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding RestoreFootprintOp: %w", ErrMaxDecodingDepthReached) @@ -30544,11 +29681,8 @@ func (s RestoreFootprintOp) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *RestoreFootprintOp) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -30908,625 +30042,475 @@ func NewOperationBody(aType OperationType, value interface{}) (result OperationB // MustCreateAccountOp retrieves the CreateAccountOp value from the union, // panicing if the value is not set. func (u OperationBody) MustCreateAccountOp() CreateAccountOp { - val, ok := u.GetCreateAccountOp() - - if !ok { - panic("arm CreateAccountOp is not set") + if OperationType(u.Type) == OperationTypeCreateAccount { + return *u.CreateAccountOp } - - return val + panic("arm CreateAccountOp is not set") } // GetCreateAccountOp retrieves the CreateAccountOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetCreateAccountOp() (result CreateAccountOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "CreateAccountOp" { + if OperationType(u.Type) == OperationTypeCreateAccount { result = *u.CreateAccountOp ok = true } - return } // MustPaymentOp retrieves the PaymentOp value from the union, // panicing if the value is not set. func (u OperationBody) MustPaymentOp() PaymentOp { - val, ok := u.GetPaymentOp() - - if !ok { - panic("arm PaymentOp is not set") + if OperationType(u.Type) == OperationTypePayment { + return *u.PaymentOp } - - return val + panic("arm PaymentOp is not set") } // GetPaymentOp retrieves the PaymentOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetPaymentOp() (result PaymentOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "PaymentOp" { + if OperationType(u.Type) == OperationTypePayment { result = *u.PaymentOp ok = true } - return } // MustPathPaymentStrictReceiveOp retrieves the PathPaymentStrictReceiveOp value from the union, // panicing if the value is not set. func (u OperationBody) MustPathPaymentStrictReceiveOp() PathPaymentStrictReceiveOp { - val, ok := u.GetPathPaymentStrictReceiveOp() - - if !ok { - panic("arm PathPaymentStrictReceiveOp is not set") + if OperationType(u.Type) == OperationTypePathPaymentStrictReceive { + return *u.PathPaymentStrictReceiveOp } - - return val + panic("arm PathPaymentStrictReceiveOp is not set") } // GetPathPaymentStrictReceiveOp retrieves the PathPaymentStrictReceiveOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetPathPaymentStrictReceiveOp() (result PathPaymentStrictReceiveOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "PathPaymentStrictReceiveOp" { + if OperationType(u.Type) == OperationTypePathPaymentStrictReceive { result = *u.PathPaymentStrictReceiveOp ok = true } - return } // MustManageSellOfferOp retrieves the ManageSellOfferOp value from the union, // panicing if the value is not set. func (u OperationBody) MustManageSellOfferOp() ManageSellOfferOp { - val, ok := u.GetManageSellOfferOp() - - if !ok { - panic("arm ManageSellOfferOp is not set") + if OperationType(u.Type) == OperationTypeManageSellOffer { + return *u.ManageSellOfferOp } - - return val + panic("arm ManageSellOfferOp is not set") } // GetManageSellOfferOp retrieves the ManageSellOfferOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetManageSellOfferOp() (result ManageSellOfferOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ManageSellOfferOp" { + if OperationType(u.Type) == OperationTypeManageSellOffer { result = *u.ManageSellOfferOp ok = true } - return } // MustCreatePassiveSellOfferOp retrieves the CreatePassiveSellOfferOp value from the union, // panicing if the value is not set. func (u OperationBody) MustCreatePassiveSellOfferOp() CreatePassiveSellOfferOp { - val, ok := u.GetCreatePassiveSellOfferOp() - - if !ok { - panic("arm CreatePassiveSellOfferOp is not set") + if OperationType(u.Type) == OperationTypeCreatePassiveSellOffer { + return *u.CreatePassiveSellOfferOp } - - return val + panic("arm CreatePassiveSellOfferOp is not set") } // GetCreatePassiveSellOfferOp retrieves the CreatePassiveSellOfferOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetCreatePassiveSellOfferOp() (result CreatePassiveSellOfferOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "CreatePassiveSellOfferOp" { + if OperationType(u.Type) == OperationTypeCreatePassiveSellOffer { result = *u.CreatePassiveSellOfferOp ok = true } - return } // MustSetOptionsOp retrieves the SetOptionsOp value from the union, // panicing if the value is not set. func (u OperationBody) MustSetOptionsOp() SetOptionsOp { - val, ok := u.GetSetOptionsOp() - - if !ok { - panic("arm SetOptionsOp is not set") + if OperationType(u.Type) == OperationTypeSetOptions { + return *u.SetOptionsOp } - - return val + panic("arm SetOptionsOp is not set") } // GetSetOptionsOp retrieves the SetOptionsOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetSetOptionsOp() (result SetOptionsOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "SetOptionsOp" { + if OperationType(u.Type) == OperationTypeSetOptions { result = *u.SetOptionsOp ok = true } - return } // MustChangeTrustOp retrieves the ChangeTrustOp value from the union, // panicing if the value is not set. func (u OperationBody) MustChangeTrustOp() ChangeTrustOp { - val, ok := u.GetChangeTrustOp() - - if !ok { - panic("arm ChangeTrustOp is not set") + if OperationType(u.Type) == OperationTypeChangeTrust { + return *u.ChangeTrustOp } - - return val + panic("arm ChangeTrustOp is not set") } // GetChangeTrustOp retrieves the ChangeTrustOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetChangeTrustOp() (result ChangeTrustOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ChangeTrustOp" { + if OperationType(u.Type) == OperationTypeChangeTrust { result = *u.ChangeTrustOp ok = true } - return } // MustAllowTrustOp retrieves the AllowTrustOp value from the union, // panicing if the value is not set. func (u OperationBody) MustAllowTrustOp() AllowTrustOp { - val, ok := u.GetAllowTrustOp() - - if !ok { - panic("arm AllowTrustOp is not set") + if OperationType(u.Type) == OperationTypeAllowTrust { + return *u.AllowTrustOp } - - return val + panic("arm AllowTrustOp is not set") } // GetAllowTrustOp retrieves the AllowTrustOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetAllowTrustOp() (result AllowTrustOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AllowTrustOp" { + if OperationType(u.Type) == OperationTypeAllowTrust { result = *u.AllowTrustOp ok = true } - return } // MustDestination retrieves the Destination value from the union, // panicing if the value is not set. func (u OperationBody) MustDestination() MuxedAccount { - val, ok := u.GetDestination() - - if !ok { - panic("arm Destination is not set") + if OperationType(u.Type) == OperationTypeAccountMerge { + return *u.Destination } - - return val + panic("arm Destination is not set") } // GetDestination retrieves the Destination value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetDestination() (result MuxedAccount, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Destination" { + if OperationType(u.Type) == OperationTypeAccountMerge { result = *u.Destination ok = true } - return } // MustManageDataOp retrieves the ManageDataOp value from the union, // panicing if the value is not set. func (u OperationBody) MustManageDataOp() ManageDataOp { - val, ok := u.GetManageDataOp() - - if !ok { - panic("arm ManageDataOp is not set") + if OperationType(u.Type) == OperationTypeManageData { + return *u.ManageDataOp } - - return val + panic("arm ManageDataOp is not set") } // GetManageDataOp retrieves the ManageDataOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetManageDataOp() (result ManageDataOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ManageDataOp" { + if OperationType(u.Type) == OperationTypeManageData { result = *u.ManageDataOp ok = true } - return } // MustBumpSequenceOp retrieves the BumpSequenceOp value from the union, // panicing if the value is not set. func (u OperationBody) MustBumpSequenceOp() BumpSequenceOp { - val, ok := u.GetBumpSequenceOp() - - if !ok { - panic("arm BumpSequenceOp is not set") + if OperationType(u.Type) == OperationTypeBumpSequence { + return *u.BumpSequenceOp } - - return val + panic("arm BumpSequenceOp is not set") } // GetBumpSequenceOp retrieves the BumpSequenceOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetBumpSequenceOp() (result BumpSequenceOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "BumpSequenceOp" { + if OperationType(u.Type) == OperationTypeBumpSequence { result = *u.BumpSequenceOp ok = true } - return } // MustManageBuyOfferOp retrieves the ManageBuyOfferOp value from the union, // panicing if the value is not set. func (u OperationBody) MustManageBuyOfferOp() ManageBuyOfferOp { - val, ok := u.GetManageBuyOfferOp() - - if !ok { - panic("arm ManageBuyOfferOp is not set") + if OperationType(u.Type) == OperationTypeManageBuyOffer { + return *u.ManageBuyOfferOp } - - return val + panic("arm ManageBuyOfferOp is not set") } // GetManageBuyOfferOp retrieves the ManageBuyOfferOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetManageBuyOfferOp() (result ManageBuyOfferOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ManageBuyOfferOp" { + if OperationType(u.Type) == OperationTypeManageBuyOffer { result = *u.ManageBuyOfferOp ok = true } - return } // MustPathPaymentStrictSendOp retrieves the PathPaymentStrictSendOp value from the union, // panicing if the value is not set. func (u OperationBody) MustPathPaymentStrictSendOp() PathPaymentStrictSendOp { - val, ok := u.GetPathPaymentStrictSendOp() - - if !ok { - panic("arm PathPaymentStrictSendOp is not set") + if OperationType(u.Type) == OperationTypePathPaymentStrictSend { + return *u.PathPaymentStrictSendOp } - - return val + panic("arm PathPaymentStrictSendOp is not set") } // GetPathPaymentStrictSendOp retrieves the PathPaymentStrictSendOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetPathPaymentStrictSendOp() (result PathPaymentStrictSendOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "PathPaymentStrictSendOp" { + if OperationType(u.Type) == OperationTypePathPaymentStrictSend { result = *u.PathPaymentStrictSendOp ok = true } - return } // MustCreateClaimableBalanceOp retrieves the CreateClaimableBalanceOp value from the union, // panicing if the value is not set. func (u OperationBody) MustCreateClaimableBalanceOp() CreateClaimableBalanceOp { - val, ok := u.GetCreateClaimableBalanceOp() - - if !ok { - panic("arm CreateClaimableBalanceOp is not set") + if OperationType(u.Type) == OperationTypeCreateClaimableBalance { + return *u.CreateClaimableBalanceOp } - - return val + panic("arm CreateClaimableBalanceOp is not set") } // GetCreateClaimableBalanceOp retrieves the CreateClaimableBalanceOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetCreateClaimableBalanceOp() (result CreateClaimableBalanceOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "CreateClaimableBalanceOp" { + if OperationType(u.Type) == OperationTypeCreateClaimableBalance { result = *u.CreateClaimableBalanceOp ok = true } - return } // MustClaimClaimableBalanceOp retrieves the ClaimClaimableBalanceOp value from the union, // panicing if the value is not set. func (u OperationBody) MustClaimClaimableBalanceOp() ClaimClaimableBalanceOp { - val, ok := u.GetClaimClaimableBalanceOp() - - if !ok { - panic("arm ClaimClaimableBalanceOp is not set") + if OperationType(u.Type) == OperationTypeClaimClaimableBalance { + return *u.ClaimClaimableBalanceOp } - - return val + panic("arm ClaimClaimableBalanceOp is not set") } // GetClaimClaimableBalanceOp retrieves the ClaimClaimableBalanceOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetClaimClaimableBalanceOp() (result ClaimClaimableBalanceOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ClaimClaimableBalanceOp" { + if OperationType(u.Type) == OperationTypeClaimClaimableBalance { result = *u.ClaimClaimableBalanceOp ok = true } - return } // MustBeginSponsoringFutureReservesOp retrieves the BeginSponsoringFutureReservesOp value from the union, // panicing if the value is not set. func (u OperationBody) MustBeginSponsoringFutureReservesOp() BeginSponsoringFutureReservesOp { - val, ok := u.GetBeginSponsoringFutureReservesOp() - - if !ok { - panic("arm BeginSponsoringFutureReservesOp is not set") + if OperationType(u.Type) == OperationTypeBeginSponsoringFutureReserves { + return *u.BeginSponsoringFutureReservesOp } - - return val + panic("arm BeginSponsoringFutureReservesOp is not set") } // GetBeginSponsoringFutureReservesOp retrieves the BeginSponsoringFutureReservesOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetBeginSponsoringFutureReservesOp() (result BeginSponsoringFutureReservesOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "BeginSponsoringFutureReservesOp" { + if OperationType(u.Type) == OperationTypeBeginSponsoringFutureReserves { result = *u.BeginSponsoringFutureReservesOp ok = true } - return } // MustRevokeSponsorshipOp retrieves the RevokeSponsorshipOp value from the union, // panicing if the value is not set. func (u OperationBody) MustRevokeSponsorshipOp() RevokeSponsorshipOp { - val, ok := u.GetRevokeSponsorshipOp() - - if !ok { - panic("arm RevokeSponsorshipOp is not set") + if OperationType(u.Type) == OperationTypeRevokeSponsorship { + return *u.RevokeSponsorshipOp } - - return val + panic("arm RevokeSponsorshipOp is not set") } // GetRevokeSponsorshipOp retrieves the RevokeSponsorshipOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetRevokeSponsorshipOp() (result RevokeSponsorshipOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "RevokeSponsorshipOp" { + if OperationType(u.Type) == OperationTypeRevokeSponsorship { result = *u.RevokeSponsorshipOp ok = true } - return } // MustClawbackOp retrieves the ClawbackOp value from the union, // panicing if the value is not set. func (u OperationBody) MustClawbackOp() ClawbackOp { - val, ok := u.GetClawbackOp() - - if !ok { - panic("arm ClawbackOp is not set") + if OperationType(u.Type) == OperationTypeClawback { + return *u.ClawbackOp } - - return val + panic("arm ClawbackOp is not set") } // GetClawbackOp retrieves the ClawbackOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetClawbackOp() (result ClawbackOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ClawbackOp" { + if OperationType(u.Type) == OperationTypeClawback { result = *u.ClawbackOp ok = true } - return } // MustClawbackClaimableBalanceOp retrieves the ClawbackClaimableBalanceOp value from the union, // panicing if the value is not set. func (u OperationBody) MustClawbackClaimableBalanceOp() ClawbackClaimableBalanceOp { - val, ok := u.GetClawbackClaimableBalanceOp() - - if !ok { - panic("arm ClawbackClaimableBalanceOp is not set") + if OperationType(u.Type) == OperationTypeClawbackClaimableBalance { + return *u.ClawbackClaimableBalanceOp } - - return val + panic("arm ClawbackClaimableBalanceOp is not set") } // GetClawbackClaimableBalanceOp retrieves the ClawbackClaimableBalanceOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetClawbackClaimableBalanceOp() (result ClawbackClaimableBalanceOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ClawbackClaimableBalanceOp" { + if OperationType(u.Type) == OperationTypeClawbackClaimableBalance { result = *u.ClawbackClaimableBalanceOp ok = true } - return } // MustSetTrustLineFlagsOp retrieves the SetTrustLineFlagsOp value from the union, // panicing if the value is not set. func (u OperationBody) MustSetTrustLineFlagsOp() SetTrustLineFlagsOp { - val, ok := u.GetSetTrustLineFlagsOp() - - if !ok { - panic("arm SetTrustLineFlagsOp is not set") + if OperationType(u.Type) == OperationTypeSetTrustLineFlags { + return *u.SetTrustLineFlagsOp } - - return val + panic("arm SetTrustLineFlagsOp is not set") } // GetSetTrustLineFlagsOp retrieves the SetTrustLineFlagsOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetSetTrustLineFlagsOp() (result SetTrustLineFlagsOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "SetTrustLineFlagsOp" { + if OperationType(u.Type) == OperationTypeSetTrustLineFlags { result = *u.SetTrustLineFlagsOp ok = true } - return } // MustLiquidityPoolDepositOp retrieves the LiquidityPoolDepositOp value from the union, // panicing if the value is not set. func (u OperationBody) MustLiquidityPoolDepositOp() LiquidityPoolDepositOp { - val, ok := u.GetLiquidityPoolDepositOp() - - if !ok { - panic("arm LiquidityPoolDepositOp is not set") + if OperationType(u.Type) == OperationTypeLiquidityPoolDeposit { + return *u.LiquidityPoolDepositOp } - - return val + panic("arm LiquidityPoolDepositOp is not set") } // GetLiquidityPoolDepositOp retrieves the LiquidityPoolDepositOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetLiquidityPoolDepositOp() (result LiquidityPoolDepositOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LiquidityPoolDepositOp" { + if OperationType(u.Type) == OperationTypeLiquidityPoolDeposit { result = *u.LiquidityPoolDepositOp ok = true } - return } // MustLiquidityPoolWithdrawOp retrieves the LiquidityPoolWithdrawOp value from the union, // panicing if the value is not set. func (u OperationBody) MustLiquidityPoolWithdrawOp() LiquidityPoolWithdrawOp { - val, ok := u.GetLiquidityPoolWithdrawOp() - - if !ok { - panic("arm LiquidityPoolWithdrawOp is not set") + if OperationType(u.Type) == OperationTypeLiquidityPoolWithdraw { + return *u.LiquidityPoolWithdrawOp } - - return val + panic("arm LiquidityPoolWithdrawOp is not set") } // GetLiquidityPoolWithdrawOp retrieves the LiquidityPoolWithdrawOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetLiquidityPoolWithdrawOp() (result LiquidityPoolWithdrawOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LiquidityPoolWithdrawOp" { + if OperationType(u.Type) == OperationTypeLiquidityPoolWithdraw { result = *u.LiquidityPoolWithdrawOp ok = true } - return } // MustInvokeHostFunctionOp retrieves the InvokeHostFunctionOp value from the union, // panicing if the value is not set. func (u OperationBody) MustInvokeHostFunctionOp() InvokeHostFunctionOp { - val, ok := u.GetInvokeHostFunctionOp() - - if !ok { - panic("arm InvokeHostFunctionOp is not set") + if OperationType(u.Type) == OperationTypeInvokeHostFunction { + return *u.InvokeHostFunctionOp } - - return val + panic("arm InvokeHostFunctionOp is not set") } // GetInvokeHostFunctionOp retrieves the InvokeHostFunctionOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetInvokeHostFunctionOp() (result InvokeHostFunctionOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "InvokeHostFunctionOp" { + if OperationType(u.Type) == OperationTypeInvokeHostFunction { result = *u.InvokeHostFunctionOp ok = true } - return } // MustExtendFootprintTtlOp retrieves the ExtendFootprintTtlOp value from the union, // panicing if the value is not set. func (u OperationBody) MustExtendFootprintTtlOp() ExtendFootprintTtlOp { - val, ok := u.GetExtendFootprintTtlOp() - - if !ok { - panic("arm ExtendFootprintTtlOp is not set") + if OperationType(u.Type) == OperationTypeExtendFootprintTtl { + return *u.ExtendFootprintTtlOp } - - return val + panic("arm ExtendFootprintTtlOp is not set") } // GetExtendFootprintTtlOp retrieves the ExtendFootprintTtlOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetExtendFootprintTtlOp() (result ExtendFootprintTtlOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ExtendFootprintTtlOp" { + if OperationType(u.Type) == OperationTypeExtendFootprintTtl { result = *u.ExtendFootprintTtlOp ok = true } - return } // MustRestoreFootprintOp retrieves the RestoreFootprintOp value from the union, // panicing if the value is not set. func (u OperationBody) MustRestoreFootprintOp() RestoreFootprintOp { - val, ok := u.GetRestoreFootprintOp() - - if !ok { - panic("arm RestoreFootprintOp is not set") + if OperationType(u.Type) == OperationTypeRestoreFootprint { + return *u.RestoreFootprintOp } - - return val + panic("arm RestoreFootprintOp is not set") } // GetRestoreFootprintOp retrieves the RestoreFootprintOp value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationBody) GetRestoreFootprintOp() (result RestoreFootprintOp, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "RestoreFootprintOp" { + if OperationType(u.Type) == OperationTypeRestoreFootprint { result = *u.RestoreFootprintOp ok = true } - return } @@ -31672,9 +30656,9 @@ func (u OperationBody) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (OperationType) switch value '%d' is not valid for union OperationBody", u.Type) } -var _ decoderFrom = (*OperationBody)(nil) +var _ xdr.DecoderFrom = (*OperationBody)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding OperationBody: %w", ErrMaxDecodingDepthReached) @@ -31689,7 +30673,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch OperationType(u.Type) { case OperationTypeCreateAccount: - u.CreateAccountOp = new(CreateAccountOp) + if u.CreateAccountOp == nil { + u.CreateAccountOp = new(CreateAccountOp) + } nTmp, err = (*u.CreateAccountOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31697,7 +30683,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypePayment: - u.PaymentOp = new(PaymentOp) + if u.PaymentOp == nil { + u.PaymentOp = new(PaymentOp) + } nTmp, err = (*u.PaymentOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31705,7 +30693,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypePathPaymentStrictReceive: - u.PathPaymentStrictReceiveOp = new(PathPaymentStrictReceiveOp) + if u.PathPaymentStrictReceiveOp == nil { + u.PathPaymentStrictReceiveOp = new(PathPaymentStrictReceiveOp) + } nTmp, err = (*u.PathPaymentStrictReceiveOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31713,7 +30703,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeManageSellOffer: - u.ManageSellOfferOp = new(ManageSellOfferOp) + if u.ManageSellOfferOp == nil { + u.ManageSellOfferOp = new(ManageSellOfferOp) + } nTmp, err = (*u.ManageSellOfferOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31721,7 +30713,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeCreatePassiveSellOffer: - u.CreatePassiveSellOfferOp = new(CreatePassiveSellOfferOp) + if u.CreatePassiveSellOfferOp == nil { + u.CreatePassiveSellOfferOp = new(CreatePassiveSellOfferOp) + } nTmp, err = (*u.CreatePassiveSellOfferOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31729,7 +30723,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeSetOptions: - u.SetOptionsOp = new(SetOptionsOp) + if u.SetOptionsOp == nil { + u.SetOptionsOp = new(SetOptionsOp) + } nTmp, err = (*u.SetOptionsOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31737,7 +30733,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeChangeTrust: - u.ChangeTrustOp = new(ChangeTrustOp) + if u.ChangeTrustOp == nil { + u.ChangeTrustOp = new(ChangeTrustOp) + } nTmp, err = (*u.ChangeTrustOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31745,7 +30743,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeAllowTrust: - u.AllowTrustOp = new(AllowTrustOp) + if u.AllowTrustOp == nil { + u.AllowTrustOp = new(AllowTrustOp) + } nTmp, err = (*u.AllowTrustOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31753,7 +30753,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeAccountMerge: - u.Destination = new(MuxedAccount) + if u.Destination == nil { + u.Destination = new(MuxedAccount) + } nTmp, err = (*u.Destination).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31764,7 +30766,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { // Void return n, nil case OperationTypeManageData: - u.ManageDataOp = new(ManageDataOp) + if u.ManageDataOp == nil { + u.ManageDataOp = new(ManageDataOp) + } nTmp, err = (*u.ManageDataOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31772,7 +30776,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeBumpSequence: - u.BumpSequenceOp = new(BumpSequenceOp) + if u.BumpSequenceOp == nil { + u.BumpSequenceOp = new(BumpSequenceOp) + } nTmp, err = (*u.BumpSequenceOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31780,7 +30786,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeManageBuyOffer: - u.ManageBuyOfferOp = new(ManageBuyOfferOp) + if u.ManageBuyOfferOp == nil { + u.ManageBuyOfferOp = new(ManageBuyOfferOp) + } nTmp, err = (*u.ManageBuyOfferOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31788,7 +30796,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypePathPaymentStrictSend: - u.PathPaymentStrictSendOp = new(PathPaymentStrictSendOp) + if u.PathPaymentStrictSendOp == nil { + u.PathPaymentStrictSendOp = new(PathPaymentStrictSendOp) + } nTmp, err = (*u.PathPaymentStrictSendOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31796,7 +30806,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeCreateClaimableBalance: - u.CreateClaimableBalanceOp = new(CreateClaimableBalanceOp) + if u.CreateClaimableBalanceOp == nil { + u.CreateClaimableBalanceOp = new(CreateClaimableBalanceOp) + } nTmp, err = (*u.CreateClaimableBalanceOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31804,7 +30816,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeClaimClaimableBalance: - u.ClaimClaimableBalanceOp = new(ClaimClaimableBalanceOp) + if u.ClaimClaimableBalanceOp == nil { + u.ClaimClaimableBalanceOp = new(ClaimClaimableBalanceOp) + } nTmp, err = (*u.ClaimClaimableBalanceOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31812,7 +30826,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeBeginSponsoringFutureReserves: - u.BeginSponsoringFutureReservesOp = new(BeginSponsoringFutureReservesOp) + if u.BeginSponsoringFutureReservesOp == nil { + u.BeginSponsoringFutureReservesOp = new(BeginSponsoringFutureReservesOp) + } nTmp, err = (*u.BeginSponsoringFutureReservesOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31823,7 +30839,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { // Void return n, nil case OperationTypeRevokeSponsorship: - u.RevokeSponsorshipOp = new(RevokeSponsorshipOp) + if u.RevokeSponsorshipOp == nil { + u.RevokeSponsorshipOp = new(RevokeSponsorshipOp) + } nTmp, err = (*u.RevokeSponsorshipOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31831,7 +30849,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeClawback: - u.ClawbackOp = new(ClawbackOp) + if u.ClawbackOp == nil { + u.ClawbackOp = new(ClawbackOp) + } nTmp, err = (*u.ClawbackOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31839,7 +30859,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeClawbackClaimableBalance: - u.ClawbackClaimableBalanceOp = new(ClawbackClaimableBalanceOp) + if u.ClawbackClaimableBalanceOp == nil { + u.ClawbackClaimableBalanceOp = new(ClawbackClaimableBalanceOp) + } nTmp, err = (*u.ClawbackClaimableBalanceOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31847,7 +30869,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeSetTrustLineFlags: - u.SetTrustLineFlagsOp = new(SetTrustLineFlagsOp) + if u.SetTrustLineFlagsOp == nil { + u.SetTrustLineFlagsOp = new(SetTrustLineFlagsOp) + } nTmp, err = (*u.SetTrustLineFlagsOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31855,7 +30879,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeLiquidityPoolDeposit: - u.LiquidityPoolDepositOp = new(LiquidityPoolDepositOp) + if u.LiquidityPoolDepositOp == nil { + u.LiquidityPoolDepositOp = new(LiquidityPoolDepositOp) + } nTmp, err = (*u.LiquidityPoolDepositOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31863,7 +30889,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeLiquidityPoolWithdraw: - u.LiquidityPoolWithdrawOp = new(LiquidityPoolWithdrawOp) + if u.LiquidityPoolWithdrawOp == nil { + u.LiquidityPoolWithdrawOp = new(LiquidityPoolWithdrawOp) + } nTmp, err = (*u.LiquidityPoolWithdrawOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31871,7 +30899,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeInvokeHostFunction: - u.InvokeHostFunctionOp = new(InvokeHostFunctionOp) + if u.InvokeHostFunctionOp == nil { + u.InvokeHostFunctionOp = new(InvokeHostFunctionOp) + } nTmp, err = (*u.InvokeHostFunctionOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31879,7 +30909,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeExtendFootprintTtl: - u.ExtendFootprintTtlOp = new(ExtendFootprintTtlOp) + if u.ExtendFootprintTtlOp == nil { + u.ExtendFootprintTtlOp = new(ExtendFootprintTtlOp) + } nTmp, err = (*u.ExtendFootprintTtlOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31887,7 +30919,9 @@ func (u *OperationBody) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case OperationTypeRestoreFootprint: - u.RestoreFootprintOp = new(RestoreFootprintOp) + if u.RestoreFootprintOp == nil { + u.RestoreFootprintOp = new(RestoreFootprintOp) + } nTmp, err = (*u.RestoreFootprintOp).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -31908,11 +30942,8 @@ func (s OperationBody) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *OperationBody) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -32016,9 +31047,9 @@ func (s *Operation) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Operation)(nil) +var _ xdr.DecoderFrom = (*Operation)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Operation) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Operation: %w", ErrMaxDecodingDepthReached) @@ -32059,11 +31090,8 @@ func (s Operation) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Operation) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -32106,9 +31134,9 @@ func (s *HashIdPreimageOperationId) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*HashIdPreimageOperationId)(nil) +var _ xdr.DecoderFrom = (*HashIdPreimageOperationId)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *HashIdPreimageOperationId) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding HashIdPreimageOperationId: %w", ErrMaxDecodingDepthReached) @@ -32144,11 +31172,8 @@ func (s HashIdPreimageOperationId) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *HashIdPreimageOperationId) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -32201,9 +31226,9 @@ func (s *HashIdPreimageRevokeId) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*HashIdPreimageRevokeId)(nil) +var _ xdr.DecoderFrom = (*HashIdPreimageRevokeId)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *HashIdPreimageRevokeId) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding HashIdPreimageRevokeId: %w", ErrMaxDecodingDepthReached) @@ -32249,11 +31274,8 @@ func (s HashIdPreimageRevokeId) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *HashIdPreimageRevokeId) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -32291,9 +31313,9 @@ func (s *HashIdPreimageContractId) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*HashIdPreimageContractId)(nil) +var _ xdr.DecoderFrom = (*HashIdPreimageContractId)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *HashIdPreimageContractId) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding HashIdPreimageContractId: %w", ErrMaxDecodingDepthReached) @@ -32324,11 +31346,8 @@ func (s HashIdPreimageContractId) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *HashIdPreimageContractId) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -32376,9 +31395,9 @@ func (s *HashIdPreimageSorobanAuthorization) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*HashIdPreimageSorobanAuthorization)(nil) +var _ xdr.DecoderFrom = (*HashIdPreimageSorobanAuthorization)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *HashIdPreimageSorobanAuthorization) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding HashIdPreimageSorobanAuthorization: %w", ErrMaxDecodingDepthReached) @@ -32419,11 +31438,8 @@ func (s HashIdPreimageSorobanAuthorization) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *HashIdPreimageSorobanAuthorization) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -32541,100 +31557,76 @@ func NewHashIdPreimage(aType EnvelopeType, value interface{}) (result HashIdPrei // MustOperationId retrieves the OperationId value from the union, // panicing if the value is not set. func (u HashIdPreimage) MustOperationId() HashIdPreimageOperationId { - val, ok := u.GetOperationId() - - if !ok { - panic("arm OperationId is not set") + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeOpId { + return *u.OperationId } - - return val + panic("arm OperationId is not set") } // GetOperationId retrieves the OperationId value from the union, // returning ok if the union's switch indicated the value is valid. func (u HashIdPreimage) GetOperationId() (result HashIdPreimageOperationId, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "OperationId" { + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeOpId { result = *u.OperationId ok = true } - return } // MustRevokeId retrieves the RevokeId value from the union, // panicing if the value is not set. func (u HashIdPreimage) MustRevokeId() HashIdPreimageRevokeId { - val, ok := u.GetRevokeId() - - if !ok { - panic("arm RevokeId is not set") + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypePoolRevokeOpId { + return *u.RevokeId } - - return val + panic("arm RevokeId is not set") } // GetRevokeId retrieves the RevokeId value from the union, // returning ok if the union's switch indicated the value is valid. func (u HashIdPreimage) GetRevokeId() (result HashIdPreimageRevokeId, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "RevokeId" { + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypePoolRevokeOpId { result = *u.RevokeId ok = true } - return } // MustContractId retrieves the ContractId value from the union, // panicing if the value is not set. func (u HashIdPreimage) MustContractId() HashIdPreimageContractId { - val, ok := u.GetContractId() - - if !ok { - panic("arm ContractId is not set") + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeContractId { + return *u.ContractId } - - return val + panic("arm ContractId is not set") } // GetContractId retrieves the ContractId value from the union, // returning ok if the union's switch indicated the value is valid. func (u HashIdPreimage) GetContractId() (result HashIdPreimageContractId, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ContractId" { + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeContractId { result = *u.ContractId ok = true } - return } // MustSorobanAuthorization retrieves the SorobanAuthorization value from the union, // panicing if the value is not set. func (u HashIdPreimage) MustSorobanAuthorization() HashIdPreimageSorobanAuthorization { - val, ok := u.GetSorobanAuthorization() - - if !ok { - panic("arm SorobanAuthorization is not set") + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeSorobanAuthorization { + return *u.SorobanAuthorization } - - return val + panic("arm SorobanAuthorization is not set") } // GetSorobanAuthorization retrieves the SorobanAuthorization value from the union, // returning ok if the union's switch indicated the value is valid. func (u HashIdPreimage) GetSorobanAuthorization() (result HashIdPreimageSorobanAuthorization, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "SorobanAuthorization" { + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeSorobanAuthorization { result = *u.SorobanAuthorization ok = true } - return } @@ -32669,9 +31661,9 @@ func (u HashIdPreimage) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (EnvelopeType) switch value '%d' is not valid for union HashIdPreimage", u.Type) } -var _ decoderFrom = (*HashIdPreimage)(nil) +var _ xdr.DecoderFrom = (*HashIdPreimage)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *HashIdPreimage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding HashIdPreimage: %w", ErrMaxDecodingDepthReached) @@ -32686,7 +31678,9 @@ func (u *HashIdPreimage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } switch EnvelopeType(u.Type) { case EnvelopeTypeEnvelopeTypeOpId: - u.OperationId = new(HashIdPreimageOperationId) + if u.OperationId == nil { + u.OperationId = new(HashIdPreimageOperationId) + } nTmp, err = (*u.OperationId).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -32694,7 +31688,9 @@ func (u *HashIdPreimage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case EnvelopeTypeEnvelopeTypePoolRevokeOpId: - u.RevokeId = new(HashIdPreimageRevokeId) + if u.RevokeId == nil { + u.RevokeId = new(HashIdPreimageRevokeId) + } nTmp, err = (*u.RevokeId).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -32702,7 +31698,9 @@ func (u *HashIdPreimage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case EnvelopeTypeEnvelopeTypeContractId: - u.ContractId = new(HashIdPreimageContractId) + if u.ContractId == nil { + u.ContractId = new(HashIdPreimageContractId) + } nTmp, err = (*u.ContractId).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -32710,7 +31708,9 @@ func (u *HashIdPreimage) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } return n, nil case EnvelopeTypeEnvelopeTypeSorobanAuthorization: - u.SorobanAuthorization = new(HashIdPreimageSorobanAuthorization) + if u.SorobanAuthorization == nil { + u.SorobanAuthorization = new(HashIdPreimageSorobanAuthorization) + } nTmp, err = (*u.SorobanAuthorization).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -32731,11 +31731,8 @@ func (s HashIdPreimage) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *HashIdPreimage) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -32768,6 +31765,10 @@ const ( MemoTypeMemoHash MemoType = 3 MemoTypeMemoReturn MemoType = 4 ) +const ( + _MemoType_Min int32 = 0 + _MemoType_Max int32 = 4 +) var memoTypeMap = map[int32]string{ 0: "MemoTypeMemoNone", @@ -32780,8 +31781,7 @@ var memoTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for MemoType func (e MemoType) ValidEnum(v int32) bool { - _, ok := memoTypeMap[v] - return ok + return v >= _MemoType_Min && v <= _MemoType_Max } // String returns the name of `e` @@ -32792,16 +31792,16 @@ func (e MemoType) String() string { // EncodeTo encodes this value using the Encoder. func (e MemoType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := memoTypeMap[int32(e)]; !ok { + if int32(e) < _MemoType_Min || int32(e) > _MemoType_Max { return fmt.Errorf("'%d' is not a valid MemoType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*MemoType)(nil) +var _ xdr.DecoderFrom = (*MemoType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *MemoType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding MemoType: %w", ErrMaxDecodingDepthReached) @@ -32811,7 +31811,7 @@ func (e *MemoType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding MemoType: %w", err) } - if _, ok := memoTypeMap[v]; !ok { + if v < _MemoType_Min || v > _MemoType_Max { return n, fmt.Errorf("'%d' is not a valid MemoType enum value", v) } *e = MemoType(v) @@ -32828,11 +31828,8 @@ func (s MemoType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *MemoType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -32864,7 +31861,7 @@ var _ xdrType = (*MemoType)(nil) type Memo struct { Type MemoType Text *string `xdrmaxsize:"28"` - Id *Uint64 + Id Uint64 Hash *Hash RetHash *Hash } @@ -32912,7 +31909,7 @@ func NewMemo(aType MemoType, value interface{}) (result Memo, err error) { err = errors.New("invalid value, must be Uint64") return } - result.Id = &tv + result.Id = tv case MemoTypeMemoHash: tv, ok := value.(Hash) if !ok { @@ -32934,100 +31931,76 @@ func NewMemo(aType MemoType, value interface{}) (result Memo, err error) { // MustText retrieves the Text value from the union, // panicing if the value is not set. func (u Memo) MustText() string { - val, ok := u.GetText() - - if !ok { - panic("arm Text is not set") + if MemoType(u.Type) == MemoTypeMemoText { + return *u.Text } - - return val + panic("arm Text is not set") } // GetText retrieves the Text value from the union, // returning ok if the union's switch indicated the value is valid. func (u Memo) GetText() (result string, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Text" { + if MemoType(u.Type) == MemoTypeMemoText { result = *u.Text ok = true } - return } // MustId retrieves the Id value from the union, // panicing if the value is not set. func (u Memo) MustId() Uint64 { - val, ok := u.GetId() - - if !ok { - panic("arm Id is not set") + if MemoType(u.Type) == MemoTypeMemoId { + return u.Id } - - return val + panic("arm Id is not set") } // GetId retrieves the Id value from the union, // returning ok if the union's switch indicated the value is valid. func (u Memo) GetId() (result Uint64, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Id" { - result = *u.Id + if MemoType(u.Type) == MemoTypeMemoId { + result = u.Id ok = true } - return } // MustHash retrieves the Hash value from the union, // panicing if the value is not set. func (u Memo) MustHash() Hash { - val, ok := u.GetHash() - - if !ok { - panic("arm Hash is not set") + if MemoType(u.Type) == MemoTypeMemoHash { + return *u.Hash } - - return val + panic("arm Hash is not set") } // GetHash retrieves the Hash value from the union, // returning ok if the union's switch indicated the value is valid. func (u Memo) GetHash() (result Hash, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Hash" { + if MemoType(u.Type) == MemoTypeMemoHash { result = *u.Hash ok = true } - return } // MustRetHash retrieves the RetHash value from the union, // panicing if the value is not set. func (u Memo) MustRetHash() Hash { - val, ok := u.GetRetHash() - - if !ok { - panic("arm RetHash is not set") + if MemoType(u.Type) == MemoTypeMemoReturn { + return *u.RetHash } - - return val + panic("arm RetHash is not set") } // GetRetHash retrieves the RetHash value from the union, // returning ok if the union's switch indicated the value is valid. func (u Memo) GetRetHash() (result Hash, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "RetHash" { + if MemoType(u.Type) == MemoTypeMemoReturn { result = *u.RetHash ok = true } - return } @@ -33047,7 +32020,7 @@ func (u Memo) EncodeTo(e *xdr.Encoder) error { } return nil case MemoTypeMemoId: - if err = (*u.Id).EncodeTo(e); err != nil { + if err = u.Id.EncodeTo(e); err != nil { return err } return nil @@ -33065,9 +32038,9 @@ func (u Memo) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (MemoType) switch value '%d' is not valid for union Memo", u.Type) } -var _ decoderFrom = (*Memo)(nil) +var _ xdr.DecoderFrom = (*Memo)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *Memo) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Memo: %w", ErrMaxDecodingDepthReached) @@ -33085,7 +32058,9 @@ func (u *Memo) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { // Void return n, nil case MemoTypeMemoText: - u.Text = new(string) + if u.Text == nil { + u.Text = new(string) + } (*u.Text), nTmp, err = d.DecodeString(28) n += nTmp if err != nil { @@ -33093,15 +32068,16 @@ func (u *Memo) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case MemoTypeMemoId: - u.Id = new(Uint64) - nTmp, err = (*u.Id).DecodeFrom(d, maxDepth) + nTmp, err = u.Id.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint64: %w", err) } return n, nil case MemoTypeMemoHash: - u.Hash = new(Hash) + if u.Hash == nil { + u.Hash = new(Hash) + } nTmp, err = (*u.Hash).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -33109,7 +32085,9 @@ func (u *Memo) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case MemoTypeMemoReturn: - u.RetHash = new(Hash) + if u.RetHash == nil { + u.RetHash = new(Hash) + } nTmp, err = (*u.RetHash).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -33130,11 +32108,8 @@ func (s Memo) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Memo) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -33172,9 +32147,9 @@ func (s *TimeBounds) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TimeBounds)(nil) +var _ xdr.DecoderFrom = (*TimeBounds)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TimeBounds) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TimeBounds: %w", ErrMaxDecodingDepthReached) @@ -33205,11 +32180,8 @@ func (s TimeBounds) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TimeBounds) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -33247,9 +32219,9 @@ func (s *LedgerBounds) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerBounds)(nil) +var _ xdr.DecoderFrom = (*LedgerBounds)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerBounds) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerBounds: %w", ErrMaxDecodingDepthReached) @@ -33280,11 +32252,8 @@ func (s LedgerBounds) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerBounds) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -33385,9 +32354,9 @@ func (s *PreconditionsV2) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*PreconditionsV2)(nil) +var _ xdr.DecoderFrom = (*PreconditionsV2)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *PreconditionsV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PreconditionsV2: %w", ErrMaxDecodingDepthReached) @@ -33457,12 +32426,17 @@ func (s *PreconditionsV2) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if l > 2 { return n, fmt.Errorf("decoding SignerKey: data size (%d) exceeds size limit (2)", l) } - s.ExtraSigners = nil - if l > 0 { + if l == 0 { + s.ExtraSigners = s.ExtraSigners[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding SignerKey: length (%d) exceeds remaining input length (%d)", l, il) } - s.ExtraSigners = make([]SignerKey, l) + if cap(s.ExtraSigners) >= int(l) { + s.ExtraSigners = s.ExtraSigners[:l] + } else { + s.ExtraSigners = make([]SignerKey, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ExtraSigners[i].DecodeFrom(d, maxDepth) n += nTmp @@ -33484,11 +32458,8 @@ func (s PreconditionsV2) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PreconditionsV2) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -33517,6 +32488,10 @@ const ( PreconditionTypePrecondTime PreconditionType = 1 PreconditionTypePrecondV2 PreconditionType = 2 ) +const ( + _PreconditionType_Min int32 = 0 + _PreconditionType_Max int32 = 2 +) var preconditionTypeMap = map[int32]string{ 0: "PreconditionTypePrecondNone", @@ -33527,8 +32502,7 @@ var preconditionTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for PreconditionType func (e PreconditionType) ValidEnum(v int32) bool { - _, ok := preconditionTypeMap[v] - return ok + return v >= _PreconditionType_Min && v <= _PreconditionType_Max } // String returns the name of `e` @@ -33539,16 +32513,16 @@ func (e PreconditionType) String() string { // EncodeTo encodes this value using the Encoder. func (e PreconditionType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := preconditionTypeMap[int32(e)]; !ok { + if int32(e) < _PreconditionType_Min || int32(e) > _PreconditionType_Max { return fmt.Errorf("'%d' is not a valid PreconditionType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*PreconditionType)(nil) +var _ xdr.DecoderFrom = (*PreconditionType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *PreconditionType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PreconditionType: %w", ErrMaxDecodingDepthReached) @@ -33558,7 +32532,7 @@ func (e *PreconditionType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error if err != nil { return n, fmt.Errorf("decoding PreconditionType: %w", err) } - if _, ok := preconditionTypeMap[v]; !ok { + if v < _PreconditionType_Min || v > _PreconditionType_Max { return n, fmt.Errorf("'%d' is not a valid PreconditionType enum value", v) } *e = PreconditionType(v) @@ -33575,11 +32549,8 @@ func (s PreconditionType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PreconditionType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -33657,50 +32628,38 @@ func NewPreconditions(aType PreconditionType, value interface{}) (result Precond // MustTimeBounds retrieves the TimeBounds value from the union, // panicing if the value is not set. func (u Preconditions) MustTimeBounds() TimeBounds { - val, ok := u.GetTimeBounds() - - if !ok { - panic("arm TimeBounds is not set") + if PreconditionType(u.Type) == PreconditionTypePrecondTime { + return *u.TimeBounds } - - return val + panic("arm TimeBounds is not set") } // GetTimeBounds retrieves the TimeBounds value from the union, // returning ok if the union's switch indicated the value is valid. func (u Preconditions) GetTimeBounds() (result TimeBounds, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "TimeBounds" { + if PreconditionType(u.Type) == PreconditionTypePrecondTime { result = *u.TimeBounds ok = true } - return } // MustV2 retrieves the V2 value from the union, // panicing if the value is not set. func (u Preconditions) MustV2() PreconditionsV2 { - val, ok := u.GetV2() - - if !ok { - panic("arm V2 is not set") + if PreconditionType(u.Type) == PreconditionTypePrecondV2 { + return *u.V2 } - - return val + panic("arm V2 is not set") } // GetV2 retrieves the V2 value from the union, // returning ok if the union's switch indicated the value is valid. func (u Preconditions) GetV2() (result PreconditionsV2, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "V2" { + if PreconditionType(u.Type) == PreconditionTypePrecondV2 { result = *u.V2 ok = true } - return } @@ -33728,9 +32687,9 @@ func (u Preconditions) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (PreconditionType) switch value '%d' is not valid for union Preconditions", u.Type) } -var _ decoderFrom = (*Preconditions)(nil) +var _ xdr.DecoderFrom = (*Preconditions)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *Preconditions) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Preconditions: %w", ErrMaxDecodingDepthReached) @@ -33748,7 +32707,9 @@ func (u *Preconditions) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { // Void return n, nil case PreconditionTypePrecondTime: - u.TimeBounds = new(TimeBounds) + if u.TimeBounds == nil { + u.TimeBounds = new(TimeBounds) + } nTmp, err = (*u.TimeBounds).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -33756,7 +32717,9 @@ func (u *Preconditions) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case PreconditionTypePrecondV2: - u.V2 = new(PreconditionsV2) + if u.V2 == nil { + u.V2 = new(PreconditionsV2) + } nTmp, err = (*u.V2).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -33777,11 +32740,8 @@ func (s Preconditions) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Preconditions) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -33829,9 +32789,9 @@ func (s *LedgerFootprint) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerFootprint)(nil) +var _ xdr.DecoderFrom = (*LedgerFootprint)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerFootprint) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerFootprint: %w", ErrMaxDecodingDepthReached) @@ -33845,12 +32805,17 @@ func (s *LedgerFootprint) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding LedgerKey: %w", err) } - s.ReadOnly = nil - if l > 0 { + if l == 0 { + s.ReadOnly = s.ReadOnly[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding LedgerKey: length (%d) exceeds remaining input length (%d)", l, il) } - s.ReadOnly = make([]LedgerKey, l) + if cap(s.ReadOnly) >= int(l) { + s.ReadOnly = s.ReadOnly[:l] + } else { + s.ReadOnly = make([]LedgerKey, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ReadOnly[i].DecodeFrom(d, maxDepth) n += nTmp @@ -33864,12 +32829,17 @@ func (s *LedgerFootprint) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding LedgerKey: %w", err) } - s.ReadWrite = nil - if l > 0 { + if l == 0 { + s.ReadWrite = s.ReadWrite[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding LedgerKey: length (%d) exceeds remaining input length (%d)", l, il) } - s.ReadWrite = make([]LedgerKey, l) + if cap(s.ReadWrite) >= int(l) { + s.ReadWrite = s.ReadWrite[:l] + } else { + s.ReadWrite = make([]LedgerKey, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ReadWrite[i].DecodeFrom(d, maxDepth) n += nTmp @@ -33891,11 +32861,8 @@ func (s LedgerFootprint) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerFootprint) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -33948,9 +32915,9 @@ func (s *SorobanResources) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SorobanResources)(nil) +var _ xdr.DecoderFrom = (*SorobanResources)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SorobanResources) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanResources: %w", ErrMaxDecodingDepthReached) @@ -33991,11 +32958,8 @@ func (s SorobanResources) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanResources) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -34036,9 +33000,9 @@ func (s *SorobanResourcesExtV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SorobanResourcesExtV0)(nil) +var _ xdr.DecoderFrom = (*SorobanResourcesExtV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SorobanResourcesExtV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanResourcesExtV0: %w", ErrMaxDecodingDepthReached) @@ -34052,12 +33016,17 @@ func (s *SorobanResourcesExtV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } - s.ArchivedSorobanEntries = nil - if l > 0 { + if l == 0 { + s.ArchivedSorobanEntries = s.ArchivedSorobanEntries[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Uint32: length (%d) exceeds remaining input length (%d)", l, il) } - s.ArchivedSorobanEntries = make([]Uint32, l) + if cap(s.ArchivedSorobanEntries) >= int(l) { + s.ArchivedSorobanEntries = s.ArchivedSorobanEntries[:l] + } else { + s.ArchivedSorobanEntries = make([]Uint32, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ArchivedSorobanEntries[i].DecodeFrom(d, maxDepth) n += nTmp @@ -34079,11 +33048,8 @@ func (s SorobanResourcesExtV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanResourcesExtV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -34149,25 +33115,19 @@ func NewSorobanTransactionDataExt(v int32, value interface{}) (result SorobanTra // MustResourceExt retrieves the ResourceExt value from the union, // panicing if the value is not set. func (u SorobanTransactionDataExt) MustResourceExt() SorobanResourcesExtV0 { - val, ok := u.GetResourceExt() - - if !ok { - panic("arm ResourceExt is not set") + if int32(u.V) == 1 { + return *u.ResourceExt } - - return val + panic("arm ResourceExt is not set") } // GetResourceExt retrieves the ResourceExt value from the union, // returning ok if the union's switch indicated the value is valid. func (u SorobanTransactionDataExt) GetResourceExt() (result SorobanResourcesExtV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "ResourceExt" { + if int32(u.V) == 1 { result = *u.ResourceExt ok = true } - return } @@ -34190,9 +33150,9 @@ func (u SorobanTransactionDataExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union SorobanTransactionDataExt", u.V) } -var _ decoderFrom = (*SorobanTransactionDataExt)(nil) +var _ xdr.DecoderFrom = (*SorobanTransactionDataExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *SorobanTransactionDataExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanTransactionDataExt: %w", ErrMaxDecodingDepthReached) @@ -34210,7 +33170,9 @@ func (u *SorobanTransactionDataExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (i // Void return n, nil case 1: - u.ResourceExt = new(SorobanResourcesExtV0) + if u.ResourceExt == nil { + u.ResourceExt = new(SorobanResourcesExtV0) + } nTmp, err = (*u.ResourceExt).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -34231,11 +33193,8 @@ func (s SorobanTransactionDataExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanTransactionDataExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -34293,9 +33252,9 @@ func (s *SorobanTransactionData) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SorobanTransactionData)(nil) +var _ xdr.DecoderFrom = (*SorobanTransactionData)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SorobanTransactionData) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SorobanTransactionData: %w", ErrMaxDecodingDepthReached) @@ -34331,11 +33290,8 @@ func (s SorobanTransactionData) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SorobanTransactionData) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -34400,9 +33356,9 @@ func (u TransactionV0Ext) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union TransactionV0Ext", u.V) } -var _ decoderFrom = (*TransactionV0Ext)(nil) +var _ xdr.DecoderFrom = (*TransactionV0Ext)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TransactionV0Ext) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionV0Ext: %w", ErrMaxDecodingDepthReached) @@ -34433,11 +33389,8 @@ func (s TransactionV0Ext) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionV0Ext) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -34515,9 +33468,9 @@ func (s *TransactionV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionV0)(nil) +var _ xdr.DecoderFrom = (*TransactionV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionV0: %w", ErrMaxDecodingDepthReached) @@ -34569,12 +33522,17 @@ func (s *TransactionV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if l > 100 { return n, fmt.Errorf("decoding Operation: data size (%d) exceeds size limit (100)", l) } - s.Operations = nil - if l > 0 { + if l == 0 { + s.Operations = s.Operations[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Operation: length (%d) exceeds remaining input length (%d)", l, il) } - s.Operations = make([]Operation, l) + if cap(s.Operations) >= int(l) { + s.Operations = s.Operations[:l] + } else { + s.Operations = make([]Operation, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Operations[i].DecodeFrom(d, maxDepth) n += nTmp @@ -34601,11 +33559,8 @@ func (s TransactionV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -34650,9 +33605,9 @@ func (s *TransactionV0Envelope) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionV0Envelope)(nil) +var _ xdr.DecoderFrom = (*TransactionV0Envelope)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionV0Envelope) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionV0Envelope: %w", ErrMaxDecodingDepthReached) @@ -34674,12 +33629,17 @@ func (s *TransactionV0Envelope) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if l > 20 { return n, fmt.Errorf("decoding DecoratedSignature: data size (%d) exceeds size limit (20)", l) } - s.Signatures = nil - if l > 0 { + if l == 0 { + s.Signatures = s.Signatures[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding DecoratedSignature: length (%d) exceeds remaining input length (%d)", l, il) } - s.Signatures = make([]DecoratedSignature, l) + if cap(s.Signatures) >= int(l) { + s.Signatures = s.Signatures[:l] + } else { + s.Signatures = make([]DecoratedSignature, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Signatures[i].DecodeFrom(d, maxDepth) n += nTmp @@ -34701,11 +33661,8 @@ func (s TransactionV0Envelope) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionV0Envelope) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -34771,25 +33728,19 @@ func NewTransactionExt(v int32, value interface{}) (result TransactionExt, err e // MustSorobanData retrieves the SorobanData value from the union, // panicing if the value is not set. func (u TransactionExt) MustSorobanData() SorobanTransactionData { - val, ok := u.GetSorobanData() - - if !ok { - panic("arm SorobanData is not set") + if int32(u.V) == 1 { + return *u.SorobanData } - - return val + panic("arm SorobanData is not set") } // GetSorobanData retrieves the SorobanData value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionExt) GetSorobanData() (result SorobanTransactionData, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "SorobanData" { + if int32(u.V) == 1 { result = *u.SorobanData ok = true } - return } @@ -34812,9 +33763,9 @@ func (u TransactionExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union TransactionExt", u.V) } -var _ decoderFrom = (*TransactionExt)(nil) +var _ xdr.DecoderFrom = (*TransactionExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TransactionExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionExt: %w", ErrMaxDecodingDepthReached) @@ -34832,7 +33783,9 @@ func (u *TransactionExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) // Void return n, nil case 1: - u.SorobanData = new(SorobanTransactionData) + if u.SorobanData == nil { + u.SorobanData = new(SorobanTransactionData) + } nTmp, err = (*u.SorobanData).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -34853,11 +33806,8 @@ func (s TransactionExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -34942,9 +33892,9 @@ func (s *Transaction) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Transaction)(nil) +var _ xdr.DecoderFrom = (*Transaction)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Transaction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Transaction: %w", ErrMaxDecodingDepthReached) @@ -34986,12 +33936,17 @@ func (s *Transaction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if l > 100 { return n, fmt.Errorf("decoding Operation: data size (%d) exceeds size limit (100)", l) } - s.Operations = nil - if l > 0 { + if l == 0 { + s.Operations = s.Operations[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Operation: length (%d) exceeds remaining input length (%d)", l, il) } - s.Operations = make([]Operation, l) + if cap(s.Operations) >= int(l) { + s.Operations = s.Operations[:l] + } else { + s.Operations = make([]Operation, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Operations[i].DecodeFrom(d, maxDepth) n += nTmp @@ -35018,11 +33973,8 @@ func (s Transaction) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Transaction) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -35067,9 +34019,9 @@ func (s *TransactionV1Envelope) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionV1Envelope)(nil) +var _ xdr.DecoderFrom = (*TransactionV1Envelope)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionV1Envelope) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionV1Envelope: %w", ErrMaxDecodingDepthReached) @@ -35091,12 +34043,17 @@ func (s *TransactionV1Envelope) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if l > 20 { return n, fmt.Errorf("decoding DecoratedSignature: data size (%d) exceeds size limit (20)", l) } - s.Signatures = nil - if l > 0 { + if l == 0 { + s.Signatures = s.Signatures[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding DecoratedSignature: length (%d) exceeds remaining input length (%d)", l, il) } - s.Signatures = make([]DecoratedSignature, l) + if cap(s.Signatures) >= int(l) { + s.Signatures = s.Signatures[:l] + } else { + s.Signatures = make([]DecoratedSignature, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Signatures[i].DecodeFrom(d, maxDepth) n += nTmp @@ -35118,11 +34075,8 @@ func (s TransactionV1Envelope) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionV1Envelope) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -35182,25 +34136,19 @@ func NewFeeBumpTransactionInnerTx(aType EnvelopeType, value interface{}) (result // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u FeeBumpTransactionInnerTx) MustV1() TransactionV1Envelope { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTx { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u FeeBumpTransactionInnerTx) GetV1() (result TransactionV1Envelope, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "V1" { + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTx { result = *u.V1 ok = true } - return } @@ -35220,9 +34168,9 @@ func (u FeeBumpTransactionInnerTx) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (EnvelopeType) switch value '%d' is not valid for union FeeBumpTransactionInnerTx", u.Type) } -var _ decoderFrom = (*FeeBumpTransactionInnerTx)(nil) +var _ xdr.DecoderFrom = (*FeeBumpTransactionInnerTx)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *FeeBumpTransactionInnerTx) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding FeeBumpTransactionInnerTx: %w", ErrMaxDecodingDepthReached) @@ -35237,7 +34185,9 @@ func (u *FeeBumpTransactionInnerTx) DecodeFrom(d *xdr.Decoder, maxDepth uint) (i } switch EnvelopeType(u.Type) { case EnvelopeTypeEnvelopeTypeTx: - u.V1 = new(TransactionV1Envelope) + if u.V1 == nil { + u.V1 = new(TransactionV1Envelope) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -35258,11 +34208,8 @@ func (s FeeBumpTransactionInnerTx) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *FeeBumpTransactionInnerTx) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -35327,9 +34274,9 @@ func (u FeeBumpTransactionExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union FeeBumpTransactionExt", u.V) } -var _ decoderFrom = (*FeeBumpTransactionExt)(nil) +var _ xdr.DecoderFrom = (*FeeBumpTransactionExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *FeeBumpTransactionExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding FeeBumpTransactionExt: %w", ErrMaxDecodingDepthReached) @@ -35360,11 +34307,8 @@ func (s FeeBumpTransactionExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *FeeBumpTransactionExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -35422,9 +34366,9 @@ func (s *FeeBumpTransaction) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*FeeBumpTransaction)(nil) +var _ xdr.DecoderFrom = (*FeeBumpTransaction)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *FeeBumpTransaction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding FeeBumpTransaction: %w", ErrMaxDecodingDepthReached) @@ -35465,11 +34409,8 @@ func (s FeeBumpTransaction) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *FeeBumpTransaction) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -35514,9 +34455,9 @@ func (s *FeeBumpTransactionEnvelope) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*FeeBumpTransactionEnvelope)(nil) +var _ xdr.DecoderFrom = (*FeeBumpTransactionEnvelope)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *FeeBumpTransactionEnvelope) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding FeeBumpTransactionEnvelope: %w", ErrMaxDecodingDepthReached) @@ -35538,12 +34479,17 @@ func (s *FeeBumpTransactionEnvelope) DecodeFrom(d *xdr.Decoder, maxDepth uint) ( if l > 20 { return n, fmt.Errorf("decoding DecoratedSignature: data size (%d) exceeds size limit (20)", l) } - s.Signatures = nil - if l > 0 { + if l == 0 { + s.Signatures = s.Signatures[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding DecoratedSignature: length (%d) exceeds remaining input length (%d)", l, il) } - s.Signatures = make([]DecoratedSignature, l) + if cap(s.Signatures) >= int(l) { + s.Signatures = s.Signatures[:l] + } else { + s.Signatures = make([]DecoratedSignature, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Signatures[i].DecodeFrom(d, maxDepth) n += nTmp @@ -35565,11 +34511,8 @@ func (s FeeBumpTransactionEnvelope) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *FeeBumpTransactionEnvelope) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -35653,75 +34596,57 @@ func NewTransactionEnvelope(aType EnvelopeType, value interface{}) (result Trans // MustV0 retrieves the V0 value from the union, // panicing if the value is not set. func (u TransactionEnvelope) MustV0() TransactionV0Envelope { - val, ok := u.GetV0() - - if !ok { - panic("arm V0 is not set") + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTxV0 { + return *u.V0 } - - return val + panic("arm V0 is not set") } // GetV0 retrieves the V0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionEnvelope) GetV0() (result TransactionV0Envelope, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "V0" { + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTxV0 { result = *u.V0 ok = true } - return } // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u TransactionEnvelope) MustV1() TransactionV1Envelope { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTx { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionEnvelope) GetV1() (result TransactionV1Envelope, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "V1" { + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTx { result = *u.V1 ok = true } - return } // MustFeeBump retrieves the FeeBump value from the union, // panicing if the value is not set. func (u TransactionEnvelope) MustFeeBump() FeeBumpTransactionEnvelope { - val, ok := u.GetFeeBump() - - if !ok { - panic("arm FeeBump is not set") + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTxFeeBump { + return *u.FeeBump } - - return val + panic("arm FeeBump is not set") } // GetFeeBump retrieves the FeeBump value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionEnvelope) GetFeeBump() (result FeeBumpTransactionEnvelope, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "FeeBump" { + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTxFeeBump { result = *u.FeeBump ok = true } - return } @@ -35751,9 +34676,9 @@ func (u TransactionEnvelope) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (EnvelopeType) switch value '%d' is not valid for union TransactionEnvelope", u.Type) } -var _ decoderFrom = (*TransactionEnvelope)(nil) +var _ xdr.DecoderFrom = (*TransactionEnvelope)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TransactionEnvelope) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionEnvelope: %w", ErrMaxDecodingDepthReached) @@ -35768,7 +34693,9 @@ func (u *TransactionEnvelope) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er } switch EnvelopeType(u.Type) { case EnvelopeTypeEnvelopeTypeTxV0: - u.V0 = new(TransactionV0Envelope) + if u.V0 == nil { + u.V0 = new(TransactionV0Envelope) + } nTmp, err = (*u.V0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -35776,7 +34703,9 @@ func (u *TransactionEnvelope) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er } return n, nil case EnvelopeTypeEnvelopeTypeTx: - u.V1 = new(TransactionV1Envelope) + if u.V1 == nil { + u.V1 = new(TransactionV1Envelope) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -35784,7 +34713,9 @@ func (u *TransactionEnvelope) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er } return n, nil case EnvelopeTypeEnvelopeTypeTxFeeBump: - u.FeeBump = new(FeeBumpTransactionEnvelope) + if u.FeeBump == nil { + u.FeeBump = new(FeeBumpTransactionEnvelope) + } nTmp, err = (*u.FeeBump).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -35805,11 +34736,8 @@ func (s TransactionEnvelope) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionEnvelope) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -35882,50 +34810,38 @@ func NewTransactionSignaturePayloadTaggedTransaction(aType EnvelopeType, value i // MustTx retrieves the Tx value from the union, // panicing if the value is not set. func (u TransactionSignaturePayloadTaggedTransaction) MustTx() Transaction { - val, ok := u.GetTx() - - if !ok { - panic("arm Tx is not set") + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTx { + return *u.Tx } - - return val + panic("arm Tx is not set") } // GetTx retrieves the Tx value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionSignaturePayloadTaggedTransaction) GetTx() (result Transaction, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Tx" { + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTx { result = *u.Tx ok = true } - return } // MustFeeBump retrieves the FeeBump value from the union, // panicing if the value is not set. func (u TransactionSignaturePayloadTaggedTransaction) MustFeeBump() FeeBumpTransaction { - val, ok := u.GetFeeBump() - - if !ok { - panic("arm FeeBump is not set") + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTxFeeBump { + return *u.FeeBump } - - return val + panic("arm FeeBump is not set") } // GetFeeBump retrieves the FeeBump value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionSignaturePayloadTaggedTransaction) GetFeeBump() (result FeeBumpTransaction, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "FeeBump" { + if EnvelopeType(u.Type) == EnvelopeTypeEnvelopeTypeTxFeeBump { result = *u.FeeBump ok = true } - return } @@ -35950,9 +34866,9 @@ func (u TransactionSignaturePayloadTaggedTransaction) EncodeTo(e *xdr.Encoder) e return fmt.Errorf("Type (EnvelopeType) switch value '%d' is not valid for union TransactionSignaturePayloadTaggedTransaction", u.Type) } -var _ decoderFrom = (*TransactionSignaturePayloadTaggedTransaction)(nil) +var _ xdr.DecoderFrom = (*TransactionSignaturePayloadTaggedTransaction)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TransactionSignaturePayloadTaggedTransaction) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionSignaturePayloadTaggedTransaction: %w", ErrMaxDecodingDepthReached) @@ -35967,7 +34883,9 @@ func (u *TransactionSignaturePayloadTaggedTransaction) DecodeFrom(d *xdr.Decoder } switch EnvelopeType(u.Type) { case EnvelopeTypeEnvelopeTypeTx: - u.Tx = new(Transaction) + if u.Tx == nil { + u.Tx = new(Transaction) + } nTmp, err = (*u.Tx).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -35975,7 +34893,9 @@ func (u *TransactionSignaturePayloadTaggedTransaction) DecodeFrom(d *xdr.Decoder } return n, nil case EnvelopeTypeEnvelopeTypeTxFeeBump: - u.FeeBump = new(FeeBumpTransaction) + if u.FeeBump == nil { + u.FeeBump = new(FeeBumpTransaction) + } nTmp, err = (*u.FeeBump).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -35996,11 +34916,8 @@ func (s TransactionSignaturePayloadTaggedTransaction) MarshalBinary() ([]byte, e // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionSignaturePayloadTaggedTransaction) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -36046,9 +34963,9 @@ func (s *TransactionSignaturePayload) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionSignaturePayload)(nil) +var _ xdr.DecoderFrom = (*TransactionSignaturePayload)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionSignaturePayload) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionSignaturePayload: %w", ErrMaxDecodingDepthReached) @@ -36079,11 +34996,8 @@ func (s TransactionSignaturePayload) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionSignaturePayload) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -36112,6 +35026,10 @@ const ( ClaimAtomTypeClaimAtomTypeOrderBook ClaimAtomType = 1 ClaimAtomTypeClaimAtomTypeLiquidityPool ClaimAtomType = 2 ) +const ( + _ClaimAtomType_Min int32 = 0 + _ClaimAtomType_Max int32 = 2 +) var claimAtomTypeMap = map[int32]string{ 0: "ClaimAtomTypeClaimAtomTypeV0", @@ -36122,8 +35040,7 @@ var claimAtomTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ClaimAtomType func (e ClaimAtomType) ValidEnum(v int32) bool { - _, ok := claimAtomTypeMap[v] - return ok + return v >= _ClaimAtomType_Min && v <= _ClaimAtomType_Max } // String returns the name of `e` @@ -36134,16 +35051,16 @@ func (e ClaimAtomType) String() string { // EncodeTo encodes this value using the Encoder. func (e ClaimAtomType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := claimAtomTypeMap[int32(e)]; !ok { + if int32(e) < _ClaimAtomType_Min || int32(e) > _ClaimAtomType_Max { return fmt.Errorf("'%d' is not a valid ClaimAtomType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ClaimAtomType)(nil) +var _ xdr.DecoderFrom = (*ClaimAtomType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ClaimAtomType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimAtomType: %w", ErrMaxDecodingDepthReached) @@ -36153,7 +35070,7 @@ func (e *ClaimAtomType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ClaimAtomType: %w", err) } - if _, ok := claimAtomTypeMap[v]; !ok { + if v < _ClaimAtomType_Min || v > _ClaimAtomType_Max { return n, fmt.Errorf("'%d' is not a valid ClaimAtomType enum value", v) } *e = ClaimAtomType(v) @@ -36170,11 +35087,8 @@ func (s ClaimAtomType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimAtomType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -36237,9 +35151,9 @@ func (s *ClaimOfferAtomV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ClaimOfferAtomV0)(nil) +var _ xdr.DecoderFrom = (*ClaimOfferAtomV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ClaimOfferAtomV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimOfferAtomV0: %w", ErrMaxDecodingDepthReached) @@ -36290,11 +35204,8 @@ func (s ClaimOfferAtomV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimOfferAtomV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -36357,9 +35268,9 @@ func (s *ClaimOfferAtom) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ClaimOfferAtom)(nil) +var _ xdr.DecoderFrom = (*ClaimOfferAtom)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ClaimOfferAtom) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimOfferAtom: %w", ErrMaxDecodingDepthReached) @@ -36410,11 +35321,8 @@ func (s ClaimOfferAtom) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimOfferAtom) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -36471,9 +35379,9 @@ func (s *ClaimLiquidityAtom) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ClaimLiquidityAtom)(nil) +var _ xdr.DecoderFrom = (*ClaimLiquidityAtom)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ClaimLiquidityAtom) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimLiquidityAtom: %w", ErrMaxDecodingDepthReached) @@ -36519,11 +35427,8 @@ func (s ClaimLiquidityAtom) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimLiquidityAtom) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -36607,75 +35512,57 @@ func NewClaimAtom(aType ClaimAtomType, value interface{}) (result ClaimAtom, err // MustV0 retrieves the V0 value from the union, // panicing if the value is not set. func (u ClaimAtom) MustV0() ClaimOfferAtomV0 { - val, ok := u.GetV0() - - if !ok { - panic("arm V0 is not set") + if ClaimAtomType(u.Type) == ClaimAtomTypeClaimAtomTypeV0 { + return *u.V0 } - - return val + panic("arm V0 is not set") } // GetV0 retrieves the V0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ClaimAtom) GetV0() (result ClaimOfferAtomV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "V0" { + if ClaimAtomType(u.Type) == ClaimAtomTypeClaimAtomTypeV0 { result = *u.V0 ok = true } - return } // MustOrderBook retrieves the OrderBook value from the union, // panicing if the value is not set. func (u ClaimAtom) MustOrderBook() ClaimOfferAtom { - val, ok := u.GetOrderBook() - - if !ok { - panic("arm OrderBook is not set") + if ClaimAtomType(u.Type) == ClaimAtomTypeClaimAtomTypeOrderBook { + return *u.OrderBook } - - return val + panic("arm OrderBook is not set") } // GetOrderBook retrieves the OrderBook value from the union, // returning ok if the union's switch indicated the value is valid. func (u ClaimAtom) GetOrderBook() (result ClaimOfferAtom, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "OrderBook" { + if ClaimAtomType(u.Type) == ClaimAtomTypeClaimAtomTypeOrderBook { result = *u.OrderBook ok = true } - return } // MustLiquidityPool retrieves the LiquidityPool value from the union, // panicing if the value is not set. func (u ClaimAtom) MustLiquidityPool() ClaimLiquidityAtom { - val, ok := u.GetLiquidityPool() - - if !ok { - panic("arm LiquidityPool is not set") + if ClaimAtomType(u.Type) == ClaimAtomTypeClaimAtomTypeLiquidityPool { + return *u.LiquidityPool } - - return val + panic("arm LiquidityPool is not set") } // GetLiquidityPool retrieves the LiquidityPool value from the union, // returning ok if the union's switch indicated the value is valid. func (u ClaimAtom) GetLiquidityPool() (result ClaimLiquidityAtom, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LiquidityPool" { + if ClaimAtomType(u.Type) == ClaimAtomTypeClaimAtomTypeLiquidityPool { result = *u.LiquidityPool ok = true } - return } @@ -36705,9 +35592,9 @@ func (u ClaimAtom) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (ClaimAtomType) switch value '%d' is not valid for union ClaimAtom", u.Type) } -var _ decoderFrom = (*ClaimAtom)(nil) +var _ xdr.DecoderFrom = (*ClaimAtom)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ClaimAtom) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimAtom: %w", ErrMaxDecodingDepthReached) @@ -36722,7 +35609,9 @@ func (u *ClaimAtom) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch ClaimAtomType(u.Type) { case ClaimAtomTypeClaimAtomTypeV0: - u.V0 = new(ClaimOfferAtomV0) + if u.V0 == nil { + u.V0 = new(ClaimOfferAtomV0) + } nTmp, err = (*u.V0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -36730,7 +35619,9 @@ func (u *ClaimAtom) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ClaimAtomTypeClaimAtomTypeOrderBook: - u.OrderBook = new(ClaimOfferAtom) + if u.OrderBook == nil { + u.OrderBook = new(ClaimOfferAtom) + } nTmp, err = (*u.OrderBook).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -36738,7 +35629,9 @@ func (u *ClaimAtom) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ClaimAtomTypeClaimAtomTypeLiquidityPool: - u.LiquidityPool = new(ClaimLiquidityAtom) + if u.LiquidityPool == nil { + u.LiquidityPool = new(ClaimLiquidityAtom) + } nTmp, err = (*u.LiquidityPool).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -36759,11 +35652,8 @@ func (s ClaimAtom) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimAtom) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -36800,6 +35690,10 @@ const ( CreateAccountResultCodeCreateAccountLowReserve CreateAccountResultCode = -3 CreateAccountResultCodeCreateAccountAlreadyExist CreateAccountResultCode = -4 ) +const ( + _CreateAccountResultCode_Min int32 = -4 + _CreateAccountResultCode_Max int32 = 0 +) var createAccountResultCodeMap = map[int32]string{ 0: "CreateAccountResultCodeCreateAccountSuccess", @@ -36812,8 +35706,7 @@ var createAccountResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for CreateAccountResultCode func (e CreateAccountResultCode) ValidEnum(v int32) bool { - _, ok := createAccountResultCodeMap[v] - return ok + return v >= _CreateAccountResultCode_Min && v <= _CreateAccountResultCode_Max } // String returns the name of `e` @@ -36824,16 +35717,16 @@ func (e CreateAccountResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e CreateAccountResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := createAccountResultCodeMap[int32(e)]; !ok { + if int32(e) < _CreateAccountResultCode_Min || int32(e) > _CreateAccountResultCode_Max { return fmt.Errorf("'%d' is not a valid CreateAccountResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*CreateAccountResultCode)(nil) +var _ xdr.DecoderFrom = (*CreateAccountResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *CreateAccountResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding CreateAccountResultCode: %w", ErrMaxDecodingDepthReached) @@ -36843,7 +35736,7 @@ func (e *CreateAccountResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int if err != nil { return n, fmt.Errorf("decoding CreateAccountResultCode: %w", err) } - if _, ok := createAccountResultCodeMap[v]; !ok { + if v < _CreateAccountResultCode_Min || v > _CreateAccountResultCode_Max { return n, fmt.Errorf("'%d' is not a valid CreateAccountResultCode enum value", v) } *e = CreateAccountResultCode(v) @@ -36860,11 +35753,8 @@ func (s CreateAccountResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *CreateAccountResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -36962,9 +35852,9 @@ func (u CreateAccountResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (CreateAccountResultCode) switch value '%d' is not valid for union CreateAccountResult", u.Code) } -var _ decoderFrom = (*CreateAccountResult)(nil) +var _ xdr.DecoderFrom = (*CreateAccountResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *CreateAccountResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding CreateAccountResult: %w", ErrMaxDecodingDepthReached) @@ -37007,11 +35897,8 @@ func (s CreateAccountResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *CreateAccountResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -37057,6 +35944,10 @@ const ( PaymentResultCodePaymentLineFull PaymentResultCode = -8 PaymentResultCodePaymentNoIssuer PaymentResultCode = -9 ) +const ( + _PaymentResultCode_Min int32 = -9 + _PaymentResultCode_Max int32 = 0 +) var paymentResultCodeMap = map[int32]string{ 0: "PaymentResultCodePaymentSuccess", @@ -37074,8 +35965,7 @@ var paymentResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for PaymentResultCode func (e PaymentResultCode) ValidEnum(v int32) bool { - _, ok := paymentResultCodeMap[v] - return ok + return v >= _PaymentResultCode_Min && v <= _PaymentResultCode_Max } // String returns the name of `e` @@ -37086,16 +35976,16 @@ func (e PaymentResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e PaymentResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := paymentResultCodeMap[int32(e)]; !ok { + if int32(e) < _PaymentResultCode_Min || int32(e) > _PaymentResultCode_Max { return fmt.Errorf("'%d' is not a valid PaymentResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*PaymentResultCode)(nil) +var _ xdr.DecoderFrom = (*PaymentResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *PaymentResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PaymentResultCode: %w", ErrMaxDecodingDepthReached) @@ -37105,7 +35995,7 @@ func (e *PaymentResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding PaymentResultCode: %w", err) } - if _, ok := paymentResultCodeMap[v]; !ok { + if v < _PaymentResultCode_Min || v > _PaymentResultCode_Max { return n, fmt.Errorf("'%d' is not a valid PaymentResultCode enum value", v) } *e = PaymentResultCode(v) @@ -37122,11 +36012,8 @@ func (s PaymentResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PaymentResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -37264,9 +36151,9 @@ func (u PaymentResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (PaymentResultCode) switch value '%d' is not valid for union PaymentResult", u.Code) } -var _ decoderFrom = (*PaymentResult)(nil) +var _ xdr.DecoderFrom = (*PaymentResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *PaymentResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PaymentResult: %w", ErrMaxDecodingDepthReached) @@ -37324,11 +36211,8 @@ func (s PaymentResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PaymentResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -37389,6 +36273,10 @@ const ( PathPaymentStrictReceiveResultCodePathPaymentStrictReceiveOfferCrossSelf PathPaymentStrictReceiveResultCode = -11 PathPaymentStrictReceiveResultCodePathPaymentStrictReceiveOverSendmax PathPaymentStrictReceiveResultCode = -12 ) +const ( + _PathPaymentStrictReceiveResultCode_Min int32 = -12 + _PathPaymentStrictReceiveResultCode_Max int32 = 0 +) var pathPaymentStrictReceiveResultCodeMap = map[int32]string{ 0: "PathPaymentStrictReceiveResultCodePathPaymentStrictReceiveSuccess", @@ -37409,8 +36297,7 @@ var pathPaymentStrictReceiveResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for PathPaymentStrictReceiveResultCode func (e PathPaymentStrictReceiveResultCode) ValidEnum(v int32) bool { - _, ok := pathPaymentStrictReceiveResultCodeMap[v] - return ok + return v >= _PathPaymentStrictReceiveResultCode_Min && v <= _PathPaymentStrictReceiveResultCode_Max } // String returns the name of `e` @@ -37421,16 +36308,16 @@ func (e PathPaymentStrictReceiveResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e PathPaymentStrictReceiveResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := pathPaymentStrictReceiveResultCodeMap[int32(e)]; !ok { + if int32(e) < _PathPaymentStrictReceiveResultCode_Min || int32(e) > _PathPaymentStrictReceiveResultCode_Max { return fmt.Errorf("'%d' is not a valid PathPaymentStrictReceiveResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*PathPaymentStrictReceiveResultCode)(nil) +var _ xdr.DecoderFrom = (*PathPaymentStrictReceiveResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *PathPaymentStrictReceiveResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PathPaymentStrictReceiveResultCode: %w", ErrMaxDecodingDepthReached) @@ -37440,7 +36327,7 @@ func (e *PathPaymentStrictReceiveResultCode) DecodeFrom(d *xdr.Decoder, maxDepth if err != nil { return n, fmt.Errorf("decoding PathPaymentStrictReceiveResultCode: %w", err) } - if _, ok := pathPaymentStrictReceiveResultCodeMap[v]; !ok { + if v < _PathPaymentStrictReceiveResultCode_Min || v > _PathPaymentStrictReceiveResultCode_Max { return n, fmt.Errorf("'%d' is not a valid PathPaymentStrictReceiveResultCode enum value", v) } *e = PathPaymentStrictReceiveResultCode(v) @@ -37457,11 +36344,8 @@ func (s PathPaymentStrictReceiveResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PathPaymentStrictReceiveResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -37504,9 +36388,9 @@ func (s *SimplePaymentResult) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SimplePaymentResult)(nil) +var _ xdr.DecoderFrom = (*SimplePaymentResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SimplePaymentResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SimplePaymentResult: %w", ErrMaxDecodingDepthReached) @@ -37542,11 +36426,8 @@ func (s SimplePaymentResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SimplePaymentResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -37589,9 +36470,9 @@ func (s *PathPaymentStrictReceiveResultSuccess) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*PathPaymentStrictReceiveResultSuccess)(nil) +var _ xdr.DecoderFrom = (*PathPaymentStrictReceiveResultSuccess)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *PathPaymentStrictReceiveResultSuccess) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PathPaymentStrictReceiveResultSuccess: %w", ErrMaxDecodingDepthReached) @@ -37605,12 +36486,17 @@ func (s *PathPaymentStrictReceiveResultSuccess) DecodeFrom(d *xdr.Decoder, maxDe if err != nil { return n, fmt.Errorf("decoding ClaimAtom: %w", err) } - s.Offers = nil - if l > 0 { + if l == 0 { + s.Offers = s.Offers[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ClaimAtom: length (%d) exceeds remaining input length (%d)", l, il) } - s.Offers = make([]ClaimAtom, l) + if cap(s.Offers) >= int(l) { + s.Offers = s.Offers[:l] + } else { + s.Offers = make([]ClaimAtom, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Offers[i].DecodeFrom(d, maxDepth) n += nTmp @@ -37637,11 +36523,8 @@ func (s PathPaymentStrictReceiveResultSuccess) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PathPaymentStrictReceiveResultSuccess) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -37775,50 +36658,38 @@ func NewPathPaymentStrictReceiveResult(code PathPaymentStrictReceiveResultCode, // MustSuccess retrieves the Success value from the union, // panicing if the value is not set. func (u PathPaymentStrictReceiveResult) MustSuccess() PathPaymentStrictReceiveResultSuccess { - val, ok := u.GetSuccess() - - if !ok { - panic("arm Success is not set") + if PathPaymentStrictReceiveResultCode(u.Code) == PathPaymentStrictReceiveResultCodePathPaymentStrictReceiveSuccess { + return *u.Success } - - return val + panic("arm Success is not set") } // GetSuccess retrieves the Success value from the union, // returning ok if the union's switch indicated the value is valid. func (u PathPaymentStrictReceiveResult) GetSuccess() (result PathPaymentStrictReceiveResultSuccess, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "Success" { + if PathPaymentStrictReceiveResultCode(u.Code) == PathPaymentStrictReceiveResultCodePathPaymentStrictReceiveSuccess { result = *u.Success ok = true } - return } // MustNoIssuer retrieves the NoIssuer value from the union, // panicing if the value is not set. func (u PathPaymentStrictReceiveResult) MustNoIssuer() Asset { - val, ok := u.GetNoIssuer() - - if !ok { - panic("arm NoIssuer is not set") + if PathPaymentStrictReceiveResultCode(u.Code) == PathPaymentStrictReceiveResultCodePathPaymentStrictReceiveNoIssuer { + return *u.NoIssuer } - - return val + panic("arm NoIssuer is not set") } // GetNoIssuer retrieves the NoIssuer value from the union, // returning ok if the union's switch indicated the value is valid. func (u PathPaymentStrictReceiveResult) GetNoIssuer() (result Asset, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "NoIssuer" { + if PathPaymentStrictReceiveResultCode(u.Code) == PathPaymentStrictReceiveResultCodePathPaymentStrictReceiveNoIssuer { result = *u.NoIssuer ok = true } - return } @@ -37876,9 +36747,9 @@ func (u PathPaymentStrictReceiveResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (PathPaymentStrictReceiveResultCode) switch value '%d' is not valid for union PathPaymentStrictReceiveResult", u.Code) } -var _ decoderFrom = (*PathPaymentStrictReceiveResult)(nil) +var _ xdr.DecoderFrom = (*PathPaymentStrictReceiveResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *PathPaymentStrictReceiveResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PathPaymentStrictReceiveResult: %w", ErrMaxDecodingDepthReached) @@ -37893,7 +36764,9 @@ func (u *PathPaymentStrictReceiveResult) DecodeFrom(d *xdr.Decoder, maxDepth uin } switch PathPaymentStrictReceiveResultCode(u.Code) { case PathPaymentStrictReceiveResultCodePathPaymentStrictReceiveSuccess: - u.Success = new(PathPaymentStrictReceiveResultSuccess) + if u.Success == nil { + u.Success = new(PathPaymentStrictReceiveResultSuccess) + } nTmp, err = (*u.Success).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -37925,7 +36798,9 @@ func (u *PathPaymentStrictReceiveResult) DecodeFrom(d *xdr.Decoder, maxDepth uin // Void return n, nil case PathPaymentStrictReceiveResultCodePathPaymentStrictReceiveNoIssuer: - u.NoIssuer = new(Asset) + if u.NoIssuer == nil { + u.NoIssuer = new(Asset) + } nTmp, err = (*u.NoIssuer).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -37955,11 +36830,8 @@ func (s PathPaymentStrictReceiveResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PathPaymentStrictReceiveResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -38019,6 +36891,10 @@ const ( PathPaymentStrictSendResultCodePathPaymentStrictSendOfferCrossSelf PathPaymentStrictSendResultCode = -11 PathPaymentStrictSendResultCodePathPaymentStrictSendUnderDestmin PathPaymentStrictSendResultCode = -12 ) +const ( + _PathPaymentStrictSendResultCode_Min int32 = -12 + _PathPaymentStrictSendResultCode_Max int32 = 0 +) var pathPaymentStrictSendResultCodeMap = map[int32]string{ 0: "PathPaymentStrictSendResultCodePathPaymentStrictSendSuccess", @@ -38039,8 +36915,7 @@ var pathPaymentStrictSendResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for PathPaymentStrictSendResultCode func (e PathPaymentStrictSendResultCode) ValidEnum(v int32) bool { - _, ok := pathPaymentStrictSendResultCodeMap[v] - return ok + return v >= _PathPaymentStrictSendResultCode_Min && v <= _PathPaymentStrictSendResultCode_Max } // String returns the name of `e` @@ -38051,16 +36926,16 @@ func (e PathPaymentStrictSendResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e PathPaymentStrictSendResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := pathPaymentStrictSendResultCodeMap[int32(e)]; !ok { + if int32(e) < _PathPaymentStrictSendResultCode_Min || int32(e) > _PathPaymentStrictSendResultCode_Max { return fmt.Errorf("'%d' is not a valid PathPaymentStrictSendResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*PathPaymentStrictSendResultCode)(nil) +var _ xdr.DecoderFrom = (*PathPaymentStrictSendResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *PathPaymentStrictSendResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PathPaymentStrictSendResultCode: %w", ErrMaxDecodingDepthReached) @@ -38070,7 +36945,7 @@ func (e *PathPaymentStrictSendResultCode) DecodeFrom(d *xdr.Decoder, maxDepth ui if err != nil { return n, fmt.Errorf("decoding PathPaymentStrictSendResultCode: %w", err) } - if _, ok := pathPaymentStrictSendResultCodeMap[v]; !ok { + if v < _PathPaymentStrictSendResultCode_Min || v > _PathPaymentStrictSendResultCode_Max { return n, fmt.Errorf("'%d' is not a valid PathPaymentStrictSendResultCode enum value", v) } *e = PathPaymentStrictSendResultCode(v) @@ -38087,11 +36962,8 @@ func (s PathPaymentStrictSendResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PathPaymentStrictSendResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -38134,9 +37006,9 @@ func (s *PathPaymentStrictSendResultSuccess) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*PathPaymentStrictSendResultSuccess)(nil) +var _ xdr.DecoderFrom = (*PathPaymentStrictSendResultSuccess)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *PathPaymentStrictSendResultSuccess) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PathPaymentStrictSendResultSuccess: %w", ErrMaxDecodingDepthReached) @@ -38150,12 +37022,17 @@ func (s *PathPaymentStrictSendResultSuccess) DecodeFrom(d *xdr.Decoder, maxDepth if err != nil { return n, fmt.Errorf("decoding ClaimAtom: %w", err) } - s.Offers = nil - if l > 0 { + if l == 0 { + s.Offers = s.Offers[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ClaimAtom: length (%d) exceeds remaining input length (%d)", l, il) } - s.Offers = make([]ClaimAtom, l) + if cap(s.Offers) >= int(l) { + s.Offers = s.Offers[:l] + } else { + s.Offers = make([]ClaimAtom, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Offers[i].DecodeFrom(d, maxDepth) n += nTmp @@ -38182,11 +37059,8 @@ func (s PathPaymentStrictSendResultSuccess) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PathPaymentStrictSendResultSuccess) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -38319,50 +37193,38 @@ func NewPathPaymentStrictSendResult(code PathPaymentStrictSendResultCode, value // MustSuccess retrieves the Success value from the union, // panicing if the value is not set. func (u PathPaymentStrictSendResult) MustSuccess() PathPaymentStrictSendResultSuccess { - val, ok := u.GetSuccess() - - if !ok { - panic("arm Success is not set") + if PathPaymentStrictSendResultCode(u.Code) == PathPaymentStrictSendResultCodePathPaymentStrictSendSuccess { + return *u.Success } - - return val + panic("arm Success is not set") } // GetSuccess retrieves the Success value from the union, // returning ok if the union's switch indicated the value is valid. func (u PathPaymentStrictSendResult) GetSuccess() (result PathPaymentStrictSendResultSuccess, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "Success" { + if PathPaymentStrictSendResultCode(u.Code) == PathPaymentStrictSendResultCodePathPaymentStrictSendSuccess { result = *u.Success ok = true } - return } // MustNoIssuer retrieves the NoIssuer value from the union, // panicing if the value is not set. func (u PathPaymentStrictSendResult) MustNoIssuer() Asset { - val, ok := u.GetNoIssuer() - - if !ok { - panic("arm NoIssuer is not set") + if PathPaymentStrictSendResultCode(u.Code) == PathPaymentStrictSendResultCodePathPaymentStrictSendNoIssuer { + return *u.NoIssuer } - - return val + panic("arm NoIssuer is not set") } // GetNoIssuer retrieves the NoIssuer value from the union, // returning ok if the union's switch indicated the value is valid. func (u PathPaymentStrictSendResult) GetNoIssuer() (result Asset, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "NoIssuer" { + if PathPaymentStrictSendResultCode(u.Code) == PathPaymentStrictSendResultCodePathPaymentStrictSendNoIssuer { result = *u.NoIssuer ok = true } - return } @@ -38420,9 +37282,9 @@ func (u PathPaymentStrictSendResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (PathPaymentStrictSendResultCode) switch value '%d' is not valid for union PathPaymentStrictSendResult", u.Code) } -var _ decoderFrom = (*PathPaymentStrictSendResult)(nil) +var _ xdr.DecoderFrom = (*PathPaymentStrictSendResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *PathPaymentStrictSendResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PathPaymentStrictSendResult: %w", ErrMaxDecodingDepthReached) @@ -38437,7 +37299,9 @@ func (u *PathPaymentStrictSendResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) } switch PathPaymentStrictSendResultCode(u.Code) { case PathPaymentStrictSendResultCodePathPaymentStrictSendSuccess: - u.Success = new(PathPaymentStrictSendResultSuccess) + if u.Success == nil { + u.Success = new(PathPaymentStrictSendResultSuccess) + } nTmp, err = (*u.Success).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -38469,7 +37333,9 @@ func (u *PathPaymentStrictSendResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) // Void return n, nil case PathPaymentStrictSendResultCodePathPaymentStrictSendNoIssuer: - u.NoIssuer = new(Asset) + if u.NoIssuer == nil { + u.NoIssuer = new(Asset) + } nTmp, err = (*u.NoIssuer).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -38499,11 +37365,8 @@ func (s PathPaymentStrictSendResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PathPaymentStrictSendResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -38562,6 +37425,10 @@ const ( ManageSellOfferResultCodeManageSellOfferNotFound ManageSellOfferResultCode = -11 ManageSellOfferResultCodeManageSellOfferLowReserve ManageSellOfferResultCode = -12 ) +const ( + _ManageSellOfferResultCode_Min int32 = -12 + _ManageSellOfferResultCode_Max int32 = 0 +) var manageSellOfferResultCodeMap = map[int32]string{ 0: "ManageSellOfferResultCodeManageSellOfferSuccess", @@ -38582,8 +37449,7 @@ var manageSellOfferResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ManageSellOfferResultCode func (e ManageSellOfferResultCode) ValidEnum(v int32) bool { - _, ok := manageSellOfferResultCodeMap[v] - return ok + return v >= _ManageSellOfferResultCode_Min && v <= _ManageSellOfferResultCode_Max } // String returns the name of `e` @@ -38594,16 +37460,16 @@ func (e ManageSellOfferResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e ManageSellOfferResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := manageSellOfferResultCodeMap[int32(e)]; !ok { + if int32(e) < _ManageSellOfferResultCode_Min || int32(e) > _ManageSellOfferResultCode_Max { return fmt.Errorf("'%d' is not a valid ManageSellOfferResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ManageSellOfferResultCode)(nil) +var _ xdr.DecoderFrom = (*ManageSellOfferResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ManageSellOfferResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageSellOfferResultCode: %w", ErrMaxDecodingDepthReached) @@ -38613,7 +37479,7 @@ func (e *ManageSellOfferResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (i if err != nil { return n, fmt.Errorf("decoding ManageSellOfferResultCode: %w", err) } - if _, ok := manageSellOfferResultCodeMap[v]; !ok { + if v < _ManageSellOfferResultCode_Min || v > _ManageSellOfferResultCode_Max { return n, fmt.Errorf("'%d' is not a valid ManageSellOfferResultCode enum value", v) } *e = ManageSellOfferResultCode(v) @@ -38630,11 +37496,8 @@ func (s ManageSellOfferResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageSellOfferResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -38663,6 +37526,10 @@ const ( ManageOfferEffectManageOfferUpdated ManageOfferEffect = 1 ManageOfferEffectManageOfferDeleted ManageOfferEffect = 2 ) +const ( + _ManageOfferEffect_Min int32 = 0 + _ManageOfferEffect_Max int32 = 2 +) var manageOfferEffectMap = map[int32]string{ 0: "ManageOfferEffectManageOfferCreated", @@ -38673,8 +37540,7 @@ var manageOfferEffectMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ManageOfferEffect func (e ManageOfferEffect) ValidEnum(v int32) bool { - _, ok := manageOfferEffectMap[v] - return ok + return v >= _ManageOfferEffect_Min && v <= _ManageOfferEffect_Max } // String returns the name of `e` @@ -38685,16 +37551,16 @@ func (e ManageOfferEffect) String() string { // EncodeTo encodes this value using the Encoder. func (e ManageOfferEffect) EncodeTo(enc *xdr.Encoder) error { - if _, ok := manageOfferEffectMap[int32(e)]; !ok { + if int32(e) < _ManageOfferEffect_Min || int32(e) > _ManageOfferEffect_Max { return fmt.Errorf("'%d' is not a valid ManageOfferEffect enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ManageOfferEffect)(nil) +var _ xdr.DecoderFrom = (*ManageOfferEffect)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ManageOfferEffect) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageOfferEffect: %w", ErrMaxDecodingDepthReached) @@ -38704,7 +37570,7 @@ func (e *ManageOfferEffect) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding ManageOfferEffect: %w", err) } - if _, ok := manageOfferEffectMap[v]; !ok { + if v < _ManageOfferEffect_Min || v > _ManageOfferEffect_Max { return n, fmt.Errorf("'%d' is not a valid ManageOfferEffect enum value", v) } *e = ManageOfferEffect(v) @@ -38721,11 +37587,8 @@ func (s ManageOfferEffect) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageOfferEffect) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -38801,25 +37664,19 @@ func NewManageOfferSuccessResultOffer(effect ManageOfferEffect, value interface{ // MustOffer retrieves the Offer value from the union, // panicing if the value is not set. func (u ManageOfferSuccessResultOffer) MustOffer() OfferEntry { - val, ok := u.GetOffer() - - if !ok { - panic("arm Offer is not set") + if ManageOfferEffect(u.Effect) == ManageOfferEffectManageOfferCreated || ManageOfferEffect(u.Effect) == ManageOfferEffectManageOfferUpdated { + return *u.Offer } - - return val + panic("arm Offer is not set") } // GetOffer retrieves the Offer value from the union, // returning ok if the union's switch indicated the value is valid. func (u ManageOfferSuccessResultOffer) GetOffer() (result OfferEntry, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Effect)) - - if armName == "Offer" { + if ManageOfferEffect(u.Effect) == ManageOfferEffectManageOfferCreated || ManageOfferEffect(u.Effect) == ManageOfferEffectManageOfferUpdated { result = *u.Offer ok = true } - return } @@ -38847,9 +37704,9 @@ func (u ManageOfferSuccessResultOffer) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Effect (ManageOfferEffect) switch value '%d' is not valid for union ManageOfferSuccessResultOffer", u.Effect) } -var _ decoderFrom = (*ManageOfferSuccessResultOffer)(nil) +var _ xdr.DecoderFrom = (*ManageOfferSuccessResultOffer)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ManageOfferSuccessResultOffer) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageOfferSuccessResultOffer: %w", ErrMaxDecodingDepthReached) @@ -38864,7 +37721,9 @@ func (u *ManageOfferSuccessResultOffer) DecodeFrom(d *xdr.Decoder, maxDepth uint } switch ManageOfferEffect(u.Effect) { case ManageOfferEffectManageOfferCreated: - u.Offer = new(OfferEntry) + if u.Offer == nil { + u.Offer = new(OfferEntry) + } nTmp, err = (*u.Offer).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -38872,7 +37731,9 @@ func (u *ManageOfferSuccessResultOffer) DecodeFrom(d *xdr.Decoder, maxDepth uint } return n, nil case ManageOfferEffectManageOfferUpdated: - u.Offer = new(OfferEntry) + if u.Offer == nil { + u.Offer = new(OfferEntry) + } nTmp, err = (*u.Offer).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -38896,11 +37757,8 @@ func (s ManageOfferSuccessResultOffer) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageOfferSuccessResultOffer) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -38953,9 +37811,9 @@ func (s *ManageOfferSuccessResult) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ManageOfferSuccessResult)(nil) +var _ xdr.DecoderFrom = (*ManageOfferSuccessResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ManageOfferSuccessResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageOfferSuccessResult: %w", ErrMaxDecodingDepthReached) @@ -38969,12 +37827,17 @@ func (s *ManageOfferSuccessResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (in if err != nil { return n, fmt.Errorf("decoding ClaimAtom: %w", err) } - s.OffersClaimed = nil - if l > 0 { + if l == 0 { + s.OffersClaimed = s.OffersClaimed[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ClaimAtom: length (%d) exceeds remaining input length (%d)", l, il) } - s.OffersClaimed = make([]ClaimAtom, l) + if cap(s.OffersClaimed) >= int(l) { + s.OffersClaimed = s.OffersClaimed[:l] + } else { + s.OffersClaimed = make([]ClaimAtom, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.OffersClaimed[i].DecodeFrom(d, maxDepth) n += nTmp @@ -39001,11 +37864,8 @@ func (s ManageOfferSuccessResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageOfferSuccessResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -39126,25 +37986,19 @@ func NewManageSellOfferResult(code ManageSellOfferResultCode, value interface{}) // MustSuccess retrieves the Success value from the union, // panicing if the value is not set. func (u ManageSellOfferResult) MustSuccess() ManageOfferSuccessResult { - val, ok := u.GetSuccess() - - if !ok { - panic("arm Success is not set") + if ManageSellOfferResultCode(u.Code) == ManageSellOfferResultCodeManageSellOfferSuccess { + return *u.Success } - - return val + panic("arm Success is not set") } // GetSuccess retrieves the Success value from the union, // returning ok if the union's switch indicated the value is valid. func (u ManageSellOfferResult) GetSuccess() (result ManageOfferSuccessResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "Success" { + if ManageSellOfferResultCode(u.Code) == ManageSellOfferResultCodeManageSellOfferSuccess { result = *u.Success ok = true } - return } @@ -39200,9 +38054,9 @@ func (u ManageSellOfferResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (ManageSellOfferResultCode) switch value '%d' is not valid for union ManageSellOfferResult", u.Code) } -var _ decoderFrom = (*ManageSellOfferResult)(nil) +var _ xdr.DecoderFrom = (*ManageSellOfferResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ManageSellOfferResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageSellOfferResult: %w", ErrMaxDecodingDepthReached) @@ -39217,7 +38071,9 @@ func (u *ManageSellOfferResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, } switch ManageSellOfferResultCode(u.Code) { case ManageSellOfferResultCodeManageSellOfferSuccess: - u.Success = new(ManageOfferSuccessResult) + if u.Success == nil { + u.Success = new(ManageOfferSuccessResult) + } nTmp, err = (*u.Success).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -39274,11 +38130,8 @@ func (s ManageSellOfferResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageSellOfferResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -39334,6 +38187,10 @@ const ( ManageBuyOfferResultCodeManageBuyOfferNotFound ManageBuyOfferResultCode = -11 ManageBuyOfferResultCodeManageBuyOfferLowReserve ManageBuyOfferResultCode = -12 ) +const ( + _ManageBuyOfferResultCode_Min int32 = -12 + _ManageBuyOfferResultCode_Max int32 = 0 +) var manageBuyOfferResultCodeMap = map[int32]string{ 0: "ManageBuyOfferResultCodeManageBuyOfferSuccess", @@ -39354,8 +38211,7 @@ var manageBuyOfferResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ManageBuyOfferResultCode func (e ManageBuyOfferResultCode) ValidEnum(v int32) bool { - _, ok := manageBuyOfferResultCodeMap[v] - return ok + return v >= _ManageBuyOfferResultCode_Min && v <= _ManageBuyOfferResultCode_Max } // String returns the name of `e` @@ -39366,16 +38222,16 @@ func (e ManageBuyOfferResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e ManageBuyOfferResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := manageBuyOfferResultCodeMap[int32(e)]; !ok { + if int32(e) < _ManageBuyOfferResultCode_Min || int32(e) > _ManageBuyOfferResultCode_Max { return fmt.Errorf("'%d' is not a valid ManageBuyOfferResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ManageBuyOfferResultCode)(nil) +var _ xdr.DecoderFrom = (*ManageBuyOfferResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ManageBuyOfferResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageBuyOfferResultCode: %w", ErrMaxDecodingDepthReached) @@ -39385,7 +38241,7 @@ func (e *ManageBuyOfferResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (in if err != nil { return n, fmt.Errorf("decoding ManageBuyOfferResultCode: %w", err) } - if _, ok := manageBuyOfferResultCodeMap[v]; !ok { + if v < _ManageBuyOfferResultCode_Min || v > _ManageBuyOfferResultCode_Max { return n, fmt.Errorf("'%d' is not a valid ManageBuyOfferResultCode enum value", v) } *e = ManageBuyOfferResultCode(v) @@ -39402,11 +38258,8 @@ func (s ManageBuyOfferResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageBuyOfferResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -39527,25 +38380,19 @@ func NewManageBuyOfferResult(code ManageBuyOfferResultCode, value interface{}) ( // MustSuccess retrieves the Success value from the union, // panicing if the value is not set. func (u ManageBuyOfferResult) MustSuccess() ManageOfferSuccessResult { - val, ok := u.GetSuccess() - - if !ok { - panic("arm Success is not set") + if ManageBuyOfferResultCode(u.Code) == ManageBuyOfferResultCodeManageBuyOfferSuccess { + return *u.Success } - - return val + panic("arm Success is not set") } // GetSuccess retrieves the Success value from the union, // returning ok if the union's switch indicated the value is valid. func (u ManageBuyOfferResult) GetSuccess() (result ManageOfferSuccessResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "Success" { + if ManageBuyOfferResultCode(u.Code) == ManageBuyOfferResultCodeManageBuyOfferSuccess { result = *u.Success ok = true } - return } @@ -39601,9 +38448,9 @@ func (u ManageBuyOfferResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (ManageBuyOfferResultCode) switch value '%d' is not valid for union ManageBuyOfferResult", u.Code) } -var _ decoderFrom = (*ManageBuyOfferResult)(nil) +var _ xdr.DecoderFrom = (*ManageBuyOfferResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ManageBuyOfferResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageBuyOfferResult: %w", ErrMaxDecodingDepthReached) @@ -39618,7 +38465,9 @@ func (u *ManageBuyOfferResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e } switch ManageBuyOfferResultCode(u.Code) { case ManageBuyOfferResultCodeManageBuyOfferSuccess: - u.Success = new(ManageOfferSuccessResult) + if u.Success == nil { + u.Success = new(ManageOfferSuccessResult) + } nTmp, err = (*u.Success).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -39675,11 +38524,8 @@ func (s ManageBuyOfferResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageBuyOfferResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -39727,6 +38573,10 @@ const ( SetOptionsResultCodeSetOptionsInvalidHomeDomain SetOptionsResultCode = -9 SetOptionsResultCodeSetOptionsAuthRevocableRequired SetOptionsResultCode = -10 ) +const ( + _SetOptionsResultCode_Min int32 = -10 + _SetOptionsResultCode_Max int32 = 0 +) var setOptionsResultCodeMap = map[int32]string{ 0: "SetOptionsResultCodeSetOptionsSuccess", @@ -39745,8 +38595,7 @@ var setOptionsResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for SetOptionsResultCode func (e SetOptionsResultCode) ValidEnum(v int32) bool { - _, ok := setOptionsResultCodeMap[v] - return ok + return v >= _SetOptionsResultCode_Min && v <= _SetOptionsResultCode_Max } // String returns the name of `e` @@ -39757,16 +38606,16 @@ func (e SetOptionsResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e SetOptionsResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := setOptionsResultCodeMap[int32(e)]; !ok { + if int32(e) < _SetOptionsResultCode_Min || int32(e) > _SetOptionsResultCode_Max { return fmt.Errorf("'%d' is not a valid SetOptionsResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*SetOptionsResultCode)(nil) +var _ xdr.DecoderFrom = (*SetOptionsResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *SetOptionsResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SetOptionsResultCode: %w", ErrMaxDecodingDepthReached) @@ -39776,7 +38625,7 @@ func (e *SetOptionsResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e if err != nil { return n, fmt.Errorf("decoding SetOptionsResultCode: %w", err) } - if _, ok := setOptionsResultCodeMap[v]; !ok { + if v < _SetOptionsResultCode_Min || v > _SetOptionsResultCode_Max { return n, fmt.Errorf("'%d' is not a valid SetOptionsResultCode enum value", v) } *e = SetOptionsResultCode(v) @@ -39793,11 +38642,8 @@ func (s SetOptionsResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SetOptionsResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -39943,9 +38789,9 @@ func (u SetOptionsResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (SetOptionsResultCode) switch value '%d' is not valid for union SetOptionsResult", u.Code) } -var _ decoderFrom = (*SetOptionsResult)(nil) +var _ xdr.DecoderFrom = (*SetOptionsResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *SetOptionsResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SetOptionsResult: %w", ErrMaxDecodingDepthReached) @@ -40006,11 +38852,8 @@ func (s SetOptionsResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SetOptionsResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -40057,6 +38900,10 @@ const ( ChangeTrustResultCodeChangeTrustCannotDelete ChangeTrustResultCode = -7 ChangeTrustResultCodeChangeTrustNotAuthMaintainLiabilities ChangeTrustResultCode = -8 ) +const ( + _ChangeTrustResultCode_Min int32 = -8 + _ChangeTrustResultCode_Max int32 = 0 +) var changeTrustResultCodeMap = map[int32]string{ 0: "ChangeTrustResultCodeChangeTrustSuccess", @@ -40073,8 +38920,7 @@ var changeTrustResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ChangeTrustResultCode func (e ChangeTrustResultCode) ValidEnum(v int32) bool { - _, ok := changeTrustResultCodeMap[v] - return ok + return v >= _ChangeTrustResultCode_Min && v <= _ChangeTrustResultCode_Max } // String returns the name of `e` @@ -40085,16 +38931,16 @@ func (e ChangeTrustResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e ChangeTrustResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := changeTrustResultCodeMap[int32(e)]; !ok { + if int32(e) < _ChangeTrustResultCode_Min || int32(e) > _ChangeTrustResultCode_Max { return fmt.Errorf("'%d' is not a valid ChangeTrustResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ChangeTrustResultCode)(nil) +var _ xdr.DecoderFrom = (*ChangeTrustResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ChangeTrustResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ChangeTrustResultCode: %w", ErrMaxDecodingDepthReached) @@ -40104,7 +38950,7 @@ func (e *ChangeTrustResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding ChangeTrustResultCode: %w", err) } - if _, ok := changeTrustResultCodeMap[v]; !ok { + if v < _ChangeTrustResultCode_Min || v > _ChangeTrustResultCode_Max { return n, fmt.Errorf("'%d' is not a valid ChangeTrustResultCode enum value", v) } *e = ChangeTrustResultCode(v) @@ -40121,11 +38967,8 @@ func (s ChangeTrustResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ChangeTrustResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -40255,9 +39098,9 @@ func (u ChangeTrustResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (ChangeTrustResultCode) switch value '%d' is not valid for union ChangeTrustResult", u.Code) } -var _ decoderFrom = (*ChangeTrustResult)(nil) +var _ xdr.DecoderFrom = (*ChangeTrustResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ChangeTrustResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ChangeTrustResult: %w", ErrMaxDecodingDepthReached) @@ -40312,11 +39155,8 @@ func (s ChangeTrustResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ChangeTrustResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -40357,6 +39197,10 @@ const ( AllowTrustResultCodeAllowTrustSelfNotAllowed AllowTrustResultCode = -5 AllowTrustResultCodeAllowTrustLowReserve AllowTrustResultCode = -6 ) +const ( + _AllowTrustResultCode_Min int32 = -6 + _AllowTrustResultCode_Max int32 = 0 +) var allowTrustResultCodeMap = map[int32]string{ 0: "AllowTrustResultCodeAllowTrustSuccess", @@ -40371,8 +39215,7 @@ var allowTrustResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for AllowTrustResultCode func (e AllowTrustResultCode) ValidEnum(v int32) bool { - _, ok := allowTrustResultCodeMap[v] - return ok + return v >= _AllowTrustResultCode_Min && v <= _AllowTrustResultCode_Max } // String returns the name of `e` @@ -40383,16 +39226,16 @@ func (e AllowTrustResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e AllowTrustResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := allowTrustResultCodeMap[int32(e)]; !ok { + if int32(e) < _AllowTrustResultCode_Min || int32(e) > _AllowTrustResultCode_Max { return fmt.Errorf("'%d' is not a valid AllowTrustResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*AllowTrustResultCode)(nil) +var _ xdr.DecoderFrom = (*AllowTrustResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *AllowTrustResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AllowTrustResultCode: %w", ErrMaxDecodingDepthReached) @@ -40402,7 +39245,7 @@ func (e *AllowTrustResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e if err != nil { return n, fmt.Errorf("decoding AllowTrustResultCode: %w", err) } - if _, ok := allowTrustResultCodeMap[v]; !ok { + if v < _AllowTrustResultCode_Min || v > _AllowTrustResultCode_Max { return n, fmt.Errorf("'%d' is not a valid AllowTrustResultCode enum value", v) } *e = AllowTrustResultCode(v) @@ -40419,11 +39262,8 @@ func (s AllowTrustResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AllowTrustResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -40537,9 +39377,9 @@ func (u AllowTrustResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (AllowTrustResultCode) switch value '%d' is not valid for union AllowTrustResult", u.Code) } -var _ decoderFrom = (*AllowTrustResult)(nil) +var _ xdr.DecoderFrom = (*AllowTrustResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *AllowTrustResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AllowTrustResult: %w", ErrMaxDecodingDepthReached) @@ -40588,11 +39428,8 @@ func (s AllowTrustResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AllowTrustResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -40634,6 +39471,10 @@ const ( AccountMergeResultCodeAccountMergeDestFull AccountMergeResultCode = -6 AccountMergeResultCodeAccountMergeIsSponsor AccountMergeResultCode = -7 ) +const ( + _AccountMergeResultCode_Min int32 = -7 + _AccountMergeResultCode_Max int32 = 0 +) var accountMergeResultCodeMap = map[int32]string{ 0: "AccountMergeResultCodeAccountMergeSuccess", @@ -40649,8 +39490,7 @@ var accountMergeResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for AccountMergeResultCode func (e AccountMergeResultCode) ValidEnum(v int32) bool { - _, ok := accountMergeResultCodeMap[v] - return ok + return v >= _AccountMergeResultCode_Min && v <= _AccountMergeResultCode_Max } // String returns the name of `e` @@ -40661,16 +39501,16 @@ func (e AccountMergeResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e AccountMergeResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := accountMergeResultCodeMap[int32(e)]; !ok { + if int32(e) < _AccountMergeResultCode_Min || int32(e) > _AccountMergeResultCode_Max { return fmt.Errorf("'%d' is not a valid AccountMergeResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*AccountMergeResultCode)(nil) +var _ xdr.DecoderFrom = (*AccountMergeResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *AccountMergeResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AccountMergeResultCode: %w", ErrMaxDecodingDepthReached) @@ -40680,7 +39520,7 @@ func (e *AccountMergeResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding AccountMergeResultCode: %w", err) } - if _, ok := accountMergeResultCodeMap[v]; !ok { + if v < _AccountMergeResultCode_Min || v > _AccountMergeResultCode_Max { return n, fmt.Errorf("'%d' is not a valid AccountMergeResultCode enum value", v) } *e = AccountMergeResultCode(v) @@ -40697,11 +39537,8 @@ func (s AccountMergeResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AccountMergeResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -40732,7 +39569,7 @@ var _ xdrType = (*AccountMergeResultCode)(nil) // }; type AccountMergeResult struct { Code AccountMergeResultCode - SourceAccountBalance *Int64 + SourceAccountBalance Int64 } // SwitchFieldName returns the field name in which this union's @@ -40775,7 +39612,7 @@ func NewAccountMergeResult(code AccountMergeResultCode, value interface{}) (resu err = errors.New("invalid value, must be Int64") return } - result.SourceAccountBalance = &tv + result.SourceAccountBalance = tv case AccountMergeResultCodeAccountMergeMalformed: // void case AccountMergeResultCodeAccountMergeNoAccount: @@ -40797,25 +39634,19 @@ func NewAccountMergeResult(code AccountMergeResultCode, value interface{}) (resu // MustSourceAccountBalance retrieves the SourceAccountBalance value from the union, // panicing if the value is not set. func (u AccountMergeResult) MustSourceAccountBalance() Int64 { - val, ok := u.GetSourceAccountBalance() - - if !ok { - panic("arm SourceAccountBalance is not set") + if AccountMergeResultCode(u.Code) == AccountMergeResultCodeAccountMergeSuccess { + return u.SourceAccountBalance } - - return val + panic("arm SourceAccountBalance is not set") } // GetSourceAccountBalance retrieves the SourceAccountBalance value from the union, // returning ok if the union's switch indicated the value is valid. func (u AccountMergeResult) GetSourceAccountBalance() (result Int64, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "SourceAccountBalance" { - result = *u.SourceAccountBalance + if AccountMergeResultCode(u.Code) == AccountMergeResultCodeAccountMergeSuccess { + result = u.SourceAccountBalance ok = true } - return } @@ -40827,7 +39658,7 @@ func (u AccountMergeResult) EncodeTo(e *xdr.Encoder) error { } switch AccountMergeResultCode(u.Code) { case AccountMergeResultCodeAccountMergeSuccess: - if err = (*u.SourceAccountBalance).EncodeTo(e); err != nil { + if err = u.SourceAccountBalance.EncodeTo(e); err != nil { return err } return nil @@ -40856,9 +39687,9 @@ func (u AccountMergeResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (AccountMergeResultCode) switch value '%d' is not valid for union AccountMergeResult", u.Code) } -var _ decoderFrom = (*AccountMergeResult)(nil) +var _ xdr.DecoderFrom = (*AccountMergeResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *AccountMergeResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AccountMergeResult: %w", ErrMaxDecodingDepthReached) @@ -40873,8 +39704,7 @@ func (u *AccountMergeResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } switch AccountMergeResultCode(u.Code) { case AccountMergeResultCodeAccountMergeSuccess: - u.SourceAccountBalance = new(Int64) - nTmp, err = (*u.SourceAccountBalance).DecodeFrom(d, maxDepth) + nTmp, err = u.SourceAccountBalance.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Int64: %w", err) @@ -40915,11 +39745,8 @@ func (s AccountMergeResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AccountMergeResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -40948,6 +39775,10 @@ const ( InflationResultCodeInflationSuccess InflationResultCode = 0 InflationResultCodeInflationNotTime InflationResultCode = -1 ) +const ( + _InflationResultCode_Min int32 = -1 + _InflationResultCode_Max int32 = 0 +) var inflationResultCodeMap = map[int32]string{ 0: "InflationResultCodeInflationSuccess", @@ -40957,8 +39788,7 @@ var inflationResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for InflationResultCode func (e InflationResultCode) ValidEnum(v int32) bool { - _, ok := inflationResultCodeMap[v] - return ok + return v >= _InflationResultCode_Min && v <= _InflationResultCode_Max } // String returns the name of `e` @@ -40969,16 +39799,16 @@ func (e InflationResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e InflationResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := inflationResultCodeMap[int32(e)]; !ok { + if int32(e) < _InflationResultCode_Min || int32(e) > _InflationResultCode_Max { return fmt.Errorf("'%d' is not a valid InflationResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*InflationResultCode)(nil) +var _ xdr.DecoderFrom = (*InflationResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *InflationResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InflationResultCode: %w", ErrMaxDecodingDepthReached) @@ -40988,7 +39818,7 @@ func (e *InflationResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er if err != nil { return n, fmt.Errorf("decoding InflationResultCode: %w", err) } - if _, ok := inflationResultCodeMap[v]; !ok { + if v < _InflationResultCode_Min || v > _InflationResultCode_Max { return n, fmt.Errorf("'%d' is not a valid InflationResultCode enum value", v) } *e = InflationResultCode(v) @@ -41005,11 +39835,8 @@ func (s InflationResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InflationResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -41047,9 +39874,9 @@ func (s *InflationPayout) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*InflationPayout)(nil) +var _ xdr.DecoderFrom = (*InflationPayout)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *InflationPayout) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InflationPayout: %w", ErrMaxDecodingDepthReached) @@ -41080,11 +39907,8 @@ func (s InflationPayout) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InflationPayout) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -41150,25 +39974,19 @@ func NewInflationResult(code InflationResultCode, value interface{}) (result Inf // MustPayouts retrieves the Payouts value from the union, // panicing if the value is not set. func (u InflationResult) MustPayouts() []InflationPayout { - val, ok := u.GetPayouts() - - if !ok { - panic("arm Payouts is not set") + if InflationResultCode(u.Code) == InflationResultCodeInflationSuccess { + return *u.Payouts } - - return val + panic("arm Payouts is not set") } // GetPayouts retrieves the Payouts value from the union, // returning ok if the union's switch indicated the value is valid. func (u InflationResult) GetPayouts() (result []InflationPayout, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "Payouts" { + if InflationResultCode(u.Code) == InflationResultCodeInflationSuccess { result = *u.Payouts ok = true } - return } @@ -41196,9 +40014,9 @@ func (u InflationResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (InflationResultCode) switch value '%d' is not valid for union InflationResult", u.Code) } -var _ decoderFrom = (*InflationResult)(nil) +var _ xdr.DecoderFrom = (*InflationResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *InflationResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InflationResult: %w", ErrMaxDecodingDepthReached) @@ -41213,19 +40031,26 @@ func (u *InflationResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } switch InflationResultCode(u.Code) { case InflationResultCodeInflationSuccess: - u.Payouts = new([]InflationPayout) + if u.Payouts == nil { + u.Payouts = new([]InflationPayout) + } var l uint32 l, nTmp, err = d.DecodeUint() n += nTmp if err != nil { return n, fmt.Errorf("decoding InflationPayout: %w", err) } - (*u.Payouts) = nil - if l > 0 { + if l == 0 { + (*u.Payouts) = (*u.Payouts)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding InflationPayout: length (%d) exceeds remaining input length (%d)", l, il) } - (*u.Payouts) = make([]InflationPayout, l) + if cap((*u.Payouts)) >= int(l) { + (*u.Payouts) = (*u.Payouts)[:l] + } else { + (*u.Payouts) = make([]InflationPayout, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*u.Payouts)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -41252,11 +40077,8 @@ func (s InflationResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InflationResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -41293,6 +40115,10 @@ const ( ManageDataResultCodeManageDataLowReserve ManageDataResultCode = -3 ManageDataResultCodeManageDataInvalidName ManageDataResultCode = -4 ) +const ( + _ManageDataResultCode_Min int32 = -4 + _ManageDataResultCode_Max int32 = 0 +) var manageDataResultCodeMap = map[int32]string{ 0: "ManageDataResultCodeManageDataSuccess", @@ -41305,8 +40131,7 @@ var manageDataResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ManageDataResultCode func (e ManageDataResultCode) ValidEnum(v int32) bool { - _, ok := manageDataResultCodeMap[v] - return ok + return v >= _ManageDataResultCode_Min && v <= _ManageDataResultCode_Max } // String returns the name of `e` @@ -41317,16 +40142,16 @@ func (e ManageDataResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e ManageDataResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := manageDataResultCodeMap[int32(e)]; !ok { + if int32(e) < _ManageDataResultCode_Min || int32(e) > _ManageDataResultCode_Max { return fmt.Errorf("'%d' is not a valid ManageDataResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ManageDataResultCode)(nil) +var _ xdr.DecoderFrom = (*ManageDataResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ManageDataResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageDataResultCode: %w", ErrMaxDecodingDepthReached) @@ -41336,7 +40161,7 @@ func (e *ManageDataResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e if err != nil { return n, fmt.Errorf("decoding ManageDataResultCode: %w", err) } - if _, ok := manageDataResultCodeMap[v]; !ok { + if v < _ManageDataResultCode_Min || v > _ManageDataResultCode_Max { return n, fmt.Errorf("'%d' is not a valid ManageDataResultCode enum value", v) } *e = ManageDataResultCode(v) @@ -41353,11 +40178,8 @@ func (s ManageDataResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageDataResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -41455,9 +40277,9 @@ func (u ManageDataResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (ManageDataResultCode) switch value '%d' is not valid for union ManageDataResult", u.Code) } -var _ decoderFrom = (*ManageDataResult)(nil) +var _ xdr.DecoderFrom = (*ManageDataResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ManageDataResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ManageDataResult: %w", ErrMaxDecodingDepthReached) @@ -41500,11 +40322,8 @@ func (s ManageDataResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ManageDataResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -41533,6 +40352,10 @@ const ( BumpSequenceResultCodeBumpSequenceSuccess BumpSequenceResultCode = 0 BumpSequenceResultCodeBumpSequenceBadSeq BumpSequenceResultCode = -1 ) +const ( + _BumpSequenceResultCode_Min int32 = -1 + _BumpSequenceResultCode_Max int32 = 0 +) var bumpSequenceResultCodeMap = map[int32]string{ 0: "BumpSequenceResultCodeBumpSequenceSuccess", @@ -41542,8 +40365,7 @@ var bumpSequenceResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for BumpSequenceResultCode func (e BumpSequenceResultCode) ValidEnum(v int32) bool { - _, ok := bumpSequenceResultCodeMap[v] - return ok + return v >= _BumpSequenceResultCode_Min && v <= _BumpSequenceResultCode_Max } // String returns the name of `e` @@ -41554,16 +40376,16 @@ func (e BumpSequenceResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e BumpSequenceResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := bumpSequenceResultCodeMap[int32(e)]; !ok { + if int32(e) < _BumpSequenceResultCode_Min || int32(e) > _BumpSequenceResultCode_Max { return fmt.Errorf("'%d' is not a valid BumpSequenceResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*BumpSequenceResultCode)(nil) +var _ xdr.DecoderFrom = (*BumpSequenceResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *BumpSequenceResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BumpSequenceResultCode: %w", ErrMaxDecodingDepthReached) @@ -41573,7 +40395,7 @@ func (e *BumpSequenceResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding BumpSequenceResultCode: %w", err) } - if _, ok := bumpSequenceResultCodeMap[v]; !ok { + if v < _BumpSequenceResultCode_Min || v > _BumpSequenceResultCode_Max { return n, fmt.Errorf("'%d' is not a valid BumpSequenceResultCode enum value", v) } *e = BumpSequenceResultCode(v) @@ -41590,11 +40412,8 @@ func (s BumpSequenceResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BumpSequenceResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -41668,9 +40487,9 @@ func (u BumpSequenceResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (BumpSequenceResultCode) switch value '%d' is not valid for union BumpSequenceResult", u.Code) } -var _ decoderFrom = (*BumpSequenceResult)(nil) +var _ xdr.DecoderFrom = (*BumpSequenceResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *BumpSequenceResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BumpSequenceResult: %w", ErrMaxDecodingDepthReached) @@ -41704,11 +40523,8 @@ func (s BumpSequenceResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BumpSequenceResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -41743,6 +40559,10 @@ const ( CreateClaimableBalanceResultCodeCreateClaimableBalanceNotAuthorized CreateClaimableBalanceResultCode = -4 CreateClaimableBalanceResultCodeCreateClaimableBalanceUnderfunded CreateClaimableBalanceResultCode = -5 ) +const ( + _CreateClaimableBalanceResultCode_Min int32 = -5 + _CreateClaimableBalanceResultCode_Max int32 = 0 +) var createClaimableBalanceResultCodeMap = map[int32]string{ 0: "CreateClaimableBalanceResultCodeCreateClaimableBalanceSuccess", @@ -41756,8 +40576,7 @@ var createClaimableBalanceResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for CreateClaimableBalanceResultCode func (e CreateClaimableBalanceResultCode) ValidEnum(v int32) bool { - _, ok := createClaimableBalanceResultCodeMap[v] - return ok + return v >= _CreateClaimableBalanceResultCode_Min && v <= _CreateClaimableBalanceResultCode_Max } // String returns the name of `e` @@ -41768,16 +40587,16 @@ func (e CreateClaimableBalanceResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e CreateClaimableBalanceResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := createClaimableBalanceResultCodeMap[int32(e)]; !ok { + if int32(e) < _CreateClaimableBalanceResultCode_Min || int32(e) > _CreateClaimableBalanceResultCode_Max { return fmt.Errorf("'%d' is not a valid CreateClaimableBalanceResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*CreateClaimableBalanceResultCode)(nil) +var _ xdr.DecoderFrom = (*CreateClaimableBalanceResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *CreateClaimableBalanceResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding CreateClaimableBalanceResultCode: %w", ErrMaxDecodingDepthReached) @@ -41787,7 +40606,7 @@ func (e *CreateClaimableBalanceResultCode) DecodeFrom(d *xdr.Decoder, maxDepth u if err != nil { return n, fmt.Errorf("decoding CreateClaimableBalanceResultCode: %w", err) } - if _, ok := createClaimableBalanceResultCodeMap[v]; !ok { + if v < _CreateClaimableBalanceResultCode_Min || v > _CreateClaimableBalanceResultCode_Max { return n, fmt.Errorf("'%d' is not a valid CreateClaimableBalanceResultCode enum value", v) } *e = CreateClaimableBalanceResultCode(v) @@ -41804,11 +40623,8 @@ func (s CreateClaimableBalanceResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *CreateClaimableBalanceResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -41895,25 +40711,19 @@ func NewCreateClaimableBalanceResult(code CreateClaimableBalanceResultCode, valu // MustBalanceId retrieves the BalanceId value from the union, // panicing if the value is not set. func (u CreateClaimableBalanceResult) MustBalanceId() ClaimableBalanceId { - val, ok := u.GetBalanceId() - - if !ok { - panic("arm BalanceId is not set") + if CreateClaimableBalanceResultCode(u.Code) == CreateClaimableBalanceResultCodeCreateClaimableBalanceSuccess { + return *u.BalanceId } - - return val + panic("arm BalanceId is not set") } // GetBalanceId retrieves the BalanceId value from the union, // returning ok if the union's switch indicated the value is valid. func (u CreateClaimableBalanceResult) GetBalanceId() (result ClaimableBalanceId, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "BalanceId" { + if CreateClaimableBalanceResultCode(u.Code) == CreateClaimableBalanceResultCodeCreateClaimableBalanceSuccess { result = *u.BalanceId ok = true } - return } @@ -41948,9 +40758,9 @@ func (u CreateClaimableBalanceResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (CreateClaimableBalanceResultCode) switch value '%d' is not valid for union CreateClaimableBalanceResult", u.Code) } -var _ decoderFrom = (*CreateClaimableBalanceResult)(nil) +var _ xdr.DecoderFrom = (*CreateClaimableBalanceResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *CreateClaimableBalanceResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding CreateClaimableBalanceResult: %w", ErrMaxDecodingDepthReached) @@ -41965,7 +40775,9 @@ func (u *CreateClaimableBalanceResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) } switch CreateClaimableBalanceResultCode(u.Code) { case CreateClaimableBalanceResultCodeCreateClaimableBalanceSuccess: - u.BalanceId = new(ClaimableBalanceId) + if u.BalanceId == nil { + u.BalanceId = new(ClaimableBalanceId) + } nTmp, err = (*u.BalanceId).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -42001,11 +40813,8 @@ func (s CreateClaimableBalanceResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *CreateClaimableBalanceResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -42040,6 +40849,10 @@ const ( ClaimClaimableBalanceResultCodeClaimClaimableBalanceNoTrust ClaimClaimableBalanceResultCode = -4 ClaimClaimableBalanceResultCodeClaimClaimableBalanceNotAuthorized ClaimClaimableBalanceResultCode = -5 ) +const ( + _ClaimClaimableBalanceResultCode_Min int32 = -5 + _ClaimClaimableBalanceResultCode_Max int32 = 0 +) var claimClaimableBalanceResultCodeMap = map[int32]string{ 0: "ClaimClaimableBalanceResultCodeClaimClaimableBalanceSuccess", @@ -42053,8 +40866,7 @@ var claimClaimableBalanceResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ClaimClaimableBalanceResultCode func (e ClaimClaimableBalanceResultCode) ValidEnum(v int32) bool { - _, ok := claimClaimableBalanceResultCodeMap[v] - return ok + return v >= _ClaimClaimableBalanceResultCode_Min && v <= _ClaimClaimableBalanceResultCode_Max } // String returns the name of `e` @@ -42065,16 +40877,16 @@ func (e ClaimClaimableBalanceResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e ClaimClaimableBalanceResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := claimClaimableBalanceResultCodeMap[int32(e)]; !ok { + if int32(e) < _ClaimClaimableBalanceResultCode_Min || int32(e) > _ClaimClaimableBalanceResultCode_Max { return fmt.Errorf("'%d' is not a valid ClaimClaimableBalanceResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ClaimClaimableBalanceResultCode)(nil) +var _ xdr.DecoderFrom = (*ClaimClaimableBalanceResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ClaimClaimableBalanceResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimClaimableBalanceResultCode: %w", ErrMaxDecodingDepthReached) @@ -42084,7 +40896,7 @@ func (e *ClaimClaimableBalanceResultCode) DecodeFrom(d *xdr.Decoder, maxDepth ui if err != nil { return n, fmt.Errorf("decoding ClaimClaimableBalanceResultCode: %w", err) } - if _, ok := claimClaimableBalanceResultCodeMap[v]; !ok { + if v < _ClaimClaimableBalanceResultCode_Min || v > _ClaimClaimableBalanceResultCode_Max { return n, fmt.Errorf("'%d' is not a valid ClaimClaimableBalanceResultCode enum value", v) } *e = ClaimClaimableBalanceResultCode(v) @@ -42101,11 +40913,8 @@ func (s ClaimClaimableBalanceResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimClaimableBalanceResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -42211,9 +41020,9 @@ func (u ClaimClaimableBalanceResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (ClaimClaimableBalanceResultCode) switch value '%d' is not valid for union ClaimClaimableBalanceResult", u.Code) } -var _ decoderFrom = (*ClaimClaimableBalanceResult)(nil) +var _ xdr.DecoderFrom = (*ClaimClaimableBalanceResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ClaimClaimableBalanceResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimClaimableBalanceResult: %w", ErrMaxDecodingDepthReached) @@ -42259,11 +41068,8 @@ func (s ClaimClaimableBalanceResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimClaimableBalanceResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -42297,6 +41103,10 @@ const ( BeginSponsoringFutureReservesResultCodeBeginSponsoringFutureReservesAlreadySponsored BeginSponsoringFutureReservesResultCode = -2 BeginSponsoringFutureReservesResultCodeBeginSponsoringFutureReservesRecursive BeginSponsoringFutureReservesResultCode = -3 ) +const ( + _BeginSponsoringFutureReservesResultCode_Min int32 = -3 + _BeginSponsoringFutureReservesResultCode_Max int32 = 0 +) var beginSponsoringFutureReservesResultCodeMap = map[int32]string{ 0: "BeginSponsoringFutureReservesResultCodeBeginSponsoringFutureReservesSuccess", @@ -42308,8 +41118,7 @@ var beginSponsoringFutureReservesResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for BeginSponsoringFutureReservesResultCode func (e BeginSponsoringFutureReservesResultCode) ValidEnum(v int32) bool { - _, ok := beginSponsoringFutureReservesResultCodeMap[v] - return ok + return v >= _BeginSponsoringFutureReservesResultCode_Min && v <= _BeginSponsoringFutureReservesResultCode_Max } // String returns the name of `e` @@ -42320,16 +41129,16 @@ func (e BeginSponsoringFutureReservesResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e BeginSponsoringFutureReservesResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := beginSponsoringFutureReservesResultCodeMap[int32(e)]; !ok { + if int32(e) < _BeginSponsoringFutureReservesResultCode_Min || int32(e) > _BeginSponsoringFutureReservesResultCode_Max { return fmt.Errorf("'%d' is not a valid BeginSponsoringFutureReservesResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*BeginSponsoringFutureReservesResultCode)(nil) +var _ xdr.DecoderFrom = (*BeginSponsoringFutureReservesResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *BeginSponsoringFutureReservesResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BeginSponsoringFutureReservesResultCode: %w", ErrMaxDecodingDepthReached) @@ -42339,7 +41148,7 @@ func (e *BeginSponsoringFutureReservesResultCode) DecodeFrom(d *xdr.Decoder, max if err != nil { return n, fmt.Errorf("decoding BeginSponsoringFutureReservesResultCode: %w", err) } - if _, ok := beginSponsoringFutureReservesResultCodeMap[v]; !ok { + if v < _BeginSponsoringFutureReservesResultCode_Min || v > _BeginSponsoringFutureReservesResultCode_Max { return n, fmt.Errorf("'%d' is not a valid BeginSponsoringFutureReservesResultCode enum value", v) } *e = BeginSponsoringFutureReservesResultCode(v) @@ -42356,11 +41165,8 @@ func (s BeginSponsoringFutureReservesResultCode) MarshalBinary() ([]byte, error) // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BeginSponsoringFutureReservesResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -42451,9 +41257,9 @@ func (u BeginSponsoringFutureReservesResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (BeginSponsoringFutureReservesResultCode) switch value '%d' is not valid for union BeginSponsoringFutureReservesResult", u.Code) } -var _ decoderFrom = (*BeginSponsoringFutureReservesResult)(nil) +var _ xdr.DecoderFrom = (*BeginSponsoringFutureReservesResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *BeginSponsoringFutureReservesResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BeginSponsoringFutureReservesResult: %w", ErrMaxDecodingDepthReached) @@ -42493,11 +41299,8 @@ func (s BeginSponsoringFutureReservesResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BeginSponsoringFutureReservesResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -42527,6 +41330,10 @@ const ( EndSponsoringFutureReservesResultCodeEndSponsoringFutureReservesSuccess EndSponsoringFutureReservesResultCode = 0 EndSponsoringFutureReservesResultCodeEndSponsoringFutureReservesNotSponsored EndSponsoringFutureReservesResultCode = -1 ) +const ( + _EndSponsoringFutureReservesResultCode_Min int32 = -1 + _EndSponsoringFutureReservesResultCode_Max int32 = 0 +) var endSponsoringFutureReservesResultCodeMap = map[int32]string{ 0: "EndSponsoringFutureReservesResultCodeEndSponsoringFutureReservesSuccess", @@ -42536,8 +41343,7 @@ var endSponsoringFutureReservesResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for EndSponsoringFutureReservesResultCode func (e EndSponsoringFutureReservesResultCode) ValidEnum(v int32) bool { - _, ok := endSponsoringFutureReservesResultCodeMap[v] - return ok + return v >= _EndSponsoringFutureReservesResultCode_Min && v <= _EndSponsoringFutureReservesResultCode_Max } // String returns the name of `e` @@ -42548,16 +41354,16 @@ func (e EndSponsoringFutureReservesResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e EndSponsoringFutureReservesResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := endSponsoringFutureReservesResultCodeMap[int32(e)]; !ok { + if int32(e) < _EndSponsoringFutureReservesResultCode_Min || int32(e) > _EndSponsoringFutureReservesResultCode_Max { return fmt.Errorf("'%d' is not a valid EndSponsoringFutureReservesResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*EndSponsoringFutureReservesResultCode)(nil) +var _ xdr.DecoderFrom = (*EndSponsoringFutureReservesResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *EndSponsoringFutureReservesResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding EndSponsoringFutureReservesResultCode: %w", ErrMaxDecodingDepthReached) @@ -42567,7 +41373,7 @@ func (e *EndSponsoringFutureReservesResultCode) DecodeFrom(d *xdr.Decoder, maxDe if err != nil { return n, fmt.Errorf("decoding EndSponsoringFutureReservesResultCode: %w", err) } - if _, ok := endSponsoringFutureReservesResultCodeMap[v]; !ok { + if v < _EndSponsoringFutureReservesResultCode_Min || v > _EndSponsoringFutureReservesResultCode_Max { return n, fmt.Errorf("'%d' is not a valid EndSponsoringFutureReservesResultCode enum value", v) } *e = EndSponsoringFutureReservesResultCode(v) @@ -42584,11 +41390,8 @@ func (s EndSponsoringFutureReservesResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *EndSponsoringFutureReservesResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -42663,9 +41466,9 @@ func (u EndSponsoringFutureReservesResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (EndSponsoringFutureReservesResultCode) switch value '%d' is not valid for union EndSponsoringFutureReservesResult", u.Code) } -var _ decoderFrom = (*EndSponsoringFutureReservesResult)(nil) +var _ xdr.DecoderFrom = (*EndSponsoringFutureReservesResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *EndSponsoringFutureReservesResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding EndSponsoringFutureReservesResult: %w", ErrMaxDecodingDepthReached) @@ -42699,11 +41502,8 @@ func (s EndSponsoringFutureReservesResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *EndSponsoringFutureReservesResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -42741,6 +41541,10 @@ const ( RevokeSponsorshipResultCodeRevokeSponsorshipOnlyTransferable RevokeSponsorshipResultCode = -4 RevokeSponsorshipResultCodeRevokeSponsorshipMalformed RevokeSponsorshipResultCode = -5 ) +const ( + _RevokeSponsorshipResultCode_Min int32 = -5 + _RevokeSponsorshipResultCode_Max int32 = 0 +) var revokeSponsorshipResultCodeMap = map[int32]string{ 0: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", @@ -42754,8 +41558,7 @@ var revokeSponsorshipResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for RevokeSponsorshipResultCode func (e RevokeSponsorshipResultCode) ValidEnum(v int32) bool { - _, ok := revokeSponsorshipResultCodeMap[v] - return ok + return v >= _RevokeSponsorshipResultCode_Min && v <= _RevokeSponsorshipResultCode_Max } // String returns the name of `e` @@ -42766,16 +41569,16 @@ func (e RevokeSponsorshipResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e RevokeSponsorshipResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := revokeSponsorshipResultCodeMap[int32(e)]; !ok { + if int32(e) < _RevokeSponsorshipResultCode_Min || int32(e) > _RevokeSponsorshipResultCode_Max { return fmt.Errorf("'%d' is not a valid RevokeSponsorshipResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*RevokeSponsorshipResultCode)(nil) +var _ xdr.DecoderFrom = (*RevokeSponsorshipResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *RevokeSponsorshipResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding RevokeSponsorshipResultCode: %w", ErrMaxDecodingDepthReached) @@ -42785,7 +41588,7 @@ func (e *RevokeSponsorshipResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) if err != nil { return n, fmt.Errorf("decoding RevokeSponsorshipResultCode: %w", err) } - if _, ok := revokeSponsorshipResultCodeMap[v]; !ok { + if v < _RevokeSponsorshipResultCode_Min || v > _RevokeSponsorshipResultCode_Max { return n, fmt.Errorf("'%d' is not a valid RevokeSponsorshipResultCode enum value", v) } *e = RevokeSponsorshipResultCode(v) @@ -42802,11 +41605,8 @@ func (s RevokeSponsorshipResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *RevokeSponsorshipResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -42912,9 +41712,9 @@ func (u RevokeSponsorshipResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (RevokeSponsorshipResultCode) switch value '%d' is not valid for union RevokeSponsorshipResult", u.Code) } -var _ decoderFrom = (*RevokeSponsorshipResult)(nil) +var _ xdr.DecoderFrom = (*RevokeSponsorshipResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *RevokeSponsorshipResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding RevokeSponsorshipResult: %w", ErrMaxDecodingDepthReached) @@ -42960,11 +41760,8 @@ func (s RevokeSponsorshipResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *RevokeSponsorshipResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -43000,6 +41797,10 @@ const ( ClawbackResultCodeClawbackNoTrust ClawbackResultCode = -3 ClawbackResultCodeClawbackUnderfunded ClawbackResultCode = -4 ) +const ( + _ClawbackResultCode_Min int32 = -4 + _ClawbackResultCode_Max int32 = 0 +) var clawbackResultCodeMap = map[int32]string{ 0: "ClawbackResultCodeClawbackSuccess", @@ -43012,8 +41813,7 @@ var clawbackResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ClawbackResultCode func (e ClawbackResultCode) ValidEnum(v int32) bool { - _, ok := clawbackResultCodeMap[v] - return ok + return v >= _ClawbackResultCode_Min && v <= _ClawbackResultCode_Max } // String returns the name of `e` @@ -43024,16 +41824,16 @@ func (e ClawbackResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e ClawbackResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := clawbackResultCodeMap[int32(e)]; !ok { + if int32(e) < _ClawbackResultCode_Min || int32(e) > _ClawbackResultCode_Max { return fmt.Errorf("'%d' is not a valid ClawbackResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ClawbackResultCode)(nil) +var _ xdr.DecoderFrom = (*ClawbackResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ClawbackResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClawbackResultCode: %w", ErrMaxDecodingDepthReached) @@ -43043,7 +41843,7 @@ func (e *ClawbackResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err if err != nil { return n, fmt.Errorf("decoding ClawbackResultCode: %w", err) } - if _, ok := clawbackResultCodeMap[v]; !ok { + if v < _ClawbackResultCode_Min || v > _ClawbackResultCode_Max { return n, fmt.Errorf("'%d' is not a valid ClawbackResultCode enum value", v) } *e = ClawbackResultCode(v) @@ -43060,11 +41860,8 @@ func (s ClawbackResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClawbackResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -43162,9 +41959,9 @@ func (u ClawbackResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (ClawbackResultCode) switch value '%d' is not valid for union ClawbackResult", u.Code) } -var _ decoderFrom = (*ClawbackResult)(nil) +var _ xdr.DecoderFrom = (*ClawbackResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ClawbackResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClawbackResult: %w", ErrMaxDecodingDepthReached) @@ -43207,11 +42004,8 @@ func (s ClawbackResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClawbackResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -43245,6 +42039,10 @@ const ( ClawbackClaimableBalanceResultCodeClawbackClaimableBalanceNotIssuer ClawbackClaimableBalanceResultCode = -2 ClawbackClaimableBalanceResultCodeClawbackClaimableBalanceNotClawbackEnabled ClawbackClaimableBalanceResultCode = -3 ) +const ( + _ClawbackClaimableBalanceResultCode_Min int32 = -3 + _ClawbackClaimableBalanceResultCode_Max int32 = 0 +) var clawbackClaimableBalanceResultCodeMap = map[int32]string{ 0: "ClawbackClaimableBalanceResultCodeClawbackClaimableBalanceSuccess", @@ -43256,8 +42054,7 @@ var clawbackClaimableBalanceResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ClawbackClaimableBalanceResultCode func (e ClawbackClaimableBalanceResultCode) ValidEnum(v int32) bool { - _, ok := clawbackClaimableBalanceResultCodeMap[v] - return ok + return v >= _ClawbackClaimableBalanceResultCode_Min && v <= _ClawbackClaimableBalanceResultCode_Max } // String returns the name of `e` @@ -43268,16 +42065,16 @@ func (e ClawbackClaimableBalanceResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e ClawbackClaimableBalanceResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := clawbackClaimableBalanceResultCodeMap[int32(e)]; !ok { + if int32(e) < _ClawbackClaimableBalanceResultCode_Min || int32(e) > _ClawbackClaimableBalanceResultCode_Max { return fmt.Errorf("'%d' is not a valid ClawbackClaimableBalanceResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ClawbackClaimableBalanceResultCode)(nil) +var _ xdr.DecoderFrom = (*ClawbackClaimableBalanceResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ClawbackClaimableBalanceResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClawbackClaimableBalanceResultCode: %w", ErrMaxDecodingDepthReached) @@ -43287,7 +42084,7 @@ func (e *ClawbackClaimableBalanceResultCode) DecodeFrom(d *xdr.Decoder, maxDepth if err != nil { return n, fmt.Errorf("decoding ClawbackClaimableBalanceResultCode: %w", err) } - if _, ok := clawbackClaimableBalanceResultCodeMap[v]; !ok { + if v < _ClawbackClaimableBalanceResultCode_Min || v > _ClawbackClaimableBalanceResultCode_Max { return n, fmt.Errorf("'%d' is not a valid ClawbackClaimableBalanceResultCode enum value", v) } *e = ClawbackClaimableBalanceResultCode(v) @@ -43304,11 +42101,8 @@ func (s ClawbackClaimableBalanceResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClawbackClaimableBalanceResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -43399,9 +42193,9 @@ func (u ClawbackClaimableBalanceResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (ClawbackClaimableBalanceResultCode) switch value '%d' is not valid for union ClawbackClaimableBalanceResult", u.Code) } -var _ decoderFrom = (*ClawbackClaimableBalanceResult)(nil) +var _ xdr.DecoderFrom = (*ClawbackClaimableBalanceResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ClawbackClaimableBalanceResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClawbackClaimableBalanceResult: %w", ErrMaxDecodingDepthReached) @@ -43441,11 +42235,8 @@ func (s ClawbackClaimableBalanceResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClawbackClaimableBalanceResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -43484,6 +42275,10 @@ const ( SetTrustLineFlagsResultCodeSetTrustLineFlagsInvalidState SetTrustLineFlagsResultCode = -4 SetTrustLineFlagsResultCodeSetTrustLineFlagsLowReserve SetTrustLineFlagsResultCode = -5 ) +const ( + _SetTrustLineFlagsResultCode_Min int32 = -5 + _SetTrustLineFlagsResultCode_Max int32 = 0 +) var setTrustLineFlagsResultCodeMap = map[int32]string{ 0: "SetTrustLineFlagsResultCodeSetTrustLineFlagsSuccess", @@ -43497,8 +42292,7 @@ var setTrustLineFlagsResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for SetTrustLineFlagsResultCode func (e SetTrustLineFlagsResultCode) ValidEnum(v int32) bool { - _, ok := setTrustLineFlagsResultCodeMap[v] - return ok + return v >= _SetTrustLineFlagsResultCode_Min && v <= _SetTrustLineFlagsResultCode_Max } // String returns the name of `e` @@ -43509,16 +42303,16 @@ func (e SetTrustLineFlagsResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e SetTrustLineFlagsResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := setTrustLineFlagsResultCodeMap[int32(e)]; !ok { + if int32(e) < _SetTrustLineFlagsResultCode_Min || int32(e) > _SetTrustLineFlagsResultCode_Max { return fmt.Errorf("'%d' is not a valid SetTrustLineFlagsResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*SetTrustLineFlagsResultCode)(nil) +var _ xdr.DecoderFrom = (*SetTrustLineFlagsResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *SetTrustLineFlagsResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SetTrustLineFlagsResultCode: %w", ErrMaxDecodingDepthReached) @@ -43528,7 +42322,7 @@ func (e *SetTrustLineFlagsResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) if err != nil { return n, fmt.Errorf("decoding SetTrustLineFlagsResultCode: %w", err) } - if _, ok := setTrustLineFlagsResultCodeMap[v]; !ok { + if v < _SetTrustLineFlagsResultCode_Min || v > _SetTrustLineFlagsResultCode_Max { return n, fmt.Errorf("'%d' is not a valid SetTrustLineFlagsResultCode enum value", v) } *e = SetTrustLineFlagsResultCode(v) @@ -43545,11 +42339,8 @@ func (s SetTrustLineFlagsResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SetTrustLineFlagsResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -43655,9 +42446,9 @@ func (u SetTrustLineFlagsResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (SetTrustLineFlagsResultCode) switch value '%d' is not valid for union SetTrustLineFlagsResult", u.Code) } -var _ decoderFrom = (*SetTrustLineFlagsResult)(nil) +var _ xdr.DecoderFrom = (*SetTrustLineFlagsResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *SetTrustLineFlagsResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SetTrustLineFlagsResult: %w", ErrMaxDecodingDepthReached) @@ -43703,11 +42494,8 @@ func (s SetTrustLineFlagsResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SetTrustLineFlagsResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -43753,6 +42541,10 @@ const ( LiquidityPoolDepositResultCodeLiquidityPoolDepositBadPrice LiquidityPoolDepositResultCode = -6 LiquidityPoolDepositResultCodeLiquidityPoolDepositPoolFull LiquidityPoolDepositResultCode = -7 ) +const ( + _LiquidityPoolDepositResultCode_Min int32 = -7 + _LiquidityPoolDepositResultCode_Max int32 = 0 +) var liquidityPoolDepositResultCodeMap = map[int32]string{ 0: "LiquidityPoolDepositResultCodeLiquidityPoolDepositSuccess", @@ -43768,8 +42560,7 @@ var liquidityPoolDepositResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for LiquidityPoolDepositResultCode func (e LiquidityPoolDepositResultCode) ValidEnum(v int32) bool { - _, ok := liquidityPoolDepositResultCodeMap[v] - return ok + return v >= _LiquidityPoolDepositResultCode_Min && v <= _LiquidityPoolDepositResultCode_Max } // String returns the name of `e` @@ -43780,16 +42571,16 @@ func (e LiquidityPoolDepositResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e LiquidityPoolDepositResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := liquidityPoolDepositResultCodeMap[int32(e)]; !ok { + if int32(e) < _LiquidityPoolDepositResultCode_Min || int32(e) > _LiquidityPoolDepositResultCode_Max { return fmt.Errorf("'%d' is not a valid LiquidityPoolDepositResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*LiquidityPoolDepositResultCode)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolDepositResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *LiquidityPoolDepositResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolDepositResultCode: %w", ErrMaxDecodingDepthReached) @@ -43799,7 +42590,7 @@ func (e *LiquidityPoolDepositResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uin if err != nil { return n, fmt.Errorf("decoding LiquidityPoolDepositResultCode: %w", err) } - if _, ok := liquidityPoolDepositResultCodeMap[v]; !ok { + if v < _LiquidityPoolDepositResultCode_Min || v > _LiquidityPoolDepositResultCode_Max { return n, fmt.Errorf("'%d' is not a valid LiquidityPoolDepositResultCode enum value", v) } *e = LiquidityPoolDepositResultCode(v) @@ -43816,11 +42607,8 @@ func (s LiquidityPoolDepositResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolDepositResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -43942,9 +42730,9 @@ func (u LiquidityPoolDepositResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (LiquidityPoolDepositResultCode) switch value '%d' is not valid for union LiquidityPoolDepositResult", u.Code) } -var _ decoderFrom = (*LiquidityPoolDepositResult)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolDepositResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LiquidityPoolDepositResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolDepositResult: %w", ErrMaxDecodingDepthReached) @@ -43996,11 +42784,8 @@ func (s LiquidityPoolDepositResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolDepositResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -44041,6 +42826,10 @@ const ( LiquidityPoolWithdrawResultCodeLiquidityPoolWithdrawLineFull LiquidityPoolWithdrawResultCode = -4 LiquidityPoolWithdrawResultCodeLiquidityPoolWithdrawUnderMinimum LiquidityPoolWithdrawResultCode = -5 ) +const ( + _LiquidityPoolWithdrawResultCode_Min int32 = -5 + _LiquidityPoolWithdrawResultCode_Max int32 = 0 +) var liquidityPoolWithdrawResultCodeMap = map[int32]string{ 0: "LiquidityPoolWithdrawResultCodeLiquidityPoolWithdrawSuccess", @@ -44054,8 +42843,7 @@ var liquidityPoolWithdrawResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for LiquidityPoolWithdrawResultCode func (e LiquidityPoolWithdrawResultCode) ValidEnum(v int32) bool { - _, ok := liquidityPoolWithdrawResultCodeMap[v] - return ok + return v >= _LiquidityPoolWithdrawResultCode_Min && v <= _LiquidityPoolWithdrawResultCode_Max } // String returns the name of `e` @@ -44066,16 +42854,16 @@ func (e LiquidityPoolWithdrawResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e LiquidityPoolWithdrawResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := liquidityPoolWithdrawResultCodeMap[int32(e)]; !ok { + if int32(e) < _LiquidityPoolWithdrawResultCode_Min || int32(e) > _LiquidityPoolWithdrawResultCode_Max { return fmt.Errorf("'%d' is not a valid LiquidityPoolWithdrawResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*LiquidityPoolWithdrawResultCode)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolWithdrawResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *LiquidityPoolWithdrawResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolWithdrawResultCode: %w", ErrMaxDecodingDepthReached) @@ -44085,7 +42873,7 @@ func (e *LiquidityPoolWithdrawResultCode) DecodeFrom(d *xdr.Decoder, maxDepth ui if err != nil { return n, fmt.Errorf("decoding LiquidityPoolWithdrawResultCode: %w", err) } - if _, ok := liquidityPoolWithdrawResultCodeMap[v]; !ok { + if v < _LiquidityPoolWithdrawResultCode_Min || v > _LiquidityPoolWithdrawResultCode_Max { return n, fmt.Errorf("'%d' is not a valid LiquidityPoolWithdrawResultCode enum value", v) } *e = LiquidityPoolWithdrawResultCode(v) @@ -44102,11 +42890,8 @@ func (s LiquidityPoolWithdrawResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolWithdrawResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -44212,9 +42997,9 @@ func (u LiquidityPoolWithdrawResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (LiquidityPoolWithdrawResultCode) switch value '%d' is not valid for union LiquidityPoolWithdrawResult", u.Code) } -var _ decoderFrom = (*LiquidityPoolWithdrawResult)(nil) +var _ xdr.DecoderFrom = (*LiquidityPoolWithdrawResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *LiquidityPoolWithdrawResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LiquidityPoolWithdrawResult: %w", ErrMaxDecodingDepthReached) @@ -44260,11 +43045,8 @@ func (s LiquidityPoolWithdrawResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LiquidityPoolWithdrawResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -44302,6 +43084,10 @@ const ( InvokeHostFunctionResultCodeInvokeHostFunctionEntryArchived InvokeHostFunctionResultCode = -4 InvokeHostFunctionResultCodeInvokeHostFunctionInsufficientRefundableFee InvokeHostFunctionResultCode = -5 ) +const ( + _InvokeHostFunctionResultCode_Min int32 = -5 + _InvokeHostFunctionResultCode_Max int32 = 0 +) var invokeHostFunctionResultCodeMap = map[int32]string{ 0: "InvokeHostFunctionResultCodeInvokeHostFunctionSuccess", @@ -44315,8 +43101,7 @@ var invokeHostFunctionResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for InvokeHostFunctionResultCode func (e InvokeHostFunctionResultCode) ValidEnum(v int32) bool { - _, ok := invokeHostFunctionResultCodeMap[v] - return ok + return v >= _InvokeHostFunctionResultCode_Min && v <= _InvokeHostFunctionResultCode_Max } // String returns the name of `e` @@ -44327,16 +43112,16 @@ func (e InvokeHostFunctionResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e InvokeHostFunctionResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := invokeHostFunctionResultCodeMap[int32(e)]; !ok { + if int32(e) < _InvokeHostFunctionResultCode_Min || int32(e) > _InvokeHostFunctionResultCode_Max { return fmt.Errorf("'%d' is not a valid InvokeHostFunctionResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*InvokeHostFunctionResultCode)(nil) +var _ xdr.DecoderFrom = (*InvokeHostFunctionResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *InvokeHostFunctionResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InvokeHostFunctionResultCode: %w", ErrMaxDecodingDepthReached) @@ -44346,7 +43131,7 @@ func (e *InvokeHostFunctionResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) if err != nil { return n, fmt.Errorf("decoding InvokeHostFunctionResultCode: %w", err) } - if _, ok := invokeHostFunctionResultCodeMap[v]; !ok { + if v < _InvokeHostFunctionResultCode_Min || v > _InvokeHostFunctionResultCode_Max { return n, fmt.Errorf("'%d' is not a valid InvokeHostFunctionResultCode enum value", v) } *e = InvokeHostFunctionResultCode(v) @@ -44363,11 +43148,8 @@ func (s InvokeHostFunctionResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InvokeHostFunctionResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -44453,25 +43235,19 @@ func NewInvokeHostFunctionResult(code InvokeHostFunctionResultCode, value interf // MustSuccess retrieves the Success value from the union, // panicing if the value is not set. func (u InvokeHostFunctionResult) MustSuccess() Hash { - val, ok := u.GetSuccess() - - if !ok { - panic("arm Success is not set") + if InvokeHostFunctionResultCode(u.Code) == InvokeHostFunctionResultCodeInvokeHostFunctionSuccess { + return *u.Success } - - return val + panic("arm Success is not set") } // GetSuccess retrieves the Success value from the union, // returning ok if the union's switch indicated the value is valid. func (u InvokeHostFunctionResult) GetSuccess() (result Hash, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "Success" { + if InvokeHostFunctionResultCode(u.Code) == InvokeHostFunctionResultCodeInvokeHostFunctionSuccess { result = *u.Success ok = true } - return } @@ -44506,9 +43282,9 @@ func (u InvokeHostFunctionResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (InvokeHostFunctionResultCode) switch value '%d' is not valid for union InvokeHostFunctionResult", u.Code) } -var _ decoderFrom = (*InvokeHostFunctionResult)(nil) +var _ xdr.DecoderFrom = (*InvokeHostFunctionResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *InvokeHostFunctionResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InvokeHostFunctionResult: %w", ErrMaxDecodingDepthReached) @@ -44523,7 +43299,9 @@ func (u *InvokeHostFunctionResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (in } switch InvokeHostFunctionResultCode(u.Code) { case InvokeHostFunctionResultCodeInvokeHostFunctionSuccess: - u.Success = new(Hash) + if u.Success == nil { + u.Success = new(Hash) + } nTmp, err = (*u.Success).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -44559,11 +43337,8 @@ func (s InvokeHostFunctionResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InvokeHostFunctionResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -44597,6 +43372,10 @@ const ( ExtendFootprintTtlResultCodeExtendFootprintTtlResourceLimitExceeded ExtendFootprintTtlResultCode = -2 ExtendFootprintTtlResultCodeExtendFootprintTtlInsufficientRefundableFee ExtendFootprintTtlResultCode = -3 ) +const ( + _ExtendFootprintTtlResultCode_Min int32 = -3 + _ExtendFootprintTtlResultCode_Max int32 = 0 +) var extendFootprintTtlResultCodeMap = map[int32]string{ 0: "ExtendFootprintTtlResultCodeExtendFootprintTtlSuccess", @@ -44608,8 +43387,7 @@ var extendFootprintTtlResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ExtendFootprintTtlResultCode func (e ExtendFootprintTtlResultCode) ValidEnum(v int32) bool { - _, ok := extendFootprintTtlResultCodeMap[v] - return ok + return v >= _ExtendFootprintTtlResultCode_Min && v <= _ExtendFootprintTtlResultCode_Max } // String returns the name of `e` @@ -44620,16 +43398,16 @@ func (e ExtendFootprintTtlResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e ExtendFootprintTtlResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := extendFootprintTtlResultCodeMap[int32(e)]; !ok { + if int32(e) < _ExtendFootprintTtlResultCode_Min || int32(e) > _ExtendFootprintTtlResultCode_Max { return fmt.Errorf("'%d' is not a valid ExtendFootprintTtlResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ExtendFootprintTtlResultCode)(nil) +var _ xdr.DecoderFrom = (*ExtendFootprintTtlResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ExtendFootprintTtlResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ExtendFootprintTtlResultCode: %w", ErrMaxDecodingDepthReached) @@ -44639,7 +43417,7 @@ func (e *ExtendFootprintTtlResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) if err != nil { return n, fmt.Errorf("decoding ExtendFootprintTtlResultCode: %w", err) } - if _, ok := extendFootprintTtlResultCodeMap[v]; !ok { + if v < _ExtendFootprintTtlResultCode_Min || v > _ExtendFootprintTtlResultCode_Max { return n, fmt.Errorf("'%d' is not a valid ExtendFootprintTtlResultCode enum value", v) } *e = ExtendFootprintTtlResultCode(v) @@ -44656,11 +43434,8 @@ func (s ExtendFootprintTtlResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ExtendFootprintTtlResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -44750,9 +43525,9 @@ func (u ExtendFootprintTtlResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (ExtendFootprintTtlResultCode) switch value '%d' is not valid for union ExtendFootprintTtlResult", u.Code) } -var _ decoderFrom = (*ExtendFootprintTtlResult)(nil) +var _ xdr.DecoderFrom = (*ExtendFootprintTtlResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ExtendFootprintTtlResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ExtendFootprintTtlResult: %w", ErrMaxDecodingDepthReached) @@ -44792,11 +43567,8 @@ func (s ExtendFootprintTtlResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ExtendFootprintTtlResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -44830,6 +43602,10 @@ const ( RestoreFootprintResultCodeRestoreFootprintResourceLimitExceeded RestoreFootprintResultCode = -2 RestoreFootprintResultCodeRestoreFootprintInsufficientRefundableFee RestoreFootprintResultCode = -3 ) +const ( + _RestoreFootprintResultCode_Min int32 = -3 + _RestoreFootprintResultCode_Max int32 = 0 +) var restoreFootprintResultCodeMap = map[int32]string{ 0: "RestoreFootprintResultCodeRestoreFootprintSuccess", @@ -44841,8 +43617,7 @@ var restoreFootprintResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for RestoreFootprintResultCode func (e RestoreFootprintResultCode) ValidEnum(v int32) bool { - _, ok := restoreFootprintResultCodeMap[v] - return ok + return v >= _RestoreFootprintResultCode_Min && v <= _RestoreFootprintResultCode_Max } // String returns the name of `e` @@ -44853,16 +43628,16 @@ func (e RestoreFootprintResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e RestoreFootprintResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := restoreFootprintResultCodeMap[int32(e)]; !ok { + if int32(e) < _RestoreFootprintResultCode_Min || int32(e) > _RestoreFootprintResultCode_Max { return fmt.Errorf("'%d' is not a valid RestoreFootprintResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*RestoreFootprintResultCode)(nil) +var _ xdr.DecoderFrom = (*RestoreFootprintResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *RestoreFootprintResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding RestoreFootprintResultCode: %w", ErrMaxDecodingDepthReached) @@ -44872,7 +43647,7 @@ func (e *RestoreFootprintResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) ( if err != nil { return n, fmt.Errorf("decoding RestoreFootprintResultCode: %w", err) } - if _, ok := restoreFootprintResultCodeMap[v]; !ok { + if v < _RestoreFootprintResultCode_Min || v > _RestoreFootprintResultCode_Max { return n, fmt.Errorf("'%d' is not a valid RestoreFootprintResultCode enum value", v) } *e = RestoreFootprintResultCode(v) @@ -44889,11 +43664,8 @@ func (s RestoreFootprintResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *RestoreFootprintResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -44983,9 +43755,9 @@ func (u RestoreFootprintResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (RestoreFootprintResultCode) switch value '%d' is not valid for union RestoreFootprintResult", u.Code) } -var _ decoderFrom = (*RestoreFootprintResult)(nil) +var _ xdr.DecoderFrom = (*RestoreFootprintResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *RestoreFootprintResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding RestoreFootprintResult: %w", ErrMaxDecodingDepthReached) @@ -45025,11 +43797,8 @@ func (s RestoreFootprintResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *RestoreFootprintResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -45067,6 +43836,10 @@ const ( OperationResultCodeOpExceededWorkLimit OperationResultCode = -5 OperationResultCodeOpTooManySponsoring OperationResultCode = -6 ) +const ( + _OperationResultCode_Min int32 = -6 + _OperationResultCode_Max int32 = 0 +) var operationResultCodeMap = map[int32]string{ 0: "OperationResultCodeOpInner", @@ -45081,8 +43854,7 @@ var operationResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for OperationResultCode func (e OperationResultCode) ValidEnum(v int32) bool { - _, ok := operationResultCodeMap[v] - return ok + return v >= _OperationResultCode_Min && v <= _OperationResultCode_Max } // String returns the name of `e` @@ -45093,16 +43865,16 @@ func (e OperationResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e OperationResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := operationResultCodeMap[int32(e)]; !ok { + if int32(e) < _OperationResultCode_Min || int32(e) > _OperationResultCode_Max { return fmt.Errorf("'%d' is not a valid OperationResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*OperationResultCode)(nil) +var _ xdr.DecoderFrom = (*OperationResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *OperationResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding OperationResultCode: %w", ErrMaxDecodingDepthReached) @@ -45112,7 +43884,7 @@ func (e *OperationResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er if err != nil { return n, fmt.Errorf("decoding OperationResultCode: %w", err) } - if _, ok := operationResultCodeMap[v]; !ok { + if v < _OperationResultCode_Min || v > _OperationResultCode_Max { return n, fmt.Errorf("'%d' is not a valid OperationResultCode enum value", v) } *e = OperationResultCode(v) @@ -45129,11 +43901,8 @@ func (s OperationResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *OperationResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -45505,675 +44274,513 @@ func NewOperationResultTr(aType OperationType, value interface{}) (result Operat // MustCreateAccountResult retrieves the CreateAccountResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustCreateAccountResult() CreateAccountResult { - val, ok := u.GetCreateAccountResult() - - if !ok { - panic("arm CreateAccountResult is not set") + if OperationType(u.Type) == OperationTypeCreateAccount { + return *u.CreateAccountResult } - - return val + panic("arm CreateAccountResult is not set") } // GetCreateAccountResult retrieves the CreateAccountResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetCreateAccountResult() (result CreateAccountResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "CreateAccountResult" { + if OperationType(u.Type) == OperationTypeCreateAccount { result = *u.CreateAccountResult ok = true } - return } // MustPaymentResult retrieves the PaymentResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustPaymentResult() PaymentResult { - val, ok := u.GetPaymentResult() - - if !ok { - panic("arm PaymentResult is not set") + if OperationType(u.Type) == OperationTypePayment { + return *u.PaymentResult } - - return val + panic("arm PaymentResult is not set") } // GetPaymentResult retrieves the PaymentResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetPaymentResult() (result PaymentResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "PaymentResult" { + if OperationType(u.Type) == OperationTypePayment { result = *u.PaymentResult ok = true } - return } // MustPathPaymentStrictReceiveResult retrieves the PathPaymentStrictReceiveResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustPathPaymentStrictReceiveResult() PathPaymentStrictReceiveResult { - val, ok := u.GetPathPaymentStrictReceiveResult() - - if !ok { - panic("arm PathPaymentStrictReceiveResult is not set") + if OperationType(u.Type) == OperationTypePathPaymentStrictReceive { + return *u.PathPaymentStrictReceiveResult } - - return val + panic("arm PathPaymentStrictReceiveResult is not set") } // GetPathPaymentStrictReceiveResult retrieves the PathPaymentStrictReceiveResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetPathPaymentStrictReceiveResult() (result PathPaymentStrictReceiveResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "PathPaymentStrictReceiveResult" { + if OperationType(u.Type) == OperationTypePathPaymentStrictReceive { result = *u.PathPaymentStrictReceiveResult ok = true } - return } // MustManageSellOfferResult retrieves the ManageSellOfferResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustManageSellOfferResult() ManageSellOfferResult { - val, ok := u.GetManageSellOfferResult() - - if !ok { - panic("arm ManageSellOfferResult is not set") + if OperationType(u.Type) == OperationTypeManageSellOffer { + return *u.ManageSellOfferResult } - - return val + panic("arm ManageSellOfferResult is not set") } // GetManageSellOfferResult retrieves the ManageSellOfferResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetManageSellOfferResult() (result ManageSellOfferResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ManageSellOfferResult" { + if OperationType(u.Type) == OperationTypeManageSellOffer { result = *u.ManageSellOfferResult ok = true } - return } // MustCreatePassiveSellOfferResult retrieves the CreatePassiveSellOfferResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustCreatePassiveSellOfferResult() ManageSellOfferResult { - val, ok := u.GetCreatePassiveSellOfferResult() - - if !ok { - panic("arm CreatePassiveSellOfferResult is not set") + if OperationType(u.Type) == OperationTypeCreatePassiveSellOffer { + return *u.CreatePassiveSellOfferResult } - - return val + panic("arm CreatePassiveSellOfferResult is not set") } // GetCreatePassiveSellOfferResult retrieves the CreatePassiveSellOfferResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetCreatePassiveSellOfferResult() (result ManageSellOfferResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "CreatePassiveSellOfferResult" { + if OperationType(u.Type) == OperationTypeCreatePassiveSellOffer { result = *u.CreatePassiveSellOfferResult ok = true } - return } // MustSetOptionsResult retrieves the SetOptionsResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustSetOptionsResult() SetOptionsResult { - val, ok := u.GetSetOptionsResult() - - if !ok { - panic("arm SetOptionsResult is not set") + if OperationType(u.Type) == OperationTypeSetOptions { + return *u.SetOptionsResult } - - return val + panic("arm SetOptionsResult is not set") } // GetSetOptionsResult retrieves the SetOptionsResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetSetOptionsResult() (result SetOptionsResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "SetOptionsResult" { + if OperationType(u.Type) == OperationTypeSetOptions { result = *u.SetOptionsResult ok = true } - return } // MustChangeTrustResult retrieves the ChangeTrustResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustChangeTrustResult() ChangeTrustResult { - val, ok := u.GetChangeTrustResult() - - if !ok { - panic("arm ChangeTrustResult is not set") + if OperationType(u.Type) == OperationTypeChangeTrust { + return *u.ChangeTrustResult } - - return val + panic("arm ChangeTrustResult is not set") } // GetChangeTrustResult retrieves the ChangeTrustResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetChangeTrustResult() (result ChangeTrustResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ChangeTrustResult" { + if OperationType(u.Type) == OperationTypeChangeTrust { result = *u.ChangeTrustResult ok = true } - return } // MustAllowTrustResult retrieves the AllowTrustResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustAllowTrustResult() AllowTrustResult { - val, ok := u.GetAllowTrustResult() - - if !ok { - panic("arm AllowTrustResult is not set") + if OperationType(u.Type) == OperationTypeAllowTrust { + return *u.AllowTrustResult } - - return val + panic("arm AllowTrustResult is not set") } // GetAllowTrustResult retrieves the AllowTrustResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetAllowTrustResult() (result AllowTrustResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AllowTrustResult" { + if OperationType(u.Type) == OperationTypeAllowTrust { result = *u.AllowTrustResult ok = true } - return } // MustAccountMergeResult retrieves the AccountMergeResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustAccountMergeResult() AccountMergeResult { - val, ok := u.GetAccountMergeResult() - - if !ok { - panic("arm AccountMergeResult is not set") + if OperationType(u.Type) == OperationTypeAccountMerge { + return *u.AccountMergeResult } - - return val + panic("arm AccountMergeResult is not set") } // GetAccountMergeResult retrieves the AccountMergeResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetAccountMergeResult() (result AccountMergeResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "AccountMergeResult" { + if OperationType(u.Type) == OperationTypeAccountMerge { result = *u.AccountMergeResult ok = true } - return } // MustInflationResult retrieves the InflationResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustInflationResult() InflationResult { - val, ok := u.GetInflationResult() - - if !ok { - panic("arm InflationResult is not set") + if OperationType(u.Type) == OperationTypeInflation { + return *u.InflationResult } - - return val + panic("arm InflationResult is not set") } // GetInflationResult retrieves the InflationResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetInflationResult() (result InflationResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "InflationResult" { + if OperationType(u.Type) == OperationTypeInflation { result = *u.InflationResult ok = true } - return } // MustManageDataResult retrieves the ManageDataResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustManageDataResult() ManageDataResult { - val, ok := u.GetManageDataResult() - - if !ok { - panic("arm ManageDataResult is not set") + if OperationType(u.Type) == OperationTypeManageData { + return *u.ManageDataResult } - - return val + panic("arm ManageDataResult is not set") } // GetManageDataResult retrieves the ManageDataResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetManageDataResult() (result ManageDataResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ManageDataResult" { + if OperationType(u.Type) == OperationTypeManageData { result = *u.ManageDataResult ok = true } - return } // MustBumpSeqResult retrieves the BumpSeqResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustBumpSeqResult() BumpSequenceResult { - val, ok := u.GetBumpSeqResult() - - if !ok { - panic("arm BumpSeqResult is not set") + if OperationType(u.Type) == OperationTypeBumpSequence { + return *u.BumpSeqResult } - - return val + panic("arm BumpSeqResult is not set") } // GetBumpSeqResult retrieves the BumpSeqResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetBumpSeqResult() (result BumpSequenceResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "BumpSeqResult" { + if OperationType(u.Type) == OperationTypeBumpSequence { result = *u.BumpSeqResult ok = true } - return } // MustManageBuyOfferResult retrieves the ManageBuyOfferResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustManageBuyOfferResult() ManageBuyOfferResult { - val, ok := u.GetManageBuyOfferResult() - - if !ok { - panic("arm ManageBuyOfferResult is not set") + if OperationType(u.Type) == OperationTypeManageBuyOffer { + return *u.ManageBuyOfferResult } - - return val + panic("arm ManageBuyOfferResult is not set") } // GetManageBuyOfferResult retrieves the ManageBuyOfferResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetManageBuyOfferResult() (result ManageBuyOfferResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ManageBuyOfferResult" { + if OperationType(u.Type) == OperationTypeManageBuyOffer { result = *u.ManageBuyOfferResult ok = true } - return } // MustPathPaymentStrictSendResult retrieves the PathPaymentStrictSendResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustPathPaymentStrictSendResult() PathPaymentStrictSendResult { - val, ok := u.GetPathPaymentStrictSendResult() - - if !ok { - panic("arm PathPaymentStrictSendResult is not set") + if OperationType(u.Type) == OperationTypePathPaymentStrictSend { + return *u.PathPaymentStrictSendResult } - - return val + panic("arm PathPaymentStrictSendResult is not set") } // GetPathPaymentStrictSendResult retrieves the PathPaymentStrictSendResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetPathPaymentStrictSendResult() (result PathPaymentStrictSendResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "PathPaymentStrictSendResult" { + if OperationType(u.Type) == OperationTypePathPaymentStrictSend { result = *u.PathPaymentStrictSendResult ok = true } - return } // MustCreateClaimableBalanceResult retrieves the CreateClaimableBalanceResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustCreateClaimableBalanceResult() CreateClaimableBalanceResult { - val, ok := u.GetCreateClaimableBalanceResult() - - if !ok { - panic("arm CreateClaimableBalanceResult is not set") + if OperationType(u.Type) == OperationTypeCreateClaimableBalance { + return *u.CreateClaimableBalanceResult } - - return val + panic("arm CreateClaimableBalanceResult is not set") } // GetCreateClaimableBalanceResult retrieves the CreateClaimableBalanceResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetCreateClaimableBalanceResult() (result CreateClaimableBalanceResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "CreateClaimableBalanceResult" { + if OperationType(u.Type) == OperationTypeCreateClaimableBalance { result = *u.CreateClaimableBalanceResult ok = true } - return } // MustClaimClaimableBalanceResult retrieves the ClaimClaimableBalanceResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustClaimClaimableBalanceResult() ClaimClaimableBalanceResult { - val, ok := u.GetClaimClaimableBalanceResult() - - if !ok { - panic("arm ClaimClaimableBalanceResult is not set") + if OperationType(u.Type) == OperationTypeClaimClaimableBalance { + return *u.ClaimClaimableBalanceResult } - - return val + panic("arm ClaimClaimableBalanceResult is not set") } // GetClaimClaimableBalanceResult retrieves the ClaimClaimableBalanceResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetClaimClaimableBalanceResult() (result ClaimClaimableBalanceResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ClaimClaimableBalanceResult" { + if OperationType(u.Type) == OperationTypeClaimClaimableBalance { result = *u.ClaimClaimableBalanceResult ok = true } - return } // MustBeginSponsoringFutureReservesResult retrieves the BeginSponsoringFutureReservesResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustBeginSponsoringFutureReservesResult() BeginSponsoringFutureReservesResult { - val, ok := u.GetBeginSponsoringFutureReservesResult() - - if !ok { - panic("arm BeginSponsoringFutureReservesResult is not set") + if OperationType(u.Type) == OperationTypeBeginSponsoringFutureReserves { + return *u.BeginSponsoringFutureReservesResult } - - return val + panic("arm BeginSponsoringFutureReservesResult is not set") } // GetBeginSponsoringFutureReservesResult retrieves the BeginSponsoringFutureReservesResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetBeginSponsoringFutureReservesResult() (result BeginSponsoringFutureReservesResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "BeginSponsoringFutureReservesResult" { + if OperationType(u.Type) == OperationTypeBeginSponsoringFutureReserves { result = *u.BeginSponsoringFutureReservesResult ok = true } - return } // MustEndSponsoringFutureReservesResult retrieves the EndSponsoringFutureReservesResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustEndSponsoringFutureReservesResult() EndSponsoringFutureReservesResult { - val, ok := u.GetEndSponsoringFutureReservesResult() - - if !ok { - panic("arm EndSponsoringFutureReservesResult is not set") + if OperationType(u.Type) == OperationTypeEndSponsoringFutureReserves { + return *u.EndSponsoringFutureReservesResult } - - return val + panic("arm EndSponsoringFutureReservesResult is not set") } // GetEndSponsoringFutureReservesResult retrieves the EndSponsoringFutureReservesResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetEndSponsoringFutureReservesResult() (result EndSponsoringFutureReservesResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "EndSponsoringFutureReservesResult" { + if OperationType(u.Type) == OperationTypeEndSponsoringFutureReserves { result = *u.EndSponsoringFutureReservesResult ok = true } - return } // MustRevokeSponsorshipResult retrieves the RevokeSponsorshipResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustRevokeSponsorshipResult() RevokeSponsorshipResult { - val, ok := u.GetRevokeSponsorshipResult() - - if !ok { - panic("arm RevokeSponsorshipResult is not set") + if OperationType(u.Type) == OperationTypeRevokeSponsorship { + return *u.RevokeSponsorshipResult } - - return val + panic("arm RevokeSponsorshipResult is not set") } // GetRevokeSponsorshipResult retrieves the RevokeSponsorshipResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetRevokeSponsorshipResult() (result RevokeSponsorshipResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "RevokeSponsorshipResult" { + if OperationType(u.Type) == OperationTypeRevokeSponsorship { result = *u.RevokeSponsorshipResult ok = true } - return } // MustClawbackResult retrieves the ClawbackResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustClawbackResult() ClawbackResult { - val, ok := u.GetClawbackResult() - - if !ok { - panic("arm ClawbackResult is not set") + if OperationType(u.Type) == OperationTypeClawback { + return *u.ClawbackResult } - - return val + panic("arm ClawbackResult is not set") } // GetClawbackResult retrieves the ClawbackResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetClawbackResult() (result ClawbackResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ClawbackResult" { + if OperationType(u.Type) == OperationTypeClawback { result = *u.ClawbackResult ok = true } - return } // MustClawbackClaimableBalanceResult retrieves the ClawbackClaimableBalanceResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustClawbackClaimableBalanceResult() ClawbackClaimableBalanceResult { - val, ok := u.GetClawbackClaimableBalanceResult() - - if !ok { - panic("arm ClawbackClaimableBalanceResult is not set") + if OperationType(u.Type) == OperationTypeClawbackClaimableBalance { + return *u.ClawbackClaimableBalanceResult } - - return val + panic("arm ClawbackClaimableBalanceResult is not set") } // GetClawbackClaimableBalanceResult retrieves the ClawbackClaimableBalanceResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetClawbackClaimableBalanceResult() (result ClawbackClaimableBalanceResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ClawbackClaimableBalanceResult" { + if OperationType(u.Type) == OperationTypeClawbackClaimableBalance { result = *u.ClawbackClaimableBalanceResult ok = true } - return } // MustSetTrustLineFlagsResult retrieves the SetTrustLineFlagsResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustSetTrustLineFlagsResult() SetTrustLineFlagsResult { - val, ok := u.GetSetTrustLineFlagsResult() - - if !ok { - panic("arm SetTrustLineFlagsResult is not set") + if OperationType(u.Type) == OperationTypeSetTrustLineFlags { + return *u.SetTrustLineFlagsResult } - - return val + panic("arm SetTrustLineFlagsResult is not set") } // GetSetTrustLineFlagsResult retrieves the SetTrustLineFlagsResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetSetTrustLineFlagsResult() (result SetTrustLineFlagsResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "SetTrustLineFlagsResult" { + if OperationType(u.Type) == OperationTypeSetTrustLineFlags { result = *u.SetTrustLineFlagsResult ok = true } - return } // MustLiquidityPoolDepositResult retrieves the LiquidityPoolDepositResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustLiquidityPoolDepositResult() LiquidityPoolDepositResult { - val, ok := u.GetLiquidityPoolDepositResult() - - if !ok { - panic("arm LiquidityPoolDepositResult is not set") + if OperationType(u.Type) == OperationTypeLiquidityPoolDeposit { + return *u.LiquidityPoolDepositResult } - - return val + panic("arm LiquidityPoolDepositResult is not set") } // GetLiquidityPoolDepositResult retrieves the LiquidityPoolDepositResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetLiquidityPoolDepositResult() (result LiquidityPoolDepositResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LiquidityPoolDepositResult" { + if OperationType(u.Type) == OperationTypeLiquidityPoolDeposit { result = *u.LiquidityPoolDepositResult ok = true } - return } // MustLiquidityPoolWithdrawResult retrieves the LiquidityPoolWithdrawResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustLiquidityPoolWithdrawResult() LiquidityPoolWithdrawResult { - val, ok := u.GetLiquidityPoolWithdrawResult() - - if !ok { - panic("arm LiquidityPoolWithdrawResult is not set") + if OperationType(u.Type) == OperationTypeLiquidityPoolWithdraw { + return *u.LiquidityPoolWithdrawResult } - - return val + panic("arm LiquidityPoolWithdrawResult is not set") } // GetLiquidityPoolWithdrawResult retrieves the LiquidityPoolWithdrawResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetLiquidityPoolWithdrawResult() (result LiquidityPoolWithdrawResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LiquidityPoolWithdrawResult" { + if OperationType(u.Type) == OperationTypeLiquidityPoolWithdraw { result = *u.LiquidityPoolWithdrawResult ok = true } - return } // MustInvokeHostFunctionResult retrieves the InvokeHostFunctionResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustInvokeHostFunctionResult() InvokeHostFunctionResult { - val, ok := u.GetInvokeHostFunctionResult() - - if !ok { - panic("arm InvokeHostFunctionResult is not set") + if OperationType(u.Type) == OperationTypeInvokeHostFunction { + return *u.InvokeHostFunctionResult } - - return val + panic("arm InvokeHostFunctionResult is not set") } // GetInvokeHostFunctionResult retrieves the InvokeHostFunctionResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetInvokeHostFunctionResult() (result InvokeHostFunctionResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "InvokeHostFunctionResult" { + if OperationType(u.Type) == OperationTypeInvokeHostFunction { result = *u.InvokeHostFunctionResult ok = true } - return } // MustExtendFootprintTtlResult retrieves the ExtendFootprintTtlResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustExtendFootprintTtlResult() ExtendFootprintTtlResult { - val, ok := u.GetExtendFootprintTtlResult() - - if !ok { - panic("arm ExtendFootprintTtlResult is not set") + if OperationType(u.Type) == OperationTypeExtendFootprintTtl { + return *u.ExtendFootprintTtlResult } - - return val + panic("arm ExtendFootprintTtlResult is not set") } // GetExtendFootprintTtlResult retrieves the ExtendFootprintTtlResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetExtendFootprintTtlResult() (result ExtendFootprintTtlResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ExtendFootprintTtlResult" { + if OperationType(u.Type) == OperationTypeExtendFootprintTtl { result = *u.ExtendFootprintTtlResult ok = true } - return } // MustRestoreFootprintResult retrieves the RestoreFootprintResult value from the union, // panicing if the value is not set. func (u OperationResultTr) MustRestoreFootprintResult() RestoreFootprintResult { - val, ok := u.GetRestoreFootprintResult() - - if !ok { - panic("arm RestoreFootprintResult is not set") + if OperationType(u.Type) == OperationTypeRestoreFootprint { + return *u.RestoreFootprintResult } - - return val + panic("arm RestoreFootprintResult is not set") } // GetRestoreFootprintResult retrieves the RestoreFootprintResult value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResultTr) GetRestoreFootprintResult() (result RestoreFootprintResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "RestoreFootprintResult" { + if OperationType(u.Type) == OperationTypeRestoreFootprint { result = *u.RestoreFootprintResult ok = true } - return } @@ -46323,9 +44930,9 @@ func (u OperationResultTr) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (OperationType) switch value '%d' is not valid for union OperationResultTr", u.Type) } -var _ decoderFrom = (*OperationResultTr)(nil) +var _ xdr.DecoderFrom = (*OperationResultTr)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding OperationResultTr: %w", ErrMaxDecodingDepthReached) @@ -46340,7 +44947,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } switch OperationType(u.Type) { case OperationTypeCreateAccount: - u.CreateAccountResult = new(CreateAccountResult) + if u.CreateAccountResult == nil { + u.CreateAccountResult = new(CreateAccountResult) + } nTmp, err = (*u.CreateAccountResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46348,7 +44957,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypePayment: - u.PaymentResult = new(PaymentResult) + if u.PaymentResult == nil { + u.PaymentResult = new(PaymentResult) + } nTmp, err = (*u.PaymentResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46356,7 +44967,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypePathPaymentStrictReceive: - u.PathPaymentStrictReceiveResult = new(PathPaymentStrictReceiveResult) + if u.PathPaymentStrictReceiveResult == nil { + u.PathPaymentStrictReceiveResult = new(PathPaymentStrictReceiveResult) + } nTmp, err = (*u.PathPaymentStrictReceiveResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46364,7 +44977,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeManageSellOffer: - u.ManageSellOfferResult = new(ManageSellOfferResult) + if u.ManageSellOfferResult == nil { + u.ManageSellOfferResult = new(ManageSellOfferResult) + } nTmp, err = (*u.ManageSellOfferResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46372,7 +44987,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeCreatePassiveSellOffer: - u.CreatePassiveSellOfferResult = new(ManageSellOfferResult) + if u.CreatePassiveSellOfferResult == nil { + u.CreatePassiveSellOfferResult = new(ManageSellOfferResult) + } nTmp, err = (*u.CreatePassiveSellOfferResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46380,7 +44997,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeSetOptions: - u.SetOptionsResult = new(SetOptionsResult) + if u.SetOptionsResult == nil { + u.SetOptionsResult = new(SetOptionsResult) + } nTmp, err = (*u.SetOptionsResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46388,7 +45007,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeChangeTrust: - u.ChangeTrustResult = new(ChangeTrustResult) + if u.ChangeTrustResult == nil { + u.ChangeTrustResult = new(ChangeTrustResult) + } nTmp, err = (*u.ChangeTrustResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46396,7 +45017,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeAllowTrust: - u.AllowTrustResult = new(AllowTrustResult) + if u.AllowTrustResult == nil { + u.AllowTrustResult = new(AllowTrustResult) + } nTmp, err = (*u.AllowTrustResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46404,7 +45027,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeAccountMerge: - u.AccountMergeResult = new(AccountMergeResult) + if u.AccountMergeResult == nil { + u.AccountMergeResult = new(AccountMergeResult) + } nTmp, err = (*u.AccountMergeResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46412,7 +45037,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeInflation: - u.InflationResult = new(InflationResult) + if u.InflationResult == nil { + u.InflationResult = new(InflationResult) + } nTmp, err = (*u.InflationResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46420,7 +45047,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeManageData: - u.ManageDataResult = new(ManageDataResult) + if u.ManageDataResult == nil { + u.ManageDataResult = new(ManageDataResult) + } nTmp, err = (*u.ManageDataResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46428,7 +45057,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeBumpSequence: - u.BumpSeqResult = new(BumpSequenceResult) + if u.BumpSeqResult == nil { + u.BumpSeqResult = new(BumpSequenceResult) + } nTmp, err = (*u.BumpSeqResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46436,7 +45067,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeManageBuyOffer: - u.ManageBuyOfferResult = new(ManageBuyOfferResult) + if u.ManageBuyOfferResult == nil { + u.ManageBuyOfferResult = new(ManageBuyOfferResult) + } nTmp, err = (*u.ManageBuyOfferResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46444,7 +45077,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypePathPaymentStrictSend: - u.PathPaymentStrictSendResult = new(PathPaymentStrictSendResult) + if u.PathPaymentStrictSendResult == nil { + u.PathPaymentStrictSendResult = new(PathPaymentStrictSendResult) + } nTmp, err = (*u.PathPaymentStrictSendResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46452,7 +45087,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeCreateClaimableBalance: - u.CreateClaimableBalanceResult = new(CreateClaimableBalanceResult) + if u.CreateClaimableBalanceResult == nil { + u.CreateClaimableBalanceResult = new(CreateClaimableBalanceResult) + } nTmp, err = (*u.CreateClaimableBalanceResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46460,7 +45097,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeClaimClaimableBalance: - u.ClaimClaimableBalanceResult = new(ClaimClaimableBalanceResult) + if u.ClaimClaimableBalanceResult == nil { + u.ClaimClaimableBalanceResult = new(ClaimClaimableBalanceResult) + } nTmp, err = (*u.ClaimClaimableBalanceResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46468,7 +45107,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeBeginSponsoringFutureReserves: - u.BeginSponsoringFutureReservesResult = new(BeginSponsoringFutureReservesResult) + if u.BeginSponsoringFutureReservesResult == nil { + u.BeginSponsoringFutureReservesResult = new(BeginSponsoringFutureReservesResult) + } nTmp, err = (*u.BeginSponsoringFutureReservesResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46476,7 +45117,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeEndSponsoringFutureReserves: - u.EndSponsoringFutureReservesResult = new(EndSponsoringFutureReservesResult) + if u.EndSponsoringFutureReservesResult == nil { + u.EndSponsoringFutureReservesResult = new(EndSponsoringFutureReservesResult) + } nTmp, err = (*u.EndSponsoringFutureReservesResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46484,7 +45127,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeRevokeSponsorship: - u.RevokeSponsorshipResult = new(RevokeSponsorshipResult) + if u.RevokeSponsorshipResult == nil { + u.RevokeSponsorshipResult = new(RevokeSponsorshipResult) + } nTmp, err = (*u.RevokeSponsorshipResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46492,7 +45137,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeClawback: - u.ClawbackResult = new(ClawbackResult) + if u.ClawbackResult == nil { + u.ClawbackResult = new(ClawbackResult) + } nTmp, err = (*u.ClawbackResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46500,7 +45147,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeClawbackClaimableBalance: - u.ClawbackClaimableBalanceResult = new(ClawbackClaimableBalanceResult) + if u.ClawbackClaimableBalanceResult == nil { + u.ClawbackClaimableBalanceResult = new(ClawbackClaimableBalanceResult) + } nTmp, err = (*u.ClawbackClaimableBalanceResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46508,7 +45157,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeSetTrustLineFlags: - u.SetTrustLineFlagsResult = new(SetTrustLineFlagsResult) + if u.SetTrustLineFlagsResult == nil { + u.SetTrustLineFlagsResult = new(SetTrustLineFlagsResult) + } nTmp, err = (*u.SetTrustLineFlagsResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46516,7 +45167,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeLiquidityPoolDeposit: - u.LiquidityPoolDepositResult = new(LiquidityPoolDepositResult) + if u.LiquidityPoolDepositResult == nil { + u.LiquidityPoolDepositResult = new(LiquidityPoolDepositResult) + } nTmp, err = (*u.LiquidityPoolDepositResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46524,7 +45177,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeLiquidityPoolWithdraw: - u.LiquidityPoolWithdrawResult = new(LiquidityPoolWithdrawResult) + if u.LiquidityPoolWithdrawResult == nil { + u.LiquidityPoolWithdrawResult = new(LiquidityPoolWithdrawResult) + } nTmp, err = (*u.LiquidityPoolWithdrawResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46532,7 +45187,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeInvokeHostFunction: - u.InvokeHostFunctionResult = new(InvokeHostFunctionResult) + if u.InvokeHostFunctionResult == nil { + u.InvokeHostFunctionResult = new(InvokeHostFunctionResult) + } nTmp, err = (*u.InvokeHostFunctionResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46540,7 +45197,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeExtendFootprintTtl: - u.ExtendFootprintTtlResult = new(ExtendFootprintTtlResult) + if u.ExtendFootprintTtlResult == nil { + u.ExtendFootprintTtlResult = new(ExtendFootprintTtlResult) + } nTmp, err = (*u.ExtendFootprintTtlResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46548,7 +45207,9 @@ func (u *OperationResultTr) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case OperationTypeRestoreFootprint: - u.RestoreFootprintResult = new(RestoreFootprintResult) + if u.RestoreFootprintResult == nil { + u.RestoreFootprintResult = new(RestoreFootprintResult) + } nTmp, err = (*u.RestoreFootprintResult).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46569,11 +45230,8 @@ func (s OperationResultTr) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *OperationResultTr) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -46721,25 +45379,19 @@ func NewOperationResult(code OperationResultCode, value interface{}) (result Ope // MustTr retrieves the Tr value from the union, // panicing if the value is not set. func (u OperationResult) MustTr() OperationResultTr { - val, ok := u.GetTr() - - if !ok { - panic("arm Tr is not set") + if OperationResultCode(u.Code) == OperationResultCodeOpInner { + return *u.Tr } - - return val + panic("arm Tr is not set") } // GetTr retrieves the Tr value from the union, // returning ok if the union's switch indicated the value is valid. func (u OperationResult) GetTr() (result OperationResultTr, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "Tr" { + if OperationResultCode(u.Code) == OperationResultCodeOpInner { result = *u.Tr ok = true } - return } @@ -46777,9 +45429,9 @@ func (u OperationResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (OperationResultCode) switch value '%d' is not valid for union OperationResult", u.Code) } -var _ decoderFrom = (*OperationResult)(nil) +var _ xdr.DecoderFrom = (*OperationResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *OperationResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding OperationResult: %w", ErrMaxDecodingDepthReached) @@ -46794,7 +45446,9 @@ func (u *OperationResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } switch OperationResultCode(u.Code) { case OperationResultCodeOpInner: - u.Tr = new(OperationResultTr) + if u.Tr == nil { + u.Tr = new(OperationResultTr) + } nTmp, err = (*u.Tr).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -46833,11 +45487,8 @@ func (s OperationResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *OperationResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -46902,6 +45553,10 @@ const ( TransactionResultCodeTxMalformed TransactionResultCode = -16 TransactionResultCodeTxSorobanInvalid TransactionResultCode = -17 ) +const ( + _TransactionResultCode_Min int32 = -17 + _TransactionResultCode_Max int32 = 1 +) var transactionResultCodeMap = map[int32]string{ 1: "TransactionResultCodeTxFeeBumpInnerSuccess", @@ -46928,8 +45583,7 @@ var transactionResultCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for TransactionResultCode func (e TransactionResultCode) ValidEnum(v int32) bool { - _, ok := transactionResultCodeMap[v] - return ok + return v >= _TransactionResultCode_Min && v <= _TransactionResultCode_Max } // String returns the name of `e` @@ -46940,16 +45594,16 @@ func (e TransactionResultCode) String() string { // EncodeTo encodes this value using the Encoder. func (e TransactionResultCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := transactionResultCodeMap[int32(e)]; !ok { + if int32(e) < _TransactionResultCode_Min || int32(e) > _TransactionResultCode_Max { return fmt.Errorf("'%d' is not a valid TransactionResultCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*TransactionResultCode)(nil) +var _ xdr.DecoderFrom = (*TransactionResultCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *TransactionResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionResultCode: %w", ErrMaxDecodingDepthReached) @@ -46959,7 +45613,7 @@ func (e *TransactionResultCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding TransactionResultCode: %w", err) } - if _, ok := transactionResultCodeMap[v]; !ok { + if v < _TransactionResultCode_Min || v > _TransactionResultCode_Max { return n, fmt.Errorf("'%d' is not a valid TransactionResultCode enum value", v) } *e = TransactionResultCode(v) @@ -46976,11 +45630,8 @@ func (s TransactionResultCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionResultCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -47128,25 +45779,19 @@ func NewInnerTransactionResultResult(code TransactionResultCode, value interface // MustResults retrieves the Results value from the union, // panicing if the value is not set. func (u InnerTransactionResultResult) MustResults() []OperationResult { - val, ok := u.GetResults() - - if !ok { - panic("arm Results is not set") + if TransactionResultCode(u.Code) == TransactionResultCodeTxSuccess || TransactionResultCode(u.Code) == TransactionResultCodeTxFailed { + return *u.Results } - - return val + panic("arm Results is not set") } // GetResults retrieves the Results value from the union, // returning ok if the union's switch indicated the value is valid. func (u InnerTransactionResultResult) GetResults() (result []OperationResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "Results" { + if TransactionResultCode(u.Code) == TransactionResultCodeTxSuccess || TransactionResultCode(u.Code) == TransactionResultCodeTxFailed { result = *u.Results ok = true } - return } @@ -47226,9 +45871,9 @@ func (u InnerTransactionResultResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (TransactionResultCode) switch value '%d' is not valid for union InnerTransactionResultResult", u.Code) } -var _ decoderFrom = (*InnerTransactionResultResult)(nil) +var _ xdr.DecoderFrom = (*InnerTransactionResultResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *InnerTransactionResultResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InnerTransactionResultResult: %w", ErrMaxDecodingDepthReached) @@ -47243,19 +45888,26 @@ func (u *InnerTransactionResultResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) } switch TransactionResultCode(u.Code) { case TransactionResultCodeTxSuccess: - u.Results = new([]OperationResult) + if u.Results == nil { + u.Results = new([]OperationResult) + } var l uint32 l, nTmp, err = d.DecodeUint() n += nTmp if err != nil { return n, fmt.Errorf("decoding OperationResult: %w", err) } - (*u.Results) = nil - if l > 0 { + if l == 0 { + (*u.Results) = (*u.Results)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding OperationResult: length (%d) exceeds remaining input length (%d)", l, il) } - (*u.Results) = make([]OperationResult, l) + if cap((*u.Results)) >= int(l) { + (*u.Results) = (*u.Results)[:l] + } else { + (*u.Results) = make([]OperationResult, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*u.Results)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -47266,19 +45918,26 @@ func (u *InnerTransactionResultResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) } return n, nil case TransactionResultCodeTxFailed: - u.Results = new([]OperationResult) + if u.Results == nil { + u.Results = new([]OperationResult) + } var l uint32 l, nTmp, err = d.DecodeUint() n += nTmp if err != nil { return n, fmt.Errorf("decoding OperationResult: %w", err) } - (*u.Results) = nil - if l > 0 { + if l == 0 { + (*u.Results) = (*u.Results)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding OperationResult: length (%d) exceeds remaining input length (%d)", l, il) } - (*u.Results) = make([]OperationResult, l) + if cap((*u.Results)) >= int(l) { + (*u.Results) = (*u.Results)[:l] + } else { + (*u.Results) = make([]OperationResult, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*u.Results)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -47347,11 +46006,8 @@ func (s InnerTransactionResultResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InnerTransactionResultResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -47416,9 +46072,9 @@ func (u InnerTransactionResultExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union InnerTransactionResultExt", u.V) } -var _ decoderFrom = (*InnerTransactionResultExt)(nil) +var _ xdr.DecoderFrom = (*InnerTransactionResultExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *InnerTransactionResultExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InnerTransactionResultExt: %w", ErrMaxDecodingDepthReached) @@ -47449,11 +46105,8 @@ func (s InnerTransactionResultExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InnerTransactionResultExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -47529,9 +46182,9 @@ func (s *InnerTransactionResult) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*InnerTransactionResult)(nil) +var _ xdr.DecoderFrom = (*InnerTransactionResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *InnerTransactionResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InnerTransactionResult: %w", ErrMaxDecodingDepthReached) @@ -47567,11 +46220,8 @@ func (s InnerTransactionResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InnerTransactionResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -47609,9 +46259,9 @@ func (s *InnerTransactionResultPair) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*InnerTransactionResultPair)(nil) +var _ xdr.DecoderFrom = (*InnerTransactionResultPair)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *InnerTransactionResultPair) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding InnerTransactionResultPair: %w", ErrMaxDecodingDepthReached) @@ -47642,11 +46292,8 @@ func (s InnerTransactionResultPair) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *InnerTransactionResultPair) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -47815,50 +46462,38 @@ func NewTransactionResultResult(code TransactionResultCode, value interface{}) ( // MustInnerResultPair retrieves the InnerResultPair value from the union, // panicing if the value is not set. func (u TransactionResultResult) MustInnerResultPair() InnerTransactionResultPair { - val, ok := u.GetInnerResultPair() - - if !ok { - panic("arm InnerResultPair is not set") + if TransactionResultCode(u.Code) == TransactionResultCodeTxFeeBumpInnerSuccess || TransactionResultCode(u.Code) == TransactionResultCodeTxFeeBumpInnerFailed { + return *u.InnerResultPair } - - return val + panic("arm InnerResultPair is not set") } // GetInnerResultPair retrieves the InnerResultPair value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionResultResult) GetInnerResultPair() (result InnerTransactionResultPair, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "InnerResultPair" { + if TransactionResultCode(u.Code) == TransactionResultCodeTxFeeBumpInnerSuccess || TransactionResultCode(u.Code) == TransactionResultCodeTxFeeBumpInnerFailed { result = *u.InnerResultPair ok = true } - return } // MustResults retrieves the Results value from the union, // panicing if the value is not set. func (u TransactionResultResult) MustResults() []OperationResult { - val, ok := u.GetResults() - - if !ok { - panic("arm Results is not set") + if TransactionResultCode(u.Code) == TransactionResultCodeTxSuccess || TransactionResultCode(u.Code) == TransactionResultCodeTxFailed { + return *u.Results } - - return val + panic("arm Results is not set") } // GetResults retrieves the Results value from the union, // returning ok if the union's switch indicated the value is valid. func (u TransactionResultResult) GetResults() (result []OperationResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Code)) - - if armName == "Results" { + if TransactionResultCode(u.Code) == TransactionResultCodeTxSuccess || TransactionResultCode(u.Code) == TransactionResultCodeTxFailed { result = *u.Results ok = true } - return } @@ -47948,9 +46583,9 @@ func (u TransactionResultResult) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Code (TransactionResultCode) switch value '%d' is not valid for union TransactionResultResult", u.Code) } -var _ decoderFrom = (*TransactionResultResult)(nil) +var _ xdr.DecoderFrom = (*TransactionResultResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TransactionResultResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionResultResult: %w", ErrMaxDecodingDepthReached) @@ -47965,7 +46600,9 @@ func (u *TransactionResultResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int } switch TransactionResultCode(u.Code) { case TransactionResultCodeTxFeeBumpInnerSuccess: - u.InnerResultPair = new(InnerTransactionResultPair) + if u.InnerResultPair == nil { + u.InnerResultPair = new(InnerTransactionResultPair) + } nTmp, err = (*u.InnerResultPair).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -47973,7 +46610,9 @@ func (u *TransactionResultResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int } return n, nil case TransactionResultCodeTxFeeBumpInnerFailed: - u.InnerResultPair = new(InnerTransactionResultPair) + if u.InnerResultPair == nil { + u.InnerResultPair = new(InnerTransactionResultPair) + } nTmp, err = (*u.InnerResultPair).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -47981,19 +46620,26 @@ func (u *TransactionResultResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int } return n, nil case TransactionResultCodeTxSuccess: - u.Results = new([]OperationResult) + if u.Results == nil { + u.Results = new([]OperationResult) + } var l uint32 l, nTmp, err = d.DecodeUint() n += nTmp if err != nil { return n, fmt.Errorf("decoding OperationResult: %w", err) } - (*u.Results) = nil - if l > 0 { + if l == 0 { + (*u.Results) = (*u.Results)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding OperationResult: length (%d) exceeds remaining input length (%d)", l, il) } - (*u.Results) = make([]OperationResult, l) + if cap((*u.Results)) >= int(l) { + (*u.Results) = (*u.Results)[:l] + } else { + (*u.Results) = make([]OperationResult, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*u.Results)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -48004,19 +46650,26 @@ func (u *TransactionResultResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int } return n, nil case TransactionResultCodeTxFailed: - u.Results = new([]OperationResult) + if u.Results == nil { + u.Results = new([]OperationResult) + } var l uint32 l, nTmp, err = d.DecodeUint() n += nTmp if err != nil { return n, fmt.Errorf("decoding OperationResult: %w", err) } - (*u.Results) = nil - if l > 0 { + if l == 0 { + (*u.Results) = (*u.Results)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding OperationResult: length (%d) exceeds remaining input length (%d)", l, il) } - (*u.Results) = make([]OperationResult, l) + if cap((*u.Results)) >= int(l) { + (*u.Results) = (*u.Results)[:l] + } else { + (*u.Results) = make([]OperationResult, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*u.Results)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -48085,11 +46738,8 @@ func (s TransactionResultResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionResultResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48154,9 +46804,9 @@ func (u TransactionResultExt) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union TransactionResultExt", u.V) } -var _ decoderFrom = (*TransactionResultExt)(nil) +var _ xdr.DecoderFrom = (*TransactionResultExt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *TransactionResultExt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionResultExt: %w", ErrMaxDecodingDepthReached) @@ -48187,11 +46837,8 @@ func (s TransactionResultExt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionResultExt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48268,9 +46915,9 @@ func (s *TransactionResult) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TransactionResult)(nil) +var _ xdr.DecoderFrom = (*TransactionResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TransactionResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TransactionResult: %w", ErrMaxDecodingDepthReached) @@ -48306,11 +46953,8 @@ func (s TransactionResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TransactionResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48343,9 +46987,9 @@ func (s *Hash) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Hash)(nil) +var _ xdr.DecoderFrom = (*Hash)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Hash) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Hash: %w", ErrMaxDecodingDepthReached) @@ -48371,11 +47015,8 @@ func (s Hash) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Hash) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48408,9 +47049,9 @@ func (s *Uint256) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Uint256)(nil) +var _ xdr.DecoderFrom = (*Uint256)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Uint256) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Uint256: %w", ErrMaxDecodingDepthReached) @@ -48436,11 +47077,8 @@ func (s Uint256) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Uint256) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48468,9 +47106,9 @@ func (s Uint32) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Uint32)(nil) +var _ xdr.DecoderFrom = (*Uint32)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Uint32) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Uint32: %w", ErrMaxDecodingDepthReached) @@ -48498,11 +47136,8 @@ func (s Uint32) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Uint32) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48530,9 +47165,9 @@ func (s Int32) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Int32)(nil) +var _ xdr.DecoderFrom = (*Int32)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Int32) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Int32: %w", ErrMaxDecodingDepthReached) @@ -48560,11 +47195,8 @@ func (s Int32) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Int32) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48592,9 +47224,9 @@ func (s Uint64) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Uint64)(nil) +var _ xdr.DecoderFrom = (*Uint64)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Uint64) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Uint64: %w", ErrMaxDecodingDepthReached) @@ -48622,11 +47254,8 @@ func (s Uint64) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Uint64) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48654,9 +47283,9 @@ func (s Int64) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Int64)(nil) +var _ xdr.DecoderFrom = (*Int64)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Int64) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Int64: %w", ErrMaxDecodingDepthReached) @@ -48684,11 +47313,8 @@ func (s Int64) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Int64) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48716,9 +47342,9 @@ func (s TimePoint) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*TimePoint)(nil) +var _ xdr.DecoderFrom = (*TimePoint)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *TimePoint) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding TimePoint: %w", ErrMaxDecodingDepthReached) @@ -48744,11 +47370,8 @@ func (s TimePoint) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *TimePoint) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48776,9 +47399,9 @@ func (s Duration) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Duration)(nil) +var _ xdr.DecoderFrom = (*Duration)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Duration) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Duration: %w", ErrMaxDecodingDepthReached) @@ -48804,11 +47427,8 @@ func (s Duration) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Duration) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48873,9 +47493,9 @@ func (u ExtensionPoint) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union ExtensionPoint", u.V) } -var _ decoderFrom = (*ExtensionPoint)(nil) +var _ xdr.DecoderFrom = (*ExtensionPoint)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ExtensionPoint) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ExtensionPoint: %w", ErrMaxDecodingDepthReached) @@ -48906,11 +47526,8 @@ func (s ExtensionPoint) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ExtensionPoint) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -48957,8 +47574,12 @@ var cryptoKeyTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for CryptoKeyType func (e CryptoKeyType) ValidEnum(v int32) bool { - _, ok := cryptoKeyTypeMap[v] - return ok + switch v { + case 0, 1, 2, 3, 256: + return true + default: + return false + } } // String returns the name of `e` @@ -48969,16 +47590,19 @@ func (e CryptoKeyType) String() string { // EncodeTo encodes this value using the Encoder. func (e CryptoKeyType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := cryptoKeyTypeMap[int32(e)]; !ok { + switch int32(e) { + case 0, 1, 2, 3, 256: + // valid + default: return fmt.Errorf("'%d' is not a valid CryptoKeyType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*CryptoKeyType)(nil) +var _ xdr.DecoderFrom = (*CryptoKeyType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *CryptoKeyType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding CryptoKeyType: %w", ErrMaxDecodingDepthReached) @@ -48988,7 +47612,10 @@ func (e *CryptoKeyType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding CryptoKeyType: %w", err) } - if _, ok := cryptoKeyTypeMap[v]; !ok { + switch v { + case 0, 1, 2, 3, 256: + // valid + default: return n, fmt.Errorf("'%d' is not a valid CryptoKeyType enum value", v) } *e = CryptoKeyType(v) @@ -49005,11 +47632,8 @@ func (s CryptoKeyType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *CryptoKeyType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -49034,6 +47658,10 @@ type PublicKeyType int32 const ( PublicKeyTypePublicKeyTypeEd25519 PublicKeyType = 0 ) +const ( + _PublicKeyType_Min int32 = 0 + _PublicKeyType_Max int32 = 0 +) var publicKeyTypeMap = map[int32]string{ 0: "PublicKeyTypePublicKeyTypeEd25519", @@ -49042,8 +47670,7 @@ var publicKeyTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for PublicKeyType func (e PublicKeyType) ValidEnum(v int32) bool { - _, ok := publicKeyTypeMap[v] - return ok + return v >= _PublicKeyType_Min && v <= _PublicKeyType_Max } // String returns the name of `e` @@ -49054,16 +47681,16 @@ func (e PublicKeyType) String() string { // EncodeTo encodes this value using the Encoder. func (e PublicKeyType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := publicKeyTypeMap[int32(e)]; !ok { + if int32(e) < _PublicKeyType_Min || int32(e) > _PublicKeyType_Max { return fmt.Errorf("'%d' is not a valid PublicKeyType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*PublicKeyType)(nil) +var _ xdr.DecoderFrom = (*PublicKeyType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *PublicKeyType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PublicKeyType: %w", ErrMaxDecodingDepthReached) @@ -49073,7 +47700,7 @@ func (e *PublicKeyType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding PublicKeyType: %w", err) } - if _, ok := publicKeyTypeMap[v]; !ok { + if v < _PublicKeyType_Min || v > _PublicKeyType_Max { return n, fmt.Errorf("'%d' is not a valid PublicKeyType enum value", v) } *e = PublicKeyType(v) @@ -49090,11 +47717,8 @@ func (s PublicKeyType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PublicKeyType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -49125,6 +47749,10 @@ const ( SignerKeyTypeSignerKeyTypeHashX SignerKeyType = 2 SignerKeyTypeSignerKeyTypeEd25519SignedPayload SignerKeyType = 3 ) +const ( + _SignerKeyType_Min int32 = 0 + _SignerKeyType_Max int32 = 3 +) var signerKeyTypeMap = map[int32]string{ 0: "SignerKeyTypeSignerKeyTypeEd25519", @@ -49136,8 +47764,7 @@ var signerKeyTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for SignerKeyType func (e SignerKeyType) ValidEnum(v int32) bool { - _, ok := signerKeyTypeMap[v] - return ok + return v >= _SignerKeyType_Min && v <= _SignerKeyType_Max } // String returns the name of `e` @@ -49148,16 +47775,16 @@ func (e SignerKeyType) String() string { // EncodeTo encodes this value using the Encoder. func (e SignerKeyType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := signerKeyTypeMap[int32(e)]; !ok { + if int32(e) < _SignerKeyType_Min || int32(e) > _SignerKeyType_Max { return fmt.Errorf("'%d' is not a valid SignerKeyType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*SignerKeyType)(nil) +var _ xdr.DecoderFrom = (*SignerKeyType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *SignerKeyType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SignerKeyType: %w", ErrMaxDecodingDepthReached) @@ -49167,7 +47794,7 @@ func (e *SignerKeyType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding SignerKeyType: %w", err) } - if _, ok := signerKeyTypeMap[v]; !ok { + if v < _SignerKeyType_Min || v > _SignerKeyType_Max { return n, fmt.Errorf("'%d' is not a valid SignerKeyType enum value", v) } *e = SignerKeyType(v) @@ -49184,11 +47811,8 @@ func (s SignerKeyType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SignerKeyType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -49248,25 +47872,19 @@ func NewPublicKey(aType PublicKeyType, value interface{}) (result PublicKey, err // MustEd25519 retrieves the Ed25519 value from the union, // panicing if the value is not set. func (u PublicKey) MustEd25519() Uint256 { - val, ok := u.GetEd25519() - - if !ok { - panic("arm Ed25519 is not set") + if PublicKeyType(u.Type) == PublicKeyTypePublicKeyTypeEd25519 { + return *u.Ed25519 } - - return val + panic("arm Ed25519 is not set") } // GetEd25519 retrieves the Ed25519 value from the union, // returning ok if the union's switch indicated the value is valid. func (u PublicKey) GetEd25519() (result Uint256, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Ed25519" { + if PublicKeyType(u.Type) == PublicKeyTypePublicKeyTypeEd25519 { result = *u.Ed25519 ok = true } - return } @@ -49286,9 +47904,9 @@ func (u PublicKey) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (PublicKeyType) switch value '%d' is not valid for union PublicKey", u.Type) } -var _ decoderFrom = (*PublicKey)(nil) +var _ xdr.DecoderFrom = (*PublicKey)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *PublicKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PublicKey: %w", ErrMaxDecodingDepthReached) @@ -49303,7 +47921,9 @@ func (u *PublicKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch PublicKeyType(u.Type) { case PublicKeyTypePublicKeyTypeEd25519: - u.Ed25519 = new(Uint256) + if u.Ed25519 == nil { + u.Ed25519 = new(Uint256) + } nTmp, err = (*u.Ed25519).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -49324,11 +47944,8 @@ func (s PublicKey) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PublicKey) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -49368,9 +47985,9 @@ func (s *SignerKeyEd25519SignedPayload) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SignerKeyEd25519SignedPayload)(nil) +var _ xdr.DecoderFrom = (*SignerKeyEd25519SignedPayload)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SignerKeyEd25519SignedPayload) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SignerKeyEd25519SignedPayload: %w", ErrMaxDecodingDepthReached) @@ -49401,11 +48018,8 @@ func (s SignerKeyEd25519SignedPayload) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SignerKeyEd25519SignedPayload) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -49509,100 +48123,76 @@ func NewSignerKey(aType SignerKeyType, value interface{}) (result SignerKey, err // MustEd25519 retrieves the Ed25519 value from the union, // panicing if the value is not set. func (u SignerKey) MustEd25519() Uint256 { - val, ok := u.GetEd25519() - - if !ok { - panic("arm Ed25519 is not set") + if SignerKeyType(u.Type) == SignerKeyTypeSignerKeyTypeEd25519 { + return *u.Ed25519 } - - return val + panic("arm Ed25519 is not set") } // GetEd25519 retrieves the Ed25519 value from the union, // returning ok if the union's switch indicated the value is valid. func (u SignerKey) GetEd25519() (result Uint256, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Ed25519" { + if SignerKeyType(u.Type) == SignerKeyTypeSignerKeyTypeEd25519 { result = *u.Ed25519 ok = true } - return } // MustPreAuthTx retrieves the PreAuthTx value from the union, // panicing if the value is not set. func (u SignerKey) MustPreAuthTx() Uint256 { - val, ok := u.GetPreAuthTx() - - if !ok { - panic("arm PreAuthTx is not set") + if SignerKeyType(u.Type) == SignerKeyTypeSignerKeyTypePreAuthTx { + return *u.PreAuthTx } - - return val + panic("arm PreAuthTx is not set") } // GetPreAuthTx retrieves the PreAuthTx value from the union, // returning ok if the union's switch indicated the value is valid. func (u SignerKey) GetPreAuthTx() (result Uint256, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "PreAuthTx" { + if SignerKeyType(u.Type) == SignerKeyTypeSignerKeyTypePreAuthTx { result = *u.PreAuthTx ok = true } - return } // MustHashX retrieves the HashX value from the union, // panicing if the value is not set. func (u SignerKey) MustHashX() Uint256 { - val, ok := u.GetHashX() - - if !ok { - panic("arm HashX is not set") + if SignerKeyType(u.Type) == SignerKeyTypeSignerKeyTypeHashX { + return *u.HashX } - - return val + panic("arm HashX is not set") } // GetHashX retrieves the HashX value from the union, // returning ok if the union's switch indicated the value is valid. func (u SignerKey) GetHashX() (result Uint256, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "HashX" { + if SignerKeyType(u.Type) == SignerKeyTypeSignerKeyTypeHashX { result = *u.HashX ok = true } - return } // MustEd25519SignedPayload retrieves the Ed25519SignedPayload value from the union, // panicing if the value is not set. func (u SignerKey) MustEd25519SignedPayload() SignerKeyEd25519SignedPayload { - val, ok := u.GetEd25519SignedPayload() - - if !ok { - panic("arm Ed25519SignedPayload is not set") + if SignerKeyType(u.Type) == SignerKeyTypeSignerKeyTypeEd25519SignedPayload { + return *u.Ed25519SignedPayload } - - return val + panic("arm Ed25519SignedPayload is not set") } // GetEd25519SignedPayload retrieves the Ed25519SignedPayload value from the union, // returning ok if the union's switch indicated the value is valid. func (u SignerKey) GetEd25519SignedPayload() (result SignerKeyEd25519SignedPayload, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Ed25519SignedPayload" { + if SignerKeyType(u.Type) == SignerKeyTypeSignerKeyTypeEd25519SignedPayload { result = *u.Ed25519SignedPayload ok = true } - return } @@ -49637,9 +48227,9 @@ func (u SignerKey) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (SignerKeyType) switch value '%d' is not valid for union SignerKey", u.Type) } -var _ decoderFrom = (*SignerKey)(nil) +var _ xdr.DecoderFrom = (*SignerKey)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *SignerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SignerKey: %w", ErrMaxDecodingDepthReached) @@ -49654,7 +48244,9 @@ func (u *SignerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch SignerKeyType(u.Type) { case SignerKeyTypeSignerKeyTypeEd25519: - u.Ed25519 = new(Uint256) + if u.Ed25519 == nil { + u.Ed25519 = new(Uint256) + } nTmp, err = (*u.Ed25519).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -49662,7 +48254,9 @@ func (u *SignerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case SignerKeyTypeSignerKeyTypePreAuthTx: - u.PreAuthTx = new(Uint256) + if u.PreAuthTx == nil { + u.PreAuthTx = new(Uint256) + } nTmp, err = (*u.PreAuthTx).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -49670,7 +48264,9 @@ func (u *SignerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case SignerKeyTypeSignerKeyTypeHashX: - u.HashX = new(Uint256) + if u.HashX == nil { + u.HashX = new(Uint256) + } nTmp, err = (*u.HashX).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -49678,7 +48274,9 @@ func (u *SignerKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case SignerKeyTypeSignerKeyTypeEd25519SignedPayload: - u.Ed25519SignedPayload = new(SignerKeyEd25519SignedPayload) + if u.Ed25519SignedPayload == nil { + u.Ed25519SignedPayload = new(SignerKeyEd25519SignedPayload) + } nTmp, err = (*u.Ed25519SignedPayload).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -49699,11 +48297,8 @@ func (s SignerKey) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SignerKey) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -49736,9 +48331,9 @@ func (s Signature) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Signature)(nil) +var _ xdr.DecoderFrom = (*Signature)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Signature) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Signature: %w", ErrMaxDecodingDepthReached) @@ -49764,11 +48359,8 @@ func (s Signature) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Signature) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -49801,9 +48393,9 @@ func (s *SignatureHint) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SignatureHint)(nil) +var _ xdr.DecoderFrom = (*SignatureHint)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SignatureHint) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SignatureHint: %w", ErrMaxDecodingDepthReached) @@ -49829,11 +48421,8 @@ func (s SignatureHint) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SignatureHint) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -49892,9 +48481,9 @@ func (s NodeId) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*NodeId)(nil) +var _ xdr.DecoderFrom = (*NodeId)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *NodeId) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding NodeId: %w", ErrMaxDecodingDepthReached) @@ -49920,11 +48509,8 @@ func (s NodeId) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *NodeId) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -49983,9 +48569,9 @@ func (s AccountId) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*AccountId)(nil) +var _ xdr.DecoderFrom = (*AccountId)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *AccountId) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding AccountId: %w", ErrMaxDecodingDepthReached) @@ -50011,11 +48597,8 @@ func (s AccountId) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *AccountId) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50043,9 +48626,9 @@ func (s *ContractId) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ContractId)(nil) +var _ xdr.DecoderFrom = (*ContractId)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ContractId) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractId: %w", ErrMaxDecodingDepthReached) @@ -50071,11 +48654,8 @@ func (s ContractId) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractId) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50108,9 +48688,9 @@ func (s *Curve25519Secret) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Curve25519Secret)(nil) +var _ xdr.DecoderFrom = (*Curve25519Secret)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Curve25519Secret) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Curve25519Secret: %w", ErrMaxDecodingDepthReached) @@ -50136,11 +48716,8 @@ func (s Curve25519Secret) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Curve25519Secret) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50173,9 +48750,9 @@ func (s *Curve25519Public) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Curve25519Public)(nil) +var _ xdr.DecoderFrom = (*Curve25519Public)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Curve25519Public) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Curve25519Public: %w", ErrMaxDecodingDepthReached) @@ -50201,11 +48778,8 @@ func (s Curve25519Public) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Curve25519Public) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50238,9 +48812,9 @@ func (s *HmacSha256Key) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*HmacSha256Key)(nil) +var _ xdr.DecoderFrom = (*HmacSha256Key)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *HmacSha256Key) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding HmacSha256Key: %w", ErrMaxDecodingDepthReached) @@ -50266,11 +48840,8 @@ func (s HmacSha256Key) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *HmacSha256Key) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50303,9 +48874,9 @@ func (s *HmacSha256Mac) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*HmacSha256Mac)(nil) +var _ xdr.DecoderFrom = (*HmacSha256Mac)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *HmacSha256Mac) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding HmacSha256Mac: %w", ErrMaxDecodingDepthReached) @@ -50331,11 +48902,8 @@ func (s HmacSha256Mac) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *HmacSha256Mac) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50368,9 +48936,9 @@ func (s *ShortHashSeed) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ShortHashSeed)(nil) +var _ xdr.DecoderFrom = (*ShortHashSeed)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ShortHashSeed) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ShortHashSeed: %w", ErrMaxDecodingDepthReached) @@ -50396,11 +48964,8 @@ func (s ShortHashSeed) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ShortHashSeed) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50429,6 +48994,10 @@ const ( BinaryFuseFilterTypeBinaryFuseFilter16Bit BinaryFuseFilterType = 1 BinaryFuseFilterTypeBinaryFuseFilter32Bit BinaryFuseFilterType = 2 ) +const ( + _BinaryFuseFilterType_Min int32 = 0 + _BinaryFuseFilterType_Max int32 = 2 +) var binaryFuseFilterTypeMap = map[int32]string{ 0: "BinaryFuseFilterTypeBinaryFuseFilter8Bit", @@ -50439,8 +49008,7 @@ var binaryFuseFilterTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for BinaryFuseFilterType func (e BinaryFuseFilterType) ValidEnum(v int32) bool { - _, ok := binaryFuseFilterTypeMap[v] - return ok + return v >= _BinaryFuseFilterType_Min && v <= _BinaryFuseFilterType_Max } // String returns the name of `e` @@ -50451,16 +49019,16 @@ func (e BinaryFuseFilterType) String() string { // EncodeTo encodes this value using the Encoder. func (e BinaryFuseFilterType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := binaryFuseFilterTypeMap[int32(e)]; !ok { + if int32(e) < _BinaryFuseFilterType_Min || int32(e) > _BinaryFuseFilterType_Max { return fmt.Errorf("'%d' is not a valid BinaryFuseFilterType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*BinaryFuseFilterType)(nil) +var _ xdr.DecoderFrom = (*BinaryFuseFilterType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *BinaryFuseFilterType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding BinaryFuseFilterType: %w", ErrMaxDecodingDepthReached) @@ -50470,7 +49038,7 @@ func (e *BinaryFuseFilterType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e if err != nil { return n, fmt.Errorf("decoding BinaryFuseFilterType: %w", err) } - if _, ok := binaryFuseFilterTypeMap[v]; !ok { + if v < _BinaryFuseFilterType_Min || v > _BinaryFuseFilterType_Max { return n, fmt.Errorf("'%d' is not a valid BinaryFuseFilterType enum value", v) } *e = BinaryFuseFilterType(v) @@ -50487,11 +49055,8 @@ func (s BinaryFuseFilterType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *BinaryFuseFilterType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50570,9 +49135,9 @@ func (s *SerializedBinaryFuseFilter) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*SerializedBinaryFuseFilter)(nil) +var _ xdr.DecoderFrom = (*SerializedBinaryFuseFilter)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *SerializedBinaryFuseFilter) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding SerializedBinaryFuseFilter: %w", ErrMaxDecodingDepthReached) @@ -50638,11 +49203,8 @@ func (s SerializedBinaryFuseFilter) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *SerializedBinaryFuseFilter) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50670,9 +49232,9 @@ func (s *PoolId) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*PoolId)(nil) +var _ xdr.DecoderFrom = (*PoolId)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *PoolId) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PoolId: %w", ErrMaxDecodingDepthReached) @@ -50698,11 +49260,8 @@ func (s PoolId) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PoolId) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50727,6 +49286,10 @@ type ClaimableBalanceIdType int32 const ( ClaimableBalanceIdTypeClaimableBalanceIdTypeV0 ClaimableBalanceIdType = 0 ) +const ( + _ClaimableBalanceIdType_Min int32 = 0 + _ClaimableBalanceIdType_Max int32 = 0 +) var claimableBalanceIdTypeMap = map[int32]string{ 0: "ClaimableBalanceIdTypeClaimableBalanceIdTypeV0", @@ -50735,8 +49298,7 @@ var claimableBalanceIdTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ClaimableBalanceIdType func (e ClaimableBalanceIdType) ValidEnum(v int32) bool { - _, ok := claimableBalanceIdTypeMap[v] - return ok + return v >= _ClaimableBalanceIdType_Min && v <= _ClaimableBalanceIdType_Max } // String returns the name of `e` @@ -50747,16 +49309,16 @@ func (e ClaimableBalanceIdType) String() string { // EncodeTo encodes this value using the Encoder. func (e ClaimableBalanceIdType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := claimableBalanceIdTypeMap[int32(e)]; !ok { + if int32(e) < _ClaimableBalanceIdType_Min || int32(e) > _ClaimableBalanceIdType_Max { return fmt.Errorf("'%d' is not a valid ClaimableBalanceIdType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ClaimableBalanceIdType)(nil) +var _ xdr.DecoderFrom = (*ClaimableBalanceIdType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ClaimableBalanceIdType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimableBalanceIdType: %w", ErrMaxDecodingDepthReached) @@ -50766,7 +49328,7 @@ func (e *ClaimableBalanceIdType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding ClaimableBalanceIdType: %w", err) } - if _, ok := claimableBalanceIdTypeMap[v]; !ok { + if v < _ClaimableBalanceIdType_Min || v > _ClaimableBalanceIdType_Max { return n, fmt.Errorf("'%d' is not a valid ClaimableBalanceIdType enum value", v) } *e = ClaimableBalanceIdType(v) @@ -50783,11 +49345,8 @@ func (s ClaimableBalanceIdType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimableBalanceIdType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50847,25 +49406,19 @@ func NewClaimableBalanceId(aType ClaimableBalanceIdType, value interface{}) (res // MustV0 retrieves the V0 value from the union, // panicing if the value is not set. func (u ClaimableBalanceId) MustV0() Hash { - val, ok := u.GetV0() - - if !ok { - panic("arm V0 is not set") + if ClaimableBalanceIdType(u.Type) == ClaimableBalanceIdTypeClaimableBalanceIdTypeV0 { + return *u.V0 } - - return val + panic("arm V0 is not set") } // GetV0 retrieves the V0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ClaimableBalanceId) GetV0() (result Hash, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "V0" { + if ClaimableBalanceIdType(u.Type) == ClaimableBalanceIdTypeClaimableBalanceIdTypeV0 { result = *u.V0 ok = true } - return } @@ -50885,9 +49438,9 @@ func (u ClaimableBalanceId) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (ClaimableBalanceIdType) switch value '%d' is not valid for union ClaimableBalanceId", u.Type) } -var _ decoderFrom = (*ClaimableBalanceId)(nil) +var _ xdr.DecoderFrom = (*ClaimableBalanceId)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ClaimableBalanceId) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ClaimableBalanceId: %w", ErrMaxDecodingDepthReached) @@ -50902,7 +49455,9 @@ func (u *ClaimableBalanceId) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } switch ClaimableBalanceIdType(u.Type) { case ClaimableBalanceIdTypeClaimableBalanceIdTypeV0: - u.V0 = new(Hash) + if u.V0 == nil { + u.V0 = new(Hash) + } nTmp, err = (*u.V0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -50923,11 +49478,8 @@ func (s ClaimableBalanceId) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ClaimableBalanceId) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -50952,6 +49504,10 @@ type ScEnvMetaKind int32 const ( ScEnvMetaKindScEnvMetaKindInterfaceVersion ScEnvMetaKind = 0 ) +const ( + _ScEnvMetaKind_Min int32 = 0 + _ScEnvMetaKind_Max int32 = 0 +) var scEnvMetaKindMap = map[int32]string{ 0: "ScEnvMetaKindScEnvMetaKindInterfaceVersion", @@ -50960,8 +49516,7 @@ var scEnvMetaKindMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScEnvMetaKind func (e ScEnvMetaKind) ValidEnum(v int32) bool { - _, ok := scEnvMetaKindMap[v] - return ok + return v >= _ScEnvMetaKind_Min && v <= _ScEnvMetaKind_Max } // String returns the name of `e` @@ -50972,16 +49527,16 @@ func (e ScEnvMetaKind) String() string { // EncodeTo encodes this value using the Encoder. func (e ScEnvMetaKind) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scEnvMetaKindMap[int32(e)]; !ok { + if int32(e) < _ScEnvMetaKind_Min || int32(e) > _ScEnvMetaKind_Max { return fmt.Errorf("'%d' is not a valid ScEnvMetaKind enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScEnvMetaKind)(nil) +var _ xdr.DecoderFrom = (*ScEnvMetaKind)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScEnvMetaKind) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScEnvMetaKind: %w", ErrMaxDecodingDepthReached) @@ -50991,7 +49546,7 @@ func (e *ScEnvMetaKind) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ScEnvMetaKind: %w", err) } - if _, ok := scEnvMetaKindMap[v]; !ok { + if v < _ScEnvMetaKind_Min || v > _ScEnvMetaKind_Max { return n, fmt.Errorf("'%d' is not a valid ScEnvMetaKind enum value", v) } *e = ScEnvMetaKind(v) @@ -51008,11 +49563,8 @@ func (s ScEnvMetaKind) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScEnvMetaKind) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -51049,9 +49601,9 @@ func (s *ScEnvMetaEntryInterfaceVersion) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScEnvMetaEntryInterfaceVersion)(nil) +var _ xdr.DecoderFrom = (*ScEnvMetaEntryInterfaceVersion)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScEnvMetaEntryInterfaceVersion) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScEnvMetaEntryInterfaceVersion: %w", ErrMaxDecodingDepthReached) @@ -51082,11 +49634,8 @@ func (s ScEnvMetaEntryInterfaceVersion) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScEnvMetaEntryInterfaceVersion) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -51149,25 +49698,19 @@ func NewScEnvMetaEntry(kind ScEnvMetaKind, value interface{}) (result ScEnvMetaE // MustInterfaceVersion retrieves the InterfaceVersion value from the union, // panicing if the value is not set. func (u ScEnvMetaEntry) MustInterfaceVersion() ScEnvMetaEntryInterfaceVersion { - val, ok := u.GetInterfaceVersion() - - if !ok { - panic("arm InterfaceVersion is not set") + if ScEnvMetaKind(u.Kind) == ScEnvMetaKindScEnvMetaKindInterfaceVersion { + return *u.InterfaceVersion } - - return val + panic("arm InterfaceVersion is not set") } // GetInterfaceVersion retrieves the InterfaceVersion value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScEnvMetaEntry) GetInterfaceVersion() (result ScEnvMetaEntryInterfaceVersion, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Kind)) - - if armName == "InterfaceVersion" { + if ScEnvMetaKind(u.Kind) == ScEnvMetaKindScEnvMetaKindInterfaceVersion { result = *u.InterfaceVersion ok = true } - return } @@ -51187,9 +49730,9 @@ func (u ScEnvMetaEntry) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Kind (ScEnvMetaKind) switch value '%d' is not valid for union ScEnvMetaEntry", u.Kind) } -var _ decoderFrom = (*ScEnvMetaEntry)(nil) +var _ xdr.DecoderFrom = (*ScEnvMetaEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ScEnvMetaEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScEnvMetaEntry: %w", ErrMaxDecodingDepthReached) @@ -51204,7 +49747,9 @@ func (u *ScEnvMetaEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) } switch ScEnvMetaKind(u.Kind) { case ScEnvMetaKindScEnvMetaKindInterfaceVersion: - u.InterfaceVersion = new(ScEnvMetaEntryInterfaceVersion) + if u.InterfaceVersion == nil { + u.InterfaceVersion = new(ScEnvMetaEntryInterfaceVersion) + } nTmp, err = (*u.InterfaceVersion).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -51225,11 +49770,8 @@ func (s ScEnvMetaEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScEnvMetaEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -51267,9 +49809,9 @@ func (s *ScMetaV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScMetaV0)(nil) +var _ xdr.DecoderFrom = (*ScMetaV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScMetaV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScMetaV0: %w", ErrMaxDecodingDepthReached) @@ -51300,11 +49842,8 @@ func (s ScMetaV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScMetaV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -51329,6 +49868,10 @@ type ScMetaKind int32 const ( ScMetaKindScMetaV0 ScMetaKind = 0 ) +const ( + _ScMetaKind_Min int32 = 0 + _ScMetaKind_Max int32 = 0 +) var scMetaKindMap = map[int32]string{ 0: "ScMetaKindScMetaV0", @@ -51337,8 +49880,7 @@ var scMetaKindMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScMetaKind func (e ScMetaKind) ValidEnum(v int32) bool { - _, ok := scMetaKindMap[v] - return ok + return v >= _ScMetaKind_Min && v <= _ScMetaKind_Max } // String returns the name of `e` @@ -51349,16 +49891,16 @@ func (e ScMetaKind) String() string { // EncodeTo encodes this value using the Encoder. func (e ScMetaKind) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scMetaKindMap[int32(e)]; !ok { + if int32(e) < _ScMetaKind_Min || int32(e) > _ScMetaKind_Max { return fmt.Errorf("'%d' is not a valid ScMetaKind enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScMetaKind)(nil) +var _ xdr.DecoderFrom = (*ScMetaKind)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScMetaKind) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScMetaKind: %w", ErrMaxDecodingDepthReached) @@ -51368,7 +49910,7 @@ func (e *ScMetaKind) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ScMetaKind: %w", err) } - if _, ok := scMetaKindMap[v]; !ok { + if v < _ScMetaKind_Min || v > _ScMetaKind_Max { return n, fmt.Errorf("'%d' is not a valid ScMetaKind enum value", v) } *e = ScMetaKind(v) @@ -51385,11 +49927,8 @@ func (s ScMetaKind) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScMetaKind) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -51449,25 +49988,19 @@ func NewScMetaEntry(kind ScMetaKind, value interface{}) (result ScMetaEntry, err // MustV0 retrieves the V0 value from the union, // panicing if the value is not set. func (u ScMetaEntry) MustV0() ScMetaV0 { - val, ok := u.GetV0() - - if !ok { - panic("arm V0 is not set") + if ScMetaKind(u.Kind) == ScMetaKindScMetaV0 { + return *u.V0 } - - return val + panic("arm V0 is not set") } // GetV0 retrieves the V0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScMetaEntry) GetV0() (result ScMetaV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Kind)) - - if armName == "V0" { + if ScMetaKind(u.Kind) == ScMetaKindScMetaV0 { result = *u.V0 ok = true } - return } @@ -51487,9 +50020,9 @@ func (u ScMetaEntry) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Kind (ScMetaKind) switch value '%d' is not valid for union ScMetaEntry", u.Kind) } -var _ decoderFrom = (*ScMetaEntry)(nil) +var _ xdr.DecoderFrom = (*ScMetaEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ScMetaEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScMetaEntry: %w", ErrMaxDecodingDepthReached) @@ -51504,7 +50037,9 @@ func (u *ScMetaEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch ScMetaKind(u.Kind) { case ScMetaKindScMetaV0: - u.V0 = new(ScMetaV0) + if u.V0 == nil { + u.V0 = new(ScMetaV0) + } nTmp, err = (*u.V0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -51525,11 +50060,8 @@ func (s ScMetaEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScMetaEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -51648,8 +50180,12 @@ var scSpecTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScSpecType func (e ScSpecType) ValidEnum(v int32) bool { - _, ok := scSpecTypeMap[v] - return ok + switch v { + case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 20, 1000, 1001, 1002, 1004, 1005, 1006, 2000: + return true + default: + return false + } } // String returns the name of `e` @@ -51660,16 +50196,19 @@ func (e ScSpecType) String() string { // EncodeTo encodes this value using the Encoder. func (e ScSpecType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scSpecTypeMap[int32(e)]; !ok { + switch int32(e) { + case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 20, 1000, 1001, 1002, 1004, 1005, 1006, 2000: + // valid + default: return fmt.Errorf("'%d' is not a valid ScSpecType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScSpecType)(nil) +var _ xdr.DecoderFrom = (*ScSpecType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScSpecType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecType: %w", ErrMaxDecodingDepthReached) @@ -51679,7 +50218,10 @@ func (e *ScSpecType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ScSpecType: %w", err) } - if _, ok := scSpecTypeMap[v]; !ok { + switch v { + case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 20, 1000, 1001, 1002, 1004, 1005, 1006, 2000: + // valid + default: return n, fmt.Errorf("'%d' is not a valid ScSpecType enum value", v) } *e = ScSpecType(v) @@ -51696,11 +50238,8 @@ func (s ScSpecType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -51733,9 +50272,9 @@ func (s *ScSpecTypeOption) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecTypeOption)(nil) +var _ xdr.DecoderFrom = (*ScSpecTypeOption)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecTypeOption) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecTypeOption: %w", ErrMaxDecodingDepthReached) @@ -51761,11 +50300,8 @@ func (s ScSpecTypeOption) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecTypeOption) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -51803,9 +50339,9 @@ func (s *ScSpecTypeResult) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecTypeResult)(nil) +var _ xdr.DecoderFrom = (*ScSpecTypeResult)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecTypeResult) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecTypeResult: %w", ErrMaxDecodingDepthReached) @@ -51836,11 +50372,8 @@ func (s ScSpecTypeResult) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecTypeResult) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -51873,9 +50406,9 @@ func (s *ScSpecTypeVec) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecTypeVec)(nil) +var _ xdr.DecoderFrom = (*ScSpecTypeVec)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecTypeVec) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecTypeVec: %w", ErrMaxDecodingDepthReached) @@ -51901,11 +50434,8 @@ func (s ScSpecTypeVec) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecTypeVec) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -51943,9 +50473,9 @@ func (s *ScSpecTypeMap) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecTypeMap)(nil) +var _ xdr.DecoderFrom = (*ScSpecTypeMap)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecTypeMap) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecTypeMap: %w", ErrMaxDecodingDepthReached) @@ -51976,11 +50506,8 @@ func (s ScSpecTypeMap) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecTypeMap) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -52018,9 +50545,9 @@ func (s *ScSpecTypeTuple) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecTypeTuple)(nil) +var _ xdr.DecoderFrom = (*ScSpecTypeTuple)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecTypeTuple) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecTypeTuple: %w", ErrMaxDecodingDepthReached) @@ -52037,12 +50564,17 @@ func (s *ScSpecTypeTuple) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if l > 12 { return n, fmt.Errorf("decoding ScSpecTypeDef: data size (%d) exceeds size limit (12)", l) } - s.ValueTypes = nil - if l > 0 { + if l == 0 { + s.ValueTypes = s.ValueTypes[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScSpecTypeDef: length (%d) exceeds remaining input length (%d)", l, il) } - s.ValueTypes = make([]ScSpecTypeDef, l) + if cap(s.ValueTypes) >= int(l) { + s.ValueTypes = s.ValueTypes[:l] + } else { + s.ValueTypes = make([]ScSpecTypeDef, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ValueTypes[i].DecodeFrom(d, maxDepth) n += nTmp @@ -52064,11 +50596,8 @@ func (s ScSpecTypeTuple) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecTypeTuple) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -52101,9 +50630,9 @@ func (s *ScSpecTypeBytesN) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecTypeBytesN)(nil) +var _ xdr.DecoderFrom = (*ScSpecTypeBytesN)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecTypeBytesN) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecTypeBytesN: %w", ErrMaxDecodingDepthReached) @@ -52129,11 +50658,8 @@ func (s ScSpecTypeBytesN) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecTypeBytesN) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -52166,9 +50692,9 @@ func (s *ScSpecTypeUdt) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecTypeUdt)(nil) +var _ xdr.DecoderFrom = (*ScSpecTypeUdt)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecTypeUdt) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecTypeUdt: %w", ErrMaxDecodingDepthReached) @@ -52194,11 +50720,8 @@ func (s ScSpecTypeUdt) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecTypeUdt) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -52426,175 +50949,133 @@ func NewScSpecTypeDef(aType ScSpecType, value interface{}) (result ScSpecTypeDef // MustOption retrieves the Option value from the union, // panicing if the value is not set. func (u ScSpecTypeDef) MustOption() ScSpecTypeOption { - val, ok := u.GetOption() - - if !ok { - panic("arm Option is not set") + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeOption { + return *u.Option } - - return val + panic("arm Option is not set") } // GetOption retrieves the Option value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecTypeDef) GetOption() (result ScSpecTypeOption, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Option" { + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeOption { result = *u.Option ok = true } - return } // MustResult retrieves the Result value from the union, // panicing if the value is not set. func (u ScSpecTypeDef) MustResult() ScSpecTypeResult { - val, ok := u.GetResult() - - if !ok { - panic("arm Result is not set") + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeResult { + return *u.Result } - - return val + panic("arm Result is not set") } // GetResult retrieves the Result value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecTypeDef) GetResult() (result ScSpecTypeResult, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Result" { + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeResult { result = *u.Result ok = true } - return } // MustVec retrieves the Vec value from the union, // panicing if the value is not set. func (u ScSpecTypeDef) MustVec() ScSpecTypeVec { - val, ok := u.GetVec() - - if !ok { - panic("arm Vec is not set") + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeVec { + return *u.Vec } - - return val + panic("arm Vec is not set") } // GetVec retrieves the Vec value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecTypeDef) GetVec() (result ScSpecTypeVec, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Vec" { + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeVec { result = *u.Vec ok = true } - return } // MustMap retrieves the Map value from the union, // panicing if the value is not set. func (u ScSpecTypeDef) MustMap() ScSpecTypeMap { - val, ok := u.GetMap() - - if !ok { - panic("arm Map is not set") + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeMap { + return *u.Map } - - return val + panic("arm Map is not set") } // GetMap retrieves the Map value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecTypeDef) GetMap() (result ScSpecTypeMap, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Map" { + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeMap { result = *u.Map ok = true } - return } // MustTuple retrieves the Tuple value from the union, // panicing if the value is not set. func (u ScSpecTypeDef) MustTuple() ScSpecTypeTuple { - val, ok := u.GetTuple() - - if !ok { - panic("arm Tuple is not set") + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeTuple { + return *u.Tuple } - - return val + panic("arm Tuple is not set") } // GetTuple retrieves the Tuple value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecTypeDef) GetTuple() (result ScSpecTypeTuple, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Tuple" { + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeTuple { result = *u.Tuple ok = true } - return } // MustBytesN retrieves the BytesN value from the union, // panicing if the value is not set. func (u ScSpecTypeDef) MustBytesN() ScSpecTypeBytesN { - val, ok := u.GetBytesN() - - if !ok { - panic("arm BytesN is not set") + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeBytesN { + return *u.BytesN } - - return val + panic("arm BytesN is not set") } // GetBytesN retrieves the BytesN value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecTypeDef) GetBytesN() (result ScSpecTypeBytesN, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "BytesN" { + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeBytesN { result = *u.BytesN ok = true } - return } // MustUdt retrieves the Udt value from the union, // panicing if the value is not set. func (u ScSpecTypeDef) MustUdt() ScSpecTypeUdt { - val, ok := u.GetUdt() - - if !ok { - panic("arm Udt is not set") + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeUdt { + return *u.Udt } - - return val + panic("arm Udt is not set") } // GetUdt retrieves the Udt value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecTypeDef) GetUdt() (result ScSpecTypeUdt, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Udt" { + if ScSpecType(u.Type) == ScSpecTypeScSpecTypeUdt { result = *u.Udt ok = true } - return } @@ -52701,9 +51182,9 @@ func (u ScSpecTypeDef) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (ScSpecType) switch value '%d' is not valid for union ScSpecTypeDef", u.Type) } -var _ decoderFrom = (*ScSpecTypeDef)(nil) +var _ xdr.DecoderFrom = (*ScSpecTypeDef)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ScSpecTypeDef) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecTypeDef: %w", ErrMaxDecodingDepthReached) @@ -52775,7 +51256,9 @@ func (u *ScSpecTypeDef) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { // Void return n, nil case ScSpecTypeScSpecTypeOption: - u.Option = new(ScSpecTypeOption) + if u.Option == nil { + u.Option = new(ScSpecTypeOption) + } nTmp, err = (*u.Option).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -52783,7 +51266,9 @@ func (u *ScSpecTypeDef) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScSpecTypeScSpecTypeResult: - u.Result = new(ScSpecTypeResult) + if u.Result == nil { + u.Result = new(ScSpecTypeResult) + } nTmp, err = (*u.Result).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -52791,7 +51276,9 @@ func (u *ScSpecTypeDef) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScSpecTypeScSpecTypeVec: - u.Vec = new(ScSpecTypeVec) + if u.Vec == nil { + u.Vec = new(ScSpecTypeVec) + } nTmp, err = (*u.Vec).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -52799,7 +51286,9 @@ func (u *ScSpecTypeDef) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScSpecTypeScSpecTypeMap: - u.Map = new(ScSpecTypeMap) + if u.Map == nil { + u.Map = new(ScSpecTypeMap) + } nTmp, err = (*u.Map).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -52807,7 +51296,9 @@ func (u *ScSpecTypeDef) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScSpecTypeScSpecTypeTuple: - u.Tuple = new(ScSpecTypeTuple) + if u.Tuple == nil { + u.Tuple = new(ScSpecTypeTuple) + } nTmp, err = (*u.Tuple).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -52815,7 +51306,9 @@ func (u *ScSpecTypeDef) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScSpecTypeScSpecTypeBytesN: - u.BytesN = new(ScSpecTypeBytesN) + if u.BytesN == nil { + u.BytesN = new(ScSpecTypeBytesN) + } nTmp, err = (*u.BytesN).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -52823,7 +51316,9 @@ func (u *ScSpecTypeDef) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScSpecTypeScSpecTypeUdt: - u.Udt = new(ScSpecTypeUdt) + if u.Udt == nil { + u.Udt = new(ScSpecTypeUdt) + } nTmp, err = (*u.Udt).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -52844,11 +51339,8 @@ func (s ScSpecTypeDef) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecTypeDef) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -52891,9 +51383,9 @@ func (s *ScSpecUdtStructFieldV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecUdtStructFieldV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecUdtStructFieldV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecUdtStructFieldV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecUdtStructFieldV0: %w", ErrMaxDecodingDepthReached) @@ -52929,11 +51421,8 @@ func (s ScSpecUdtStructFieldV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecUdtStructFieldV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -52986,9 +51475,9 @@ func (s *ScSpecUdtStructV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecUdtStructV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecUdtStructV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecUdtStructV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecUdtStructV0: %w", ErrMaxDecodingDepthReached) @@ -53017,12 +51506,17 @@ func (s *ScSpecUdtStructV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro if err != nil { return n, fmt.Errorf("decoding ScSpecUdtStructFieldV0: %w", err) } - s.Fields = nil - if l > 0 { + if l == 0 { + s.Fields = s.Fields[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScSpecUdtStructFieldV0: length (%d) exceeds remaining input length (%d)", l, il) } - s.Fields = make([]ScSpecUdtStructFieldV0, l) + if cap(s.Fields) >= int(l) { + s.Fields = s.Fields[:l] + } else { + s.Fields = make([]ScSpecUdtStructFieldV0, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Fields[i].DecodeFrom(d, maxDepth) n += nTmp @@ -53044,11 +51538,8 @@ func (s ScSpecUdtStructV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecUdtStructV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -53086,9 +51577,9 @@ func (s *ScSpecUdtUnionCaseVoidV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecUdtUnionCaseVoidV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecUdtUnionCaseVoidV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecUdtUnionCaseVoidV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecUdtUnionCaseVoidV0: %w", ErrMaxDecodingDepthReached) @@ -53119,11 +51610,8 @@ func (s ScSpecUdtUnionCaseVoidV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecUdtUnionCaseVoidV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -53171,9 +51659,9 @@ func (s *ScSpecUdtUnionCaseTupleV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecUdtUnionCaseTupleV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecUdtUnionCaseTupleV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecUdtUnionCaseTupleV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecUdtUnionCaseTupleV0: %w", ErrMaxDecodingDepthReached) @@ -53197,12 +51685,17 @@ func (s *ScSpecUdtUnionCaseTupleV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (i if err != nil { return n, fmt.Errorf("decoding ScSpecTypeDef: %w", err) } - s.Type = nil - if l > 0 { + if l == 0 { + s.Type = s.Type[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScSpecTypeDef: length (%d) exceeds remaining input length (%d)", l, il) } - s.Type = make([]ScSpecTypeDef, l) + if cap(s.Type) >= int(l) { + s.Type = s.Type[:l] + } else { + s.Type = make([]ScSpecTypeDef, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Type[i].DecodeFrom(d, maxDepth) n += nTmp @@ -53224,11 +51717,8 @@ func (s ScSpecUdtUnionCaseTupleV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecUdtUnionCaseTupleV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -53255,6 +51745,10 @@ const ( ScSpecUdtUnionCaseV0KindScSpecUdtUnionCaseVoidV0 ScSpecUdtUnionCaseV0Kind = 0 ScSpecUdtUnionCaseV0KindScSpecUdtUnionCaseTupleV0 ScSpecUdtUnionCaseV0Kind = 1 ) +const ( + _ScSpecUdtUnionCaseV0Kind_Min int32 = 0 + _ScSpecUdtUnionCaseV0Kind_Max int32 = 1 +) var scSpecUdtUnionCaseV0KindMap = map[int32]string{ 0: "ScSpecUdtUnionCaseV0KindScSpecUdtUnionCaseVoidV0", @@ -53264,8 +51758,7 @@ var scSpecUdtUnionCaseV0KindMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScSpecUdtUnionCaseV0Kind func (e ScSpecUdtUnionCaseV0Kind) ValidEnum(v int32) bool { - _, ok := scSpecUdtUnionCaseV0KindMap[v] - return ok + return v >= _ScSpecUdtUnionCaseV0Kind_Min && v <= _ScSpecUdtUnionCaseV0Kind_Max } // String returns the name of `e` @@ -53276,16 +51769,16 @@ func (e ScSpecUdtUnionCaseV0Kind) String() string { // EncodeTo encodes this value using the Encoder. func (e ScSpecUdtUnionCaseV0Kind) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scSpecUdtUnionCaseV0KindMap[int32(e)]; !ok { + if int32(e) < _ScSpecUdtUnionCaseV0Kind_Min || int32(e) > _ScSpecUdtUnionCaseV0Kind_Max { return fmt.Errorf("'%d' is not a valid ScSpecUdtUnionCaseV0Kind enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScSpecUdtUnionCaseV0Kind)(nil) +var _ xdr.DecoderFrom = (*ScSpecUdtUnionCaseV0Kind)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScSpecUdtUnionCaseV0Kind) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecUdtUnionCaseV0Kind: %w", ErrMaxDecodingDepthReached) @@ -53295,7 +51788,7 @@ func (e *ScSpecUdtUnionCaseV0Kind) DecodeFrom(d *xdr.Decoder, maxDepth uint) (in if err != nil { return n, fmt.Errorf("decoding ScSpecUdtUnionCaseV0Kind: %w", err) } - if _, ok := scSpecUdtUnionCaseV0KindMap[v]; !ok { + if v < _ScSpecUdtUnionCaseV0Kind_Min || v > _ScSpecUdtUnionCaseV0Kind_Max { return n, fmt.Errorf("'%d' is not a valid ScSpecUdtUnionCaseV0Kind enum value", v) } *e = ScSpecUdtUnionCaseV0Kind(v) @@ -53312,11 +51805,8 @@ func (s ScSpecUdtUnionCaseV0Kind) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecUdtUnionCaseV0Kind) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -53388,50 +51878,38 @@ func NewScSpecUdtUnionCaseV0(kind ScSpecUdtUnionCaseV0Kind, value interface{}) ( // MustVoidCase retrieves the VoidCase value from the union, // panicing if the value is not set. func (u ScSpecUdtUnionCaseV0) MustVoidCase() ScSpecUdtUnionCaseVoidV0 { - val, ok := u.GetVoidCase() - - if !ok { - panic("arm VoidCase is not set") + if ScSpecUdtUnionCaseV0Kind(u.Kind) == ScSpecUdtUnionCaseV0KindScSpecUdtUnionCaseVoidV0 { + return *u.VoidCase } - - return val + panic("arm VoidCase is not set") } // GetVoidCase retrieves the VoidCase value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecUdtUnionCaseV0) GetVoidCase() (result ScSpecUdtUnionCaseVoidV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Kind)) - - if armName == "VoidCase" { + if ScSpecUdtUnionCaseV0Kind(u.Kind) == ScSpecUdtUnionCaseV0KindScSpecUdtUnionCaseVoidV0 { result = *u.VoidCase ok = true } - return } // MustTupleCase retrieves the TupleCase value from the union, // panicing if the value is not set. func (u ScSpecUdtUnionCaseV0) MustTupleCase() ScSpecUdtUnionCaseTupleV0 { - val, ok := u.GetTupleCase() - - if !ok { - panic("arm TupleCase is not set") + if ScSpecUdtUnionCaseV0Kind(u.Kind) == ScSpecUdtUnionCaseV0KindScSpecUdtUnionCaseTupleV0 { + return *u.TupleCase } - - return val + panic("arm TupleCase is not set") } // GetTupleCase retrieves the TupleCase value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecUdtUnionCaseV0) GetTupleCase() (result ScSpecUdtUnionCaseTupleV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Kind)) - - if armName == "TupleCase" { + if ScSpecUdtUnionCaseV0Kind(u.Kind) == ScSpecUdtUnionCaseV0KindScSpecUdtUnionCaseTupleV0 { result = *u.TupleCase ok = true } - return } @@ -53456,9 +51934,9 @@ func (u ScSpecUdtUnionCaseV0) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Kind (ScSpecUdtUnionCaseV0Kind) switch value '%d' is not valid for union ScSpecUdtUnionCaseV0", u.Kind) } -var _ decoderFrom = (*ScSpecUdtUnionCaseV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecUdtUnionCaseV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ScSpecUdtUnionCaseV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecUdtUnionCaseV0: %w", ErrMaxDecodingDepthReached) @@ -53473,7 +51951,9 @@ func (u *ScSpecUdtUnionCaseV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e } switch ScSpecUdtUnionCaseV0Kind(u.Kind) { case ScSpecUdtUnionCaseV0KindScSpecUdtUnionCaseVoidV0: - u.VoidCase = new(ScSpecUdtUnionCaseVoidV0) + if u.VoidCase == nil { + u.VoidCase = new(ScSpecUdtUnionCaseVoidV0) + } nTmp, err = (*u.VoidCase).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -53481,7 +51961,9 @@ func (u *ScSpecUdtUnionCaseV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e } return n, nil case ScSpecUdtUnionCaseV0KindScSpecUdtUnionCaseTupleV0: - u.TupleCase = new(ScSpecUdtUnionCaseTupleV0) + if u.TupleCase == nil { + u.TupleCase = new(ScSpecUdtUnionCaseTupleV0) + } nTmp, err = (*u.TupleCase).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -53502,11 +51984,8 @@ func (s ScSpecUdtUnionCaseV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecUdtUnionCaseV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -53559,9 +52038,9 @@ func (s *ScSpecUdtUnionV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecUdtUnionV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecUdtUnionV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecUdtUnionV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecUdtUnionV0: %w", ErrMaxDecodingDepthReached) @@ -53590,12 +52069,17 @@ func (s *ScSpecUdtUnionV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error if err != nil { return n, fmt.Errorf("decoding ScSpecUdtUnionCaseV0: %w", err) } - s.Cases = nil - if l > 0 { + if l == 0 { + s.Cases = s.Cases[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScSpecUdtUnionCaseV0: length (%d) exceeds remaining input length (%d)", l, il) } - s.Cases = make([]ScSpecUdtUnionCaseV0, l) + if cap(s.Cases) >= int(l) { + s.Cases = s.Cases[:l] + } else { + s.Cases = make([]ScSpecUdtUnionCaseV0, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Cases[i].DecodeFrom(d, maxDepth) n += nTmp @@ -53617,11 +52101,8 @@ func (s ScSpecUdtUnionV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecUdtUnionV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -53664,9 +52145,9 @@ func (s *ScSpecUdtEnumCaseV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecUdtEnumCaseV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecUdtEnumCaseV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecUdtEnumCaseV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecUdtEnumCaseV0: %w", ErrMaxDecodingDepthReached) @@ -53702,11 +52183,8 @@ func (s ScSpecUdtEnumCaseV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecUdtEnumCaseV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -53759,9 +52237,9 @@ func (s *ScSpecUdtEnumV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecUdtEnumV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecUdtEnumV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecUdtEnumV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecUdtEnumV0: %w", ErrMaxDecodingDepthReached) @@ -53790,12 +52268,17 @@ func (s *ScSpecUdtEnumV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding ScSpecUdtEnumCaseV0: %w", err) } - s.Cases = nil - if l > 0 { + if l == 0 { + s.Cases = s.Cases[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScSpecUdtEnumCaseV0: length (%d) exceeds remaining input length (%d)", l, il) } - s.Cases = make([]ScSpecUdtEnumCaseV0, l) + if cap(s.Cases) >= int(l) { + s.Cases = s.Cases[:l] + } else { + s.Cases = make([]ScSpecUdtEnumCaseV0, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Cases[i].DecodeFrom(d, maxDepth) n += nTmp @@ -53817,11 +52300,8 @@ func (s ScSpecUdtEnumV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecUdtEnumV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -53864,9 +52344,9 @@ func (s *ScSpecUdtErrorEnumCaseV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecUdtErrorEnumCaseV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecUdtErrorEnumCaseV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecUdtErrorEnumCaseV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecUdtErrorEnumCaseV0: %w", ErrMaxDecodingDepthReached) @@ -53902,11 +52382,8 @@ func (s ScSpecUdtErrorEnumCaseV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecUdtErrorEnumCaseV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -53959,9 +52436,9 @@ func (s *ScSpecUdtErrorEnumV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecUdtErrorEnumV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecUdtErrorEnumV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecUdtErrorEnumV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecUdtErrorEnumV0: %w", ErrMaxDecodingDepthReached) @@ -53990,12 +52467,17 @@ func (s *ScSpecUdtErrorEnumV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e if err != nil { return n, fmt.Errorf("decoding ScSpecUdtErrorEnumCaseV0: %w", err) } - s.Cases = nil - if l > 0 { + if l == 0 { + s.Cases = s.Cases[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScSpecUdtErrorEnumCaseV0: length (%d) exceeds remaining input length (%d)", l, il) } - s.Cases = make([]ScSpecUdtErrorEnumCaseV0, l) + if cap(s.Cases) >= int(l) { + s.Cases = s.Cases[:l] + } else { + s.Cases = make([]ScSpecUdtErrorEnumCaseV0, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Cases[i].DecodeFrom(d, maxDepth) n += nTmp @@ -54017,11 +52499,8 @@ func (s ScSpecUdtErrorEnumV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecUdtErrorEnumV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -54064,9 +52543,9 @@ func (s *ScSpecFunctionInputV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecFunctionInputV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecFunctionInputV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecFunctionInputV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecFunctionInputV0: %w", ErrMaxDecodingDepthReached) @@ -54102,11 +52581,8 @@ func (s ScSpecFunctionInputV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecFunctionInputV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -54164,9 +52640,9 @@ func (s *ScSpecFunctionV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecFunctionV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecFunctionV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecFunctionV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecFunctionV0: %w", ErrMaxDecodingDepthReached) @@ -54190,12 +52666,17 @@ func (s *ScSpecFunctionV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error if err != nil { return n, fmt.Errorf("decoding ScSpecFunctionInputV0: %w", err) } - s.Inputs = nil - if l > 0 { + if l == 0 { + s.Inputs = s.Inputs[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScSpecFunctionInputV0: length (%d) exceeds remaining input length (%d)", l, il) } - s.Inputs = make([]ScSpecFunctionInputV0, l) + if cap(s.Inputs) >= int(l) { + s.Inputs = s.Inputs[:l] + } else { + s.Inputs = make([]ScSpecFunctionInputV0, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Inputs[i].DecodeFrom(d, maxDepth) n += nTmp @@ -54212,12 +52693,17 @@ func (s *ScSpecFunctionV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error if l > 1 { return n, fmt.Errorf("decoding ScSpecTypeDef: data size (%d) exceeds size limit (1)", l) } - s.Outputs = nil - if l > 0 { + if l == 0 { + s.Outputs = s.Outputs[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScSpecTypeDef: length (%d) exceeds remaining input length (%d)", l, il) } - s.Outputs = make([]ScSpecTypeDef, l) + if cap(s.Outputs) >= int(l) { + s.Outputs = s.Outputs[:l] + } else { + s.Outputs = make([]ScSpecTypeDef, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Outputs[i].DecodeFrom(d, maxDepth) n += nTmp @@ -54239,11 +52725,8 @@ func (s ScSpecFunctionV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecFunctionV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -54270,6 +52753,10 @@ const ( ScSpecEventParamLocationV0ScSpecEventParamLocationData ScSpecEventParamLocationV0 = 0 ScSpecEventParamLocationV0ScSpecEventParamLocationTopicList ScSpecEventParamLocationV0 = 1 ) +const ( + _ScSpecEventParamLocationV0_Min int32 = 0 + _ScSpecEventParamLocationV0_Max int32 = 1 +) var scSpecEventParamLocationV0Map = map[int32]string{ 0: "ScSpecEventParamLocationV0ScSpecEventParamLocationData", @@ -54279,8 +52766,7 @@ var scSpecEventParamLocationV0Map = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScSpecEventParamLocationV0 func (e ScSpecEventParamLocationV0) ValidEnum(v int32) bool { - _, ok := scSpecEventParamLocationV0Map[v] - return ok + return v >= _ScSpecEventParamLocationV0_Min && v <= _ScSpecEventParamLocationV0_Max } // String returns the name of `e` @@ -54291,16 +52777,16 @@ func (e ScSpecEventParamLocationV0) String() string { // EncodeTo encodes this value using the Encoder. func (e ScSpecEventParamLocationV0) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scSpecEventParamLocationV0Map[int32(e)]; !ok { + if int32(e) < _ScSpecEventParamLocationV0_Min || int32(e) > _ScSpecEventParamLocationV0_Max { return fmt.Errorf("'%d' is not a valid ScSpecEventParamLocationV0 enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScSpecEventParamLocationV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecEventParamLocationV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScSpecEventParamLocationV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecEventParamLocationV0: %w", ErrMaxDecodingDepthReached) @@ -54310,7 +52796,7 @@ func (e *ScSpecEventParamLocationV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) ( if err != nil { return n, fmt.Errorf("decoding ScSpecEventParamLocationV0: %w", err) } - if _, ok := scSpecEventParamLocationV0Map[v]; !ok { + if v < _ScSpecEventParamLocationV0_Min || v > _ScSpecEventParamLocationV0_Max { return n, fmt.Errorf("'%d' is not a valid ScSpecEventParamLocationV0 enum value", v) } *e = ScSpecEventParamLocationV0(v) @@ -54327,11 +52813,8 @@ func (s ScSpecEventParamLocationV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecEventParamLocationV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -54379,9 +52862,9 @@ func (s *ScSpecEventParamV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecEventParamV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecEventParamV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecEventParamV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecEventParamV0: %w", ErrMaxDecodingDepthReached) @@ -54422,11 +52905,8 @@ func (s ScSpecEventParamV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecEventParamV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -54455,6 +52935,10 @@ const ( ScSpecEventDataFormatScSpecEventDataFormatVec ScSpecEventDataFormat = 1 ScSpecEventDataFormatScSpecEventDataFormatMap ScSpecEventDataFormat = 2 ) +const ( + _ScSpecEventDataFormat_Min int32 = 0 + _ScSpecEventDataFormat_Max int32 = 2 +) var scSpecEventDataFormatMap = map[int32]string{ 0: "ScSpecEventDataFormatScSpecEventDataFormatSingleValue", @@ -54465,8 +52949,7 @@ var scSpecEventDataFormatMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScSpecEventDataFormat func (e ScSpecEventDataFormat) ValidEnum(v int32) bool { - _, ok := scSpecEventDataFormatMap[v] - return ok + return v >= _ScSpecEventDataFormat_Min && v <= _ScSpecEventDataFormat_Max } // String returns the name of `e` @@ -54477,16 +52960,16 @@ func (e ScSpecEventDataFormat) String() string { // EncodeTo encodes this value using the Encoder. func (e ScSpecEventDataFormat) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scSpecEventDataFormatMap[int32(e)]; !ok { + if int32(e) < _ScSpecEventDataFormat_Min || int32(e) > _ScSpecEventDataFormat_Max { return fmt.Errorf("'%d' is not a valid ScSpecEventDataFormat enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScSpecEventDataFormat)(nil) +var _ xdr.DecoderFrom = (*ScSpecEventDataFormat)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScSpecEventDataFormat) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecEventDataFormat: %w", ErrMaxDecodingDepthReached) @@ -54496,7 +52979,7 @@ func (e *ScSpecEventDataFormat) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding ScSpecEventDataFormat: %w", err) } - if _, ok := scSpecEventDataFormatMap[v]; !ok { + if v < _ScSpecEventDataFormat_Min || v > _ScSpecEventDataFormat_Max { return n, fmt.Errorf("'%d' is not a valid ScSpecEventDataFormat enum value", v) } *e = ScSpecEventDataFormat(v) @@ -54513,11 +52996,8 @@ func (s ScSpecEventDataFormat) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecEventDataFormat) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -54585,9 +53065,9 @@ func (s *ScSpecEventV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSpecEventV0)(nil) +var _ xdr.DecoderFrom = (*ScSpecEventV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSpecEventV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecEventV0: %w", ErrMaxDecodingDepthReached) @@ -54619,12 +53099,17 @@ func (s *ScSpecEventV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if l > 2 { return n, fmt.Errorf("decoding ScSymbol: data size (%d) exceeds size limit (2)", l) } - s.PrefixTopics = nil - if l > 0 { + if l == 0 { + s.PrefixTopics = s.PrefixTopics[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScSymbol: length (%d) exceeds remaining input length (%d)", l, il) } - s.PrefixTopics = make([]ScSymbol, l) + if cap(s.PrefixTopics) >= int(l) { + s.PrefixTopics = s.PrefixTopics[:l] + } else { + s.PrefixTopics = make([]ScSymbol, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.PrefixTopics[i].DecodeFrom(d, maxDepth) n += nTmp @@ -54638,12 +53123,17 @@ func (s *ScSpecEventV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ScSpecEventParamV0: %w", err) } - s.Params = nil - if l > 0 { + if l == 0 { + s.Params = s.Params[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScSpecEventParamV0: length (%d) exceeds remaining input length (%d)", l, il) } - s.Params = make([]ScSpecEventParamV0, l) + if cap(s.Params) >= int(l) { + s.Params = s.Params[:l] + } else { + s.Params = make([]ScSpecEventParamV0, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.Params[i].DecodeFrom(d, maxDepth) n += nTmp @@ -54670,11 +53160,8 @@ func (s ScSpecEventV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecEventV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -54709,6 +53196,10 @@ const ( ScSpecEntryKindScSpecEntryUdtErrorEnumV0 ScSpecEntryKind = 4 ScSpecEntryKindScSpecEntryEventV0 ScSpecEntryKind = 5 ) +const ( + _ScSpecEntryKind_Min int32 = 0 + _ScSpecEntryKind_Max int32 = 5 +) var scSpecEntryKindMap = map[int32]string{ 0: "ScSpecEntryKindScSpecEntryFunctionV0", @@ -54722,8 +53213,7 @@ var scSpecEntryKindMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScSpecEntryKind func (e ScSpecEntryKind) ValidEnum(v int32) bool { - _, ok := scSpecEntryKindMap[v] - return ok + return v >= _ScSpecEntryKind_Min && v <= _ScSpecEntryKind_Max } // String returns the name of `e` @@ -54734,16 +53224,16 @@ func (e ScSpecEntryKind) String() string { // EncodeTo encodes this value using the Encoder. func (e ScSpecEntryKind) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scSpecEntryKindMap[int32(e)]; !ok { + if int32(e) < _ScSpecEntryKind_Min || int32(e) > _ScSpecEntryKind_Max { return fmt.Errorf("'%d' is not a valid ScSpecEntryKind enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScSpecEntryKind)(nil) +var _ xdr.DecoderFrom = (*ScSpecEntryKind)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScSpecEntryKind) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecEntryKind: %w", ErrMaxDecodingDepthReached) @@ -54753,7 +53243,7 @@ func (e *ScSpecEntryKind) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding ScSpecEntryKind: %w", err) } - if _, ok := scSpecEntryKindMap[v]; !ok { + if v < _ScSpecEntryKind_Min || v > _ScSpecEntryKind_Max { return n, fmt.Errorf("'%d' is not a valid ScSpecEntryKind enum value", v) } *e = ScSpecEntryKind(v) @@ -54770,11 +53260,8 @@ func (s ScSpecEntryKind) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecEntryKind) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -54894,150 +53381,114 @@ func NewScSpecEntry(kind ScSpecEntryKind, value interface{}) (result ScSpecEntry // MustFunctionV0 retrieves the FunctionV0 value from the union, // panicing if the value is not set. func (u ScSpecEntry) MustFunctionV0() ScSpecFunctionV0 { - val, ok := u.GetFunctionV0() - - if !ok { - panic("arm FunctionV0 is not set") + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryFunctionV0 { + return *u.FunctionV0 } - - return val + panic("arm FunctionV0 is not set") } // GetFunctionV0 retrieves the FunctionV0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecEntry) GetFunctionV0() (result ScSpecFunctionV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Kind)) - - if armName == "FunctionV0" { + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryFunctionV0 { result = *u.FunctionV0 ok = true } - return } // MustUdtStructV0 retrieves the UdtStructV0 value from the union, // panicing if the value is not set. func (u ScSpecEntry) MustUdtStructV0() ScSpecUdtStructV0 { - val, ok := u.GetUdtStructV0() - - if !ok { - panic("arm UdtStructV0 is not set") + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryUdtStructV0 { + return *u.UdtStructV0 } - - return val + panic("arm UdtStructV0 is not set") } // GetUdtStructV0 retrieves the UdtStructV0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecEntry) GetUdtStructV0() (result ScSpecUdtStructV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Kind)) - - if armName == "UdtStructV0" { + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryUdtStructV0 { result = *u.UdtStructV0 ok = true } - return } // MustUdtUnionV0 retrieves the UdtUnionV0 value from the union, // panicing if the value is not set. func (u ScSpecEntry) MustUdtUnionV0() ScSpecUdtUnionV0 { - val, ok := u.GetUdtUnionV0() - - if !ok { - panic("arm UdtUnionV0 is not set") + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryUdtUnionV0 { + return *u.UdtUnionV0 } - - return val + panic("arm UdtUnionV0 is not set") } // GetUdtUnionV0 retrieves the UdtUnionV0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecEntry) GetUdtUnionV0() (result ScSpecUdtUnionV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Kind)) - - if armName == "UdtUnionV0" { + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryUdtUnionV0 { result = *u.UdtUnionV0 ok = true } - return } // MustUdtEnumV0 retrieves the UdtEnumV0 value from the union, // panicing if the value is not set. func (u ScSpecEntry) MustUdtEnumV0() ScSpecUdtEnumV0 { - val, ok := u.GetUdtEnumV0() - - if !ok { - panic("arm UdtEnumV0 is not set") + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryUdtEnumV0 { + return *u.UdtEnumV0 } - - return val + panic("arm UdtEnumV0 is not set") } // GetUdtEnumV0 retrieves the UdtEnumV0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecEntry) GetUdtEnumV0() (result ScSpecUdtEnumV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Kind)) - - if armName == "UdtEnumV0" { + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryUdtEnumV0 { result = *u.UdtEnumV0 ok = true } - return } // MustUdtErrorEnumV0 retrieves the UdtErrorEnumV0 value from the union, // panicing if the value is not set. func (u ScSpecEntry) MustUdtErrorEnumV0() ScSpecUdtErrorEnumV0 { - val, ok := u.GetUdtErrorEnumV0() - - if !ok { - panic("arm UdtErrorEnumV0 is not set") + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryUdtErrorEnumV0 { + return *u.UdtErrorEnumV0 } - - return val + panic("arm UdtErrorEnumV0 is not set") } // GetUdtErrorEnumV0 retrieves the UdtErrorEnumV0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecEntry) GetUdtErrorEnumV0() (result ScSpecUdtErrorEnumV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Kind)) - - if armName == "UdtErrorEnumV0" { + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryUdtErrorEnumV0 { result = *u.UdtErrorEnumV0 ok = true } - return } // MustEventV0 retrieves the EventV0 value from the union, // panicing if the value is not set. func (u ScSpecEntry) MustEventV0() ScSpecEventV0 { - val, ok := u.GetEventV0() - - if !ok { - panic("arm EventV0 is not set") + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryEventV0 { + return *u.EventV0 } - - return val + panic("arm EventV0 is not set") } // GetEventV0 retrieves the EventV0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScSpecEntry) GetEventV0() (result ScSpecEventV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Kind)) - - if armName == "EventV0" { + if ScSpecEntryKind(u.Kind) == ScSpecEntryKindScSpecEntryEventV0 { result = *u.EventV0 ok = true } - return } @@ -55082,9 +53533,9 @@ func (u ScSpecEntry) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Kind (ScSpecEntryKind) switch value '%d' is not valid for union ScSpecEntry", u.Kind) } -var _ decoderFrom = (*ScSpecEntry)(nil) +var _ xdr.DecoderFrom = (*ScSpecEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ScSpecEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSpecEntry: %w", ErrMaxDecodingDepthReached) @@ -55099,7 +53550,9 @@ func (u *ScSpecEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch ScSpecEntryKind(u.Kind) { case ScSpecEntryKindScSpecEntryFunctionV0: - u.FunctionV0 = new(ScSpecFunctionV0) + if u.FunctionV0 == nil { + u.FunctionV0 = new(ScSpecFunctionV0) + } nTmp, err = (*u.FunctionV0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -55107,7 +53560,9 @@ func (u *ScSpecEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScSpecEntryKindScSpecEntryUdtStructV0: - u.UdtStructV0 = new(ScSpecUdtStructV0) + if u.UdtStructV0 == nil { + u.UdtStructV0 = new(ScSpecUdtStructV0) + } nTmp, err = (*u.UdtStructV0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -55115,7 +53570,9 @@ func (u *ScSpecEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScSpecEntryKindScSpecEntryUdtUnionV0: - u.UdtUnionV0 = new(ScSpecUdtUnionV0) + if u.UdtUnionV0 == nil { + u.UdtUnionV0 = new(ScSpecUdtUnionV0) + } nTmp, err = (*u.UdtUnionV0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -55123,7 +53580,9 @@ func (u *ScSpecEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScSpecEntryKindScSpecEntryUdtEnumV0: - u.UdtEnumV0 = new(ScSpecUdtEnumV0) + if u.UdtEnumV0 == nil { + u.UdtEnumV0 = new(ScSpecUdtEnumV0) + } nTmp, err = (*u.UdtEnumV0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -55131,7 +53590,9 @@ func (u *ScSpecEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScSpecEntryKindScSpecEntryUdtErrorEnumV0: - u.UdtErrorEnumV0 = new(ScSpecUdtErrorEnumV0) + if u.UdtErrorEnumV0 == nil { + u.UdtErrorEnumV0 = new(ScSpecUdtErrorEnumV0) + } nTmp, err = (*u.UdtErrorEnumV0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -55139,7 +53600,9 @@ func (u *ScSpecEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScSpecEntryKindScSpecEntryEventV0: - u.EventV0 = new(ScSpecEventV0) + if u.EventV0 == nil { + u.EventV0 = new(ScSpecEventV0) + } nTmp, err = (*u.EventV0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -55160,11 +53623,8 @@ func (s ScSpecEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSpecEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -55260,6 +53720,10 @@ const ( ScValTypeScvLedgerKeyContractInstance ScValType = 20 ScValTypeScvLedgerKeyNonce ScValType = 21 ) +const ( + _ScValType_Min int32 = 0 + _ScValType_Max int32 = 21 +) var scValTypeMap = map[int32]string{ 0: "ScValTypeScvBool", @@ -55289,8 +53753,7 @@ var scValTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScValType func (e ScValType) ValidEnum(v int32) bool { - _, ok := scValTypeMap[v] - return ok + return v >= _ScValType_Min && v <= _ScValType_Max } // String returns the name of `e` @@ -55301,16 +53764,16 @@ func (e ScValType) String() string { // EncodeTo encodes this value using the Encoder. func (e ScValType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scValTypeMap[int32(e)]; !ok { + if int32(e) < _ScValType_Min || int32(e) > _ScValType_Max { return fmt.Errorf("'%d' is not a valid ScValType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScValType)(nil) +var _ xdr.DecoderFrom = (*ScValType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScValType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScValType: %w", ErrMaxDecodingDepthReached) @@ -55320,7 +53783,7 @@ func (e *ScValType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ScValType: %w", err) } - if _, ok := scValTypeMap[v]; !ok { + if v < _ScValType_Min || v > _ScValType_Max { return n, fmt.Errorf("'%d' is not a valid ScValType enum value", v) } *e = ScValType(v) @@ -55337,11 +53800,8 @@ func (s ScValType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScValType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -55384,6 +53844,10 @@ const ( ScErrorTypeSceValue ScErrorType = 8 ScErrorTypeSceAuth ScErrorType = 9 ) +const ( + _ScErrorType_Min int32 = 0 + _ScErrorType_Max int32 = 9 +) var scErrorTypeMap = map[int32]string{ 0: "ScErrorTypeSceContract", @@ -55401,8 +53865,7 @@ var scErrorTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScErrorType func (e ScErrorType) ValidEnum(v int32) bool { - _, ok := scErrorTypeMap[v] - return ok + return v >= _ScErrorType_Min && v <= _ScErrorType_Max } // String returns the name of `e` @@ -55413,16 +53876,16 @@ func (e ScErrorType) String() string { // EncodeTo encodes this value using the Encoder. func (e ScErrorType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scErrorTypeMap[int32(e)]; !ok { + if int32(e) < _ScErrorType_Min || int32(e) > _ScErrorType_Max { return fmt.Errorf("'%d' is not a valid ScErrorType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScErrorType)(nil) +var _ xdr.DecoderFrom = (*ScErrorType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScErrorType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScErrorType: %w", ErrMaxDecodingDepthReached) @@ -55432,7 +53895,7 @@ func (e *ScErrorType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ScErrorType: %w", err) } - if _, ok := scErrorTypeMap[v]; !ok { + if v < _ScErrorType_Min || v > _ScErrorType_Max { return n, fmt.Errorf("'%d' is not a valid ScErrorType enum value", v) } *e = ScErrorType(v) @@ -55449,11 +53912,8 @@ func (s ScErrorType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScErrorType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -55496,6 +53956,10 @@ const ( ScErrorCodeScecUnexpectedType ScErrorCode = 8 ScErrorCodeScecUnexpectedSize ScErrorCode = 9 ) +const ( + _ScErrorCode_Min int32 = 0 + _ScErrorCode_Max int32 = 9 +) var scErrorCodeMap = map[int32]string{ 0: "ScErrorCodeScecArithDomain", @@ -55513,8 +53977,7 @@ var scErrorCodeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScErrorCode func (e ScErrorCode) ValidEnum(v int32) bool { - _, ok := scErrorCodeMap[v] - return ok + return v >= _ScErrorCode_Min && v <= _ScErrorCode_Max } // String returns the name of `e` @@ -55525,16 +53988,16 @@ func (e ScErrorCode) String() string { // EncodeTo encodes this value using the Encoder. func (e ScErrorCode) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scErrorCodeMap[int32(e)]; !ok { + if int32(e) < _ScErrorCode_Min || int32(e) > _ScErrorCode_Max { return fmt.Errorf("'%d' is not a valid ScErrorCode enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScErrorCode)(nil) +var _ xdr.DecoderFrom = (*ScErrorCode)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScErrorCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScErrorCode: %w", ErrMaxDecodingDepthReached) @@ -55544,7 +54007,7 @@ func (e *ScErrorCode) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ScErrorCode: %w", err) } - if _, ok := scErrorCodeMap[v]; !ok { + if v < _ScErrorCode_Min || v > _ScErrorCode_Max { return n, fmt.Errorf("'%d' is not a valid ScErrorCode enum value", v) } *e = ScErrorCode(v) @@ -55561,11 +54024,8 @@ func (s ScErrorCode) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScErrorCode) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -55598,8 +54058,8 @@ var _ xdrType = (*ScErrorCode)(nil) // }; type ScError struct { Type ScErrorType - ContractCode *Uint32 - Code *ScErrorCode + ContractCode Uint32 + Code ScErrorCode } // SwitchFieldName returns the field name in which this union's @@ -55646,70 +54106,70 @@ func NewScError(aType ScErrorType, value interface{}) (result ScError, err error err = errors.New("invalid value, must be Uint32") return } - result.ContractCode = &tv + result.ContractCode = tv case ScErrorTypeSceWasmVm: tv, ok := value.(ScErrorCode) if !ok { err = errors.New("invalid value, must be ScErrorCode") return } - result.Code = &tv + result.Code = tv case ScErrorTypeSceContext: tv, ok := value.(ScErrorCode) if !ok { err = errors.New("invalid value, must be ScErrorCode") return } - result.Code = &tv + result.Code = tv case ScErrorTypeSceStorage: tv, ok := value.(ScErrorCode) if !ok { err = errors.New("invalid value, must be ScErrorCode") return } - result.Code = &tv + result.Code = tv case ScErrorTypeSceObject: tv, ok := value.(ScErrorCode) if !ok { err = errors.New("invalid value, must be ScErrorCode") return } - result.Code = &tv + result.Code = tv case ScErrorTypeSceCrypto: tv, ok := value.(ScErrorCode) if !ok { err = errors.New("invalid value, must be ScErrorCode") return } - result.Code = &tv + result.Code = tv case ScErrorTypeSceEvents: tv, ok := value.(ScErrorCode) if !ok { err = errors.New("invalid value, must be ScErrorCode") return } - result.Code = &tv + result.Code = tv case ScErrorTypeSceBudget: tv, ok := value.(ScErrorCode) if !ok { err = errors.New("invalid value, must be ScErrorCode") return } - result.Code = &tv + result.Code = tv case ScErrorTypeSceValue: tv, ok := value.(ScErrorCode) if !ok { err = errors.New("invalid value, must be ScErrorCode") return } - result.Code = &tv + result.Code = tv case ScErrorTypeSceAuth: tv, ok := value.(ScErrorCode) if !ok { err = errors.New("invalid value, must be ScErrorCode") return } - result.Code = &tv + result.Code = tv } return } @@ -55717,50 +54177,38 @@ func NewScError(aType ScErrorType, value interface{}) (result ScError, err error // MustContractCode retrieves the ContractCode value from the union, // panicing if the value is not set. func (u ScError) MustContractCode() Uint32 { - val, ok := u.GetContractCode() - - if !ok { - panic("arm ContractCode is not set") + if ScErrorType(u.Type) == ScErrorTypeSceContract { + return u.ContractCode } - - return val + panic("arm ContractCode is not set") } // GetContractCode retrieves the ContractCode value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScError) GetContractCode() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ContractCode" { - result = *u.ContractCode + if ScErrorType(u.Type) == ScErrorTypeSceContract { + result = u.ContractCode ok = true } - return } // MustCode retrieves the Code value from the union, // panicing if the value is not set. func (u ScError) MustCode() ScErrorCode { - val, ok := u.GetCode() - - if !ok { - panic("arm Code is not set") + if ScErrorType(u.Type) == ScErrorTypeSceWasmVm || ScErrorType(u.Type) == ScErrorTypeSceContext || ScErrorType(u.Type) == ScErrorTypeSceStorage || ScErrorType(u.Type) == ScErrorTypeSceObject || ScErrorType(u.Type) == ScErrorTypeSceCrypto || ScErrorType(u.Type) == ScErrorTypeSceEvents || ScErrorType(u.Type) == ScErrorTypeSceBudget || ScErrorType(u.Type) == ScErrorTypeSceValue || ScErrorType(u.Type) == ScErrorTypeSceAuth { + return u.Code } - - return val + panic("arm Code is not set") } // GetCode retrieves the Code value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScError) GetCode() (result ScErrorCode, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Code" { - result = *u.Code + if ScErrorType(u.Type) == ScErrorTypeSceWasmVm || ScErrorType(u.Type) == ScErrorTypeSceContext || ScErrorType(u.Type) == ScErrorTypeSceStorage || ScErrorType(u.Type) == ScErrorTypeSceObject || ScErrorType(u.Type) == ScErrorTypeSceCrypto || ScErrorType(u.Type) == ScErrorTypeSceEvents || ScErrorType(u.Type) == ScErrorTypeSceBudget || ScErrorType(u.Type) == ScErrorTypeSceValue || ScErrorType(u.Type) == ScErrorTypeSceAuth { + result = u.Code ok = true } - return } @@ -55772,52 +54220,52 @@ func (u ScError) EncodeTo(e *xdr.Encoder) error { } switch ScErrorType(u.Type) { case ScErrorTypeSceContract: - if err = (*u.ContractCode).EncodeTo(e); err != nil { + if err = u.ContractCode.EncodeTo(e); err != nil { return err } return nil case ScErrorTypeSceWasmVm: - if err = (*u.Code).EncodeTo(e); err != nil { + if err = u.Code.EncodeTo(e); err != nil { return err } return nil case ScErrorTypeSceContext: - if err = (*u.Code).EncodeTo(e); err != nil { + if err = u.Code.EncodeTo(e); err != nil { return err } return nil case ScErrorTypeSceStorage: - if err = (*u.Code).EncodeTo(e); err != nil { + if err = u.Code.EncodeTo(e); err != nil { return err } return nil case ScErrorTypeSceObject: - if err = (*u.Code).EncodeTo(e); err != nil { + if err = u.Code.EncodeTo(e); err != nil { return err } return nil case ScErrorTypeSceCrypto: - if err = (*u.Code).EncodeTo(e); err != nil { + if err = u.Code.EncodeTo(e); err != nil { return err } return nil case ScErrorTypeSceEvents: - if err = (*u.Code).EncodeTo(e); err != nil { + if err = u.Code.EncodeTo(e); err != nil { return err } return nil case ScErrorTypeSceBudget: - if err = (*u.Code).EncodeTo(e); err != nil { + if err = u.Code.EncodeTo(e); err != nil { return err } return nil case ScErrorTypeSceValue: - if err = (*u.Code).EncodeTo(e); err != nil { + if err = u.Code.EncodeTo(e); err != nil { return err } return nil case ScErrorTypeSceAuth: - if err = (*u.Code).EncodeTo(e); err != nil { + if err = u.Code.EncodeTo(e); err != nil { return err } return nil @@ -55825,9 +54273,9 @@ func (u ScError) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (ScErrorType) switch value '%d' is not valid for union ScError", u.Type) } -var _ decoderFrom = (*ScError)(nil) +var _ xdr.DecoderFrom = (*ScError)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ScError) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScError: %w", ErrMaxDecodingDepthReached) @@ -55842,80 +54290,70 @@ func (u *ScError) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch ScErrorType(u.Type) { case ScErrorTypeSceContract: - u.ContractCode = new(Uint32) - nTmp, err = (*u.ContractCode).DecodeFrom(d, maxDepth) + nTmp, err = u.ContractCode.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } return n, nil case ScErrorTypeSceWasmVm: - u.Code = new(ScErrorCode) - nTmp, err = (*u.Code).DecodeFrom(d, maxDepth) + nTmp, err = u.Code.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding ScErrorCode: %w", err) } return n, nil case ScErrorTypeSceContext: - u.Code = new(ScErrorCode) - nTmp, err = (*u.Code).DecodeFrom(d, maxDepth) + nTmp, err = u.Code.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding ScErrorCode: %w", err) } return n, nil case ScErrorTypeSceStorage: - u.Code = new(ScErrorCode) - nTmp, err = (*u.Code).DecodeFrom(d, maxDepth) + nTmp, err = u.Code.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding ScErrorCode: %w", err) } return n, nil case ScErrorTypeSceObject: - u.Code = new(ScErrorCode) - nTmp, err = (*u.Code).DecodeFrom(d, maxDepth) + nTmp, err = u.Code.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding ScErrorCode: %w", err) } return n, nil case ScErrorTypeSceCrypto: - u.Code = new(ScErrorCode) - nTmp, err = (*u.Code).DecodeFrom(d, maxDepth) + nTmp, err = u.Code.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding ScErrorCode: %w", err) } return n, nil case ScErrorTypeSceEvents: - u.Code = new(ScErrorCode) - nTmp, err = (*u.Code).DecodeFrom(d, maxDepth) + nTmp, err = u.Code.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding ScErrorCode: %w", err) } return n, nil case ScErrorTypeSceBudget: - u.Code = new(ScErrorCode) - nTmp, err = (*u.Code).DecodeFrom(d, maxDepth) + nTmp, err = u.Code.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding ScErrorCode: %w", err) } return n, nil case ScErrorTypeSceValue: - u.Code = new(ScErrorCode) - nTmp, err = (*u.Code).DecodeFrom(d, maxDepth) + nTmp, err = u.Code.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding ScErrorCode: %w", err) } return n, nil case ScErrorTypeSceAuth: - u.Code = new(ScErrorCode) - nTmp, err = (*u.Code).DecodeFrom(d, maxDepth) + nTmp, err = u.Code.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding ScErrorCode: %w", err) @@ -55935,11 +54373,8 @@ func (s ScError) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScError) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -55976,9 +54411,9 @@ func (s *UInt128Parts) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*UInt128Parts)(nil) +var _ xdr.DecoderFrom = (*UInt128Parts)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *UInt128Parts) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding UInt128Parts: %w", ErrMaxDecodingDepthReached) @@ -56009,11 +54444,8 @@ func (s UInt128Parts) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *UInt128Parts) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -56050,9 +54482,9 @@ func (s *Int128Parts) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Int128Parts)(nil) +var _ xdr.DecoderFrom = (*Int128Parts)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Int128Parts) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Int128Parts: %w", ErrMaxDecodingDepthReached) @@ -56083,11 +54515,8 @@ func (s Int128Parts) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Int128Parts) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -56134,9 +54563,9 @@ func (s *UInt256Parts) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*UInt256Parts)(nil) +var _ xdr.DecoderFrom = (*UInt256Parts)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *UInt256Parts) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding UInt256Parts: %w", ErrMaxDecodingDepthReached) @@ -56177,11 +54606,8 @@ func (s UInt256Parts) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *UInt256Parts) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -56228,9 +54654,9 @@ func (s *Int256Parts) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*Int256Parts)(nil) +var _ xdr.DecoderFrom = (*Int256Parts)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *Int256Parts) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding Int256Parts: %w", ErrMaxDecodingDepthReached) @@ -56271,11 +54697,8 @@ func (s Int256Parts) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *Int256Parts) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -56302,6 +54725,10 @@ const ( ContractExecutableTypeContractExecutableWasm ContractExecutableType = 0 ContractExecutableTypeContractExecutableStellarAsset ContractExecutableType = 1 ) +const ( + _ContractExecutableType_Min int32 = 0 + _ContractExecutableType_Max int32 = 1 +) var contractExecutableTypeMap = map[int32]string{ 0: "ContractExecutableTypeContractExecutableWasm", @@ -56311,8 +54738,7 @@ var contractExecutableTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ContractExecutableType func (e ContractExecutableType) ValidEnum(v int32) bool { - _, ok := contractExecutableTypeMap[v] - return ok + return v >= _ContractExecutableType_Min && v <= _ContractExecutableType_Max } // String returns the name of `e` @@ -56323,16 +54749,16 @@ func (e ContractExecutableType) String() string { // EncodeTo encodes this value using the Encoder. func (e ContractExecutableType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := contractExecutableTypeMap[int32(e)]; !ok { + if int32(e) < _ContractExecutableType_Min || int32(e) > _ContractExecutableType_Max { return fmt.Errorf("'%d' is not a valid ContractExecutableType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ContractExecutableType)(nil) +var _ xdr.DecoderFrom = (*ContractExecutableType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ContractExecutableType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractExecutableType: %w", ErrMaxDecodingDepthReached) @@ -56342,7 +54768,7 @@ func (e *ContractExecutableType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, if err != nil { return n, fmt.Errorf("decoding ContractExecutableType: %w", err) } - if _, ok := contractExecutableTypeMap[v]; !ok { + if v < _ContractExecutableType_Min || v > _ContractExecutableType_Max { return n, fmt.Errorf("'%d' is not a valid ContractExecutableType enum value", v) } *e = ContractExecutableType(v) @@ -56359,11 +54785,8 @@ func (s ContractExecutableType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractExecutableType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -56429,25 +54852,19 @@ func NewContractExecutable(aType ContractExecutableType, value interface{}) (res // MustWasmHash retrieves the WasmHash value from the union, // panicing if the value is not set. func (u ContractExecutable) MustWasmHash() Hash { - val, ok := u.GetWasmHash() - - if !ok { - panic("arm WasmHash is not set") + if ContractExecutableType(u.Type) == ContractExecutableTypeContractExecutableWasm { + return *u.WasmHash } - - return val + panic("arm WasmHash is not set") } // GetWasmHash retrieves the WasmHash value from the union, // returning ok if the union's switch indicated the value is valid. func (u ContractExecutable) GetWasmHash() (result Hash, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "WasmHash" { + if ContractExecutableType(u.Type) == ContractExecutableTypeContractExecutableWasm { result = *u.WasmHash ok = true } - return } @@ -56470,9 +54887,9 @@ func (u ContractExecutable) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (ContractExecutableType) switch value '%d' is not valid for union ContractExecutable", u.Type) } -var _ decoderFrom = (*ContractExecutable)(nil) +var _ xdr.DecoderFrom = (*ContractExecutable)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ContractExecutable) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractExecutable: %w", ErrMaxDecodingDepthReached) @@ -56487,7 +54904,9 @@ func (u *ContractExecutable) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } switch ContractExecutableType(u.Type) { case ContractExecutableTypeContractExecutableWasm: - u.WasmHash = new(Hash) + if u.WasmHash == nil { + u.WasmHash = new(Hash) + } nTmp, err = (*u.WasmHash).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -56511,11 +54930,8 @@ func (s ContractExecutable) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractExecutable) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -56548,6 +54964,10 @@ const ( ScAddressTypeScAddressTypeClaimableBalance ScAddressType = 3 ScAddressTypeScAddressTypeLiquidityPool ScAddressType = 4 ) +const ( + _ScAddressType_Min int32 = 0 + _ScAddressType_Max int32 = 4 +) var scAddressTypeMap = map[int32]string{ 0: "ScAddressTypeScAddressTypeAccount", @@ -56560,8 +54980,7 @@ var scAddressTypeMap = map[int32]string{ // 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 + return v >= _ScAddressType_Min && v <= _ScAddressType_Max } // String returns the name of `e` @@ -56572,16 +54991,16 @@ func (e ScAddressType) String() string { // EncodeTo encodes this value using the Encoder. func (e ScAddressType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := scAddressTypeMap[int32(e)]; !ok { + if int32(e) < _ScAddressType_Min || int32(e) > _ScAddressType_Max { return fmt.Errorf("'%d' is not a valid ScAddressType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ScAddressType)(nil) +var _ xdr.DecoderFrom = (*ScAddressType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ScAddressType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScAddressType: %w", ErrMaxDecodingDepthReached) @@ -56591,7 +55010,7 @@ func (e *ScAddressType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ScAddressType: %w", err) } - if _, ok := scAddressTypeMap[v]; !ok { + if v < _ScAddressType_Min || v > _ScAddressType_Max { return n, fmt.Errorf("'%d' is not a valid ScAddressType enum value", v) } *e = ScAddressType(v) @@ -56608,11 +55027,8 @@ func (s ScAddressType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScAddressType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -56650,9 +55066,9 @@ func (s *MuxedEd25519Account) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*MuxedEd25519Account)(nil) +var _ xdr.DecoderFrom = (*MuxedEd25519Account)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *MuxedEd25519Account) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding MuxedEd25519Account: %w", ErrMaxDecodingDepthReached) @@ -56683,11 +55099,8 @@ func (s MuxedEd25519Account) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *MuxedEd25519Account) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -56795,125 +55208,95 @@ func NewScAddress(aType ScAddressType, value interface{}) (result ScAddress, err // 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") + if ScAddressType(u.Type) == ScAddressTypeScAddressTypeAccount { + return *u.AccountId } - - return val + panic("arm AccountId is not set") } // 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" { + if ScAddressType(u.Type) == ScAddressTypeScAddressTypeAccount { 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() ContractId { - val, ok := u.GetContractId() - - if !ok { - panic("arm ContractId is not set") + if ScAddressType(u.Type) == ScAddressTypeScAddressTypeContract { + return *u.ContractId } - - return val + panic("arm ContractId is not set") } // 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 ContractId, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ContractId" { + if ScAddressType(u.Type) == ScAddressTypeScAddressTypeContract { result = *u.ContractId ok = true } - return } // MustMuxedAccount retrieves the MuxedAccount value from the union, // panicing if the value is not set. func (u ScAddress) MustMuxedAccount() MuxedEd25519Account { - val, ok := u.GetMuxedAccount() - - if !ok { - panic("arm MuxedAccount is not set") + if ScAddressType(u.Type) == ScAddressTypeScAddressTypeMuxedAccount { + return *u.MuxedAccount } - - return val + panic("arm MuxedAccount is not set") } // GetMuxedAccount retrieves the MuxedAccount value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScAddress) GetMuxedAccount() (result MuxedEd25519Account, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "MuxedAccount" { + if ScAddressType(u.Type) == ScAddressTypeScAddressTypeMuxedAccount { result = *u.MuxedAccount ok = true } - return } // MustClaimableBalanceId retrieves the ClaimableBalanceId value from the union, // panicing if the value is not set. func (u ScAddress) MustClaimableBalanceId() ClaimableBalanceId { - val, ok := u.GetClaimableBalanceId() - - if !ok { - panic("arm ClaimableBalanceId is not set") + if ScAddressType(u.Type) == ScAddressTypeScAddressTypeClaimableBalance { + return *u.ClaimableBalanceId } - - return val + panic("arm ClaimableBalanceId is not set") } // GetClaimableBalanceId retrieves the ClaimableBalanceId value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScAddress) GetClaimableBalanceId() (result ClaimableBalanceId, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "ClaimableBalanceId" { + if ScAddressType(u.Type) == ScAddressTypeScAddressTypeClaimableBalance { result = *u.ClaimableBalanceId ok = true } - return } // MustLiquidityPoolId retrieves the LiquidityPoolId value from the union, // panicing if the value is not set. func (u ScAddress) MustLiquidityPoolId() PoolId { - val, ok := u.GetLiquidityPoolId() - - if !ok { - panic("arm LiquidityPoolId is not set") + if ScAddressType(u.Type) == ScAddressTypeScAddressTypeLiquidityPool { + return *u.LiquidityPoolId } - - return val + panic("arm LiquidityPoolId is not set") } // GetLiquidityPoolId retrieves the LiquidityPoolId value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScAddress) GetLiquidityPoolId() (result PoolId, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "LiquidityPoolId" { + if ScAddressType(u.Type) == ScAddressTypeScAddressTypeLiquidityPool { result = *u.LiquidityPoolId ok = true } - return } @@ -56953,9 +55336,9 @@ func (u ScAddress) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (ScAddressType) switch value '%d' is not valid for union ScAddress", u.Type) } -var _ decoderFrom = (*ScAddress)(nil) +var _ xdr.DecoderFrom = (*ScAddress)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ScAddress) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScAddress: %w", ErrMaxDecodingDepthReached) @@ -56970,7 +55353,9 @@ func (u *ScAddress) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch ScAddressType(u.Type) { case ScAddressTypeScAddressTypeAccount: - u.AccountId = new(AccountId) + if u.AccountId == nil { + u.AccountId = new(AccountId) + } nTmp, err = (*u.AccountId).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -56978,7 +55363,9 @@ func (u *ScAddress) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScAddressTypeScAddressTypeContract: - u.ContractId = new(ContractId) + if u.ContractId == nil { + u.ContractId = new(ContractId) + } nTmp, err = (*u.ContractId).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -56986,7 +55373,9 @@ func (u *ScAddress) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScAddressTypeScAddressTypeMuxedAccount: - u.MuxedAccount = new(MuxedEd25519Account) + if u.MuxedAccount == nil { + u.MuxedAccount = new(MuxedEd25519Account) + } nTmp, err = (*u.MuxedAccount).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -56994,7 +55383,9 @@ func (u *ScAddress) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScAddressTypeScAddressTypeClaimableBalance: - u.ClaimableBalanceId = new(ClaimableBalanceId) + if u.ClaimableBalanceId == nil { + u.ClaimableBalanceId = new(ClaimableBalanceId) + } nTmp, err = (*u.ClaimableBalanceId).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -57002,7 +55393,9 @@ func (u *ScAddress) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScAddressTypeScAddressTypeLiquidityPool: - u.LiquidityPoolId = new(PoolId) + if u.LiquidityPoolId == nil { + u.LiquidityPoolId = new(PoolId) + } nTmp, err = (*u.LiquidityPoolId).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -57023,11 +55416,8 @@ func (s ScAddress) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScAddress) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -57065,9 +55455,9 @@ func (s ScVec) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScVec)(nil) +var _ xdr.DecoderFrom = (*ScVec)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScVec) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScVec: %w", ErrMaxDecodingDepthReached) @@ -57081,12 +55471,17 @@ func (s *ScVec) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ScVal: %w", err) } - (*s) = nil - if l > 0 { + if l == 0 { + (*s) = (*s)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScVal: length (%d) exceeds remaining input length (%d)", l, il) } - (*s) = make([]ScVal, l) + if cap((*s)) >= int(l) { + (*s) = (*s)[:l] + } else { + (*s) = make([]ScVal, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*s)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -57108,11 +55503,8 @@ func (s ScVec) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScVec) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -57145,9 +55537,9 @@ func (s ScMap) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScMap)(nil) +var _ xdr.DecoderFrom = (*ScMap)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScMap) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScMap: %w", ErrMaxDecodingDepthReached) @@ -57161,12 +55553,17 @@ func (s *ScMap) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if err != nil { return n, fmt.Errorf("decoding ScMapEntry: %w", err) } - (*s) = nil - if l > 0 { + if l == 0 { + (*s) = (*s)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScMapEntry: length (%d) exceeds remaining input length (%d)", l, il) } - (*s) = make([]ScMapEntry, l) + if cap((*s)) >= int(l) { + (*s) = (*s)[:l] + } else { + (*s) = make([]ScMapEntry, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*s)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -57188,11 +55585,8 @@ func (s ScMap) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScMap) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -57220,9 +55614,9 @@ func (s ScBytes) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScBytes)(nil) +var _ xdr.DecoderFrom = (*ScBytes)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScBytes) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScBytes: %w", ErrMaxDecodingDepthReached) @@ -57248,11 +55642,8 @@ func (s ScBytes) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScBytes) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -57280,9 +55671,9 @@ func (s ScString) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScString)(nil) +var _ xdr.DecoderFrom = (*ScString)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScString) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScString: %w", ErrMaxDecodingDepthReached) @@ -57310,11 +55701,8 @@ func (s ScString) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScString) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -57347,9 +55735,9 @@ func (s ScSymbol) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScSymbol)(nil) +var _ xdr.DecoderFrom = (*ScSymbol)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScSymbol) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScSymbol: %w", ErrMaxDecodingDepthReached) @@ -57377,11 +55765,8 @@ func (s ScSymbol) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScSymbol) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -57413,9 +55798,9 @@ func (s *ScNonceKey) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScNonceKey)(nil) +var _ xdr.DecoderFrom = (*ScNonceKey)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScNonceKey) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScNonceKey: %w", ErrMaxDecodingDepthReached) @@ -57441,11 +55826,8 @@ func (s ScNonceKey) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScNonceKey) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -57487,9 +55869,9 @@ func (s *ScContractInstance) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScContractInstance)(nil) +var _ xdr.DecoderFrom = (*ScContractInstance)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScContractInstance) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScContractInstance: %w", ErrMaxDecodingDepthReached) @@ -57530,11 +55912,8 @@ func (s ScContractInstance) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScContractInstance) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -57612,14 +55991,14 @@ var _ xdrType = (*ScContractInstance)(nil) // }; type ScVal struct { Type ScValType - B *bool + B bool Error *ScError - U32 *Uint32 - I32 *Int32 - U64 *Uint64 - I64 *Int64 - Timepoint *TimePoint - Duration *Duration + U32 Uint32 + I32 Int32 + U64 Uint64 + I64 Int64 + Timepoint TimePoint + Duration Duration U128 *UInt128Parts I128 *Int128Parts U256 *UInt256Parts @@ -57702,7 +56081,7 @@ func NewScVal(aType ScValType, value interface{}) (result ScVal, err error) { err = errors.New("invalid value, must be bool") return } - result.B = &tv + result.B = tv case ScValTypeScvVoid: // void case ScValTypeScvError: @@ -57718,42 +56097,42 @@ func NewScVal(aType ScValType, value interface{}) (result ScVal, err error) { err = errors.New("invalid value, must be Uint32") return } - result.U32 = &tv + result.U32 = tv case ScValTypeScvI32: tv, ok := value.(Int32) if !ok { err = errors.New("invalid value, must be Int32") return } - result.I32 = &tv + result.I32 = tv case ScValTypeScvU64: tv, ok := value.(Uint64) if !ok { err = errors.New("invalid value, must be Uint64") return } - result.U64 = &tv + result.U64 = tv case ScValTypeScvI64: tv, ok := value.(Int64) if !ok { err = errors.New("invalid value, must be Int64") return } - result.I64 = &tv + result.I64 = tv case ScValTypeScvTimepoint: tv, ok := value.(TimePoint) if !ok { err = errors.New("invalid value, must be TimePoint") return } - result.Timepoint = &tv + result.Timepoint = tv case ScValTypeScvDuration: tv, ok := value.(Duration) if !ok { err = errors.New("invalid value, must be Duration") return } - result.Duration = &tv + result.Duration = tv case ScValTypeScvU128: tv, ok := value.(UInt128Parts) if !ok { @@ -57847,500 +56226,380 @@ func NewScVal(aType ScValType, value interface{}) (result ScVal, err error) { // MustB retrieves the B value from the union, // panicing if the value is not set. func (u ScVal) MustB() bool { - val, ok := u.GetB() - - if !ok { - panic("arm B is not set") + if ScValType(u.Type) == ScValTypeScvBool { + return u.B } - - return val + panic("arm B is not set") } // GetB retrieves the B value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScVal) GetB() (result bool, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "B" { - result = *u.B + if ScValType(u.Type) == ScValTypeScvBool { + result = u.B ok = true } - return } // MustError retrieves the Error value from the union, // panicing if the value is not set. func (u ScVal) MustError() ScError { - val, ok := u.GetError() - - if !ok { - panic("arm Error is not set") + if ScValType(u.Type) == ScValTypeScvError { + return *u.Error } - - return val + panic("arm Error is not set") } // GetError retrieves the Error value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScVal) GetError() (result ScError, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Error" { + if ScValType(u.Type) == ScValTypeScvError { 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") + if ScValType(u.Type) == ScValTypeScvU32 { + return u.U32 } - - return val + panic("arm U32 is not set") } // 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 + if ScValType(u.Type) == ScValTypeScvU32 { + 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") + if ScValType(u.Type) == ScValTypeScvI32 { + return u.I32 } - - return val + panic("arm I32 is not set") } // 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 + if ScValType(u.Type) == ScValTypeScvI32 { + result = u.I32 ok = true } - return } // MustU64 retrieves the U64 value from the union, // panicing if the value is not set. func (u ScVal) MustU64() Uint64 { - val, ok := u.GetU64() - - if !ok { - panic("arm U64 is not set") + if ScValType(u.Type) == ScValTypeScvU64 { + return u.U64 } - - return val + panic("arm U64 is not set") } // GetU64 retrieves the U64 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScVal) GetU64() (result Uint64, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "U64" { - result = *u.U64 + if ScValType(u.Type) == ScValTypeScvU64 { + result = u.U64 ok = true } - return } // MustI64 retrieves the I64 value from the union, // panicing if the value is not set. func (u ScVal) MustI64() Int64 { - val, ok := u.GetI64() - - if !ok { - panic("arm I64 is not set") + if ScValType(u.Type) == ScValTypeScvI64 { + return u.I64 } - - return val + panic("arm I64 is not set") } // GetI64 retrieves the I64 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScVal) GetI64() (result Int64, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "I64" { - result = *u.I64 + if ScValType(u.Type) == ScValTypeScvI64 { + result = u.I64 ok = true } - 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") + if ScValType(u.Type) == ScValTypeScvTimepoint { + return u.Timepoint } - - return val + panic("arm Timepoint is not set") } // 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 + if ScValType(u.Type) == ScValTypeScvTimepoint { + 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") + if ScValType(u.Type) == ScValTypeScvDuration { + return u.Duration } - - return val + panic("arm Duration is not set") } // 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 + if ScValType(u.Type) == ScValTypeScvDuration { + result = u.Duration ok = true } - return } // MustU128 retrieves the U128 value from the union, // panicing if the value is not set. func (u ScVal) MustU128() UInt128Parts { - val, ok := u.GetU128() - - if !ok { - panic("arm U128 is not set") + if ScValType(u.Type) == ScValTypeScvU128 { + return *u.U128 } - - return val + panic("arm U128 is not set") } // GetU128 retrieves the U128 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScVal) GetU128() (result UInt128Parts, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "U128" { + if ScValType(u.Type) == ScValTypeScvU128 { result = *u.U128 ok = true } - return } // MustI128 retrieves the I128 value from the union, // panicing if the value is not set. func (u ScVal) MustI128() Int128Parts { - val, ok := u.GetI128() - - if !ok { - panic("arm I128 is not set") + if ScValType(u.Type) == ScValTypeScvI128 { + return *u.I128 } - - return val + panic("arm I128 is not set") } // GetI128 retrieves the I128 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScVal) GetI128() (result Int128Parts, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "I128" { + if ScValType(u.Type) == ScValTypeScvI128 { result = *u.I128 ok = true } - return } // MustU256 retrieves the U256 value from the union, // panicing if the value is not set. func (u ScVal) MustU256() UInt256Parts { - val, ok := u.GetU256() - - if !ok { - panic("arm U256 is not set") + if ScValType(u.Type) == ScValTypeScvU256 { + return *u.U256 } - - return val + panic("arm U256 is not set") } // GetU256 retrieves the U256 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScVal) GetU256() (result UInt256Parts, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "U256" { + if ScValType(u.Type) == ScValTypeScvU256 { result = *u.U256 ok = true } - return } // MustI256 retrieves the I256 value from the union, // panicing if the value is not set. func (u ScVal) MustI256() Int256Parts { - val, ok := u.GetI256() - - if !ok { - panic("arm I256 is not set") + if ScValType(u.Type) == ScValTypeScvI256 { + return *u.I256 } - - return val + panic("arm I256 is not set") } // GetI256 retrieves the I256 value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScVal) GetI256() (result Int256Parts, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "I256" { + if ScValType(u.Type) == ScValTypeScvI256 { 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") + if ScValType(u.Type) == ScValTypeScvBytes { + return *u.Bytes } - - return val + panic("arm Bytes is not set") } // 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" { + if ScValType(u.Type) == ScValTypeScvBytes { 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") + if ScValType(u.Type) == ScValTypeScvString { + return *u.Str } - - return val + panic("arm Str is not set") } // 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" { + if ScValType(u.Type) == ScValTypeScvString { 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") + if ScValType(u.Type) == ScValTypeScvSymbol { + return *u.Sym } - - return val + panic("arm Sym is not set") } // 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" { + if ScValType(u.Type) == ScValTypeScvSymbol { 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") + if ScValType(u.Type) == ScValTypeScvVec { + return *u.Vec } - - return val + panic("arm Vec is not set") } // 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" { + if ScValType(u.Type) == ScValTypeScvVec { 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") + if ScValType(u.Type) == ScValTypeScvMap { + return *u.Map } - - return val + panic("arm Map is not set") } // 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" { + if ScValType(u.Type) == ScValTypeScvMap { result = *u.Map ok = true } - return } // MustAddress retrieves the Address value from the union, // panicing if the value is not set. func (u ScVal) MustAddress() ScAddress { - val, ok := u.GetAddress() - - if !ok { - panic("arm Address is not set") + if ScValType(u.Type) == ScValTypeScvAddress { + return *u.Address } - - return val + panic("arm Address is not set") } // GetAddress retrieves the Address value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScVal) GetAddress() (result ScAddress, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Address" { + if ScValType(u.Type) == ScValTypeScvAddress { result = *u.Address ok = true } - return } // MustInstance retrieves the Instance value from the union, // panicing if the value is not set. func (u ScVal) MustInstance() ScContractInstance { - val, ok := u.GetInstance() - - if !ok { - panic("arm Instance is not set") + if ScValType(u.Type) == ScValTypeScvContractInstance { + return *u.Instance } - - return val + panic("arm Instance is not set") } // GetInstance retrieves the Instance value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScVal) GetInstance() (result ScContractInstance, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "Instance" { + if ScValType(u.Type) == ScValTypeScvContractInstance { result = *u.Instance ok = true } - return } // MustNonceKey retrieves the NonceKey value from the union, // panicing if the value is not set. func (u ScVal) MustNonceKey() ScNonceKey { - val, ok := u.GetNonceKey() - - if !ok { - panic("arm NonceKey is not set") + if ScValType(u.Type) == ScValTypeScvLedgerKeyNonce { + return *u.NonceKey } - - return val + panic("arm NonceKey is not set") } // GetNonceKey retrieves the NonceKey value from the union, // returning ok if the union's switch indicated the value is valid. func (u ScVal) GetNonceKey() (result ScNonceKey, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.Type)) - - if armName == "NonceKey" { + if ScValType(u.Type) == ScValTypeScvLedgerKeyNonce { result = *u.NonceKey ok = true } - return } @@ -58352,7 +56611,7 @@ func (u ScVal) EncodeTo(e *xdr.Encoder) error { } switch ScValType(u.Type) { case ScValTypeScvBool: - if _, err = e.EncodeBool(bool((*u.B))); err != nil { + if _, err = e.EncodeBool(bool(u.B)); err != nil { return err } return nil @@ -58365,32 +56624,32 @@ func (u ScVal) EncodeTo(e *xdr.Encoder) error { } return nil case ScValTypeScvU32: - if err = (*u.U32).EncodeTo(e); err != nil { + if err = u.U32.EncodeTo(e); err != nil { return err } return nil case ScValTypeScvI32: - if err = (*u.I32).EncodeTo(e); err != nil { + if err = u.I32.EncodeTo(e); err != nil { return err } return nil case ScValTypeScvU64: - if err = (*u.U64).EncodeTo(e); err != nil { + if err = u.U64.EncodeTo(e); err != nil { return err } return nil case ScValTypeScvI64: - if err = (*u.I64).EncodeTo(e); err != nil { + if err = u.I64.EncodeTo(e); err != nil { return err } return nil case ScValTypeScvTimepoint: - if err = (*u.Timepoint).EncodeTo(e); err != nil { + if err = u.Timepoint.EncodeTo(e); err != nil { return err } return nil case ScValTypeScvDuration: - if err = (*u.Duration).EncodeTo(e); err != nil { + if err = u.Duration.EncodeTo(e); err != nil { return err } return nil @@ -58471,9 +56730,9 @@ func (u ScVal) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("Type (ScValType) switch value '%d' is not valid for union ScVal", u.Type) } -var _ decoderFrom = (*ScVal)(nil) +var _ xdr.DecoderFrom = (*ScVal)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScVal: %w", ErrMaxDecodingDepthReached) @@ -58488,8 +56747,7 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } switch ScValType(u.Type) { case ScValTypeScvBool: - u.B = new(bool) - (*u.B), nTmp, err = d.DecodeBool() + u.B, nTmp, err = d.DecodeBool() n += nTmp if err != nil { return n, fmt.Errorf("decoding Bool: %w", err) @@ -58499,7 +56757,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { // Void return n, nil case ScValTypeScvError: - u.Error = new(ScError) + if u.Error == nil { + u.Error = new(ScError) + } nTmp, err = (*u.Error).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58507,55 +56767,51 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScValTypeScvU32: - u.U32 = new(Uint32) - nTmp, err = (*u.U32).DecodeFrom(d, maxDepth) + nTmp, err = u.U32.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } return n, nil case ScValTypeScvI32: - u.I32 = new(Int32) - nTmp, err = (*u.I32).DecodeFrom(d, maxDepth) + nTmp, err = u.I32.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Int32: %w", err) } return n, nil case ScValTypeScvU64: - u.U64 = new(Uint64) - nTmp, err = (*u.U64).DecodeFrom(d, maxDepth) + nTmp, err = u.U64.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint64: %w", err) } return n, nil case ScValTypeScvI64: - u.I64 = new(Int64) - nTmp, err = (*u.I64).DecodeFrom(d, maxDepth) + nTmp, err = u.I64.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Int64: %w", err) } return n, nil case ScValTypeScvTimepoint: - u.Timepoint = new(TimePoint) - nTmp, err = (*u.Timepoint).DecodeFrom(d, maxDepth) + nTmp, err = u.Timepoint.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding TimePoint: %w", err) } return n, nil case ScValTypeScvDuration: - u.Duration = new(Duration) - nTmp, err = (*u.Duration).DecodeFrom(d, maxDepth) + nTmp, err = u.Duration.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Duration: %w", err) } return n, nil case ScValTypeScvU128: - u.U128 = new(UInt128Parts) + if u.U128 == nil { + u.U128 = new(UInt128Parts) + } nTmp, err = (*u.U128).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58563,7 +56819,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScValTypeScvI128: - u.I128 = new(Int128Parts) + if u.I128 == nil { + u.I128 = new(Int128Parts) + } nTmp, err = (*u.I128).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58571,7 +56829,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScValTypeScvU256: - u.U256 = new(UInt256Parts) + if u.U256 == nil { + u.U256 = new(UInt256Parts) + } nTmp, err = (*u.U256).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58579,7 +56839,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScValTypeScvI256: - u.I256 = new(Int256Parts) + if u.I256 == nil { + u.I256 = new(Int256Parts) + } nTmp, err = (*u.I256).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58587,7 +56849,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScValTypeScvBytes: - u.Bytes = new(ScBytes) + if u.Bytes == nil { + u.Bytes = new(ScBytes) + } nTmp, err = (*u.Bytes).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58595,7 +56859,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScValTypeScvString: - u.Str = new(ScString) + if u.Str == nil { + u.Str = new(ScString) + } nTmp, err = (*u.Str).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58603,7 +56869,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScValTypeScvSymbol: - u.Sym = new(ScSymbol) + if u.Sym == nil { + u.Sym = new(ScSymbol) + } nTmp, err = (*u.Sym).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58611,7 +56879,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScValTypeScvVec: - u.Vec = new(*ScVec) + if u.Vec == nil { + u.Vec = new(*ScVec) + } var b bool b, nTmp, err = d.DecodeBool() n += nTmp @@ -58629,7 +56899,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScValTypeScvMap: - u.Map = new(*ScMap) + if u.Map == nil { + u.Map = new(*ScMap) + } var b bool b, nTmp, err = d.DecodeBool() n += nTmp @@ -58647,7 +56919,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScValTypeScvAddress: - u.Address = new(ScAddress) + if u.Address == nil { + u.Address = new(ScAddress) + } nTmp, err = (*u.Address).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58655,7 +56929,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { } return n, nil case ScValTypeScvContractInstance: - u.Instance = new(ScContractInstance) + if u.Instance == nil { + u.Instance = new(ScContractInstance) + } nTmp, err = (*u.Instance).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58666,7 +56942,9 @@ func (u *ScVal) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { // Void return n, nil case ScValTypeScvLedgerKeyNonce: - u.NonceKey = new(ScNonceKey) + if u.NonceKey == nil { + u.NonceKey = new(ScNonceKey) + } nTmp, err = (*u.NonceKey).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58687,11 +56965,8 @@ func (s ScVal) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScVal) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -58729,9 +57004,9 @@ func (s *ScMapEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ScMapEntry)(nil) +var _ xdr.DecoderFrom = (*ScMapEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ScMapEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ScMapEntry: %w", ErrMaxDecodingDepthReached) @@ -58762,11 +57037,8 @@ func (s ScMapEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ScMapEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -58838,50 +57110,38 @@ func NewStoredTransactionSet(v int32, value interface{}) (result StoredTransacti // MustTxSet retrieves the TxSet value from the union, // panicing if the value is not set. func (u StoredTransactionSet) MustTxSet() TransactionSet { - val, ok := u.GetTxSet() - - if !ok { - panic("arm TxSet is not set") + if int32(u.V) == 0 { + return *u.TxSet } - - return val + panic("arm TxSet is not set") } // GetTxSet retrieves the TxSet value from the union, // returning ok if the union's switch indicated the value is valid. func (u StoredTransactionSet) GetTxSet() (result TransactionSet, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "TxSet" { + if int32(u.V) == 0 { result = *u.TxSet ok = true } - return } // MustGeneralizedTxSet retrieves the GeneralizedTxSet value from the union, // panicing if the value is not set. func (u StoredTransactionSet) MustGeneralizedTxSet() GeneralizedTransactionSet { - val, ok := u.GetGeneralizedTxSet() - - if !ok { - panic("arm GeneralizedTxSet is not set") + if int32(u.V) == 1 { + return *u.GeneralizedTxSet } - - return val + panic("arm GeneralizedTxSet is not set") } // GetGeneralizedTxSet retrieves the GeneralizedTxSet value from the union, // returning ok if the union's switch indicated the value is valid. func (u StoredTransactionSet) GetGeneralizedTxSet() (result GeneralizedTransactionSet, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "GeneralizedTxSet" { + if int32(u.V) == 1 { result = *u.GeneralizedTxSet ok = true } - return } @@ -58906,9 +57166,9 @@ func (u StoredTransactionSet) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union StoredTransactionSet", u.V) } -var _ decoderFrom = (*StoredTransactionSet)(nil) +var _ xdr.DecoderFrom = (*StoredTransactionSet)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *StoredTransactionSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding StoredTransactionSet: %w", ErrMaxDecodingDepthReached) @@ -58923,7 +57183,9 @@ func (u *StoredTransactionSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e } switch int32(u.V) { case 0: - u.TxSet = new(TransactionSet) + if u.TxSet == nil { + u.TxSet = new(TransactionSet) + } nTmp, err = (*u.TxSet).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58931,7 +57193,9 @@ func (u *StoredTransactionSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e } return n, nil case 1: - u.GeneralizedTxSet = new(GeneralizedTransactionSet) + if u.GeneralizedTxSet == nil { + u.GeneralizedTxSet = new(GeneralizedTransactionSet) + } nTmp, err = (*u.GeneralizedTxSet).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -58952,11 +57216,8 @@ func (s StoredTransactionSet) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *StoredTransactionSet) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -58999,9 +57260,9 @@ func (s *StoredDebugTransactionSet) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*StoredDebugTransactionSet)(nil) +var _ xdr.DecoderFrom = (*StoredDebugTransactionSet)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *StoredDebugTransactionSet) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding StoredDebugTransactionSet: %w", ErrMaxDecodingDepthReached) @@ -59037,11 +57298,8 @@ func (s StoredDebugTransactionSet) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *StoredDebugTransactionSet) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -59099,9 +57357,9 @@ func (s *PersistedScpStateV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*PersistedScpStateV0)(nil) +var _ xdr.DecoderFrom = (*PersistedScpStateV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *PersistedScpStateV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PersistedScpStateV0: %w", ErrMaxDecodingDepthReached) @@ -59115,12 +57373,17 @@ func (s *PersistedScpStateV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er if err != nil { return n, fmt.Errorf("decoding ScpEnvelope: %w", err) } - s.ScpEnvelopes = nil - if l > 0 { + if l == 0 { + s.ScpEnvelopes = s.ScpEnvelopes[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScpEnvelope: length (%d) exceeds remaining input length (%d)", l, il) } - s.ScpEnvelopes = make([]ScpEnvelope, l) + if cap(s.ScpEnvelopes) >= int(l) { + s.ScpEnvelopes = s.ScpEnvelopes[:l] + } else { + s.ScpEnvelopes = make([]ScpEnvelope, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ScpEnvelopes[i].DecodeFrom(d, maxDepth) n += nTmp @@ -59134,12 +57397,17 @@ func (s *PersistedScpStateV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er if err != nil { return n, fmt.Errorf("decoding ScpQuorumSet: %w", err) } - s.QuorumSets = nil - if l > 0 { + if l == 0 { + s.QuorumSets = s.QuorumSets[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScpQuorumSet: length (%d) exceeds remaining input length (%d)", l, il) } - s.QuorumSets = make([]ScpQuorumSet, l) + if cap(s.QuorumSets) >= int(l) { + s.QuorumSets = s.QuorumSets[:l] + } else { + s.QuorumSets = make([]ScpQuorumSet, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.QuorumSets[i].DecodeFrom(d, maxDepth) n += nTmp @@ -59153,12 +57421,17 @@ func (s *PersistedScpStateV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er if err != nil { return n, fmt.Errorf("decoding StoredTransactionSet: %w", err) } - s.TxSets = nil - if l > 0 { + if l == 0 { + s.TxSets = s.TxSets[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding StoredTransactionSet: length (%d) exceeds remaining input length (%d)", l, il) } - s.TxSets = make([]StoredTransactionSet, l) + if cap(s.TxSets) >= int(l) { + s.TxSets = s.TxSets[:l] + } else { + s.TxSets = make([]StoredTransactionSet, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.TxSets[i].DecodeFrom(d, maxDepth) n += nTmp @@ -59180,11 +57453,8 @@ func (s PersistedScpStateV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PersistedScpStateV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -59233,9 +57503,9 @@ func (s *PersistedScpStateV1) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*PersistedScpStateV1)(nil) +var _ xdr.DecoderFrom = (*PersistedScpStateV1)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *PersistedScpStateV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PersistedScpStateV1: %w", ErrMaxDecodingDepthReached) @@ -59249,12 +57519,17 @@ func (s *PersistedScpStateV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er if err != nil { return n, fmt.Errorf("decoding ScpEnvelope: %w", err) } - s.ScpEnvelopes = nil - if l > 0 { + if l == 0 { + s.ScpEnvelopes = s.ScpEnvelopes[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScpEnvelope: length (%d) exceeds remaining input length (%d)", l, il) } - s.ScpEnvelopes = make([]ScpEnvelope, l) + if cap(s.ScpEnvelopes) >= int(l) { + s.ScpEnvelopes = s.ScpEnvelopes[:l] + } else { + s.ScpEnvelopes = make([]ScpEnvelope, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.ScpEnvelopes[i].DecodeFrom(d, maxDepth) n += nTmp @@ -59268,12 +57543,17 @@ func (s *PersistedScpStateV1) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, er if err != nil { return n, fmt.Errorf("decoding ScpQuorumSet: %w", err) } - s.QuorumSets = nil - if l > 0 { + if l == 0 { + s.QuorumSets = s.QuorumSets[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ScpQuorumSet: length (%d) exceeds remaining input length (%d)", l, il) } - s.QuorumSets = make([]ScpQuorumSet, l) + if cap(s.QuorumSets) >= int(l) { + s.QuorumSets = s.QuorumSets[:l] + } else { + s.QuorumSets = make([]ScpQuorumSet, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.QuorumSets[i].DecodeFrom(d, maxDepth) n += nTmp @@ -59295,11 +57575,8 @@ func (s PersistedScpStateV1) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PersistedScpStateV1) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -59371,50 +57648,38 @@ func NewPersistedScpState(v int32, value interface{}) (result PersistedScpState, // MustV0 retrieves the V0 value from the union, // panicing if the value is not set. func (u PersistedScpState) MustV0() PersistedScpStateV0 { - val, ok := u.GetV0() - - if !ok { - panic("arm V0 is not set") + if int32(u.V) == 0 { + return *u.V0 } - - return val + panic("arm V0 is not set") } // GetV0 retrieves the V0 value from the union, // returning ok if the union's switch indicated the value is valid. func (u PersistedScpState) GetV0() (result PersistedScpStateV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V0" { + if int32(u.V) == 0 { result = *u.V0 ok = true } - return } // MustV1 retrieves the V1 value from the union, // panicing if the value is not set. func (u PersistedScpState) MustV1() PersistedScpStateV1 { - val, ok := u.GetV1() - - if !ok { - panic("arm V1 is not set") + if int32(u.V) == 1 { + return *u.V1 } - - return val + panic("arm V1 is not set") } // GetV1 retrieves the V1 value from the union, // returning ok if the union's switch indicated the value is valid. func (u PersistedScpState) GetV1() (result PersistedScpStateV1, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.V)) - - if armName == "V1" { + if int32(u.V) == 1 { result = *u.V1 ok = true } - return } @@ -59439,9 +57704,9 @@ func (u PersistedScpState) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("V (int32) switch value '%d' is not valid for union PersistedScpState", u.V) } -var _ decoderFrom = (*PersistedScpState)(nil) +var _ xdr.DecoderFrom = (*PersistedScpState)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *PersistedScpState) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding PersistedScpState: %w", ErrMaxDecodingDepthReached) @@ -59456,7 +57721,9 @@ func (u *PersistedScpState) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } switch int32(u.V) { case 0: - u.V0 = new(PersistedScpStateV0) + if u.V0 == nil { + u.V0 = new(PersistedScpStateV0) + } nTmp, err = (*u.V0).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -59464,7 +57731,9 @@ func (u *PersistedScpState) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, erro } return n, nil case 1: - u.V1 = new(PersistedScpStateV1) + if u.V1 == nil { + u.V1 = new(PersistedScpStateV1) + } nTmp, err = (*u.V1).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -59485,11 +57754,8 @@ func (s PersistedScpState) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *PersistedScpState) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -59523,9 +57789,9 @@ func (s *ConfigSettingContractExecutionLanesV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ConfigSettingContractExecutionLanesV0)(nil) +var _ xdr.DecoderFrom = (*ConfigSettingContractExecutionLanesV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ConfigSettingContractExecutionLanesV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigSettingContractExecutionLanesV0: %w", ErrMaxDecodingDepthReached) @@ -59551,11 +57817,8 @@ func (s ConfigSettingContractExecutionLanesV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigSettingContractExecutionLanesV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -59609,9 +57872,9 @@ func (s *ConfigSettingContractComputeV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ConfigSettingContractComputeV0)(nil) +var _ xdr.DecoderFrom = (*ConfigSettingContractComputeV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ConfigSettingContractComputeV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigSettingContractComputeV0: %w", ErrMaxDecodingDepthReached) @@ -59652,11 +57915,8 @@ func (s ConfigSettingContractComputeV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigSettingContractComputeV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -59693,9 +57953,9 @@ func (s *ConfigSettingContractParallelComputeV0) EncodeTo(e *xdr.Encoder) error return nil } -var _ decoderFrom = (*ConfigSettingContractParallelComputeV0)(nil) +var _ xdr.DecoderFrom = (*ConfigSettingContractParallelComputeV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ConfigSettingContractParallelComputeV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigSettingContractParallelComputeV0: %w", ErrMaxDecodingDepthReached) @@ -59721,11 +57981,8 @@ func (s ConfigSettingContractParallelComputeV0) MarshalBinary() ([]byte, error) // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigSettingContractParallelComputeV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -59845,9 +58102,9 @@ func (s *ConfigSettingContractLedgerCostV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ConfigSettingContractLedgerCostV0)(nil) +var _ xdr.DecoderFrom = (*ConfigSettingContractLedgerCostV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ConfigSettingContractLedgerCostV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigSettingContractLedgerCostV0: %w", ErrMaxDecodingDepthReached) @@ -59943,11 +58200,8 @@ func (s ConfigSettingContractLedgerCostV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigSettingContractLedgerCostV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -59989,9 +58243,9 @@ func (s *ConfigSettingContractLedgerCostExtV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ConfigSettingContractLedgerCostExtV0)(nil) +var _ xdr.DecoderFrom = (*ConfigSettingContractLedgerCostExtV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ConfigSettingContractLedgerCostExtV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigSettingContractLedgerCostExtV0: %w", ErrMaxDecodingDepthReached) @@ -60022,11 +58276,8 @@ func (s ConfigSettingContractLedgerCostExtV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigSettingContractLedgerCostExtV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -60059,9 +58310,9 @@ func (s *ConfigSettingContractHistoricalDataV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ConfigSettingContractHistoricalDataV0)(nil) +var _ xdr.DecoderFrom = (*ConfigSettingContractHistoricalDataV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ConfigSettingContractHistoricalDataV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigSettingContractHistoricalDataV0: %w", ErrMaxDecodingDepthReached) @@ -60087,11 +58338,8 @@ func (s ConfigSettingContractHistoricalDataV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigSettingContractHistoricalDataV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -60131,9 +58379,9 @@ func (s *ConfigSettingContractEventsV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ConfigSettingContractEventsV0)(nil) +var _ xdr.DecoderFrom = (*ConfigSettingContractEventsV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ConfigSettingContractEventsV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigSettingContractEventsV0: %w", ErrMaxDecodingDepthReached) @@ -60164,11 +58412,8 @@ func (s ConfigSettingContractEventsV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigSettingContractEventsV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -60215,9 +58460,9 @@ func (s *ConfigSettingContractBandwidthV0) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ConfigSettingContractBandwidthV0)(nil) +var _ xdr.DecoderFrom = (*ConfigSettingContractBandwidthV0)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ConfigSettingContractBandwidthV0) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigSettingContractBandwidthV0: %w", ErrMaxDecodingDepthReached) @@ -60253,11 +58498,8 @@ func (s ConfigSettingContractBandwidthV0) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigSettingContractBandwidthV0) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -60545,6 +58787,10 @@ const ( ContractCostTypeBn254FrPow ContractCostType = 83 ContractCostTypeBn254FrInv ContractCostType = 84 ) +const ( + _ContractCostType_Min int32 = 0 + _ContractCostType_Max int32 = 84 +) var contractCostTypeMap = map[int32]string{ 0: "ContractCostTypeWasmInsnExec", @@ -60637,8 +58883,7 @@ var contractCostTypeMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ContractCostType func (e ContractCostType) ValidEnum(v int32) bool { - _, ok := contractCostTypeMap[v] - return ok + return v >= _ContractCostType_Min && v <= _ContractCostType_Max } // String returns the name of `e` @@ -60649,16 +58894,16 @@ func (e ContractCostType) String() string { // EncodeTo encodes this value using the Encoder. func (e ContractCostType) EncodeTo(enc *xdr.Encoder) error { - if _, ok := contractCostTypeMap[int32(e)]; !ok { + if int32(e) < _ContractCostType_Min || int32(e) > _ContractCostType_Max { return fmt.Errorf("'%d' is not a valid ContractCostType enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ContractCostType)(nil) +var _ xdr.DecoderFrom = (*ContractCostType)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ContractCostType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractCostType: %w", ErrMaxDecodingDepthReached) @@ -60668,7 +58913,7 @@ func (e *ContractCostType) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error if err != nil { return n, fmt.Errorf("decoding ContractCostType: %w", err) } - if _, ok := contractCostTypeMap[v]; !ok { + if v < _ContractCostType_Min || v > _ContractCostType_Max { return n, fmt.Errorf("'%d' is not a valid ContractCostType enum value", v) } *e = ContractCostType(v) @@ -60685,11 +58930,8 @@ func (s ContractCostType) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractCostType) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -60733,9 +58975,9 @@ func (s *ContractCostParamEntry) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ContractCostParamEntry)(nil) +var _ xdr.DecoderFrom = (*ContractCostParamEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ContractCostParamEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractCostParamEntry: %w", ErrMaxDecodingDepthReached) @@ -60771,11 +59013,8 @@ func (s ContractCostParamEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractCostParamEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -60864,9 +59103,9 @@ func (s *StateArchivalSettings) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*StateArchivalSettings)(nil) +var _ xdr.DecoderFrom = (*StateArchivalSettings)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *StateArchivalSettings) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding StateArchivalSettings: %w", ErrMaxDecodingDepthReached) @@ -60937,11 +59176,8 @@ func (s StateArchivalSettings) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *StateArchivalSettings) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -60983,9 +59219,9 @@ func (s *EvictionIterator) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*EvictionIterator)(nil) +var _ xdr.DecoderFrom = (*EvictionIterator)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *EvictionIterator) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding EvictionIterator: %w", ErrMaxDecodingDepthReached) @@ -61021,11 +59257,8 @@ func (s EvictionIterator) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *EvictionIterator) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -61077,9 +59310,9 @@ func (s *ConfigSettingScpTiming) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ConfigSettingScpTiming)(nil) +var _ xdr.DecoderFrom = (*ConfigSettingScpTiming)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ConfigSettingScpTiming) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigSettingScpTiming: %w", ErrMaxDecodingDepthReached) @@ -61125,11 +59358,8 @@ func (s ConfigSettingScpTiming) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigSettingScpTiming) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -61172,9 +59402,9 @@ func (s ContractCostParams) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*ContractCostParams)(nil) +var _ xdr.DecoderFrom = (*ContractCostParams)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *ContractCostParams) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ContractCostParams: %w", ErrMaxDecodingDepthReached) @@ -61191,12 +59421,17 @@ func (s *ContractCostParams) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err if l > 1024 { return n, fmt.Errorf("decoding ContractCostParamEntry: data size (%d) exceeds size limit (1024)", l) } - (*s) = nil - if l > 0 { + if l == 0 { + (*s) = (*s)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding ContractCostParamEntry: length (%d) exceeds remaining input length (%d)", l, il) } - (*s) = make([]ContractCostParamEntry, l) + if cap((*s)) >= int(l) { + (*s) = (*s)[:l] + } else { + (*s) = make([]ContractCostParamEntry, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*s)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -61218,11 +59453,8 @@ func (s ContractCostParams) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ContractCostParams) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -61279,6 +59511,10 @@ const ( ConfigSettingIdConfigSettingContractLedgerCostExtV0 ConfigSettingId = 15 ConfigSettingIdConfigSettingScpTiming ConfigSettingId = 16 ) +const ( + _ConfigSettingId_Min int32 = 0 + _ConfigSettingId_Max int32 = 16 +) var configSettingIdMap = map[int32]string{ 0: "ConfigSettingIdConfigSettingContractMaxSizeBytes", @@ -61303,8 +59539,7 @@ var configSettingIdMap = map[int32]string{ // ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ConfigSettingId func (e ConfigSettingId) ValidEnum(v int32) bool { - _, ok := configSettingIdMap[v] - return ok + return v >= _ConfigSettingId_Min && v <= _ConfigSettingId_Max } // String returns the name of `e` @@ -61315,16 +59550,16 @@ func (e ConfigSettingId) String() string { // EncodeTo encodes this value using the Encoder. func (e ConfigSettingId) EncodeTo(enc *xdr.Encoder) error { - if _, ok := configSettingIdMap[int32(e)]; !ok { + if int32(e) < _ConfigSettingId_Min || int32(e) > _ConfigSettingId_Max { return fmt.Errorf("'%d' is not a valid ConfigSettingId enum value", e) } _, err := enc.EncodeInt(int32(e)) return err } -var _ decoderFrom = (*ConfigSettingId)(nil) +var _ xdr.DecoderFrom = (*ConfigSettingId)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (e *ConfigSettingId) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigSettingId: %w", ErrMaxDecodingDepthReached) @@ -61334,7 +59569,7 @@ func (e *ConfigSettingId) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) if err != nil { return n, fmt.Errorf("decoding ConfigSettingId: %w", err) } - if _, ok := configSettingIdMap[v]; !ok { + if v < _ConfigSettingId_Min || v > _ConfigSettingId_Max { return n, fmt.Errorf("'%d' is not a valid ConfigSettingId enum value", v) } *e = ConfigSettingId(v) @@ -61351,11 +59586,8 @@ func (s ConfigSettingId) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigSettingId) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -61410,7 +59642,7 @@ var _ xdrType = (*ConfigSettingId)(nil) // }; type ConfigSettingEntry struct { ConfigSettingId ConfigSettingId - ContractMaxSizeBytes *Uint32 + ContractMaxSizeBytes Uint32 ContractCompute *ConfigSettingContractComputeV0 ContractLedgerCost *ConfigSettingContractLedgerCostV0 ContractHistoricalData *ConfigSettingContractHistoricalDataV0 @@ -61418,8 +59650,8 @@ type ConfigSettingEntry struct { ContractBandwidth *ConfigSettingContractBandwidthV0 ContractCostParamsCpuInsns *ContractCostParams ContractCostParamsMemBytes *ContractCostParams - ContractDataKeySizeBytes *Uint32 - ContractDataEntrySizeBytes *Uint32 + ContractDataKeySizeBytes Uint32 + ContractDataEntrySizeBytes Uint32 StateArchivalSettings *StateArchivalSettings ContractExecutionLanes *ConfigSettingContractExecutionLanesV0 LiveSorobanStateSizeWindow *[]Uint64 @@ -61487,7 +59719,7 @@ func NewConfigSettingEntry(configSettingId ConfigSettingId, value interface{}) ( err = errors.New("invalid value, must be Uint32") return } - result.ContractMaxSizeBytes = &tv + result.ContractMaxSizeBytes = tv case ConfigSettingIdConfigSettingContractComputeV0: tv, ok := value.(ConfigSettingContractComputeV0) if !ok { @@ -61543,14 +59775,14 @@ func NewConfigSettingEntry(configSettingId ConfigSettingId, value interface{}) ( err = errors.New("invalid value, must be Uint32") return } - result.ContractDataKeySizeBytes = &tv + result.ContractDataKeySizeBytes = tv case ConfigSettingIdConfigSettingContractDataEntrySizeBytes: tv, ok := value.(Uint32) if !ok { err = errors.New("invalid value, must be Uint32") return } - result.ContractDataEntrySizeBytes = &tv + result.ContractDataEntrySizeBytes = tv case ConfigSettingIdConfigSettingStateArchival: tv, ok := value.(StateArchivalSettings) if !ok { @@ -61607,425 +59839,323 @@ func NewConfigSettingEntry(configSettingId ConfigSettingId, value interface{}) ( // MustContractMaxSizeBytes retrieves the ContractMaxSizeBytes value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractMaxSizeBytes() Uint32 { - val, ok := u.GetContractMaxSizeBytes() - - if !ok { - panic("arm ContractMaxSizeBytes is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractMaxSizeBytes { + return u.ContractMaxSizeBytes } - - return val + panic("arm ContractMaxSizeBytes is not set") } // GetContractMaxSizeBytes retrieves the ContractMaxSizeBytes value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractMaxSizeBytes() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractMaxSizeBytes" { - result = *u.ContractMaxSizeBytes + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractMaxSizeBytes { + result = u.ContractMaxSizeBytes ok = true } - return } // MustContractCompute retrieves the ContractCompute value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractCompute() ConfigSettingContractComputeV0 { - val, ok := u.GetContractCompute() - - if !ok { - panic("arm ContractCompute is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractComputeV0 { + return *u.ContractCompute } - - return val + panic("arm ContractCompute is not set") } // GetContractCompute retrieves the ContractCompute value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractCompute() (result ConfigSettingContractComputeV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractCompute" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractComputeV0 { result = *u.ContractCompute ok = true } - return } // MustContractLedgerCost retrieves the ContractLedgerCost value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractLedgerCost() ConfigSettingContractLedgerCostV0 { - val, ok := u.GetContractLedgerCost() - - if !ok { - panic("arm ContractLedgerCost is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractLedgerCostV0 { + return *u.ContractLedgerCost } - - return val + panic("arm ContractLedgerCost is not set") } // GetContractLedgerCost retrieves the ContractLedgerCost value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractLedgerCost() (result ConfigSettingContractLedgerCostV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractLedgerCost" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractLedgerCostV0 { result = *u.ContractLedgerCost ok = true } - return } // MustContractHistoricalData retrieves the ContractHistoricalData value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractHistoricalData() ConfigSettingContractHistoricalDataV0 { - val, ok := u.GetContractHistoricalData() - - if !ok { - panic("arm ContractHistoricalData is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractHistoricalDataV0 { + return *u.ContractHistoricalData } - - return val + panic("arm ContractHistoricalData is not set") } // GetContractHistoricalData retrieves the ContractHistoricalData value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractHistoricalData() (result ConfigSettingContractHistoricalDataV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractHistoricalData" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractHistoricalDataV0 { result = *u.ContractHistoricalData ok = true } - return } // MustContractEvents retrieves the ContractEvents value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractEvents() ConfigSettingContractEventsV0 { - val, ok := u.GetContractEvents() - - if !ok { - panic("arm ContractEvents is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractEventsV0 { + return *u.ContractEvents } - - return val + panic("arm ContractEvents is not set") } // GetContractEvents retrieves the ContractEvents value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractEvents() (result ConfigSettingContractEventsV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractEvents" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractEventsV0 { result = *u.ContractEvents ok = true } - return } // MustContractBandwidth retrieves the ContractBandwidth value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractBandwidth() ConfigSettingContractBandwidthV0 { - val, ok := u.GetContractBandwidth() - - if !ok { - panic("arm ContractBandwidth is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractBandwidthV0 { + return *u.ContractBandwidth } - - return val + panic("arm ContractBandwidth is not set") } // GetContractBandwidth retrieves the ContractBandwidth value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractBandwidth() (result ConfigSettingContractBandwidthV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractBandwidth" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractBandwidthV0 { result = *u.ContractBandwidth ok = true } - return } // MustContractCostParamsCpuInsns retrieves the ContractCostParamsCpuInsns value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractCostParamsCpuInsns() ContractCostParams { - val, ok := u.GetContractCostParamsCpuInsns() - - if !ok { - panic("arm ContractCostParamsCpuInsns is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractCostParamsCpuInstructions { + return *u.ContractCostParamsCpuInsns } - - return val + panic("arm ContractCostParamsCpuInsns is not set") } // GetContractCostParamsCpuInsns retrieves the ContractCostParamsCpuInsns value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractCostParamsCpuInsns() (result ContractCostParams, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractCostParamsCpuInsns" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractCostParamsCpuInstructions { result = *u.ContractCostParamsCpuInsns ok = true } - return } // MustContractCostParamsMemBytes retrieves the ContractCostParamsMemBytes value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractCostParamsMemBytes() ContractCostParams { - val, ok := u.GetContractCostParamsMemBytes() - - if !ok { - panic("arm ContractCostParamsMemBytes is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractCostParamsMemoryBytes { + return *u.ContractCostParamsMemBytes } - - return val + panic("arm ContractCostParamsMemBytes is not set") } // GetContractCostParamsMemBytes retrieves the ContractCostParamsMemBytes value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractCostParamsMemBytes() (result ContractCostParams, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractCostParamsMemBytes" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractCostParamsMemoryBytes { result = *u.ContractCostParamsMemBytes ok = true } - return } // MustContractDataKeySizeBytes retrieves the ContractDataKeySizeBytes value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractDataKeySizeBytes() Uint32 { - val, ok := u.GetContractDataKeySizeBytes() - - if !ok { - panic("arm ContractDataKeySizeBytes is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractDataKeySizeBytes { + return u.ContractDataKeySizeBytes } - - return val + panic("arm ContractDataKeySizeBytes is not set") } // GetContractDataKeySizeBytes retrieves the ContractDataKeySizeBytes value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractDataKeySizeBytes() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractDataKeySizeBytes" { - result = *u.ContractDataKeySizeBytes + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractDataKeySizeBytes { + result = u.ContractDataKeySizeBytes ok = true } - return } // MustContractDataEntrySizeBytes retrieves the ContractDataEntrySizeBytes value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractDataEntrySizeBytes() Uint32 { - val, ok := u.GetContractDataEntrySizeBytes() - - if !ok { - panic("arm ContractDataEntrySizeBytes is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractDataEntrySizeBytes { + return u.ContractDataEntrySizeBytes } - - return val + panic("arm ContractDataEntrySizeBytes is not set") } // GetContractDataEntrySizeBytes retrieves the ContractDataEntrySizeBytes value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractDataEntrySizeBytes() (result Uint32, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractDataEntrySizeBytes" { - result = *u.ContractDataEntrySizeBytes + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractDataEntrySizeBytes { + result = u.ContractDataEntrySizeBytes ok = true } - return } // MustStateArchivalSettings retrieves the StateArchivalSettings value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustStateArchivalSettings() StateArchivalSettings { - val, ok := u.GetStateArchivalSettings() - - if !ok { - panic("arm StateArchivalSettings is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingStateArchival { + return *u.StateArchivalSettings } - - return val + panic("arm StateArchivalSettings is not set") } // GetStateArchivalSettings retrieves the StateArchivalSettings value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetStateArchivalSettings() (result StateArchivalSettings, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "StateArchivalSettings" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingStateArchival { result = *u.StateArchivalSettings ok = true } - return } // MustContractExecutionLanes retrieves the ContractExecutionLanes value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractExecutionLanes() ConfigSettingContractExecutionLanesV0 { - val, ok := u.GetContractExecutionLanes() - - if !ok { - panic("arm ContractExecutionLanes is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractExecutionLanes { + return *u.ContractExecutionLanes } - - return val + panic("arm ContractExecutionLanes is not set") } // GetContractExecutionLanes retrieves the ContractExecutionLanes value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractExecutionLanes() (result ConfigSettingContractExecutionLanesV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractExecutionLanes" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractExecutionLanes { result = *u.ContractExecutionLanes ok = true } - return } // MustLiveSorobanStateSizeWindow retrieves the LiveSorobanStateSizeWindow value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustLiveSorobanStateSizeWindow() []Uint64 { - val, ok := u.GetLiveSorobanStateSizeWindow() - - if !ok { - panic("arm LiveSorobanStateSizeWindow is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingLiveSorobanStateSizeWindow { + return *u.LiveSorobanStateSizeWindow } - - return val + panic("arm LiveSorobanStateSizeWindow is not set") } // GetLiveSorobanStateSizeWindow retrieves the LiveSorobanStateSizeWindow value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetLiveSorobanStateSizeWindow() (result []Uint64, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "LiveSorobanStateSizeWindow" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingLiveSorobanStateSizeWindow { result = *u.LiveSorobanStateSizeWindow ok = true } - return } // MustEvictionIterator retrieves the EvictionIterator value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustEvictionIterator() EvictionIterator { - val, ok := u.GetEvictionIterator() - - if !ok { - panic("arm EvictionIterator is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingEvictionIterator { + return *u.EvictionIterator } - - return val + panic("arm EvictionIterator is not set") } // GetEvictionIterator retrieves the EvictionIterator value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetEvictionIterator() (result EvictionIterator, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "EvictionIterator" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingEvictionIterator { result = *u.EvictionIterator ok = true } - return } // MustContractParallelCompute retrieves the ContractParallelCompute value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractParallelCompute() ConfigSettingContractParallelComputeV0 { - val, ok := u.GetContractParallelCompute() - - if !ok { - panic("arm ContractParallelCompute is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractParallelComputeV0 { + return *u.ContractParallelCompute } - - return val + panic("arm ContractParallelCompute is not set") } // GetContractParallelCompute retrieves the ContractParallelCompute value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractParallelCompute() (result ConfigSettingContractParallelComputeV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractParallelCompute" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractParallelComputeV0 { result = *u.ContractParallelCompute ok = true } - return } // MustContractLedgerCostExt retrieves the ContractLedgerCostExt value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractLedgerCostExt() ConfigSettingContractLedgerCostExtV0 { - val, ok := u.GetContractLedgerCostExt() - - if !ok { - panic("arm ContractLedgerCostExt is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractLedgerCostExtV0 { + return *u.ContractLedgerCostExt } - - return val + panic("arm ContractLedgerCostExt is not set") } // GetContractLedgerCostExt retrieves the ContractLedgerCostExt value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractLedgerCostExt() (result ConfigSettingContractLedgerCostExtV0, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractLedgerCostExt" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingContractLedgerCostExtV0 { result = *u.ContractLedgerCostExt ok = true } - return } // MustContractScpTiming retrieves the ContractScpTiming value from the union, // panicing if the value is not set. func (u ConfigSettingEntry) MustContractScpTiming() ConfigSettingScpTiming { - val, ok := u.GetContractScpTiming() - - if !ok { - panic("arm ContractScpTiming is not set") + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingScpTiming { + return *u.ContractScpTiming } - - return val + panic("arm ContractScpTiming is not set") } // GetContractScpTiming retrieves the ContractScpTiming value from the union, // returning ok if the union's switch indicated the value is valid. func (u ConfigSettingEntry) GetContractScpTiming() (result ConfigSettingScpTiming, ok bool) { - armName, _ := u.ArmForSwitch(int32(u.ConfigSettingId)) - - if armName == "ContractScpTiming" { + if ConfigSettingId(u.ConfigSettingId) == ConfigSettingIdConfigSettingScpTiming { result = *u.ContractScpTiming ok = true } - return } @@ -62037,7 +60167,7 @@ func (u ConfigSettingEntry) EncodeTo(e *xdr.Encoder) error { } switch ConfigSettingId(u.ConfigSettingId) { case ConfigSettingIdConfigSettingContractMaxSizeBytes: - if err = (*u.ContractMaxSizeBytes).EncodeTo(e); err != nil { + if err = u.ContractMaxSizeBytes.EncodeTo(e); err != nil { return err } return nil @@ -62077,12 +60207,12 @@ func (u ConfigSettingEntry) EncodeTo(e *xdr.Encoder) error { } return nil case ConfigSettingIdConfigSettingContractDataKeySizeBytes: - if err = (*u.ContractDataKeySizeBytes).EncodeTo(e); err != nil { + if err = u.ContractDataKeySizeBytes.EncodeTo(e); err != nil { return err } return nil case ConfigSettingIdConfigSettingContractDataEntrySizeBytes: - if err = (*u.ContractDataEntrySizeBytes).EncodeTo(e); err != nil { + if err = u.ContractDataEntrySizeBytes.EncodeTo(e); err != nil { return err } return nil @@ -62130,9 +60260,9 @@ func (u ConfigSettingEntry) EncodeTo(e *xdr.Encoder) error { return fmt.Errorf("ConfigSettingId (ConfigSettingId) switch value '%d' is not valid for union ConfigSettingEntry", u.ConfigSettingId) } -var _ decoderFrom = (*ConfigSettingEntry)(nil) +var _ xdr.DecoderFrom = (*ConfigSettingEntry)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding ConfigSettingEntry: %w", ErrMaxDecodingDepthReached) @@ -62147,15 +60277,16 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } switch ConfigSettingId(u.ConfigSettingId) { case ConfigSettingIdConfigSettingContractMaxSizeBytes: - u.ContractMaxSizeBytes = new(Uint32) - nTmp, err = (*u.ContractMaxSizeBytes).DecodeFrom(d, maxDepth) + nTmp, err = u.ContractMaxSizeBytes.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } return n, nil case ConfigSettingIdConfigSettingContractComputeV0: - u.ContractCompute = new(ConfigSettingContractComputeV0) + if u.ContractCompute == nil { + u.ContractCompute = new(ConfigSettingContractComputeV0) + } nTmp, err = (*u.ContractCompute).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62163,7 +60294,9 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingContractLedgerCostV0: - u.ContractLedgerCost = new(ConfigSettingContractLedgerCostV0) + if u.ContractLedgerCost == nil { + u.ContractLedgerCost = new(ConfigSettingContractLedgerCostV0) + } nTmp, err = (*u.ContractLedgerCost).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62171,7 +60304,9 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingContractHistoricalDataV0: - u.ContractHistoricalData = new(ConfigSettingContractHistoricalDataV0) + if u.ContractHistoricalData == nil { + u.ContractHistoricalData = new(ConfigSettingContractHistoricalDataV0) + } nTmp, err = (*u.ContractHistoricalData).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62179,7 +60314,9 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingContractEventsV0: - u.ContractEvents = new(ConfigSettingContractEventsV0) + if u.ContractEvents == nil { + u.ContractEvents = new(ConfigSettingContractEventsV0) + } nTmp, err = (*u.ContractEvents).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62187,7 +60324,9 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingContractBandwidthV0: - u.ContractBandwidth = new(ConfigSettingContractBandwidthV0) + if u.ContractBandwidth == nil { + u.ContractBandwidth = new(ConfigSettingContractBandwidthV0) + } nTmp, err = (*u.ContractBandwidth).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62195,7 +60334,9 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingContractCostParamsCpuInstructions: - u.ContractCostParamsCpuInsns = new(ContractCostParams) + if u.ContractCostParamsCpuInsns == nil { + u.ContractCostParamsCpuInsns = new(ContractCostParams) + } nTmp, err = (*u.ContractCostParamsCpuInsns).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62203,7 +60344,9 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingContractCostParamsMemoryBytes: - u.ContractCostParamsMemBytes = new(ContractCostParams) + if u.ContractCostParamsMemBytes == nil { + u.ContractCostParamsMemBytes = new(ContractCostParams) + } nTmp, err = (*u.ContractCostParamsMemBytes).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62211,23 +60354,23 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingContractDataKeySizeBytes: - u.ContractDataKeySizeBytes = new(Uint32) - nTmp, err = (*u.ContractDataKeySizeBytes).DecodeFrom(d, maxDepth) + nTmp, err = u.ContractDataKeySizeBytes.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } return n, nil case ConfigSettingIdConfigSettingContractDataEntrySizeBytes: - u.ContractDataEntrySizeBytes = new(Uint32) - nTmp, err = (*u.ContractDataEntrySizeBytes).DecodeFrom(d, maxDepth) + nTmp, err = u.ContractDataEntrySizeBytes.DecodeFrom(d, maxDepth) n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint32: %w", err) } return n, nil case ConfigSettingIdConfigSettingStateArchival: - u.StateArchivalSettings = new(StateArchivalSettings) + if u.StateArchivalSettings == nil { + u.StateArchivalSettings = new(StateArchivalSettings) + } nTmp, err = (*u.StateArchivalSettings).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62235,7 +60378,9 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingContractExecutionLanes: - u.ContractExecutionLanes = new(ConfigSettingContractExecutionLanesV0) + if u.ContractExecutionLanes == nil { + u.ContractExecutionLanes = new(ConfigSettingContractExecutionLanesV0) + } nTmp, err = (*u.ContractExecutionLanes).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62243,19 +60388,26 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingLiveSorobanStateSizeWindow: - u.LiveSorobanStateSizeWindow = new([]Uint64) + if u.LiveSorobanStateSizeWindow == nil { + u.LiveSorobanStateSizeWindow = new([]Uint64) + } var l uint32 l, nTmp, err = d.DecodeUint() n += nTmp if err != nil { return n, fmt.Errorf("decoding Uint64: %w", err) } - (*u.LiveSorobanStateSizeWindow) = nil - if l > 0 { + if l == 0 { + (*u.LiveSorobanStateSizeWindow) = (*u.LiveSorobanStateSizeWindow)[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding Uint64: length (%d) exceeds remaining input length (%d)", l, il) } - (*u.LiveSorobanStateSizeWindow) = make([]Uint64, l) + if cap((*u.LiveSorobanStateSizeWindow)) >= int(l) { + (*u.LiveSorobanStateSizeWindow) = (*u.LiveSorobanStateSizeWindow)[:l] + } else { + (*u.LiveSorobanStateSizeWindow) = make([]Uint64, l) + } for i := uint32(0); i < l; i++ { nTmp, err = (*u.LiveSorobanStateSizeWindow)[i].DecodeFrom(d, maxDepth) n += nTmp @@ -62266,7 +60418,9 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingEvictionIterator: - u.EvictionIterator = new(EvictionIterator) + if u.EvictionIterator == nil { + u.EvictionIterator = new(EvictionIterator) + } nTmp, err = (*u.EvictionIterator).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62274,7 +60428,9 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingContractParallelComputeV0: - u.ContractParallelCompute = new(ConfigSettingContractParallelComputeV0) + if u.ContractParallelCompute == nil { + u.ContractParallelCompute = new(ConfigSettingContractParallelComputeV0) + } nTmp, err = (*u.ContractParallelCompute).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62282,7 +60438,9 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingContractLedgerCostExtV0: - u.ContractLedgerCostExt = new(ConfigSettingContractLedgerCostExtV0) + if u.ContractLedgerCostExt == nil { + u.ContractLedgerCostExt = new(ConfigSettingContractLedgerCostExtV0) + } nTmp, err = (*u.ContractLedgerCostExt).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62290,7 +60448,9 @@ func (u *ConfigSettingEntry) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, err } return n, nil case ConfigSettingIdConfigSettingScpTiming: - u.ContractScpTiming = new(ConfigSettingScpTiming) + if u.ContractScpTiming == nil { + u.ContractScpTiming = new(ConfigSettingScpTiming) + } nTmp, err = (*u.ContractScpTiming).DecodeFrom(d, maxDepth) n += nTmp if err != nil { @@ -62311,11 +60471,8 @@ func (s ConfigSettingEntry) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *ConfigSettingEntry) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } @@ -62368,9 +60525,9 @@ func (s *LedgerCloseMetaBatch) EncodeTo(e *xdr.Encoder) error { return nil } -var _ decoderFrom = (*LedgerCloseMetaBatch)(nil) +var _ xdr.DecoderFrom = (*LedgerCloseMetaBatch)(nil) -// DecodeFrom decodes this value using the Decoder. +// DecodeFrom decodes this value from the given decoder. func (s *LedgerCloseMetaBatch) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) { if maxDepth == 0 { return 0, fmt.Errorf("decoding LedgerCloseMetaBatch: %w", ErrMaxDecodingDepthReached) @@ -62394,12 +60551,17 @@ func (s *LedgerCloseMetaBatch) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, e if err != nil { return n, fmt.Errorf("decoding LedgerCloseMeta: %w", err) } - s.LedgerCloseMetas = nil - if l > 0 { + if l == 0 { + s.LedgerCloseMetas = s.LedgerCloseMetas[:0] + } else { if il, ok := d.InputLen(); ok && uint(il) < uint(l) { return n, fmt.Errorf("decoding LedgerCloseMeta: length (%d) exceeds remaining input length (%d)", l, il) } - s.LedgerCloseMetas = make([]LedgerCloseMeta, l) + if cap(s.LedgerCloseMetas) >= int(l) { + s.LedgerCloseMetas = s.LedgerCloseMetas[:l] + } else { + s.LedgerCloseMetas = make([]LedgerCloseMeta, l) + } for i := uint32(0); i < l; i++ { nTmp, err = s.LedgerCloseMetas[i].DecodeFrom(d, maxDepth) n += nTmp @@ -62421,11 +60583,8 @@ func (s LedgerCloseMetaBatch) MarshalBinary() ([]byte, error) { // UnmarshalBinary implements encoding.BinaryUnmarshaler. func (s *LedgerCloseMetaBatch) UnmarshalBinary(inp []byte) error { - r := bytes.NewReader(inp) - o := xdr.DefaultDecodeOptions - o.MaxInputLen = len(inp) - d := xdr.NewDecoderWithOptions(r, o) - _, err := s.DecodeFrom(d, o.MaxDepth) + d := xdr.NewDecoder(inp) + _, err := d.Decode(s) return err } diff --git a/xdr/xdrstream.go b/xdr/xdrstream.go index dce9f7aa11..29ba3cdfee 100644 --- a/xdr/xdrstream.go +++ b/xdr/xdrstream.go @@ -9,13 +9,12 @@ import ( "bytes" "compress/gzip" "crypto/sha256" - "encoding/binary" "fmt" "hash" "io" - "io/ioutil" "github.com/klauspost/compress/zstd" + xdr3 "github.com/stellar/go-xdr/xdr3" "github.com/stellar/go-stellar-sdk/support/errors" ) @@ -28,7 +27,7 @@ type Stream struct { validateHash bool expectedHash [sha256.Size]byte - xdrDecoder *BytesDecoder + xdrDecoder *xdr3.Decoder } type countReader struct { @@ -61,7 +60,7 @@ func NewStream(in io.ReadCloser) *Stream { }{bufio.NewReader(teeReader), in}, ), sha256Hash: sha256Hash, - xdrDecoder: NewBytesDecoder(), + xdrDecoder: xdr3.NewDecoder(nil), } } @@ -166,41 +165,40 @@ func (x *Stream) closeReaders() error { } func (x *Stream) ReadOne(in DecoderFrom) error { - var nbytes uint32 - err := binary.Read(x.reader, binary.BigEndian, &nbytes) + frameLen, err := ReadFrameLength(x.reader) if err != nil { x.reader.Close() if err == io.EOF { - // Do not wrap io.EOF return err } - return errors.Wrap(err, "binary.Read error") + return errors.Wrap(err, "reading frame length") } - nbytes &= 0x7fffffff - x.buf.Reset() - if nbytes == 0 { + if frameLen == 0 { x.reader.Close() return io.EOF } - x.buf.Grow(int(nbytes)) - read, err := x.buf.ReadFrom(io.LimitReader(x.reader, int64(nbytes))) + + x.buf.Reset() + x.buf.Grow(int(frameLen)) + read, err := x.buf.ReadFrom(io.LimitReader(x.reader, int64(frameLen))) if err != nil { x.reader.Close() return err } - if read != int64(nbytes) { + if read != int64(frameLen) { x.reader.Close() return errors.New("Read wrong number of bytes from XDR") } - readi, err := x.xdrDecoder.DecodeBytes(in, x.buf.Bytes()) + x.xdrDecoder.Reset(x.buf.Bytes()) + readi, err := x.xdrDecoder.Decode(in) if err != nil { x.reader.Close() return err } - if int64(readi) != int64(nbytes) { + if int64(readi) != int64(frameLen) { return fmt.Errorf("Unmarshalled %d bytes from XDR, expected %d)", - readi, nbytes) + readi, frameLen) } return nil } @@ -221,7 +219,7 @@ func (x *Stream) CompressedBytesRead() int64 { // Discard removes n bytes from the stream func (x *Stream) Discard(n int64) (int64, error) { - return io.CopyN(ioutil.Discard, x.reader, n) + return io.CopyN(io.Discard, x.reader, n) } func CreateXdrStream(entries ...BucketEntry) *Stream { @@ -233,5 +231,5 @@ func CreateXdrStream(entries ...BucketEntry) *Stream { } } - return NewStream(ioutil.NopCloser(b)) + return NewStream(io.NopCloser(b)) }