@@ -29,16 +29,18 @@ type (
29
29
30
30
contract struct {
31
31
* Account
32
- dirtyCode bool // contract's code has been set
33
- dirtyState bool // contract's account state has changed
34
- code []byte // contract byte-code
35
- trie trie.Trie // storage trie of the contract
32
+ dirtyCode bool // contract's code has been set
33
+ dirtyState bool // contract's account state has changed
34
+ addr hash.PKHash // contract's address
35
+ code []byte // contract byte-code
36
+ trie trie.Trie // storage trie of the contract
36
37
}
37
38
)
38
39
39
40
// GetState get the value from contract storage
40
41
func (c * contract ) GetState (key hash.Hash32B ) ([]byte , error ) {
41
- v , err := c .trie .Get (key [:])
42
+ slot := hash .Hash256b (append (key [:], c .addr [:]... ))
43
+ v , err := c .trie .Get (slot [:])
42
44
if err != nil {
43
45
return nil , err
44
46
}
@@ -48,7 +50,8 @@ func (c *contract) GetState(key hash.Hash32B) ([]byte, error) {
48
50
// SetState set the value into contract storage
49
51
func (c * contract ) SetState (key hash.Hash32B , value []byte ) error {
50
52
c .dirtyState = true
51
- return c .trie .Upsert (key [:], value )
53
+ slot := hash .Hash256b (append (key [:], c .addr [:]... ))
54
+ return c .trie .Upsert (slot [:], value )
52
55
}
53
56
54
57
// GetCode gets the contract's byte-code
@@ -94,9 +97,10 @@ func (c *contract) RootHash() hash.Hash32B {
94
97
}
95
98
96
99
// newContract returns a Contract instance
97
- func newContract (state * Account , tr trie.Trie ) Contract {
100
+ func newContract (state * Account , pkhash hash. PKHash , tr trie.Trie ) Contract {
98
101
c := contract {
99
102
Account : state ,
103
+ addr : pkhash ,
100
104
trie : tr ,
101
105
}
102
106
c .trie .Start (context .Background ())
0 commit comments