Skip to content

Commit

Permalink
fixup! extend faucet package support for other transactions
Browse files Browse the repository at this point in the history
vochaintx: add GetFaucetPackage method
  • Loading branch information
altergui committed Sep 5, 2024
1 parent 37e269c commit 65cb171
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
29 changes: 3 additions & 26 deletions vochain/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions vochain/transaction/vochaintx/vochaintx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 65cb171

Please sign in to comment.