-
Notifications
You must be signed in to change notification settings - Fork 4
/
ifil_approve.go
60 lines (48 loc) · 1.35 KB
/
ifil_approve.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
package cmd
import (
"fmt"
"time"
"github.com/briandowns/spinner"
"github.com/spf13/cobra"
)
var iFILApproveCmd = &cobra.Command{
Use: "approve <spender> <allowance>",
Short: "Approve another address to spend your iFIL",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
from := cmd.Flag("from").Value.String()
auth, _, err := commonGenericAccountSetup(ctx, from)
if err != nil {
logFatal(err)
}
strAddr := args[0]
strAmt := args[1]
fmt.Printf("Approving %s to spend %s of your iFIL balance...\n", strAddr, strAmt)
addr, err := AddressOrAccountNameToEVM(ctx, strAddr)
if err != nil {
logFatalf("Failed to parse address %s", err)
}
amount, err := parseFILAmount(strAmt)
if err != nil {
logFatalf("Failed to parse amount %s", err)
}
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Start()
defer s.Stop()
tx, err := PoolsSDK.Act().IFILApprove(ctx, auth, addr, amount)
if err != nil {
logFatalf("Failed to approve iFIL %s", err)
}
_, err = PoolsSDK.Query().StateWaitReceipt(ctx, tx.Hash())
if err != nil {
logFatalf("Failed to approve iFIL %s", err)
}
s.Stop()
fmt.Printf("iFIL approved!\n")
},
}
func init() {
iFILCmd.AddCommand(iFILApproveCmd)
iFILApproveCmd.Flags().String("from", "default", "account to approve iFIL transfer from")
}