-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
133 lines (118 loc) · 3.88 KB
/
utils.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
123
124
125
126
127
128
129
130
131
132
133
package relay_grpc
import (
"fmt"
"math/big"
v1 "github.com/attestantio/go-builder-client/api/v1"
builderSpec "github.com/attestantio/go-builder-client/spec"
consensusspec "github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/holiman/uint256"
"github.com/pkg/errors"
)
var ErrInvalidVersion = errors.New("invalid version")
// Based on the version, delegate to the correct RequestToProtoRequest
func VersionedRequestToProtoRequest(block *builderSpec.VersionedSubmitBlockRequest) (*SubmitBlockRequest, error) {
switch block.Version {
case consensusspec.DataVersionCapella:
return CapellaRequestToProtoRequest(block.Capella), nil
case consensusspec.DataVersionDeneb:
return DenebRequestToProtoRequest(block.Deneb), nil
default:
return nil, errors.Wrap(ErrInvalidVersion, fmt.Sprintf("%s is not supported", block.Version))
}
}
// Based on the version, delegate to the correct RequestToProtoRequestWithShortIDs
func VersionedRequestToProtoRequestWithShortIDs(block *builderSpec.VersionedSubmitBlockRequest, compressTxs []*CompressTx) (*SubmitBlockRequest, error) {
switch block.Version {
case consensusspec.DataVersionCapella:
return CapellaRequestToProtoRequestWithShortIDs(block.Capella, compressTxs), nil
case consensusspec.DataVersionDeneb:
return DenebRequestToProtoRequestWithShortIDs(block.Deneb, compressTxs), nil
default:
return nil, errors.Wrap(ErrInvalidVersion, fmt.Sprintf("%s is not supported", block.Version))
}
}
// Based on the version, delegate to the correct ProtoRequestToVersionedRequest
func ProtoRequestToVersionedRequest(block *SubmitBlockRequest) (*builderSpec.VersionedSubmitBlockRequest, error) {
switch consensusspec.DataVersion(block.Version) {
case consensusspec.DataVersionCapella:
blockRequest, err := ProtoRequestToCapellaRequest(block)
if err != nil {
return nil, err
}
return &builderSpec.VersionedSubmitBlockRequest{
Version: consensusspec.DataVersionCapella,
Capella: blockRequest,
}, nil
case consensusspec.DataVersionDeneb:
blockRequest, err := ProtoRequestToDenebRequest(block)
if err != nil {
return nil, err
}
return &builderSpec.VersionedSubmitBlockRequest{
Version: consensusspec.DataVersionDeneb,
Deneb: blockRequest,
}, nil
default:
return nil, errors.Wrap(ErrInvalidVersion, fmt.Sprintf("%s is not supported", consensusspec.DataVersion(block.Version)))
}
}
type BidTraceExecutionPayload struct {
Timestamp uint64
}
type BidtracePayload struct {
Message *v1.BidTrace
ExecutionPayload *BidTraceExecutionPayload
Signature phase0.BLSSignature
}
func ProtoRequestToBidtracePayload(block *SubmitBlockRequest) (*BidtracePayload, error) {
blockRequest, err := ProtoRequestToDenebBidtracePayload(block)
if err != nil {
return nil, err
}
return blockRequest, nil
}
// b20 converts a byte slice to a [20]byte.
func b20(b []byte) [20]byte {
out := [20]byte{}
copy(out[:], b)
return out
}
// b32 converts a byte slice to a [32]byte.
func b32(b []byte) [32]byte {
out := [32]byte{}
copy(out[:], b)
return out
}
// b48 converts a byte slice to a [48]byte.
func b48(b []byte) [48]byte {
out := [48]byte{}
copy(out[:], b)
return out
}
// b96 converts a byte slice to a [96]byte.
func b96(b []byte) [96]byte {
out := [96]byte{}
copy(out[:], b)
return out
}
// b256 converts a byte slice to a [256]byte.
func b256(b []byte) [256]byte {
out := [256]byte{}
copy(out[:], b)
return out
}
// uint256ToIntToByteSlice converts a *uint256.Int to a byte slice.
func uint256ToIntToByteSlice(u *uint256.Int) []byte {
if u == nil {
return nil
}
// Convert the uint256.Int to a byte slice.
// The Bytes method returns the absolute value as a big-endian byte slice.
return u.Bytes()
}
// byteSliceToUint256Int converts a byte slice to a *uint256.Int.
func byteSliceToUint256Int(b []byte) *uint256.Int {
u256, _ := uint256.FromBig(new(big.Int).SetBytes(b))
return u256
}