diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-07-03 17:24:42 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-07-03 19:56:50 +0800 |
commit | 29e2fb38f8e80dfa077d139d8ff563169c644d74 (patch) | |
tree | 95ddfb2c8fb11cbaae65c9ee59555411debef4cf /core/transaction_util.go | |
parent | 03129e7c93a4705eb159a2dacbab6e3755fe02ed (diff) | |
download | dexon-29e2fb38f8e80dfa077d139d8ff563169c644d74.tar dexon-29e2fb38f8e80dfa077d139d8ff563169c644d74.tar.gz dexon-29e2fb38f8e80dfa077d139d8ff563169c644d74.tar.bz2 dexon-29e2fb38f8e80dfa077d139d8ff563169c644d74.tar.lz dexon-29e2fb38f8e80dfa077d139d8ff563169c644d74.tar.xz dexon-29e2fb38f8e80dfa077d139d8ff563169c644d74.tar.zst dexon-29e2fb38f8e80dfa077d139d8ff563169c644d74.zip |
core, miner: miner header validation, transaction & receipt writing
* Miners do now verify their own header, not their state.
* Changed old putTx and putReceipts to be exported
* Moved writing of transactions and receipts out of the block processer
in to the chain manager. Closes #1386
* Miner post ChainHeadEvent & ChainEvent. Closes #1388
Diffstat (limited to 'core/transaction_util.go')
-rw-r--r-- | core/transaction_util.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/transaction_util.go b/core/transaction_util.go new file mode 100644 index 000000000..bbb215d91 --- /dev/null +++ b/core/transaction_util.go @@ -0,0 +1,51 @@ +package core + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/rlp" +) + +func PutTransactions(db common.Database, block *types.Block, txs types.Transactions) { + for i, tx := range block.Transactions() { + rlpEnc, err := rlp.EncodeToBytes(tx) + if err != nil { + glog.V(logger.Debug).Infoln("Failed encoding tx", err) + return + } + db.Put(tx.Hash().Bytes(), rlpEnc) + + var txExtra struct { + BlockHash common.Hash + BlockIndex uint64 + Index uint64 + } + txExtra.BlockHash = block.Hash() + txExtra.BlockIndex = block.NumberU64() + txExtra.Index = uint64(i) + rlpMeta, err := rlp.EncodeToBytes(txExtra) + if err != nil { + glog.V(logger.Debug).Infoln("Failed encoding tx meta data", err) + return + } + db.Put(append(tx.Hash().Bytes(), 0x0001), rlpMeta) + } +} + +func PutReceipts(db common.Database, hash common.Hash, receipts types.Receipts) error { + storageReceipts := make([]*types.ReceiptForStorage, len(receipts)) + for i, receipt := range receipts { + storageReceipts[i] = (*types.ReceiptForStorage)(receipt) + } + + bytes, err := rlp.EncodeToBytes(storageReceipts) + if err != nil { + return err + } + + db.Put(append(receiptsPre, hash[:]...), bytes) + + return nil +} |