mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-30 14:05:23 +00:00
103656dbb5
details: For documentation, see comments in the file tx_pool.nim. For prettified manual pages run 'make docs' in the nimbus directory and point your web browser to the newly created 'docs' directory.
71 lines
2.1 KiB
Nim
71 lines
2.1 KiB
Nim
# Nimbus
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
# Licensed under either of
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
# http://opensource.org/licenses/MIT)
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
# according to those terms.
|
|
|
|
## Transaction Pool Tasklet: Recover From Waste Basket or Create
|
|
## =============================================================
|
|
##
|
|
|
|
import
|
|
../tx_desc,
|
|
../tx_info,
|
|
../tx_item,
|
|
../tx_tabs,
|
|
chronicles,
|
|
eth/[common, keys],
|
|
stew/keyed_queue
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
logScope:
|
|
topics = "tx-pool recover item"
|
|
|
|
let
|
|
nullSender = block:
|
|
var rc: EthAddress
|
|
rc
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public functions
|
|
# ------------------------------------------------------------------------------
|
|
|
|
proc recoverItem*(xp: TxPoolRef; tx: var Transaction;
|
|
status = txItemPending; info = ""): Result[TxItemRef,TxInfo]
|
|
{.gcsafe,raises: [Defect,CatchableError].} =
|
|
## Recover item from waste basket or create new. It is an error if the item
|
|
## is in the buckets database, already.
|
|
let itemID = tx.itemID
|
|
|
|
# Test whether the item is in the database, already
|
|
if xp.txDB.byItemID.hasKey(itemID):
|
|
return err(txInfoErrAlreadyKnown)
|
|
|
|
# Check whether the tx can be re-cycled from waste basket
|
|
block:
|
|
let rc = xp.txDB.byRejects.delete(itemID)
|
|
if rc.isOK:
|
|
let item = rc.value.data
|
|
# must not be a waste tx without meta-data
|
|
if item.sender != nullSender:
|
|
let itemInfo = if info != "": info else: item.info
|
|
item.init(status, itemInfo)
|
|
return ok(item)
|
|
|
|
# New item generated from scratch, e.g. with `nullSender`
|
|
block:
|
|
let rc = TxItemRef.new(tx, itemID, status, info)
|
|
if rc.isOk:
|
|
return ok(rc.value)
|
|
|
|
err(txInfoErrInvalidSender)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# End
|
|
# ------------------------------------------------------------------------------
|