-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstate_update.go
115 lines (98 loc) · 3.29 KB
/
state_update.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package data
// Nonce -
type Nonce struct {
ContractAddress Felt `json:"contract_address"`
Nonce Felt `json:"nonce"`
}
// StorageDiff -
type StorageDiff struct {
Address Felt `json:"address"`
StorageEntries []KeyValue `json:"storage_entries"`
}
// KeyValue -
type KeyValue struct {
Key Felt `json:"key"`
Value Felt `json:"value"`
}
// DeployedContract -
type DeployedContract struct {
Address Felt `json:"address"`
ClassHash Felt `json:"class_hash"`
}
// DeclaredClass -
type DeclaredClass struct {
ClassHash Felt `json:"class_hash"`
CompiledClassHash Felt `json:"compiled_class_hash"`
}
// StateDiff -
type StateDiff struct {
StorageDiffs map[Felt][]KeyValue `json:"storage_diffs"`
DeclaredClasses []DeclaredClass `json:"declared_classes"`
ReplacedClasses []ReplacedClass `json:"replaced_classes"`
OldDeclaredContracts []Felt `json:"old_declared_contracts"`
DeployedContracts []DeployedContract `json:"deployed_contracts"`
Nonces map[Felt]Felt `json:"nonces"`
}
type ReplacedClass struct {
Address Felt `json:"address"`
ClassHash Felt `json:"class_hash"`
}
type ReplacedClassRpc struct {
Address Felt `json:"contract_address"`
ClassHash Felt `json:"class_hash"`
}
// StateUpdate -
type StateUpdate struct {
BlockHash Felt `json:"block_hash"`
NewRoot Felt `json:"new_root"`
OldRoot Felt `json:"old_root"`
StateDiff StateDiff `json:"state_diff"`
}
// StateDiffRpc -
type StateDiffRpc struct {
DeclaredClasses []DeclaredClass `json:"declared_classes"`
DeprecatedDeclaredClasses []Felt `json:"deprecated_declared_classes"`
ReplacedClasses []ReplacedClassRpc `json:"replaced_classes"`
DeclaredContractHashes []Felt `json:"declared_contract_hashes"`
DeployedContracts []DeployedContract `json:"deployed_contracts"`
Nonces []Nonce `json:"nonces"`
StorageDiffs []StorageDiff `json:"storage_diffs"`
}
// ToStateDiff -
func (sdr StateDiffRpc) ToStateDiff() StateDiff {
sd := StateDiff{
StorageDiffs: make(map[Felt][]KeyValue),
Nonces: make(map[Felt]Felt),
DeclaredClasses: sdr.DeclaredClasses,
ReplacedClasses: make([]ReplacedClass, len(sdr.ReplacedClasses)),
OldDeclaredContracts: append(sdr.DeclaredContractHashes, sdr.DeprecatedDeclaredClasses...),
DeployedContracts: sdr.DeployedContracts,
}
for i := range sdr.Nonces {
sd.Nonces[sdr.Nonces[i].ContractAddress] = sdr.Nonces[i].Nonce
}
for i := range sdr.StorageDiffs {
sd.StorageDiffs[sdr.StorageDiffs[i].Address] = sdr.StorageDiffs[i].StorageEntries
}
for i := range sdr.ReplacedClasses {
sd.ReplacedClasses[i].Address = sdr.ReplacedClasses[i].Address
sd.ReplacedClasses[i].ClassHash = sdr.ReplacedClasses[i].ClassHash
}
return sd
}
// StateUpdateRpc -
type StateUpdateRpc struct {
BlockHash Felt `json:"block_hash"`
NewRoot Felt `json:"new_root"`
OldRoot Felt `json:"old_root"`
StateDiff StateDiffRpc `json:"state_diff"`
}
// ToStateUpdate -
func (sur StateUpdateRpc) ToStateUpdate() StateUpdate {
return StateUpdate{
BlockHash: sur.BlockHash,
NewRoot: sur.NewRoot,
OldRoot: sur.OldRoot,
StateDiff: sur.StateDiff.ToStateDiff(),
}
}