예제 #1
0
파일: documents.py 프로젝트: duniter/sakia
    def prepare_tx(self, key, receiver, blockstamp, amount, amount_base, message, currency):
        """
        Prepare a simple Transaction document
        :param SigningKey key: the issuer of the transaction
        :param str receiver: the target of the transaction
        :param duniterpy.documents.BlockUID blockstamp: the blockstamp
        :param int amount: the amount sent to the receiver
        :param int amount_base: the amount base of the currency
        :param str message: the comment of the tx
        :param str currency: the target community
        :return: the transaction document
        :rtype: List[sakia.data.entities.Transaction]
        """
        forged_tx = []
        sources = [None]*41
        while len(sources) > 40:
            result = self.tx_sources(int(amount), amount_base, currency, key.pubkey)
            sources = result[0]
            computed_outputs = result[1]
            overheads = result[2]
            # Fix issue #594
            if len(sources) > 40:
                sources_value = 0
                for s in sources[:39]:
                    sources_value += s.amount * (10**s.base)
                sources_value, sources_base = reduce_base(sources_value, 0)
                chained_tx = self.prepare_tx(key, key.pubkey, blockstamp,
                                             sources_value, sources_base, "[CHAINED]", currency)
                forged_tx += chained_tx
        self._sources_processor.consume(sources)
        logging.debug("Inputs : {0}".format(sources))

        inputs = self.tx_inputs(sources)
        unlocks = self.tx_unlocks(sources)
        outputs = self.tx_outputs(key.pubkey, receiver, computed_outputs, overheads)
        logging.debug("Outputs : {0}".format(outputs))
        txdoc = TransactionDoc(10, currency, blockstamp, 0,
                               [key.pubkey], inputs, unlocks,
                               outputs, message, None)
        txdoc.sign([key])
        self.commit_outputs_to_self(currency, key.pubkey, txdoc)
        time = self._blockchain_processor.time(currency)
        tx = Transaction(currency=currency,
                         pubkey=key.pubkey,
                         sha_hash=txdoc.sha_hash,
                         written_block=0,
                         blockstamp=blockstamp,
                         timestamp=time,
                         signatures=txdoc.signatures,
                         issuers=[key.pubkey],
                         receivers=[receiver],
                         amount=amount,
                         amount_base=amount_base,
                         comment=txdoc.comment,
                         txid=0,
                         state=Transaction.TO_SEND,
                         local=True,
                         raw=txdoc.signed_raw())
        forged_tx.append(tx)
        return forged_tx
예제 #2
0
파일: documents.py 프로젝트: florck/sakia
    def prepare_tx(self, key, receiver, blockstamp, amount, amount_base, message, currency):
        """
        Prepare a simple Transaction document
        :param SigningKey key: the issuer of the transaction
        :param str receiver: the target of the transaction
        :param duniterpy.documents.BlockUID blockstamp: the blockstamp
        :param int amount: the amount sent to the receiver
        :param int amount_base: the amount base of the currency
        :param str message: the comment of the tx
        :param str currency: the target community
        :return: the transaction document
        :rtype: List[sakia.data.entities.Transaction]
        """
        forged_tx = []
        sources = [None]*41
        while len(sources) > 40:
            result = self.tx_sources(int(amount), amount_base, currency, key.pubkey)
            sources = result[0]
            computed_outputs = result[1]
            overheads = result[2]
            # Fix issue #594
            if len(sources) > 40:
                sources_value = 0
                for s in sources[:39]:
                    sources_value += s.amount * (10**s.base)
                sources_value, sources_base = reduce_base(sources_value, 0)
                chained_tx = self.prepare_tx(key, key.pubkey, blockstamp,
                                             sources_value, sources_base, "[CHAINED]", currency)
                forged_tx += chained_tx
        self._sources_processor.consume(sources)
        logging.debug("Inputs : {0}".format(sources))

        inputs = self.tx_inputs(sources)
        unlocks = self.tx_unlocks(sources)
        outputs = self.tx_outputs(key.pubkey, receiver, computed_outputs, overheads)
        logging.debug("Outputs : {0}".format(outputs))
        txdoc = TransactionDoc(10, currency, blockstamp, 0,
                               [key.pubkey], inputs, unlocks,
                               outputs, message, None)
        txdoc.sign([key])
        self.commit_outputs_to_self(currency, key.pubkey, txdoc)
        time = self._blockchain_processor.time(currency)
        tx = Transaction(currency=currency,
                         pubkey=key.pubkey,
                         sha_hash=txdoc.sha_hash,
                         written_block=0,
                         blockstamp=blockstamp,
                         timestamp=time,
                         signatures=txdoc.signatures,
                         issuers=[key.pubkey],
                         receivers=[receiver],
                         amount=amount,
                         amount_base=amount_base,
                         comment=txdoc.comment,
                         txid=0,
                         state=Transaction.TO_SEND,
                         local=True,
                         raw=txdoc.signed_raw())
        forged_tx.append(tx)
        return forged_tx
예제 #3
0
    def send_money(self, amount, sources, receiver, blockstamp, message):

        result = self.outputs_from_sources(amount, sources)
        inputs = result[0]
        computed_outputs = result[1]
        overheads = result[2]

        unlocks = []
        for i, s in enumerate(sources):
            unlocks.append(Unlock(i, [SIGParameter(0)]))
        outputs = self.tx_outputs(receiver, computed_outputs, overheads)

        tx = Transaction(3, self.currency, blockstamp, 0, [self.key.pubkey],
                         inputs, unlocks, outputs, message, None)
        tx.sign([self.key])
        return tx