Esempio n. 1
0
    def serialise_tx(self):

        self._process_outputs()

        inputs_cbor = []
        for input in self.inputs:
            inputs_cbor.append(
                [
                    (input.type or 0),
                    cbor.Tagged(24, cbor.encode([input.prev_hash, input.prev_index])),
                ]
            )

        inputs_cbor = cbor.IndefiniteLengthArray(inputs_cbor)

        outputs_cbor = []
        for index, address in enumerate(self.output_addresses):
            outputs_cbor.append(
                [cbor.Raw(base58.decode(address)), self.outgoing_coins[index]]
            )

        for index, address in enumerate(self.change_addresses):
            outputs_cbor.append(
                [cbor.Raw(base58.decode(address)), self.change_coins[index]]
            )

        outputs_cbor = cbor.IndefiniteLengthArray(outputs_cbor)

        tx_aux_cbor = [inputs_cbor, outputs_cbor, self.attributes]
        tx_hash = hashlib.blake2b(data=cbor.encode(tx_aux_cbor), outlen=32).digest()

        witnesses = self._build_witnesses(tx_hash)
        tx_body = cbor.encode([tx_aux_cbor, witnesses])

        self.fee = self.compute_fee(
            self.input_coins_sum, self.outgoing_coins, self.change_coins
        )

        return tx_body, tx_hash
Esempio n. 2
0
def _cborize_signed_tx(keychain: seed.Keychain,
                       msg: CardanoSignTx) -> tuple[CborizedSignedTx, TxHash]:
    tx_body = _cborize_tx_body(keychain, msg)
    tx_hash = _hash_tx_body(tx_body)

    witnesses = _cborize_witnesses(
        keychain,
        msg.inputs,
        msg.certificates,
        msg.withdrawals,
        tx_hash,
        msg.protocol_magic,
    )

    metadata = None
    if msg.metadata:
        metadata = cbor.Raw(bytes(msg.metadata))

    return (tx_body, witnesses, metadata), tx_hash
Esempio n. 3
0
def _serialize_tx(keychain: seed.Keychain, msg: CardanoSignTx) -> Tuple[bytes, bytes]:
    tx_body = _build_tx_body(keychain, msg)
    tx_hash = _hash_tx_body(tx_body)

    witnesses = _build_witnesses(
        keychain,
        msg.inputs,
        msg.certificates,
        msg.withdrawals,
        tx_hash,
        msg.protocol_magic,
    )

    metadata = None
    if msg.metadata:
        metadata = cbor.Raw(bytes(msg.metadata))

    serialized_tx = cbor.encode([tx_body, witnesses, metadata])

    return serialized_tx, tx_hash
Esempio n. 4
0
def _cborize_signed_tx(keychain: seed.Keychain,
                       msg: CardanoSignTx) -> tuple[CborizedSignedTx, TxHash]:
    tx_body = _cborize_tx_body(keychain, msg)
    tx_hash = _hash_tx_body(tx_body)

    witnesses = _cborize_witnesses(
        keychain,
        msg.inputs,
        msg.certificates,
        msg.withdrawals,
        tx_hash,
        msg.protocol_magic,
    )

    auxiliary_data = None
    if msg.auxiliary_data:
        auxiliary_data_cbor = get_auxiliary_data_cbor(keychain,
                                                      msg.auxiliary_data,
                                                      msg.protocol_magic,
                                                      msg.network_id)
        auxiliary_data = cbor.Raw(auxiliary_data_cbor)

    return (tx_body, witnesses, auxiliary_data), tx_hash