def crc_proposal_tracking(self, new_leader_private_key, tracking_type: int,
                           stage: int):
     global result
     result = True
     tracking = CRCProposalTracking(
         secretary_private_key=self.secretary_private_key,
         leader_private_key=self.owner_private_key,
         new_leader_private_key=new_leader_private_key,
         proposal_hash=self.crc_proposal_hash,
         document_hash=Random.get_random_bytes(serialize.UINT256SIZE),
         stage=stage,
         tracking_type=tracking_type,
         secretary_opinion_hash=Random.get_random_bytes(
             serialize.UINT256SIZE),
     )
     Logger.info("{} create crc proposal tracking on success. \n{}".format(
         self.tag, tracking))
     ret = self.tx_manager.crc_proposal_tracking(
         input_private_key=self.tap_account.private_key(),
         amount=10 * constant.TO_SELA,
         crc_proposal_tracking=tracking)
     if not ret:
         return False
     self.discrete_miner(1)
     return result
    def crc_proposal_secretary_general(self):
        ela_node = self.node_manager.ela_nodes[1]
        cr_private_key = ela_node.cr_account.private_key()
        ela_node = self.node_manager.ela_nodes[2]
        secretary_general_private_key = ela_node.cr_account.private_key()

        result = True
        crc_proposal = CRCProposal(
            private_key=cr_private_key,
            cr_private_key=cr_private_key,
            secretary_general_private_key=secretary_general_private_key,
            proposal_type=CRCProposal.SECRETARY_GENERAL,
            category_data="",
            draft_hash=Random.get_random_bytes(serialize.UINT256SIZE))
        Logger.info(
            "{} create crc proposal change secretary general on success. \n{}".
            format(self.tag, crc_proposal))

        ret = self.tx_manager.crc_proposal(
            input_private_key=self.tap_account.private_key(),
            amount=10 * constant.TO_SELA,
            crc_proposal=crc_proposal)
        if not ret:
            return False
        self.discrete_miner(1)
        return result
 def ready_for_crc_proposal_secretary_general(self):
     ret = self.crc_proposal_secretary_general()
     self.get_current_height()
     self.check_result("crc proposal change secretary general", ret)
     Logger.info(
         "{} crc proposal change secretary general on success!".format(
             self.tag))
    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 register_producers_candidates(self):

        global result
        result = False
        for i in range(
                self.params.ela_params.crc_number + 1,
                self.params.ela_params.number - round(self.params.ela_params.later_start_number / 2) + 1
        ):
            ela_node = self.node_manager.ela_nodes[i]
            public_key = ela_node.node_account.public_key()
            ret = self.register_producer(ela_node)
            if not ret:
                return False
            rpc.discrete_mining(7)

            status = rpc.producer_status(public_key)
            Logger.debug("After mining 7 blocks, register status: {}".format(status))
            result = status == "Active"
            if not result:
                Logger.error("{} register producer {} failed".format(self.tag, ela_node.name))
                break

            Logger.info("{} register node-{} to be a producer on success!\n".format(self.tag, i))

        return result
    def ready_for_cr(self):
        ret = self.register_cr_candidates()
        self.get_current_height()
        self.check_result("register cr", ret)
        Logger.info("{} register cr on success!".format(self.tag))

        ret = self.tx_manager.vote_cr_candidates()
        self.get_current_height()
        self.check_result("vote cr", ret)
        Logger.info("{} vote cr on success!".format(self.tag))

        # transfer to CRFoundation
        # self.tx_manager.transfer_asset(self.tap_account.private_key(), [self.CR_Foundation_TEMP], 5000 * util.TO_SELA)
        # if ret:
        #     rpc.discrete_mining(1)
        #     value = rpc.get_balance_by_address(self.CR_Foundation_TEMP)
        #     Logger.debug("{} CRFoundation {} wallet balance: {}".format(self.tag, self.CR_Foundation_TEMP, value))
        # else:
        #     Logger.error("{} CRFoundation transfer failed".format(self.tag))
        self.tx_manager.transfer_asset(self.tap_account.private_key(),
                                       [self.CRC_COMMITTEE_ADDRESS],
                                       5000 * util.TO_SELA)
        if ret:
            rpc.discrete_mining(1)
            value = rpc.get_balance_by_address(self.CRC_COMMITTEE_ADDRESS)
            Logger.debug("{} CRFoundation {} wallet balance: {}".format(
                self.tag, self.CRC_COMMITTEE_ADDRESS, value))
        else:
            Logger.error("{} CRFoundation transfer failed".format(self.tag))
    def register_cr_candidates(self):

        global result
        result = True
        for i in range(1, self.params.ela_params.crc_number + 1):
            ela_node = self.node_manager.ela_nodes[i]
            cid = ela_node.cr_account.cid_address()
            cr_info = self.create_cr_info(
                register_private_key=ela_node.cr_account.private_key(),
                nickname="CR-00{}".format(i),
                url="www.00{}.com".format(i),
                location=0)
            ret = self.tx_manager.register_cr(
                input_private_key=self.tap_account.private_key(),
                amount=5000 * constant.TO_SELA,
                cr_info=cr_info)
            if not ret:
                return False
            self.discrete_miner(7)
            status = self.get_cr_status(cid)
            Logger.debug(
                "After mining 7 blocks, register status: {}".format(status))
            result = status == "Active"
            if not result:
                Logger.error("{} register CR {} failed".format(
                    self.tag, ela_node.name))
                break
            Logger.info("{} register CR-{} to be a CR on success!\n".format(
                self.tag, i))

        return result
 def terminate_all_process(self, result=True):
     Logger.info("{} terminal all the process and exit...".format(self.tag))
     self.node_manager.stop_nodes()
     time.sleep(1)
     os.system("sh {}/shell/killall.sh".format(self.root_path))
     if result:
         exit(0)
