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
Beispiel #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
Beispiel #3
0
async def generate_transaction_document(
    issuers,
    tx_amounts,
    listinput_and_amount,
    outputAddresses,
    Comment="",
    OutputbackChange=None,
):

    listinput = listinput_and_amount[0]
    totalAmountInput = listinput_and_amount[1]
    total_tx_amount = sum(tx_amounts)

    head_block = await HeadBlock().head_block
    currency_name = head_block["currency"]
    blockstamp_current = BlockUID(head_block["number"], head_block["hash"])
    curentUnitBase = head_block["unitbase"]

    if not OutputbackChange:
        OutputbackChange = issuers

    # if it's not a foreign exchange transaction, we remove units after 2 digits after the decimal point.
    if issuers not in outputAddresses:
        total_tx_amount = (total_tx_amount //
                           10**curentUnitBase) * 10**curentUnitBase

    # Generate output
    ################
    listoutput = []
    for tx_amount, outputAddress in zip(tx_amounts, outputAddresses):
        generate_output(listoutput, curentUnitBase, tx_amount, outputAddress)

    # Outputs to himself
    rest = totalAmountInput - total_tx_amount
    generate_output(listoutput, curentUnitBase, rest, OutputbackChange)

    # Unlocks
    unlocks = generate_unlocks(listinput)

    # Generate transaction document
    ##############################

    return Transaction(
        version=10,
        currency=currency_name,
        blockstamp=blockstamp_current,
        locktime=0,
        issuers=[issuers],
        inputs=listinput,
        unlocks=unlocks,
        outputs=listoutput,
        comment=Comment,
        signatures=[],
    )
Beispiel #4
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