Skip to content

Commit bd13c32

Browse files
committed
core/rawdb, eth: fix lost sign bit, shorten API output fields
1 parent 29025ab commit bd13c32

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

core/rawdb/accessors_metadata.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,33 @@ func WriteTransitionStatus(db ethdb.KeyValueWriter, data []byte) {
192192
// specific block. If unavailable for the specific block (non full synced node),
193193
// nil will be returned.
194194
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 {
197197
return nil
198198
}
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
200207
}
201208

202209
// WriteIssuance stores the amount of Ether (in wei) issued (or burnt) in a
203210
// specific block.
204211
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 {
206222
log.Crit("Failed to store block issuance", "err", err)
207223
}
208224
}

eth/api.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,14 @@ func (api *PublicEthereumAPI) Issuance(ctx context.Context, from uint64) (*rpc.S
8989

9090
// Define an internal type for issuance notifications
9191
type issuanceNotification struct {
92-
Number uint64 `json:"blockNumber"`
93-
Hash common.Hash `json:"blockHash"`
94-
Issuance *big.Int `json:"totalIssuance"`
95-
Subsidy *big.Int `json:"subsidyMining"`
96-
Uncles *big.Int `json:"subsidyUncles"`
97-
Burn *big.Int `json:"burnProtocol"`
98-
Destruct *big.Int `json:"burnDestruct"`
92+
Number uint64 `json:"block"`
93+
Hash common.Hash `json:"hash"`
94+
Issuance *big.Int `json:"issuance"`
95+
Subsidy *big.Int `json:"subsidy"`
96+
Uncles *big.Int `json:"uncles"`
97+
Burn *big.Int `json:"burn"`
98+
Destruct *big.Int `json:"destruct"`
9999
}
100-
101100
// Define a method to convert a block into an issuance notification
102101
service := func(block *types.Block) {
103102
// Retrieve the state-crawled issuance - if available

0 commit comments

Comments
 (0)