-
Notifications
You must be signed in to change notification settings - Fork 0
/
eth_key.go
76 lines (65 loc) · 2.23 KB
/
eth_key.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
package presenters
import (
"time"
commonassets "github.com/O1MaGnUmO1/chainlink-common/pkg/assets"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/chains/evm/assets"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/chains/evm/utils/big"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/services/keystore/keys/ethkey"
)
// ETHKeyResource represents a ETH key JSONAPI resource. It holds the hex
// representation of the address plus its ETH & LINK balances
type ETHKeyResource struct {
JAID
EVMChainID big.Big `json:"evmChainID"`
Address string `json:"address"`
EthBalance *assets.Eth `json:"ethBalance"`
LinkBalance *commonassets.Link `json:"linkBalance"`
Disabled bool `json:"disabled"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
MaxGasPriceWei *big.Big `json:"maxGasPriceWei"`
}
// GetName implements the api2go EntityNamer interface
//
// This is named as such for backwards compatibility with the operator ui
// TODO - Standardise this to ethKeys
func (r ETHKeyResource) GetName() string {
return "eTHKeys"
}
// NewETHKeyOption defines a functional option which allows customisation of the
// EthKeyResource
type NewETHKeyOption func(*ETHKeyResource)
// NewETHKeyResource constructs a new ETHKeyResource from a Key.
//
// Use the functional options to inject the ETH and LINK balances
func NewETHKeyResource(k ethkey.KeyV2, state ethkey.State, opts ...NewETHKeyOption) *ETHKeyResource {
r := ÐKeyResource{
JAID: NewJAID(k.Address.Hex()),
EVMChainID: state.EVMChainID,
Address: k.Address.Hex(),
EthBalance: nil,
LinkBalance: nil,
Disabled: state.Disabled,
CreatedAt: state.CreatedAt,
UpdatedAt: state.UpdatedAt,
}
for _, opt := range opts {
opt(r)
}
return r
}
func SetETHKeyEthBalance(ethBalance *assets.Eth) NewETHKeyOption {
return func(r *ETHKeyResource) {
r.EthBalance = ethBalance
}
}
func SetETHKeyLinkBalance(linkBalance *commonassets.Link) NewETHKeyOption {
return func(r *ETHKeyResource) {
r.LinkBalance = linkBalance
}
}
func SetETHKeyMaxGasPriceWei(maxGasPriceWei *big.Big) NewETHKeyOption {
return func(r *ETHKeyResource) {
r.MaxGasPriceWei = maxGasPriceWei
}
}