Skip to content

Commit

Permalink
feat(): add assemble tx without sig
Browse files Browse the repository at this point in the history
  • Loading branch information
zyjblockchain committed Mar 9, 2023
1 parent dd99370 commit 74f87d3
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/everFinance/go-everpay/sdk/schema"
"github.com/everFinance/go-everpay/token"
tokSchema "github.com/everFinance/go-everpay/token/schema"
"github.com/tidwall/sjson"
"gopkg.in/h2non/gentleman.v2"
"gopkg.in/h2non/gentleman.v2/plugins/body"
"time"
)

type Client struct {
Expand Down Expand Up @@ -400,6 +402,63 @@ func (c *Client) SubmitTx(tx paySchema.Transaction) (err error) {
return
}

func (c *Client) Mint102WithoutSig(tokenTag, from, to, amount string) (everTx paySchema.Transaction, err error) {
return c.AssembleTxWithoutSig(tokenTag, from, to, amount, "0", tokSchema.TxActionMint, "")
}

func (c *Client) TransferWithoutSig(tokenTag, from, to, amount string) (everTx paySchema.Transaction, err error) {
return c.AssembleTxWithoutSig(tokenTag, from, to, amount, "0", tokSchema.TxActionTransfer, "")
}

func (c *Client) AddWhiteListWithoutSig(tokenTag, from string, whiteList []string) (everTx paySchema.Transaction, err error) {
data, err := sjson.Set("", "whiteList", whiteList)
if err != nil {
return
}
return c.AssembleTxWithoutSig(tokenTag, from, from, "0", "0", tokSchema.TxActionAddWhiteList, data)
}

func (c *Client) Burn102WithoutSig(tokenTag, from, amount string) (everTx paySchema.Transaction, err error) {
data, err := sjson.Set("", "targetChainType", tokSchema.ChainTypeEverpay)
if err != nil {
return
}
return c.AssembleTxWithoutSig(tokenTag, from, tokSchema.ZeroAddress, amount, "0", tokSchema.TxActionBurn, data)
}

func (c *Client) AssembleTxWithoutSig(tokenTag, from, to, amount, fee, action, data string) (everTx paySchema.Transaction, err error) {
info, err := c.GetInfo()
if err != nil {
return
}
tokenInfo := schema.TokenInfo{}
for _, t := range info.TokenList {
if t.Tag == tokenTag {
tokenInfo = t
}
break
}

// assemble tx
everTx = paySchema.Transaction{
TokenSymbol: tokenInfo.Symbol,
Action: action,
From: from,
To: to,
Amount: amount,
Fee: fee,
FeeRecipient: info.FeeRecipient,
Nonce: fmt.Sprintf("%d", time.Now().UnixNano()/1000000),
TokenID: tokenInfo.ID,
ChainType: tokenInfo.ChainType,
ChainID: tokenInfo.ChainID,
Data: data,
Version: tokSchema.TxVersionV1,
Sig: "",
}
return
}

func decodeRespErr(errMsg []byte) error {
resErr := schema.RespErr{}
if err := json.Unmarshal(errMsg, &resErr); err != nil {
Expand Down

0 comments on commit 74f87d3

Please # to comment.