Example #1
0
def main(args):
    if args["serve"]:
        # HACK!
        alice_public_key = user_public_key("alice")
        bank.issue(1000, alice_public_key)
        serve()
    elif args["ping"]:
        send_message("ping", "")
    elif args["balance"]:
        name = args["<name>"]
        public_key = user_public_key(name)
        send_message("balance", public_key)
    elif args["tx"]:
        sender_private_key = user_private_key(args["<from>"])
        sender_public_key = sender_private_key.get_verifying_key()

        recipient_public_key = user_public_key(args["<to>"])
        amount = int(args["<amount>"])

        # fetch sender utxos
        utxo_response = send_message("utxo", sender_public_key)
        utxo = utxo_response["data"]

        # prepare transaction
        tx = prepare_simple_tx(utxo, sender_private_key, recipient_public_key,
                               amount)

        # send transactions to bank
        response = send_message("tx", tx)
        print(response)
    else:
        print("invalid command")
Example #2
0
def main(args):
    if args["serve"]:
        from identities import alice_public_key
        bank.issue(1000, alice_public_key)
        serve()
    elif args["ping"]:
        response = send_message(ADDRESS, "ping", "", response=True)
        print(response)
    elif args["balance"]:
        name = args["<name>"]
        public_key = user_public_key(name)
        response = send_message(ADDRESS, "balance", public_key, response=True)
        print(response)
    elif args["tx"]:
        # Grab parameters
        sender_private_key = user_private_key(args["<from>"])
        sender_public_key = sender_private_key.get_verifying_key()
        recipient_private_key = user_private_key(args["<to>"])
        recipient_public_key = recipient_private_key.get_verifying_key()
        amount = int(args["<amount>"])

        # Fetch utxos available to spend
        response = send_message(ADDRESS, "utxos", sender_public_key, response=True)
        utxos = response["data"]

        # Prepare transaction
        tx = prepare_simple_tx(utxos, sender_private_key, recipient_public_key, amount)

        # send to bank
        response = send_message(ADDRESS, "tx", tx, response=True)
        print(response)
    else:
        print("Invalid commands")
Example #3
0
def main(args):
    if args["serve"]:
        global bank
        bank_id = int(os.environ["BANK_ID"])
        bank = Bank(id=bank_id, private_key=bank_private_key(bank_id))
        bank.airdrop(airdrop_tx())
        bank.schedule_next_block()
        serve()
    elif args["ping"]:
        send_message("ping", "")
    elif args["balance"]:
        name = args["<name>"]
        public_key = user_public_key(name)
        send_message("balance", public_key)
    elif args["tx"]:
        sender_private_key = user_private_key(args["<from>"])
        recipient_public_key = user_public_key(args["<to>"])
        amount = int(args["<amount>"])
        sender_public_key = sender_private_key.get_verifying_key()

        utxo_response = send_message("utxo", sender_public_key)
        utxo = utxo_response["data"]

        tx = prepare_simple_tx(utxo, sender_private_key, recipient_public_key,
                               amount)

        response = send_message("tx", tx)
        print("response")

    else:
        print("invalid command")
Example #4
0
def main(args):
    # Can't use 0.0.0.0 from the outside to talk to the docker containers
    local_address = ("127.0.0.1", 5000)

    if args["serve"]:
        global bank
        bank_id = int(os.environ["BANK_ID"])
        bank = Bank(
            id=bank_id,
            private_key=bank_private_key(bank_id),
        )
        bank.airdrop(airdrop_tx())
        bank.schedule_next_block()
        serve()
    elif args["ping"]:
        response = send_message(local_address, "ping", "", response=True)
        print(f"Response to ping: {response}")
    elif args["balance"]:
        name = args["<name>"]
        public_key = user_public_key(name)
        response = send_message(local_address,
                                "balance",
                                public_key,
                                response=True)
        print(f"Response to balance: {response}")
    elif args["tx"]:
        # Grab parameters
        sender_private_key = user_private_key(args["<from>"])
        sender_public_key = sender_private_key.get_verifying_key()
        recipient_private_key = user_private_key(args["<to>"])
        recipient_public_key = recipient_private_key.get_verifying_key()
        amount = int(args["<amount>"])

        # Fetch utxos available to spend
        response = send_message(local_address,
                                "utxos",
                                sender_public_key,
                                response=True)
        utxos = response["data"]

        # Prepare transaction
        tx = prepare_simple_tx(utxos, sender_private_key, recipient_public_key,
                               amount)

        # send to bank
        response = send_message(local_address, "tx", tx, response=True)
        print(f"Response to tx: {response}")
    else:
        print("Invalid commands")
Example #5
0
def main(args):
    if args["serve"]:
        global bank
        bank_id = int(os.environ["BANK_ID"])
        bank = Bank(
            id=bank_id,
            private_key=bank_private_key(bank_id),
        )
        bank.airdrop(airdrop_tx())
        bank.schedule_next_block()
        serve()
    elif args["ping"]:
        response = send_message(ADDRESS, "ping", "", response=True)
        print(response)
    elif args["balance"]:
        name = args["<name>"]
        public_key = user_public_key(name)
        response = send_message(ADDRESS, "balance", public_key, response=True)
        print(response)
    elif args["tx"]:
        # Grab parameters
        sender_private_key = user_private_key(args["<from>"])
        sender_public_key = sender_private_key.get_verifying_key()
        recipient_private_key = user_private_key(args["<to>"])
        recipient_public_key = recipient_private_key.get_verifying_key()
        amount = int(args["<amount>"])

        # Fetch utxos available to spend
        response = send_message(ADDRESS,
                                "utxos",
                                sender_public_key,
                                response=True)
        utxos = response["data"]

        # Prepare transaction
        tx = prepare_simple_tx(utxos, sender_private_key, recipient_public_key,
                               amount)

        # send to bank
        response = send_message(ADDRESS, "tx", tx, response=True)
        print(response)
    else:
        print("Invalid commands")
Example #6
0
        bank.issue(1000, alice_public_key)
        serve()
    elif args["balance"]:
        name = args["<name>"]
        public_key = user_public_key(name)
        send_message("balance", public_key)
    elif args["tx"]:
        sender_private_key = user_private_key(args["<from>"])
        sender_public_key = sender_private_key.get_verifying_key()
        
        recipient_public_key = user_public_key(args["<to>"])
        amount = int(args["<amount>"])

        # fetch utxo
        utxo_response = send_message("utxo", sender_public_key)
        utxo = utxo_response["data"]

        # prepare
        tx = prepare_simple_tx(utxo, sender_private_key, recipient_public_key,
                               amount)
        # send to bank
        response = send_message("tx", tx)
        print(response)
    else:
        print("invalid command")