Ejemplo n.º 1
0
def add_contact(wallet, approved_puzhash_sig_pairs):
    choice = "c"
    print(divider)
    while choice == "c":
        singlestring = input("Enter contact string from authoriser: ")
        if singlestring == "q":
            return
        try:
            arr = singlestring.split(":")
            name = arr[0]
            puzzle = arr[1]
            puzhash = puzzlehash_from_string(puzzle)
            sig = arr[2]
            signature = BLSSignature_from_string(sig)
            while name in approved_puzhash_sig_pairs:
                print(
                    f"{name} is already a contact. Would you like to add a new contact or overwrite {name}?"
                )
                print(f"{selectable} 1: Overwrite")
                print(f"{selectable} 2: Add new contact")
                print(f"{selectable} q: Return to menu")
                pick = input(prompt)
                if pick == "q":
                    return
                elif pick == "1":
                    continue
                elif pick == "2":
                    name = input("Enter new name for contact: ")
            approved_puzhash_sig_pairs[name] = (puzhash, signature)
            choice = input(
                "Press 'c' to add another, or 'q' to return to menu: ")
        except Exception as err:
            print(err)
            return
Ejemplo n.º 2
0
async def initiate_ap(wallet, ledger_api):
    if wallet.temp_balance <= 0:
        print("You need some money first")
        return None
    # TODO: add a strict format checker to input here (and everywhere tbh)
    # Actual puzzle lockup/spend
    a_pubkey = wallet.get_next_public_key().serialize()
    b_pubkey = input("Enter recipient's pubkey: 0x")
    amount = -1
    while amount > wallet.temp_balance or amount < 0:
        amount = input("Enter amount to give recipient: ")
        if amount == "q":
            return
        if not amount.isdigit():
            amount = -1
        amount = int(amount)

    APpuzzlehash = ap_wallet_a_functions.ap_get_new_puzzlehash(
        a_pubkey, b_pubkey)
    spend_bundle = wallet.generate_signed_transaction(amount, APpuzzlehash)
    await ledger_api.push_tx(tx=spend_bundle)
    print()
    print(f"{informative} AP Puzzlehash is: {str(APpuzzlehash)}")
    print(f"{informative} Pubkey used is: {hexlify(a_pubkey).decode('ascii')}")
    sig = str(
        ap_wallet_a_functions.ap_sign_output_newpuzzlehash(
            APpuzzlehash, wallet, a_pubkey).sig)
    print(f"{informative} Approved change signature is: {sig}")
    print()
    print("Give the AP wallet the following initialisation string -")
    print(
        f"{informative} Initialisation string: {str(APpuzzlehash)}:{hexlify(a_pubkey).decode('ascii')}:{sig}"
    )

    print()
    print(
        "The next step is to approve some contacts for the AP wallet to send to."
    )
    print(
        "From another standard wallet press '4' to print out their puzzlehash for receiving money."
    )
    choice = ""
    while choice != "q":
        singlestr = input("Enter approved puzzlehash: ")
        if singlestr == "q":
            return
        puzzlehash = puzzlehash_from_string(singlestr)
        print()
        #print("Puzzle: " + str(puzzlehash))
        sig = wallet.sign(puzzlehash, a_pubkey)
        #print("Signature: " + str(sig.sig))
        name = input("Add a name for this puzzlehash: ")
        print("Give the following contact string to the AP wallet.")
        print(
            f"{informative} Contact string for AP Wallet: {name}:{str(puzzlehash)}:{str(sig.sig)}"
        )
        choice = input("Press 'c' to continue, or 'q' to quit to menu: ")
Ejemplo n.º 3
0
    def set_sender_values(self, AP_puzzlehash, a_pubkey_used):
        if isinstance(AP_puzzlehash, str):
            self.AP_puzzlehash = puzzlehash_from_string(AP_puzzlehash)
        else:
            self.AP_puzzlehash = AP_puzzlehash

        if isinstance(a_pubkey_used, str):
            a_pubkey = BLSPublicKey.from_bytes(bytes.fromhex(a_pubkey_used))
            self.a_pubkey = a_pubkey
        else:
            self.a_pubkey = a_pubkey_used
Ejemplo n.º 4
0
 def as_select_coins(self, amount, as_puzzlehash):
     if amount > self.current_balance or amount < 0:
         return None
     used_utxos = set()
     if isinstance(as_puzzlehash, str):
         as_puzzlehash = puzzlehash_from_string(as_puzzlehash)
     coins = self.my_utxos.copy()
     for pcoin in self.as_pending_utxos:
         coins.add(pcoin)
     for coin in coins:
         if coin.puzzle_hash == as_puzzlehash:
             used_utxos.add(coin)
     return used_utxos
Ejemplo n.º 5
0
def read_qr(wallet):
    amount = -1
    if wallet.current_balance <= 0:
        print("You need some money first")
        return None
    print("Input filename of QR code: ")
    fn = input(prompt)
    decoded = decode(Image.open(fn))
    puzzlehash = puzzlehash_from_string(decoded[0].data)
    while amount > wallet.temp_balance or amount <= 0:
        amount = input("Amount: ")
        if amount == "q":
            return
        if not amount.isdigit():
            amount = -1
        amount = int(amount)
    return wallet.generate_signed_transaction(amount, puzzlehash)
Ejemplo n.º 6
0
async def make_payment(wallet, ledger_api):
    amount = -1
    if wallet.current_balance <= 0:
        print("You need some money first")
        return None
    while amount > wallet.temp_balance or amount < 0:
        amount = input(f"{prompt} Enter amount to give recipient: ")
        if amount == "q":
            return
        if not amount.isdigit():
            amount = -1
        amount = int(amount)

    puzhashstring = input(f"{prompt} Enter puzzlehash: ")
    puzzlehash = puzzlehash_from_string(puzhashstring)
    tx = wallet.generate_signed_transaction(amount, puzzlehash)
    if tx is not None:
        await ledger_api.push_tx(tx=tx)