Convert existing Body field users to use accessors

pull/1546/head
Eugene Kim 5 years ago
parent 070a42c387
commit ad0434aee4
  1. 2
      core/rawdb/accessors_chain.go
  2. 4
      core/rawdb/accessors_chain_test.go
  3. 5
      core/rawdb/accessors_indexes.go

@ -341,7 +341,7 @@ func ReadBlock(db DatabaseReader, hash common.Hash, number uint64) *types.Block
if body == nil {
return nil
}
return types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles, body.IncomingReceipts)
return types.NewBlockWithHeader(header).WithBody(body.Transactions(), body.Uncles(), body.IncomingReceipts())
}
// WriteBlock serializes a block into the database, header and body separately.

@ -87,7 +87,7 @@ func TestBodyStorage(t *testing.T) {
WriteBody(db, hash, 0, body)
if entry := ReadBody(db, hash, 0); entry == nil {
t.Fatalf("Stored body not found")
} else if types.DeriveSha(types.Transactions(entry.Transactions)) != types.DeriveSha(types.Transactions(body.Transactions)) || types.CalcUncleHash(entry.Uncles) != types.CalcUncleHash(body.Uncles) {
} else if types.DeriveSha(types.Transactions(entry.Transactions())) != types.DeriveSha(types.Transactions(body.Transactions())) || types.CalcUncleHash(entry.Uncles()) != types.CalcUncleHash(body.Uncles()) {
t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, body)
}
if entry := ReadBodyRLP(db, hash, 0); entry == nil {
@ -142,7 +142,7 @@ func TestBlockStorage(t *testing.T) {
}
if entry := ReadBody(db, block.Hash(), block.NumberU64()); entry == nil {
t.Fatalf("Stored body not found")
} else if types.DeriveSha(types.Transactions(entry.Transactions)) != types.DeriveSha(block.Transactions()) || types.CalcUncleHash(entry.Uncles) != types.CalcUncleHash(block.Uncles()) {
} else if types.DeriveSha(types.Transactions(entry.Transactions())) != types.DeriveSha(block.Transactions()) || types.CalcUncleHash(entry.Uncles()) != types.CalcUncleHash(block.Uncles()) {
t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, block.Body())
}
if actual, err := ReadEpochBlockNumber(db, big.NewInt(0)); err != nil {

@ -71,7 +71,8 @@ func ReadTransaction(db DatabaseReader, hash common.Hash) (*types.Transaction, c
return nil, common.Hash{}, 0, 0
}
body := ReadBody(db, blockHash, blockNumber)
if body == nil || len(body.Transactions) <= int(txIndex) {
txs := body.Transactions()
if body == nil || len(txs) <= int(txIndex) {
utils.Logger().Error().
Uint64("number", blockNumber).
Str("hash", blockHash.Hex()).
@ -79,7 +80,7 @@ func ReadTransaction(db DatabaseReader, hash common.Hash) (*types.Transaction, c
Msg("Transaction referenced missing")
return nil, common.Hash{}, 0, 0
}
return body.Transactions[txIndex], blockHash, blockNumber, txIndex
return txs[txIndex], blockHash, blockNumber, txIndex
}
// ReadReceipt retrieves a specific transaction receipt from the database, along with

Loading…
Cancel
Save