forked from AstraProtocol/astra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx_receivercommit.go
90 lines (77 loc) · 2.25 KB
/
tx_receivercommit.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package cli
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"strconv"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/dungtt-astra/astra/v3/x/channel/types"
"github.com/spf13/cobra"
)
var _ = strconv.Itoa(0)
func CmdReceivercommit() *cobra.Command {
cmd := &cobra.Command{
Use: "receivercommit [receiver-addr] [channelid] [cointoreceiver] [cointohtlc] [cointransfer] [hashcodehtlc] [timelockhtlc] [hashcodedest] [timelocksender] [multisig-addr]",
Short: "Broadcast message receivercommit",
Args: cobra.ExactArgs(10),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argReceiverAddr := args[0]
argChannelid := args[1]
//argCointoreceiver := args[2]
//argCointohtlc := args[3]
//argCointransfer := args[4]
argHashcodehtlc := args[5]
//argTimelockhtlc := args[6]
argHashcodedest := args[7]
//argTimelocksender := args[8]
argMultisigAddr := args[9]
cmd.Flags().Set(flags.FlagFrom, argMultisigAddr)
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
decCoin, err := sdk.ParseDecCoin(args[2])
if err != nil {
return err
}
argCointoreceiver, _ := sdk.NormalizeDecCoin(decCoin).TruncateDecimal()
decCoin, err = sdk.ParseDecCoin(args[3])
if err != nil {
return err
}
argCointohtlc, _ := sdk.NormalizeDecCoin(decCoin).TruncateDecimal()
decCoin, err = sdk.ParseDecCoin(args[4])
if err != nil {
return err
}
argCointransfer, _ := sdk.NormalizeDecCoin(decCoin).TruncateDecimal()
argTimelockhtlc, err := strconv.ParseUint(args[6], 10, 64)
if err != nil {
return err
}
argTimelocksender, err := strconv.ParseUint(args[8], 10, 64)
if err != nil {
return err
}
msg := types.NewMsgReceivercommit(
clientCtx.GetFromAddress().String(),
argReceiverAddr,
argChannelid,
&argCointoreceiver,
&argCointohtlc,
&argCointransfer,
argHashcodehtlc,
argTimelockhtlc,
argHashcodedest,
argTimelocksender,
argMultisigAddr,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}