Skip to content

Instantly share code, notes, and snippets.

@leongaban
Last active March 5, 2018 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leongaban/6aa9779194f87445eff1f62e4cec6342 to your computer and use it in GitHub Desktop.
Save leongaban/6aa9779194f87445eff1f62e4cec6342 to your computer and use it in GitHub Desktop.
Guide to setup Decred edge-currency-plugin

Plugin Forked from Airbitz https://github.com/leongaban/edge-currency-decred

EdgeDecred

Challenges / Sprint items

  • Setup and run a Decred full node locally

  • Setup and run ElectrumX server (requires leveldb)

  • ISSUE: Can't run ElectrumX locally

  • Connect ElectrumX to the Decred full node

  • Obtain electrumServers for Decred to be used in edge-currency plugin

  • Update the JavaScript plugin to use the ElectrumX Decred servers

  • Build ReactNative app to test

  • Move from local to hosted dev test

  • Deploy servers to production, submit plugin PR 🚀

stakey

Running the ElectrumX Docker image:

docker run \
  -v /Users/leongaban/electrumx_docker:/data \
  -e DAEMON_URL=http://USER:PASSWORD@127.0.0.1:19119 \
  -e RPC_HOST=127.0.0.1 \
  -e COIN=Decred \
  -p 19119:19119 \
  cipherz/docker-electrumx
@leongaban
Copy link
Author

leongaban commented Feb 22, 2018

New electrum server setup + error

Adding a new coin to the electrumx server can be a pain to develop since the only real instructions online are meant to install and 
run it as a service. The following is a guide to get it up and running quickly and to be able to make changes that are quickly reflected.
References: 
https://freedomnode.com/blog/69/how-to-install-an-electrum-server-using-full-bitcoin-node-and-electrumx
https://github.com/kyuupichan/electrumx/blob/master/docs/HOWTO.rst
Assumptions: OSX
1. Install LevelDB
  brew install leveldb

2. Install Python3
  brew install python3

3. Install Python Dependencies
  pip3 install --upgrade pip setuptools wheel
  pip3 install aiohttp pylru leveldb plyvel

4. Clone ElectrumX
  cd <Project Home>
  git clone https://github.com/cipherzzz/electrumx.git

5. Setup Env(Testnet)
  export DAEMON_URL="http://<rpcuser>:<rpcpassword>@127.0.0.1:19119/"
  export DB_DIRECTORY="/Users/macuser/.electrumx/"
  export DB_ENGINE="leveldb"
  export HOST="0.0.0.0"
  export COIN="Decred"
  export NET="testnet"

6. Startup electrumx
  cd <Project Home>/electrumx
  python3 ./electrumx_server.py

*Note

You should see the server startup with an error like:

ERROR:Daemon:connection problem - is your daemon running? Retrying occasionally...

7. Startup dcrd(testnet)
dcrd --testnet -u USER -P PASSWORD --rpclisten=127.0.0.1:19119 --rpccert=$HOME/Library/Application\ Support/Dcrd/rpc.cert --notls

*Note

I am getting further now, but I'm not sure what this error means:

ERROR:Controller:Traceback (most recent call last):
File "/Users/macuser/Projects/Decred/electrumx/server/controller.py", line 176, in on_future_done future.result()
File "/Users/macuser/Projects/Decred/electrumx/server/block_processor.py", line 206, in main_loop await task()
File "/Users/macuser/Projects/Decred/electrumx/server/block_processor.py", line 243, in check_and_advance_blocks for n, raw_block in enumerate(raw_blocks)]
File "/Users/macuser/Projects/Decred/electrumx/server/block_processor.py", line 243, in for n, raw_block in enumerate(raw_blocks)]
File "/Users/macuser/Projects/Decred/electrumx/lib/coins.py", line 272, in block txs = cls.DESERIALIZER(raw_block, start=len(header)).read_tx_block()
File "/Users/macuser/Projects/Decred/electrumx/lib/tx.py", line 113, in read_tx_block return [read() for _ in range(self._read_varint())]
File "/Users/macuser/Projects/Decred/electrumx/lib/tx.py", line 113, in return [read() for _ in range(self._read_varint())]
File "/Users/macuser/Projects/Decred/electrumx/lib/tx.py", line 245, in read_tx_and_hash tx, tx_hash, vsize = self._read_tx_parts()
File "/Users/macuser/Projects/Decred/electrumx/lib/tx.py", line 214, in _read_tx_parts tx = super().read_tx()
File "/Users/macuser/Projects/Decred/electrumx/lib/tx.py", line 91, in read_tx self._read_inputs(), # inputs
File "/Users/macuser/Projects/Decred/electrumx/lib/tx.py", line 117, in _read_inputs return [read_input() for i in range(self._read_varint())]
File "/Users/macuser/Projects/Decred/electrumx/lib/tx.py", line 117, in return [read_input() for i in range(self._read_varint())]
File "/Users/macuser/Projects/Decred/electrumx/lib/tx.py", line 123, in _read_input self._read_varbytes(), # script
File "/Users/macuser/Projects/Decred/electrumx/lib/tx.py", line 149, in _read_varbytes return self._read_nbytes(self._read_varint())
File "/Users/macuser/Projects/Decred/electrumx/lib/tx.py", line 145, in _read_nbytes assert self.binary_length >= end
AssertionError

