Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix balance changes bug for soroban #207

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/export_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var operationsCmd = &cobra.Command{
numFailures := 0
totalNumBytes := 0
for _, transformInput := range operations {
transformed, err := transform.TransformOperation(transformInput.Operation, transformInput.OperationIndex, transformInput.Transaction, transformInput.LedgerSeqNum, transformInput.LedgerCloseMeta)
transformed, err := transform.TransformOperation(transformInput.Operation, transformInput.OperationIndex, transformInput.Transaction, transformInput.LedgerSeqNum, transformInput.LedgerCloseMeta, env.NetworkPassphrase)
if err != nil {
txIndex := transformInput.Transaction.Index
cmdLogger.LogError(fmt.Errorf("could not transform operation %d in transaction %d in ledger %d: %v", transformInput.OperationIndex, txIndex, transformInput.LedgerSeqNum, err))
Expand Down
4 changes: 4 additions & 0 deletions internal/transform/diagnostic_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func TransformDiagnosticEvent(transaction ingest.LedgerTransaction, lhe xdr.Ledg
return []DiagnosticEventOutput{}, nil, false
}

if transactionMeta.SorobanMeta == nil {
return []DiagnosticEventOutput{}, nil, false
}

var transformedDiagnosticEvents []DiagnosticEventOutput

for _, diagnoticEvent := range transactionMeta.SorobanMeta.DiagnosticEvents {
Expand Down
12 changes: 6 additions & 6 deletions internal/transform/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type liquidityPoolDelta struct {
}

// TransformOperation converts an operation from the history archive ingestion system into a form suitable for BigQuery
func TransformOperation(operation xdr.Operation, operationIndex int32, transaction ingest.LedgerTransaction, ledgerSeq int32, ledgerCloseMeta xdr.LedgerCloseMeta) (OperationOutput, error) {
func TransformOperation(operation xdr.Operation, operationIndex int32, transaction ingest.LedgerTransaction, ledgerSeq int32, ledgerCloseMeta xdr.LedgerCloseMeta, network string) (OperationOutput, error) {
outputTransactionID := toid.New(ledgerSeq, int32(transaction.Index), 0).ToInt64()
outputOperationID := toid.New(ledgerSeq, int32(transaction.Index), operationIndex+1).ToInt64() //operationIndex needs +1 increment to stay in sync with ingest package

Expand All @@ -51,7 +51,7 @@ func TransformOperation(operation xdr.Operation, operationIndex int32, transacti
return OperationOutput{}, fmt.Errorf("The operation type (%d) is negative for operation %d (operation id=%d)", outputOperationType, operationIndex, outputOperationID)
}

outputDetails, err := extractOperationDetails(operation, transaction, operationIndex)
outputDetails, err := extractOperationDetails(operation, transaction, operationIndex, network)
if err != nil {
return OperationOutput{}, err
}
Expand Down Expand Up @@ -474,7 +474,7 @@ func addOperationFlagToOperationDetails(result map[string]interface{}, flag uint
result[prefix+"flags_s"] = stringFlags
}

func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerTransaction, operationIndex int32) (map[string]interface{}, error) {
func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerTransaction, operationIndex int32, network string) (map[string]interface{}, error) {
details := map[string]interface{}{}
sourceAccount := getOperationSourceAccount(operation, transaction)
operationType := operation.Body.Type
Expand Down Expand Up @@ -967,7 +967,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT
}
details["parameters"] = params

if balanceChanges, err := parseAssetBalanceChangesFromContractEvents(transaction); err != nil {
if balanceChanges, err := parseAssetBalanceChangesFromContractEvents(transaction, network); err != nil {
return nil, err
} else {
details["asset_balance_changes"] = balanceChanges
Expand Down Expand Up @@ -1739,7 +1739,7 @@ func (operation *transactionOperationWrapper) parseAssetBalanceChangesFromContra
return balanceChanges, nil
}

func parseAssetBalanceChangesFromContractEvents(transaction ingest.LedgerTransaction) ([]map[string]interface{}, error) {
func parseAssetBalanceChangesFromContractEvents(transaction ingest.LedgerTransaction, network string) ([]map[string]interface{}, error) {
balanceChanges := []map[string]interface{}{}

diagnosticEvents, err := transaction.GetDiagnosticEvents()
Expand All @@ -1753,7 +1753,7 @@ func parseAssetBalanceChangesFromContractEvents(transaction ingest.LedgerTransac
// Parse the xdr contract event to contractevents.StellarAssetContractEvent model

// has some convenience like to/from attributes are expressed in strkey format for accounts(G...) and contracts(C...)
if sacEvent, err := contractevents.NewStellarAssetContractEvent(&contractEvent, "Test SDF Future Network ; October 2022"); err == nil {
if sacEvent, err := contractevents.NewStellarAssetContractEvent(&contractEvent, network); err == nil {
switch sacEvent.GetType() {
case contractevents.EventTypeTransfer:
transferEvt := sacEvent.(*contractevents.TransferEvent)
Expand Down
2 changes: 1 addition & 1 deletion internal/transform/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestTransformOperation(t *testing.T) {
}

for _, test := range tests {
actualOutput, actualError := TransformOperation(test.input.operation, test.input.index, test.input.transaction, 0, test.input.ledgerClosedMeta)
actualOutput, actualError := TransformOperation(test.input.operation, test.input.index, test.input.transaction, 0, test.input.ledgerClosedMeta, "")
assert.Equal(t, test.wantErr, actualError)
assert.Equal(t, test.wantOutput, actualOutput)
}
Expand Down
Loading