diff --git a/vochain/transaction/transaction.go b/vochain/transaction/transaction.go index 62efdf5d5..783ab3bfc 100644 --- a/vochain/transaction/transaction.go +++ b/vochain/transaction/transaction.go @@ -597,32 +597,9 @@ func (t *TransactionHandler) checkAccountCanPayCost(txType models.TxType, vtx *v if cost > 0 { // check if faucet package can pay for the transaction - canFaucetPackagePay := false - switch vtx.Tx.Payload.(type) { - case *models.Tx_SetAccount: - tx := vtx.Tx.GetSetAccount() - canFaucetPackagePay, err = t.checkFaucetPackageAndTransfer(tx.FaucetPackage, cost, txSenderAddress, vtx.TxID[:], false) - if err != nil { - return nil, nil, err - } - case *models.Tx_DelSIK: - tx := vtx.Tx.GetDelSIK() - canFaucetPackagePay, err = t.checkFaucetPackageAndTransfer(tx.FaucetPackage, cost, txSenderAddress, vtx.TxID[:], false) - if err != nil { - return nil, nil, err - } - case *models.Tx_SetSIK: - tx := vtx.Tx.GetSetSIK() - canFaucetPackagePay, err = t.checkFaucetPackageAndTransfer(tx.FaucetPackage, cost, txSenderAddress, vtx.TxID[:], false) - if err != nil { - return nil, nil, err - } - case *models.Tx_SetProcess: - tx := vtx.Tx.GetSetProcess() - canFaucetPackagePay, err = t.checkFaucetPackageAndTransfer(tx.FaucetPackage, cost, txSenderAddress, vtx.TxID[:], false) - if err != nil { - return nil, nil, err - } + canFaucetPackagePay, err := t.checkFaucetPackageAndTransfer(vtx.GetFaucetPackage(), cost, txSenderAddress, vtx.TxID[:], false) + if err != nil { + return nil, nil, err } // if faucet cannot pay for it, check tx sender balance diff --git a/vochain/transaction/vochaintx/vochaintx.go b/vochain/transaction/vochaintx/vochaintx.go index f413e5e3b..b18ec184b 100644 --- a/vochain/transaction/vochaintx/vochaintx.go +++ b/vochain/transaction/vochaintx/vochaintx.go @@ -62,3 +62,23 @@ type TokenTransfer struct { Amount uint64 TxHash []byte } + +// GetFaucetPackage returns the FaucetPackage found inside the tx.Tx.Payload, or nil if not found. +func (tx *Tx) GetFaucetPackage() *models.FaucetPackage { + switch tx.Tx.Payload.(type) { + case *models.Tx_NewProcess: + return tx.Tx.GetNewProcess().GetFaucetPackage() + case *models.Tx_SetProcess: + return tx.Tx.GetSetProcess().GetFaucetPackage() + case *models.Tx_SetAccount: + return tx.Tx.GetSetAccount().GetFaucetPackage() + case *models.Tx_CollectFaucet: + return tx.Tx.GetCollectFaucet().GetFaucetPackage() + case *models.Tx_SetSIK: + return tx.Tx.GetSetSIK().GetFaucetPackage() + case *models.Tx_DelSIK: + return tx.Tx.GetDelSIK().GetFaucetPackage() + default: + return nil + } +}