-
Notifications
You must be signed in to change notification settings - Fork 4
/
agent_withdraw.go
72 lines (59 loc) · 1.54 KB
/
agent_withdraw.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
/*
Copyright © 2023 Glif LTD
*/
package cmd
import (
"fmt"
"time"
"github.com/briandowns/spinner"
"github.com/glifio/glif/v2/events"
"github.com/spf13/cobra"
)
var withdrawCmd = &cobra.Command{
Use: "withdraw <amount> <receiver>",
Short: "Withdraw FIL from your Agent.",
Long: "",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
agentAddr, auth, _, requesterKey, err := commonSetupOwnerCall()
if err != nil {
logFatal(err)
}
receiver, err := AddressOrAccountNameToEVM(cmd.Context(), args[1])
if err != nil {
logFatal(err)
}
amount, err := parseFILAmount(args[0])
if err != nil {
logFatal(err)
}
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Start()
defer s.Stop()
withdrawevt := journal.RegisterEventType("agent", "withdraw")
evt := &events.AgentWithdraw{
AgentID: agentAddr.String(),
Amount: amount.String(),
To: receiver.String(),
}
defer journal.Close()
defer journal.RecordEvent(withdrawevt, func() interface{} { return evt })
fmt.Printf("Withdrawing %s FIL from your Agent", args[0])
tx, err := PoolsSDK.Act().AgentWithdraw(cmd.Context(), auth, agentAddr, receiver, amount, requesterKey)
if err != nil {
evt.Error = err.Error()
logFatal(err)
}
evt.Tx = tx.Hash().String()
_, err = PoolsSDK.Query().StateWaitReceipt(cmd.Context(), tx.Hash())
if err != nil {
evt.Error = err.Error()
logFatal(err)
}
s.Stop()
fmt.Printf("Successfully withdrew %s FIL\n", args[0])
},
}
func init() {
agentCmd.AddCommand(withdrawCmd)
}