def spend_utxo(self, utxo_id, new_owner, amount, signer): """Creates a spending transaction and inserts it into the chain. Args: utxo_id (int): Identifier of the UTXO to spend. new_owner (EthereumAccount): Account to own the output of this spend. amount (int): Amount to spend. signer (EthereumAccount): Account to sign this transaction. Returns: int: Unique identifier of the spend. """ spend_tx = Transaction(*decode_utxo_id(utxo_id), 0, 0, 0, NULL_ADDRESS, new_owner.address, amount, NULL_ADDRESS, 0) spend_tx.sign1(signer.key) blknum = self.root_chain.currentChildBlock() block = Block(transaction_set=[spend_tx], number=blknum) block.sign(self.operator.key) self.root_chain.submitBlock(block.root) self.child_chain.add_block(block) return encode_utxo_id(blknum, 0, 0)
def submit_block(self, transactions, signer=None, force_invalid=False): signer = signer or self.operator blknum = self.root_chain.nextChildBlock() block = Block(transactions, number=blknum) block.sign(signer.key) self.root_chain.submitBlock(block.root, sender=signer.key) if force_invalid: self.child_chain.blocks[self.child_chain.next_child_block] = block self.child_chain.next_deposit_block = self.child_chain.next_child_block + 1 self.child_chain.next_child_block += self.child_chain.child_block_interval else: assert self.child_chain.add_block(block) return blknum