/
get_bundle_stats.go
66 lines (56 loc) · 1.63 KB
/
get_bundle_stats.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
package flashbots
import (
"math/big"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
)
type bundleStatsRequest struct {
BundleHash common.Hash `json:"bundleHash"`
BlockNumber *hexutil.Big `json:"blockNumber"`
}
type BundleStatsResponse struct {
IsSimulated bool
IsSentToMiners bool
IsHighPriority bool
SimulatedAt time.Time
SubmittedAt time.Time
SentToMinersAt time.Time
}
// BundleStats requests the bundles Flashbots relay stats. The given block
// number must be within 20 blocks of the current chain tip.
func BundleStats(bundleHash common.Hash, blockNumber *big.Int) *BundleStatsFactory {
return &BundleStatsFactory{bundleHash: bundleHash, blockNumber: blockNumber}
}
type BundleStatsFactory struct {
// args
bundleHash common.Hash
blockNumber *big.Int
// returns
result BundleStatsResponse
returns *BundleStatsResponse
}
func (f *BundleStatsFactory) Returns(bundleStats *BundleStatsResponse) *BundleStatsFactory {
f.returns = bundleStats
return f
}
// CreateRequest implements the w3/core.RequestCreator interface.
func (f *BundleStatsFactory) CreateRequest() (rpc.BatchElem, error) {
return rpc.BatchElem{
Method: "flashbots_getBundleStats",
Args: []interface{}{&bundleStatsRequest{
BundleHash: f.bundleHash,
BlockNumber: (*hexutil.Big)(f.blockNumber),
}},
Result: &f.result,
}, nil
}
// HandleResponse implements the w3/core.ResponseHandler interface.
func (f *BundleStatsFactory) HandleResponse(elem rpc.BatchElem) error {
if err := elem.Error; err != nil {
return err
}
*f.returns = f.result
return nil
}