def crc_proposal_withdraw(self): global result result = True # Recipient ela_node = self.node_manager.ela_nodes[1] recipient = ela_node.cr_account.address() # leader privatekey ela_node = self.node_manager.ela_nodes[2] cr_private_key = ela_node.cr_account.private_key() withdraw = CRCProposalWithdraw( private_key=cr_private_key, proposal_hash=self.crc_proposal_hash, ) Logger.info("{} create crc proposal withdraw on success. \n{}".format( self.tag, withdraw)) amount = self.get_withdraw_amount( util.bytes_reverse(self.crc_proposal_hash).hex()) - util.TX_FEE ret = self.tx_manager.crc_proposal_withdraw( input_address=self.CRC_COMMITTEE_ADDRESS, amount=amount, crc_proposal_withdraw=withdraw, output_address=recipient) if not ret: return False self.discrete_miner(1) return result
def __init__(self, value=0, output_lock=0, program_hash=None, output_type=0, output_payload=None): self.asset_id = util.bytes_reverse(bytes.fromhex(self.ASSET_ID)) self.value = value self.output_lock = output_lock self.program_hash = program_hash self.output_type = output_type self.output_payload = output_payload
def handle_tx_result(self, tx: Transaction, port=rpc.DEFAULT_PORT): r = tx.serialize() response = rpc.send_raw_transaction(r.hex(), port) if isinstance(response, dict): Logger.error("{} rpc response: {}".format(self.tag, response)) Logger.error("rpc send raw transaction failed") return False tx_hash = util.bytes_reverse(bytes.fromhex(tx.hash())).hex() Logger.debug("{} tx hash : {}".format(self.tag, tx_hash)) Logger.debug("{} response: {}".format(self.tag, response)) return tx_hash
def create_normal_inputs(address: str, total_amount: int, rpc_port: int, utxo_index=-1): global total_amount_global global response total_amount_global = total_amount response = rpc.list_unspent_utxos(address, port=rpc_port) if not response or isinstance(response, dict): Logger.error("get utxos return error: {}".format(response)) return None, None utxos = response if utxo_index >= 0 and len(utxos) >= utxo_index+1: utxo = utxos[utxo_index] utxos = list() utxos.append(utxo) inputs = list() change_outputs = list() program_hash = keytool.address_to_program_hash(address) for utxo in utxos: txid = util.bytes_reverse(bytes.fromhex(utxo["txid"])) index = utxo["vout"] input = Input(txid, index) inputs.append(input) amount = int(Decimal(utxo["amount"]) * util.TO_SELA) if amount < total_amount_global: # total_amount -= amount total_amount_global -= amount elif amount == total_amount_global: total_amount_global = 0 break elif amount > total_amount_global: change = Output( value=amount - total_amount_global, output_lock=0, program_hash=program_hash, output_type=Output.OT_NONE, output_payload=OutputPayload() ) change_outputs.append(change) total_amount_global = 0 break if total_amount_global > 0: Logger.error("Available token is not enough!") return None, None return inputs, change_outputs
def create_normal_inputs(address: str, total_amount: int, port=rpc.DEFAULT_PORT): global total_amount_global global response total_amount_global = total_amount total_amount_format = str(Decimal(str(total_amount_global)) / Decimal(constant.TO_SELA)) if port != rpc.DEFAULT_PORT: response = rpc.list_unspent_utxos(address, port=port) else: response = rpc.get_utxos_by_amount(address, total_amount_format, port) if not response or isinstance(response, dict): Logger.debug("get utxos return error: {}".format(response)) return None, None utxos = response Logger.debug("utxos: {}".format(utxos)) inputs = list() change_outputs = list() program_hash = keytool.address_to_program_hash(address) for utxo in utxos: txid = util.bytes_reverse(bytes.fromhex(utxo["txid"])) index = utxo["vout"] input = Input(txid, index) inputs.append(input) amount = int(Decimal(utxo["amount"]) * constant.TO_SELA) if amount < total_amount_global: total_amount -= amount elif amount == total_amount: total_amount_global = 0 break elif amount > total_amount: change = Output( value=amount - total_amount_global, output_lock=0, program_hash=program_hash, output_type=Output.OT_NONE, output_payload=OutputPayload() ) change_outputs.append(change) total_amount_global = 0 break if total_amount_global > 0: Logger.error("Available token is not enough!") return None, None return inputs, change_outputs
def handle_tx_result(self, tx: Transaction, port=rpc.DEFAULT_PORT): # Logger.debug("{} {}".format(self.tag, tx)) r = tx.serialize() response = rpc.send_raw_transaction(r.hex(), port) if isinstance(response, dict): Logger.error("{} rpc response: {}".format(self.tag, response)) Logger.error("rpc send raw transaction failed") return False # response return on success, response is tx hash, but we should reverse it at first reverse_res = util.bytes_reverse(bytes.fromhex(response)).hex() Logger.debug("{} tx hash : {}".format(self.tag, tx.hash())) Logger.debug("{} response: {}".format(self.tag, reverse_res)) return tx.hash() == reverse_res
def create_normal_inputs_by_utxo(address: str, total_amount: int, utxos: list): global total_amount_global global response total_amount_global = total_amount inputs = list() change_outputs = list() program_hash = keytool.address_to_program_hash(address) for utxo in utxos: txid = util.bytes_reverse(bytes.fromhex(utxo["txid"])) index = utxo["vout"] input = Input(txid, index) inputs.append(input) amount = int(Decimal(utxo["amount"]) * util.TO_SELA) if amount < total_amount_global: # total_amount -= amount total_amount_global -= amount elif amount == total_amount_global: total_amount_global = 0 break elif amount > total_amount_global: change = Output( value=amount - total_amount_global, output_lock=0, program_hash=program_hash, output_type=Output.OT_NONE, output_payload=OutputPayload() ) change_outputs.append(change) total_amount_global = 0 break if total_amount_global > 0: Logger.error("Available token is not enough!") return None, None return inputs, change_outputs
elif tx_type == 0x0f: return "ILLEGAL_VOTE_EVIDENCE" elif tx_type == 0x10: return "ILLEGAL_BLOCK_EVIDENCE" elif tx_type == 0x11: return "ILLEGAL_SIDE_CHAIN_EVIDENCE" elif tx_type == 0x12: return "INACTIVE_ARBITRATORS" elif tx_type == 0x13: return "UPDATE_VERSION" if __name__ == '__main__': txid = "16c90c1e3a45cdf11f39fe0aa9f5eaea8fd0e6ab8bf5830c8cec4029c5964498" index = 2 tx_id = util.bytes_reverse(bytes.fromhex(txid)) input = Input(tx_id, index) inputs = list() inputs.append(input) outputs = list() address = "EUrmyVjtQkUijfffapHM6tJrw7EN2vUHxp" program_hash = keytool.address_to_program_hash(address) amount = 123 output_lock = 0 output = Output(value=amount, output_lock=output_lock, program_hash=program_hash, output_type=Output.OT_NONE, output_payload=OutputPayload()) outputs.append(output)