aboutsummaryrefslogtreecommitdiffstats
path: root/core/transaction_util.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-08-17 20:01:41 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-09-22 02:33:28 +0800
commiteaa4473dbd4ad404b85f8f0f63b0418a782351b4 (patch)
tree27eabb671346c279969caafe28d25a44aef0f9a0 /core/transaction_util.go
parent12c0afe4fe9f284dd10a80af7744102dac8bf06b (diff)
downloadgo-tangerine-eaa4473dbd4ad404b85f8f0f63b0418a782351b4.tar.gz
go-tangerine-eaa4473dbd4ad404b85f8f0f63b0418a782351b4.tar.zst
go-tangerine-eaa4473dbd4ad404b85f8f0f63b0418a782351b4.zip
core, core/types: readd transactions after chain re-org
Added a `Difference` method to `types.Transactions` which sets the receiver to the difference of a to b (NOTE: not a **and** b). Transaction pool subscribes to RemovedTransactionEvent adding back to those potential missing from the chain. When a chain re-org occurs remove any transactions that were removed from the canonical chain during the re-org as well as the receipts that were generated in the process. Closes #1746
Diffstat (limited to 'core/transaction_util.go')
-rw-r--r--core/transaction_util.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/core/transaction_util.go b/core/transaction_util.go
index 69c6bc36f..ebe095abb 100644
--- a/core/transaction_util.go
+++ b/core/transaction_util.go
@@ -77,6 +77,22 @@ func PutTransactions(db ethdb.Database, block *types.Block, txs types.Transactio
}
}
+func DeleteTransaction(db ethdb.Database, txHash common.Hash) {
+ db.Delete(txHash[:])
+}
+
+func GetTransaction(db ethdb.Database, txhash common.Hash) *types.Transaction {
+ data, _ := db.Get(txhash[:])
+ if len(data) != 0 {
+ var tx types.Transaction
+ if err := rlp.DecodeBytes(data, &tx); err != nil {
+ return nil
+ }
+ return &tx
+ }
+ return nil
+}
+
// PutReceipts stores the receipts in the current database
func PutReceipts(db ethdb.Database, receipts types.Receipts) error {
batch := new(leveldb.Batch)
@@ -107,6 +123,11 @@ func PutReceipts(db ethdb.Database, receipts types.Receipts) error {
return nil
}
+// Delete a receipts from the database
+func DeleteReceipt(db ethdb.Database, txHash common.Hash) {
+ db.Delete(append(receiptsPre, txHash[:]...))
+}
+
// GetReceipt returns a receipt by hash
func GetReceipt(db ethdb.Database, txHash common.Hash) *types.Receipt {
data, _ := db.Get(append(receiptsPre, txHash[:]...))