Skip to content

Instantly share code, notes, and snippets.

@Vishwas1
Created March 21, 2019 08:40
Show Gist options
  • Save Vishwas1/5bf1cc64aac215f2f62ac7faf630ea81 to your computer and use it in GitHub Desktop.
Save Vishwas1/5bf1cc64aac215f2f62ac7faf630ea81 to your computer and use it in GitHub Desktop.

Initial setup

Bitcoin setup

sudo apt-get install build-essential libtool autotools-dev automake pkg-config bsdmainutils python3

sudo apt-get install libssl-dev libevent-dev libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev

Setup Zagg-core

git clone [email protected]:zagg-protocol/zagg-core.git
git checkout bitcoin_merge
git pull
git submodule init
git submodule update
cd lib/bitcoin
./autogen.sh
./configure CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768" --disable-zmq --disable-wallet --without-gui --without-miniupnpc
make -j 8
cd ..
cd ..
./autogen.sh
./configure
make -j 8
  • configure bitcoin.conf file
  • Put it in the folder /home/vishswasb/.bitcoin - by deffault bitcoin folder. change the according to yours.
  • configure stellar-core.cfg file
  • Make sure to configure stellar configuration as per stellar's specs like creating newdb, forcescp etc. you can follow this blog for that.
  • Put this file in the root directory of the project : zagg-core/src
  • Open terminal, navigate into directory zagg-core/src and run the command ./stellar-core --conf ../stellar-core.cfg
  • You will notice that, first Bitcoin-core (in RegTest mode) runs and then Stellar-core core runs.

Doing UTXO transaction on Zagg

  • Open url in browser: http://localhost:11626/info
  • Get the transaction Hex and put it into utxo endpoint.
http://localhost:11626/utxo?hex=0100000001165e16075ed04a18def8189f25b819d12d77cbe0a0cc11a07e2ef2cba7c0f6a5010000006b483045022100aa257728154d1086f4662de6a82cbd7c207a7a2a2d210db6c2fe657ad9867e590220447005c27a5f54124304e1229797ff939ad964037c31dc8d867bd6eed3fafab4012102f04f81b5e18567b3bf2b4f9dbbe85a9a27cf0461d408d9f4633681837e336197fdffffff02a08601000000000017a914da7ec908514b582a76e38bd150c00667ae4d63858780076559000000001976a914f16f8594c321d1c4ccb910ffa34a7df3540abc5f88ac95010000

  • This will fail to say like, account not found or invalid signature etc. which is what is expected. since your are using incorrect HEX (I mean the one which is created in my system)
  • Till this step, it is enough for testing UTXO tx in Zagg now if you want to test the real HEX and want to see if the transaction is successfully going inside the mempool and then into the block then follow the next section.

Use Electrum to form transaction HEX

Electrum wallet

  • Download wallet: https://github.com/spesmilo/electrum/releases/tag/3.2.3 ver : Electrum-3.2.3.tar.gz
  • Setup and run Electrum Wallet using command ./run_electrum --regtest. Create a new wallet for yourself (<wallet address>).
  • Send some money to the newly generated public key (in Electrum wallet app) from zagg-core miner account.
    • Run the zagg-core
    • Open a terminal (anywhere)
    • Create an account bitcoin-cli getnewaddress : (<new public key>)
    • Mine some coin for that account using command bitcoin-cli generatetoaddress <no. of blocks> <new public key>
    • Send money to <wallet address> using command bitcoin-cli sendtoaddress <wallet address> <value>

Electrum server

  • Download server: https://github.com/chris-belcher/electrum-personal-server/releases/tag/eps-v0.1.5
  • ver : electrum-personal-server-eps-v0.1.5
  • Configure the configuration file in Electrum server.
    • Add the newly generated public key (<wallet address>) to wallet_segwit
    • Add host, port,rpcport, rpc_user, rpc_password, bitcoin-rpc-host, bitcoin-rpc-port etc.
  • Get the server config from here
  • Run ./rescan-script.py script in Electrrum server to fetch all related transactions for the public key specified in configuration file. Provide the block height = 1 if asked.
  • Run Electrum server using command ./server.py
  • Once everything works, you will notice the RED button turns GREEN in Electrum wallet
  • Wait for sometime for Electrum server to sync with zagg-core.
  • Once it gets synced, you will notice UTXOs in wallet.

Generating HEX

Now we will try to form HEX from Electrum wallet.

  • Copy the public key which you had created using bitcoin-cli (<new public key>) and open the Electrum wallet, go to send tab, paste the public key in pay to text box. Fill in the other details.
  • Stop the Electrum server because we don't want to use it. We only wanted to use Electrum server to sync the utxo - mainly to bring the utxo into the wallet to form tx.
  • Click on Preview button.
  • Press the Sign button to sign the transaction.
  • Click on Copy button to get the signed transaction HEX.

Disclaimer

  • zagg-core is not compactible with Electrum
  • When you try to run the Electrum rescan in server, you will get error. {'code': -32601, 'message': 'Method not found'}
  • What you can do is, run latest bitcoind first and connect the electrum server to it with the above configuration files.
  • Once the wallet is synced, just form the HEX and stop everything.
  • Then re-run the zagg-core and throw the HEX on utxo via browser as mentioned above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment