This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
types.go
122 lines (105 loc) · 2.88 KB
/
types.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package eth
import (
"context"
"encoding/hex"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/magicpool-co/pool/internal/log"
"github.com/magicpool-co/pool/pkg/crypto"
"github.com/magicpool-co/pool/pkg/hostpool"
"github.com/magicpool-co/pool/pkg/stratum/rpc"
"github.com/magicpool-co/pool/types"
)
func generateHost(url string, logger *log.Logger) (*hostpool.HTTPPool, error) {
var (
hostHealthCheck = &hostpool.HTTPHealthCheck{
RPCRequest: &rpc.Request{
ID: []byte(`1`),
JSONRPC: "2.0",
Method: "eth_syncing",
},
}
)
if url == "" {
return nil, nil
}
host := hostpool.NewHTTPPool(context.Background(), logger, hostHealthCheck, nil)
err := host.AddHost(url, 0, nil)
return host, err
}
func New(
mainnet bool,
url, rawPriv string,
erc20 *ERC20,
logger *log.Logger,
) (*Node, error) {
host, err := generateHost(url, logger)
if err != nil {
return nil, err
}
privBytes, err := crypto.ObscureHex(rawPriv)
if err != nil {
return nil, err
}
privKey := secp256k1.PrivKeyFromBytes(privBytes)
pubKeyBytes := privKey.PubKey().SerializeUncompressed()
address := "0x" + hex.EncodeToString(crypto.Keccak256(pubKeyBytes[1:])[12:])
node := &Node{
mocked: host == nil,
mainnet: mainnet,
address: address,
privKey: privKey,
rpcHost: host,
erc20: erc20,
logger: logger,
}
return node, nil
}
type Node struct {
mocked bool
mainnet bool
address string
privKey *secp256k1.PrivateKey
rpcHost *hostpool.HTTPPool
erc20 *ERC20
logger *log.Logger
}
type ERC20 struct {
Chain string
Address string
Decimals int
Units *types.Number
}
type Block struct {
Number string `json:"number"`
Hash string `json:"hash"`
GasLimit string `json:"gasLimit"`
GasUsed string `json:"gasUsed"`
BaseFee string `json:"baseFeePerGas"`
}
type Transaction struct {
Hash string `json:"hash"`
BlockHash string `json:"blockHash"`
BlockNumber string `json:"blockNumber"`
From string `json:"from"`
To string `json:"to"`
Value string `json:"value"`
Gas string `json:"gas"`
GasPrice string `json:"gasPrice"`
MaxFeePerGas string `json:"maxFeePerGas"`
MaxPriorityFeePerGas string `json:"maxPriorityFeePerGas"`
Input string `json:"input"`
Nonce string `json:"nonce"`
Index string `json:"transactionIndex"`
Type string `json:"type"`
V string `json:"v"`
R string `json:"r"`
S string `json:"s"`
}
type TransactionReceipt struct {
TxHash string `json:"transactionHash"`
GasUsed string `json:"gasUsed"`
EffectiveGasPrice string `json:"effectiveGasPrice"`
BlockHash string `json:"blockHash"`
BlockNumber string `json:"blockNumber"`
Status string `json:"status"`
}