Beispiel #1
0
    def sign(self, context: Dict[str, Any]) -> List[str]:
        """
        Creates a Transaction with a context prepared by a view-only Wallet.
        Returns a List of the Transaction hash (as hex) and serialized raw Transaction (as hex).
        """

        # Extract the inputs.
        inputs: List[OutputInfo] = []
        for input_i in context["inputs"]:
            inputs.append(self.crypto.output_from_json(input_i))
            inputs[-1].index.index = input_i["mixin_index"]

        # Extract the outputs.
        outputs: List[SpendableOutput] = []
        for output in context["outputs"]:
            address: Address = Address.parse(self.crypto, output["address"])
            outputs.append(
                SpendableOutput(
                    address.network,
                    address.view_key,
                    address.spend_key,
                    address.payment_id,
                    output["amount"],
                ))

        # Convert the ring to binary.
        ring: List[List[List[bytes]]] = []
        for i in range(len(context["ring"])):
            ring.append([])
            for v in range(len(context["ring"][i])):
                ring[i].append([])
                ring[i][v].append(bytes.fromhex(context["ring"][i][v][0]))
                ring[i][v].append(bytes.fromhex(context["ring"][i][v][1]))

        # Construct a SpendableTransaction from the context.
        sending: SpendableTransaction = self.crypto.spendable_transaction(
            inputs,
            context["mixins"],
            outputs,
            ring,
            SpendableOutput(
                self.crypto.network_bytes[0],
                self.public_view_key,
                self.public_spend_key,
                None,
                0,
            ),
            context["fee"],
        )

        # Sign it.
        self.crypto.sign(sending, self.private_view_key,
                         self.private_spend_key)

        result: Tuple[bytes, bytes] = sending.serialize()
        return [result[0].hex(), result[1].hex()]
Beispiel #2
0
def XMR_address_test(monero_crypto: MoneroCrypto, constants: Dict[str, Any]):
    watch: WatchWallet = WatchWallet(
        monero_crypto,
        MoneroRPC("", -1),
        constants["PRIVATE_VIEW_KEY"],
        constants["PUBLIC_SPEND_KEY"],
        -1,
    )

    address: Address = watch.new_address((0, 0))
    assert address.network == monero_crypto.network_bytes[0]
    assert address.payment_id is None
    assert address.address == constants["XMR"]["ADDRESS"]
    assert address == Address.parse(monero_crypto, constants["XMR"]["ADDRESS"])
Beispiel #3
0
def XMR_subaddress_address_test(monero_crypto: MoneroCrypto, constants: Dict[str, Any]):
    watch: WatchWallet = WatchWallet(
        monero_crypto,
        MoneroRPC("", -1),
        constants["PRIVATE_VIEW_KEY"],
        constants["PUBLIC_SPEND_KEY"],
        -1,
    )

    for subaddress in constants["XMR"]["SUBADDRESSES"]:
        address: Address = watch.new_address(subaddress[0])
        assert address.payment_id is None
        assert address.address == subaddress[1]
        assert address.address == subaddress[1]
        assert address == Address.parse(monero_crypto, subaddress[1])
Beispiel #4
0
def TRTL_integrated_address_test(turtlecoin_crypto: TurtlecoinCrypto,
                                 constants: Dict[str, Any]):
    watch: WatchWallet = WatchWallet(
        turtlecoin_crypto,
        TurtlecoinRPC("", -1),
        constants["PRIVATE_VIEW_KEY"],
        constants["PUBLIC_SPEND_KEY"],
        -1,
    )

    address: Address = watch.new_address(constants["TRTL"]["PAYMENT_ID"])
    assert address.network == turtlecoin_crypto.network_bytes[1]
    assert address.payment_id == constants["TRTL"]["PAYMENT_ID"]
    assert address.address == constants["TRTL"]["INTEGRATED_ADDRESS"]
    assert address == Address.parse(turtlecoin_crypto,
                                    constants["TRTL"]["INTEGRATED_ADDRESS"])
Beispiel #5
0
def TRTL_address_test(turtlecoin_crypto: TurtlecoinCrypto,
                      constants: Dict[str, Any]):
    watch: WatchWallet = WatchWallet(
        turtlecoin_crypto,
        TurtlecoinRPC("", -1),
        constants["PRIVATE_VIEW_KEY"],
        constants["PUBLIC_SPEND_KEY"],
        -1,
    )

    address: Address = watch.new_address(b"")
    assert address.network == turtlecoin_crypto.network_bytes[0]
    assert address.payment_id is None
    assert address.address == constants["TRTL"]["ADDRESS"]
    assert address == Address.parse(turtlecoin_crypto,
                                    constants["TRTL"]["ADDRESS"])
Beispiel #6
0
    def new_address(self, unique_factor: Union[Tuple[int, int],
                                               bytes]) -> Address:
        """Creates a new address."""

        properties: Tuple[Tuple[bytes, bytes], Optional[bytes], bytes,
                          bytes] = self.crypto.new_address(
                              (self.private_view_key, self.public_spend_key),
                              unique_factor)

        if properties[0][1] not in self.unique_factors:
            if not isinstance(unique_factor, bytes):
                self.unique_factors[properties[0][1]] = unique_factor

        return Address(self.crypto,
                       properties[0],
                       properties[1],
                       network_byte=properties[2])
Beispiel #7
0
def XMR_integrated_address_test(
    monero_payment_id_crypto: MoneroCrypto, constants: Dict[str, Any]
):
    watch: WatchWallet = WatchWallet(
        monero_payment_id_crypto,
        MoneroRPC("", -1),
        constants["PRIVATE_VIEW_KEY"],
        constants["PUBLIC_SPEND_KEY"],
        -1,
    )

    address: Address = watch.new_address(constants["XMR"]["PAYMENT_ID"])
    assert address.network == monero_payment_id_crypto.network_bytes[1]
    assert address.payment_id == constants["XMR"]["PAYMENT_ID"]
    assert address.address == constants["XMR"]["INTEGRATED_ADDRESS"]
    assert address == Address.parse(
        monero_payment_id_crypto, constants["XMR"]["INTEGRATED_ADDRESS"]
    )
Beispiel #8
0
                          str(index.index) + " for " +
                          str(spendable[1][index].amount) + ".")
                    available += spendable[1][index].amount
                waiting = False
                break
    last = current

# Wait 10 more blocks.
print("Waiting for the output to unlock.")
while rpc.get_block_count() != last + 10:
    sleep(10)

print(
    "Where would you like to forward it? 0.0001 XMR will be ignored to make room for the fee. "
)
dest: Address = Address.parse(crypto, input())

# Prepare the Transaction.
# Leave 1 off the fee to allow a change output.
context: Dict[str, Any] = watch.prepare_send(dest, available - 100000000,
                                             100000000 - 1)

# Sign it.
publishable: List[str] = json.loads(
    json.dumps(wallet.sign(json.loads(json.dumps(context)))))

# Publish it.
watch.finalize_send(True, context, publishable[1])

# Print the hash.
print("The hash is " + publishable[0] + ".")