Teach wallet to include optional Tx input data

pull/577/head
Eugene Kim 6 years ago
parent 67eac97cde
commit 39fcb1a3e6
  1. 23
      cmd/client/wallet/main.go

@ -3,6 +3,7 @@ package main
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"crypto/rand" "crypto/rand"
"encoding/base64"
"encoding/hex" "encoding/hex"
"flag" "flag"
"fmt" "fmt"
@ -48,11 +49,12 @@ var (
accountImportPtr = accountImportCommand.String("privateKey", "", "Specify the private key to import") accountImportPtr = accountImportCommand.String("privateKey", "", "Specify the private key to import")
// Transfer subcommands // Transfer subcommands
transferCommand = flag.NewFlagSet("transfer", flag.ExitOnError) transferCommand = flag.NewFlagSet("transfer", flag.ExitOnError)
transferSenderPtr = transferCommand.String("from", "0", "Specify the sender account address or index") transferSenderPtr = transferCommand.String("from", "0", "Specify the sender account address or index")
transferReceiverPtr = transferCommand.String("to", "", "Specify the receiver account") transferReceiverPtr = transferCommand.String("to", "", "Specify the receiver account")
transferAmountPtr = transferCommand.Float64("amount", 0, "Specify the amount to transfer") transferAmountPtr = transferCommand.Float64("amount", 0, "Specify the amount to transfer")
transferShardIDPtr = transferCommand.Int("shardID", -1, "Specify the shard ID for the transfer") transferShardIDPtr = transferCommand.Int("shardID", -1, "Specify the shard ID for the transfer")
transferInputDataPtr = transferCommand.String("inputData", "", "Base64-encoded input data to embed in the transaction")
freeTokenCommand = flag.NewFlagSet("getFreeToken", flag.ExitOnError) freeTokenCommand = flag.NewFlagSet("getFreeToken", flag.ExitOnError)
freeTokenAddressPtr = freeTokenCommand.String("address", "", "Specify the account address to receive the free token") freeTokenAddressPtr = freeTokenCommand.String("address", "", "Specify the account address to receive the free token")
@ -93,6 +95,7 @@ func main() {
fmt.Println(" --to - The receiver account's address") fmt.Println(" --to - The receiver account's address")
fmt.Println(" --amount - The amount of token to transfer") fmt.Println(" --amount - The amount of token to transfer")
fmt.Println(" --shardID - The shard Id for the transfer") fmt.Println(" --shardID - The shard Id for the transfer")
fmt.Println(" --inputData - Base64-encoded input data to embed in the transaction")
os.Exit(1) os.Exit(1)
} }
@ -212,6 +215,14 @@ func processTransferCommand() {
receiver := *transferReceiverPtr receiver := *transferReceiverPtr
amount := *transferAmountPtr amount := *transferAmountPtr
shardID := *transferShardIDPtr shardID := *transferShardIDPtr
base64InputData := *transferInputDataPtr
inputData, err := base64.StdEncoding.DecodeString(base64InputData)
if err != nil {
fmt.Printf("Cannot base64-decode input data (%s): %s\n",
base64InputData, err)
return
}
if shardID == -1 { if shardID == -1 {
fmt.Println("Please specify the shard ID for the transfer (e.g. --shardID=0)") fmt.Println("Please specify the shard ID for the transfer (e.g. --shardID=0)")
@ -273,7 +284,7 @@ func processTransferCommand() {
amountBigInt := big.NewInt(int64(amount * params.GWei)) amountBigInt := big.NewInt(int64(amount * params.GWei))
amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(params.GWei)) amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(params.GWei))
tx, _ := types.SignTx(types.NewTransaction(state.nonce, receiverAddress, uint32(shardID), amountBigInt, params.TxGas, nil, nil), types.HomesteadSigner{}, senderPriKey) tx, _ := types.SignTx(types.NewTransaction(state.nonce, receiverAddress, uint32(shardID), amountBigInt, params.TxGas, nil, inputData), types.HomesteadSigner{}, senderPriKey)
wallet.SubmitTransaction(tx, walletNode, uint32(shardID)) wallet.SubmitTransaction(tx, walletNode, uint32(shardID))
} }

Loading…
Cancel
Save