Shows first bitcoin address of an HD wallet

Committer:
stepansnigirev
Date:
Tue Feb 05 10:22:08 2019 +0000
Revision:
2:44e51c3d3bda
Parent:
1:6fc207e6e60d
mbed-os

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stepansnigirev 0:21a56f84206e 1 #include <mbed.h>
stepansnigirev 0:21a56f84206e 2 #include "gui.h"
stepansnigirev 0:21a56f84206e 3 #include "Bitcoin.h"
stepansnigirev 0:21a56f84206e 4
stepansnigirev 0:21a56f84206e 5 /* to drop std:: part in the code */
stepansnigirev 0:21a56f84206e 6 using std::string;
stepansnigirev 0:21a56f84206e 7
stepansnigirev 0:21a56f84206e 8 GUI gui; /* our GUI instance */
stepansnigirev 0:21a56f84206e 9 Label lbl; /* label in the global scope, we will change text from the button callback */
stepansnigirev 1:6fc207e6e60d 10 QR qr; /* QR in the global scope, we will change text from the button callback */
stepansnigirev 0:21a56f84206e 11
stepansnigirev 0:21a56f84206e 12 /* we gonna use testnet here, will be used in address generation and key derivation */
stepansnigirev 0:21a56f84206e 13 /* to switch to the mainnet just change this to false */
stepansnigirev 0:21a56f84206e 14 #define USE_TESTNET true
stepansnigirev 0:21a56f84206e 15
stepansnigirev 0:21a56f84206e 16 int main() {
stepansnigirev 0:21a56f84206e 17
stepansnigirev 1:6fc207e6e60d 18 /* init the key. handy tool: https://iancoleman.io/bip39/ */
stepansnigirev 1:6fc207e6e60d 19 HDPrivateKey hd("rhythm witness display knock head cable era exact submit boost exile seek topic pool sound", "my secret password");
stepansnigirev 1:6fc207e6e60d 20 HDPrivateKey first_key = hd.hardenedChild(84).hardenedChild(USE_TESTNET).hardenedChild(0).child(0).child(0);
stepansnigirev 0:21a56f84206e 21 string address = first_key.address();
stepansnigirev 0:21a56f84206e 22
stepansnigirev 0:21a56f84206e 23 gui.init();
stepansnigirev 0:21a56f84206e 24
stepansnigirev 0:21a56f84206e 25 /* Create a label to display addresses and xpub */
stepansnigirev 0:21a56f84206e 26 lbl = Label(address);
stepansnigirev 0:21a56f84206e 27 lbl.size(gui.width()-40, 100); // full width
stepansnigirev 1:6fc207e6e60d 28 lbl.position(20, 400);
stepansnigirev 2:44e51c3d3bda 29 lbl.alignText(ALIGN_TEXT_CENTER);
stepansnigirev 0:21a56f84206e 30
stepansnigirev 1:6fc207e6e60d 31 qr = QR("bitcoin:"+address);
stepansnigirev 1:6fc207e6e60d 32 qr.size(300);
stepansnigirev 1:6fc207e6e60d 33 qr.position(0, 50);
stepansnigirev 1:6fc207e6e60d 34 qr.align(ALIGN_CENTER);
stepansnigirev 1:6fc207e6e60d 35
stepansnigirev 0:21a56f84206e 36 while(1) {
stepansnigirev 0:21a56f84206e 37 gui.update();
stepansnigirev 0:21a56f84206e 38 }
stepansnigirev 1:6fc207e6e60d 39 }