-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx_withdraw_from_subaccount.go
70 lines (61 loc) · 2.03 KB
/
tx_withdraw_from_subaccount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cli
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
assettypes "github.com/furyanprotocol/v4-chain/protocol/x/assets/types"
"github.com/furyanprotocol/v4-chain/protocol/x/sending/types"
satypes "github.com/furyanprotocol/v4-chain/protocol/x/subaccounts/types"
"github.com/spf13/cast"
"github.com/spf13/cobra"
)
// CmdWithdrawFromSubaccount initiates a transfer from sender (an `x/subaccounts` subaccount)
// to a recipient (an `x/banks` account).
func CmdWithdrawFromSubaccount() *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw-from-subaccount [sender_key_or_address] [sender_subaccount_number] [recipient_address] [quantums]",
Short: "Withdraw funds from a subaccount to an account.",
Long: `Withdraw funds from a subaccount to an account.
Note, the '--from' flag is ignored as it is implied from [sender_key_or_address].
[sender_key_or_address] and [sender_subaccount_number] together specify the sender subaccount.
[quantums] specifies the amount to withdraw.
`,
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argSenderOwner := args[0]
err = cmd.Flags().Set(flags.FlagFrom, argSenderOwner)
if err != nil {
return err
}
argSenderNumber, err := cast.ToUint32E(args[1])
if err != nil {
return err
}
// Recipient address validation done in `ValidateBasic()` below.
argRecipient := args[2]
argAmount, err := cast.ToUint64E(args[3])
if err != nil {
return err
}
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgWithdrawFromSubaccount(
satypes.SubaccountId{
Owner: clientCtx.GetFromAddress().String(),
Number: argSenderNumber,
},
argRecipient,
assettypes.AssetUsdc.Id,
argAmount,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}