Skip to content

Commit

Permalink
new tx types parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rajranjan0608 committed Dec 2, 2024
1 parent 95395c5 commit ba264bb
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 16 deletions.
20 changes: 20 additions & 0 deletions mapper/pchain/tx_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ func GetTxDependenciesIDs(tx txs.UnsignedTx) ([]ids.ID, error) {
ins = unsignedTx.Ins
case *txs.TransferSubnetOwnershipTx:
ins = unsignedTx.Ins
case *txs.ConvertSubnetToL1Tx:
ins = unsignedTx.Ins
case *txs.RegisterL1ValidatorTx:
ins = unsignedTx.Ins
case *txs.IncreaseL1ValidatorBalanceTx:
ins = unsignedTx.Ins
case *txs.SetL1ValidatorWeightTx:
ins = unsignedTx.Ins
case *txs.DisableL1ValidatorTx:
ins = unsignedTx.Ins
case *txs.BaseTx:
ins = unsignedTx.Ins
default:
Expand Down Expand Up @@ -167,6 +177,16 @@ func (d *SingleTxDependency) GetUtxos() map[avax.UTXOID]*avax.UTXO {
outsToAdd = append(outsToAdd, unsignedTx.Stake()...)
case *txs.TransferSubnetOwnershipTx:
outsToAdd = append(outsToAdd, unsignedTx.Outputs()...)
case *txs.ConvertSubnetToL1Tx:
outsToAdd = append(outsToAdd, unsignedTx.Outputs()...)
case *txs.RegisterL1ValidatorTx:
outsToAdd = append(outsToAdd, unsignedTx.Outputs()...)
case *txs.IncreaseL1ValidatorBalanceTx:
outsToAdd = append(outsToAdd, unsignedTx.Outputs()...)
case *txs.SetL1ValidatorWeightTx:
outsToAdd = append(outsToAdd, unsignedTx.Outputs()...)
case *txs.DisableL1ValidatorTx:
outsToAdd = append(outsToAdd, unsignedTx.Outputs()...)
case *txs.BaseTx:
outsToAdd = append(outsToAdd, unsignedTx.Outputs()...)
default:
Expand Down
35 changes: 35 additions & 0 deletions mapper/pchain/tx_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ func (t *TxParser) Parse(signedTx *txs.Tx) (*types.Transaction, error) {
case *txs.TransferSubnetOwnershipTx:
txType = OpTransferSubnetOwnership
ops, err = t.parseTransferSubnetOwnershipTx(txID, unsignedTx)
case *txs.ConvertSubnetToL1Tx:
txType = OpConvertSubnetToL1Tx
ops, err = t.parseConvertSubnetToL1Tx(txID, unsignedTx)
case *txs.RegisterL1ValidatorTx:
txType = OpRegisterL1ValidatorTx
ops, err = t.parseRegisterL1ValidatorTx(txID, unsignedTx)
case *txs.IncreaseL1ValidatorBalanceTx:
txType = OpIncreaseL1ValidatorBalanceTx
ops, err = t.parseIncreaseL1ValidatorBalanceTx(txID, unsignedTx)
case *txs.SetL1ValidatorWeightTx:
txType = OpSetL1ValidatorWeightTx
ops, err = t.parseSetL1ValidatorWeightTx(txID, unsignedTx)
case *txs.DisableL1ValidatorTx:
txType = OpDisableL1ValidatorTx
ops, err = t.parseDisableL1ValidatorTx(txID, unsignedTx)
case *txs.BaseTx:
txType = OpBase
ops, err = t.parseBaseTx(txID, unsignedTx)
Expand Down Expand Up @@ -420,6 +435,26 @@ func (t *TxParser) parseCreateChainTx(txID ids.ID, tx *txs.CreateChainTx) (*txOp
return t.baseTxToCombinedOperations(txID, &tx.BaseTx, OpCreateChain)
}

func (t *TxParser) parseConvertSubnetToL1Tx(txID ids.ID, tx *txs.ConvertSubnetToL1Tx) (*txOps, error) {
return t.baseTxToCombinedOperations(txID, &tx.BaseTx, OpConvertSubnetToL1Tx)
}

func (t *TxParser) parseRegisterL1ValidatorTx(txID ids.ID, tx *txs.RegisterL1ValidatorTx) (*txOps, error) {
return t.baseTxToCombinedOperations(txID, &tx.BaseTx, OpRegisterL1ValidatorTx)
}

func (t *TxParser) parseIncreaseL1ValidatorBalanceTx(txID ids.ID, tx *txs.IncreaseL1ValidatorBalanceTx) (*txOps, error) {
return t.baseTxToCombinedOperations(txID, &tx.BaseTx, OpIncreaseL1ValidatorBalanceTx)
}

func (t *TxParser) parseSetL1ValidatorWeightTx(txID ids.ID, tx *txs.SetL1ValidatorWeightTx) (*txOps, error) {
return t.baseTxToCombinedOperations(txID, &tx.BaseTx, OpSetL1ValidatorWeightTx)
}

func (t *TxParser) parseDisableL1ValidatorTx(txID ids.ID, tx *txs.DisableL1ValidatorTx) (*txOps, error) {
return t.baseTxToCombinedOperations(txID, &tx.BaseTx, OpDisableL1ValidatorTx)
}

func (t *TxParser) baseTxToCombinedOperations(txID ids.ID, tx *txs.BaseTx, txType string) (*txOps, error) {
ops := newTxOps(t.cfg.IsConstruction)

Expand Down
37 changes: 21 additions & 16 deletions mapper/pchain/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ import (
)

const (
OpImportAvax = "IMPORT_AVAX"
OpExportAvax = "EXPORT_AVAX"
OpAddValidator = "ADD_VALIDATOR"
OpAddPermissionlessValidator = "ADD_PERMISSIONLESS_VALIDATOR"
OpAddDelegator = "ADD_DELEGATOR"
OpAddPermissionlessDelegator = "ADD_PERMISSIONLESS_DELEGATOR"
OpRewardValidator = "REWARD_VALIDATOR"
OpCreateChain = "CREATE_CHAIN"
OpCreateSubnet = "CREATE_SUBNET"
OpAddSubnetValidator = "ADD_SUBNET_VALIDATOR"
OpRemoveSubnetValidator = "REMOVE_SUBNET_VALIDATOR"
OpTransformSubnetValidator = "TRANSFORM_SUBNET_VALIDATOR"
OpAdvanceTime = "ADVANCE_TIME"
OpBase = "BASE"
OpTransferSubnetOwnership = "TRANSFER_SUBNET_OWNERSHIP"
OpDummyBase = "DUMMY_BASE"
OpImportAvax = "IMPORT_AVAX"
OpExportAvax = "EXPORT_AVAX"
OpAddValidator = "ADD_VALIDATOR"
OpAddPermissionlessValidator = "ADD_PERMISSIONLESS_VALIDATOR"
OpAddDelegator = "ADD_DELEGATOR"
OpAddPermissionlessDelegator = "ADD_PERMISSIONLESS_DELEGATOR"
OpRewardValidator = "REWARD_VALIDATOR"
OpCreateChain = "CREATE_CHAIN"
OpCreateSubnet = "CREATE_SUBNET"
OpAddSubnetValidator = "ADD_SUBNET_VALIDATOR"
OpRemoveSubnetValidator = "REMOVE_SUBNET_VALIDATOR"
OpTransformSubnetValidator = "TRANSFORM_SUBNET_VALIDATOR"
OpAdvanceTime = "ADVANCE_TIME"
OpBase = "BASE"
OpTransferSubnetOwnership = "TRANSFER_SUBNET_OWNERSHIP"
OpDummyBase = "DUMMY_BASE"
OpConvertSubnetToL1Tx = "CONVERT_SUBNET_TO_L1_TX"
OpRegisterL1ValidatorTx = "REGISTER_L1_VALIDATOR_TX"
OpIncreaseL1ValidatorBalanceTx = "INCREASE_L1_VALIDATOR_BALANCE_TX"
OpSetL1ValidatorWeightTx = "SET_L1_VALIDATOR_WEIGHT_TX"
OpDisableL1ValidatorTx = "DISABLE_L1_VALIDATOR_TX"

OpTypeImport = "IMPORT"
OpTypeExport = "EXPORT"
Expand Down
10 changes: 10 additions & 0 deletions service/backend/pchain/construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ func getTxInputs(
return utx.Ins, nil
case *txs.TransferSubnetOwnershipTx:
return utx.Ins, nil
case *txs.ConvertSubnetToL1Tx:
return utx.Ins, nil
case *txs.RegisterL1ValidatorTx:
return utx.Ins, nil
case *txs.IncreaseL1ValidatorBalanceTx:
return utx.Ins, nil
case *txs.SetL1ValidatorWeightTx:
return utx.Ins, nil
case *txs.DisableL1ValidatorTx:
return utx.Ins, nil
case *txs.BaseTx:
return utx.Ins, nil
default:
Expand Down

0 comments on commit ba264bb

Please sign in to comment.