/
farmHandler.go
109 lines (100 loc) · 3.38 KB
/
farmHandler.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 chain33
import (
"errors"
"fmt"
"time"
"github.com/33cn/plugin/plugin/dapp/dex/contracts/pancake-farm/src/cakeToken"
"github.com/33cn/plugin/plugin/dapp/dex/contracts/pancake-farm/src/masterChef"
"github.com/33cn/plugin/plugin/dapp/dex/contracts/pancake-farm/src/syrupBar"
"github.com/spf13/cobra"
)
func DeployFarm(cmd *cobra.Command) error {
caller, _ := cmd.Flags().GetString("caller")
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
txhexCakeToken, err := deployContract(cmd, cakeToken.CakeTokenBin, cakeToken.CakeTokenABI, "", "CakeToken")
if err != nil {
return errors.New(err.Error())
}
{
timeout := time.NewTimer(300 * time.Second)
oneSecondtimeout := time.NewTicker(1 * time.Second)
for {
select {
case <-timeout.C:
panic("Deploy CakeToken timeout")
case <-oneSecondtimeout.C:
data, _ := getTxByHashesRpc(txhexCakeToken, rpcLaddr)
if data == "" {
fmt.Println("No receipt received yet for Deploy CakeToken tx and continue to wait")
continue
} else if data != "2" {
return errors.New("DeployPancakeFactory failed due to" + ", ty = " + data)
}
fmt.Println("Succeed to deploy CakeToken with address =", getContractAddr(caller, txhexCakeToken))
fmt.Println("")
goto deploySyrupBar
}
}
}
deploySyrupBar:
txhexSyrupBar, err := deployContract(cmd, syrupBar.SyrupBarBin, syrupBar.SyrupBarABI, getContractAddr(caller, txhexCakeToken), "SyrupBar")
if err != nil {
return errors.New(err.Error())
}
{
timeout := time.NewTimer(300 * time.Second)
oneSecondtimeout := time.NewTicker(1 * time.Second)
for {
select {
case <-timeout.C:
panic("Deploy SyrupBar timeout")
case <-oneSecondtimeout.C:
data, _ := getTxByHashesRpc(txhexSyrupBar, rpcLaddr)
if data == "" {
fmt.Println("No receipt received yet for Deploy SyrupBar tx and continue to wait")
continue
} else if data != "2" {
return errors.New("Deploy SyrupBar failed due to" + ", ty = " + data)
}
fmt.Println("Succeed to deploy SyrupBar with address =", getContractAddr(caller, txhexSyrupBar))
fmt.Println("")
goto deployMasterChef
}
}
}
deployMasterChef:
// constructor(
// CakeToken _cake,
// SyrupBar _syrup,
// address _devaddr,
// uint256 _cakePerBlock,
// uint256 _startBlock
// )
// masterChef.DeployMasterChef(auth, ethClient, cakeTokenAddr, SyrupBarAddr, deployerAddr, big.NewInt(5*1e18), big.NewInt(100))
txparam := getContractAddr(caller, txhexCakeToken) + "," + getContractAddr(caller, txhexSyrupBar) + "," + caller + ", 5000000000000000000, 100"
txhexMasterChef, err := deployContract(cmd, masterChef.MasterChefBin, masterChef.MasterChefABI, txparam, "MasterChef")
if err != nil {
return errors.New(err.Error())
}
{
timeout := time.NewTimer(300 * time.Second)
oneSecondtimeout := time.NewTicker(1 * time.Second)
for {
select {
case <-timeout.C:
panic("Deploy MasterChef timeout")
case <-oneSecondtimeout.C:
data, _ := getTxByHashesRpc(txhexMasterChef, rpcLaddr)
if data == "" {
fmt.Println("No receipt received yet for Deploy MasterChef tx and continue to wait")
continue
} else if data != "2" {
return errors.New("Deploy MasterChef failed due to" + ", ty = " + data)
}
fmt.Println("Succeed to deploy MasterChef with address =", getContractAddr(caller, txhexMasterChef))
fmt.Println("")
return nil
}
}
}
}