aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/args.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-30 22:20:30 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-30 22:20:30 +0800
commit2f3a9681360f5326137de3aeb0aa8e2130de562a (patch)
tree6e226d0cf53cb6cfd7dba15a6959df09d7ab1237 /rpc/args.go
parentf23529c5cde47f713ada745629a7bdc8e1506fa7 (diff)
downloaddexon-2f3a9681360f5326137de3aeb0aa8e2130de562a.tar
dexon-2f3a9681360f5326137de3aeb0aa8e2130de562a.tar.gz
dexon-2f3a9681360f5326137de3aeb0aa8e2130de562a.tar.bz2
dexon-2f3a9681360f5326137de3aeb0aa8e2130de562a.tar.lz
dexon-2f3a9681360f5326137de3aeb0aa8e2130de562a.tar.xz
dexon-2f3a9681360f5326137de3aeb0aa8e2130de562a.tar.zst
dexon-2f3a9681360f5326137de3aeb0aa8e2130de562a.zip
New CallArgs
Requirements for calls differ from transactions
Diffstat (limited to 'rpc/args.go')
-rw-r--r--rpc/args.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/rpc/args.go b/rpc/args.go
index 25a6c7a4f..dd013147d 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -238,6 +238,93 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
return nil
}
+type CallArgs struct {
+ From string
+ To string
+ Value *big.Int
+ Gas *big.Int
+ GasPrice *big.Int
+ Data string
+
+ BlockNumber int64
+}
+
+func (args *CallArgs) UnmarshalJSON(b []byte) (err error) {
+ var obj []json.RawMessage
+ var ext struct {
+ From string
+ To string
+ Value interface{}
+ Gas interface{}
+ GasPrice interface{}
+ Data string
+ }
+
+ // Decode byte slice to array of RawMessages
+ if err := json.Unmarshal(b, &obj); err != nil {
+ return NewDecodeParamError(err.Error())
+ }
+
+ // Check for sufficient params
+ if len(obj) < 1 {
+ return NewInsufficientParamsError(len(obj), 1)
+ }
+
+ // Decode 0th RawMessage to temporary struct
+ if err := json.Unmarshal(obj[0], &ext); err != nil {
+ return NewDecodeParamError(err.Error())
+ }
+
+ if len(ext.From) == 0 {
+ return NewValidationError("from", "is required")
+ }
+ args.From = ext.From
+
+ if len(ext.To) == 0 {
+ return NewValidationError("to", "is required")
+ }
+ args.To = ext.To
+
+ var num int64
+ if ext.Value == nil {
+ num = int64(0)
+ } else {
+ if err := numString(ext.Value, &num); err != nil {
+ return err
+ }
+ }
+ args.Value = big.NewInt(num)
+
+ if ext.Gas == nil {
+ num = int64(0)
+ } else {
+ if err := numString(ext.Gas, &num); err != nil {
+ return err
+ }
+ }
+ args.Gas = big.NewInt(num)
+
+ if ext.GasPrice == nil {
+ num = int64(0)
+ } else {
+ if err := numString(ext.GasPrice, &num); err != nil {
+ return err
+ }
+ }
+ args.GasPrice = big.NewInt(num)
+
+ args.Data = ext.Data
+
+ // Check for optional BlockNumber param
+ if len(obj) > 1 {
+ if err := blockHeightFromJson(obj[1], &args.BlockNumber); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
type GetStorageArgs struct {
Address string
BlockNumber int64