Added unmarshalState
This commit is contained in:
parent
53f8f29744
commit
bbe8b18660
@ -35,7 +35,7 @@
|
|||||||
var web3 = require('web3');
|
var web3 = require('web3');
|
||||||
var eth = web3.eth;
|
var eth = web3.eth;
|
||||||
|
|
||||||
web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8545'));
|
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
|
||||||
var desc = [{
|
var desc = [{
|
||||||
"name": "balance(address)",
|
"name": "balance(address)",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
|
2499
cmd/mist/assets/ext/ethereum.js/dist/ethereum.js
vendored
2499
cmd/mist/assets/ext/ethereum.js/dist/ethereum.js
vendored
File diff suppressed because it is too large
Load Diff
50
rpc/args.go
50
rpc/args.go
@ -8,6 +8,30 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Unmarshal state is a helper method which has the ability to decode messsages
|
||||||
|
// that use the `defaultBlock` (https://github.com/ethereum/wiki/wiki/JSON-RPC#the-default-block-parameter)
|
||||||
|
// For example a `call`: [{to: "0x....", data:"0x..."}, "latest"]. The first argument is the transaction
|
||||||
|
// message and the second one refers to the block height (or state) to which to apply this `call`.
|
||||||
|
func unmarshalState(b []byte, iface interface{}, str *string) (err error) {
|
||||||
|
var data []json.RawMessage
|
||||||
|
if err = json.Unmarshal(b, &data); err != nil && len(data) == 0 {
|
||||||
|
return errDecodeArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = json.Unmarshal(data[0], iface); err != nil {
|
||||||
|
return errDecodeArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second argument is optional (transact doesn't require it)
|
||||||
|
if len(data) > 1 {
|
||||||
|
if err = json.Unmarshal(data[1], str); err != nil {
|
||||||
|
return errDecodeArgs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type GetBlockByHashArgs struct {
|
type GetBlockByHashArgs struct {
|
||||||
BlockHash string
|
BlockHash string
|
||||||
Transactions bool
|
Transactions bool
|
||||||
@ -63,10 +87,12 @@ type NewTxArgs struct {
|
|||||||
Gas *big.Int
|
Gas *big.Int
|
||||||
GasPrice *big.Int
|
GasPrice *big.Int
|
||||||
Data string
|
Data string
|
||||||
|
|
||||||
|
BlockHeight string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
|
func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
|
||||||
var obj []struct {
|
var obj struct {
|
||||||
From string `json:"from"`
|
From string `json:"from"`
|
||||||
To string `json:"to"`
|
To string `json:"to"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
@ -74,20 +100,18 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
|
|||||||
GasPrice string `json:"gasPrice"`
|
GasPrice string `json:"gasPrice"`
|
||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}
|
}
|
||||||
|
var height string
|
||||||
if err = json.Unmarshal(b, &obj); err != nil {
|
if err = unmarshalState(b, &obj, &height); err != nil {
|
||||||
return errDecodeArgs
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(obj) < 1 {
|
args.From = obj.From
|
||||||
return errArguments
|
args.To = obj.To
|
||||||
}
|
args.Value = ethutil.Big(obj.Value)
|
||||||
args.From = obj[0].From
|
args.Gas = ethutil.Big(obj.Gas)
|
||||||
args.To = obj[0].To
|
args.GasPrice = ethutil.Big(obj.GasPrice)
|
||||||
args.Value = ethutil.Big(obj[0].Value)
|
args.Data = obj.Data
|
||||||
args.Gas = ethutil.Big(obj[0].Gas)
|
args.BlockHeight = height
|
||||||
args.GasPrice = ethutil.Big(obj[0].GasPrice)
|
|
||||||
args.Data = obj[0].Data
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user