@leongaban
Copy link
Author

leongaban commented Feb 25, 2018

2 current issues

1) can't run Electrumx locally

decred cd electrumx
➜  electrumx git:(master) python3 ./electrumx_server.py
INFO:root:ElectrumX server starting
Traceback (most recent call last):
  File "./electrumx_server.py", line 24, in main
    controller = Controller(Env())
  File "/Users/leongaban/projects/decred/electrumx/server/env.py", line 38, in __init__
    self.coin = Coin.lookup_coin_class(coin_name, network)
  File "/Users/leongaban/projects/decred/electrumx/lib/coins.py", line 94, in lookup_coin_class
    .format(name, net))
lib.coins.CoinError: unknown coin Decred and network testnet combination
CRITICAL:root:ElectrumX server terminated abnormally
➜  electrumx git:(master)

2) Need electrumx servers for Decred

src/info/decred.js

feeUpdateInterval: 10000,
// @TODO need to replace these
feeInfoServer: 'https://decredfees.21.co/api/v1/fees/list',
infoServer: 'https://info1.edgesecure.co:8444/v1/electrumServers/DCR',
simpleFeeSettings: {
  highFee: '1000000',
  lowFee: '10000',
  standardFeeLow: '10000',
  standardFeeHigh: '1000000',
  standardFeeLowAmount: '',
  standardFeeHighAmount: ''
},
electrumServers: []

@leongaban
Copy link
Author

leongaban commented Mar 2, 2018

EdgeApp/edge-react-gui#271

Current issue: Errors when using the Decred edge-plugin with the Edge-React-Gui

Error: node_modules/edge-currency-bitcoin/lib/engine/currencyEngine.js.flow:28
 28: import bcoin from 'bcoin'
                       ^^^^^^^ bcoin. Required module not found

Error: node_modules/edge-currency-bitcoin/lib/engine/keyManager.js.flow:6
  6: import bcoin from 'bcoin'
                       ^^^^^^^ bcoin. Required module not found

Error: node_modules/edge-currency-bitcoin/lib/engine/parseTransaction.js.flow:2
  2: import bcoin from 'bcoin'
                       ^^^^^^^ bcoin. Required module not found

Error: node_modules/edge-currency-bitcoin/lib/index.js.flow:8
  8: import bcoin from 'bcoin'
                       ^^^^^^^ bcoin. Required module not found

Error: node_modules/edge-currency-bitcoin/lib/info/decred.js.flow:4
  4: export const decredInfo: AbcCurrencyInfo = {
                              ^^^^^^^^^^^^^^^ property `metaTokens`. Property not found in
                                                v
  4: export const decredInfo: AbcCurrencyInfo = {
  5:   // Basic currency information:
  6:   currencyCode: 'DCR',
...:
 59: }
     ^ object literal

Error: node_modules/edge-currency-bitcoin/lib/plugin/currencyPlugin.js.flow:20
 20: import bcoin from 'bcoin'
                       ^^^^^^^ bcoin. Required module not found

Error: node_modules/edge-currency-bitcoin/lib/utils/addressFormat/addressFormatIndex.js.flow:3
  3: import bcoin from 'bcoin'
                       ^^^^^^^ bcoin. Required module not found

Error: node_modules/edge-currency-bitcoin/lib/utils/addressFormat/cashAddress.js.flow:5
  5: import bcoin from 'bcoin'
                       ^^^^^^^ bcoin. Required module not found

@leongaban
Copy link
Author

Steps to install and setup edge-react-gui && use the edge-cryptocurrency-bitcoin plugin:
https://gist.github.com/cipherzzz/65a46f3b1fd6194ef6a20c35de2986a8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment