forked from tellor-io/telliot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
argTypes.go
executable file
·81 lines (66 loc) · 1.37 KB
/
argTypes.go
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
72
73
74
75
76
77
78
79
80
81
// Copyright (c) The Tellor Authors.
// Licensed under the MIT License.
package main
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/tellor-io/TellorMiner/pkg/util"
)
type TRBAmount struct {
*big.Int
}
func (a *TRBAmount) Set(v string) error {
f, _, err := big.ParseFloat(v, 10, 256, 0)
if err != nil {
return err
}
scale := big.NewFloat(1e18)
f.Mul(f, scale)
a.Int, _ = f.Int(nil)
return nil
}
func (a *TRBAmount) String() string {
return util.FormatERC20Balance(a.Int)
}
func (a *TRBAmount) IsDefault() bool {
return true
}
type ETHAddress struct {
addr common.Address
}
func (a *ETHAddress) Set(v string) error {
valid := common.IsHexAddress(v)
if !valid {
return errors.Errorf("%s valid etherum address format", v)
}
a.addr = common.HexToAddress(v)
return nil
}
func (a *ETHAddress) String() string {
return a.addr.String()
}
func (a *ETHAddress) IsDefault() bool {
return true
}
type EthereumInt struct {
*big.Int
}
func (b *EthereumInt) Set(v string) error {
g := new(big.Int)
_, ok := g.SetString(v, 10)
if !ok {
return errors.Errorf("%s is not a valid integer", v)
}
if len(g.Bytes()) > 32 {
return errors.Errorf("%s is larger than 256 bits", v)
}
b.Int = g
return nil
}
func (b *EthereumInt) String() string {
return b.Int.Text(10)
}
func (b *EthereumInt) IsDefault() bool {
return true
}