-
Notifications
You must be signed in to change notification settings - Fork 1
/
hub_withdraw.go
109 lines (93 loc) · 2.24 KB
/
hub_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package commands
import (
"fmt"
"log"
"math/big"
"github.com/abiosoft/ishell"
"github.com/qlcchain/qlc-hub/pkg/types"
)
func hEth2NeoCmd(parentCmd *ishell.Cmd) {
c := &ishell.Cmd{
Name: "eth2neo",
Help: "eth -> neo",
Func: func(c *ishell.Context) {
hEth2Neo()
},
}
parentCmd.AddCmd(c)
}
func hEth2NeoPendingCmd(parentCmd *ishell.Cmd) {
c := &ishell.Cmd{
Name: "eth2neoPending",
Help: "eth -> neo",
Func: func(c *ishell.Context) {
hEth2NeoPending()
},
}
parentCmd.AddCmd(c)
}
func hEth2Neo() {
amount := 110000000
ethTx, err := ethTransactionNep5.Burn(ethUserPrivate, neoUserAddr, big.NewInt(int64(amount)))
if err != nil {
log.Fatal(err)
}
fmt.Println("withdraw send eth tx done: ", ethTx)
sentParas := fmt.Sprintf(`{
"hash":"%s",
"chainType":"%s"
}`, ethTx, "eth")
r, err := post(sentParas, fmt.Sprintf("%s/withdraw/chainTransactionSent", hubUrl))
if err != nil {
log.Fatal(err, r)
}
if !waitForSwapState(ethTx, types.SwapStateToString(types.WithDrawDone)) {
log.Fatal("fail")
}
fmt.Println("successfully")
}
func hEth2NeoPending() {
hash := "0x037260513ec5d8cca4b619d81852608a9a5dcb0e865cb11efcdf2029919738df"
sendParas := fmt.Sprintf(`{
"hash": "%s"
}`, hash)
r, err := post(sendParas, fmt.Sprintf("%s/withdraw/ethTransactionConfirmed", hubUrl))
if err != nil {
log.Fatal(err, r)
}
fmt.Println("withdraw send eth tx done: ", r["value"].(bool))
if !waitForSwapState(hash, types.SwapStateToString(types.WithDrawDone)) {
log.Fatal("fail")
}
fmt.Println("successfully")
}
func hBsc2NeoCmd(parentCmd *ishell.Cmd) {
c := &ishell.Cmd{
Name: "bsc2neo",
Help: "bsc -> neo",
Func: func(c *ishell.Context) {
hBsc2Neo()
},
}
parentCmd.AddCmd(c)
}
func hBsc2Neo() {
amount := 110000000
ethTx, err := bscTransactionNep5.Burn(bscUserPrivate, neoUserAddr, big.NewInt(int64(amount)))
if err != nil {
log.Fatal(err)
}
fmt.Println("withdraw send eth tx done: ", ethTx)
sentParas := fmt.Sprintf(`{
"hash":"%s",
"chainType":"%s"
}`, ethTx, "bsc")
r, err := post(sentParas, fmt.Sprintf("%s/withdraw/chainTransactionSent", hubUrl))
if err != nil {
log.Fatal(err, r)
}
if !waitForSwapState(ethTx, types.SwapStateToString(types.WithDrawDone)) {
log.Fatal("fail")
}
fmt.Println("successfully")
}