Ejemplo n.º 1
0
class Faucet:
    """Initializes and controls dedicated btc faucet wallet"""
    def __init__(self):
        self.key = Key(config.private_key)
        self.address = self.key.address
        self.balance = self.key.get_balance("btc")
        self.fee = get_fee(fast=False)

    def send(self, wallet_address):
        # minimum amount that can be sent is .00000546 satoshi's
        return self.key.send([(wallet_address, 0.00000546, "btc")])

    def generate_qr_hash(self, hash):
        latest_transaction = pyqrcode.create("https://blockstream.info/tx/" +
                                             hash)
        latest_transaction.png(filepath + "latest_transaction.png", scale=5.5)
Ejemplo n.º 2
0
 def post_action_transaction(self):
     if not self.check_input_arguments(["address", "private_key", "amount"
                                        ]):
         return self._response(error_msg.PARAMS_ERROR)
     try:
         key = Key(self._input.get("private_key"))
         transaction_id = key.send(
             [(str(self._input.get("address")), self._input.get("amount"),
               "satoshi")],
             fee=80,
         )
         logger.info("create transaction {}".format(transaction_id))
         return self._response(data=transaction_id)
     except Exception as e:
         logger.error("create transaction error {}".format(e))
         self._msg = str(e)
         self._ret = 1
         return self._response()
Ejemplo n.º 3
0
def get_somme(message, destinataire):
    current_user_id = message.from_user.id
    current_wallet = wallet_exist(current_user_id)
    current_key = Key(current_wallet[1])
    solde = decimal.Decimal(current_key.get_balance('btc'))
    if message.text == 'Annuler':
        msg = bot.send_message(
            message.chat.id,
            "Bonjour, voici l'adresse de votre wallet Bitcoin : \n\n```" +
            current_wallet[0] +
            "```\n\nUtilisez-la pour réapprovisionner votre porte-feuille Bitcoin.",
            reply_markup=markup,
            parse_mode="Markdown")
        bot.register_next_step_handler(msg, process_step)
    else:
        try:
            somme = float(message.text)
            try:
                outputs = [
                    (str(destinataire), float(somme), 'btc'),
                ]
                trans_link = current_key.send(outputs)
                msg = bot.send_message(
                    message.chat.id,
                    "Très bien, l'argent a été envoyé ! Les fonds seront disponibles d'ici une heure.\nVoici l'adresse de votre transaction :\nhttps://blockchain.info/tx/"
                    + str(trans_link) + ".",
                    reply_markup=markup,
                    parse_mode="Markdown")
                bot.register_next_step_handler(msg, process_step)
            except:
                msg = bot.send_message(
                    message.chat.id,
                    "Vos BTC n'ont pas été envoyés ! Vérifiez bien que vous avez assez de fonds et réessayez.",
                    reply_markup=markup,
                    parse_mode="Markdown")
                bot.register_next_step_handler(msg, process_step)
        except:
            msg = bot.send_message(
                message.chat.id,
                "Entrez la somme à envoyer sous le format suivant : *0.843* (avec un point) !",
                reply_markup=markup,
                parse_mode="Markdown")
            bot.register_next_step_handler(msg, process_step)
Ejemplo n.º 4
0
def get_somme(message, destinataire):
    current_user_id = message.from_user.id
    current_wallet = wallet_exist(current_user_id)
    current_key = Key(current_wallet[1])
    solde = decimal.Decimal(current_key.get_balance('btc'))
    if message.text == 'Back':
        msg = bot.send_message(
            message.chat.id,
            "Hello, here is the address of your Bitcoin wallet: \n\n```" +
            current_wallet[0] + "```\n\n Use it to fund your Bitcoin wallet.",
            reply_markup=markup,
            parse_mode="Markdown")
        bot.register_next_step_handler(msg, process_step)
    else:
        try:
            somme = float(message.text)
            try:
                outputs = [
                    (str(destinataire), float(somme), 'btc'),
                ]
                trans_link = current_key.send(outputs)
                msg = bot.send_message(
                    message.chat.id,
                    "All right, the money has been sent! Funds will be available within an hour. \n Here is the address of your transaction :\nhttps://blockchain.info/tx/"
                    + str(trans_link) + ".",
                    reply_markup=markup,
                    parse_mode="Markdown")
                bot.register_next_step_handler(msg, process_step)
            except:
                msg = bot.send_message(
                    message.chat.id,
                    "Your wallet has no balance. Make sure you have enough funds and try again.",
                    reply_markup=markup,
                    parse_mode="Markdown")
                bot.register_next_step_handler(msg, process_step)
        except:
            msg = bot.send_message(
                message.chat.id,
                "Enter the amount to be sent in the following format: * 0.843 * (with a point)!",
                reply_markup=markup,
                parse_mode="Markdown")
            bot.register_next_step_handler(msg, process_step)
