@@ -192,17 +192,33 @@ func WriteTransitionStatus(db ethdb.KeyValueWriter, data []byte) {
192
192
// specific block. If unavailable for the specific block (non full synced node),
193
193
// nil will be returned.
194
194
func ReadIssuance (db ethdb.KeyValueReader , number uint64 , hash common.Hash ) * big.Int {
195
- data , _ := db .Get (issuanceKey (number , hash ))
196
- if len (data ) == 0 {
195
+ blob , _ := db .Get (issuanceKey (number , hash ))
196
+ if len (blob ) < 2 {
197
197
return nil
198
198
}
199
- return new (big.Int ).SetBytes (data )
199
+ // Since negative big ints can't be encoded to bytes directly, use a dirty
200
+ // hack to store the negativift flag in the first byte (0 == positive,
201
+ // 1 == negative)
202
+ issuance := new (big.Int ).SetBytes (blob [1 :])
203
+ if blob [0 ] == 1 {
204
+ issuance .Neg (issuance )
205
+ }
206
+ return issuance
200
207
}
201
208
202
209
// WriteIssuance stores the amount of Ether (in wei) issued (or burnt) in a
203
210
// specific block.
204
211
func WriteIssuance (db ethdb.KeyValueWriter , number uint64 , hash common.Hash , issuance * big.Int ) {
205
- if err := db .Put (issuanceKey (number , hash ), issuance .Bytes ()); err != nil {
212
+ // Since negative big ints can't be encoded to bytes directly, use a dirty
213
+ // hack to store the negativift flag in the first byte (0 == positive,
214
+ // 1 == negative)
215
+ blob := []byte {0 }
216
+ if issuance .Sign () < 0 {
217
+ blob [0 ] = 1
218
+ }
219
+ blob = append (blob , issuance .Bytes ()... )
220
+
221
+ if err := db .Put (issuanceKey (number , hash ), blob ); err != nil {
206
222
log .Crit ("Failed to store block issuance" , "err" , err )
207
223
}
208
224
}
0 commit comments