From 285e2e4369210ba86e69daba0283b779065a6d4f Mon Sep 17 00:00:00 2001 From: sydneynotthecity Date: Tue, 5 Mar 2024 00:09:01 -0600 Subject: [PATCH 1/2] Add tx and operation error codes --- internal/transform/operation.go | 94 +++++- internal/transform/operation_test.go | 426 +++++++++++++++++++++---- internal/transform/schema.go | 19 +- internal/transform/transaction.go | 3 + internal/transform/transaction_test.go | 7 +- 5 files changed, 465 insertions(+), 84 deletions(-) diff --git a/internal/transform/operation.go b/internal/transform/operation.go index 9229419b..cb22c942 100644 --- a/internal/transform/operation.go +++ b/internal/transform/operation.go @@ -66,15 +66,28 @@ func TransformOperation(operation xdr.Operation, operationIndex int32, transacti return OperationOutput{}, err } + outputOperationResults, ok := transaction.Result.Result.OperationResults() + if !ok { + return OperationOutput{}, err + } + outputOperationResultCode := outputOperationResults[operationIndex].Code.String() + // TODO: add trace code details + outputOperationTraceCode, err := mapOperationTrace(*outputOperationResults[operationIndex].Tr) + if err != nil { + return OperationOutput{}, err + } + transformedOperation := OperationOutput{ - SourceAccount: outputSourceAccount, - SourceAccountMuxed: outputSourceAccountMuxed.String, - Type: outputOperationType, - TypeString: outputOperationTypeString, - TransactionID: outputTransactionID, - OperationID: outputOperationID, - OperationDetails: outputDetails, - ClosedAt: outputCloseTime, + SourceAccount: outputSourceAccount, + SourceAccountMuxed: outputSourceAccountMuxed.String, + Type: outputOperationType, + TypeString: outputOperationTypeString, + TransactionID: outputTransactionID, + OperationID: outputOperationID, + OperationDetails: outputDetails, + ClosedAt: outputCloseTime, + OperationResultCode: outputOperationResultCode, + OperationTraceCode: outputOperationTraceCode, } return transformedOperation, nil @@ -145,6 +158,71 @@ func mapOperationType(operation xdr.Operation) (string, error) { return op_string_type, nil } +func mapOperationTrace(operationTrace xdr.OperationResultTr) (string, error) { + var operationTraceDescription string + operationType := operationTrace.Type + + switch operationType { + case xdr.OperationTypeCreateAccount: + operationTraceDescription = operationTrace.CreateAccountResult.Code.String() + case xdr.OperationTypePayment: + operationTraceDescription = operationTrace.PaymentResult.Code.String() + case xdr.OperationTypePathPaymentStrictReceive: + operationTraceDescription = operationTrace.PathPaymentStrictReceiveResult.Code.String() + case xdr.OperationTypePathPaymentStrictSend: + operationTraceDescription = operationTrace.PathPaymentStrictSendResult.Code.String() + case xdr.OperationTypeManageBuyOffer: + operationTraceDescription = operationTrace.ManageBuyOfferResult.Code.String() + case xdr.OperationTypeManageSellOffer: + operationTraceDescription = operationTrace.ManageSellOfferResult.Code.String() + case xdr.OperationTypeCreatePassiveSellOffer: + operationTraceDescription = operationTrace.CreatePassiveSellOfferResult.Code.String() + case xdr.OperationTypeSetOptions: + operationTraceDescription = operationTrace.SetOptionsResult.Code.String() + case xdr.OperationTypeChangeTrust: + operationTraceDescription = operationTrace.ChangeTrustResult.Code.String() + case xdr.OperationTypeAllowTrust: + operationTraceDescription = operationTrace.AllowTrustResult.Code.String() + case xdr.OperationTypeAccountMerge: + operationTraceDescription = operationTrace.AccountMergeResult.Code.String() + case xdr.OperationTypeInflation: + operationTraceDescription = operationTrace.InflationResult.Code.String() + case xdr.OperationTypeManageData: + operationTraceDescription = operationTrace.ManageDataResult.Code.String() + case xdr.OperationTypeBumpSequence: + operationTraceDescription = operationTrace.BumpSeqResult.Code.String() + case xdr.OperationTypeCreateClaimableBalance: + operationTraceDescription = operationTrace.CreateClaimableBalanceResult.Code.String() + case xdr.OperationTypeClaimClaimableBalance: + operationTraceDescription = operationTrace.ClaimClaimableBalanceResult.Code.String() + case xdr.OperationTypeBeginSponsoringFutureReserves: + operationTraceDescription = operationTrace.BeginSponsoringFutureReservesResult.Code.String() + case xdr.OperationTypeEndSponsoringFutureReserves: + operationTraceDescription = operationTrace.EndSponsoringFutureReservesResult.Code.String() + case xdr.OperationTypeRevokeSponsorship: + operationTraceDescription = operationTrace.RevokeSponsorshipResult.Code.String() + case xdr.OperationTypeClawback: + operationTraceDescription = operationTrace.ClawbackResult.Code.String() + case xdr.OperationTypeClawbackClaimableBalance: + operationTraceDescription = operationTrace.ClawbackClaimableBalanceResult.Code.String() + case xdr.OperationTypeSetTrustLineFlags: + operationTraceDescription = operationTrace.SetTrustLineFlagsResult.Code.String() + case xdr.OperationTypeLiquidityPoolDeposit: + operationTraceDescription = operationTrace.LiquidityPoolDepositResult.Code.String() + case xdr.OperationTypeLiquidityPoolWithdraw: + operationTraceDescription = operationTrace.LiquidityPoolWithdrawResult.Code.String() + case xdr.OperationTypeInvokeHostFunction: + operationTraceDescription = operationTrace.InvokeHostFunctionResult.Code.String() + case xdr.OperationTypeExtendFootprintTtl: + operationTraceDescription = operationTrace.ExtendFootprintTtlResult.Code.String() + case xdr.OperationTypeRestoreFootprint: + operationTraceDescription = operationTrace.RestoreFootprintResult.Code.String() + default: + return operationTraceDescription, fmt.Errorf("Unknown operation type: %s", operationTrace.Type.String()) + } + return operationTraceDescription, nil +} + func PoolIDToString(id xdr.PoolId) string { return xdr.Hash(id).HexString() } diff --git a/internal/transform/operation_test.go b/internal/transform/operation_test.go index 7ae5b341..86702448 100644 --- a/internal/transform/operation_test.go +++ b/internal/transform/operation_test.go @@ -622,9 +622,33 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er } inputEnvelope.Tx.Operations = inputOperations results := []xdr.OperationResult{ - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeCreateAccount, + CreateAccountResult: &xdr.CreateAccountResult{ + Code: xdr.CreateAccountResultCodeCreateAccountSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypePayment, + PaymentResult: &xdr.PaymentResult{ + Code: xdr.PaymentResultCodePaymentSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypePayment, + PaymentResult: &xdr.PaymentResult{ + Code: xdr.PaymentResultCodePaymentSuccess, + }, + }, + }, // There needs to be a true result for path payment receive and send xdr.OperationResult{ Code: xdr.OperationResultCodeOpInner, @@ -638,17 +662,105 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeManageSellOffer, + ManageSellOfferResult: &xdr.ManageSellOfferResult{ + Code: xdr.ManageSellOfferResultCodeManageSellOfferSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeManageSellOffer, + ManageSellOfferResult: &xdr.ManageSellOfferResult{ + Code: xdr.ManageSellOfferResultCodeManageSellOfferSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeSetOptions, + SetOptionsResult: &xdr.SetOptionsResult{ + Code: xdr.SetOptionsResultCodeSetOptionsSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeChangeTrust, + ChangeTrustResult: &xdr.ChangeTrustResult{ + Code: xdr.ChangeTrustResultCodeChangeTrustSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeChangeTrust, + ChangeTrustResult: &xdr.ChangeTrustResult{ + Code: xdr.ChangeTrustResultCodeChangeTrustSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeAllowTrust, + AllowTrustResult: &xdr.AllowTrustResult{ + Code: xdr.AllowTrustResultCodeAllowTrustSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeAccountMerge, + AccountMergeResult: &xdr.AccountMergeResult{ + Code: xdr.AccountMergeResultCodeAccountMergeSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeInflation, + InflationResult: &xdr.InflationResult{ + Code: xdr.InflationResultCodeInflationSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeManageData, + ManageDataResult: &xdr.ManageDataResult{ + Code: xdr.ManageDataResultCodeManageDataSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeBumpSequence, + BumpSeqResult: &xdr.BumpSequenceResult{ + Code: xdr.BumpSequenceResultCodeBumpSequenceSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeManageBuyOffer, + ManageBuyOfferResult: &xdr.ManageBuyOfferResult{ + Code: xdr.ManageBuyOfferResultCodeManageBuyOfferSuccess, + }, + }, + }, xdr.OperationResult{ Code: xdr.OperationResultCodeOpInner, Tr: &xdr.OperationResultTr{ @@ -661,21 +773,141 @@ func makeOperationTestInput() (inputTransaction ingest.LedgerTransaction, err er }, }, }, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, - xdr.OperationResult{}, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeCreateClaimableBalance, + CreateClaimableBalanceResult: &xdr.CreateClaimableBalanceResult{ + Code: xdr.CreateClaimableBalanceResultCodeCreateClaimableBalanceSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeClaimClaimableBalance, + ClaimClaimableBalanceResult: &xdr.ClaimClaimableBalanceResult{ + Code: xdr.ClaimClaimableBalanceResultCodeClaimClaimableBalanceSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeBeginSponsoringFutureReserves, + BeginSponsoringFutureReservesResult: &xdr.BeginSponsoringFutureReservesResult{ + Code: xdr.BeginSponsoringFutureReservesResultCodeBeginSponsoringFutureReservesSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeRevokeSponsorship, + RevokeSponsorshipResult: &xdr.RevokeSponsorshipResult{ + Code: xdr.RevokeSponsorshipResultCodeRevokeSponsorshipSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeRevokeSponsorship, + RevokeSponsorshipResult: &xdr.RevokeSponsorshipResult{ + Code: xdr.RevokeSponsorshipResultCodeRevokeSponsorshipSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeRevokeSponsorship, + RevokeSponsorshipResult: &xdr.RevokeSponsorshipResult{ + Code: xdr.RevokeSponsorshipResultCodeRevokeSponsorshipSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeRevokeSponsorship, + RevokeSponsorshipResult: &xdr.RevokeSponsorshipResult{ + Code: xdr.RevokeSponsorshipResultCodeRevokeSponsorshipSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeRevokeSponsorship, + RevokeSponsorshipResult: &xdr.RevokeSponsorshipResult{ + Code: xdr.RevokeSponsorshipResultCodeRevokeSponsorshipSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeRevokeSponsorship, + RevokeSponsorshipResult: &xdr.RevokeSponsorshipResult{ + Code: xdr.RevokeSponsorshipResultCodeRevokeSponsorshipSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeRevokeSponsorship, + RevokeSponsorshipResult: &xdr.RevokeSponsorshipResult{ + Code: xdr.RevokeSponsorshipResultCodeRevokeSponsorshipSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeClawback, + ClawbackResult: &xdr.ClawbackResult{ + Code: xdr.ClawbackResultCodeClawbackSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeClawbackClaimableBalance, + ClawbackClaimableBalanceResult: &xdr.ClawbackClaimableBalanceResult{ + Code: xdr.ClawbackClaimableBalanceResultCodeClawbackClaimableBalanceSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeSetTrustLineFlags, + SetTrustLineFlagsResult: &xdr.SetTrustLineFlagsResult{ + Code: xdr.SetTrustLineFlagsResultCodeSetTrustLineFlagsSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeLiquidityPoolDeposit, + LiquidityPoolDepositResult: &xdr.LiquidityPoolDepositResult{ + Code: xdr.LiquidityPoolDepositResultCodeLiquidityPoolDepositSuccess, + }, + }, + }, + xdr.OperationResult{ + Code: xdr.OperationResultCodeOpInner, + Tr: &xdr.OperationResultTr{ + Type: xdr.OperationTypeLiquidityPoolWithdraw, + LiquidityPoolWithdrawResult: &xdr.LiquidityPoolWithdrawResult{ + Code: xdr.LiquidityPoolWithdrawResultCodeLiquidityPoolWithdrawSuccess, + }, + }, + }, //xdr.OperationResult{}, //xdr.OperationResult{}, //xdr.OperationResult{}, @@ -704,7 +936,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "funder": hardCodedSourceAccountAddress, "starting_balance": 2.5, }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "CreateAccountResultCodeCreateAccountSuccess", }, OperationOutput{ Type: 1, @@ -721,7 +955,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "asset_issuer": hardCodedDestAccountAddress, "asset_id": int64(-8205667356306085451), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "PaymentResultCodePaymentSuccess", }, OperationOutput{ Type: 1, @@ -736,7 +972,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "asset_type": "native", "asset_id": int64(-5706705804583548011), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "PaymentResultCodePaymentSuccess", }, OperationOutput{ Type: 2, @@ -756,7 +994,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "asset_id": int64(-5706705804583548011), "path": []Path{usdtAssetPath}, }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "PathPaymentStrictReceiveResultCodePathPaymentStrictReceiveSuccess", }, OperationOutput{ Type: 3, @@ -779,7 +1019,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "buying_asset_type": "native", "buying_asset_id": int64(-5706705804583548011), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "ManageSellOfferResultCodeManageSellOfferSuccess", }, OperationOutput{ Type: 4, @@ -801,7 +1043,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "selling_asset_type": "native", "selling_asset_id": int64(-5706705804583548011), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "ManageSellOfferResultCodeManageSellOfferSuccess", }, OperationOutput{ Type: 5, @@ -823,7 +1067,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "signer_key": "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF", "signer_weight": uint32(1), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "SetOptionsResultCodeSetOptionsSuccess", }, OperationOutput{ Type: 6, @@ -840,7 +1086,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "asset_issuer": hardCodedDestAccountAddress, "asset_id": int64(6690054458235693884), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "ChangeTrustResultCodeChangeTrustSuccess", }, OperationOutput{ Type: 6, @@ -854,7 +1102,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "asset_type": "liquidity_pool_shares", "liquidity_pool_id": "185a6b384c651552ba09b32851b79f5f6ab61e80883d303f52bea1406a4923f0", }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "ChangeTrustResultCodeChangeTrustSuccess", }, OperationOutput{ Type: 7, @@ -871,7 +1121,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "asset_issuer": hardCodedSourceAccountAddress, "asset_id": int64(8485542065083974675), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "AllowTrustResultCodeAllowTrustSuccess", }, OperationOutput{ Type: 8, @@ -883,16 +1135,20 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "account": hardCodedSourceAccountAddress, "into": hardCodedDestAccountAddress, }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "AccountMergeResultCodeAccountMergeSuccess", }, OperationOutput{ - Type: 9, - TypeString: "inflation", - SourceAccount: hardCodedSourceAccountAddress, - TransactionID: 4096, - OperationID: 4108, - OperationDetails: map[string]interface{}{}, - ClosedAt: hardCodedLedgerClose, + Type: 9, + TypeString: "inflation", + SourceAccount: hardCodedSourceAccountAddress, + TransactionID: 4096, + OperationID: 4108, + OperationDetails: map[string]interface{}{}, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "InflationResultCodeInflationSuccess", }, OperationOutput{ Type: 10, @@ -904,7 +1160,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "name": "test", "value": base64.StdEncoding.EncodeToString([]byte{0x76, 0x61, 0x6c, 0x75, 0x65}), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "ManageDataResultCodeManageDataSuccess", }, OperationOutput{ Type: 11, @@ -915,7 +1173,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationDetails: map[string]interface{}{ "bump_to": "100", }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "BumpSequenceResultCodeBumpSequenceSuccess", }, OperationOutput{ Type: 12, @@ -938,7 +1198,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "buying_asset_id": int64(-5706705804583548011), "offer_id": int64(100), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "ManageBuyOfferResultCodeManageBuyOfferSuccess", }, OperationOutput{ Type: 13, @@ -958,7 +1220,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "asset_type": "native", "asset_id": int64(-5706705804583548011), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "PathPaymentStrictSendResultCodePathPaymentStrictSendSuccess", }, OperationOutput{ Type: 14, @@ -971,7 +1235,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "amount": 123456.789, "claimants": []Claimant{testClaimantDetails}, }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "CreateClaimableBalanceResultCodeCreateClaimableBalanceSuccess", }, OperationOutput{ Type: 15, @@ -983,7 +1249,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "claimant": hardCodedSourceAccountAddress, "balance_id": "000000000102030405060708090000000000000000000000000000000000000000000000", }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "ClaimClaimableBalanceResultCodeClaimClaimableBalanceSuccess", }, OperationOutput{ Type: 16, @@ -994,7 +1262,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationDetails: map[string]interface{}{ "sponsored_id": hardCodedDestAccountAddress, }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "BeginSponsoringFutureReservesResultCodeBeginSponsoringFutureReservesSuccess", }, OperationOutput{ Type: 18, @@ -1006,7 +1276,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "signer_account_id": hardCodedDestAccountAddress, "signer_key": "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF", }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, OperationOutput{ Type: 18, @@ -1017,7 +1289,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationDetails: map[string]interface{}{ "account_id": hardCodedDestAccountAddress, }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, OperationOutput{ Type: 18, @@ -1028,7 +1302,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationDetails: map[string]interface{}{ "claimable_balance_id": "000000000102030405060708090000000000000000000000000000000000000000000000", }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, OperationOutput{ Type: 18, @@ -1040,7 +1316,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "data_account_id": hardCodedDestAccountAddress, "data_name": "test", }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, OperationOutput{ Type: 18, @@ -1051,7 +1329,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationDetails: map[string]interface{}{ "offer_id": int64(100), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, OperationOutput{ Type: 18, @@ -1063,7 +1343,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "trustline_account_id": testAccount3Address, "trustline_asset": "USTT:GBT4YAEGJQ5YSFUMNKX6BPBUOCPNAIOFAVZOF6MIME2CECBMEIUXFZZN", }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, OperationOutput{ Type: 18, @@ -1074,7 +1356,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationDetails: map[string]interface{}{ "liquidity_pool_id": "0102030405060708090000000000000000000000000000000000000000000000", }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "RevokeSponsorshipResultCodeRevokeSponsorshipSuccess", }, OperationOutput{ Type: 19, @@ -1090,7 +1374,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "asset_type": "credit_alphanum4", "asset_id": int64(-8205667356306085451), }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "ClawbackResultCodeClawbackSuccess", }, OperationOutput{ Type: 20, @@ -1101,7 +1387,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationDetails: map[string]interface{}{ "balance_id": "000000000102030405060708090000000000000000000000000000000000000000000000", }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "ClawbackClaimableBalanceResultCodeClawbackClaimableBalanceSuccess", }, OperationOutput{ Type: 21, @@ -1120,7 +1408,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "set_flags": []int32{4}, "set_flags_s": []string{"clawback_enabled"}, }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "SetTrustLineFlagsResultCodeSetTrustLineFlagsSuccess", }, OperationOutput{ Type: 22, @@ -1152,7 +1442,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { }, "shares_received": 0.0000002, }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "LiquidityPoolDepositResultCodeLiquidityPoolDepositSuccess", }, OperationOutput{ Type: 23, @@ -1174,7 +1466,9 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "reserve_b_min_amount": 0.0000001, "shares": 0.0000004, }, - ClosedAt: hardCodedLedgerClose, + ClosedAt: hardCodedLedgerClose, + OperationResultCode: "OperationResultCodeOpInner", + OperationTraceCode: "LiquidityPoolWithdrawResultCodeLiquidityPoolWithdrawSuccess", }, //OperationOutput{ // Type: 24, diff --git a/internal/transform/schema.go b/internal/transform/schema.go index 8321855c..601ec5b3 100644 --- a/internal/transform/schema.go +++ b/internal/transform/schema.go @@ -64,6 +64,7 @@ type TransactionOutput struct { 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"` } type LedgerTransactionOutput struct { @@ -118,14 +119,16 @@ type AccountSignerOutput struct { // OperationOutput is a representation of an operation that aligns with the BigQuery table history_operations type OperationOutput struct { - SourceAccount string `json:"source_account"` - SourceAccountMuxed string `json:"source_account_muxed,omitempty"` - Type int32 `json:"type"` - TypeString string `json:"type_string"` - OperationDetails map[string]interface{} `json:"details"` //Details is a JSON object that varies based on operation type - TransactionID int64 `json:"transaction_id"` - OperationID int64 `json:"id"` - ClosedAt time.Time `json:"closed_at"` + SourceAccount string `json:"source_account"` + SourceAccountMuxed string `json:"source_account_muxed,omitempty"` + Type int32 `json:"type"` + TypeString string `json:"type_string"` + OperationDetails map[string]interface{} `json:"details"` //Details is a JSON object that varies based on operation type + TransactionID int64 `json:"transaction_id"` + OperationID int64 `json:"id"` + ClosedAt time.Time `json:"closed_at"` + OperationResultCode string `json:"operation_result_code"` + OperationTraceCode string `json:"operation_trace_code"` } // ClaimableBalanceOutput is a representation of a claimable balances that aligns with the BigQuery table claimable_balances diff --git a/internal/transform/transaction.go b/internal/transform/transaction.go index baad3770..a5e6d79f 100644 --- a/internal/transform/transaction.go +++ b/internal/transform/transaction.go @@ -155,6 +155,8 @@ func TransformTransaction(transaction ingest.LedgerTransaction, lhe xdr.LedgerHe return TransactionOutput{}, fmt.Errorf("for ledger %d; transaction %d (transaction id=%d): %v", outputLedgerSequence, transactionIndex, outputTransactionID, err) } + outputTxResultCode := transaction.Result.Result.Result.Code.String() + outputSuccessful := transaction.Result.Successful() transformedTransaction := TransactionOutput{ TransactionHash: outputTransactionHash, @@ -184,6 +186,7 @@ func TransformTransaction(transaction ingest.LedgerTransaction, lhe xdr.LedgerHe SorobanResourcesInstructions: outputSorobanResourcesInstructions, SorobanResourcesReadBytes: outputSorobanResourcesReadBytes, SorobanResourcesWriteBytes: outputSorobanResourcesWriteBytes, + TransactionResultCode: outputTxResultCode, } // Add Muxed Account Details, if exists diff --git a/internal/transform/transaction_test.go b/internal/transform/transaction_test.go index bf21e463..9ca8708b 100644 --- a/internal/transform/transaction_test.go +++ b/internal/transform/transaction_test.go @@ -105,6 +105,7 @@ func makeTransactionTestOutput() (output []TransactionOutput, err error) { SorobanResourcesInstructions: 0, SorobanResourcesReadBytes: 0, SorobanResourcesWriteBytes: 0, + TransactionResultCode: "TransactionResultCodeTxFailed", }, TransactionOutput{ TxEnvelope: "AAAABQAAAABnzACGTDuJFoxqr+C8NHCe0CHFBXLi+YhhNCIILCIpcgAAAAAAABwgAAAAAgAAAACI4aa0pXFSj6qfJuIObLw/5zyugLRGYwxb7wFSr3B9eAAAAAACFPY2AAAAfQAAAAEAAAAAAAAAAAAAAABfBqt0AAAAAQAAABdITDVhQ2dvelFISVc3c1NjNVhkY2ZtUgAAAAABAAAAAQAAAAAcR0GXGO76pFs4y38vJVAanjnLg4emNun7zAx0pHcDGAAAAAIAAAAAAAAAAAAAAAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", @@ -132,10 +133,11 @@ func makeTransactionTestOutput() (output []TransactionOutput, err error) { SorobanResourcesInstructions: 0, SorobanResourcesReadBytes: 0, SorobanResourcesWriteBytes: 0, + TransactionResultCode: "TransactionResultCodeTxFeeBumpInnerSuccess", //inner fee bump success }, TransactionOutput{ TxEnvelope: "AAAAAgAAAAAcR0GXGO76pFs4y38vJVAanjnLg4emNun7zAx0pHcDGAAAAGQBpLyvsiV6gwAAAAIAAAABAAAAAAAAAAAAAAAAXwardAAAAAEAAAAFAAAACgAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAMCAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAABdITDVhQ2dvelFISVc3c1NjNVhkY2ZtUgAAAAABAAAAAQAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAAIAAAAAAAAAAAAAAAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", - TxResult: "AAAAAAAAAGT/////AAAAAQAAAAAAAAAAAAAAAAAAAAA=", + TxResult: "AAAAAAAAAGT////5AAAAAA==", TxMeta: "AAAAAQAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAACAAAAAwAAAAAAAAAFAQIDBAUGBwgJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVU1NEAAAAAGtY3WxokwttAx3Fu/riPvoew/C7WMK8jZONR8Hfs75zAAAAHgAAAAAAAYagAAAAAAAAA+gAAAAAAAAB9AAAAAAAAAAZAAAAAAAAAAEAAAAAAAAABQECAwQFBgcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVVNTRAAAAABrWN1saJMLbQMdxbv64j76HsPwu1jCvI2TjUfB37O+cwAAAB4AAAAAAAGKiAAAAAAAAARMAAAAAAAAAfYAAAAAAAAAGgAAAAAAAAAA", TxFeeMeta: "AAAAAA==", TransactionHash: "a87fef5eeb260269c380f2de456aad72b59bb315aaac777860456e09dac0bafb", @@ -160,6 +162,7 @@ func makeTransactionTestOutput() (output []TransactionOutput, err error) { SorobanResourcesInstructions: 0, SorobanResourcesReadBytes: 0, SorobanResourcesWriteBytes: 0, + TransactionResultCode: "TransactionResultCodeTxInsufficientBalance", }, } return @@ -360,7 +363,7 @@ func makeTransactionTestInput() (transaction []ingest.LedgerTransaction, history Result: xdr.TransactionResult{ FeeCharged: 100, Result: xdr.TransactionResultResult{ - Code: xdr.TransactionResultCodeTxFailed, + Code: xdr.TransactionResultCodeTxInsufficientBalance, Results: genericResultResults, }, }, From 190606ac426e013f9283b4f12b53efd137edaad3 Mon Sep 17 00:00:00 2001 From: sydneynotthecity Date: Tue, 5 Mar 2024 00:12:21 -0600 Subject: [PATCH 2/2] Remove todo --- internal/transform/operation.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/transform/operation.go b/internal/transform/operation.go index cb22c942..5fe3e8af 100644 --- a/internal/transform/operation.go +++ b/internal/transform/operation.go @@ -71,7 +71,6 @@ func TransformOperation(operation xdr.Operation, operationIndex int32, transacti return OperationOutput{}, err } outputOperationResultCode := outputOperationResults[operationIndex].Code.String() - // TODO: add trace code details outputOperationTraceCode, err := mapOperationTrace(*outputOperationResults[operationIndex].Tr) if err != nil { return OperationOutput{}, err