aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api/debug_args.go
blob: b72fb03ae4a01544e19f8669ecb15b709ca5e3ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package api

import (
    "encoding/json"
    "fmt"
    "math/big"
    "reflect"

    "github.com/ethereum/go-ethereum/rpc/shared"
)

type WaitForBlockArgs struct {
    MinHeight int
    Timeout   int // in seconds
}

func (args *WaitForBlockArgs) UnmarshalJSON(b []byte) (err error) {
    var obj []interface{}
    if err := json.Unmarshal(b, &obj); err != nil {
        return shared.NewDecodeParamError(err.Error())
    }

    if len(obj) > 2 {
        return fmt.Errorf("waitForArgs needs 0, 1, 2 arguments")
    }

    // default values when not provided
    args.MinHeight = -1
    args.Timeout = -1

    if len(obj) >= 1 {
        var minHeight *big.Int
        if minHeight, err = numString(obj[0]); err != nil {
            return err
        }
        args.MinHeight = int(minHeight.Int64())
    }

    if len(obj) >= 2 {
        timeout, err := numString(obj[1])
        if err != nil {
            return err
        }
        args.Timeout = int(timeout.Int64())
    }

    return nil
}

type MetricsArgs struct {
    Raw bool
}

func (args *MetricsArgs) UnmarshalJSON(b []byte) (err error) {
    var obj []interface{}
    if err := json.Unmarshal(b, &obj); err != nil {
        return shared.NewDecodeParamError(err.Error())
    }
    if len(obj) > 1 {
        return fmt.Errorf("metricsArgs needs 0, 1 arguments")
    }
    // default values when not provided
    if len(obj) >= 1 && obj[0] != nil {
        if value, ok := obj[0].(bool); !ok {
            return fmt.Errorf("invalid argument %v", reflect.TypeOf(obj[0]))
        } else {
            args.Raw = value
        }
    }
    return nil
}