예제 #1
0
파일: piper.py 프로젝트: Chankster/BitBox
def genAndPrintKeys(curbtc, inputamt, numCopies, password, lcd):
	remPubKey = False
	remPrivKey = False

	#open serial number file which tracks the serial number
	snumfile = open('serialnumber.txt', 'r+')
	snum = snumfile.read()

	#open the printer itself
	printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)


	#load a blank image of the paper wallet with no QR codes or keys on it which we will draw on
	finalImg = Image.open("btc-wallet-blank.bmp")
	lcd_display(lcd, "Generating", "address")
	#this actually generates the keys.  see the file genkeys.py or genkeys_forget.py
	import genkeys as btckeys

	btckeys.genKeys()

	if btckeys.keysAreValid == False:
		printer.write("Error: The generated keys (public/private) are not the correct length.  Please try again.")
		
	#import wallet_enc as WalletEnc
	#encrypt the keys if needed
	#if(password != ""):
	#	privkey = WalletEnc.pw_encode(btckeys.privkey, password)
	#else:
	privkey = btckeys.privkey
	
	
	rememberKeys = False
	sqlitePubKey = ""
	sqlitePrivKey = ""
	strToWrite = ""
	if remPubKey:
		strToWrite = "\nPublic Key: "+btckeys.pubkey
		sqlitePubKey = btckeys.pubkey
		rememberKeys = True

	if remPrivKey:
		strToWrite = strToWrite + "\nPrivate Key: "+privkey
		sqlitePrivKey = privkey
		rememberKeys = True


	if rememberKeys == True:
		#store it to the sqlite db
		con = None
		try:
			con = sqlite3.connect('/home/pi/build/Piper/keys.db3')
		        con.execute("INSERT INTO keys (serialnum, public, private) VALUES (?,?,?)", (snum, sqlitePubKey, sqlitePrivKey))
		except sqlite3.Error, e:
			print "Error %s:" % e.args[0]
			sys.exit(1)
		finally:
예제 #2
0
파일: piper.py 프로젝트: Chankster/BitBox
			if con:
				con.commit()
				con.close()
			
		
		#store it in a flat file on the sd card
		f = open("/boot/keys.txt", 'a+')
		strToWrite = "Serial Number: " + snum + strToWrite
		f.write(strToWrite);
		f.write("\n---------------------------------\n")
		f.close()


	leftMarkText = "Serial Number: "+snum

	lcd_display(lcd, "Transferring", "Bitcoins!")
	usd = 1.0/float(curbtc)
	returnamt = usd*float(inputamt)
	#electrum -w /home/pi/.electrum/wallets/default_wallet -f 0.0001 payto 1PPyJbKyMtKjiMPJcm4dYbRdy9BcW3i3j2 0.0030
	transfer_cmd = ['electrum', '-w', '/home/pi/.electrum/wallets/default_wallet', '-f', '0.0001', 'payto', str(btckeys.pubkey), str(returnamt)]
	tx_hash = Popen(transfer_cmd, stdout=PIPE).communicate()[0]
	lcd_display(lcd, "Printing", "receipt")
	#do the actual printing
	for x in range(0, numCopies):

		#piper.print_keypair(pubkey, privkey, leftBorderText)
		print_keypair(btckeys.pubkey, privkey, leftMarkText, curbtc, inputamt, tx_hash)
		
		if numCopies > 1 and x < numCopies-1:
			time.sleep(30)