Ejemplo n.º 1
0
    def load(cls, data):
        """
        Create a transfer from a dict in json format.

        :param data: The transfer as a dict in json format
        """
        txdoc = Transaction.from_signed_raw(data["txdoc"])
        return cls(txdoc, data["metadata"])
Ejemplo n.º 2
0
    def load(cls, data):
        '''
        Create a transfer from a dict in json format.

        :param data: The transfer as a dict in json format
        '''
        txdoc = Transaction.from_signed_raw(data['txdoc'])
        return cls(txdoc, data['metadata'])
Ejemplo n.º 3
0
 def load(cls, data):
     """
     Create a new transfer from a dict in json format.
     """
     if data["state"] is Transfer.TO_SEND:
         txdoc = None
     else:
         txdoc = Transaction.from_signed_raw(data["txdoc"])
     return cls(txdoc, data["state"], data["metadata"])
Ejemplo n.º 4
0
 def load(cls, data):
     '''
     Create a new transfer from a dict in json format.
     '''
     if data['state'] is Transfer.TO_SEND:
         txdoc = None
     else:
         txdoc = Transaction.from_signed_raw(data['txdoc'])
     return cls(txdoc, data['state'], data['metadata'])
Ejemplo n.º 5
0
    def send_money(self, salt, password, community,
                   recipient, amount, message):
        '''
        Send money to a given recipient in a specified community

        :param str salt: The account salt
        :param str password: The account password
        :param community: The community target of the transfer
        :param str recipient: The pubkey of the recipient
        :param int amount: The amount of money to transfer
        :param str message: The message to send with the transfer
        '''
        time = community.get_block().mediantime
        block_number = community.current_blockid()['number']
        block = community.request(bma.blockchain.Block,
                                  req_args={'number': block_number})
        txid = len(block['transactions'])
        key = None
        logging.debug("Key : {0} : {1}".format(salt, password))
        if self.walletid == 0:
            key = SigningKey(salt, password)
        else:
            key = SigningKey("{0}{1}".format(salt, self.walletid), password)
        logging.debug("Sender pubkey:{0}".format(key.pubkey))

        try:
            issuer_uid = Person.lookup(key.pubkey, community).uid
        except PersonNotFoundError:
            issuer_uid = ""

        try:
            receiver_uid = Person.lookup(recipient, community).uid
        except PersonNotFoundError:
            receiver_uid = ""

        metadata = {'block': block_number,
                    'time': time,
                    'amount': amount,
                    'issuer': key.pubkey,
                    'issuer_uid': issuer_uid,
                    'receiver': recipient,
                    'receiver_uid': receiver_uid,
                    'comment': message,
                    'txid': txid
                    }
        transfer = Transfer.initiate(metadata)

        self.caches[community.currency]._transfers.append(transfer)

        result = self.tx_inputs(int(amount), community)
        inputs = result[0]
        self.caches[community.currency].available_sources = result[1]
        logging.debug("Inputs : {0}".format(inputs))

        outputs = self.tx_outputs(recipient, amount, inputs)
        logging.debug("Outputs : {0}".format(outputs))
        tx = Transaction(PROTOCOL_VERSION, community.currency,
                         [self.pubkey], inputs,
                         outputs, message, None)
        logging.debug("TX : {0}".format(tx.raw()))

        tx.sign([key])
        logging.debug("Transaction : {0}".format(tx.signed_raw()))
        transfer.send(tx, community)
