def send(self, txdoc, community): """ Send a transaction and update the transfer state to AWAITING if accepted. If the transaction was refused (return code != 200), state becomes REFUSED The txdoc is saved as the transfer txdoc. :param txdoc: A transaction ucoinpy object :param community: The community target of the transaction """ self.sha_hash = txdoc.sha_hash responses = yield from community.bma_access.broadcast( bma.tx.Process, post_args={"transaction": txdoc.signed_raw()} ) blockid = yield from community.blockid() block = yield from community.bma_access.future_request( bma.blockchain.Block, req_args={"number": blockid.number} ) signed_raw = "{0}{1}\n".format(block["raw"], block["signature"]) block_doc = Block.from_signed_raw(signed_raw) result = (False, "") for r in responses: if r.status == 200: result = (True, (yield from r.json())) elif not result[0]: result = (False, (yield from r.text())) else: yield from r.text() self.run_state_transitions(([r.status for r in responses], block_doc)) self.run_state_transitions(([r.status for r in responses])) return result
def blockid(self): """ Get the block id. :return: The current block ID as [NUMBER-HASH] format. """ try: block_number = self.network.current_blockid.number block = yield from self.bma_access.future_request(bma.blockchain.Block, req_args={"number": block_number}) signed_raw = "{0}{1}\n".format(block["raw"], block["signature"]) except ValueError as e: if "404" in str(e): return BlockId.empty() return Block.from_signed_raw(signed_raw).blockid
async def blockid(self): """ Get the block id. :return: The current block ID as [NUMBER-HASH] format. """ try: block_number = self.network.current_blockid.number block = await self.bma_access.future_request(bma.blockchain.Block, req_args={'number': block_number}) signed_raw = "{0}{1}\n".format(block['raw'], block['signature']) except ValueError as e: if '404' in str(e): return BlockId.empty() return Block.from_signed_raw(signed_raw).blockid
async def copy_membership_to_clipboard(self, identity): """ :param sakia.core.registry.Identity identity: :return: """ clipboard = QApplication.clipboard() try: membership = await identity.membership(self._community) if membership: block_number = membership['written'] block = await self._community.get_block(block_number) block_doc = Block.from_signed_raw("{0}{1}\n".format(block['raw'], block['signature'])) for ms_doc in block_doc.joiners: if ms_doc.issuer == identity.pubkey: clipboard.setText(ms_doc.signed_raw()) except MembershipNotFoundError: logging.debug("Could not find membership")
async def copy_block_to_clipboard(self, number): clipboard = QApplication.clipboard() block = await self._community.get_block(number) if block: block_doc = Block.from_signed_raw("{0}{1}\n".format(block['raw'], block['signature'])) clipboard.setText(block_doc.signed_raw())