Exemplo n.º 9
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
    def crc_proposal(self):
        ela_node = self.node_manager.ela_nodes[1]
        cr_private_key = ela_node.cr_account.private_key()
        self.owner_private_key = cr_private_key
        budget_list = list()
        budget_list.append(
            Budget(budget_type=Budget.IMPREST, stage=0, amount=100000))
        budget_list.append(
            Budget(budget_type=Budget.NORMAL_PAYMENT, stage=1, amount=200000))
        budget_list.append(
            Budget(budget_type=Budget.NORMAL_PAYMENT, stage=2, amount=300000))
        budget_list.append(
            Budget(budget_type=Budget.FINAL_PAYMENT, stage=3, amount=400000))
        result = True
        crc_proposal = CRCProposal(
            private_key=cr_private_key,
            cr_private_key=cr_private_key,
            proposal_type=CRCProposal.NORMAL,
            category_data="",
            draft_hash=Random.get_random_bytes(serialize.UINT256SIZE),
            budget=budget_list,
            recipient=bytes.fromhex(ela_node.cr_account.program_hash()))
        Logger.info("{} create crc proposal on success. \n{}".format(
            self.tag, crc_proposal))

        ret = self.tx_manager.crc_proposal(
            input_private_key=self.tap_account.private_key(),
            amount=10 * constant.TO_SELA,
            crc_proposal=crc_proposal)
        self.crc_proposal_hash = crc_proposal.hash
        if not ret:
            return False
        self.discrete_miner(1)
        return result
    def crc_proposal_change_owner(self):
        ela_node = self.node_manager.ela_nodes[1]
        cr_private_key = ela_node.cr_account.private_key()
        ela_node = self.node_manager.ela_nodes[2]
        new_owner_private_key = ela_node.cr_account.private_key()
        result = True
        crc_proposal = CRCProposal(
            private_key=cr_private_key,
            cr_private_key=cr_private_key,
            new_owner_private_key=new_owner_private_key,
            proposal_type=CRCProposal.CHANGE_SPONSOR_OWNER,
            category_data="",
            draft_hash=Random.get_random_bytes(serialize.UINT256SIZE),
            target_proposal_hash=self.crc_proposal_hash)
        Logger.info(
            "{} create crc proposal change owner on success. \n{}".format(
                self.tag, crc_proposal))

        ret = self.tx_manager.crc_proposal(
            input_private_key=self.tap_account.private_key(),
            amount=10 * constant.TO_SELA,
            crc_proposal=crc_proposal)
        if not ret:
            return False
        self.discrete_miner(1)
        return result
 def ready_for_dpos(self):
     ret = self.tx_manager.register_producers_candidates()
     self.check_result("register producers", ret)
     Logger.info("{} register producers on success!".format(self.tag))
     ret = self.tx_manager.vote_producers_candidates()
     self.check_result("vote producers", ret)
     Logger.info("{} vote producer on success!".format(self.tag))
     self.get_dpos_votes()
 def create_crc_tracking(self, register_private_key: str, nickname: str,
                         url: str, location: int):
     cr_info = CRInfo(private_key=register_private_key,
                      nickname=nickname,
                      url=url,
                      location=location)
     Logger.info("{} create create_crc_tracking on success. \n{}".format(
         self.tag, cr_info))
     return cr_info
