Update NewTXArgs to accept hex

This commit is contained in:
Taylor Gerring 2015-03-04 08:22:59 -06:00
parent c92e48ce3f
commit c3deafabda
2 changed files with 28 additions and 21 deletions

View File

@ -252,12 +252,12 @@ func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *interface{}) error {
} }
func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error { func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error {
if len(args.Gas) == 0 { if args.Gas == ethutil.Big0 {
args.Gas = defaultGas.String() args.Gas = defaultGas
} }
if len(args.GasPrice) == 0 { if args.GasPrice == ethutil.Big0 {
args.GasPrice = defaultGasPrice.String() args.GasPrice = defaultGasPrice
} }
// TODO if no_private_key then // TODO if no_private_key then
@ -281,7 +281,10 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error {
p.register[ags.From] = append(p.register[args.From], args) p.register[ags.From] = append(p.register[args.From], args)
} }
*/ */
result, _ := p.xeth().Transact( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data) result, err := p.xeth().Transact( /* TODO specify account */ args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
if err != nil {
return err
}
*reply = result *reply = result
//} //}
@ -289,7 +292,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error {
} }
func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error { func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error {
result, err := p.xeth().Call( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data) result, err := p.xeth().Call( /* TODO specify account */ args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,8 +1,12 @@
package rpc package rpc
import "encoding/json" import (
"encoding/json"
"math/big"
import "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/ethutil"
)
type GetBlockArgs struct { type GetBlockArgs struct {
BlockNumber int32 BlockNumber int32
@ -25,9 +29,9 @@ func (obj *GetBlockArgs) UnmarshalJSON(b []byte) (err error) {
type NewTxArgs struct { type NewTxArgs struct {
From string `json:"from"` From string `json:"from"`
To string `json:"to"` To string `json:"to"`
Value string `json:"value"` Value *big.Int `json:"value"`
Gas string `json:"gas"` Gas *big.Int `json:"gas"`
GasPrice string `json:"gasPrice"` GasPrice *big.Int `json:"gasPrice"`
Data string `json:"data"` Data string `json:"data"`
} }
@ -40,18 +44,18 @@ func (obj *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
Gas string Gas string
GasPrice string GasPrice string
Data string Data string
Code string // Code string
} }
if err = json.Unmarshal(b, &ext); err == nil { if err = json.Unmarshal(b, &ext); err == nil {
if len(ext.Data) == 0 { // if len(ext.Data) == 0 {
ext.Data = ext.Code // ext.Data = ext.Code
} // }
obj.From = ext.From obj.From = ext.From
obj.To = ext.To obj.To = ext.To
obj.Value = ext.Value obj.Value = ethutil.Big(ext.Value)
obj.Gas = ext.Gas obj.Gas = ethutil.Big(ext.Gas)
obj.GasPrice = ext.GasPrice obj.GasPrice = ethutil.Big(ext.GasPrice)
obj.Data = ext.Data obj.Data = ext.Data
return return