Bitcoin Forum
May 24, 2024, 08:54:47 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Python - Multi Creador de direcciones bitcoin y saber saldo + saldo total  (Read 1229 times)
xcbtrader (OP)
Hero Member
*****
Offline Offline

Activity: 865
Merit: 1006


View Profile
December 28, 2016, 07:38:41 AM
 #1

Buenas a todos.

He creado en Python + entorno gráfico, un pequeño programa que te permite crear direcciones bitcoin, ya sea mediante una palabra (o frase) o al azar.
También permite comprobar el saldo y el saldo total.

La comparto con ustedes por si a alguien le puede interesar.

Tener en cuenta que es simplemente a modo de ejemplo!!!!

Code:
__author__ = 'xcbtrader'
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from bitcoin import *
from tkinter import *
from tkinter import ttk, font
import sys
import requests
import json

class Aplicacion():
def __init__(self):

self.raiz = Tk()
self.raiz.geometry("700x305")
         
self.raiz.resizable(width=False, height=False)
self.raiz.title("Multi Create Addr Win 1.0")
self.fuente = font.Font(weight='bold', size=11)

self.etqText = ttk.Label(self.raiz, text= 'TEXTO PARA CREAR ADDR', font=self.fuente)
self.etqAddr = ttk.Label(self.raiz, text= 'DIRECCION BTC', font=self.fuente)
self.etqPriv = ttk.Label(self.raiz, text= 'PRIVADA',font=self.fuente)
self.etqWif = ttk.Label(self.raiz, text= 'WIF PARA IMPORTAR',font=self.fuente)
self.etqSaldo = ttk.Label(self.raiz, text= 'SALDO-TOT.RECIB.',font=self.fuente)
self.etqLin = ttk.Label(self.raiz, text= '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------')

self.msgText = StringVar()
self.msgText.set('')
self.msgAddr = StringVar()
self.msgAddr.set('')
self.msgPriv = StringVar()
self.msgPriv.set('')
self.msgWif = StringVar()
self.msgWif.set('')
self.msgSaldo = DoubleVar()
self.msgSaldo.set(0.0)
self.msgTotRec = DoubleVar()
self.msgTotRec.set(0.0)

self.tText = ttk.Entry(self.raiz,textvariable=self.msgText,justify= 'center',width=67,font=self.fuente)
self.tAddr = ttk.Entry(self.raiz,textvariable=self.msgAddr,justify= 'center',width=50,font=self.fuente)
self.tPriv = ttk.Entry(self.raiz,textvariable=self.msgPriv,justify= 'center',width=67,font=self.fuente)
self.tWif = ttk.Entry(self.raiz,textvariable=self.msgWif,justify= 'center',width=67,font=self.fuente)
self.tSaldo = ttk.Label(self.raiz,textvariable=str(self.msgSaldo),justify= 'center',font=self.fuente)
self.tTotRec = ttk.Label(self.raiz,textvariable=str(self.msgTotRec),justify= 'center',font=self.fuente)

self.BotAddrText = ttk.Button(self.raiz, text="ADDR <-> TEXT", padding=(5,5), command=self.crear_addr_text)
self.BotAddrAleat = ttk.Button(self.raiz, text="ADDR <-> ALEAT", padding=(5,5), command=self.crear_addr_aleat)
self.BotAddrSaldo = ttk.Button(self.raiz, text="SALDO", padding=(5,5), command=self.b1)
self.BotAddrGuardar = ttk.Button(self.raiz, text="GUARDAR", padding=(5,5), command=self.guardar)
self.BotInicializar = ttk.Button(self.raiz, text="INICIALIZAR", padding=(5,5), command=self.inicializar)
self.BotSalir = ttk.Button(self.raiz, text="SALIR", padding=(5,5), command=quit)

self.etqText.place(x=220, y=10)
self.tText.place(x=10, y=30)
self.etqAddr.place(x=180, y=65)
self.tAddr.place(x=10, y=85)
self.etqSaldo.place(x=530, y=65)
self.tSaldo.place(x=540, y=85)
self.tTotRec.place(x=540, y=105)
self.etqPriv.place(x=300, y=125)
self.tPriv.place(x=10, y=145)
self.etqWif.place(x=260, y=185)
self.tWif.place(x=10, y=205)
self.etqLin.place(x=10, y=240)

self.BotAddrText.place(x=20, y=260)
self.BotAddrAleat.place(x=150, y=260)
self.BotAddrSaldo.place(x=285, y=260)
self.BotAddrGuardar.place(x=388, y=260)
self.BotInicializar.place(x=492, y=260)
self.BotSalir.place(x=595, y=260)

self.raiz.mainloop()

