From a8122bb52f92789c1de3784023421197ae9fb017 Mon Sep 17 00:00:00 2001 From: Lutty Date: Sun, 20 Feb 2022 15:16:09 +0800 Subject: [PATCH] fix bug --- rosetta/services/tx_operation.go | 50 ++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/rosetta/services/tx_operation.go b/rosetta/services/tx_operation.go index 2989ab7ce..dd1a466da 100644 --- a/rosetta/services/tx_operation.go +++ b/rosetta/services/tx_operation.go @@ -763,28 +763,20 @@ func newSameShardTransferNativeOperations( } else { opIndex = 0 } - subOperationID := &types.OperationIdentifier{ - Index: opIndex, - } - subAmount := &types.Amount{ - Value: negativeBigValue(amount), - Currency: &common.NativeCurrency, - } - // Addition operation elements - addOperationID := &types.OperationIdentifier{ - Index: subOperationID.Index + 1, - } - addRelatedID := []*types.OperationIdentifier{ - subOperationID, - } - addAmount := &types.Amount{ - Value: amount.String(), - Currency: &common.NativeCurrency, - } + var subOperationID *types.OperationIdentifier + var op []*types.Operation - op := []*types.Operation{} if from != nil { + subOperationID = &types.OperationIdentifier{ + Index: opIndex, + } + + subAmount := &types.Amount{ + Value: negativeBigValue(amount), + Currency: &common.NativeCurrency, + } + op = append(op, &types.Operation{ OperationIdentifier: subOperationID, Type: common.NativeTransferOperation, @@ -794,6 +786,26 @@ func newSameShardTransferNativeOperations( }) } if to != nil { + var addOperationID *types.OperationIdentifier + var addRelatedID []*types.OperationIdentifier + if subOperationID == nil { + addOperationID = &types.OperationIdentifier{ + Index: opIndex, + } + } else { + addOperationID = &types.OperationIdentifier{ + Index: subOperationID.Index + 1, + } + addRelatedID = []*types.OperationIdentifier{ + subOperationID, + } + } + + addAmount := &types.Amount{ + Value: amount.String(), + Currency: &common.NativeCurrency, + } + op = append(op, &types.Operation{ OperationIdentifier: addOperationID, RelatedOperations: addRelatedID,