forked from chenzhijie/go-web3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
77 lines (68 loc) · 2.31 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
package flashbots
import (
"encoding/json"
"errors"
"math/big"
)
const (
DefaultRelayURL = "https://relay.flashbots.net"
TestRelayURL = "https://relay-goerli.flashbots.net"
)
type BundleResult struct {
BundleHash string `json:"bundleHash"`
}
type txResult struct {
CoinbaseDiff string `json:"coinbaseDiff"`
EthSentToCoinbase string `json:"ethSentToCoinbase"`
FromAddress string `json:"fromAddress"`
GasFees string `json:"gasFees"`
GasPrice string `json:"gasPrice"`
GasUsed uint64 `json:"gasUsed"`
ToAddress string `json:"toAddress"`
TxHash string `json:"txHash"`
Value string `json:"value"`
Error string `json:"error,omitempty"`
}
type CallResult struct {
BundleGasPrice string `json:"bundleGasPrice"`
BundleHash string `json:"bundleHash"`
CoinbaseDiff string `json:"coinbaseDiff"`
EthSentToCoinbase string `json:"ethSentToCoinbase"`
GasFees string `json:"gasFees"`
Results []txResult `json:"results"`
StateBlockNumber uint64 `json:"stateBlockNumber"`
TotalGasUsed uint64 `json:"totalGasUsed"`
}
func (cr *CallResult) String() string {
r, err := json.Marshal(cr)
if err != nil {
return err.Error()
}
return string(r)
}
func (r *CallResult) EffectiveGasPrice() (*big.Int, error) {
gu := new(big.Int).SetUint64(r.TotalGasUsed)
gp, ok := new(big.Int).SetString(r.CoinbaseDiff, 10)
if !ok {
return nil, errors.New("invalid value returned for CoinbaseDiff")
}
wei := new(big.Int).Div(gp, gu)
return wei, nil
}
type UserStats struct {
IsHighPriority bool `json:"is_high_priority"`
AllTimeMinerPayments string `json:"all_time_miner_payments"`
AllTimeGasSimulated string `json:"all_time_gas_simulated"`
Last7dMinerPayments string `json:"last_7d_miner_payments"`
Last7dGasSimulated string `json:"last_7d_gas_simulated"`
Last1dMinerPayments string `json:"last_1d_miner_payments"`
Last1dGasSimulated string `json:"last_1d_gas_simulated"`
}
type BundleStats struct {
IsHighPriority bool `json:"is_high_priority"`
IsSimulated bool `json:"is_simulated"`
IsSentToMiners bool `json:"is_sent_to_miners"`
SimulatedAt string `json:"simulated_at"`
SubmittedAt string `json:"submitted_at"`
SentToMinersAt string `json:"sent_to_miners_at"`
}