def get_transaction_document(current_block: dict, source: dict,
                             from_pubkey: str, to_pubkey: str) -> Transaction:
    """
    Return a Transaction document

    :param current_block: Current block infos
    :param source: Source to send
    :param from_pubkey: Public key of the issuer
    :param to_pubkey: Public key of the receiver

    :return: Transaction
    """
    # list of inputs (sources)
    inputs = [
        InputSource(
            amount=source["amount"],
            base=source["base"],
            source=source["type"],
            origin_id=source["identifier"],
            index=source["noffset"],
        )
    ]

    # list of issuers of the inputs
    issuers = [from_pubkey]

    # list of unlocks of the inputs
    unlocks = [
        Unlock(
            # inputs[index]
            index=0,
            # unlock inputs[index] if signatures[0] is from public key of issuers[0]
            parameters=[SIGParameter(0)],
        )
    ]

    # lists of outputs
    outputs = [
        OutputSource(
            amount=source["amount"],
            base=source["base"],
            condition="SIG({0})".format(to_pubkey),
        )
    ]

    transaction = Transaction(
        version=TRANSACTION_VERSION,
        currency=current_block["currency"],
        blockstamp=BlockUID(current_block["number"], current_block["hash"]),
        locktime=0,
        issuers=issuers,
        inputs=inputs,
        unlocks=unlocks,
        outputs=outputs,
        comment="",
        signatures=[],
    )

    return transaction
Exemplo n.º 2
0
def get_transaction_document(current_block, source, from_pubkey, to_pubkey):
    """
    Return a Transaction document

    :param dict current_block: Current block infos
    :param dict source: Source to send
    :param str from_pubkey: Public key of the issuer
    :param str to_pubkey: Public key of the receiver

    :return: Transaction
    """
    # list of inputs (sources)
    inputs = [
        InputSource(amount=source['amount'],
                    base=source['base'],
                    source=source['type'],
                    origin_id=source['identifier'],
                    index=source['noffset'])
    ]

    # list of issuers of the inputs
    issuers = [from_pubkey]

    # list of unlocks of the inputs
    unlocks = [
        Unlock(
            # inputs[index]
            index=0,
            # unlock inputs[index] if signatures[0] is from public key of issuers[0]
            parameters=[SIGParameter(0)])
    ]

    # lists of outputs
    outputs = [
        OutputSource(
            amount=source['amount'],
            base=source['base'],
            # only the receiver of the output can use it as input in another transaction
            conditions=Condition.token(SIG.token(to_pubkey)))
    ]

    transaction = Transaction(version=TRANSACTION_VERSION,
                              currency=current_block['currency'],
                              blockstamp=BlockUID(current_block['number'],
                                                  current_block['hash']),
                              locktime=0,
                              issuers=issuers,
                              inputs=inputs,
                              unlocks=unlocks,
                              outputs=outputs,
                              comment='',
                              signatures=None)

    return transaction
Exemplo n.º 3
0
    def tx_unlocks(self, sources):
        """
        Get unlocks to generate a transaction with a given amount of money

        :param list sources: The sources used to send the given amount of money

        :return: The list of unlocks to use in the transaction document
        """
        unlocks = []
        for i, s in enumerate(sources):
            unlocks.append(Unlock(i, [SIGParameter(0)]))
        return unlocks
 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)
Exemplo n.º 5
0
Arquivo: tx.py Projeto: duniter/silkaj
def generate_unlocks(listinput):
    unlocks = list()
    for i in range(0, len(listinput)):
        unlocks.append(Unlock(index=i, parameters=[SIGParameter(0)]))
    return unlocks
 def test_unlock(self):
     unlock1 = Unlock(0, [SIGParameter(0)])
     unlock2 = Unlock.from_inline("0:SIG(0)")
     self.assertEqual(unlock1, unlock2)
Exemplo n.º 7
0
         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),