Exemplo n.º 14
0
 def show_arbiter_info(self):
     arbiters_nicknames = self.get_arbiter_names("arbiters")
     arbiters_nicknames.sort()
     next_arbiter_nicknames = self.get_arbiter_names("nextarbiters")
     next_arbiter_nicknames.sort()
     Logger.info(
         "current arbiters nicknames: {}".format(arbiters_nicknames))
     Logger.info(
         "next    arbiters nicknames: {}".format(next_arbiter_nicknames))
Exemplo n.º 15
0
 def wait_block(self):
     Logger.info("waiting for the block ... ")
     count_height = 0
     height = self.get_current_height()
     while True:
         if height < count_height:
             break
         else:
             time.sleep(10)
             count_height = self.get_current_height()
Exemplo n.º 16
0
 def ready_for_dpos(self):
     producers = rpc.list_producers(0, 100, state="active")
     if producers is None:
         Logger.info('{} list producers is null'.format(self.tag))
         return
     Logger.debug('{} list producers:{}'.format(self.tag, producers))
     self.producers_list = producers["producers"]
     ret = self.vote_producers_candidates()
     self.check_result("vote producers", ret)
     Logger.info("{} vote producer on success!".format(self.tag))
 def wait_block(self):
     Logger.info("waiting for the block ... ")
     count_height = 0
     height = self.get_current_height()
     while True:
         if height + 1 >= count_height:
             rpc.discrete_mining(1)
             time.sleep(1)
             count_height = self.get_current_height()
         else:
             break
 def vote_crc_proposal_candidates(self, crc_proposal_hash: bytes):
     vote_amount = 1 * constant.TO_SELA
     ret = self.vote_proposal(
         input_private_key=self.tap_account.private_key(),
         amount=vote_amount,
         candidates=[crc_proposal_hash])
     if not ret:
         return False
     rpc.discrete_mining(1)
     Logger.info(
         "{} vote crc proposal:{} amount:{} on success!\n".format(self.tag, crc_proposal_hash.hex(), vote_amount))
     return True
Exemplo n.º 19
0
 def ready_for_cr(self):
     cr = rpc.list_current_crs()
     # cr = rpc.list_cr_candidates(0, 100, state="active")
     if cr is None:
         Logger.info('{} list cr is null'.format(self.tag))
         return
     Logger.debug('{} list cr:{}'.format(self.tag, cr))
     # self.cr_list = cr["crcandidatesinfo"]
     self.cr_list = cr["crmembersinfo"]
     ret = self.vote_cr_candidates()
     self.check_result("vote cr", ret)
     Logger.info("{} vote cr on success!".format(self.tag))
