Example #1
0
    def transfer_multi_cross_chain_asset(self, input_private_key: str,
                                         lock_address: str, cross_address: str,
                                         tx_count: int, amount: int,
                                         recharge: bool, port: int):
        account = Account(input_private_key)
        response = rpc.list_unspent_utxos(account.address(), port=port)
        if not response or isinstance(response, dict):
            Logger.error("get utxos return error: {}".format(response))
            return False
        utxos = response
        if len(utxos) < tx_count:
            Logger.error("utxo is not enough")
            return False

        for i in range(tx_count):
            current_utxos = list()
            utxo = utxos[i]
            current_utxos.append(utxo)
            Logger.info("current cross chain index: {}".format(i))
            tx = txbuild.create_cross_chain_transaction_by_utxo(
                input_private_key=input_private_key,
                lock_address=lock_address,
                cross_chain_address=cross_address,
                amount=amount,
                recharge=recharge,
                utxos=current_utxos)

            if tx is None:
                return False

            tx = txbuild.single_sign_transaction(input_private_key, tx)
            Logger.debug("cross chain asset transaction: \n{}".format(tx))
            ret = self.handle_tx_result(tx, port)

        return ret
Example #2
0
    def update(self, producer_info: ProducerInfo, rpc_port: int):
        tx = txbuild.create_update_transaction(
            input_private_key=self.input_private_key,
            payload=producer_info,
            rpc_port=rpc_port)

        if tx is None:
            return None
        producer_info.gen_signature()
        tx = txbuild.single_sign_transaction(self.input_private_key, tx)

        return tx
Example #3
0
    def cancel(self, rpc_port: int):
        tx = txbuild.create_cancel_transaction(
            input_private_key=self.input_private_key,
            payload=self.producer_info(),
            rpc_port=rpc_port)

        if tx is None:
            return None

        tx = txbuild.single_sign_transaction(self.input_private_key, tx)

        return tx
Example #4
0
    def register(self, rpc_port: int):
        tx = txbuild.create_register_transaction(
            input_private_key=self.input_private_key,
            amount=self.deposit_amount,
            payload=self.info,
            rpc_port=rpc_port)

        if tx is None:
            return None

        tx = txbuild.single_sign_transaction(self.input_private_key, tx)

        return tx
Example #5
0
    def redeem(self, amount: int, rpc_port: int):

        tx = txbuild.create_redeem_transaction(
            payload=self.producer_info(),
            output_address=self.input.address(),
            amount=amount,
            rpc_port=rpc_port)

        if tx is None:
            return None

        tx = txbuild.single_sign_transaction(
            self.producer_info().owner_account.private_key(), tx)

        return tx
    def update_cr(self, input_private_key: str, cr_info: CRInfo, port=rpc.DEFAULT_PORT):
        tx = txbuild.create_cr_update_transaction(
            input_private_key=input_private_key,
            update_payload=cr_info,
            rpc_port=port
        )

        if tx is None:
            return False

        tx.payload_version = cr_info.CR_INFO_DID_VERSION
        tx = txbuild.single_sign_transaction(input_private_key, tx)
        Logger.info("update cr transaction:\n{}".format(tx))
        ret = self.handle_tx_result(tx, port)

        return ret
    def redeem_cr(self, crc_info: CRInfo, return_address: str, amount: int, port=rpc.DEFAULT_PORT):
        tx = txbuild.create_cr_redeem_transaction(
            payload=crc_info,
            output_address=return_address,
            amount=amount,
            rpc_port=port
        )

        if tx is None:
            return False

        tx = txbuild.single_sign_transaction(crc_info.account.private_key(), tx)
        Logger.info("redeem cr transaction:\n{}".format(tx))
        ret = self.handle_tx_result(tx, port)

        return ret
    def crc_proposal_tracking(self, input_private_key: str, amount: int, crc_proposal_tracking: CRCProposalTracking,
                              port=rpc.DEFAULT_PORT):

        tx = txbuild.create_crc_proposal_tracking_transaction(
            input_private_key=input_private_key,
            amount=amount,
            payload=crc_proposal_tracking,
            rpc_port=port
        )

        if tx is None:
            return False
        tx = txbuild.single_sign_transaction(input_private_key, tx)
        Logger.info("crc proposal tracking transaction:\n{} ".format(tx))
        ret = self.handle_tx_result(tx, port)
        return ret
    def unregister_cr(self, input_private_key: str, register_private_key: str, port=rpc.DEFAULT_PORT):
        un_register_cr = UnRegisterCR(register_private_key)

        tx = txbuild.create_cr_cancel_transaction(
            input_private_key=input_private_key,
            payload=un_register_cr,
            rpc_port=port
        )

        if tx is None:
            return False

        tx = txbuild.single_sign_transaction(input_private_key, tx)
        Logger.info("ungister cr transaction:\n{}".format(tx))
        ret = self.handle_tx_result(tx, port)

        return ret
