From f7259678fa9e5c2e3e2acf4a51d0ec7c618e0639 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Tue, 25 Oct 2022 22:39:33 +0200 Subject: [PATCH] nit --- cmd/server/main.go | 2 +- constants/p_chain_operations.go | 10 +++++----- mapper/pchain/tx_parser.go | 12 ++++++------ mapper/pchain/tx_parser_test.go | 16 ++++++++-------- service/backend/pchain/network.go | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index baede6a2..0ecbfdf7 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -153,7 +153,7 @@ func main() { var operationTypes []string operationTypes = append(operationTypes, constants.CChainOps()...) - operationTypes = append(operationTypes, constants.PChainOps()...) + operationTypes = append(operationTypes, constants.PChainTxTypes()...) asserter, err := asserter.NewServer( operationTypes, // supported operation types diff --git a/constants/p_chain_operations.go b/constants/p_chain_operations.go index 352ecbae..451bbd3a 100644 --- a/constants/p_chain_operations.go +++ b/constants/p_chain_operations.go @@ -1,9 +1,9 @@ package constants -type PChainOp uint16 +type PChainTxType uint16 const ( - ImportAvax PChainOp = iota + 1 + ImportAvax PChainTxType = iota + 1 ExportAvax AddValidator AddPermissionlessValidator @@ -18,7 +18,7 @@ const ( AdvanceTime ) -func (op PChainOp) String() string { +func (op PChainTxType) String() string { switch op { case ImportAvax: return "IMPORT_AVAX" @@ -52,7 +52,7 @@ func (op PChainOp) String() string { } } -var pOpsStrings = []string{ +var pTxTypesStrings = []string{ ImportAvax.String(), ExportAvax.String(), AddValidator.String(), @@ -67,4 +67,4 @@ var pOpsStrings = []string{ AddPermissionlessDelegator.String(), } -func PChainOps() []string { return pOpsStrings } +func PChainTxTypes() []string { return pTxTypesStrings } diff --git a/mapper/pchain/tx_parser.go b/mapper/pchain/tx_parser.go index 62ea26fd..ad377c14 100644 --- a/mapper/pchain/tx_parser.go +++ b/mapper/pchain/tx_parser.go @@ -90,7 +90,7 @@ func NewTxParser( func (t *TxParser) Parse(signedTx *txs.Tx) (*types.Transaction, error) { var ( ops *txOps - txType constants.PChainOp + txType constants.PChainTxType err error ) @@ -354,7 +354,7 @@ func (t *TxParser) parseCreateChainTx(txID ids.ID, tx *txs.CreateChainTx) (*txOp return t.baseTxToCombinedOperations(txID, &tx.BaseTx, constants.CreateChain) } -func (t *TxParser) baseTxToCombinedOperations(txID ids.ID, tx *txs.BaseTx, txType constants.PChainOp) (*txOps, error) { +func (t *TxParser) baseTxToCombinedOperations(txID ids.ID, tx *txs.BaseTx, txType constants.PChainTxType) (*txOps, error) { ops := newTxOps(t.cfg.IsConstruction) err := t.insToOperations(ops, txType, tx.Ins, OpTypeInput) @@ -372,7 +372,7 @@ func (t *TxParser) baseTxToCombinedOperations(txID ids.ID, tx *txs.BaseTx, txTyp func (t *TxParser) insToOperations( inOps *txOps, - opType constants.PChainOp, + opType constants.PChainTxType, txIns []*avax.TransferableInput, metaType string, ) error { @@ -477,7 +477,7 @@ func (t *TxParser) buildAmount(value *big.Int, assetID ids.ID) (*types.Amount, e func (t *TxParser) outsToOperations( outOps *txOps, - opType constants.PChainOp, + opType constants.PChainTxType, txID ids.ID, txOut []*avax.TransferableOutput, metaType string, @@ -536,7 +536,7 @@ func (t *TxParser) outsToOperations( func (t *TxParser) utxosToOperations( outOps *txOps, - opType constants.PChainOp, + opType constants.PChainTxType, utxos []*avax.UTXO, metaType string, chainIDAlias constants.ChainIDAlias, @@ -598,7 +598,7 @@ func (t *TxParser) buildOutputOperation( startIndex int, txID ids.ID, outIndex uint32, - opType constants.PChainOp, + opType constants.PChainTxType, metaType string, chainIDAlias constants.ChainIDAlias, ) (*types.Operation, error) { diff --git a/mapper/pchain/tx_parser_test.go b/mapper/pchain/tx_parser_test.go index aebd15c9..f48ee450 100644 --- a/mapper/pchain/tx_parser_test.go +++ b/mapper/pchain/tx_parser_test.go @@ -135,7 +135,7 @@ func TestMapAddValidatorTx(t *testing.T) { total := len(addValidatorTx.Ins) + len(addValidatorTx.Outs) + len(addValidatorTx.StakeOuts) assert.Equal(t, total, len(rosettaTransaction.Operations)) - cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.AddValidator.String(), OpTypeStakeOutput) + cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.AddValidator, OpTypeStakeOutput) assert.Equal(t, 2, cntTxType) assert.Equal(t, 1, cntInputMeta) @@ -164,7 +164,7 @@ func TestMapAddDelegatorTx(t *testing.T) { total := len(addDelegatorTx.Ins) + len(addDelegatorTx.Outs) + len(addDelegatorTx.StakeOuts) assert.Equal(t, total, len(rosettaTransaction.Operations)) - cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.AddDelegator.String(), OpTypeStakeOutput) + cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.AddDelegator, OpTypeStakeOutput) assert.Equal(t, 3, cntTxType) assert.Equal(t, 1, cntInputMeta) @@ -211,7 +211,7 @@ func TestMapImportTx(t *testing.T) { total := len(importTx.Ins) + len(importTx.Outs) + len(importTx.ImportedInputs) - 2 // - 1 for the multisig output assert.Equal(t, total, len(rosettaTransaction.Operations)) - cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.ImportAvax.String(), OpTypeImport) + cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.ImportAvax, OpTypeImport) assert.Equal(t, 2, cntTxType) assert.Equal(t, 0, cntInputMeta) @@ -243,7 +243,7 @@ func TestMapNonConstructionImportTx(t *testing.T) { total := len(importTx.Ins) + len(importTx.Outs) + len(importTx.ImportedInputs) - 3 // - 1 for the multisig output assert.Equal(t, total, len(rosettaTransaction.Operations)) - cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.ImportAvax.String(), OpTypeImport) + cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.ImportAvax, OpTypeImport) assert.Equal(t, 1, cntTxType) assert.Equal(t, 0, cntInputMeta) @@ -297,7 +297,7 @@ func TestMapExportTx(t *testing.T) { total := len(exportTx.Ins) + len(exportTx.Outs) + len(exportTx.ExportedOutputs) assert.Equal(t, total, len(rosettaTransaction.Operations)) - cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.ExportAvax.String(), OpTypeExport) + cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.ExportAvax, OpTypeExport) assert.Equal(t, 3, cntTxType) assert.Equal(t, 1, cntInputMeta) @@ -326,7 +326,7 @@ func TestMapNonConstructionExportTx(t *testing.T) { total := len(exportTx.Ins) + len(exportTx.Outs) assert.Equal(t, total, len(rosettaTransaction.Operations)) - cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.ExportAvax.String(), OpTypeExport) + cntTxType, cntInputMeta, cntOutputMeta, cntMetaType := verifyRosettaTransaction(rosettaTransaction.Operations, rosConst.ExportAvax, OpTypeExport) assert.Equal(t, 2, cntTxType) assert.Equal(t, 1, cntInputMeta) @@ -359,14 +359,14 @@ func TestMapNonConstructionExportTx(t *testing.T) { assert.Equal(t, []*types.Operation{out}, exportOutputs) } -func verifyRosettaTransaction(operations []*types.Operation, txType string, metaType string) (int, int, int, int) { +func verifyRosettaTransaction(operations []*types.Operation, txType rosConst.PChainTxType, metaType string) (int, int, int, int) { cntOpInputMeta := 0 cntOpOutputMeta := 0 cntTxType := 0 cntMetaType := 0 for _, v := range operations { - if v.Type == txType { + if v.Type == txType.String() { cntTxType++ } diff --git a/service/backend/pchain/network.go b/service/backend/pchain/network.go index 41437e35..cbacb3a7 100644 --- a/service/backend/pchain/network.go +++ b/service/backend/pchain/network.go @@ -71,7 +71,7 @@ func (b *Backend) NetworkOptions(ctx context.Context, request *types.NetworkRequ }, Allow: &types.Allow{ OperationStatuses: mapper.OperationStatuses, - OperationTypes: constants.PChainOps(), + OperationTypes: constants.PChainTxTypes(), CallMethods: pmapper.CallMethods, Errors: service.Errors, HistoricalBalanceLookup: false,