-
Notifications
You must be signed in to change notification settings - Fork 76
/
eip2930.go
66 lines (53 loc) · 2.21 KB
/
eip2930.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 txs
//EIP-2930 was part of the Berlin upgrade and is seen as a step towards improving the
//efficiency and flexibility of the Ethereum network. It allows for more sophisticated
//transaction handling and can mitigate some of the effects of increased gas costs
//introduced by other changes in the protocol.
//
//Access lists in EIP-2930 provide several benefits:
//1. **Gas Cost Predictability**: By specifying the addresses and keys that will be accessed,
//the sender can pre-calculate the gas costs, making them more predictable.
//2. **Increased Efficiency**: Clients and miners can txs transactions more efficiently,
//as they know in advance which addresses and keys will be accessed.
//3. **Compatibility with Future Upgrades**: Access lists can facilitate smoother upgrades,
//such as the transition to Ethereum 2.0, by allowing transactions to explicitly states their dependencies.
import (
"github.com/artela-network/artela/x/evm/txs/support"
"github.com/ethereum/go-ethereum/common"
ethereum "github.com/ethereum/go-ethereum/core/types"
)
// AccessList is EIP-2930 access list
type AccessList []support.AccessTuple
// NewAccessList creates a new protobuf-compatible AccessList from an ethereum type
func NewAccessList(ethAccessList *ethereum.AccessList) AccessList {
if ethAccessList == nil {
return nil
}
accessList := AccessList{}
for _, tuple := range *ethAccessList {
storageKeys := make([]string, len(tuple.StorageKeys))
for i := range tuple.StorageKeys {
storageKeys[i] = tuple.StorageKeys[i].String()
}
accessList = append(accessList, support.AccessTuple{
Address: tuple.Address.String(),
StorageKeys: storageKeys,
})
}
return accessList
}
// ToEthAccessList convert the protobuf-compatible AccessList to an ethereum AccessList
func (al AccessList) ToEthAccessList() *ethereum.AccessList {
var ethAccessList ethereum.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, ethereum.AccessTuple{
Address: common.HexToAddress(tuple.Address),
StorageKeys: storageKeys,
})
}
return ðAccessList
}