web3-flashbots icon indicating copy to clipboard operation
web3-flashbots copied to clipboard

Munger throws TypeError if optional `opts` dict not provided

Open BowTiedDevil opened this issue 2 years ago • 1 comments

The default argument opts=None within send_raw_bundle_munger leads to exception TypeError: argument of type 'NoneType' is not iterable inside this code block:

def send_raw_bundle_munger(
    self,
    signed_bundled_transactions: List[HexBytes],
    target_block_number: int,
    opts: Optional[FlashbotsOpts] = None,
) -> List[Any]:
    """Given a raw signed bundle, it packages it up with the block number and the timestamps"""
    # convert to hex
    return [
        {
            "txs": list(map(lambda x: self.to_hex(x), signed_bundled_transactions)),
            "blockNumber": hex(target_block_number),
            "minTimestamp": opts["minTimestamp"] if "minTimestamp" in opts else 0,
            "maxTimestamp": opts["maxTimestamp"] if "maxTimestamp" in opts else 0,
            "revertingTxHashes": opts["revertingTxHashes"]
            if "revertingTxHashes" in opts
            else [],
            "replacementUuid": opts["replacementUuid"]
            if "replacementUuid" in opts
            else None,
        }
    ]

None is not iterable, so the ternary assignment "minTimestamp": opts["minTimestamp"] if "minTimestamp" in opts else 0, throws the title exception.

The code works fine if opts={} is provided to send_bundle, so the fix is to set opts={} inside the munger if a value was not included.

Will submit a PR after doing a few tests.

BowTiedDevil avatar Jan 23 '23 06:01 BowTiedDevil

Thank you @BowTiedDevil! Your contributions are always very much appreciated 🙏 🙏

zeroXbrock avatar Jan 24 '23 03:01 zeroXbrock