diff --git a/cmd/export_ledger_entry_changes.go b/cmd/export_ledger_entry_changes.go index 726f5cee..7b727680 100644 --- a/cmd/export_ledger_entry_changes.go +++ b/cmd/export_ledger_entry_changes.go @@ -57,7 +57,7 @@ be exported.`, } if allFalse { - for export_name, _ := range exports { + for export_name := range exports { exports[export_name] = true } } diff --git a/cmd/export_ledgers.go b/cmd/export_ledgers.go index de3baa13..f5000289 100644 --- a/cmd/export_ledgers.go +++ b/cmd/export_ledgers.go @@ -5,7 +5,6 @@ import ( "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/stellar/go/historyarchive" "github.com/stellar/stellar-etl/internal/input" "github.com/stellar/stellar-etl/internal/transform" "github.com/stellar/stellar-etl/internal/utils" @@ -23,7 +22,7 @@ var ledgersCmd = &cobra.Command{ cloudStorageBucket, cloudCredentials, cloudProvider := utils.MustCloudStorageFlags(cmd.Flags(), cmdLogger) env := utils.GetEnvironmentDetails(isTest, isFuture, datastoreUrl) - var ledgers []historyarchive.Ledger + var ledgers []utils.HistoryArchiveLedgerAndLCM var err error if useCaptiveCore { @@ -39,8 +38,8 @@ var ledgersCmd = &cobra.Command{ numFailures := 0 totalNumBytes := 0 - for i, lcm := range ledgers { - transformed, err := transform.TransformLedger(lcm) + for i, ledger := range ledgers { + transformed, err := transform.TransformLedger(ledger.Ledger, ledger.LCM) if err != nil { cmdLogger.LogError(fmt.Errorf("could not json transform ledger %d: %s", startNum+uint32(i), err)) numFailures += 1 diff --git a/cmd/export_ledgers_test.go b/cmd/export_ledgers_test.go index 68d3f0f5..8006ea6d 100644 --- a/cmd/export_ledgers_test.go +++ b/cmd/export_ledgers_test.go @@ -121,7 +121,7 @@ func indexOf(l []string, s string) int { return -1 } -func sortByName(files []os.FileInfo) { +func sortByName(files []os.DirEntry) { sort.Slice(files, func(i, j int) bool { return files[i].Name() < files[j].Name() }) @@ -144,14 +144,14 @@ func runCLITest(t *testing.T, test cliTest, goldenFolder string) { // If the output arg specified is a directory, concat the contents for comparison. if stat.IsDir() { - files, err := ioutil.ReadDir(outLocation) + files, err := os.ReadDir(outLocation) if err != nil { log.Fatal(err) } var buf bytes.Buffer sortByName(files) for _, f := range files { - b, err := ioutil.ReadFile(filepath.Join(outLocation, f.Name())) + b, err := os.ReadFile(filepath.Join(outLocation, f.Name())) if err != nil { log.Fatal(err) } @@ -160,7 +160,7 @@ func runCLITest(t *testing.T, test cliTest, goldenFolder string) { testOutput = buf.Bytes() } else { // If the output is written to a file, read the contents of the file for comparison. - testOutput, err = ioutil.ReadFile(outLocation) + testOutput, err = os.ReadFile(outLocation) if err != nil { log.Fatal(err) } @@ -197,16 +197,6 @@ func extractErrorMsg(loggerOutput string) string { return loggerOutput[errIndex : errIndex+endIndex] } -func removeCoreLogging(loggerOutput string) string { - endIndex := strings.Index(loggerOutput, "{\"") - // if there is no bracket, then nothing was exported except logs - if endIndex == -1 { - return "" - } - - return loggerOutput[endIndex:] -} - func getLastSeqNum(archiveURLs []string) uint32 { num, err := utils.GetLatestLedgerSequence(archiveURLs) if err != nil { @@ -218,10 +208,10 @@ func getLastSeqNum(archiveURLs []string) uint32 { func getGolden(t *testing.T, goldenFile string, actual string, update bool) (string, error) { t.Helper() f, err := os.OpenFile(goldenFile, os.O_RDWR, 0644) - defer f.Close() if err != nil { return "", err } + defer f.Close() // If the update flag is true, clear the current contents of the golden file and write the actual output // This is useful for when new tests or added or functionality changes that breaks current tests diff --git a/docker/Dockerfile b/docker/Dockerfile index d85a126c..76842e8e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,7 +11,7 @@ COPY . . RUN go build -v -o /usr/local/bin ./... # stage 2: runtime enviroment -FROM stellar/stellar-core:20.2.0-1716.rc3.34d82fc00.focal +FROM stellar/unsafe-stellar-core:21.0.0-1812.rc1.a10329cca.focal WORKDIR /etl diff --git a/docker/stellar-core.cfg b/docker/stellar-core.cfg index 753d16c7..b7c710d8 100644 --- a/docker/stellar-core.cfg +++ b/docker/stellar-core.cfg @@ -3,6 +3,8 @@ # for how to properly configure your environment ENABLE_SOROBAN_DIAGNOSTIC_EVENTS=true +EMIT_SOROBAN_TRANSACTION_META_EXT_V1=true +EMIT_LEDGER_CLOSE_META_EXT_V1=true #FAILURE_SAFETY is minimum number of nodes that are allowed to fail before you no longer have quorum FAILURE_SAFETY=1 diff --git a/docker/stellar-core_futurenet.cfg b/docker/stellar-core_futurenet.cfg index 8ab94fb0..832c75c4 100644 --- a/docker/stellar-core_futurenet.cfg +++ b/docker/stellar-core_futurenet.cfg @@ -7,6 +7,8 @@ PUBLIC_HTTP_PORT=false NETWORK_PASSPHRASE="Test SDF Future Network ; October 2022" ENABLE_SOROBAN_DIAGNOSTIC_EVENTS=true +EMIT_SOROBAN_TRANSACTION_META_EXT_V1=true +EMIT_LEDGER_CLOSE_META_EXT_V1=true # DATABASE="sqlite3://stellar.db" PEER_PORT=11725 diff --git a/docker/stellar-core_testnet.cfg b/docker/stellar-core_testnet.cfg index 94502b2c..2d8a0426 100644 --- a/docker/stellar-core_testnet.cfg +++ b/docker/stellar-core_testnet.cfg @@ -6,6 +6,8 @@ NETWORK_PASSPHRASE="Test SDF Network ; September 2015" # DATABASE="sqlite3://stellar.db" ENABLE_SOROBAN_DIAGNOSTIC_EVENTS=true +EMIT_SOROBAN_TRANSACTION_META_EXT_V1=true +EMIT_LEDGER_CLOSE_META_EXT_V1=true # Stellar Testnet validators [[HOME_DOMAINS]] diff --git a/go.mod b/go.mod index e87fbc1a..56f483d1 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,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 v0.0.0-20240419222646-3a79646669ab + github.com/stellar/go v0.0.0-20240423031611-e1c5206ad1ba github.com/stretchr/testify v1.9.0 ) diff --git a/go.sum b/go.sum index 3d6f1fa8..92a52cf7 100644 --- a/go.sum +++ b/go.sum @@ -296,10 +296,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 v0.0.0-20240419044405-2d7308b67c07 h1:AgxlbRmsFAc9VaOLj29K9RpsSmlmtJ0KCVnGxV7bUwo= -github.com/stellar/go v0.0.0-20240419044405-2d7308b67c07/go.mod h1:ckzsX0B0qfTMVZQJtPELJLs7cJ6xXMYHPVLyIsReGsU= -github.com/stellar/go v0.0.0-20240419222646-3a79646669ab h1:+uTCn/DrOc1cXugQ8PKZPAkZS3KWeHk5f2aKk9jdrDs= -github.com/stellar/go v0.0.0-20240419222646-3a79646669ab/go.mod h1:ckzsX0B0qfTMVZQJtPELJLs7cJ6xXMYHPVLyIsReGsU= +github.com/stellar/go v0.0.0-20240423031611-e1c5206ad1ba h1:2UPb78V6mL07B0nJ6/89nJ2cimVD3xPMCFxawwRvpJ0= +github.com/stellar/go v0.0.0-20240423031611-e1c5206ad1ba/go.mod h1:ckzsX0B0qfTMVZQJtPELJLs7cJ6xXMYHPVLyIsReGsU= 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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/internal/input/ledgers.go b/internal/input/ledgers.go index c83b3b55..d70012de 100644 --- a/internal/input/ledgers.go +++ b/internal/input/ledgers.go @@ -11,20 +11,20 @@ import ( ) // GetLedgers returns a slice of ledger close metas for the ledgers in the provided range (inclusive on both ends) -func GetLedgers(start, end uint32, limit int64, env utils.EnvironmentDetails, useCaptiveCore bool) ([]historyarchive.Ledger, error) { +func GetLedgers(start, end uint32, limit int64, env utils.EnvironmentDetails, useCaptiveCore bool) ([]utils.HistoryArchiveLedgerAndLCM, error) { ctx := context.Background() backend, err := utils.CreateLedgerBackend(ctx, useCaptiveCore, env) if err != nil { - return []historyarchive.Ledger{}, err + return []utils.HistoryArchiveLedgerAndLCM{}, err } - ledgerSlice := []historyarchive.Ledger{} + ledgerSlice := []utils.HistoryArchiveLedgerAndLCM{} err = backend.PrepareRange(ctx, ledgerbackend.BoundedRange(start, end)) panicIf(err) for seq := start; seq <= end; seq++ { lcm, err := backend.GetLedger(ctx, seq) if err != nil { - return []historyarchive.Ledger{}, err + return []utils.HistoryArchiveLedgerAndLCM{}, err } var ext xdr.TransactionHistoryEntryExt @@ -68,7 +68,12 @@ func GetLedgers(start, end uint32, limit int64, env utils.EnvironmentDetails, us }, } - ledgerSlice = append(ledgerSlice, ledger) + ledgerLCM := utils.HistoryArchiveLedgerAndLCM{ + Ledger: ledger, + LCM: lcm, + } + + ledgerSlice = append(ledgerSlice, ledgerLCM) if int64(len(ledgerSlice)) >= limit && limit >= 0 { break } diff --git a/internal/input/ledgers_history_archive.go b/internal/input/ledgers_history_archive.go index 613efd1e..5b42ba5c 100644 --- a/internal/input/ledgers_history_archive.go +++ b/internal/input/ledgers_history_archive.go @@ -4,26 +4,28 @@ import ( "context" "github.com/stellar/stellar-etl/internal/utils" - - "github.com/stellar/go/historyarchive" ) // GetLedgers returns a slice of ledger close metas for the ledgers in the provided range (inclusive on both ends) -func GetLedgersHistoryArchive(start, end uint32, limit int64, env utils.EnvironmentDetails, useCaptiveCore bool) ([]historyarchive.Ledger, error) { +func GetLedgersHistoryArchive(start, end uint32, limit int64, env utils.EnvironmentDetails, useCaptiveCore bool) ([]utils.HistoryArchiveLedgerAndLCM, error) { backend, err := utils.CreateBackend(start, end, env.ArchiveURLs) if err != nil { - return []historyarchive.Ledger{}, err + return []utils.HistoryArchiveLedgerAndLCM{}, err } - ledgerSlice := []historyarchive.Ledger{} + ledgerSlice := []utils.HistoryArchiveLedgerAndLCM{} ctx := context.Background() for seq := start; seq <= end; seq++ { ledger, err := backend.GetLedgerArchive(ctx, seq) if err != nil { - return []historyarchive.Ledger{}, err + return []utils.HistoryArchiveLedgerAndLCM{}, err + } + + ledgerLCM := utils.HistoryArchiveLedgerAndLCM{ + Ledger: ledger, } - ledgerSlice = append(ledgerSlice, ledger) + ledgerSlice = append(ledgerSlice, ledgerLCM) if int64(len(ledgerSlice)) >= limit && limit >= 0 { break } diff --git a/internal/transform/account.go b/internal/transform/account.go index 1a605ac6..84f4c706 100644 --- a/internal/transform/account.go +++ b/internal/transform/account.go @@ -18,7 +18,7 @@ func TransformAccount(ledgerChange ingest.Change, header xdr.LedgerHeaderHistory accountEntry, accountFound := ledgerEntry.Data.GetAccount() if !accountFound { - return AccountOutput{}, fmt.Errorf("Could not extract account data from ledger entry; actual type is %s", ledgerEntry.Data.Type) + return AccountOutput{}, fmt.Errorf("could not extract account data from ledger entry; actual type is %s", ledgerEntry.Data.Type) } outputID, err := accountEntry.AccountId.GetAddress() @@ -28,7 +28,7 @@ func TransformAccount(ledgerChange ingest.Change, header xdr.LedgerHeaderHistory outputBalance := accountEntry.Balance if outputBalance < 0 { - return AccountOutput{}, fmt.Errorf("Balance is negative (%d) for account: %s", outputBalance, outputID) + return AccountOutput{}, fmt.Errorf("balance is negative (%d) for account: %s", outputBalance, outputID) } //The V1 struct is the first version of the extender from accountEntry. It contains information on liabilities, and in the future @@ -39,17 +39,17 @@ func TransformAccount(ledgerChange ingest.Change, header xdr.LedgerHeaderHistory liabilities := accountExtensionInfo.Liabilities outputBuyingLiabilities, outputSellingLiabilities = liabilities.Buying, liabilities.Selling if outputBuyingLiabilities < 0 { - return AccountOutput{}, fmt.Errorf("The buying liabilities count is negative (%d) for account: %s", outputBuyingLiabilities, outputID) + return AccountOutput{}, fmt.Errorf("the buying liabilities count is negative (%d) for account: %s", outputBuyingLiabilities, outputID) } if outputSellingLiabilities < 0 { - return AccountOutput{}, fmt.Errorf("The selling liabilities count is negative (%d) for account: %s", outputSellingLiabilities, outputID) + return AccountOutput{}, fmt.Errorf("the selling liabilities count is negative (%d) for account: %s", outputSellingLiabilities, outputID) } } outputSequenceNumber := int64(accountEntry.SeqNum) if outputSequenceNumber < 0 { - return AccountOutput{}, fmt.Errorf("Account sequence number is negative (%d) for account: %s", outputSequenceNumber, outputID) + return AccountOutput{}, fmt.Errorf("account sequence number is negative (%d) for account: %s", outputSequenceNumber, outputID) } outputSequenceLedger := accountEntry.SeqLedger() outputSequenceTime := accountEntry.SeqTime() diff --git a/internal/transform/account_test.go b/internal/transform/account_test.go index c99b66fc..af050c03 100644 --- a/internal/transform/account_test.go +++ b/internal/transform/account_test.go @@ -38,7 +38,7 @@ func TestTransformAccount(t *testing.T) { }, }, }, - AccountOutput{}, fmt.Errorf("Could not extract account data from ledger entry; actual type is LedgerEntryTypeOffer"), + AccountOutput{}, fmt.Errorf("could not extract account data from ledger entry; actual type is LedgerEntryTypeOffer"), }, { inputStruct{wrapAccountEntry(xdr.AccountEntry{ @@ -46,7 +46,7 @@ func TestTransformAccount(t *testing.T) { Balance: -1, }, 0), }, - AccountOutput{}, fmt.Errorf("Balance is negative (-1) for account: %s", genericAccountAddress), + AccountOutput{}, fmt.Errorf("balance is negative (-1) for account: %s", genericAccountAddress), }, { inputStruct{wrapAccountEntry(xdr.AccountEntry{ @@ -61,7 +61,7 @@ func TestTransformAccount(t *testing.T) { }, }, 0), }, - AccountOutput{}, fmt.Errorf("The buying liabilities count is negative (-1) for account: %s", genericAccountAddress), + AccountOutput{}, fmt.Errorf("the buying liabilities count is negative (-1) for account: %s", genericAccountAddress), }, { inputStruct{wrapAccountEntry(xdr.AccountEntry{ @@ -76,7 +76,7 @@ func TestTransformAccount(t *testing.T) { }, }, 0), }, - AccountOutput{}, fmt.Errorf("The selling liabilities count is negative (-2) for account: %s", genericAccountAddress), + AccountOutput{}, fmt.Errorf("the selling liabilities count is negative (-2) for account: %s", genericAccountAddress), }, { inputStruct{wrapAccountEntry(xdr.AccountEntry{ @@ -84,7 +84,7 @@ func TestTransformAccount(t *testing.T) { SeqNum: -3, }, 0), }, - AccountOutput{}, fmt.Errorf("Account sequence number is negative (-3) for account: %s", genericAccountAddress), + AccountOutput{}, fmt.Errorf("account sequence number is negative (-3) for account: %s", genericAccountAddress), }, { inputStruct{ diff --git a/internal/transform/asset_test.go b/internal/transform/asset_test.go index deedbe49..cc5f813b 100644 --- a/internal/transform/asset_test.go +++ b/internal/transform/asset_test.go @@ -68,7 +68,7 @@ func makeAssetTestInput() (inputTransaction ingest.LedgerTransaction, err error) inputEnvelope.Tx.SourceAccount = testAccount1 inputOperations := []xdr.Operation{ - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypePayment, @@ -79,7 +79,7 @@ func makeAssetTestInput() (inputTransaction ingest.LedgerTransaction, err error) }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypePayment, @@ -99,7 +99,7 @@ func makeAssetTestInput() (inputTransaction ingest.LedgerTransaction, err error) func makeAssetTestOutput() (transformedAssets []AssetOutput) { transformedAssets = []AssetOutput{ - AssetOutput{ + { AssetCode: "USDT", AssetIssuer: "GBVVRXLMNCJQW3IDDXC3X6XCH35B5Q7QXNMMFPENSOGUPQO7WO7HGZPA", AssetType: "credit_alphanum4", @@ -107,7 +107,7 @@ func makeAssetTestOutput() (transformedAssets []AssetOutput) { ID: -8205667356306085451, }, - AssetOutput{ + { AssetCode: "", AssetIssuer: "", AssetType: "native", diff --git a/internal/transform/claimable_balance.go b/internal/transform/claimable_balance.go index 73cfc0a0..ca1cf6fb 100644 --- a/internal/transform/claimable_balance.go +++ b/internal/transform/claimable_balance.go @@ -33,7 +33,7 @@ func TransformClaimableBalance(ledgerChange ingest.Change, header xdr.LedgerHead } balanceID, err := xdr.MarshalHex(balanceEntry.BalanceId) if err != nil { - return ClaimableBalanceOutput{}, fmt.Errorf("Invalid balanceId in op: %d", uint32(ledgerEntry.LastModifiedLedgerSeq)) + return ClaimableBalanceOutput{}, fmt.Errorf("invalid balanceId in op: %d", uint32(ledgerEntry.LastModifiedLedgerSeq)) } outputFlags := uint32(balanceEntry.Flags()) outputAsset, err := transformSingleAsset(balanceEntry.Asset) diff --git a/internal/transform/config_setting.go b/internal/transform/config_setting.go index c98d17c1..f110b2ab 100644 --- a/internal/transform/config_setting.go +++ b/internal/transform/config_setting.go @@ -18,7 +18,7 @@ func TransformConfigSetting(ledgerChange ingest.Change, header xdr.LedgerHeaderH configSetting, ok := ledgerEntry.Data.GetConfigSetting() if !ok { - return ConfigSettingOutput{}, fmt.Errorf("Could not extract config setting from ledger entry; actual type is %s", ledgerEntry.Data.Type) + return ConfigSettingOutput{}, fmt.Errorf("could not extract config setting from ledger entry; actual type is %s", ledgerEntry.Data.Type) } configSettingId := configSetting.ConfigSettingId @@ -48,7 +48,7 @@ func TransformConfigSetting(ledgerChange ingest.Change, header xdr.LedgerHeaderH writeFee1KbBucketListHigh := contractLedgerCost.WriteFee1KbBucketListHigh bucketListWriteFeeGrowthFactor := contractLedgerCost.BucketListWriteFeeGrowthFactor - contractHistoricalData, ok := configSetting.GetContractHistoricalData() + contractHistoricalData, _ := configSetting.GetContractHistoricalData() feeHistorical1Kb := contractHistoricalData.FeeHistorical1Kb contractMetaData, _ := configSetting.GetContractEvents() @@ -66,9 +66,9 @@ func TransformConfigSetting(ledgerChange ingest.Change, header xdr.LedgerHeaderH paramsMemBytes, _ := configSetting.GetContractCostParamsMemBytes() contractCostParamsMemBytes := serializeParams(paramsMemBytes) - contractDataKeySizeBytes, ok := configSetting.GetContractDataKeySizeBytes() + contractDataKeySizeBytes, _ := configSetting.GetContractDataKeySizeBytes() - contractDataEntrySizeBytes, ok := configSetting.GetContractDataEntrySizeBytes() + contractDataEntrySizeBytes, _ := configSetting.GetContractDataEntrySizeBytes() stateArchivalSettings, _ := configSetting.GetStateArchivalSettings() maxEntryTtl := stateArchivalSettings.MaxEntryTtl diff --git a/internal/transform/config_setting_test.go b/internal/transform/config_setting_test.go index b780c3fe..59163e88 100644 --- a/internal/transform/config_setting_test.go +++ b/internal/transform/config_setting_test.go @@ -31,7 +31,7 @@ func TestTransformConfigSetting(t *testing.T) { }, }, }, - ConfigSettingOutput{}, fmt.Errorf("Could not extract config setting from ledger entry; actual type is LedgerEntryTypeOffer"), + ConfigSettingOutput{}, fmt.Errorf("could not extract config setting from ledger entry; actual type is LedgerEntryTypeOffer"), }, } @@ -82,8 +82,8 @@ func makeConfigSettingTestInput() []ingest.Change { } func makeConfigSettingTestOutput() []ConfigSettingOutput { - contractMapType := make([]map[string]string, 0, 0) - bucket := make([]uint64, 0, 0) + contractMapType := make([]map[string]string, 0) + bucket := make([]uint64, 0) return []ConfigSettingOutput{ { diff --git a/internal/transform/contract_code.go b/internal/transform/contract_code.go index 8bfcf574..bea834a3 100644 --- a/internal/transform/contract_code.go +++ b/internal/transform/contract_code.go @@ -17,7 +17,7 @@ func TransformContractCode(ledgerChange ingest.Change, header xdr.LedgerHeaderHi contractCode, ok := ledgerEntry.Data.GetContractCode() if !ok { - return ContractCodeOutput{}, fmt.Errorf("Could not extract contract code from ledger entry; actual type is %s", ledgerEntry.Data.Type) + return ContractCodeOutput{}, fmt.Errorf("could not extract contract code from ledger entry; actual type is %s", ledgerEntry.Data.Type) } // LedgerEntryChange must contain a contract code change to be parsed, otherwise skip diff --git a/internal/transform/contract_code_test.go b/internal/transform/contract_code_test.go index e55e13ae..cc710081 100644 --- a/internal/transform/contract_code_test.go +++ b/internal/transform/contract_code_test.go @@ -31,7 +31,7 @@ func TestTransformContractCode(t *testing.T) { }, }, }, - ContractCodeOutput{}, fmt.Errorf("Could not extract contract code from ledger entry; actual type is LedgerEntryTypeOffer"), + ContractCodeOutput{}, fmt.Errorf("could not extract contract code from ledger entry; actual type is LedgerEntryTypeOffer"), }, } diff --git a/internal/transform/contract_data.go b/internal/transform/contract_data.go index 30fec49b..614c8655 100644 --- a/internal/transform/contract_data.go +++ b/internal/transform/contract_data.go @@ -10,27 +10,13 @@ import ( "github.com/stellar/stellar-etl/internal/utils" ) -const ( - scDecimalPrecision = 7 -) - var ( - // https://github.com/stellar/rs-soroban-env/blob/v0.0.16/soroban-env-host/src/native_contract/token/public_types.rs#L22 - nativeAssetSym = xdr.ScSymbol("Native") // these are storage DataKey enum // https://github.com/stellar/rs-soroban-env/blob/v0.0.16/soroban-env-host/src/native_contract/token/storage_types.rs#L23 balanceMetadataSym = xdr.ScSymbol("Balance") - metadataSym = xdr.ScSymbol("METADATA") - metadataNameSym = xdr.ScSymbol("name") - metadataSymbolSym = xdr.ScSymbol("symbol") - adminSym = xdr.ScSymbol("Admin") issuerSym = xdr.ScSymbol("issuer") assetCodeSym = xdr.ScSymbol("asset_code") - alphaNum4Sym = xdr.ScSymbol("AlphaNum4") - alphaNum12Sym = xdr.ScSymbol("AlphaNum12") - decimalSym = xdr.ScSymbol("decimal") assetInfoSym = xdr.ScSymbol("AssetInfo") - decimalVal = xdr.Uint32(scDecimalPrecision) assetInfoVec = &xdr.ScVec{ xdr.ScVal{ Type: xdr.ScValTypeScvSymbol, @@ -67,7 +53,7 @@ func (t *TransformContractDataStruct) TransformContractData(ledgerChange ingest. contractData, ok := ledgerEntry.Data.GetContractData() if !ok { - return ContractDataOutput{}, fmt.Errorf("Could not extract contract data from ledger entry; actual type is %s", ledgerEntry.Data.Type), false + return ContractDataOutput{}, fmt.Errorf("could not extract contract data from ledger entry; actual type is %s", ledgerEntry.Data.Type), false } if contractData.Key.Type.String() == "ScValTypeScvLedgerKeyNonce" { @@ -100,7 +86,7 @@ func (t *TransformContractDataStruct) TransformContractData(ledgerChange ingest. contractDataContractId, ok := contractData.Contract.GetContractId() if !ok { - return ContractDataOutput{}, fmt.Errorf("Could not extract contractId data information from contractData"), false + return ContractDataOutput{}, fmt.Errorf("could not extract contractId data information from contractData"), false } contractDataKeyType := contractData.Key.Type.String() diff --git a/internal/transform/contract_data_test.go b/internal/transform/contract_data_test.go index d09ab588..2777fae9 100644 --- a/internal/transform/contract_data_test.go +++ b/internal/transform/contract_data_test.go @@ -34,7 +34,7 @@ func TestTransformContractData(t *testing.T) { }, }, "unit test", - ContractDataOutput{}, fmt.Errorf("Could not extract contract data from ledger entry; actual type is LedgerEntryTypeOffer"), + ContractDataOutput{}, fmt.Errorf("could not extract contract data from ledger entry; actual type is LedgerEntryTypeOffer"), }, } diff --git a/internal/transform/diagnostic_events_test.go b/internal/transform/diagnostic_events_test.go index 39a71de1..ed6f0c47 100644 --- a/internal/transform/diagnostic_events_test.go +++ b/internal/transform/diagnostic_events_test.go @@ -98,7 +98,7 @@ func makeDiagnosticEventTestInput() (transaction []ingest.LedgerTransaction, his } genericResultResults := &[]xdr.OperationResult{ - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeCreateAccount, CreateAccountResult: &xdr.CreateAccountResult{ @@ -118,7 +118,7 @@ func makeDiagnosticEventTestInput() (transaction []ingest.LedgerTransaction, his } transaction = []ingest.LedgerTransaction{ - ingest.LedgerTransaction{ + { Index: 1, UnsafeMeta: hardCodedMeta, Envelope: xdr.TransactionEnvelope{ @@ -140,7 +140,7 @@ func makeDiagnosticEventTestInput() (transaction []ingest.LedgerTransaction, his }, }, Operations: []xdr.Operation{ - xdr.Operation{ + { SourceAccount: &testAccount2, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictReceive, @@ -166,7 +166,7 @@ func makeDiagnosticEventTestInput() (transaction []ingest.LedgerTransaction, his }, } historyHeader = []xdr.LedgerHeaderHistoryEntry{ - xdr.LedgerHeaderHistoryEntry{ + { Header: xdr.LedgerHeader{ LedgerSeq: 30521816, ScpValue: xdr.StellarValue{CloseTime: 1594272522}, diff --git a/internal/transform/effects.go b/internal/transform/effects.go index f1867347..711ed60e 100644 --- a/internal/transform/effects.go +++ b/internal/transform/effects.go @@ -131,7 +131,7 @@ func (operation *transactionOperationWrapper) effects() ([]EffectOutput, error) case xdr.OperationTypeRestoreFootprint: err = wrapper.addRestoreFootprintExpirationEffect() default: - return nil, fmt.Errorf("Unknown operation type: %s", op.Body.Type) + return nil, fmt.Errorf("unknown operation type: %s", op.Body.Type) } if err != nil { return nil, err @@ -905,7 +905,7 @@ func (e *effectsWrapper) addClaimClaimableBalanceEffects(changes []ingest.Change balanceID, err := xdr.MarshalHex(op.BalanceId) if err != nil { - return fmt.Errorf("Invalid balanceId in op: %d", e.operation.index) + return fmt.Errorf("invalid balanceId in op: %d", e.operation.index) } var cBalance xdr.ClaimableBalanceEntry @@ -919,7 +919,7 @@ func (e *effectsWrapper) addClaimClaimableBalanceEffects(changes []ingest.Change cBalance = change.Pre.Data.MustClaimableBalance() preBalanceID, err := xdr.MarshalHex(cBalance.BalanceId) if err != nil { - return fmt.Errorf("Invalid balanceId in meta changes for op: %d", e.operation.index) + return fmt.Errorf("invalid balanceId in meta changes for op: %d", e.operation.index) } if preBalanceID == balanceID { @@ -930,7 +930,7 @@ func (e *effectsWrapper) addClaimClaimableBalanceEffects(changes []ingest.Change } if !found { - return fmt.Errorf("Change not found for balanceId : %s", balanceID) + return fmt.Errorf("change not found for balanceId : %s", balanceID) } details := map[string]interface{}{ diff --git a/internal/transform/effects_test.go b/internal/transform/effects_test.go index d99cfb4c..09fd2722 100644 --- a/internal/transform/effects_test.go +++ b/internal/transform/effects_test.go @@ -78,7 +78,7 @@ func TestEffectsCoversAllOperationTypes(t *testing.T) { } // calling effects should error due to the unknown operation _, err := operation.effects() - assert.Contains(t, err.Error(), "Unknown operation type") + assert.Contains(t, err.Error(), "unknown operation type") } func TestOperationEffects(t *testing.T) { @@ -349,6 +349,7 @@ func TestOperationEffects(t *testing.T) { harCodedCloseMetaInput := makeLedgerCloseMeta() LedgerClosed, err := utils.GetCloseTime(harCodedCloseMetaInput) + assert.NoError(t, err) revokeSponsorshipMeta, revokeSponsorshipEffects := getRevokeSponsorshipMeta(t) @@ -2565,12 +2566,12 @@ func TestLiquidityPoolEffects(t *testing.T) { "id": poolIDStr, "reserves": []base.AssetAmount{ { - "native", - "0.0000200", + Asset: "native", + Amount: "0.0000200", }, { - "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - "0.0000100", + Asset: "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", + Amount: "0.0000100", }, }, "total_shares": "0.0001000", @@ -2623,12 +2624,12 @@ func TestLiquidityPoolEffects(t *testing.T) { "id": poolIDStr, "reserves": []base.AssetAmount{ { - "native", - "0.0000250", + Asset: "native", + Amount: "0.0000250", }, { - "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - "0.0000160", + Asset: "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", + Amount: "0.0000160", }, }, "total_shares": "0.0001010", @@ -2637,12 +2638,12 @@ func TestLiquidityPoolEffects(t *testing.T) { }, "reserves_deposited": []base.AssetAmount{ { - "native", - "0.0000050", + Asset: "native", + Amount: "0.0000050", }, { - "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - "0.0000060", + Asset: "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", + Amount: "0.0000060", }, }, "shares_received": "0.0000010", @@ -2685,12 +2686,12 @@ func TestLiquidityPoolEffects(t *testing.T) { "id": poolIDStr, "reserves": []base.AssetAmount{ { - "native", - "0.0000189", + Asset: "native", + Amount: "0.0000189", }, { - "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - "0.0000094", + Asset: "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", + Amount: "0.0000094", }, }, "total_shares": "0.0000990", @@ -2699,12 +2700,12 @@ func TestLiquidityPoolEffects(t *testing.T) { }, "reserves_received": []base.AssetAmount{ { - "native", - "0.0000011", + Asset: "native", + Amount: "0.0000011", }, { - "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - "0.0000006", + Asset: "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", + Amount: "0.0000006", }, }, "shares_redeemed": "0.0000010", @@ -2805,12 +2806,12 @@ func TestLiquidityPoolEffects(t *testing.T) { "id": poolIDStr, "reserves": []base.AssetAmount{ { - "native", - "0.0000189", + Asset: "native", + Amount: "0.0000189", }, { - "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - "0.0000094", + Asset: "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", + Amount: "0.0000094", }, }, "total_shares": "0.0000990", @@ -3002,12 +3003,12 @@ func TestLiquidityPoolEffects(t *testing.T) { "id": poolIDStr, "reserves": []base.AssetAmount{ { - "native", - "0.0000200", + Asset: "native", + Amount: "0.0000200", }, { - "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - "0.0000100", + Asset: "USD:GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", + Amount: "0.0000100", }, }, "total_shares": "0.0001000", @@ -3326,29 +3327,16 @@ func getRevokeSponsorshipMeta(t *testing.T) (string, []EffectOutput) { type ClaimClaimableBalanceEffectsTestSuite struct { suite.Suite - ops []xdr.Operation - tx ingest.LedgerTransaction } type CreateClaimableBalanceEffectsTestSuite struct { suite.Suite - ops []xdr.Operation - tx ingest.LedgerTransaction } const ( networkPassphrase = "Arbitrary Testing Passphrase" ) -type effect struct { - address string - addressMuxed null.String - operationID int64 - details map[string]interface{} - effectType EffectType - order uint32 -} - func TestInvokeHostFunctionEffects(t *testing.T) { randAddr := func() string { return keypair.MustRandom().Address() diff --git a/internal/transform/ledger.go b/internal/transform/ledger.go index 2239eaae..9324e21e 100644 --- a/internal/transform/ledger.go +++ b/internal/transform/ledger.go @@ -12,7 +12,7 @@ import ( ) // TransformLedger converts a ledger from the history archive ingestion system into a form suitable for BigQuery -func TransformLedger(inputLedger historyarchive.Ledger) (LedgerOutput, error) { +func TransformLedger(inputLedger historyarchive.Ledger, lcm xdr.LedgerCloseMeta) (LedgerOutput, error) { ledgerHeader := inputLedger.Header.Header outputSequence := uint32(ledgerHeader.LedgerSeq) @@ -55,6 +55,15 @@ func TransformLedger(inputLedger historyarchive.Ledger) (LedgerOutput, error) { outputProtocolVersion := uint32(ledgerHeader.LedgerVersion) + var outputSorobanFeeWrite1Kb int64 + lcmV1, ok := lcm.GetV1() + if ok { + extV1, ok := lcmV1.Ext.GetV1() + if ok { + outputSorobanFeeWrite1Kb = int64(extV1.SorobanFeeWrite1Kb) + } + } + transformedLedger := LedgerOutput{ Sequence: outputSequence, LedgerID: outputLedgerID, @@ -73,6 +82,7 @@ func TransformLedger(inputLedger historyarchive.Ledger) (LedgerOutput, error) { BaseReserve: outputBaseReserve, MaxTxSetSize: outputMaxTxSetSize, ProtocolVersion: outputProtocolVersion, + SorobanFeeWrite1Kb: outputSorobanFeeWrite1Kb, } return transformedLedger, nil } @@ -93,7 +103,7 @@ func extractCounts(ledger historyarchive.Ledger) (transactionCount int32, operat results := ledger.TransactionResult.TxResultSet.Results txCount := len(transactions) if txCount != len(results) { - err = fmt.Errorf("The number of transactions and results are different (%d != %d)", txCount, len(results)) + err = fmt.Errorf("the number of transactions and results are different (%d != %d)", txCount, len(results)) return } @@ -107,7 +117,7 @@ func extractCounts(ledger historyarchive.Ledger) (transactionCount int32, operat if results[i].Result.Successful() { operationResults, ok := results[i].Result.OperationResults() if !ok { - err = fmt.Errorf("Could not access operation results for result %d", i) + err = fmt.Errorf("could not access operation results for result %d", i) return } diff --git a/internal/transform/ledger_test.go b/internal/transform/ledger_test.go index ba40e28d..0e58e2e8 100644 --- a/internal/transform/ledger_test.go +++ b/internal/transform/ledger_test.go @@ -14,7 +14,7 @@ import ( func TestTransformLedger(t *testing.T) { type transformTest struct { - input historyarchive.Ledger + input utils.HistoryArchiveLedgerAndLCM wantOutput LedgerOutput wantErr error } @@ -26,10 +26,23 @@ func TestTransformLedger(t *testing.T) { tests := []transformTest{ { - historyarchive.Ledger{ - Header: xdr.LedgerHeaderHistoryEntry{ - Header: xdr.LedgerHeader{ - TotalCoins: -1, + utils.HistoryArchiveLedgerAndLCM{ + Ledger: historyarchive.Ledger{ + Header: xdr.LedgerHeaderHistoryEntry{ + Header: xdr.LedgerHeader{ + TotalCoins: -1, + }, + }, + }, + LCM: xdr.LedgerCloseMeta{ + V: 1, + V1: &xdr.LedgerCloseMetaV1{ + Ext: xdr.LedgerCloseMetaExt{ + V: 1, + V1: &xdr.LedgerCloseMetaExtV1{ + SorobanFeeWrite1Kb: xdr.Int64(1234), + }, + }, }, }, }, @@ -37,10 +50,23 @@ func TestTransformLedger(t *testing.T) { fmt.Errorf("the total number of coins (-1) is negative for ledger 0 (ledger id=0)"), }, { - historyarchive.Ledger{ - Header: xdr.LedgerHeaderHistoryEntry{ - Header: xdr.LedgerHeader{ - FeePool: -1, + utils.HistoryArchiveLedgerAndLCM{ + Ledger: historyarchive.Ledger{ + Header: xdr.LedgerHeaderHistoryEntry{ + Header: xdr.LedgerHeader{ + FeePool: -1, + }, + }, + }, + LCM: xdr.LedgerCloseMeta{ + V: 1, + V1: &xdr.LedgerCloseMetaV1{ + Ext: xdr.LedgerCloseMetaExt{ + V: 1, + V1: &xdr.LedgerCloseMetaExtV1{ + SorobanFeeWrite1Kb: xdr.Int64(1234), + }, + }, }, }, }, @@ -55,7 +81,7 @@ func TestTransformLedger(t *testing.T) { } for _, test := range tests { - actualOutput, actualError := TransformLedger(test.input) + actualOutput, actualError := TransformLedger(test.input.Ledger, test.input.LCM) assert.Equal(t, test.wantErr, actualError) assert.Equal(t, test.wantOutput, actualOutput) } @@ -88,11 +114,12 @@ func makeLedgerTestOutput() (output LedgerOutput, err error) { SuccessfulTransactionCount: 1, FailedTransactionCount: 1, TxSetOperationCount: "13", + SorobanFeeWrite1Kb: 1234, } return } -func makeLedgerTestInput() (lcm historyarchive.Ledger, err error) { +func makeLedgerTestInput() (lcm utils.HistoryArchiveLedgerAndLCM, err error) { hardCodedTxSet := xdr.TransactionSet{ Txs: []xdr.TransactionEnvelope{ utils.CreateSampleTx(0, 3), @@ -103,7 +130,7 @@ func makeLedgerTestInput() (lcm historyarchive.Ledger, err error) { utils.CreateSampleResultPair(false, 3), utils.CreateSampleResultPair(true, 10), } - lcm = historyarchive.Ledger{ + ledger := historyarchive.Ledger{ Header: xdr.LedgerHeaderHistoryEntry{ Header: xdr.LedgerHeader{ LedgerSeq: 30578981, @@ -130,5 +157,21 @@ func makeLedgerTestInput() (lcm historyarchive.Ledger, err error) { Ext: xdr.TransactionHistoryResultEntryExt{}, }, } + + lcm = utils.HistoryArchiveLedgerAndLCM{ + Ledger: ledger, + LCM: xdr.LedgerCloseMeta{ + V: 1, + V1: &xdr.LedgerCloseMetaV1{ + Ext: xdr.LedgerCloseMetaExt{ + V: 1, + V1: &xdr.LedgerCloseMetaExtV1{ + SorobanFeeWrite1Kb: xdr.Int64(1234), + }, + }, + }, + }, + } + return lcm, nil } diff --git a/internal/transform/ledger_transaction_test.go b/internal/transform/ledger_transaction_test.go index 7e53e63d..2c471744 100644 --- a/internal/transform/ledger_transaction_test.go +++ b/internal/transform/ledger_transaction_test.go @@ -45,7 +45,7 @@ func TestTransformTx(t *testing.T) { func makeLedgerTransactionTestOutput() (output []LedgerTransactionOutput, err error) { output = []LedgerTransactionOutput{ - LedgerTransactionOutput{ + { TxEnvelope: "AAAAAgAAAACI4aa0pXFSj6qfJuIObLw/5zyugLRGYwxb7wFSr3B9eAABX5ABjydzAABBtwAAAAEAAAAAAAAAAAAAAABfBqt0AAAAAQAAABdITDVhQ2dvelFISVc3c1NjNVhkY2ZtUgAAAAABAAAAAQAAAAAcR0GXGO76pFs4y38vJVAanjnLg4emNun7zAx0pHcDGAAAAAIAAAAAAAAAAAAAAAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", TxResult: "qH/vXusmAmnDgPLeRWqtcrWbsxWqrHd4YEVuCdrAuvsAAAAAAAABLP////8AAAABAAAAAAAAAAAAAAAAAAAAAA==", TxMeta: "AAAAAQAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAAA", @@ -54,7 +54,7 @@ func makeLedgerTransactionTestOutput() (output []LedgerTransactionOutput, err er LedgerSequence: 30521816, ClosedAt: time.Date(2020, time.July, 9, 5, 28, 42, 0, time.UTC), }, - LedgerTransactionOutput{ + { TxEnvelope: "AAAABQAAAABnzACGTDuJFoxqr+C8NHCe0CHFBXLi+YhhNCIILCIpcgAAAAAAABwgAAAAAgAAAACI4aa0pXFSj6qfJuIObLw/5zyugLRGYwxb7wFSr3B9eAAAAAACFPY2AAAAfQAAAAEAAAAAAAAAAAAAAABfBqt0AAAAAQAAABdITDVhQ2dvelFISVc3c1NjNVhkY2ZtUgAAAAABAAAAAQAAAAAcR0GXGO76pFs4y38vJVAanjnLg4emNun7zAx0pHcDGAAAAAIAAAAAAAAAAAAAAAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", TxResult: "qH/vXusmAmnDgPLeRWqtcrWbsxWqrHd4YEVuCdrAuvsAAAAAAAABLAAAAAGof+9e6yYCacOA8t5Faq1ytZuzFaqsd3hgRW4J2sC6+wAAAAAAAABkAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAA==", TxMeta: "AAAAAQAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAAA", @@ -63,7 +63,7 @@ func makeLedgerTransactionTestOutput() (output []LedgerTransactionOutput, err er LedgerSequence: 30521817, ClosedAt: time.Date(2020, time.July, 9, 5, 28, 42, 0, time.UTC), }, - LedgerTransactionOutput{ + { TxEnvelope: "AAAAAgAAAAAcR0GXGO76pFs4y38vJVAanjnLg4emNun7zAx0pHcDGAAAAGQBpLyvsiV6gwAAAAIAAAABAAAAAAAAAAAAAAAAXwardAAAAAEAAAAFAAAACgAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAMCAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAABdITDVhQ2dvelFISVc3c1NjNVhkY2ZtUgAAAAABAAAAAQAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAAIAAAAAAAAAAAAAAAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", TxResult: "qH/vXusmAmnDgPLeRWqtcrWbsxWqrHd4YEVuCdrAuvsAAAAAAAAAZP////8AAAABAAAAAAAAAAAAAAAAAAAAAA==", TxMeta: "AAAAAQAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAAA", @@ -79,7 +79,7 @@ func makeLedgerTransactionTestInput() (transaction []ingest.LedgerTransaction, h hardCodedMemoText := "HL5aCgozQHIW7sSc5XdcfmR" hardCodedTransactionHash := xdr.Hash([32]byte{0xa8, 0x7f, 0xef, 0x5e, 0xeb, 0x26, 0x2, 0x69, 0xc3, 0x80, 0xf2, 0xde, 0x45, 0x6a, 0xad, 0x72, 0xb5, 0x9b, 0xb3, 0x15, 0xaa, 0xac, 0x77, 0x78, 0x60, 0x45, 0x6e, 0x9, 0xda, 0xc0, 0xba, 0xfb}) genericResultResults := &[]xdr.OperationResult{ - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeCreateAccount, CreateAccountResult: &xdr.CreateAccountResult{ @@ -106,7 +106,7 @@ func makeLedgerTransactionTestInput() (transaction []ingest.LedgerTransaction, h Ed25519: source.Ed25519, } transaction = []ingest.LedgerTransaction{ - ingest.LedgerTransaction{ + { Index: 1, UnsafeMeta: hardCodedMeta, Envelope: xdr.TransactionEnvelope{ @@ -128,7 +128,7 @@ func makeLedgerTransactionTestInput() (transaction []ingest.LedgerTransaction, h }, }, Operations: []xdr.Operation{ - xdr.Operation{ + { SourceAccount: &testAccount2, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictReceive, @@ -152,7 +152,7 @@ func makeLedgerTransactionTestInput() (transaction []ingest.LedgerTransaction, h }, }, }, - ingest.LedgerTransaction{ + { Index: 1, UnsafeMeta: hardCodedMeta, Envelope: xdr.TransactionEnvelope{ @@ -179,7 +179,7 @@ func makeLedgerTransactionTestInput() (transaction []ingest.LedgerTransaction, h }, }, Operations: []xdr.Operation{ - xdr.Operation{ + { SourceAccount: &testAccount2, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictReceive, @@ -208,7 +208,7 @@ func makeLedgerTransactionTestInput() (transaction []ingest.LedgerTransaction, h Result: xdr.InnerTransactionResultResult{ Code: xdr.TransactionResultCodeTxSuccess, Results: &[]xdr.OperationResult{ - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ CreateAccountResult: &xdr.CreateAccountResult{}, }, @@ -217,14 +217,12 @@ func makeLedgerTransactionTestInput() (transaction []ingest.LedgerTransaction, h }, }, }, - Results: &[]xdr.OperationResult{ - xdr.OperationResult{}, - }, + Results: &[]xdr.OperationResult{{}}, }, }, }, }, - ingest.LedgerTransaction{ + { Index: 1, UnsafeMeta: hardCodedMeta, Envelope: xdr.TransactionEnvelope{ @@ -253,7 +251,7 @@ func makeLedgerTransactionTestInput() (transaction []ingest.LedgerTransaction, h }, }, Operations: []xdr.Operation{ - xdr.Operation{ + { SourceAccount: &testAccount4, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictReceive, @@ -279,19 +277,19 @@ func makeLedgerTransactionTestInput() (transaction []ingest.LedgerTransaction, h }, } historyHeader = []xdr.LedgerHeaderHistoryEntry{ - xdr.LedgerHeaderHistoryEntry{ + { Header: xdr.LedgerHeader{ LedgerSeq: 30521816, ScpValue: xdr.StellarValue{CloseTime: 1594272522}, }, }, - xdr.LedgerHeaderHistoryEntry{ + { Header: xdr.LedgerHeader{ LedgerSeq: 30521817, ScpValue: xdr.StellarValue{CloseTime: 1594272522}, }, }, - xdr.LedgerHeaderHistoryEntry{ + { Header: xdr.LedgerHeader{ LedgerSeq: 30521818, ScpValue: xdr.StellarValue{CloseTime: 1594272522}, diff --git a/internal/transform/liquidity_pool.go b/internal/transform/liquidity_pool.go index 30cbaa24..eacc6be3 100644 --- a/internal/transform/liquidity_pool.go +++ b/internal/transform/liquidity_pool.go @@ -22,17 +22,17 @@ func TransformPool(ledgerChange ingest.Change, header xdr.LedgerHeaderHistoryEnt lp, ok := ledgerEntry.Data.GetLiquidityPool() if !ok { - return PoolOutput{}, fmt.Errorf("Could not extract liquidity pool data from ledger entry; actual type is %s", ledgerEntry.Data.Type) + return PoolOutput{}, fmt.Errorf("could not extract liquidity pool data from ledger entry; actual type is %s", ledgerEntry.Data.Type) } cp, ok := lp.Body.GetConstantProduct() if !ok { - return PoolOutput{}, fmt.Errorf("Could not extract constant product information for liquidity pool %s", xdr.Hash(lp.LiquidityPoolId).HexString()) + return PoolOutput{}, fmt.Errorf("could not extract constant product information for liquidity pool %s", xdr.Hash(lp.LiquidityPoolId).HexString()) } poolType, ok := xdr.LiquidityPoolTypeToString[lp.Body.Type] if !ok { - return PoolOutput{}, fmt.Errorf("Unknown liquidity pool type: %d", lp.Body.Type) + return PoolOutput{}, fmt.Errorf("unknown liquidity pool type: %d", lp.Body.Type) } var assetAType, assetACode, assetAIssuer string @@ -44,6 +44,9 @@ func TransformPool(ledgerChange ingest.Change, header xdr.LedgerHeaderHistoryEnt var assetBType, assetBCode, assetBIssuer string err = cp.Params.AssetB.Extract(&assetBType, &assetBCode, &assetBIssuer) + if err != nil { + return PoolOutput{}, err + } assetBID := FarmHashAsset(assetBCode, assetBIssuer, assetBType) closedAt, err := utils.TimePointToUTCTimeStamp(header.Header.ScpValue.CloseTime) diff --git a/internal/transform/liquidity_pool_test.go b/internal/transform/liquidity_pool_test.go index 8a60f59d..af97587a 100644 --- a/internal/transform/liquidity_pool_test.go +++ b/internal/transform/liquidity_pool_test.go @@ -61,19 +61,6 @@ func TestTransformPool(t *testing.T) { } } -func wrapPoolEntry(poolEntry xdr.LiquidityPoolEntry, lastModified int) ingest.Change { - return ingest.Change{ - Type: xdr.LedgerEntryTypeLiquidityPool, - Pre: &xdr.LedgerEntry{ - LastModifiedLedgerSeq: xdr.Uint32(lastModified), - Data: xdr.LedgerEntryData{ - Type: xdr.LedgerEntryTypeLiquidityPool, - LiquidityPool: &poolEntry, - }, - }, - } -} - func makePoolTestInput() ingest.Change { ledgerEntry := xdr.LedgerEntry{ LastModifiedLedgerSeq: 30705278, diff --git a/internal/transform/offer.go b/internal/transform/offer.go index 21e1c4b4..fd88846b 100644 --- a/internal/transform/offer.go +++ b/internal/transform/offer.go @@ -18,7 +18,7 @@ func TransformOffer(ledgerChange ingest.Change, header xdr.LedgerHeaderHistoryEn offerEntry, offerFound := ledgerEntry.Data.GetOffer() if !offerFound { - return OfferOutput{}, fmt.Errorf("Could not extract offer data from ledger entry; actual type is %s", ledgerEntry.Data.Type) + return OfferOutput{}, fmt.Errorf("could not extract offer data from ledger entry; actual type is %s", ledgerEntry.Data.Type) } outputSellerID, err := offerEntry.SellerId.GetAddress() @@ -28,7 +28,7 @@ func TransformOffer(ledgerChange ingest.Change, header xdr.LedgerHeaderHistoryEn outputOfferID := int64(offerEntry.OfferId) if outputOfferID < 0 { - return OfferOutput{}, fmt.Errorf("OfferID is negative (%d) for offer from account: %s", outputOfferID, outputSellerID) + return OfferOutput{}, fmt.Errorf("offerID is negative (%d) for offer from account: %s", outputOfferID, outputSellerID) } outputSellingAsset, err := transformSingleAsset(offerEntry.Selling) @@ -43,21 +43,21 @@ func TransformOffer(ledgerChange ingest.Change, header xdr.LedgerHeaderHistoryEn outputAmount := offerEntry.Amount if outputAmount < 0 { - return OfferOutput{}, fmt.Errorf("Amount is negative (%d) for offer %d", outputAmount, outputOfferID) + return OfferOutput{}, fmt.Errorf("amount is negative (%d) for offer %d", outputAmount, outputOfferID) } outputPriceN := int32(offerEntry.Price.N) if outputPriceN < 0 { - return OfferOutput{}, fmt.Errorf("Price numerator is negative (%d) for offer %d", outputPriceN, outputOfferID) + return OfferOutput{}, fmt.Errorf("price numerator is negative (%d) for offer %d", outputPriceN, outputOfferID) } outputPriceD := int32(offerEntry.Price.D) if outputPriceD == 0 { - return OfferOutput{}, fmt.Errorf("Price denominator is 0 for offer %d", outputOfferID) + return OfferOutput{}, fmt.Errorf("price denominator is 0 for offer %d", outputOfferID) } if outputPriceD < 0 { - return OfferOutput{}, fmt.Errorf("Price denominator is negative (%d) for offer %d", outputPriceD, outputOfferID) + return OfferOutput{}, fmt.Errorf("price denominator is negative (%d) for offer %d", outputPriceD, outputOfferID) } var outputPrice float64 diff --git a/internal/transform/offer_normalized.go b/internal/transform/offer_normalized.go index 83eced04..0276509e 100644 --- a/internal/transform/offer_normalized.go +++ b/internal/transform/offer_normalized.go @@ -25,7 +25,7 @@ func TransformOfferNormalized(ledgerChange ingest.Change, ledgerSeq uint32) (Nor return NormalizedOfferOutput{}, fmt.Errorf("offer %d is deleted", transformed.OfferID) } - buyingAsset, sellingAsset, err := extractAssets(ledgerChange, transformed) + buyingAsset, sellingAsset, err := extractAssets(ledgerChange) if err != nil { return NormalizedOfferOutput{}, err } @@ -57,7 +57,7 @@ func TransformOfferNormalized(ledgerChange ingest.Change, ledgerSeq uint32) (Nor } // extractAssets extracts the buying and selling assets as strings of the format code:issuer -func extractAssets(ledgerChange ingest.Change, transformed OfferOutput) (string, string, error) { +func extractAssets(ledgerChange ingest.Change) (string, string, error) { ledgerEntry, _, _, err := utils.ExtractEntryFromChange(ledgerChange) if err != nil { return "", "", err @@ -65,7 +65,7 @@ func extractAssets(ledgerChange ingest.Change, transformed OfferOutput) (string, offerEntry, offerFound := ledgerEntry.Data.GetOffer() if !offerFound { - return "", "", fmt.Errorf("Could not extract offer data from ledger entry; actual type is %s", ledgerEntry.Data.Type) + return "", "", fmt.Errorf("could not extract offer data from ledger entry; actual type is %s", ledgerEntry.Data.Type) } var sellType, sellCode, sellIssuer string diff --git a/internal/transform/offer_test.go b/internal/transform/offer_test.go index 303693eb..8279d620 100644 --- a/internal/transform/offer_test.go +++ b/internal/transform/offer_test.go @@ -37,7 +37,7 @@ func TestTransformOffer(t *testing.T) { }, }, }, - OfferOutput{}, fmt.Errorf("Could not extract offer data from ledger entry; actual type is LedgerEntryTypeAccount"), + OfferOutput{}, fmt.Errorf("could not extract offer data from ledger entry; actual type is LedgerEntryTypeAccount"), }, { inputStruct{wrapOfferEntry(xdr.OfferEntry{ @@ -45,7 +45,7 @@ func TestTransformOffer(t *testing.T) { OfferId: -1, }, 0), }, - OfferOutput{}, fmt.Errorf("OfferID is negative (-1) for offer from account: %s", genericAccountAddress), + OfferOutput{}, fmt.Errorf("offerID is negative (-1) for offer from account: %s", genericAccountAddress), }, { inputStruct{wrapOfferEntry(xdr.OfferEntry{ @@ -53,7 +53,7 @@ func TestTransformOffer(t *testing.T) { Amount: -2, }, 0), }, - OfferOutput{}, fmt.Errorf("Amount is negative (-2) for offer 0"), + OfferOutput{}, fmt.Errorf("amount is negative (-2) for offer 0"), }, { inputStruct{wrapOfferEntry(xdr.OfferEntry{ @@ -64,7 +64,7 @@ func TestTransformOffer(t *testing.T) { }, }, 0), }, - OfferOutput{}, fmt.Errorf("Price numerator is negative (-3) for offer 0"), + OfferOutput{}, fmt.Errorf("price numerator is negative (-3) for offer 0"), }, { inputStruct{wrapOfferEntry(xdr.OfferEntry{ @@ -75,7 +75,7 @@ func TestTransformOffer(t *testing.T) { }, }, 0), }, - OfferOutput{}, fmt.Errorf("Price denominator is negative (-4) for offer 0"), + OfferOutput{}, fmt.Errorf("price denominator is negative (-4) for offer 0"), }, { inputStruct{wrapOfferEntry(xdr.OfferEntry{ @@ -86,7 +86,7 @@ func TestTransformOffer(t *testing.T) { }, }, 0), }, - OfferOutput{}, fmt.Errorf("Price denominator is 0 for offer 0"), + OfferOutput{}, fmt.Errorf("price denominator is 0 for offer 0"), }, { inputStruct{ diff --git a/internal/transform/operation.go b/internal/transform/operation.go index b8badaba..b3a79def 100644 --- a/internal/transform/operation.go +++ b/internal/transform/operation.go @@ -156,7 +156,7 @@ func mapOperationType(operation xdr.Operation) (string, error) { case xdr.OperationTypeRestoreFootprint: op_string_type = "restore_footprint" default: - return op_string_type, fmt.Errorf("Unknown operation type: %s", operation.Body.Type.String()) + return op_string_type, fmt.Errorf("unknown operation type: %s", operation.Body.Type.String()) } return op_string_type, nil } @@ -221,7 +221,7 @@ func mapOperationTrace(operationTrace xdr.OperationResultTr) (string, error) { case xdr.OperationTypeRestoreFootprint: operationTraceDescription = operationTrace.RestoreFootprintResult.Code.String() default: - return operationTraceDescription, fmt.Errorf("Unknown operation type: %s", operationTrace.Type.String()) + return operationTraceDescription, fmt.Errorf("unknown operation type: %s", operationTrace.Type.String()) } return operationTraceDescription, nil } @@ -277,7 +277,7 @@ func getLiquidityPoolAndProductDelta(operationIndex int32, transaction ingest.Le return lp, delta, nil } - return nil, nil, fmt.Errorf("Liquidity pool change not found") + return nil, nil, fmt.Errorf("liquidity pool change not found") } func getOperationSourceAccount(operation xdr.Operation, transaction ingest.LedgerTransaction) xdr.MuxedAccount { @@ -564,7 +564,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypeCreateAccount: op, ok := operation.Body.GetCreateAccountOp() if !ok { - return details, fmt.Errorf("Could not access CreateAccount info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access CreateAccount info for this operation (index %d)", operationIndex) } if err := addAccountAndMuxedAccountDetails(details, sourceAccount, "funder"); err != nil { @@ -576,7 +576,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypePayment: op, ok := operation.Body.GetPaymentOp() if !ok { - return details, fmt.Errorf("Could not access Payment info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access Payment info for this operation (index %d)", operationIndex) } if err := addAccountAndMuxedAccountDetails(details, sourceAccount, "from"); err != nil { @@ -593,7 +593,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypePathPaymentStrictReceive: op, ok := operation.Body.GetPathPaymentStrictReceiveOp() if !ok { - return details, fmt.Errorf("Could not access PathPaymentStrictReceive info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access PathPaymentStrictReceive info for this operation (index %d)", operationIndex) } if err := addAccountAndMuxedAccountDetails(details, sourceAccount, "from"); err != nil { @@ -615,16 +615,16 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT if transaction.Result.Successful() { allOperationResults, ok := transaction.Result.OperationResults() if !ok { - return details, fmt.Errorf("Could not access any results for this transaction") + return details, fmt.Errorf("could not access any results for this transaction") } currentOperationResult := allOperationResults[operationIndex] resultBody, ok := currentOperationResult.GetTr() if !ok { - return details, fmt.Errorf("Could not access result body for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access result body for this operation (index %d)", operationIndex) } result, ok := resultBody.GetPathPaymentStrictReceiveResult() if !ok { - return details, fmt.Errorf("Could not access PathPaymentStrictReceive result info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access PathPaymentStrictReceive result info for this operation (index %d)", operationIndex) } details["source_amount"] = utils.ConvertStroopValueToReal(result.SendAmount()) } @@ -634,7 +634,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypePathPaymentStrictSend: op, ok := operation.Body.GetPathPaymentStrictSendOp() if !ok { - return details, fmt.Errorf("Could not access PathPaymentStrictSend info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access PathPaymentStrictSend info for this operation (index %d)", operationIndex) } if err := addAccountAndMuxedAccountDetails(details, sourceAccount, "from"); err != nil { @@ -656,16 +656,16 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT if transaction.Result.Successful() { allOperationResults, ok := transaction.Result.OperationResults() if !ok { - return details, fmt.Errorf("Could not access any results for this transaction") + return details, fmt.Errorf("could not access any results for this transaction") } currentOperationResult := allOperationResults[operationIndex] resultBody, ok := currentOperationResult.GetTr() if !ok { - return details, fmt.Errorf("Could not access result body for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access result body for this operation (index %d)", operationIndex) } result, ok := resultBody.GetPathPaymentStrictSendResult() if !ok { - return details, fmt.Errorf("Could not access GetPathPaymentStrictSendResult result info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access GetPathPaymentStrictSendResult result info for this operation (index %d)", operationIndex) } details["amount"] = utils.ConvertStroopValueToReal(result.DestAmount()) } @@ -675,7 +675,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypeManageBuyOffer: op, ok := operation.Body.GetManageBuyOfferOp() if !ok { - return details, fmt.Errorf("Could not access ManageBuyOffer info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access ManageBuyOffer info for this operation (index %d)", operationIndex) } details["offer_id"] = int64(op.OfferId) @@ -694,7 +694,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypeManageSellOffer: op, ok := operation.Body.GetManageSellOfferOp() if !ok { - return details, fmt.Errorf("Could not access ManageSellOffer info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access ManageSellOffer info for this operation (index %d)", operationIndex) } details["offer_id"] = int64(op.OfferId) @@ -713,7 +713,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypeCreatePassiveSellOffer: op, ok := operation.Body.GetCreatePassiveSellOfferOp() if !ok { - return details, fmt.Errorf("Could not access CreatePassiveSellOffer info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access CreatePassiveSellOffer info for this operation (index %d)", operationIndex) } details["amount"] = utils.ConvertStroopValueToReal(op.Amount) @@ -731,7 +731,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypeSetOptions: op, ok := operation.Body.GetSetOptionsOp() if !ok { - return details, fmt.Errorf("Could not access GetSetOptions info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access GetSetOptions info for this operation (index %d)", operationIndex) } if op.InflationDest != nil { @@ -774,7 +774,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypeChangeTrust: op, ok := operation.Body.GetChangeTrustOp() if !ok { - return details, fmt.Errorf("Could not access GetChangeTrust info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access GetChangeTrust info for this operation (index %d)", operationIndex) } if op.Line.Type == xdr.AssetTypeAssetTypePoolShare { @@ -796,7 +796,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypeAllowTrust: op, ok := operation.Body.GetAllowTrustOp() if !ok { - return details, fmt.Errorf("Could not access AllowTrust info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access AllowTrust info for this operation (index %d)", operationIndex) } if err := addAssetDetailsToOperationDetails(details, op.Asset.ToAsset(sourceAccount.ToAccountId()), ""); err != nil { @@ -820,7 +820,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypeAccountMerge: destinationAccount, ok := operation.Body.GetDestination() if !ok { - return details, fmt.Errorf("Could not access Destination info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access Destination info for this operation (index %d)", operationIndex) } if err := addAccountAndMuxedAccountDetails(details, sourceAccount, "account"); err != nil { @@ -835,7 +835,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypeManageData: op, ok := operation.Body.GetManageDataOp() if !ok { - return details, fmt.Errorf("Could not access GetManageData info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access GetManageData info for this operation (index %d)", operationIndex) } details["name"] = string(op.DataName) @@ -848,7 +848,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT case xdr.OperationTypeBumpSequence: op, ok := operation.Body.GetBumpSequenceOp() if !ok { - return details, fmt.Errorf("Could not access BumpSequence info for this operation (index %d)", operationIndex) + return details, fmt.Errorf("could not access BumpSequence info for this operation (index %d)", operationIndex) } details["bump_to"] = fmt.Sprintf("%d", op.BumpTo) @@ -862,7 +862,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT op := operation.Body.MustClaimClaimableBalanceOp() balanceID, err := xdr.MarshalHex(op.BalanceId) if err != nil { - return details, fmt.Errorf("Invalid balanceId in op: %d", operationIndex) + return details, fmt.Errorf("invalid balanceId in op: %d", operationIndex) } details["balance_id"] = balanceID if err := addAccountAndMuxedAccountDetails(details, sourceAccount, "claimant"); err != nil { @@ -908,7 +908,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT op := operation.Body.MustClawbackClaimableBalanceOp() balanceID, err := xdr.MarshalHex(op.BalanceId) if err != nil { - return details, fmt.Errorf("Invalid balanceId in op: %d", operationIndex) + return details, fmt.Errorf("invalid balanceId in op: %d", operationIndex) } details["balance_id"] = balanceID @@ -1113,7 +1113,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope) details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) default: - return details, fmt.Errorf("Unknown operation type: %s", operation.Body.Type.String()) + return details, fmt.Errorf("unknown operation type: %s", operation.Body.Type.String()) } sponsor, err := getSponsor(operation, transaction, operationIndex) @@ -1506,7 +1506,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{}, op := operation.operation.Body.MustClaimClaimableBalanceOp() balanceID, err := xdr.MarshalHex(op.BalanceId) if err != nil { - panic(fmt.Errorf("Invalid balanceId in op: %d", operation.index)) + panic(fmt.Errorf("invalid balanceId in op: %d", operation.index)) } details["balance_id"] = balanceID addAccountAndMuxedAccountDetails(details, *source, "claimant") @@ -1539,7 +1539,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{}, op := operation.operation.Body.MustClawbackClaimableBalanceOp() balanceID, err := xdr.MarshalHex(op.BalanceId) if err != nil { - panic(fmt.Errorf("Invalid balanceId in op: %d", operation.index)) + panic(fmt.Errorf("invalid balanceId in op: %d", operation.index)) } details["balance_id"] = balanceID case xdr.OperationTypeSetTrustLineFlags: @@ -1716,7 +1716,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{}, details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope) details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) default: - panic(fmt.Errorf("Unknown operation type: %s", operation.OperationType())) + panic(fmt.Errorf("unknown operation type: %s", operation.OperationType())) } sponsor, err := operation.getSponsor() @@ -2135,7 +2135,7 @@ func (operation *transactionOperationWrapper) Participants() ([]xdr.AccountId, e case xdr.OperationTypeRestoreFootprint: // the only direct participant is the source_account default: - return participants, fmt.Errorf("Unknown operation type: %s", op.Body.Type) + return participants, fmt.Errorf("unknown operation type: %s", op.Body.Type) } sponsor, err := operation.getSponsor() @@ -2161,25 +2161,3 @@ func dedupeParticipants(in []xdr.AccountId) (out []xdr.AccountId) { } return } - -// OperationsParticipants returns a map with all participants per operation -func operationsParticipants(transaction ingest.LedgerTransaction, sequence uint32) (map[int64][]xdr.AccountId, error) { - participants := map[int64][]xdr.AccountId{} - - for opi, op := range transaction.Envelope.Operations() { - operation := transactionOperationWrapper{ - index: uint32(opi), - transaction: transaction, - operation: op, - ledgerSequence: sequence, - } - - p, err := operation.Participants() - if err != nil { - return participants, errors.Wrapf(err, "reading operation %v participants", operation.ID()) - } - participants[operation.ID()] = p - } - - return participants, nil -} diff --git a/internal/transform/operation_test.go b/internal/transform/operation_test.go index de6ff439..97959107 100644 --- a/internal/transform/operation_test.go +++ b/internal/transform/operation_test.go @@ -50,7 +50,7 @@ func TestTransformOperation(t *testing.T) { { unknownOpTypeInput, OperationOutput{}, - fmt.Errorf("Unknown operation type: "), + fmt.Errorf("unknown operation type: "), }, } hardCodedInputTransaction, err := makeOperationTestInput() @@ -129,7 +129,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er hardCodedDataValue := xdr.DataValue([]byte{0x76, 0x61, 0x6c, 0x75, 0x65}) hardCodedSequenceNumber := xdr.SequenceNumber(100) inputOperations := []xdr.Operation{ - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeCreateAccount, @@ -139,7 +139,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypePayment, @@ -150,7 +150,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypePayment, @@ -161,7 +161,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: &testAccount3, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictReceive, @@ -175,7 +175,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeManageSellOffer, @@ -191,7 +191,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeCreatePassiveSellOffer, @@ -206,7 +206,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeSetOptions, @@ -223,7 +223,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeChangeTrust, @@ -233,7 +233,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeChangeTrust, @@ -243,7 +243,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeAllowTrust, @@ -254,20 +254,20 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeAccountMerge, Destination: &testAccount4, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeInflation, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeManageData, @@ -277,7 +277,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeBumpSequence, @@ -286,7 +286,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeManageBuyOffer, @@ -302,7 +302,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictSend, @@ -316,7 +316,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeCreateClaimableBalance, @@ -327,7 +327,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: &testAccount3, Body: xdr.OperationBody{ Type: xdr.OperationTypeClaimClaimableBalance, @@ -336,7 +336,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeBeginSponsoringFutureReserves, @@ -345,7 +345,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeRevokeSponsorship, @@ -358,7 +358,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeRevokeSponsorship, @@ -373,7 +373,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeRevokeSponsorship, @@ -388,7 +388,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeRevokeSponsorship, @@ -404,7 +404,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeRevokeSponsorship, @@ -420,7 +420,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeRevokeSponsorship, @@ -436,7 +436,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeRevokeSponsorship, @@ -451,7 +451,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeClawback, @@ -462,7 +462,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeClawbackClaimableBalance, @@ -471,7 +471,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeSetTrustLineFlags, @@ -483,7 +483,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeLiquidityPoolDeposit, @@ -502,7 +502,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeLiquidityPoolWithdraw, @@ -514,7 +514,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - //xdr.Operation{ + //{ // SourceAccount: nil, // Body: xdr.OperationBody{ // Type: xdr.OperationTypeInvokeHostFunction, @@ -533,7 +533,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er // }, // }, //}, - //xdr.Operation{ + //{ // SourceAccount: nil, // Body: xdr.OperationBody{ // Type: xdr.OperationTypeInvokeHostFunction, @@ -557,7 +557,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er // }, // }, //}, - //xdr.Operation{ + //{ // SourceAccount: nil, // Body: xdr.OperationBody{ // Type: xdr.OperationTypeInvokeHostFunction, @@ -584,7 +584,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er // }, // }, //}, - //xdr.Operation{ + //{ // SourceAccount: nil, // Body: xdr.OperationBody{ // Type: xdr.OperationTypeInvokeHostFunction, @@ -596,7 +596,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er // }, // }, //}, - //xdr.Operation{ + //{ // SourceAccount: nil, // Body: xdr.OperationBody{ // Type: xdr.OperationTypeBumpFootprintExpiration, @@ -608,7 +608,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er // }, // }, //}, - //xdr.Operation{ + //{ // SourceAccount: nil, // Body: xdr.OperationBody{ // Type: xdr.OperationTypeRestoreFootprint, @@ -622,7 +622,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er } inputEnvelope.Tx.Operations = inputOperations results := []xdr.OperationResult{ - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeCreateAccount, @@ -631,7 +631,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypePayment, @@ -640,7 +640,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypePayment, @@ -650,7 +650,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, // There needs to be a true result for path payment receive and send - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypePathPaymentStrictReceive, @@ -662,7 +662,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeManageSellOffer, @@ -671,7 +671,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeManageSellOffer, @@ -680,7 +680,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeSetOptions, @@ -689,7 +689,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeChangeTrust, @@ -698,7 +698,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeChangeTrust, @@ -707,7 +707,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeAllowTrust, @@ -716,7 +716,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeAccountMerge, @@ -725,7 +725,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeInflation, @@ -734,7 +734,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeManageData, @@ -743,7 +743,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeBumpSequence, @@ -752,7 +752,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeManageBuyOffer, @@ -761,7 +761,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypePathPaymentStrictSend, @@ -773,7 +773,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeCreateClaimableBalance, @@ -782,7 +782,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeClaimClaimableBalance, @@ -791,7 +791,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeBeginSponsoringFutureReserves, @@ -800,7 +800,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeRevokeSponsorship, @@ -809,7 +809,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeRevokeSponsorship, @@ -818,7 +818,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeRevokeSponsorship, @@ -827,7 +827,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeRevokeSponsorship, @@ -836,7 +836,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeRevokeSponsorship, @@ -845,7 +845,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeRevokeSponsorship, @@ -854,7 +854,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeRevokeSponsorship, @@ -863,7 +863,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeClawback, @@ -872,7 +872,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeClawbackClaimableBalance, @@ -881,7 +881,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeSetTrustLineFlags, @@ -890,7 +890,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeLiquidityPoolDeposit, @@ -899,7 +899,7 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeLiquidityPoolWithdraw, @@ -908,12 +908,12 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - //xdr.OperationResult{}, - //xdr.OperationResult{}, - //xdr.OperationResult{}, - //xdr.OperationResult{}, - //xdr.OperationResult{}, - //xdr.OperationResult{}, + //{}, + //{}, + //{}, + //{}, + //{}, + //{}, } inputTransaction.Result.Result.Result.Results = &results inputTransaction.Envelope.V1 = &inputEnvelope @@ -925,7 +925,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { hardCodedDestAccountAddress := testAccount4Address hardCodedLedgerClose := genericCloseTime.UTC() transformedOperations = []OperationOutput{ - OperationOutput{ + { SourceAccount: hardCodedSourceAccountAddress, Type: 0, TypeString: "create_account", @@ -940,7 +940,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "CreateAccountResultCodeCreateAccountSuccess", }, - OperationOutput{ + { Type: 1, TypeString: "payment", SourceAccount: hardCodedSourceAccountAddress, @@ -959,7 +959,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "PaymentResultCodePaymentSuccess", }, - OperationOutput{ + { Type: 1, TypeString: "payment", SourceAccount: hardCodedSourceAccountAddress, @@ -976,7 +976,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "PaymentResultCodePaymentSuccess", }, - OperationOutput{ + { Type: 2, TypeString: "path_payment_strict_receive", SourceAccount: hardCodedSourceAccountAddress, @@ -998,7 +998,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "PathPaymentStrictReceiveResultCodePathPaymentStrictReceiveSuccess", }, - OperationOutput{ + { Type: 3, TypeString: "manage_sell_offer", SourceAccount: hardCodedSourceAccountAddress, @@ -1023,7 +1023,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "ManageSellOfferResultCodeManageSellOfferSuccess", }, - OperationOutput{ + { Type: 4, TypeString: "create_passive_sell_offer", SourceAccount: hardCodedSourceAccountAddress, @@ -1047,7 +1047,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "ManageSellOfferResultCodeManageSellOfferSuccess", }, - OperationOutput{ + { Type: 5, TypeString: "set_options", SourceAccount: hardCodedSourceAccountAddress, @@ -1071,7 +1071,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "SetOptionsResultCodeSetOptionsSuccess", }, - OperationOutput{ + { Type: 6, TypeString: "change_trust", SourceAccount: hardCodedSourceAccountAddress, @@ -1090,7 +1090,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "ChangeTrustResultCodeChangeTrustSuccess", }, - OperationOutput{ + { Type: 6, TypeString: "change_trust", SourceAccount: hardCodedSourceAccountAddress, @@ -1106,7 +1106,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "ChangeTrustResultCodeChangeTrustSuccess", }, - OperationOutput{ + { Type: 7, TypeString: "allow_trust", SourceAccount: hardCodedSourceAccountAddress, @@ -1125,7 +1125,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "AllowTrustResultCodeAllowTrustSuccess", }, - OperationOutput{ + { Type: 8, TypeString: "account_merge", SourceAccount: hardCodedSourceAccountAddress, @@ -1139,7 +1139,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "AccountMergeResultCodeAccountMergeSuccess", }, - OperationOutput{ + { Type: 9, TypeString: "inflation", SourceAccount: hardCodedSourceAccountAddress, @@ -1150,7 +1150,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "InflationResultCodeInflationSuccess", }, - OperationOutput{ + { Type: 10, TypeString: "manage_data", SourceAccount: hardCodedSourceAccountAddress, @@ -1164,7 +1164,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "ManageDataResultCodeManageDataSuccess", }, - OperationOutput{ + { Type: 11, TypeString: "bump_sequence", SourceAccount: hardCodedSourceAccountAddress, @@ -1177,7 +1177,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "BumpSequenceResultCodeBumpSequenceSuccess", }, - OperationOutput{ + { Type: 12, TypeString: "manage_buy_offer", SourceAccount: hardCodedSourceAccountAddress, @@ -1202,7 +1202,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "ManageBuyOfferResultCodeManageBuyOfferSuccess", }, - OperationOutput{ + { Type: 13, TypeString: "path_payment_strict_send", SourceAccount: hardCodedSourceAccountAddress, @@ -1224,7 +1224,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "PathPaymentStrictSendResultCodePathPaymentStrictSendSuccess", }, - OperationOutput{ + { Type: 14, TypeString: "create_claimable_balance", SourceAccount: hardCodedSourceAccountAddress, @@ -1239,7 +1239,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "CreateClaimableBalanceResultCodeCreateClaimableBalanceSuccess", }, - OperationOutput{ + { Type: 15, TypeString: "claim_claimable_balance", SourceAccount: testAccount3Address, @@ -1253,7 +1253,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "ClaimClaimableBalanceResultCodeClaimClaimableBalanceSuccess", }, - OperationOutput{ + { Type: 16, TypeString: "begin_sponsoring_future_reserves", SourceAccount: hardCodedSourceAccountAddress, @@ -1266,7 +1266,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "BeginSponsoringFutureReservesResultCodeBeginSponsoringFutureReservesSuccess", }, - OperationOutput{ + { Type: 18, TypeString: "revoke_sponsorship", SourceAccount: hardCodedSourceAccountAddress, @@ -1280,7 +1280,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, - OperationOutput{ + { Type: 18, TypeString: "revoke_sponsorship", SourceAccount: hardCodedSourceAccountAddress, @@ -1293,7 +1293,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, - OperationOutput{ + { Type: 18, TypeString: "revoke_sponsorship", SourceAccount: hardCodedSourceAccountAddress, @@ -1306,7 +1306,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, - OperationOutput{ + { Type: 18, TypeString: "revoke_sponsorship", SourceAccount: hardCodedSourceAccountAddress, @@ -1320,7 +1320,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, - OperationOutput{ + { Type: 18, TypeString: "revoke_sponsorship", SourceAccount: hardCodedSourceAccountAddress, @@ -1333,7 +1333,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, - OperationOutput{ + { Type: 18, TypeString: "revoke_sponsorship", SourceAccount: hardCodedSourceAccountAddress, @@ -1347,7 +1347,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, - OperationOutput{ + { Type: 18, TypeString: "revoke_sponsorship", SourceAccount: hardCodedSourceAccountAddress, @@ -1360,7 +1360,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, - OperationOutput{ + { Type: 19, TypeString: "clawback", SourceAccount: hardCodedSourceAccountAddress, @@ -1378,7 +1378,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "ClawbackResultCodeClawbackSuccess", }, - OperationOutput{ + { Type: 20, TypeString: "clawback_claimable_balance", SourceAccount: hardCodedSourceAccountAddress, @@ -1391,7 +1391,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "ClawbackClaimableBalanceResultCodeClawbackClaimableBalanceSuccess", }, - OperationOutput{ + { Type: 21, TypeString: "set_trust_line_flags", SourceAccount: hardCodedSourceAccountAddress, @@ -1412,7 +1412,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "SetTrustLineFlagsResultCodeSetTrustLineFlagsSuccess", }, - OperationOutput{ + { Type: 22, TypeString: "liquidity_pool_deposit", SourceAccount: hardCodedSourceAccountAddress, @@ -1446,7 +1446,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationResultCode: "OperationResultCodeOpInner", OperationTraceCode: "LiquidityPoolDepositResultCodeLiquidityPoolDepositSuccess", }, - OperationOutput{ + { Type: 23, TypeString: "liquidity_pool_withdraw", SourceAccount: hardCodedSourceAccountAddress, diff --git a/internal/transform/schema.go b/internal/transform/schema.go index f3f64aee..5f78dba3 100644 --- a/internal/transform/schema.go +++ b/internal/transform/schema.go @@ -28,46 +28,50 @@ type LedgerOutput struct { MaxTxSetSize uint32 `json:"max_tx_set_size"` ProtocolVersion uint32 `json:"protocol_version"` LedgerID int64 `json:"id"` + SorobanFeeWrite1Kb int64 `json:"soroban_fee_write_1kb"` } // TransactionOutput is a representation of a transaction that aligns with the BigQuery table history_transactions type TransactionOutput struct { - TransactionHash string `json:"transaction_hash"` - LedgerSequence uint32 `json:"ledger_sequence"` - Account string `json:"account"` - AccountMuxed string `json:"account_muxed,omitempty"` - AccountSequence int64 `json:"account_sequence"` - MaxFee uint32 `json:"max_fee"` - FeeCharged int64 `json:"fee_charged"` - OperationCount int32 `json:"operation_count"` - TxEnvelope string `json:"tx_envelope"` - TxResult string `json:"tx_result"` - TxMeta string `json:"tx_meta"` - TxFeeMeta string `json:"tx_fee_meta"` - CreatedAt time.Time `json:"created_at"` - MemoType string `json:"memo_type"` - Memo string `json:"memo"` - TimeBounds string `json:"time_bounds"` - Successful bool `json:"successful"` - TransactionID int64 `json:"id"` - FeeAccount string `json:"fee_account,omitempty"` - FeeAccountMuxed string `json:"fee_account_muxed,omitempty"` - InnerTransactionHash string `json:"inner_transaction_hash,omitempty"` - NewMaxFee uint32 `json:"new_max_fee,omitempty"` - LedgerBounds string `json:"ledger_bounds"` - MinAccountSequence null.Int `json:"min_account_sequence"` - MinAccountSequenceAge null.Int `json:"min_account_sequence_age"` - MinAccountSequenceLedgerGap null.Int `json:"min_account_sequence_ledger_gap"` - ExtraSigners pq.StringArray `json:"extra_signers"` - ClosedAt time.Time `json:"closed_at"` - ResourceFee int64 `json:"resource_fee"` - SorobanResourcesInstructions uint32 `json:"soroban_resources_instructions"` - SorobanResourcesReadBytes uint32 `json:"soroban_resources_read_bytes"` - SorobanResourcesWriteBytes uint32 `json:"soroban_resources_write_bytes"` - TransactionResultCode string `json:"transaction_result_code"` - InclusionFeeBid int64 `json:"inclusion_fee_bid"` - InclusionFeeCharged int64 `json:"inclusion_fee_charged"` - ResourceFeeRefund int64 `json:"resource_fee_refund"` + TransactionHash string `json:"transaction_hash"` + LedgerSequence uint32 `json:"ledger_sequence"` + Account string `json:"account"` + AccountMuxed string `json:"account_muxed,omitempty"` + AccountSequence int64 `json:"account_sequence"` + MaxFee uint32 `json:"max_fee"` + FeeCharged int64 `json:"fee_charged"` + OperationCount int32 `json:"operation_count"` + TxEnvelope string `json:"tx_envelope"` + TxResult string `json:"tx_result"` + TxMeta string `json:"tx_meta"` + TxFeeMeta string `json:"tx_fee_meta"` + CreatedAt time.Time `json:"created_at"` + MemoType string `json:"memo_type"` + Memo string `json:"memo"` + TimeBounds string `json:"time_bounds"` + Successful bool `json:"successful"` + TransactionID int64 `json:"id"` + FeeAccount string `json:"fee_account,omitempty"` + FeeAccountMuxed string `json:"fee_account_muxed,omitempty"` + InnerTransactionHash string `json:"inner_transaction_hash,omitempty"` + NewMaxFee uint32 `json:"new_max_fee,omitempty"` + LedgerBounds string `json:"ledger_bounds"` + MinAccountSequence null.Int `json:"min_account_sequence"` + MinAccountSequenceAge null.Int `json:"min_account_sequence_age"` + MinAccountSequenceLedgerGap null.Int `json:"min_account_sequence_ledger_gap"` + ExtraSigners pq.StringArray `json:"extra_signers"` + ClosedAt time.Time `json:"closed_at"` + ResourceFee int64 `json:"resource_fee"` + SorobanResourcesInstructions uint32 `json:"soroban_resources_instructions"` + SorobanResourcesReadBytes uint32 `json:"soroban_resources_read_bytes"` + SorobanResourcesWriteBytes uint32 `json:"soroban_resources_write_bytes"` + TransactionResultCode string `json:"transaction_result_code"` + InclusionFeeBid int64 `json:"inclusion_fee_bid"` + InclusionFeeCharged int64 `json:"inclusion_fee_charged"` + ResourceFeeRefund int64 `json:"resource_fee_refund"` + TotalNonRefundableResourceFeeCharged int64 `json:"non_refundable_resource_fee_charged"` + TotalRefundableResourceFeeCharged int64 `json:"refundable_resource_fee_charged"` + RentFeeCharged int64 `json:"rent_fee_charged"` } type LedgerTransactionOutput struct { diff --git a/internal/transform/test_variables_test.go b/internal/transform/test_variables_test.go index 9621723b..e007aa19 100644 --- a/internal/transform/test_variables_test.go +++ b/internal/transform/test_variables_test.go @@ -95,64 +95,6 @@ var testAccount4Address = "GBVVRXLMNCJQW3IDDXC3X6XCH35B5Q7QXNMMFPENSOGUPQO7WO7HG var testAccount4ID, _ = xdr.AddressToAccountId(testAccount4Address) var testAccount4 = testAccount4ID.ToMuxedAccount() -// a selection of hardcoded Liquidity Pools -var lpDepositChanges = []xdr.OperationMeta{ - { - Changes: xdr.LedgerEntryChanges{ - xdr.LedgerEntryChange{ - Type: xdr.LedgerEntryChangeTypeLedgerEntryState, - State: &xdr.LedgerEntry{ - Data: xdr.LedgerEntryData{ - Type: xdr.LedgerEntryTypeLiquidityPool, - LiquidityPool: &xdr.LiquidityPoolEntry{ - LiquidityPoolId: xdr.PoolId{1, 2, 3, 4, 5, 6, 7, 8, 9}, - Body: xdr.LiquidityPoolEntryBody{ - Type: xdr.LiquidityPoolTypeLiquidityPoolConstantProduct, - ConstantProduct: &xdr.LiquidityPoolEntryConstantProduct{ - Params: xdr.LiquidityPoolConstantProductParameters{ - AssetA: lpAssetA, - AssetB: lpAssetB, - Fee: 30, - }, - ReserveA: 100000, - ReserveB: 1000, - TotalPoolShares: 500, - PoolSharesTrustLineCount: 25, - }, - }, - }, - }, - }, - }, - xdr.LedgerEntryChange{ - Type: xdr.LedgerEntryChangeTypeLedgerEntryUpdated, - Updated: &xdr.LedgerEntry{ - Data: xdr.LedgerEntryData{ - Type: xdr.LedgerEntryTypeLiquidityPool, - LiquidityPool: &xdr.LiquidityPoolEntry{ - LiquidityPoolId: xdr.PoolId{1, 2, 3, 4, 5, 6, 7, 8, 9}, - Body: xdr.LiquidityPoolEntryBody{ - Type: xdr.LiquidityPoolTypeLiquidityPoolConstantProduct, - ConstantProduct: &xdr.LiquidityPoolEntryConstantProduct{ - Params: xdr.LiquidityPoolConstantProductParameters{ - AssetA: lpAssetA, - AssetB: lpAssetB, - Fee: 30, - }, - ReserveA: 101000, - ReserveB: 1100, - TotalPoolShares: 502, - PoolSharesTrustLineCount: 26, - }, - }, - }, - }, - }, - }, - }, - }, -} - // a selection of hardcoded assets and their AssetOutput representations var usdtAsset = xdr.Asset{ @@ -225,23 +167,12 @@ var ethTrustLineAsset = xdr.TrustLineAsset{ }, } -var ethAssetPath = Path{ - AssetType: "credit_alphanum4", - AssetCode: "ETH", - AssetIssuer: testAccount1Address, -} - var liquidityPoolAsset = xdr.TrustLineAsset{ Type: xdr.AssetTypeAssetTypePoolShare, LiquidityPoolId: &xdr.PoolId{1, 3, 4, 5, 7, 9}, } var nativeAsset = xdr.MustNewNativeAsset() -var nativeAssetPath = Path{ - AssetType: "native", -} - -var nativeTrustLineAsset = xdr.MustNewNativeAsset().ToTrustLineAsset() var genericClaimableBalance = xdr.ClaimableBalanceId{ Type: xdr.ClaimableBalanceIdTypeClaimableBalanceIdTypeV0, diff --git a/internal/transform/trade.go b/internal/transform/trade.go index 27dfc0da..06ac05f0 100644 --- a/internal/transform/trade.go +++ b/internal/transform/trade.go @@ -20,11 +20,11 @@ import ( func TransformTrade(operationIndex int32, operationID int64, transaction ingest.LedgerTransaction, ledgerCloseTime time.Time) ([]TradeOutput, error) { operationResults, ok := transaction.Result.OperationResults() if !ok { - return []TradeOutput{}, fmt.Errorf("Could not get any results from this transaction") + return []TradeOutput{}, fmt.Errorf("could not get any results from this transaction") } if !transaction.Result.Successful() { - return []TradeOutput{}, fmt.Errorf("Transaction failed; no trades") + return []TradeOutput{}, fmt.Errorf("transaction failed; no trades") } operation := transaction.Envelope.Operations()[operationIndex] @@ -50,7 +50,7 @@ func TransformTrade(operationIndex int32, operationID int64, transaction ingest. outputSellingAmount := claimOffer.AmountSold() if outputSellingAmount < 0 { - return []TradeOutput{}, fmt.Errorf("Amount sold is negative (%d) for operation at index %d", outputSellingAmount, operationIndex) + return []TradeOutput{}, fmt.Errorf("amount sold is negative (%d) for operation at index %d", outputSellingAmount, operationIndex) } var outputBuyingAssetType, outputBuyingAssetCode, outputBuyingAssetIssuer string @@ -62,7 +62,7 @@ func TransformTrade(operationIndex int32, operationID int64, transaction ingest. outputBuyingAmount := int64(claimOffer.AmountBought()) if outputBuyingAmount < 0 { - return []TradeOutput{}, fmt.Errorf("Amount bought is negative (%d) for operation at index %d", outputBuyingAmount, operationIndex) + return []TradeOutput{}, fmt.Errorf("amount bought is negative (%d) for operation at index %d", outputBuyingAmount, operationIndex) } if outputSellingAmount == 0 && outputBuyingAmount == 0 { @@ -87,7 +87,7 @@ func TransformTrade(operationIndex int32, operationID int64, transaction ingest. tradeType = int32(2) var fee uint32 if fee, err = findPoolFee(transaction, operationIndex, id); err != nil { - return []TradeOutput{}, fmt.Errorf("Cannot parse fee for liquidity pool %v", liquidityPoolID) + return []TradeOutput{}, fmt.Errorf("cannot parse fee for liquidity pool %v", liquidityPoolID) } outputPoolFee = null.IntFrom(int64(fee)) @@ -156,25 +156,25 @@ func TransformTrade(operationIndex int32, operationID int64, transaction ingest. func extractClaimedOffers(operationResults []xdr.OperationResult, operationIndex int32, operationType xdr.OperationType) (claimedOffers []xdr.ClaimAtom, BuyingOffer *xdr.OfferEntry, sellerIsExact null.Bool, err error) { if operationIndex >= int32(len(operationResults)) { - err = fmt.Errorf("Operation index of %d is out of bounds in result slice (len = %d)", operationIndex, len(operationResults)) + err = fmt.Errorf("operation index of %d is out of bounds in result slice (len = %d)", operationIndex, len(operationResults)) return } if operationResults[operationIndex].Tr == nil { - err = fmt.Errorf("Could not get result Tr for operation at index %d", operationIndex) + err = fmt.Errorf("could not get result Tr for operation at index %d", operationIndex) return } operationTr, ok := operationResults[operationIndex].GetTr() if !ok { - err = fmt.Errorf("Could not get result Tr for operation at index %d", operationIndex) + err = fmt.Errorf("could not get result Tr for operation at index %d", operationIndex) return } switch operationType { case xdr.OperationTypeManageBuyOffer: var buyOfferResult xdr.ManageBuyOfferResult if buyOfferResult, ok = operationTr.GetManageBuyOfferResult(); !ok { - err = fmt.Errorf("Could not get ManageBuyOfferResult for operation at index %d", operationIndex) + err = fmt.Errorf("could not get ManageBuyOfferResult for operation at index %d", operationIndex) return } if success, ok := buyOfferResult.GetSuccess(); ok { @@ -183,12 +183,12 @@ func extractClaimedOffers(operationResults []xdr.OperationResult, operationIndex return } - err = fmt.Errorf("Could not get ManageOfferSuccess for operation at index %d", operationIndex) + err = fmt.Errorf("could not get ManageOfferSuccess for operation at index %d", operationIndex) case xdr.OperationTypeManageSellOffer: var sellOfferResult xdr.ManageSellOfferResult if sellOfferResult, ok = operationTr.GetManageSellOfferResult(); !ok { - err = fmt.Errorf("Could not get ManageSellOfferResult for operation at index %d", operationIndex) + err = fmt.Errorf("could not get ManageSellOfferResult for operation at index %d", operationIndex) return } @@ -198,7 +198,7 @@ func extractClaimedOffers(operationResults []xdr.OperationResult, operationIndex return } - err = fmt.Errorf("Could not get ManageOfferSuccess for operation at index %d", operationIndex) + err = fmt.Errorf("could not get ManageOfferSuccess for operation at index %d", operationIndex) case xdr.OperationTypeCreatePassiveSellOffer: // KNOWN ISSUE: stellar-core creates results for CreatePassiveOffer operations @@ -219,7 +219,7 @@ func extractClaimedOffers(operationResults []xdr.OperationResult, operationIndex var pathSendResult xdr.PathPaymentStrictSendResult sellerIsExact = null.BoolFrom(false) if pathSendResult, ok = operationTr.GetPathPaymentStrictSendResult(); !ok { - err = fmt.Errorf("Could not get PathPaymentStrictSendResult for operation at index %d", operationIndex) + err = fmt.Errorf("could not get PathPaymentStrictSendResult for operation at index %d", operationIndex) return } @@ -229,13 +229,13 @@ func extractClaimedOffers(operationResults []xdr.OperationResult, operationIndex return } - err = fmt.Errorf("Could not get PathPaymentStrictSendSuccess for operation at index %d", operationIndex) + err = fmt.Errorf("could not get PathPaymentStrictSendSuccess for operation at index %d", operationIndex) case xdr.OperationTypePathPaymentStrictReceive: var pathReceiveResult xdr.PathPaymentStrictReceiveResult sellerIsExact = null.BoolFrom(true) if pathReceiveResult, ok = operationTr.GetPathPaymentStrictReceiveResult(); !ok { - err = fmt.Errorf("Could not get PathPaymentStrictReceiveResult for operation at index %d", operationIndex) + err = fmt.Errorf("could not get PathPaymentStrictReceiveResult for operation at index %d", operationIndex) return } @@ -244,10 +244,10 @@ func extractClaimedOffers(operationResults []xdr.OperationResult, operationIndex return } - err = fmt.Errorf("Could not get GetPathPaymentStrictReceiveSuccess for operation at index %d", operationIndex) + err = fmt.Errorf("could not get GetPathPaymentStrictReceiveSuccess for operation at index %d", operationIndex) default: - err = fmt.Errorf("Operation of type %s at index %d does not result in trades", operationType, operationIndex) + err = fmt.Errorf("operation of type %s at index %d does not result in trades", operationType, operationIndex) return } @@ -386,7 +386,7 @@ func roundingSlippage(t ingest.LedgerTransaction, operationIndex int32, trade xd } return null.IntFrom(int64(roundingSlippageBips)), nil default: - return null.Int{}, fmt.Errorf("Unexpected trade operation type: %v", op.Body.Type) + return null.Int{}, fmt.Errorf("unexpected trade operation type: %v", op.Body.Type) } } diff --git a/internal/transform/trade_test.go b/internal/transform/trade_test.go index 8e963366..8cc46241 100644 --- a/internal/transform/trade_test.go +++ b/internal/transform/trade_test.go @@ -65,14 +65,14 @@ func TestTransformTrade(t *testing.T) { noTrEnvelope := genericManageBuyOfferEnvelope noTrInput.transaction.Envelope.V1 = &noTrEnvelope noTrInput.transaction.Result = wrapOperationsResultsSlice([]xdr.OperationResult{ - xdr.OperationResult{Tr: nil}, + {Tr: nil}, }, true) failedResultInput := genericInput failedResultEnvelope := genericManageBuyOfferEnvelope failedResultInput.transaction.Envelope.V1 = &failedResultEnvelope failedResultInput.transaction.Result = wrapOperationsResultsSlice([]xdr.OperationResult{ - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeManageBuyOffer, ManageBuyOfferResult: &xdr.ManageBuyOfferResult{ @@ -85,14 +85,14 @@ func TestTransformTrade(t *testing.T) { negBaseAmountEnvelope := genericManageBuyOfferEnvelope negBaseAmountInput.transaction.Envelope.V1 = &negBaseAmountEnvelope negBaseAmountInput.transaction.Result = wrapOperationsResultsSlice([]xdr.OperationResult{ - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeManageBuyOffer, ManageBuyOfferResult: &xdr.ManageBuyOfferResult{ Code: xdr.ManageBuyOfferResultCodeManageBuyOfferSuccess, Success: &xdr.ManageOfferSuccessResult{ OffersClaimed: []xdr.ClaimAtom{ - xdr.ClaimAtom{ + { Type: xdr.ClaimAtomTypeClaimAtomTypeOrderBook, OrderBook: &xdr.ClaimOfferAtom{ SellerId: genericAccountID, @@ -109,14 +109,14 @@ func TestTransformTrade(t *testing.T) { negCounterAmountEnvelope := genericManageBuyOfferEnvelope negCounterAmountInput.transaction.Envelope.V1 = &negCounterAmountEnvelope negCounterAmountInput.transaction.Result = wrapOperationsResultsSlice([]xdr.OperationResult{ - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeManageBuyOffer, ManageBuyOfferResult: &xdr.ManageBuyOfferResult{ Code: xdr.ManageBuyOfferResultCodeManageBuyOfferSuccess, Success: &xdr.ManageOfferSuccessResult{ OffersClaimed: []xdr.ClaimAtom{ - xdr.ClaimAtom{ + { Type: xdr.ClaimAtomTypeClaimAtomTypeOrderBook, OrderBook: &xdr.ClaimOfferAtom{ SellerId: genericAccountID, @@ -132,31 +132,31 @@ func TestTransformTrade(t *testing.T) { tests := []transformTest{ { wrongTypeInput, - []TradeOutput{}, fmt.Errorf("Operation of type OperationTypeBumpSequence at index 0 does not result in trades"), + []TradeOutput{}, fmt.Errorf("operation of type OperationTypeBumpSequence at index 0 does not result in trades"), }, { resultOutOfRangeInput, - []TradeOutput{}, fmt.Errorf("Operation index of 0 is out of bounds in result slice (len = 0)"), + []TradeOutput{}, fmt.Errorf("operation index of 0 is out of bounds in result slice (len = 0)"), }, { failedTxInput, - []TradeOutput{}, fmt.Errorf("Transaction failed; no trades"), + []TradeOutput{}, fmt.Errorf("transaction failed; no trades"), }, { noTrInput, - []TradeOutput{}, fmt.Errorf("Could not get result Tr for operation at index 0"), + []TradeOutput{}, fmt.Errorf("could not get result Tr for operation at index 0"), }, { failedResultInput, - []TradeOutput{}, fmt.Errorf("Could not get ManageOfferSuccess for operation at index 0"), + []TradeOutput{}, fmt.Errorf("could not get ManageOfferSuccess for operation at index 0"), }, { negBaseAmountInput, - []TradeOutput{}, fmt.Errorf("Amount sold is negative (-1) for operation at index 0"), + []TradeOutput{}, fmt.Errorf("amount sold is negative (-1) for operation at index 0"), }, { negCounterAmountInput, - []TradeOutput{}, fmt.Errorf("Amount bought is negative (-2) for operation at index 0"), + []TradeOutput{}, fmt.Errorf("amount bought is negative (-2) for operation at index 0"), }, } @@ -240,23 +240,21 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { } inputOperations := []xdr.Operation{ - - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeManageSellOffer, ManageSellOfferOp: &xdr.ManageSellOfferOp{}, }, }, - - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeManageBuyOffer, ManageBuyOfferOp: &xdr.ManageBuyOfferOp{}, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictSend, @@ -265,7 +263,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.Operation{ + { SourceAccount: &testAccount3, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictReceive, @@ -274,21 +272,21 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.Operation{ + { SourceAccount: &testAccount3, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictSend, PathPaymentStrictSendOp: &xdr.PathPaymentStrictSendOp{}, }, }, - xdr.Operation{ + { SourceAccount: &testAccount3, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictReceive, PathPaymentStrictReceiveOp: &xdr.PathPaymentStrictReceiveOp{}, }, }, - xdr.Operation{ + { SourceAccount: nil, Body: xdr.OperationBody{ Type: xdr.OperationTypeCreatePassiveSellOffer, @@ -298,7 +296,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { } inputEnvelope.Tx.Operations = inputOperations results := []xdr.OperationResult{ - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeManageSellOffer, @@ -313,7 +311,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeManageBuyOffer, ManageBuyOfferResult: &xdr.ManageBuyOfferResult{ @@ -326,7 +324,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypePathPaymentStrictSend, @@ -340,7 +338,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.OperationResult{ + { Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypePathPaymentStrictReceive, @@ -354,7 +352,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypePathPaymentStrictSend, PathPaymentStrictSendResult: &xdr.PathPaymentStrictSendResult{ @@ -367,7 +365,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypePathPaymentStrictReceive, PathPaymentStrictReceiveResult: &xdr.PathPaymentStrictReceiveResult{ @@ -380,7 +378,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeCreatePassiveSellOffer, CreatePassiveSellOfferResult: &xdr.ManageSellOfferResult{ @@ -395,7 +393,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { unsafeMeta := xdr.TransactionMetaV1{ Operations: []xdr.OperationMeta{ - xdr.OperationMeta{ + { Changes: xdr.LedgerEntryChanges{ xdr.LedgerEntryChange{ Type: xdr.LedgerEntryChangeTypeLedgerEntryState, @@ -431,7 +429,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.OperationMeta{ + { Changes: xdr.LedgerEntryChanges{ xdr.LedgerEntryChange{ Type: xdr.LedgerEntryChangeTypeLedgerEntryState, @@ -467,7 +465,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.OperationMeta{ + { Changes: xdr.LedgerEntryChanges{ xdr.LedgerEntryChange{ Type: xdr.LedgerEntryChangeTypeLedgerEntryState, @@ -535,7 +533,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.OperationMeta{ + { Changes: xdr.LedgerEntryChanges{ xdr.LedgerEntryChange{ Type: xdr.LedgerEntryChangeTypeLedgerEntryState, @@ -602,7 +600,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.OperationMeta{ + { Changes: xdr.LedgerEntryChanges{ xdr.LedgerEntryChange{ Type: xdr.LedgerEntryChangeTypeLedgerEntryState, @@ -656,7 +654,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.OperationMeta{ + { Changes: xdr.LedgerEntryChanges{ xdr.LedgerEntryChange{ Type: xdr.LedgerEntryChangeTypeLedgerEntryState, @@ -710,7 +708,7 @@ func makeTradeTestInput() (inputTransaction ingest.LedgerTransaction) { }, }, }, - xdr.OperationMeta{}, + {}, }} inputTransaction.Result.Result.Result.Results = &results @@ -834,13 +832,13 @@ func makeTradeTestOutput() [][]TradeOutput { offerTwoOutputSecondPlace.SellerIsExact = null.BoolFrom(false) output := [][]TradeOutput{ - []TradeOutput{offerOneOutput}, - []TradeOutput{offerTwoOutput}, - []TradeOutput{onePriceIsAmount, offerTwoOutputSecondPlace}, - []TradeOutput{twoPriceIsAmount, offerOneOutputSecondPlace}, - []TradeOutput{lPOneOutput}, - []TradeOutput{lPTwoOutput}, - []TradeOutput{}, + {offerOneOutput}, + {offerTwoOutput}, + {onePriceIsAmount, offerTwoOutputSecondPlace}, + {twoPriceIsAmount, offerOneOutputSecondPlace}, + {lPOneOutput}, + {lPTwoOutput}, + {}, } return output } diff --git a/internal/transform/transaction.go b/internal/transform/transaction.go index 9d105bf4..f4eb255d 100644 --- a/internal/transform/transaction.go +++ b/internal/transform/transaction.go @@ -33,17 +33,14 @@ func TransformTransaction(transaction ingest.LedgerTransaction, lhe xdr.LedgerHe outputAccountSequence := transaction.Envelope.SeqNum() if outputAccountSequence < 0 { - return TransactionOutput{}, fmt.Errorf("The account's sequence number (%d) is negative for ledger %d; transaction %d (transaction id=%d)", outputAccountSequence, outputLedgerSequence, transactionIndex, outputTransactionID) + return TransactionOutput{}, fmt.Errorf("the account's sequence number (%d) is negative for ledger %d; transaction %d (transaction id=%d)", outputAccountSequence, outputLedgerSequence, transactionIndex, outputTransactionID) } outputMaxFee := transaction.Envelope.Fee() - if outputMaxFee < 0 { - return TransactionOutput{}, fmt.Errorf("The fee (%d) is negative for ledger %d; transaction %d (transaction id=%d)", outputMaxFee, outputLedgerSequence, transactionIndex, outputTransactionID) - } outputFeeCharged := int64(transaction.Result.Result.FeeCharged) if outputFeeCharged < 0 { - return TransactionOutput{}, fmt.Errorf("The fee charged (%d) is negative for ledger %d; transaction %d (transaction id=%d)", outputFeeCharged, outputLedgerSequence, transactionIndex, outputTransactionID) + return TransactionOutput{}, fmt.Errorf("the fee charged (%d) is negative for ledger %d; transaction %d (transaction id=%d)", outputFeeCharged, outputLedgerSequence, transactionIndex, outputTransactionID) } outputOperationCount := int32(len(transaction.Envelope.Operations())) @@ -94,7 +91,7 @@ func TransformTransaction(transaction ingest.LedgerTransaction, lhe xdr.LedgerHe if timeBound != nil { if timeBound.MaxTime < timeBound.MinTime && timeBound.MaxTime != 0 { - return TransactionOutput{}, fmt.Errorf("The max time is earlier than the min time (%d < %d) for ledger %d; transaction %d (transaction id=%d)", + return TransactionOutput{}, fmt.Errorf("the max time is earlier than the min time (%d < %d) for ledger %d; transaction %d (transaction id=%d)", timeBound.MaxTime, timeBound.MinTime, outputLedgerSequence, transactionIndex, outputTransactionID) } @@ -143,6 +140,9 @@ func TransformTransaction(transaction ingest.LedgerTransaction, lhe xdr.LedgerHe var outputInclusionFeeBid int64 var outputInclusionFeeCharged int64 var outputResourceFeeRefund int64 + var outputTotalNonRefundableResourceFeeCharged int64 + var outputTotalRefundableResourceFeeCharged int64 + var outputRentFeeCharged int64 // Soroban data can exist in V1 and FeeBump transactionEnvelopes switch transaction.Envelope.Type { @@ -167,6 +167,12 @@ func TransformTransaction(transaction ingest.LedgerTransaction, lhe xdr.LedgerHe if ok { accountBalanceStart, accountBalanceEnd := getAccountBalanceFromLedgerEntryChanges(meta.TxChangesAfter, sourceAccount.Address()) outputResourceFeeRefund = accountBalanceEnd - accountBalanceStart + extV1, ok := meta.SorobanMeta.Ext.GetV1() + if ok { + outputTotalNonRefundableResourceFeeCharged = int64(extV1.TotalNonRefundableResourceFeeCharged) + outputTotalRefundableResourceFeeCharged = int64(extV1.TotalRefundableResourceFeeCharged) + outputRentFeeCharged = int64(extV1.RentFeeCharged) + } } // TODO: FeeCharged is calculated incorrectly in protocol 20. Remove when protocol is updated and the bug is fixed @@ -182,37 +188,40 @@ func TransformTransaction(transaction ingest.LedgerTransaction, lhe xdr.LedgerHe outputSuccessful := transaction.Result.Successful() transformedTransaction := TransactionOutput{ - TransactionHash: outputTransactionHash, - LedgerSequence: outputLedgerSequence, - TransactionID: outputTransactionID, - Account: outputAccount, - AccountSequence: outputAccountSequence, - MaxFee: outputMaxFee, - FeeCharged: outputFeeCharged, - OperationCount: outputOperationCount, - TxEnvelope: outputTxEnvelope, - TxResult: outputTxResult, - TxMeta: outputTxMeta, - TxFeeMeta: outputTxFeeMeta, - CreatedAt: outputCreatedAt, - MemoType: outputMemoType, - Memo: outputMemoContents, - TimeBounds: outputTimeBounds, - Successful: outputSuccessful, - LedgerBounds: outputLedgerBound, - MinAccountSequence: outputMinSequence, - MinAccountSequenceAge: outputMinSequenceAge, - MinAccountSequenceLedgerGap: outputMinSequenceLedgerGap, - ExtraSigners: formatSigners(transaction.Envelope.ExtraSigners()), - ClosedAt: outputCloseTime, - ResourceFee: outputResourceFee, - SorobanResourcesInstructions: outputSorobanResourcesInstructions, - SorobanResourcesReadBytes: outputSorobanResourcesReadBytes, - SorobanResourcesWriteBytes: outputSorobanResourcesWriteBytes, - TransactionResultCode: outputTxResultCode, - InclusionFeeBid: outputInclusionFeeBid, - InclusionFeeCharged: outputInclusionFeeCharged, - ResourceFeeRefund: outputResourceFeeRefund, + TransactionHash: outputTransactionHash, + LedgerSequence: outputLedgerSequence, + TransactionID: outputTransactionID, + Account: outputAccount, + AccountSequence: outputAccountSequence, + MaxFee: outputMaxFee, + FeeCharged: outputFeeCharged, + OperationCount: outputOperationCount, + TxEnvelope: outputTxEnvelope, + TxResult: outputTxResult, + TxMeta: outputTxMeta, + TxFeeMeta: outputTxFeeMeta, + CreatedAt: outputCreatedAt, + MemoType: outputMemoType, + Memo: outputMemoContents, + TimeBounds: outputTimeBounds, + Successful: outputSuccessful, + LedgerBounds: outputLedgerBound, + MinAccountSequence: outputMinSequence, + MinAccountSequenceAge: outputMinSequenceAge, + MinAccountSequenceLedgerGap: outputMinSequenceLedgerGap, + ExtraSigners: formatSigners(transaction.Envelope.ExtraSigners()), + ClosedAt: outputCloseTime, + ResourceFee: outputResourceFee, + SorobanResourcesInstructions: outputSorobanResourcesInstructions, + SorobanResourcesReadBytes: outputSorobanResourcesReadBytes, + SorobanResourcesWriteBytes: outputSorobanResourcesWriteBytes, + TransactionResultCode: outputTxResultCode, + InclusionFeeBid: outputInclusionFeeBid, + InclusionFeeCharged: outputInclusionFeeCharged, + ResourceFeeRefund: outputResourceFeeRefund, + TotalNonRefundableResourceFeeCharged: outputTotalNonRefundableResourceFeeCharged, + TotalRefundableResourceFeeCharged: outputTotalRefundableResourceFeeCharged, + RentFeeCharged: outputRentFeeCharged, } // Add Muxed Account Details, if exists diff --git a/internal/transform/transaction_test.go b/internal/transform/transaction_test.go index 9ca8708b..fd1d8b47 100644 --- a/internal/transform/transaction_test.go +++ b/internal/transform/transaction_test.go @@ -47,20 +47,20 @@ func TestTransformTransaction(t *testing.T) { assert.NoError(t, err) tests := []transformTest{ - transformTest{ + { negativeSeqInput, TransactionOutput{}, - fmt.Errorf("The account's sequence number (-1) is negative for ledger 0; transaction 1 (transaction id=4096)"), + fmt.Errorf("the account's sequence number (-1) is negative for ledger 0; transaction 1 (transaction id=4096)"), }, { badFeeChargedInput, TransactionOutput{}, - fmt.Errorf("The fee charged (-1) is negative for ledger 0; transaction 1 (transaction id=4096)"), + fmt.Errorf("the fee charged (-1) is negative for ledger 0; transaction 1 (transaction id=4096)"), }, { badTimeboundInput, TransactionOutput{}, - fmt.Errorf("The max time is earlier than the min time (100 < 1594586912) for ledger 0; transaction 1 (transaction id=4096)"), + fmt.Errorf("the max time is earlier than the min time (100 < 1594586912) for ledger 0; transaction 1 (transaction id=4096)"), }, } @@ -82,7 +82,7 @@ func TestTransformTransaction(t *testing.T) { func makeTransactionTestOutput() (output []TransactionOutput, err error) { correctTime, err := time.Parse("2006-1-2 15:04:05 MST", "2020-07-09 05:28:42 UTC") output = []TransactionOutput{ - TransactionOutput{ + { TxEnvelope: "AAAAAgAAAACI4aa0pXFSj6qfJuIObLw/5zyugLRGYwxb7wFSr3B9eAABX5ABjydzAABBtwAAAAEAAAAAAAAAAAAAAABfBqt0AAAAAQAAABdITDVhQ2dvelFISVc3c1NjNVhkY2ZtUgAAAAABAAAAAQAAAAAcR0GXGO76pFs4y38vJVAanjnLg4emNun7zAx0pHcDGAAAAAIAAAAAAAAAAAAAAAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", TxResult: "AAAAAAAAASz/////AAAAAQAAAAAAAAAAAAAAAAAAAAA=", TxMeta: "AAAAAQAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAAA", @@ -107,7 +107,7 @@ func makeTransactionTestOutput() (output []TransactionOutput, err error) { SorobanResourcesWriteBytes: 0, TransactionResultCode: "TransactionResultCodeTxFailed", }, - TransactionOutput{ + { TxEnvelope: "AAAABQAAAABnzACGTDuJFoxqr+C8NHCe0CHFBXLi+YhhNCIILCIpcgAAAAAAABwgAAAAAgAAAACI4aa0pXFSj6qfJuIObLw/5zyugLRGYwxb7wFSr3B9eAAAAAACFPY2AAAAfQAAAAEAAAAAAAAAAAAAAABfBqt0AAAAAQAAABdITDVhQ2dvelFISVc3c1NjNVhkY2ZtUgAAAAABAAAAAQAAAAAcR0GXGO76pFs4y38vJVAanjnLg4emNun7zAx0pHcDGAAAAAIAAAAAAAAAAAAAAAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", TxResult: "AAAAAAAAASwAAAABqH/vXusmAmnDgPLeRWqtcrWbsxWqrHd4YEVuCdrAuvsAAAAAAAAAZAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAA=", TxMeta: "AAAAAQAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAAA", @@ -135,7 +135,7 @@ func makeTransactionTestOutput() (output []TransactionOutput, err error) { SorobanResourcesWriteBytes: 0, TransactionResultCode: "TransactionResultCodeTxFeeBumpInnerSuccess", //inner fee bump success }, - TransactionOutput{ + { TxEnvelope: "AAAAAgAAAAAcR0GXGO76pFs4y38vJVAanjnLg4emNun7zAx0pHcDGAAAAGQBpLyvsiV6gwAAAAIAAAABAAAAAAAAAAAAAAAAXwardAAAAAEAAAAFAAAACgAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAMCAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAABdITDVhQ2dvelFISVc3c1NjNVhkY2ZtUgAAAAABAAAAAQAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAAIAAAAAAAAAAAAAAAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", TxResult: "AAAAAAAAAGT////5AAAAAA==", TxMeta: "AAAAAQAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAAA", @@ -171,7 +171,7 @@ func makeTransactionTestInput() (transaction []ingest.LedgerTransaction, history hardCodedMemoText := "HL5aCgozQHIW7sSc5XdcfmR" hardCodedTransactionHash := xdr.Hash([32]byte{0xa8, 0x7f, 0xef, 0x5e, 0xeb, 0x26, 0x2, 0x69, 0xc3, 0x80, 0xf2, 0xde, 0x45, 0x6a, 0xad, 0x72, 0xb5, 0x9b, 0xb3, 0x15, 0xaa, 0xac, 0x77, 0x78, 0x60, 0x45, 0x6e, 0x9, 0xda, 0xc0, 0xba, 0xfb}) genericResultResults := &[]xdr.OperationResult{ - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ Type: xdr.OperationTypeCreateAccount, CreateAccountResult: &xdr.CreateAccountResult{ @@ -198,7 +198,7 @@ func makeTransactionTestInput() (transaction []ingest.LedgerTransaction, history Ed25519: source.Ed25519, } transaction = []ingest.LedgerTransaction{ - ingest.LedgerTransaction{ + { Index: 1, UnsafeMeta: hardCodedMeta, Envelope: xdr.TransactionEnvelope{ @@ -220,7 +220,7 @@ func makeTransactionTestInput() (transaction []ingest.LedgerTransaction, history }, }, Operations: []xdr.Operation{ - xdr.Operation{ + { SourceAccount: &testAccount2, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictReceive, @@ -244,7 +244,7 @@ func makeTransactionTestInput() (transaction []ingest.LedgerTransaction, history }, }, }, - ingest.LedgerTransaction{ + { Index: 1, UnsafeMeta: hardCodedMeta, Envelope: xdr.TransactionEnvelope{ @@ -271,7 +271,7 @@ func makeTransactionTestInput() (transaction []ingest.LedgerTransaction, history }, }, Operations: []xdr.Operation{ - xdr.Operation{ + { SourceAccount: &testAccount2, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictReceive, @@ -300,7 +300,7 @@ func makeTransactionTestInput() (transaction []ingest.LedgerTransaction, history Result: xdr.InnerTransactionResultResult{ Code: xdr.TransactionResultCodeTxSuccess, Results: &[]xdr.OperationResult{ - xdr.OperationResult{ + { Tr: &xdr.OperationResultTr{ CreateAccountResult: &xdr.CreateAccountResult{}, }, @@ -309,14 +309,12 @@ func makeTransactionTestInput() (transaction []ingest.LedgerTransaction, history }, }, }, - Results: &[]xdr.OperationResult{ - xdr.OperationResult{}, - }, + Results: &[]xdr.OperationResult{{}}, }, }, }, }, - ingest.LedgerTransaction{ + { Index: 1, UnsafeMeta: hardCodedMeta, Envelope: xdr.TransactionEnvelope{ @@ -345,7 +343,7 @@ func makeTransactionTestInput() (transaction []ingest.LedgerTransaction, history }, }, Operations: []xdr.Operation{ - xdr.Operation{ + { SourceAccount: &testAccount4, Body: xdr.OperationBody{ Type: xdr.OperationTypePathPaymentStrictReceive, @@ -371,19 +369,19 @@ func makeTransactionTestInput() (transaction []ingest.LedgerTransaction, history }, } historyHeader = []xdr.LedgerHeaderHistoryEntry{ - xdr.LedgerHeaderHistoryEntry{ + { Header: xdr.LedgerHeader{ LedgerSeq: 30521816, ScpValue: xdr.StellarValue{CloseTime: 1594272522}, }, }, - xdr.LedgerHeaderHistoryEntry{ + { Header: xdr.LedgerHeader{ LedgerSeq: 30521817, ScpValue: xdr.StellarValue{CloseTime: 1594272522}, }, }, - xdr.LedgerHeaderHistoryEntry{ + { Header: xdr.LedgerHeader{ LedgerSeq: 30521818, ScpValue: xdr.StellarValue{CloseTime: 1594272522}, diff --git a/internal/transform/trustline.go b/internal/transform/trustline.go index 3099f306..dd0f3c26 100644 --- a/internal/transform/trustline.go +++ b/internal/transform/trustline.go @@ -22,7 +22,7 @@ func TransformTrustline(ledgerChange ingest.Change, header xdr.LedgerHeaderHisto trustEntry, ok := ledgerEntry.Data.GetTrustLine() if !ok { - return TrustlineOutput{}, fmt.Errorf("Could not extract trustline data from ledger entry; actual type is %s", ledgerEntry.Data.Type) + return TrustlineOutput{}, fmt.Errorf("could not extract trustline data from ledger entry; actual type is %s", ledgerEntry.Data.Type) } outputAccountID, err := trustEntry.AccountId.GetAddress() @@ -86,12 +86,12 @@ func trustLineEntryToLedgerKeyString(trustLine xdr.TrustLineEntry) (string, erro ledgerKey := &xdr.LedgerKey{} err := ledgerKey.SetTrustline(trustLine.AccountId, trustLine.Asset) if err != nil { - return "", fmt.Errorf("Error running ledgerKey.SetTrustline when calculating ledger key") + return "", fmt.Errorf("error running ledgerKey.SetTrustline when calculating ledger key") } key, err := ledgerKey.MarshalBinary() if err != nil { - return "", fmt.Errorf("Error running MarshalBinaryCompress when calculating ledger key") + return "", fmt.Errorf("error running MarshalBinaryCompress when calculating ledger key") } return base64.StdEncoding.EncodeToString(key), nil diff --git a/internal/transform/trustline_test.go b/internal/transform/trustline_test.go index 24efa2f5..437fd7dc 100644 --- a/internal/transform/trustline_test.go +++ b/internal/transform/trustline_test.go @@ -37,7 +37,7 @@ func TestTransformTrustline(t *testing.T) { }, }, }, - TrustlineOutput{}, fmt.Errorf("Could not extract trustline data from ledger entry; actual type is LedgerEntryTypeOffer"), + TrustlineOutput{}, fmt.Errorf("could not extract trustline data from ledger entry; actual type is LedgerEntryTypeOffer"), }, } diff --git a/internal/transform/ttl.go b/internal/transform/ttl.go index cb9218e1..c0e6fe9c 100644 --- a/internal/transform/ttl.go +++ b/internal/transform/ttl.go @@ -17,7 +17,7 @@ func TransformTtl(ledgerChange ingest.Change, header xdr.LedgerHeaderHistoryEntr ttl, ok := ledgerEntry.Data.GetTtl() if !ok { - return TtlOutput{}, fmt.Errorf("Could not extract ttl from ledger entry; actual type is %s", ledgerEntry.Data.Type) + return TtlOutput{}, fmt.Errorf("could not extract ttl from ledger entry; actual type is %s", ledgerEntry.Data.Type) } // LedgerEntryChange must contain a ttl change to be parsed, otherwise skip diff --git a/internal/transform/ttl_test.go b/internal/transform/ttl_test.go index 4d49a54b..8f14e089 100644 --- a/internal/transform/ttl_test.go +++ b/internal/transform/ttl_test.go @@ -31,7 +31,7 @@ func TestTransformTtl(t *testing.T) { }, }, }, - TtlOutput{}, fmt.Errorf("Could not extract ttl from ledger entry; actual type is LedgerEntryTypeOffer"), + TtlOutput{}, fmt.Errorf("could not extract ttl from ledger entry; actual type is LedgerEntryTypeOffer"), }, } diff --git a/internal/utils/main.go b/internal/utils/main.go index a91e6ef2..c1259a50 100644 --- a/internal/utils/main.go +++ b/internal/utils/main.go @@ -859,3 +859,8 @@ func AccountSignersChanged(c ingest.Change) bool { return false } + +type HistoryArchiveLedgerAndLCM struct { + Ledger historyarchive.Ledger + LCM xdr.LedgerCloseMeta +}