Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Oct 25, 2022
1 parent ead1b4b commit f725967
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions constants/p_chain_operations.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package constants

type PChainOp uint16
type PChainTxType uint16

const (
ImportAvax PChainOp = iota + 1
ImportAvax PChainTxType = iota + 1
ExportAvax
AddValidator
AddPermissionlessValidator
Expand All @@ -18,7 +18,7 @@ const (
AdvanceTime
)

func (op PChainOp) String() string {
func (op PChainTxType) String() string {
switch op {
case ImportAvax:
return "IMPORT_AVAX"
Expand Down Expand Up @@ -52,7 +52,7 @@ func (op PChainOp) String() string {
}
}

var pOpsStrings = []string{
var pTxTypesStrings = []string{
ImportAvax.String(),
ExportAvax.String(),
AddValidator.String(),
Expand All @@ -67,4 +67,4 @@ var pOpsStrings = []string{
AddPermissionlessDelegator.String(),
}

func PChainOps() []string { return pOpsStrings }
func PChainTxTypes() []string { return pTxTypesStrings }
12 changes: 6 additions & 6 deletions mapper/pchain/tx_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions mapper/pchain/tx_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++
}

Expand Down
2 changes: 1 addition & 1 deletion service/backend/pchain/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f725967

Please sign in to comment.