-
Notifications
You must be signed in to change notification settings - Fork 2
/
access_list.go
55 lines (43 loc) · 1.37 KB
/
access_list.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
package types
import (
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
)
// AccessList is an EIP-2930 access list that represents the slice of
// the protobuf AccessTuples.
type AccessList []AccessTuple
// NewAccessList creates a new protobuf-compatible AccessList from an ethereum
// core AccessList type
func NewAccessList(ethAccessList *ethtypes.AccessList) AccessList {
if ethAccessList == nil {
return nil
}
al := AccessList{}
for _, tuple := range *ethAccessList {
storageKeys := make([]string, len(tuple.StorageKeys))
for i := range tuple.StorageKeys {
storageKeys[i] = tuple.StorageKeys[i].String()
}
al = append(al, AccessTuple{
Address: tuple.Address.String(),
StorageKeys: storageKeys,
})
}
return al
}
// ToEthAccessList is an utility function to convert the protobuf compatible
// AccessList to eth core AccessList from go-ethereum
func (al AccessList) ToEthAccessList() *ethtypes.AccessList {
var ethAccessList ethtypes.AccessList
for _, tuple := range al {
storageKeys := make([]common.Hash, len(tuple.StorageKeys))
for i := range tuple.StorageKeys {
storageKeys[i] = common.HexToHash(tuple.StorageKeys[i])
}
ethAccessList = append(ethAccessList, ethtypes.AccessTuple{
Address: common.HexToAddress(tuple.Address),
StorageKeys: storageKeys,
})
}
return ðAccessList
}