From 2f94b7e20a784ce4e7fd538ee3e2012c31273179 Mon Sep 17 00:00:00 2001 From: Cayod Date: Tue, 19 Dec 2023 17:07:31 -0300 Subject: [PATCH 1/2] Add OperationTypeManageSellOffer operation type to history_assets export --- internal/input/assets.go | 2 +- internal/transform/asset.go | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/input/assets.go b/internal/input/assets.go index 6e29e816..00e83984 100644 --- a/internal/input/assets.go +++ b/internal/input/assets.go @@ -37,7 +37,7 @@ func GetPaymentOperations(start, end uint32, limit int64, isTest bool, isFuture for txIndex, transaction := range transactionSet { for opIndex, op := range transaction.Operations() { - if op.Body.Type == xdr.OperationTypePayment { + if op.Body.Type == xdr.OperationTypePayment || op.Body.Type == xdr.OperationTypeManageSellOffer { assetSlice = append(assetSlice, AssetTransformInput{ Operation: op, OperationIndex: int32(opIndex), diff --git a/internal/transform/asset.go b/internal/transform/asset.go index cbe60395..deb53a5f 100644 --- a/internal/transform/asset.go +++ b/internal/transform/asset.go @@ -15,16 +15,29 @@ func TransformAsset(operation xdr.Operation, operationIndex int32, transactionIn operationID := toid.New(ledgerSeq, int32(transactionIndex), operationIndex).ToInt64() opType := operation.Body.Type - if opType != xdr.OperationTypePayment { + if opType != xdr.OperationTypePayment && opType != xdr.OperationTypeManageSellOffer { return AssetOutput{}, fmt.Errorf("operation of type %d cannot issue an asset (id %d)", opType, operationID) } - op, ok := operation.Body.GetPaymentOp() - if !ok { - return AssetOutput{}, fmt.Errorf("could not access Payment info for this operation (id %d)", operationID) + op := xdr.Asset{} + switch opType { + case xdr.OperationTypeManageSellOffer: + opSellOf, ok := operation.Body.GetManageSellOfferOp() + if ok { + return AssetOutput{}, fmt.Errorf("operation of type ManageSellOfferOp cannot issue an asset (id %d)", operationID) + } + op = opSellOf.Selling + + case xdr.OperationTypePayment: + opPayment, ok := operation.Body.GetPaymentOp() + if !ok { + return AssetOutput{}, fmt.Errorf("could not access Payment info for this operation (id %d)", operationID) + } + op = opPayment.Asset + } - outputAsset, err := transformSingleAsset(op.Asset) + outputAsset, err := transformSingleAsset(op) if err != nil { return AssetOutput{}, fmt.Errorf("%s (id %d)", err.Error(), operationID) } From ae74bafca41d1ccc3b3b15e08ddc088a5f8506d2 Mon Sep 17 00:00:00 2001 From: Cayod Date: Wed, 24 Jan 2024 15:01:33 -0300 Subject: [PATCH 2/2] Change variable name from op to asset --- internal/transform/asset.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/transform/asset.go b/internal/transform/asset.go index deb53a5f..beec2540 100644 --- a/internal/transform/asset.go +++ b/internal/transform/asset.go @@ -19,25 +19,25 @@ func TransformAsset(operation xdr.Operation, operationIndex int32, transactionIn return AssetOutput{}, fmt.Errorf("operation of type %d cannot issue an asset (id %d)", opType, operationID) } - op := xdr.Asset{} + asset := xdr.Asset{} switch opType { case xdr.OperationTypeManageSellOffer: opSellOf, ok := operation.Body.GetManageSellOfferOp() if ok { return AssetOutput{}, fmt.Errorf("operation of type ManageSellOfferOp cannot issue an asset (id %d)", operationID) } - op = opSellOf.Selling + asset = opSellOf.Selling case xdr.OperationTypePayment: opPayment, ok := operation.Body.GetPaymentOp() if !ok { return AssetOutput{}, fmt.Errorf("could not access Payment info for this operation (id %d)", operationID) } - op = opPayment.Asset + asset = opPayment.Asset } - outputAsset, err := transformSingleAsset(op) + outputAsset, err := transformSingleAsset(asset) if err != nil { return AssetOutput{}, fmt.Errorf("%s (id %d)", err.Error(), operationID) }