Skip to content

Commit

Permalink
Add get fee method
Browse files Browse the repository at this point in the history
  • Loading branch information
devfans committed Dec 2, 2021
1 parent aee86a8 commit 6868709
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
7 changes: 6 additions & 1 deletion chains/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
)

type Client struct {
address string
address string
explorer string
}

func New(url string) *Client {
Expand All @@ -35,6 +36,10 @@ func New(url string) *Client {
}
}

func (c *Client) SetExplorer(url string) {
c.explorer = url
}

func (c *Client) Address() string {
return c.address
}
Expand Down
27 changes: 27 additions & 0 deletions chains/bridge/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,30 @@ func (r *CheckFeeRequest) Missing() bool {
func (c *Client) CheckFee(req map[string]*CheckFeeRequest) (err error) {
return tools.PostJsonFor(c.address+"/newcheckfee", req, &req)
}

type GetFeeRequest struct {
SrcChainId uint64
DstChainId uint64
SwapTokenHash string
Hash string
}

type GetFeeResponse struct {
SrcChainId uint64
DstChainId uint64
SwapTokenHash string
TokenAmount string
UsdtAmount string
TokenAmountWithPrecision string
Balance string
BalanceWithPrecision string
}

func (c *Client) GetFee(req *GetFeeRequest) (res *GetFeeResponse, err error) {
res = new(GetFeeResponse)
err = tools.PostJsonFor(c.address+"/getfee", req, res)
if err != nil {
return nil, err
}
return
}
20 changes: 20 additions & 0 deletions chains/bridge/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ type CheckTxResponse struct {
}
}

type TxBody struct {
Chainid uint64
Txhash string
}

type TxResponse struct {
Fchaintx *TxBody
Mchaintx *TxBody
Tchaintx *TxBody
}

func (c *Client) CheckTx(req *CheckTxRequest) (res *CheckTxResponse, err error) {
res = new(CheckTxResponse)
err = tools.PostJsonFor(c.address+"/transactionofhash", req, res)
Expand All @@ -56,3 +67,12 @@ func (c *Client) CheckTx(req *CheckTxRequest) (res *CheckTxResponse, err error)
}
return
}

func (c *Client) FetchTx(req *CheckTxRequest) (res *TxResponse, err error) {
res = new(TxResponse)
err = tools.GetJsonFor(c.explorer+"/getcrosstx?txhash="+req.Hash, res)
if err != nil {
res = nil
}
return
}
23 changes: 23 additions & 0 deletions tools/ding.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,26 @@ func PostJsonFor(url string, payload interface{}, result interface{}) error {
}
return nil
}

func GetJsonFor(url string, result interface{}) error {
req, err := http.NewRequest("GET", url, nil)
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
err = json.Unmarshal(respBody, result)
if err != nil {
log.Error("GetJson response", "url", url, "Body", string(respBody))
} else {
log.Debug("GetJson response", "url", url, "Body", string(respBody))
}
return nil
}
2 changes: 1 addition & 1 deletion wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (w *Wallet) SendWithAccount(account accounts.Account, addr common.Address,
return
}
if gasLimit == 0 {
msg := ethereum.CallMsg{From: account.Address, To: &addr, GasPrice: gasPrice, Value: big.NewInt(0), Data: data}
msg := ethereum.CallMsg{From: account.Address, To: &addr, GasPrice: gasPrice, Value: amount, Data: data}
gasLimit, err = w.sdk.Node().EstimateGas(context.Background(), msg)
if err != nil {
nonces.Update(false)
Expand Down

0 comments on commit 6868709

Please sign in to comment.