@ -485,18 +485,14 @@ public class DefaultBlockchain implements MutableBlockchain {
final List < TransactionReceipt > transactionReceipts ,
final Optional < Difficulty > maybeTotalDifficulty ) {
final BlockchainStorage . Updater updater = blockchainStorage . updater ( ) ;
final Hash hash = block . getHash ( ) ;
updater . putBlockHeader ( hash , block . getHeader ( ) ) ;
updater . putBlockHash ( block . getHeader ( ) . getNumber ( ) , hash ) ;
updater . putBlockBody ( hash , block . getBody ( ) ) ;
final int nbTrx = block . getBody ( ) . getTransactions ( ) . size ( ) ;
for ( int i = 0 ; i < nbTrx ; i + + ) {
final Hash transactionHash = block . getBody ( ) . getTransactions ( ) . get ( i ) . getHash ( ) ;
updater . putTransactionLocation ( transactionHash , new TransactionLocation ( transactionHash , i ) ) ;
}
updater . putTransactionReceipts ( hash , transactionReceipts ) ;
final Hash blockHash = block . getHash ( ) ;
updater . putBlockHeader ( blockHash , block . getHeader ( ) ) ;
updater . putBlockHash ( block . getHeader ( ) . getNumber ( ) , blockHash ) ;
updater . putBlockBody ( blockHash , block . getBody ( ) ) ;
indexTransactionsForBlock ( updater , blockHash , block . getBody ( ) . getTransactions ( ) ) ;
updater . putTransactionReceipts ( blockHash , transactionReceipts ) ;
maybeTotalDifficulty . ifPresent (
totalDifficulty - > updater . putTotalDifficulty ( h ash, totalDifficulty ) ) ;
totalDifficulty - > updater . putTotalDifficulty ( blockHash , totalDifficulty ) ) ;
updater . commit ( ) ;
}
@ -563,7 +559,7 @@ public class DefaultBlockchain implements MutableBlockchain {
updater . putBlockHash ( blockWithReceipts . getNumber ( ) , newBlockHash ) ;
updater . setChainHead ( newBlockHash ) ;
indexTransactionForBlock (
indexTransactions ForBlock (
updater , newBlockHash , blockWithReceipts . getBlock ( ) . getBody ( ) . getTransactions ( ) ) ;
gasUsedCounter . inc ( blockWithReceipts . getHeader ( ) . getGasUsed ( ) ) ;
numberOfTransactionsCounter . inc (
@ -652,7 +648,7 @@ public class DefaultBlockchain implements MutableBlockchain {
// Update indexed transactions
newTransactions . forEach (
( blockHash , transactionsInBlock ) - > {
indexTransactionForBlock ( updater , blockHash , transactionsInBlock ) ;
indexTransactions ForBlock ( updater , blockHash , transactionsInBlock ) ;
// Don't remove transactions that are being re-indexed.
removedTransactions . removeAll ( transactionsInBlock ) ;
} ) ;
@ -792,11 +788,11 @@ public class DefaultBlockchain implements MutableBlockchain {
chainHeadOmmerCount = block . getBody ( ) . getOmmers ( ) . size ( ) ;
}
private static void indexTransactionForBlock (
final BlockchainStorage . Updater updater , final Hash h ash, final List < Transaction > txs ) {
for ( int i = 0 ; i < txs . size ( ) ; i + + ) {
final Hash txHash = txs . get ( i ) . getHash ( ) ;
final TransactionLocation loc = new TransactionLocation ( h ash, i ) ;
private static void indexTransactions ForBlock (
final BlockchainStorage . Updater updater , final Hash blockH ash, final List < Transaction > txs ) {
for ( int index = 0 ; index < txs . size ( ) ; index + + ) {
final Hash txHash = txs . get ( index ) . getHash ( ) ;
final TransactionLocation loc = new TransactionLocation ( blockH ash, index ) ;
updater . putTransactionLocation ( txHash , loc ) ;
}
}