Skip to content

Commit

Permalink
feat: update client cli
Browse files Browse the repository at this point in the history
  • Loading branch information
zengchen221 committed Apr 12, 2021
1 parent 2adbab8 commit 8bdf66d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cmd/client/commands/hub_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func addHubCmd(shell *ishell.Shell) {
hEth2NeoCmd(hubCmd)
hEth2NeoPendingCmd(hubCmd)
hNeo2BscCmd(hubCmd)
hBsc2NeoCmd(hubCmd)
}

func hNeo2EthCmd(parentCmd *ishell.Cmd) {
Expand Down Expand Up @@ -125,7 +126,7 @@ func hNeo2Eth() {
unsignedParas := fmt.Sprintf(`{
"amount": %d,
"nep5SenderAddr": "%s",
"erc20ReceiverAddr": "%s"
"tokenMintedToAddress": "%s"
}`, amount, neoUserAddr, ethUserAddress)
r, err := post(unsignedParas, fmt.Sprintf("%s/deposit/packNeoTransaction", hubUrl))
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions cmd/client/commands/hub_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,38 @@ func hEth2NeoPending() {

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")
}
2 changes: 1 addition & 1 deletion cmd/client/commands/qlc_pledge.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func qQlc2EthPendingCmd(parentCmd *ishell.Cmd) {
}

func nQlc2Eth() {
amount := 900000000
amount := 500000000

// get pledge send block
Paras := fmt.Sprintf(`{
Expand Down
2 changes: 1 addition & 1 deletion cmd/client/commands/qlc_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func qEth2QlcCmdPending(parentCmd *ishell.Cmd) {
}

func nEth2Qlc() {
amount := 900000
amount := 300000000
ethTx, err := ethTransactionQLC.Burn(ethUserPrivate, qlcUserAddress, big.NewInt(int64(amount)))
if err != nil {
log.Fatal(err)
Expand Down
8 changes: 4 additions & 4 deletions cmd/client/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ var (
bscUserAddress = "0x318c6E6613D34a57972f2679d5039E807f048C6E"

// eth setting (qgas -> eth)
ethContractQLC = "0x1aFFc415416f1D157F4603f37aE1AC9011487111"
ethContractQGas = "0x1aFFc415416f1D157F4603f37aE1AC9011487111"

// bsc setting (qgas -> eth)
bscContractQLC = "0xF791c6cf47C3650Fb8e65f1Ab0bFaDEfcFD51af5"
bscContractQGas = "0xF791c6cf47C3650Fb8e65f1Ab0bFaDEfcFD51af5"

// qlc setting
qlcUserPrivate = "8be0696a2d51dec8e2859dcb8ce2fd7ce7412eb9d6fa8a2089be8e8f1eeb4f0e458779381a8d21312b071729344a0cb49dc1da385993e19d58b5578da44c0df0"
Expand Down Expand Up @@ -102,8 +102,8 @@ func initParams(osArgs []string) {

ethTransactionNep5, _ = eth.NewTransaction(ethUrl, ethContract)
bscTransactionNep5, _ = eth.NewTransaction(bscUrl, bscContractNep5)
ethTransactionQLC, _ = eth.NewTransaction(ethUrl, ethContractQLC)
bscTransactionQLC, _ = eth.NewTransaction(bscUrl, bscContractQLC)
ethTransactionQLC, _ = eth.NewTransaction(ethUrl, ethContractQGas)
bscTransactionQLC, _ = eth.NewTransaction(bscUrl, bscContractQGas)
//defer ethClient.Close()

log.Println("hub endpoint: ", hubUrl)
Expand Down
6 changes: 5 additions & 1 deletion pkg/eth/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ func (t *Transaction) WaitTxVerifyAndConfirmed(txHash common.Hash, txHeight uint
cTicker := time.NewTicker(3 * time.Second)
cTimer := time.NewTimer(600 * time.Second)
client := t.Client()
var erro error
for {
select {
case <-cTicker.C:
tx, p, err := client.TransactionByHash(context.Background(), txHash)
if err != nil {
t.logger.Errorf("tx by hash: %s , txHash: %s", err, txHash.String())
erro = err
}
if tx != nil && !p { // if tx not found , p is false
if txHeight == 0 {
Expand All @@ -67,6 +68,9 @@ func (t *Transaction) WaitTxVerifyAndConfirmed(txHash common.Hash, txHeight uint
}
}
case <-cTimer.C:
if erro != nil {
t.logger.Errorf("tx by hash: %s , txHash: %s", erro, txHash.String())
}
return fmt.Errorf("tx by hash timeout: %s", txHash)
}
}
Expand Down

0 comments on commit 8bdf66d

Please sign in to comment.