Skip to content

Commit

Permalink
api: expose memo and source
Browse files Browse the repository at this point in the history
  • Loading branch information
unclezoro committed Jun 3, 2019
1 parent 8939eb7 commit 2d472a5
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 58 deletions.
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ If you want broadcast some transactions, like send coins, create orders or cance

Create a `buy` order:
```go
createOrderResult, err := client.CreateOrder(tradeSymbol, nativeSymbol, txmsg.OrderSide.BUY, 100000000, 100000000, true)
createOrderResult, err := client.CreateOrder(tradeSymbol, nativeSymbol, txmsg.OrderSide.BUY, 100000000, 100000000, true, "", tx.Source)
```

For more API usage documentation, please check the [wiki](https://github.com/binance-chain/go-sdk/wiki)..
Expand Down
4 changes: 2 additions & 2 deletions client/transaction/burn_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type BurnTokenResult struct {
tx.TxCommitResult
}

func (c *client) BurnToken(symbol string, amount int64, sync bool) (*BurnTokenResult, error) {
func (c *client) BurnToken(symbol string, amount int64, sync bool,memo string, source int64) (*BurnTokenResult, error) {
if symbol == "" {
return nil, fmt.Errorf("Burn token symbol can'c be empty ")
}
Expand All @@ -26,7 +26,7 @@ func (c *client) BurnToken(symbol string, amount int64, sync bool) (*BurnTokenRe
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(burnMsg, sync)
commit, err := c.broadcastMsg(burnMsg, sync,memo,source)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/transaction/cancel_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type CancelOrderResult struct {
tx.TxCommitResult
}

func (c *client) CancelOrder(baseAssetSymbol, quoteAssetSymbol, refId string, sync bool) (*CancelOrderResult, error) {
func (c *client) CancelOrder(baseAssetSymbol, quoteAssetSymbol, refId string, sync bool,memo string, source int64) (*CancelOrderResult, error) {
if baseAssetSymbol == "" || quoteAssetSymbol == "" {
return nil, fmt.Errorf("BaseAssetSymbol or QuoteAssetSymbol is missing. ")
}
Expand All @@ -27,7 +27,7 @@ func (c *client) CancelOrder(baseAssetSymbol, quoteAssetSymbol, refId string, sy
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(cancelOrderMsg, sync)
commit, err := c.broadcastMsg(cancelOrderMsg, sync,memo,source)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/transaction/create_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type CreateOrderResult struct {
OrderId string
}

func (c *client) CreateOrder(baseAssetSymbol, quoteAssetSymbol string, op int8, price, quantity int64, sync bool) (*CreateOrderResult, error) {
func (c *client) CreateOrder(baseAssetSymbol, quoteAssetSymbol string, op int8, price, quantity int64, sync bool,memo string, source int64) (*CreateOrderResult, error) {
if baseAssetSymbol == "" || quoteAssetSymbol == "" {
return nil, fmt.Errorf("BaseAssetSymbol or QuoteAssetSymbol is missing. ")
}
Expand All @@ -37,7 +37,7 @@ func (c *client) CreateOrder(baseAssetSymbol, quoteAssetSymbol string, op int8,
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(newOrderMsg, sync)
commit, err := c.broadcastMsg(newOrderMsg, sync,memo,source)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/transaction/deposit_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ type DepositProposalResult struct {
tx.TxCommitResult
}

func (c *client) DepositProposal(proposalID int64, amount int64, sync bool) (*DepositProposalResult, error) {
func (c *client) DepositProposal(proposalID int64, amount int64, sync bool,memo string, source int64) (*DepositProposalResult, error) {
fromAddr := c.keyManager.GetAddr()
coins := ctypes.Coins{ctypes.Coin{Denom: types.NativeSymbol, Amount: amount}}
depositMsg := msg.NewDepositMsg(fromAddr, proposalID, coins)
err := depositMsg.ValidateBasic()
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(depositMsg, sync)
commit, err := c.broadcastMsg(depositMsg, sync,memo,source)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/transaction/freeze_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type FreezeTokenResult struct {
tx.TxCommitResult
}

func (c *client) FreezeToken(symbol string, amount int64, sync bool) (*FreezeTokenResult, error) {
func (c *client) FreezeToken(symbol string, amount int64, sync bool,memo string, source int64) (*FreezeTokenResult, error) {
if symbol == "" {
return nil, fmt.Errorf("Freeze token symbol can'c be empty ")
}
Expand All @@ -26,7 +26,7 @@ func (c *client) FreezeToken(symbol string, amount int64, sync bool) (*FreezeTok
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(freezeMsg, sync)
commit, err := c.broadcastMsg(freezeMsg, sync,memo,source)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/transaction/issue_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type IssueTokenValue struct {
Owner string `json:"owner"`
}

func (c *client) IssueToken(name, symbol string, supply int64, sync bool, mintable bool) (*IssueTokenResult, error) {
func (c *client) IssueToken(name, symbol string, supply int64, sync bool, mintable bool,memo string, source int64) (*IssueTokenResult, error) {
if symbol == "" {
return nil, fmt.Errorf("Freeze token symbol can'c be empty ")
}
Expand All @@ -38,7 +38,7 @@ func (c *client) IssueToken(name, symbol string, supply int64, sync bool, mintab
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(issueMsg, sync)
commit, err := c.broadcastMsg(issueMsg, sync,memo,source)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/transaction/list_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ type ListPairResult struct {
tx.TxCommitResult
}

func (c *client) ListPair(proposalId int64, baseAssetSymbol string, quoteAssetSymbol string, initPrice int64, sync bool) (*ListPairResult, error) {
func (c *client) ListPair(proposalId int64, baseAssetSymbol string, quoteAssetSymbol string, initPrice int64, sync bool,memo string, source int64) (*ListPairResult, error) {
fromAddr := c.keyManager.GetAddr()

burnMsg := msg.NewDexListMsg(fromAddr, proposalId, baseAssetSymbol, quoteAssetSymbol, initPrice)
err := burnMsg.ValidateBasic()
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(burnMsg, sync)
commit, err := c.broadcastMsg(burnMsg, sync,memo,source)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/transaction/mint_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type MintTokenResult struct {
tx.TxCommitResult
}

func (c *client) MintToken(symbol string, amount int64, sync bool) (*MintTokenResult, error) {
func (c *client) MintToken(symbol string, amount int64, sync bool,memo string, source int64) (*MintTokenResult, error) {
if symbol == "" {
return nil, fmt.Errorf("Freeze token symbol can'c be empty ")
}
Expand All @@ -26,7 +26,7 @@ func (c *client) MintToken(symbol string, amount int64, sync bool) (*MintTokenRe
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(mintMsg, sync)
commit, err := c.broadcastMsg(mintMsg, sync,memo,source)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/transaction/send_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type SendTokenResult struct {
tx.TxCommitResult
}

func (c *client) SendToken(transfers []msg.Transfer, sync bool) (*SendTokenResult, error) {
func (c *client) SendToken(transfers []msg.Transfer, sync bool,memo string, source int64) (*SendTokenResult, error) {
fromAddr := c.keyManager.GetAddr()
fromCoins := types.Coins{}
for _, t := range transfers {
Expand All @@ -21,7 +21,7 @@ func (c *client) SendToken(transfers []msg.Transfer, sync bool) (*SendTokenResul
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(sendMsg, sync)
commit, err := c.broadcastMsg(sendMsg, sync,memo,source)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions client/transaction/submit_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ type SubmitProposalResult struct {
ProposalId int64 `json:"proposal_id"`
}

func (c *client) SubmitListPairProposal(title string, param msg.ListTradingPairParams, initialDeposit int64, votingPeriod time.Duration, sync bool) (*SubmitProposalResult, error) {
func (c *client) SubmitListPairProposal(title string, param msg.ListTradingPairParams, initialDeposit int64, votingPeriod time.Duration, sync bool,memo string, source int64) (*SubmitProposalResult, error) {
bz, err := json.Marshal(&param)
if err != nil {
return nil, err
}
return c.SubmitProposal(title, string(bz), msg.ProposalTypeListTradingPair, initialDeposit, votingPeriod, sync)
return c.SubmitProposal(title, string(bz), msg.ProposalTypeListTradingPair, initialDeposit, votingPeriod, sync,memo,source)
}

func (c *client) SubmitProposal(title string, description string, proposalType msg.ProposalKind, initialDeposit int64, votingPeriod time.Duration, sync bool) (*SubmitProposalResult, error) {
func (c *client) SubmitProposal(title string, description string, proposalType msg.ProposalKind, initialDeposit int64, votingPeriod time.Duration, sync bool,memo string, source int64) (*SubmitProposalResult, error) {
fromAddr := c.keyManager.GetAddr()
coins := ctypes.Coins{ctypes.Coin{Denom: types.NativeSymbol, Amount: initialDeposit}}
proposalMsg := msg.NewMsgSubmitProposal(title, description, proposalType, fromAddr, coins, votingPeriod)
err := proposalMsg.ValidateBasic()
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(proposalMsg, sync)
commit, err := c.broadcastMsg(proposalMsg, sync,memo,source)
if err != nil {
return nil, err
}
Expand Down
33 changes: 16 additions & 17 deletions client/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ import (
"github.com/binance-chain/go-sdk/client/basic"
"github.com/binance-chain/go-sdk/client/query"
"github.com/binance-chain/go-sdk/keys"
"github.com/binance-chain/go-sdk/types"
"github.com/binance-chain/go-sdk/types/msg"
"github.com/binance-chain/go-sdk/types/tx"
)

type TransactionClient interface {
CreateOrder(baseAssetSymbol, quoteAssetSymbol string, op int8, price, quantity int64, sync bool) (*CreateOrderResult, error)
CancelOrder(baseAssetSymbol, quoteAssetSymbol, refId string, sync bool) (*CancelOrderResult, error)
BurnToken(symbol string, amount int64, sync bool) (*BurnTokenResult, error)
ListPair(proposalId int64, baseAssetSymbol string, quoteAssetSymbol string, initPrice int64, sync bool) (*ListPairResult, error)
FreezeToken(symbol string, amount int64, sync bool) (*FreezeTokenResult, error)
UnfreezeToken(symbol string, amount int64, sync bool) (*UnfreezeTokenResult, error)
IssueToken(name, symbol string, supply int64, sync bool, mintable bool) (*IssueTokenResult, error)
SendToken(transfers []msg.Transfer, sync bool) (*SendTokenResult, error)
MintToken(symbol string, amount int64, sync bool) (*MintTokenResult, error)
CreateOrder(baseAssetSymbol, quoteAssetSymbol string, op int8, price, quantity int64, sync bool, memo string, source int64) (*CreateOrderResult, error)
CancelOrder(baseAssetSymbol, quoteAssetSymbol, refId string, sync bool, memo string, source int64) (*CancelOrderResult, error)
BurnToken(symbol string, amount int64, sync bool, memo string, source int64) (*BurnTokenResult, error)
ListPair(proposalId int64, baseAssetSymbol string, quoteAssetSymbol string, initPrice int64, sync bool, memo string, source int64) (*ListPairResult, error)
FreezeToken(symbol string, amount int64, sync bool, memo string, source int64) (*FreezeTokenResult, error)
UnfreezeToken(symbol string, amount int64, sync bool, memo string, source int64) (*UnfreezeTokenResult, error)
IssueToken(name, symbol string, supply int64, sync bool, mintable bool, memo string, source int64) (*IssueTokenResult, error)
SendToken(transfers []msg.Transfer, sync bool, memo string, source int64) (*SendTokenResult, error)
MintToken(symbol string, amount int64, sync bool, memo string, source int64) (*MintTokenResult, error)

SubmitListPairProposal(title string, param msg.ListTradingPairParams, initialDeposit int64, votingPeriod time.Duration, sync bool) (*SubmitProposalResult, error)
SubmitProposal(title string, description string, proposalType msg.ProposalKind, initialDeposit int64, votingPeriod time.Duration, sync bool) (*SubmitProposalResult, error)
DepositProposal(proposalID int64, amount int64, sync bool) (*DepositProposalResult, error)
VoteProposal(proposalID int64, option msg.VoteOption, sync bool) (*VoteProposalResult, error)
SubmitListPairProposal(title string, param msg.ListTradingPairParams, initialDeposit int64, votingPeriod time.Duration, sync bool, memo string, source int64) (*SubmitProposalResult, error)
SubmitProposal(title string, description string, proposalType msg.ProposalKind, initialDeposit int64, votingPeriod time.Duration, sync bool, memo string, source int64) (*SubmitProposalResult, error)
DepositProposal(proposalID int64, amount int64, sync bool, memo string, source int64) (*DepositProposalResult, error)
VoteProposal(proposalID int64, option msg.VoteOption, sync bool, memo string, source int64) (*VoteProposalResult, error)

GetKeyManager() keys.KeyManager
}
Expand All @@ -46,7 +45,7 @@ func (c *client) GetKeyManager() keys.KeyManager {
return c.keyManager
}

func (c *client) broadcastMsg(m msg.Msg, sync bool) (*tx.TxCommitResult, error) {
func (c *client) broadcastMsg(m msg.Msg, sync bool, memo string, source int64) (*tx.TxCommitResult, error) {
fromAddr := c.keyManager.GetAddr()
acc, err := c.queryClient.GetAccount(fromAddr.String())
if err != nil {
Expand All @@ -58,9 +57,9 @@ func (c *client) broadcastMsg(m msg.Msg, sync bool) (*tx.TxCommitResult, error)
ChainID: c.chainId,
AccountNumber: acc.Number,
Sequence: sequence,
Memo: "",
Memo: memo,
Msgs: []msg.Msg{m},
Source: types.GoSdkSource,
Source: source,
}

// Hex encoded signed transaction, ready to be posted to BncChain API
Expand Down
4 changes: 2 additions & 2 deletions client/transaction/unfreeze_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type UnfreezeTokenResult struct {
tx.TxCommitResult
}

func (c *client) UnfreezeToken(symbol string, amount int64, sync bool) (*UnfreezeTokenResult, error) {
func (c *client) UnfreezeToken(symbol string, amount int64, sync bool, memo string, source int64) (*UnfreezeTokenResult, error) {
if symbol == "" {
return nil, fmt.Errorf("Freeze token symbol can'c be empty ")
}
Expand All @@ -26,7 +26,7 @@ func (c *client) UnfreezeToken(symbol string, amount int64, sync bool) (*Unfreez
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(unfreezeMsg, sync)
commit, err := c.broadcastMsg(unfreezeMsg, sync, memo, source)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/transaction/vote_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ type VoteProposalResult struct {
tx.TxCommitResult
}

func (c *client) VoteProposal(proposalID int64, option msg.VoteOption, sync bool) (*VoteProposalResult, error) {
func (c *client) VoteProposal(proposalID int64, option msg.VoteOption, sync bool, memo string, source int64) (*VoteProposalResult, error) {
fromAddr := c.keyManager.GetAddr()
voteMsg := msg.NewMsgVote(fromAddr, proposalID, option)
err := voteMsg.ValidateBasic()
if err != nil {
return nil, err
}
commit, err := c.broadcastMsg(voteMsg, sync)
commit, err := c.broadcastMsg(voteMsg, sync, memo, source)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 2d472a5

Please sign in to comment.