Beispiel #1
0
    def prepare_tx(self, pubkey, blockstamp, amount, message, community):
        """
        Prepare a simple Transaction document
        :param str pubkey: the target of the transaction
        :param duniterpy.documents.BlockUID blockstamp: the blockstamp
        :param int amount: the amount sent to the receiver
        :param Community community: the target community
        :return: the transaction document
        :rtype: duniterpy.documents.Transaction
        """
        result = self.tx_sources(int(amount), community)
        sources = result[0]
        computed_outputs = result[1]
        overheads = result[2]
        self.caches[community.currency].available_sources = result[3][1:]
        logging.debug("Inputs : {0}".format(sources))

        inputs = self.tx_inputs(sources)
        unlocks = self.tx_unlocks(sources)
        outputs = self.tx_outputs(pubkey, computed_outputs, overheads)
        logging.debug("Outputs : {0}".format(outputs))
        tx = Transaction(3, community.currency, blockstamp, 0,
                         [self.pubkey], inputs, unlocks,
                         outputs, message, None)
        return tx
 def test_transaction_document_generation(self):
     transaction = Transaction(
         version=10,
         currency="gtest",
         blockstamp=BlockUID(
             8979, "000041DF0CCA173F09B5FBA48F619D4BC934F12ADF1D0B798639EB2149C4A8CC"
         ),
         locktime=0,
         issuers=list("8kXygUHh1vLjmcRzXVM86t38EL8dfFJgfBeHmkaWLamu"),
         inputs=[InputSource.from_inline(input_source_str)],
         unlocks=[Unlock(index=0, parameters=[SIGParameter(0)])],
         outputs=[OutputSource.from_inline(output_source_str)],
         comment="",
         signatures=[],
     )
     self.assertTrue(transaction.time is None)
     self.assertTrue(transaction.currency == "gtest")
     self.assertTrue(transaction.inputs[0].amount == 30)
Beispiel #3
0
result1 = Transaction(
    version=10,
    currency="g1",
    blockstamp=BlockUID(
        48000, "0000010D30B1284D34123E036B7BE0A449AE9F2B928A77D7D20E3BDEAC7EE14C"
    ),
    locktime=0,
    issuers=["BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh"],
    inputs=[
        InputSource(
            10000,
            0,
            "T",
            "B37D161185A760FD81C3242D73FABD3D01F4BD9EAD98C2842061A75BAD4DFA61",
            1,
        ),
        InputSource(
            257,
            0,
            "T",
            "16F1CF9C9B89BB8C34A945F56073AB3C3ACFD858D5FA420047BA7AED1575D1FE",
            1,
        ),
    ],
    unlocks=[
        Unlock(index=0, parameters=[SIGParameter(0)]),
        Unlock(index=1, parameters=[SIGParameter(0)]),
    ],
    outputs=[
        OutputSource(
            amount=str(1000),
            base=0,
            condition="SIG(DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw)",
        ),
        OutputSource(
            amount=str(4000),
            base=0,
            condition="SIG(4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw)",
        ),
        OutputSource(
            amount=str(5000),
            base=0,
            condition="SIG(BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh)",
        ),
    ],
    comment="Test comment",
    signatures=[],
)