def crear_addr_aleat(self):
priv = random_key()
pub = privtopub(priv)
addr = pubtoaddr(pub)
wif = encode_privkey(priv, 'wif')
self.msgAddr.set(addr)__author__ = 'deunido'
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from bitcoin import *
from tkinter import *
from tkinter import ttk, font
import sys
import requests
import json

class Aplicacion():
def __init__(self):

self.raiz = Tk()
self.raiz.geometry("700x305")
         
self.raiz.resizable(width=False, height=False)
self.raiz.title("Multi Create Addr Win 1.0")
self.fuente = font.Font(weight='bold', size=11)

self.etqText = ttk.Label(self.raiz, text= 'TEXTO PARA CREAR ADDR', font=self.fuente)
self.etqAddr = ttk.Label(self.raiz, text= 'DIRECCION BTC', font=self.fuente)
self.etqPriv = ttk.Label(self.raiz, text= 'PRIVADA',font=self.fuente)
self.etqWif = ttk.Label(self.raiz, text= 'WIF PARA IMPORTAR',font=self.fuente)
self.etqSaldo = ttk.Label(self.raiz, text= 'SALDO-TOT.RECIB.',font=self.fuente)
self.etqLin = ttk.Label(self.raiz, text= '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------')

self.msgText = StringVar()
self.msgText.set('')
self.msgAddr = StringVar()
self.msgAddr.set('')
self.msgPriv = StringVar()
self.msgPriv.set('')
self.msgWif = StringVar()
self.msgWif.set('')
self.msgSaldo = DoubleVar()
self.msgSaldo.set(0.0)
self.msgTotRec = DoubleVar()
self.msgTotRec.set(0.0)

self.tText = ttk.Entry(self.raiz,textvariable=self.msgText,justify= 'center',width=67,font=self.fuente)
self.tAddr = ttk.Entry(self.raiz,textvariable=self.msgAddr,justify= 'center',width=50,font=self.fuente)
self.tPriv = ttk.Entry(self.raiz,textvariable=self.msgPriv,justify= 'center',width=67,font=self.fuente)
self.tWif = ttk.Entry(self.raiz,textvariable=self.msgWif,justify= 'center',width=67,font=self.fuente)
self.tSaldo = ttk.Label(self.raiz,textvariable=str(self.msgSaldo),justify= 'center',font=self.fuente)
self.tTotRec = ttk.Label(self.raiz,textvariable=str(self.msgTotRec),justify= 'center',font=self.fuente)

self.BotAddrText = ttk.Button(self.raiz, text="ADDR <-> TEXT", padding=(5,5), command=self.crear_addr_text)
self.BotAddrAleat = ttk.Button(self.raiz, text="ADDR <-> ALEAT", padding=(5,5), command=self.crear_addr_aleat)
self.BotAddrSaldo = ttk.Button(self.raiz, text="SALDO", padding=(5,5), command=self.b1)
self.BotAddrGuardar = ttk.Button(self.raiz, text="GUARDAR", padding=(5,5), command=self.guardar)
self.BotInicializar = ttk.Button(self.raiz, text="INICIALIZAR", padding=(5,5), command=self.inicializar)
self.BotSalir = ttk.Button(self.raiz, text="SALIR", padding=(5,5), command=quit)

self.etqText.place(x=220, y=10)
self.tText.place(x=10, y=30)
self.etqAddr.place(x=180, y=65)
self.tAddr.place(x=10, y=85)
self.etqSaldo.place(x=530, y=65)
self.tSaldo.place(x=540, y=85)
self.tTotRec.place(x=540, y=105)
self.etqPriv.place(x=300, y=125)
self.tPriv.place(x=10, y=145)
self.etqWif.place(x=260, y=185)
self.tWif.place(x=10, y=205)
self.etqLin.place(x=10, y=240)

self.BotAddrText.place(x=20, y=260)
self.BotAddrAleat.place(x=150, y=260)
self.BotAddrSaldo.place(x=285, y=260)
self.BotAddrGuardar.place(x=388, y=260)
self.BotInicializar.place(x=492, y=260)
self.BotSalir.place(x=595, y=260)

self.raiz.mainloop()

def crear_addr_aleat(self):
priv = random_key()
pub = privtopub(priv)
addr = pubtoaddr(pub)
wif = encode_privkey(priv, 'wif')
self.msgAddr.set(addr)
self.msgPriv.set(priv)
self.msgWif.set(wif)

def crear_addr_text(self):
priv = sha256(self.msgText.get())
pub = privtopub(priv)
addr = pubtoaddr(pub)
wif = encode_privkey(priv, 'wif')
self.msgAddr.set(addr)
self.msgPriv.set(priv)
self.msgWif.set(wif)

def guardar(self):
if self.msgAddr.get() != '':
f = open(self.msgAddr.get() + '.dat', 'w')
f.write('WIF: ' + self.msgWif.get() + '\n')
f.write('PRIV: ' + self.msgPriv.get() + '\n')
f.write('ADDR: ' + self.msgAddr.get() + '\n')
f.write('SALDO: ' + str(self.msgSaldo.get()))
f.close()


