Ejemplo n.º 1
0
def send_poke_tx(poke_tx, signature):
    complete_tx = utils.update_tx_signature(poke_tx, signature)
    res = forge_rpc.send_tx(complete_tx)
    if res.code != 0:
        logger.error('Fail to send poke tx.')
        logger.error(res)
    else:
        return res.hash
Ejemplo n.º 2
0
def consume_ticket_mobile(origin_tx, signature, ticket_address):
    new_tx = build_cosnume_ticket_mobile_tx(origin_tx, signature, )
    res = forge_rpc.send_tx(new_tx)

    if res.code != 0 or res.hash is None:
        logger.error(res)
        logger.error(f'Fail to consume ticket by mobile {ticket_address}')
    else:
        logger.info(f"Mobile ConsumeTx has been sent by tx: {res.hash}!")
    return res.hash
Ejemplo n.º 3
0
def buy_ticket_mobile(tx, signature):
    acquire_asset_tx = forge_utils.parse_to_proto(tx.itx.value,
                                                  forge_protos.AcquireAssetTx)

    tx.signature = signature

    ticket_address = acquire_asset_tx.specs[0].address
    res = forge_rpc.send_tx(tx)
    if forge_utils.is_response_ok(res):
        return ticket_address, res.hash
    else:
        return None, None
Ejemplo n.º 4
0
 def create_ticket(self):
     ticket_holder = self.get_next_ticket()
     create_tx = ticket_holder.ticket_create
     res = forge_rpc.send_tx(create_tx)
     logger.debug(u"About to create ticket with ticketInfo: {info}".format(
         info=forge_utils.data_of_create_asset(
             create_tx,
             protos.TicketInfo,
         ), ))
     if res.code != 0:
         logger.error(res)
         logger.error(u'Fail to create ticket: {tx}'.format(tx=create_tx))
     return res.hash
Ejemplo n.º 5
0
    def consume_mobile(self, consume_tx, address, signature, user_pk):
        multisig_data = forge_utils.encode_to_any(
            'fg:x:address',
            self.address,
        )

        tx = utils.update_tx_multisig(
            tx=consume_tx,
            signer=address,
            signature=signature,
            pk=user_pk,
            data=multisig_data,
        )
        return forge_rpc.send_tx(tx)
Ejemplo n.º 6
0
 def consume(self, consume_tx, wallet, token):
     res = forge_rpc.multisig(
         tx=consume_tx,
         wallet=wallet,
         token=token,
         data=Any(
             type_url='fg:x:address',
             value=self.address.encode(),
         ),
     )
     if res.code != 0 or not res.tx:
         logger.error("Fail to multisig consume tx.")
     else:
         return forge_rpc.send_tx(res.tx)
Ejemplo n.º 7
0
 def exchange_ticket_mobile(self, buyer_address, buyer_signature, user_pk):
     logger.debug(u"Preparing to send exchange_tx with mobile data.")
     ticket_holder = self.get_next_ticket()
     exchange_tx = ticket_holder.ticket_exchange
     buyer_signed = utils.add_multi_sig_to_tx(exchange_tx, buyer_address,
                                              buyer_signature, user_pk)
     logger.debug(
         "Buyer multisig kv pair has been inserted into tx "
         "successfully. ", )
     logger.debug("url_safe base64 encoded tx: {}".format(
         base64.urlsafe_b64encode(buyer_signed.SerializeToString()), ))
     res = forge_rpc.send_tx(buyer_signed)
     if res.code != 0:
         logger.error("Fail to send mobile buyer_signed exchange tx.")
         logger.error(res)
         return None
     else:
         return res.hash
Ejemplo n.º 8
0
 def exchange_ticket(self, buyer_wallet, buyer_token):
     ticket_holder = self.get_next_ticket()
     exchange_tx = ticket_holder.ticket_exchange
     res1 = forge_rpc.multisig(
         tx=exchange_tx,
         wallet=buyer_wallet,
         token=buyer_token,
     )
     if res1.code != 0:
         logger.error("Buyer multisig failed!")
         logger.error(res1)
         logger.error(exchange_tx)
     else:
         buyer_signed = res1.tx
         res = forge_rpc.send_tx(buyer_signed)
         if res.code != 0:
             logger.error(res)
             return None
         else:
             logger.debug(
                 u"Ticket {} has been exchanged.".format(
                     ticket_holder.address, ), )
             return res.hash