Ejemplo n.º 5
0
def 付款(私钥, 比特地址集):
    my_key=Key(私钥)
    my_key.send(比特地址集)
Ejemplo n.º 6
0
class MainPage(tk.Frame):  
    def __init__(self, parent, controller): 
        tk.Frame.__init__(self, parent)
        
        self.parent = parent
        self.configure(background='white')
        self.currency = 'btc'
        self.trans_url = "https://blockstream.info/testnet/api/tx/"
        
        addressLabel = tk.Label(self, text = "Address: dfsu3fdu434", bg = "white", fg = "black", font = LARGEFONT)
        addressLabel.grid(row = 0, column = 0, columnspan = 2, sticky = W, padx = 10, pady = 10, ipadx = 5, ipady = 5)
        self.coinLabel = tk.Label(self, text = "Coins: 1 btc", bg = "white", fg = "black", font = LARGEFONT)
        self.coinLabel.grid(row = 1, column = 0, columnspan = 2, sticky = W, padx = 10, pady = 10, ipadx = 5, ipady = 5)
        self.sendAddressInput = tk.Entry(self, bg='#ebf3ff', font = LARGEFONT)
        self.sendAddressInput.grid(row = 2, column = 0, sticky = W+E, padx = 10, pady = 10, ipadx = 5, ipady = 5)
        self.sendCoinsInput = tk.Entry(self, bg='#ebf3ff', font = LARGEFONT)
        self.sendCoinsInput.grid(row = 3, column = 0, sticky = W, padx = 10, pady = 10, ipadx = 5, ipady = 5)
        sendButton = tk.Button(self, text = 'Send',
                                fg = 'white',
                                bg = '#8c9fbd',
                                activeforeground = 'white',
                                activebackground = '#b8c2d1',
                                borderwidth = 2,
                                relief = FLAT,
                                overrelief = RAISED,
                                font = LARGEFONT,
                                command = lambda : self.asyncSendCoins())
        sendButton.grid(row = 4, column = 0, sticky = W, padx = 10, pady = 10, ipadx = 5, ipady = 5)
        copyButton = tk.Button(self, text = 'Copy PrivKey to Clipboard',
                                fg = 'white',
                                bg = '#de9ec0',
                                activeforeground = 'white',
                                activebackground = '#de9ec0',
                                borderwidth = 2,
                                relief = FLAT,
                                overrelief = RAISED,
                                font = LARGEFONT,
                                command = lambda : self.copyKey())
        copyButton.grid(row = 4, column = 1, sticky = W, padx = 10, pady = 10, ipadx = 5, ipady = 5)
        self.changeCurrencyInput = tk.Entry(self, bg='#ebf3ff', font = LARGEFONT)
        self.changeCurrencyInput.grid(row = 5, column = 0, sticky = W, padx = 10, pady = 10, ipadx = 5, ipady = 5)
        changeCurrencyButton = tk.Button(self, text = 'Change currency',
                                fg = 'white',
                                bg = '#8c9fbd',
                                activeforeground = 'white',
                                activebackground = '#b8c2d1',
                                borderwidth = 2,
                                relief = FLAT,
                                overrelief = RAISED,
                                font = LARGEFONT,
                                command = lambda : self.asyncChangeCurrency())
        changeCurrencyButton.grid(row = 5, column = 1, padx = 10, pady = 10, ipadx = 5, ipady = 5)
        
        self.transactions = Listbox(self)
        self.transactions.grid(row = 0, column = 2, rowspan = 3, columnspan = 4, sticky = 'nsew')
        self.transactions.bind('<<ListboxSelect>>', self.asynconselect)
        self.transactionsVar = StringVar()
        self.transactionsVar.set(150 * " ")
        self.transactionsLabel = tk.Message(self, textvariable = self.transactionsVar, bg = "white", fg = "black", width = 300)
        self.transactionsLabel.grid(row = 3, column = 2, rowspan = 3, sticky = W+E, columnspan = 4, padx = 10, pady = 10, ipadx = 5, ipady = 5)
        
        self.parent.after(3000, self.asyncUpdateInterface)
        
        if (controller.config.get('istestnet') == 1):
            self.trans_url = "https://blockstream.info/testnet/api/tx/"
            if (controller.config.get('private_key') != None):
                self.key = PrivateKeyTestnet(controller.config.get('private_key'))
            else:
                self.key = PrivateKeyTestnet()
        else:
            self.trans_url = "https://blockstream.info/api/tx/"
            if (controller.config.get('private_key') != None):
                self.key = Key(controller.config.get('private_key'))
            else:
                self.key = Key()
        
        addressLabel.config(text = "Address: " + self.key.address)
        self.coinLabel.config(text = "Coins: " + self.key.get_balance(self.currency) + " " + self.currency)
            
        transactions_list = self.key.get_transactions()
        for trans in transactions_list:
            print(trans)
            self.transactions.insert(END, trans)
        print(self.trans_url)
        for x in range(6):
            Grid.columnconfigure(self, x, weight=1)

        for y in range(5):
            Grid.rowconfigure(self, y, weight=1)
    
    def asyncChangeCurrency(self):
        x = threading.Thread(target = self.changeCurrency)
        x.start()
        
    def changeCurrency(self):
        cur_values = dict(SUPPORTED_CURRENCIES).keys()
        us_input = self.changeCurrencyInput.get()
        self.changeCurrencyInput.delete(0, 'end')
        if (us_input in cur_values):
            self.currency = us_input
            coins = self.key.get_balance(self.currency)
            self.coinLabel.config(text = "Coins: " + coins + " " + self.currency)
    
    def asynconselect(self,evt):
        x = threading.Thread(target = self.onselect, args = (evt,))
        x.start()
    
    def onselect(self, evt):
        # Note here that Tkinter passes an event object to onselect()
        w = evt.widget
        index = 0
        try:
            index = int(w.curselection()[0])
        except IndexError:
            print('Unselected item in list of transactions')
            return
        value = w.get(index)
        cb.copy(value)
        print('You selected item %d: "%s"' % (index, value))
        try:
            response = requests.get(self.trans_url + value)
            print(response.json())
            json_resp = response.json()
            in_address = json_resp['vin'][0]['prevout']['scriptpubkey_address']
            out_address = json_resp['vout'][0]['scriptpubkey_address']
            fee = json_resp['fee']
            money = json_resp['vout'][0]['value']
            block_time = json_resp['status']['block_time']
            block_time = datetime.datetime.fromtimestamp(block_time).strftime('%Y-%m-%d %H:%M:%S')
            self.transactionsVar.set("Transaction: " + str(value) +
                            "\nFrom: " + str(in_address) + 
                            "\nTo: " + str(out_address) +
                            "\nValue: " + str(money) + " satoshi" +
                            "\nFee: " + str(fee) + " satoshi" + 
                            "\nTime: " + block_time)
        except BaseException:
            messagebox.showerror(title = 'Error', message = 'Maybe problems with connection or you don\'t have transactions')
    
    def asyncSendCoins(self):
        x = threading.Thread(target = self.sendCoins)
        x.start()
    
    def sendCoins(self):
        us_address = self.sendAddressInput.get()
        us_coins = self.sendCoinsInput.get()
        self.sendAddressInput.delete(0, 'end')
        self.sendCoinsInput.delete(0, 'end')
        try:
            if (us_address == '' or us_coins == ''):
                return
            us_coins = float(us_coins)
        except ValueError:
            print('invalid transformation')
            return
        
        try:
            # Send coins and update labels
            outputs = [
                (us_address, us_coins, self.currency)
            ]
            print(self.key.send(outputs))
            self.updateInterface()
            messagebox.showinfo(title = 'Transacation', message = 'Successed')
        except BaseException:
            messagebox.showerror(title = 'Error', message = 'Maybe, you don\'t have internet connection or use wrong key or you don\'t have enough money')
            
    def asyncUpdateInterface(self):
        x = threading.Thread(target = self.cycleUpdateInterface, daemon = True)
        x.start()
    
    def cycleUpdateInterface(self):
        self.updateInterface()
        self.parent.after(3000, self.asyncUpdateInterface)
            
    def updateInterface(self):
        self.coinLabel.config(text = "Coins: " + self.key.get_balance(self.currency) + " " + self.currency)
        new_transactions = self.key.get_transactions()
        trans_values = self.transactions.get(0, 'end')
        for trans in new_transactions:
            if trans not in trans_values:
                self.transactions.insert(0, trans)

    def copyKey(self):
        cb.copy(self.key.to_wif())