-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathapi_deneb.go
More file actions
55 lines (46 loc) · 1.87 KB
/
api_deneb.go
File metadata and controls
55 lines (46 loc) · 1.87 KB
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
package api
import (
"math/big"
"github.com/snowfork/go-substrate-rpc-client/v4/types"
"github.com/snowfork/snowbridge/relayer/relays/beacon/header/syncer/scale"
"github.com/snowfork/snowbridge/relayer/relays/beacon/state"
"github.com/snowfork/snowbridge/relayer/relays/util"
)
func DenebExecutionPayloadToScale(e *state.ExecutionPayloadDeneb) (scale.ExecutionPayloadHeaderDeneb, error) {
var payloadHeader scale.ExecutionPayloadHeaderDeneb
transactionsContainer := state.TransactionsRootContainer{}
transactionsContainer.Transactions = e.Transactions
transactionsRoot, err := transactionsContainer.HashTreeRoot()
if err != nil {
return payloadHeader, err
}
var withdrawalRoot types.H256
withdrawalContainer := state.WithdrawalsRootContainerMainnet{}
withdrawalContainer.Withdrawals = e.Withdrawals
withdrawalRoot, err = withdrawalContainer.HashTreeRoot()
if err != nil {
return payloadHeader, err
}
baseFeePerGas := big.Int{}
// Change BaseFeePerGas back from little-endian to big-endian
baseFeePerGas.SetBytes(util.ChangeByteOrder(e.BaseFeePerGas[:]))
return scale.ExecutionPayloadHeaderDeneb{
ParentHash: types.NewH256(e.ParentHash[:]),
FeeRecipient: e.FeeRecipient,
StateRoot: types.NewH256(e.StateRoot[:]),
ReceiptsRoot: types.NewH256(e.ReceiptsRoot[:]),
LogsBloom: e.LogsBloom[:],
PrevRandao: types.NewH256(e.PrevRandao[:]),
BlockNumber: types.NewU64(e.BlockNumber),
GasLimit: types.NewU64(e.GasLimit),
GasUsed: types.NewU64(e.GasUsed),
Timestamp: types.NewU64(e.Timestamp),
ExtraData: e.ExtraData,
BaseFeePerGas: types.NewU256(baseFeePerGas),
BlockHash: types.NewH256(e.BlockHash[:]),
TransactionsRoot: transactionsRoot,
WithdrawalsRoot: withdrawalRoot,
BlobGasUsed: types.NewU64(e.BlobGasUsed),
ExcessBlobGas: types.NewU64(e.ExcessBlobGas),
}, nil
}