Example #10
0
    def vote_cr(self, input_private_key: str, amount: int, candidates: list):
        vote_content = VoteContent(VoteContent.CRC, candidates)
        tx = txbuild.create_vote_transaction(
            input_private_key=input_private_key,
            candidates_list=candidates,
            amount=amount,
            rpc_port=self.rpc_port,
            vote_content=vote_content)

        if tx is None:
            return False

        tx = txbuild.single_sign_transaction(input_private_key, tx)
        Logger.info("vote cr transaction:\n{} ".format(tx))
        ret = self.handle_tx_result(tx, self.rpc_port)

        return ret
    def invoke_neo_contract(self, input_private_key: str, output_addresses: list, payload: NeoInvokeContract,
                            amount: int, rpc_port: int):
        tx = txbuild.invoke_contract_transaction(
            input_private_key=input_private_key,
            output_addresses=output_addresses,
            payload=payload,
            amount=amount,
            rpc_port=rpc_port
        )

        if tx is None:
            return False

        tx = txbuild.single_sign_transaction(input_private_key, tx)

        ret = self.handle_tx_result(tx, rpc_port)

        return ret
    def register_cr(self, input_private_key: str, amount: int, cr_info: CRInfo, port=rpc.DEFAULT_PORT):

        tx = txbuild.create_cr_register_transaction(
            input_private_key=input_private_key,
            amount=amount,
            payload=cr_info,
            rpc_port=port
        )

        if tx is None:
            return False
        tx.payload_version = cr_info.CR_INFO_DID_VERSION
        tx = txbuild.single_sign_transaction(input_private_key, tx)
        Logger.info("register cr transaction:\n{} ".format(tx))
        ret = self.handle_tx_result(tx, port)
        if ret:
            self.register_cr_list.append(cr_info)
        return ret
    def transfer_cross_chain_asset(self, input_private_key: str, lock_address: str, cross_address: str,
                                   amount: int, recharge: bool, port=rpc.DEFAULT_PORT):
        tx = txbuild.create_cross_chain_transaction(
            input_private_key=input_private_key,
            lock_address=lock_address,
            cross_chain_address=cross_address,
            amount=amount,
            recharge=recharge,
            rpc_port=port
        )

        if tx is None:
            return False

        tx = txbuild.single_sign_transaction(input_private_key, tx)
        Logger.warn("cross chain asset transaction: \n{}".format(tx))
        ret = self.handle_tx_result(tx, port)

        return ret
    def transfer_asset(self, input_private_key: str, output_addresses: list, amount: int):

        # create transfer asset tx
        tx = txbuild.create_transaction(
            input_private_key=input_private_key,
            output_addresses=output_addresses,
            amount=amount,
            rpc_port=self.rpc_port
        )

        if tx is None:
            return False
        # single sign this tx
        tx = txbuild.single_sign_transaction(input_private_key, tx)

        # return the result
        ret = self.handle_tx_result(tx)

        return ret
Example #15
0
    def transfer_asset(self, input_private_key: str, output_addresses: list,
                       amount: int, side_chain: bool):

        # create transfer asset tx
        tx = txbuild.create_transaction(input_private_key=input_private_key,
                                        output_addresses=output_addresses,
                                        amount=amount,
                                        rpc_port=self.rpc_port,
                                        side_chain=side_chain)

        if tx is None:
            return False
        # single sign this tx
        tx = txbuild.single_sign_transaction(input_private_key, tx)
        # Logger.debug("transaction:\n{} ".format(tx))
        # return the result
        ret = self.handle_tx_result(tx, self.rpc_port)

        return ret
    def vote_proposal(self, input_private_key: str, amount: int, candidates: list):
        candidates_list = list()
        for crc_proposal_hash in candidates:
            candidates_list.append(CandidateVotes(crc_proposal_hash, amount))
        vote_content = VoteContent(VoteContent.CRC_PROPOSAL, candidates_list)
        tx = txbuild.create_vote_transaction(
            input_private_key=input_private_key,
            candidates_list=candidates_list,
            amount=amount,
            rpc_port=self.rpc_port,
            vote_content=vote_content
        )

        if tx is None:
            return False

        tx = txbuild.single_sign_transaction(input_private_key, tx)
        Logger.info("vote cr proposal transaction:\n{} ".format(tx))
        ret = self.handle_tx_result(tx)

        return ret
    def vote_cr(self, input_private_key: str, amount: int, candidates: list):
        candidates_list = list()
        for cr_info in candidates:
            candidates_list.append(CandidateVotes(bytes.fromhex(cr_info.cid), amount))
        vote_content = VoteContent(VoteContent.CRC, candidates_list)
        tx = txbuild.create_vote_transaction(
            input_private_key=input_private_key,
            candidates_list=candidates_list,
            amount=amount,
            rpc_port=self.rpc_port,
            vote_content=vote_content
        )

        if tx is None:
            return False

        tx = txbuild.single_sign_transaction(input_private_key, tx)
        Logger.info("vote cr transaction:\n{} ".format(tx))
        ret = self.handle_tx_result(tx)

        return ret
    def vote_producer(self, input_private_key: str, amount: int, candidates: list):
        candidates_list = list()
        for producer in candidates:
            candidates_list.append(CandidateVotes(bytes.fromhex(producer.owner_account().public_key()), amount))
        vote_content = VoteContent(VoteContent.DELEGATE, candidates_list)
        tx = txbuild.create_vote_transaction(
            input_private_key=input_private_key,
            candidates_list=candidates_list,
            amount=amount,
            rpc_port=self.rpc_port,
            vote_content=vote_content
        )

        if tx is None:
            return False

        tx = txbuild.single_sign_transaction(input_private_key, tx)
        Logger.info("vote producer transaction:\n{} ".format(tx))
        ret = self.handle_tx_result(tx)

        return ret