-
Notifications
You must be signed in to change notification settings - Fork 2
/
tmp_status_node.go
54 lines (37 loc) · 1006 Bytes
/
tmp_status_node.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
package sdk
import (
"bchain.io/common/types"
"bchain.io/utils/crypto"
)
type TmpKey struct {
contractAddress types.Address
key types.Address
stateRoot types.Hash //nothing or a last stateRoot
}
func (this *TmpKey)MakeHashKey()(types.Hash , error){
keyHexLen := types.AddressLength + len(this.key) + types.HashLength
keyHex := make([]byte , keyHexLen)
keyHex = keyHex[:0]
keyHex = append(keyHex , this.contractAddress[:]...)
keyHex = append(keyHex , this.key[:]...)
keyHex = append(keyHex , this.stateRoot[:]...)
hash := crypto.Keccak256Hash(keyHex)
return hash , nil
}
type TmpStatusNode struct {
Modified map[TmpKey][]byte
}
func NewStatusNode()*TmpStatusNode{
n := new(TmpStatusNode)
n.Modified = make(map[TmpKey][]byte)
return n
}
func (this *TmpStatusNode)ExistValue(tmpKey TmpKey)[]byte{
if value , ok := this.Modified[tmpKey];ok{
return value
}
return nil
}
func (this *TmpStatusNode)SetValue(tmpKey TmpKey , value []byte){
this.Modified[tmpKey] = value
}