Exemplo n.º 20
0
    def ready_for_crc_proposal_review(self, p_hash: bytes):
        ret = self.crc_proposal_review(p_hash)
        self.get_current_height()
        self.check_result("crc proposal review", ret)
        Logger.info("{} crc proposal review on success!".format(self.tag))
        self.discrete_miner(self.params.ela_params.proposal_cr_voting_period)

        ret = self.tx_manager.vote_crc_proposal_candidates()
        self.get_current_height()
        self.check_result("vote cr proposal", ret)
        Logger.info("{} vote crc proposal  on success!".format(self.tag))
        self.discrete_miner(
            self.params.ela_params.proposal_public_voting_period)
Exemplo n.º 21
0
 def vote_producers(self, start: int, end: int):
     for i in range(start, end):
         producer = self.register_producers_list
         vote_amount = constant.TO_SELA
         ret = self.vote_producer(input_private_key=self.private_key,
                                  amount=vote_amount,
                                  candidates=[producer])
         if not ret:
             return False
         Logger.info("{} vote node-{} {} Elas on success!\n".format(
             self.tag, i, vote_amount))
         rpc.discrete_mining(1)
     return True
 def vote_producers(self, start: int, end: int):
     for i in range(start, end):
         producer = self.register_producers_list[i - self.params.ela_params.crc_number - 1]
         vote_amount = (self.params.ela_params.number - i + 1) * constant.TO_SELA
         ret = self.vote_producer(
             input_private_key=producer.node_account().private_key(),
             amount=vote_amount,
             candidates=[producer]
         )
         if not ret:
             return False
         Logger.info("{} vote node-{} {} Elas on success!\n".format(self.tag, i, vote_amount))
         rpc.discrete_mining(1)
     return True
 def vote_cr_candidates(self):
     for i in range(1, self.params.ela_params.crc_number + 1):
         crs = self.register_cr_list[i - 1]
         vote_amount = (self.params.ela_params.crc_number - i + 1) * constant.TO_SELA
         ret = self.vote_cr(
             input_private_key=self.tap_account.private_key(),
             amount=vote_amount,
             candidates=[crs],
         )
         if not ret:
             return False
         rpc.discrete_mining(1)
         Logger.info("{} vote CR-{} {} Elas on success!\n".format(self.tag, i, vote_amount))
     return True
Exemplo n.º 24
0
 def vote_crc_proposal_candidates(self):
     for i in range(len(self.crc_proposal_list)):
         proposal = self.crc_proposal_list[i]
         vote_amount = (self.params.ela_params.crc_number - i +
                        1) * constant.TO_SELA
         ret = self.vote_proposal(
             input_private_key=self.tap_account.private_key(),
             amount=vote_amount,
             candidates=[proposal])
         if not ret:
             return False
         rpc.discrete_mining(1)
         Logger.info("{} vote crc proposal:{} on success!\n".format(
             self.tag, proposal.hash, vote_amount))
     return True
    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 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 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 crc_proposal_withdraw(self, input_address: str, amount: int, crc_proposal_withdraw: CRCProposalWithdraw,
                              output_address: str, port=rpc.DEFAULT_PORT):

        tx = txbuild.create_crc_proposal_withdraw_transaction(
            input_address=input_address,
            amount=amount,
            payload=crc_proposal_withdraw,
            rpc_port=port,
            output_address=output_address
        )

        if tx is None:
            return False
        Logger.info("crc proposal withdraw 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
    def _create_keystore_files(self):
        Logger.info("{} begin to generate the key stores".format(self.tag))

        self.key_message_saved_dir = os.path.join(self.params.root_path,
                                                  "datas/stables")
        if not os.path.exists(self.key_message_saved_dir):
            os.mkdir(self.key_message_saved_dir)
        else:
            os.system("rm -fr " + self.key_message_saved_dir + "/*")

        self._create_keystore("special", 13)
        self._create_keystore("owner", 109)
        self._create_keystore("node", 109)
        self._create_keystore("arbiter", 13)
        self._create_keystore("origin", 5)

        Logger.info("{} generate the key stores on success!".format(self.tag))