Skip to content

Commit 689c838

Browse files
Merge pull request #202 from canopy-network/tx-create-order-data
tx create order data support
2 parents 831e4df + 24a44ae commit 689c838

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

cmd/cli/admin.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/canopy-network/canopy/cmd/rpc"
99
"github.com/canopy-network/canopy/lib"
1010
"github.com/canopy-network/canopy/lib/crypto"
11+
"github.com/ethereum/go-ethereum/common"
1112
"github.com/spf13/cobra"
1213
"golang.org/x/term"
1314
)
@@ -20,6 +21,7 @@ var adminCmd = &cobra.Command{
2021
var (
2122
pwd string
2223
nick string
24+
data string
2325
fee uint64
2426
delegate bool
2527
earlyWithdrawal bool
@@ -35,6 +37,7 @@ func init() {
3537
txEditStakeCmd.PersistentFlags().BoolVar(&delegate, "delegate", false, "delegate tokens to committee(s) only without actual validator operation")
3638
txStakeCmd.PersistentFlags().BoolVar(&earlyWithdrawal, "early-withdrawal", false, "immediately withdrawal any rewards (with penalty) directly to output address instead of auto-compounding directly to stake")
3739
txEditStakeCmd.PersistentFlags().BoolVar(&earlyWithdrawal, "early-withdrawal", false, "immediately withdrawal any rewards (with penalty) directly to output address instead of auto-compounding directly to stake")
40+
txCreateOrderCmd.PersistentFlags().StringVar(&data, "data", "", "data for create order")
3841
adminCmd.AddCommand(ksCmd)
3942
adminCmd.AddCommand(ksNewKeyCmd)
4043
adminCmd.AddCommand(ksImportCmd)
@@ -215,11 +218,11 @@ var (
215218
}
216219

217220
txCreateOrderCmd = &cobra.Command{
218-
Use: "tx-create-order <address or nickname> <sell-amount> <receive-amount> <chain-id> <receive-address> --fee=10000 --simulate=true",
221+
Use: "tx-create-order <address or nickname> <sell-amount> <receive-amount> <chain-id> <receive-address> --fee=10000 --data=<hex-data> --simulate=true",
219222
Short: "create a sell order - use the simulate flag to generate json only",
220223
Args: cobra.MinimumNArgs(5),
221224
Run: func(cmd *cobra.Command, args []string) {
222-
writeTxResultToConsole(client.TxCreateOrder(argGetAddrOrNickname(args[0]), uint64(argToInt(args[1])), uint64(argToInt(args[2])), uint64(argToInt(args[3])), args[4], getPassword(), !sim, fee))
225+
writeTxResultToConsole(client.TxCreateOrder(argGetAddrOrNickname(args[0]), uint64(argToInt(args[1])), uint64(argToInt(args[2])), uint64(argToInt(args[3])), args[4], getPassword(), argStringToBytes(data), !sim, fee))
223226
},
224227
}
225228

@@ -374,6 +377,11 @@ func writeTxResultToConsole(hash *string, tx json.RawMessage, e lib.ErrorI) {
374377
}
375378
}
376379

380+
func argStringToBytes(data string) []byte {
381+
bz := common.FromHex(data)
382+
return bz
383+
}
384+
377385
func argGetAddr(arg string) string {
378386
bz, err := lib.StringToBytes(arg)
379387
if err != nil {

cmd/rpc/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func (c *Client) TxSubsidy(from AddrOrNickname, amt, chainId uint64, opCode stri
559559
}
560560

561561
func (c *Client) TxCreateOrder(from AddrOrNickname, sellAmount, receiveAmount, chainId uint64, receiveAddress string,
562-
pwd string, submit bool, optFee uint64) (hash *string, tx json.RawMessage, e lib.ErrorI) {
562+
pwd string, data lib.HexBytes, submit bool, optFee uint64) (hash *string, tx json.RawMessage, e lib.ErrorI) {
563563
receiveAddr, err := lib.NewHexBytesFromString(receiveAddress)
564564
if err != nil {
565565
return nil, nil, err
@@ -570,6 +570,7 @@ func (c *Client) TxCreateOrder(from AddrOrNickname, sellAmount, receiveAmount, c
570570
Submit: submit,
571571
ReceiveAmount: receiveAmount,
572572
ReceiveAddress: receiveAddr,
573+
Data: data,
573574
Password: pwd,
574575
txChangeParamRequest: txChangeParamRequest{},
575576
committeesRequest: committeesRequest{fmt.Sprintf("%d", chainId)},

cmd/rpc/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ type txCreateOrder struct {
215215
Fee uint64 `json:"fee"`
216216
Amount uint64 `json:"amount"`
217217
Password string `json:"password"`
218+
Data lib.HexBytes `json:"data"`
218219
Submit bool `json:"submit"`
219220
ReceiveAmount uint64 `json:"receiveAmount"`
220221
ReceiveAddress lib.HexBytes `json:"receiveAddress"`

0 commit comments

Comments
 (0)