Ejemplo n.º 6
0
    def send_money(self, salt, password, community, recipient, amount,
                   message):
        '''
        Send money to a given recipient in a specified community

        :param str salt: The account salt
        :param str password: The account password
        :param community: The community target of the transfer
        :param str recipient: The pubkey of the recipient
        :param int amount: The amount of money to transfer
        :param str message: The message to send with the transfer
        '''
        time = community.get_block().mediantime
        block_number = community.current_blockid()['number']
        block = community.request(bma.blockchain.Block,
                                  req_args={'number': block_number})
        txid = len(block['transactions'])
        key = None
        logging.debug("Key : {0} : {1}".format(salt, password))
        if self.walletid == 0:
            key = SigningKey(salt, password)
        else:
            key = SigningKey("{0}{1}".format(salt, self.walletid), password)
        logging.debug("Sender pubkey:{0}".format(key.pubkey))

        try:
            issuer_uid = Person.lookup(key.pubkey, community).uid
        except PersonNotFoundError:
            issuer_uid = ""

        try:
            receiver_uid = Person.lookup(recipient, community).uid
        except PersonNotFoundError:
            receiver_uid = ""

        metadata = {
            'block': block_number,
            'time': time,
            'amount': amount,
            'issuer': key.pubkey,
            'issuer_uid': issuer_uid,
            'receiver': recipient,
            'receiver_uid': receiver_uid,
            'comment': message,
            'txid': txid
        }
        transfer = Transfer.initiate(metadata)

        self.caches[community.currency]._transfers.append(transfer)

        result = self.tx_inputs(int(amount), community)
        inputs = result[0]
        self.caches[community.currency].available_sources = result[1]
        logging.debug("Inputs : {0}".format(inputs))

        outputs = self.tx_outputs(recipient, amount, inputs)
        logging.debug("Outputs : {0}".format(outputs))
        tx = Transaction(PROTOCOL_VERSION, community.currency, [self.pubkey],
                         inputs, outputs, message, None)
        logging.debug("TX : {0}".format(tx.raw()))

        tx.sign([key])
        logging.debug("Transaction : {0}".format(tx.signed_raw()))
        transfer.send(tx, community)
Ejemplo n.º 7
0
    async def send_money(self, salt, password, community,
                   recipient, amount, message):
        """
        Send money to a given recipient in a specified community

        :param str salt: The account salt
        :param str password: The account password
        :param community: The community target of the transfer
        :param str recipient: The pubkey of the recipient
        :param int amount: The amount of money to transfer
        :param str message: The message to send with the transfer
        """
        try:
            blockid = await community.blockid()
            block = await community.bma_access.future_request(bma.blockchain.Block,
                                      req_args={'number': blockid.number})
        except ValueError as e:
            if '404' in str(e):
                return False, "Could not send transfer with null blockchain"

        time = block['medianTime']
        txid = len(block['transactions'])
        if self.walletid == 0:
            key = SigningKey(salt, password)
        else:
            key = SigningKey("{0}{1}".format(salt, self.walletid), password)
        logging.debug("Sender pubkey:{0}".format(key.pubkey))

        try:
            issuer = await self._identities_registry.future_find(key.pubkey, community)
            issuer_uid = issuer.uid
        except LookupFailureError as e:
            issuer_uid = ""

        try:
            receiver = await self._identities_registry.future_find(recipient, community)
            receiver_uid = receiver.uid
        except LookupFailureError as e:
            receiver_uid = ""

        metadata = {'block': None,
                    'time': time,
                    'amount': amount,
                    'issuer': key.pubkey,
                    'issuer_uid': issuer_uid,
                    'receiver': recipient,
                    'receiver_uid': receiver_uid,
                    'comment': message,
                    'txid': txid
                    }
        transfer = Transfer.initiate(metadata)

        self.caches[community.currency]._transfers.append(transfer)

        try:
            result = self.tx_inputs(int(amount), community)
            inputs = result[0]
            self.caches[community.currency].available_sources = result[1][1:]
        except NotEnoughMoneyError as e:
            return False, str(e)
        logging.debug("Inputs : {0}".format(inputs))

        outputs = self.tx_outputs(recipient, amount, inputs)
        logging.debug("Outputs : {0}".format(outputs))
        tx = Transaction(PROTOCOL_VERSION, community.currency,
                         [self.pubkey], inputs,
                         outputs, message, None)
        logging.debug("TX : {0}".format(tx.raw()))

        tx.sign([key])
        logging.debug("Transaction : {0}".format(tx.signed_raw()))
        return (await transfer.send(tx, community))