示例#1
0
def print_balance():
    """
    Prints the current wallet balance.
    """

    balance = GetBalance(Wallet_Import(-1, 0), GetBlock())
    print(balance)
    return balance
    def createTrans(self, sequance_number, signature, fromUser, toUser, transaction_fee, data, amount, transaction_time, transaction_sender=None):

      # Printing the info of tx
      dprint("\nCreating the transaction")
      dprint("***")
      dprint(sequance_number)
      dprint(signature)
      dprint(fromUser)
      dprint(toUser)
      dprint(data)
      dprint(amount)
      dprint("***\n")
      # End

      # Some data
      signature_class = Signature.fromBase64(signature)
      temp_signature = signature_class.toBase64()

      already_got = self.tx_already_got(temp_signature)
      # End

      # Validation
      dprint("\nValidation")
      if Ecdsa.verify((str(sequance_number)+str(fromUser)+str(toUser)+str(data)+str(amount)+str(transaction_fee)+str(transaction_time)), signature_class, PublicKey.fromPem(fromUser)) and not amount < self.minumum_transfer_amount and not transaction_fee < self.transaction_fee and not already_got and not (int(time.time()) - transaction_time) > 60:
        dprint("Signature is valid")

        dprint("Getsequancenumber: "+str(GetSequanceNumber(fromUser, self)+1))
        if sequance_number == (GetSequanceNumber(fromUser, self)+1):
          dprint("Sequance number is valid")

          balance = GetBalance(fromUser, self)

          if balance >= (float(amount)+float(transaction_fee)) and (balance - (float(amount)+float(transaction_fee))) > 2:
            dprint("Amount is valid")

            # Local saving
            the_tx = Transaction(
                sequance_number= sequance_number,
                signature=temp_signature,
                fromUser= fromUser,
                toUser=toUser,
                data = data,
                amount = amount,
                transaction_fee= transaction_fee,
                time_of_transaction = transaction_time
            )
            self.pendingTransaction.append(the_tx)
            self.change_transaction_fee()
            self.save_block()
            # End

            self.propagating_the_tx(the_tx)

            return True

      dprint(" Validation end")
示例#3
0
def menu():
    """
    The main structure of the cli mode, this function prints the menu, 
    listens to the entries, makes the directions.
    """

    while True:
        show_menu()
        choices_input = question_maker(mode="main")

        if choices_input == "connectmainnetwork":
            connect_to_main_network()
        if choices_input == "cw":
            Wallet_Create()
        if choices_input == "sc":
            temp_coin_amount = input("Coin Amount (ex. 1.0): ")
            type_control = False
            try:
                float(temp_coin_amount)
                type_control = True
            except:
                print("This is not float coin amount.")

            if type_control and not float(temp_coin_amount) < GetBlock().minumum_transfer_amount:
                send_coin(float(temp_coin_amount), input("Please write receiver adress: "))

        if choices_input == "gb":
            print(GetBalance(Wallet_Import(0,0), GetBlock()))
            print(Wallet_Import(0,3))
        if choices_input == "help":
            show_menu()
        if choices_input == "ndstart":
            ndstart(str(input("ip: ")), int(input("port: ")))
        if choices_input == "ndstop":
            ndstop()
        if choices_input == "ndconnect":
            ndconnect(str(input("node ip: ")), int(input("node port: ")))

        if choices_input == "ndconnectmixdb":
            ndconnectmixdb()
        if choices_input == "ndnewunl":
            save_new_unl_node(input("Please write ID of the node: "))
        if choices_input == "testmodeon":
            test_mode(True)
        if choices_input == "testmodeoff":
            test_mode(False)
        if choices_input == "debugmodeon":
            debug_mode(True)
            # from node.myownp2pn import mynode
            # mynode.main_node.debug = True
        if choices_input == "debugmodeoff":
            debug_mode(False)
            # from node.myownp2pn import mynode
            # mynode.main_node.debug = False

        if choices_input == "getfullnodelist":
            GetNodeList()
        if choices_input == "getblock":
            if the_settings()["test_mode"]:
                CreateBlock()
            else:
                GetBlockFromOtherNode()



        if choices_input == "0":
            exit()
示例#4
0
    def reflesh_balance(self):

        self.text = "Balance: " + str(
            GetBalance(Wallet_Import(-1, 0), GetBlock()))
示例#5
0
def menu():
    """
    The main structure of the cli mode, this function prints the menu, 
    listens to the entries, makes the directions.
    """

    while True:
        show_menu()
        choices_input = question_maker(mode="main")

        if choices_input == "w":
            all_wallets = list(get_saved_wallet())
            if not len(all_wallets) == 0:

                current_wallet = the_settings()["wallet"]
                for wallet in all_wallets:
                    number = str(all_wallets.index(wallet))
                    address = Wallet_Import(all_wallets.index(wallet),3)
                    if not current_wallet == number:
                        print(menu_maker(menu_number=number, menu_text=address))
                    else:
                        print(menu_maker(menu_number=number, menu_text=address + " - CURRENTLY USED"))

                while True:
                    try:
                        new_wallet = input("Please select wallet: ")
                        if int(new_wallet) in list(range(len(all_wallets))):
                            change_wallet(new_wallet)
                            break
                        else:
                            print("There is no such wallet")
                    except:
                        print("This is not a number")
            else:
                print("There is no wallet")




        if choices_input == "connectmainnetwork":
            connect_to_main_network()
        if choices_input == "cw":
            Wallet_Create()
        if choices_input == "sc":
            temp_coin_amount = input("Coin Amount (ex. 1.0): ")
            type_control = False
            try:
                float(temp_coin_amount)
                type_control = True
            except:
                print("This is not float coin amount.")

            if type_control and not float(temp_coin_amount) < GetBlock().minumum_transfer_amount:
                send_coin(float(temp_coin_amount), input("Please write receiver adress: "))

        if choices_input == "gb":
            print(GetBalance(Wallet_Import(-1,0), GetBlock()))
        if choices_input == "help":
            show_menu()
        if choices_input == "ndstart":
            ndstart(str(input("ip: ")), int(input("port: ")))
        if choices_input == "ndstop":
            ndstop()
        if choices_input == "ndconnect":
            ndconnect(str(input("node ip: ")), int(input("node port: ")))

        if choices_input == "ndconnectmixdb":
            ndconnectmixdb()
        if choices_input == "ndnewunl":
            save_new_unl_node(input("Please write ID of the node: "))
        if choices_input == "testmodeon":
            test_mode(True)
        if choices_input == "testmodeoff":
            test_mode(False)
        if choices_input == "debugmodeon":
            debug_mode(True)
            # from node.myownp2pn import mynode
            # mynode.main_node.debug = True
        if choices_input == "debugmodeoff":
            debug_mode(False)
            # from node.myownp2pn import mynode
            # mynode.main_node.debug = False

        if choices_input == "getfullnodelist":
            GetNodeList()
        if choices_input == "getblock":
            if the_settings()["test_mode"]:
                CreateBlock()
            else:
                GetBlockFromOtherNode()



        if choices_input == "0":
            exit()