def create_cross_chain_asset(input_private_key: str, lock_address: str,
                             cross_chain_address: str, amount: int,
                             recharge: bool, rpc_port: int):
    if lock_address is None or lock_address is "":
        Logger.error("Invalid lock address")
        return None

    if cross_chain_address is None or cross_chain_address is "":
        Logger.error("Invalid cross chain address")
        return None

    account = Account(input_private_key)
    # create outputs:
    outputs, total_amount = create_normal_outputs(
        output_addresses=[lock_address],
        amount=amount,
        fee=util.TX_FEE,
        output_lock=0)

    # create inputs:
    inputs, change_outputs = create_normal_inputs(account.address(),
                                                  total_amount, rpc_port)
    if inputs is None or change_outputs is None:
        Logger.error("Create normal inputs failed")
        return None
    outputs.extend(change_outputs)

    # create program
    programs = list()
    redeem_script = bytes.fromhex(account.redeem_script())
    program = Program(code=redeem_script, params=None)
    programs.append(program)

    # create attributes
    attributes = list()
    attribute = Attribute(usage=Attribute.NONCE,
                          data=bytes("attributes".encode()))
    attributes.append(attribute)

    cross_chain_asset = TransferCrossChainAsset()
    cross_chain_asset.cross_chain_addresses = [cross_chain_address]
    cross_chain_asset.output_indexes = [0]
    cross_chain_asset.cross_chain_amounts = [amount - util.TX_FEE]

    tx = Transaction()
    if recharge:
        tx.version = Transaction.TX_VERSION_09
    else:
        tx.version = Transaction.TX_VERSION_DEFAULT

    Logger.debug("transaction version {}".format(tx.version))
    tx.tx_type = Transaction.TRANSFER_CROSS_CHAIN_ASSET
    tx.payload = cross_chain_asset
    tx.attributes = attributes
    tx.inputs = inputs
    tx.outputs = outputs
    tx.lock_time = 0
    tx.programs = programs

    return tx
 def _producer_info(self, owner_private_key: str, node_private_key: str,
                    nick_name: str, url: str, location: int,
                    net_address: str):
     info = ProducerInfo(owner_private_key=owner_private_key,
                         node_private_key=node_private_key,
                         nickname=nick_name,
                         url=url,
                         location=location,
                         net_address=net_address)
     Logger.debug("generate register producer{} payload".format(nick_name))
     return info
Exemple #3
0
    def save_to_file(self, dest_dir_path: str):
        if not self._valid:
            Logger.error("Invalid keystore!")
            return False
        if dest_dir_path is "":
            Logger.debug("Invalid parameter!")
            return False

        if not os.path.exists(dest_dir_path):
            os.makedirs(dest_dir_path)

        file_path = os.path.join(dest_dir_path, "keystore.dat")
        util.write_config_file(self.key_store_dict(), file_path)

        return True