Shows first bitcoin address of an HD wallet

main.cpp

Committer:
stepansnigirev
Date:
2019-02-05
Revision:
2:44e51c3d3bda
Parent:
1:6fc207e6e60d

File content as of revision 2:44e51c3d3bda:

#include <mbed.h>
#include "gui.h"
#include "Bitcoin.h"

/* to drop std:: part in the code */
using std::string;

GUI gui;     /* our GUI instance */
Label lbl;   /* label in the global scope, we will change text from the button callback */
QR qr;       /* QR in the global scope, we will change text from the button callback */

/* we gonna use testnet here, will be used in address generation and key derivation */
/* to switch to the mainnet just change this to false */
#define USE_TESTNET true

int main() {

  /* init the key. handy tool: https://iancoleman.io/bip39/ */
  HDPrivateKey hd("rhythm witness display knock head cable era exact submit boost exile seek topic pool sound", "my secret password");
  HDPrivateKey first_key = hd.hardenedChild(84).hardenedChild(USE_TESTNET).hardenedChild(0).child(0).child(0);
  string address = first_key.address();

  gui.init();

  /* Create a label to display addresses and xpub */
  lbl = Label(address);
  lbl.size(gui.width()-40, 100); // full width
  lbl.position(20, 400);
  lbl.alignText(ALIGN_TEXT_CENTER);

  qr = QR("bitcoin:"+address);
  qr.size(300);
  qr.position(0, 50);
  qr.align(ALIGN_CENTER);

  while(1) {
    gui.update();
  }
}