55
66 "github.com/spf13/cobra"
77
8+ "github.com/oasisprotocol/oasis-core/go/common/quantity"
89 staking "github.com/oasisprotocol/oasis-core/go/staking/api"
910 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
1011 sdkSignature "github.com/oasisprotocol/oasis-sdk/client-sdk/go/crypto/signature"
@@ -60,6 +61,7 @@ var transferCmd = &cobra.Command{
6061 var sigTx , meta interface {}
6162 switch npa .ParaTime {
6263 case nil :
64+ // Consensus layer transfer.
6365 common .CheckForceErr (common .CheckAddressIsConsensusCapable (cfg , toAddr .String ()))
6466 if toEthAddr != nil {
6567 common .CheckForceErr (common .CheckAddressIsConsensusCapable (cfg , toEthAddr .Hex ()))
@@ -69,29 +71,46 @@ var transferCmd = &cobra.Command{
6971 cobra .CheckErr ("consensus layer only supports the native denomination" )
7072 }
7173
72- // Consensus layer transfer.
73- amount , err := helpers .ParseConsensusDenomination (npa .Network , amount )
74+ amt , err := helpers .ParseConsensusDenomination (npa .Network , amount )
7475 cobra .CheckErr (err )
7576
7677 // Prepare transaction.
77- tx := staking . NewTransferTx ( 0 , nil , & staking.Transfer {
78+ innerTx := staking.Transfer {
7879 To : toAddr .ConsensusAddress (),
79- Amount : * amount ,
80- })
81-
80+ Amount : * amt ,
81+ }
82+ tx := staking .NewTransferTx (0 , nil , & innerTx )
83+ if subtractFee {
84+ var fee * quantity.Quantity
85+ _ , fee , err = common .PrepareConsensusTransaction (ctx , npa , acc .ConsensusSigner (), conn , tx )
86+ cobra .CheckErr (err )
87+ err = amt .Sub (fee )
88+ cobra .CheckErr (err )
89+ innerTx .Amount = * amt
90+ tx = staking .NewTransferTx (0 , nil , & innerTx )
91+ }
8292 sigTx , err = common .SignConsensusTransaction (ctx , npa , acc , conn , tx )
8393 cobra .CheckErr (err )
8494 default :
8595 // ParaTime transfer.
86- amountBaseUnits , err := helpers .ParseParaTimeDenomination (npa .ParaTime , amount , types .Denomination (denom ))
96+ amtBaseUnits , err := helpers .ParseParaTimeDenomination (npa .ParaTime , amount , types .Denomination (denom ))
8797 cobra .CheckErr (err )
8898
8999 // Prepare transaction.
90- tx := accounts . NewTransferTx ( nil , & accounts.Transfer {
100+ innerTx := accounts.Transfer {
91101 To : * toAddr ,
92- Amount : * amountBaseUnits ,
93- })
94-
102+ Amount : * amtBaseUnits ,
103+ }
104+ tx := accounts .NewTransferTx (nil , & innerTx )
105+ if subtractFee {
106+ var fee * quantity.Quantity
107+ _ , fee , _ , err = common .PrepareParatimeTransaction (ctx , npa , acc , conn , tx )
108+ cobra .CheckErr (err )
109+ err = amtBaseUnits .Amount .Sub (fee )
110+ cobra .CheckErr (err )
111+ innerTx .Amount = * amtBaseUnits
112+ tx = accounts .NewTransferTx (nil , & innerTx )
113+ }
95114 txDetails := sdkSignature.TxDetails {OrigTo : toEthAddr }
96115 sigTx , meta , err = common .SignParaTimeTransaction (ctx , npa , acc , conn , tx , & txDetails )
97116 cobra .CheckErr (err )
@@ -102,6 +121,7 @@ var transferCmd = &cobra.Command{
102121}
103122
104123func init () {
124+ transferCmd .Flags ().AddFlagSet (SubtractFeeFlags )
105125 transferCmd .Flags ().AddFlagSet (common .SelectorFlags )
106126 transferCmd .Flags ().AddFlagSet (common .RuntimeTxFlags )
107127 transferCmd .Flags ().AddFlagSet (common .ForceFlag )
0 commit comments