def b1(self):
try:
request = 'http://btc.blockr.io/api/v1/address/info/' + self.msgAddr.get()
response = requests.get(request, timeout=10)
content = response.json()
content1 = content['data'] ['balance']
content2 = content['data'] ['totalreceived']
self.msgSaldo.set(content1)
self.msgTotRec.set(content2)
except KeyboardInterrupt:
exit()
except Exception:
self.msgSaldo.set(-1)
self.msgTotRec.set(-1)

def inicializar(self):
self.msgText.set('')
self.msgAddr.set('')
self.msgPriv.set('')
self.msgWif.set('')
self.msgSaldo.set(0.0)

def main():

mi_app = Aplicacion()
return 0

if __name__ == '__main__':
    main()
self.msgPriv.set(priv)
self.msgWif.set(wif)

def crear_addr_text(self):
priv = sha256(self.msgText.get())
pub = privtopub(priv)
addr = pubtoaddr(pub)
wif = encode_privkey(priv, 'wif')
self.msgAddr.set(addr)
self.msgPriv.set(priv)
self.msgWif.set(wif)

def guardar(self):
if self.msgAddr.get() != '':
f = open(self.msgAddr.get() + '.dat', 'w')
f.write('WIF: ' + self.msgWif.get() + '\n')
f.write('PRIV: ' + self.msgPriv.get() + '\n')
f.write('ADDR: ' + self.msgAddr.get() + '\n')
f.write('SALDO: ' + str(self.msgSaldo.get()))
f.close()


def b1(self):
try:
request = 'http://btc.blockr.io/api/v1/address/info/' + self.msgAddr.get()
response = requests.get(request, timeout=10)
content = response.json()
content1 = content['data'] ['balance']
content2 = content['data'] ['totalreceived']
self.msgSaldo.set(content1)
self.msgTotRec.set(content2)
except KeyboardInterrupt:
exit()
except Exception:
self.msgSaldo.set(-1)
self.msgTotRec.set(-1)

def inicializar(self):
self.msgText.set('')
self.msgAddr.set('')
self.msgPriv.set('')
self.msgWif.set('')
self.msgSaldo.set(0.0)

def main():

mi_app = Aplicacion()
return 0

if __name__ == '__main__':
    main()

AbraxasCcs
Legendary
*
Offline Offline

Activity: 1568
Merit: 1032


Beyond the flavor!


View Profile
December 28, 2016, 08:31:47 AM
 #2

Buenisimo!!!

No lo intento executar pues me parece que todo ese codigo va en al menos dos archivos distintos (¿estoy en lo correcto?) como debo llamar a cada archivo?

Mine Chococoin, eat real chocolate!
Bitrated user: Abraxas.
xcbtrader (OP)
Hero Member
*****
Offline Offline

Activity: 865
Merit: 1006


View Profile
December 28, 2016, 11:23:05 PM
 #3

Buenisimo!!!

No lo intento executar pues me parece que todo ese codigo va en al menos dos archivos distintos (¿estoy en lo correcto?) como debo llamar a cada archivo?


Buenas.

Disculpa que haya tardado tanto en contestar...

Copias el código que he puesto en un solo fichero y lo nombras como quieras, pero con extension .py

Por ejemplo: generarbtc.py

Para poder ejecutarlo correctamente, tienes que tener instaladas las librerías necesarias: bitcoin, tkinter y creo que las otras vienen por defecto, sinó, cuando te de error, instalas lo que te falte.

Un saludo

xcbtrader (OP)
Hero Member
*****
Offline Offline

Activity: 865
Merit: 1006


View Profile
December 29, 2016, 11:44:06 AM
 #4

Añadido el programa a mi github, junto a otros programas que os pueden interesar.

https://github.com/xcbtrader

Saludos

AbraxasCcs
Legendary
*
Offline Offline

Activity: 1568
Merit: 1032


Beyond the flavor!


View Profile
January 02, 2017, 04:06:21 PM
 #5

Buenisimo!!!

No lo intento executar pues me parece que todo ese codigo va en al menos dos archivos distintos (¿estoy en lo correcto?) como debo llamar a cada archivo?


Buenas.

Disculpa que haya tardado tanto en contestar...

Copias el código que he puesto en un solo fichero y lo nombras como quieras, pero con extension .py

Por ejemplo: generarbtc.py

Para poder ejecutarlo correctamente, tienes que tener instaladas las librerías necesarias: bitcoin, tkinter y creo que las otras vienen por defecto, sinó, cuando te de error, instalas lo que te falte.

Un saludo

Muchas gracias!!!

Mine Chococoin, eat real chocolate!
Bitrated user: Abraxas.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!