Skip to content

Commit

Permalink
BTC integration (#5)
Browse files Browse the repository at this point in the history
* Initial work on LTC

* Support for BTC

* BTC progress

* Final updates for bitcoin

* configure fix
  • Loading branch information
seibelj authored May 17, 2020
1 parent c9c6063 commit ccee801
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 18 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# iCryptoNode - Monero Raspberry Pi Cryptocurrency Node Management Software
# iCryptoNode - Bitcoin and Monero Raspberry Pi Cryptocurrency Node Management Software

[iCryptoNode](https://icryptonode.com/) is an open source software project to manage blockchain daemons, specifically for single-board computers like Raspberry Pi. It aims to be blockchain agnostic by standardizing interfaces.

For now, we are only supporting [Monero](https://getmonero.org/).
For now, we are only supporting [Bitcoin](https://bitcoin.org/) and [Monero](https://getmonero.org/).

Anyone can use or build this software. Development is sponsored by [iCryptoNode.com](https://icryptonode.com/) which sells hardware pre-installed and configured with iCryptoNode and blockchain software.

## Features

- Blockchains:
- Bitcoin
- Monero
- *More coming soon*
- Privacy & Security
Expand Down Expand Up @@ -91,6 +92,10 @@ To:

Then `cmake .`, `make`, `sudo make install`.

### External Hard Drive

If you are trying to use a cryptocurrency with a large blockchain, (Bitcoin) and need an external hard drive, you must set it up at `/mnt/[coin name]` such as `/mnt/bitcoin`. You can follow instructions [here](https://www.raspberrypi.org/documentation/configuration/external-storage.md).

### Clone this repository

In your home folder on the raspberry pi:
Expand All @@ -101,7 +106,7 @@ In your home folder on the raspberry pi:
This automatically configures as many things as possible. Unfortunately some things can't (easily) be automated, which is why there are more manual steps after this.

`cd iCryptoNode/setup`
`sudo ./icn_configure monero`
`sudo ./icn_configure [bitcoin|monero]`

Let it run.

Expand All @@ -110,13 +115,13 @@ Let it run.
We use GPG for our PGP encryption implementation. It must be enabled in `php.ini`.

Edit `php.ini`:
`sudo nano /etc/php/7.0/cgi/php.ini`
`sudo nano /etc/php/7.3/cgi/php.ini`

Navigate to the `Dynamic Extensions` section and add this line:
`extension=gnupg.so`

Do the same for the PHP command-line interface if you'd like:
`sudo nano /etc/php/7.0/cli/php.ini`
`sudo nano /etc/php/7.3/cli/php.ini`

Make sure there are no semi-colons (`;`) before it! That comments out the line.

Expand Down Expand Up @@ -239,7 +244,7 @@ You should now be able to access iCryptoNode. Instructions on use are hosted her

When you build your own iCryptoNode rather than pre-purchase one, you need to install the blockchain software and sync it.

Go to the Updates tab and download and install the latest version of Monero. Once installed, go to the Node tab and enable the daemon. Syncing will take about a week, [unless you pre-install the blockchain](https://getmonero.org/resources/user-guides/importing_blockchain.html).
Go to the Updates tab and download and install the latest version of the blockchain software. Once installed, go to the Node tab and enable the daemon. Syncing will take about a week unless you pre-install the blockchain.

### Conclusion

Expand Down
2 changes: 1 addition & 1 deletion icryptonode/api/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function control($operation) {
return array('success' => false);
}

$output = shell_exec( NODE_CMD . ' ' . $operation );
$output = shell_exec( 'sudo ' . NODE_CMD . ' ' . $operation );
$vpn_status = json_decode($output);
return $vpn_status;
}
Expand Down
9 changes: 7 additions & 2 deletions icryptonode/api/Updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function install_daemon() {

$daemon_compressed_path = DAEMON_DOWNLOAD_PATH . '/' . basename($update_config[NODE_TYPE]['url']);

if ($this->endsWith($daemon_compressed_path, '.tar.bz2')) {
if ($this->endsWith($daemon_compressed_path, '.tar.bz2') || $this->endsWith($daemon_compressed_path, '.tar.gz')) {
shell_exec( "sudo " . SYSTEM_CMD_DIR . "/update_daemon " . escapeshellarg($daemon_compressed_path) );
}
else {
Expand Down Expand Up @@ -377,7 +377,12 @@ private function sha256($path) {
private function get_update_config() {
putenv('GNUPGHOME=' . GNUPG_HOME);
$res = gnupg_init();
$signed = file_get_contents( UPDATE_ENDPOINT . '/latest.json.asc' );
if (TESTMODE_ENABLED) {
$signed = file_get_contents( UPDATE_ENDPOINT . '/testing.json.asc' );
}
else {
$signed = file_get_contents( UPDATE_ENDPOINT . '/latest.json.asc' );
}
$plain = "";
$info = gnupg_verify($res, $signed, false, $plain);

Expand Down
3 changes: 2 additions & 1 deletion icryptonode/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define('ICRYPTONODE_VERSION', 2);
define('ICRYPTONODE_VERSION', 3);

define('DEBUG_ENABLED', true);
define('APP_ROOT', __DIR__);
Expand All @@ -14,6 +14,7 @@
define('NODE_CMD', APP_ROOT . '/node_commands/' . NODE_TYPE);

define('UPDATE_ENDPOINT', 'https://updates.icryptonode.com');
define('TESTMODE_ENABLED', false);

define('DAEMON_DIR', '/etc/icryptonode/daemon');
define('FIX_DAEMON_DIR_SCRIPT', '/etc/icryptonode/fix_folders.sh');
Expand Down
7 changes: 7 additions & 0 deletions icryptonode/cron/daemon_cron
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ fi

NODE_TYPE="$(sudo uci get icryptonode.@info[0].node_type)"

if [ "$NODE_TYPE" = "bitcoin" ]; then
if [ ! -d "/mnt/bitcoin/blockchain" ]; then
echo "daemon_cron: external drive not mounted, mounting"
sudo mount /dev/sda1 /mnt/bitcoin
fi
fi

DAEMON_FILE="/var/www/html/icryptonode/node_commands/$NODE_TYPE"

$DAEMON_FILE status
Expand Down
79 changes: 79 additions & 0 deletions icryptonode/node_commands/bitcoin
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/sh

DAEMON_FILE=/etc/icryptonode/daemon/bitcoin/bin/bitcoind
DAEMON_CLI_FILE=/etc/icryptonode/daemon/bitcoin/bin/bitcoin-cli
BLOCKCHAIN_DIR=/mnt/bitcoin/blockchain

LOG_FILE=/mnt/bitcoin/blockchain/debug.log
LOG_ROWS="200"

DAEMON_ENABLED="$(uci get icryptonode.@info[0].daemon_enabled)"

DAEMON_USER="$(uci get icryptonode.@info[0].daemon_user)"
DAEMON_PASS="$(uci get icryptonode.@info[0].daemon_pass)"
DAEMON_RPC_PORT="$(uci get icryptonode.@info[0].daemon_rpc_port)"

CMD="$1"

bitcoin_stop () {
PIDOF=$(ps aux | egrep bitcoind.-daemon | egrep -v grep | awk '{print $2}')
if [ -n "$PIDOF" ]; then
echo "Stopping bitcoin (PID = $PIDOF)"
$DAEMON_CLI_FILE -rpcuser=$DAEMON_USER -rpcpassword=$DAEMON_PASS -rpcport=$DAEMON_RPC_PORT stop
fi
}

bitcoin_start () {

if [ "$DAEMON_ENABLED" = "no" ]; then
echo "DAEMON_ENABLED = no, not starting bitcoin"
exit 1
fi
echo "Starting bitcoin"
$DAEMON_FILE -daemon -debuglogfile=$LOG_FILE -datadir=$BLOCKCHAIN_DIR -dbcache=128 -maxmempool=128 -mempoolexpiry=24 -disablewallet -noonion -debug=1 -shrinkdebugfile -rest -rpcallowip=0.0.0.0/0 -rpcbind=0.0.0.0 -rpcuser=$DAEMON_USER -rpcpassword=$DAEMON_PASS -rpcport=$DAEMON_RPC_PORT -server
}

bitcoin_restart () {
bitcoin_stop
sleep 6
bitcoin_start
}

if [ "$CMD" = "logs" ]; then

tail -n"$LOG_ROWS" "$LOG_FILE"

elif [ "$CMD" = "status" ]; then

PIDOF=$(ps aux | egrep bitcoind.-daemon | egrep -v grep | awk '{print $2}')

if [ -n "$PIDOF" ]; then
echo "Bitcoin running (PIDOF = $PIDOF)"
exit 5
else
exit 4
fi

elif [ "$CMD" = "stop" ]; then

bitcoin_stop
exit 0

elif [ "$CMD" = "start" ]; then

bitcoin_start
exit 0

elif [ "$CMD" = "restart" ]; then

bitcoin_restart
exit 0

elif [ "$CMD" = "version" ]; then

$DAEMON_FILE -version

else
exit 9
fi

79 changes: 79 additions & 0 deletions icryptonode/node_commands/litecoin
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/sh

DAEMON_FILE=/etc/icryptonode/daemon/litecoin/bin/litecoind
DAEMON_CLI_FILE=/etc/icryptonode/daemon/litecoin/bin/litecoin-cli
BLOCKCHAIN_DIR=/etc/icryptonode/blockchain

LOG_FILE=/etc/icryptonode/blockchain/debug.log
LOG_ROWS="200"

DAEMON_ENABLED="$(uci get icryptonode.@info[0].daemon_enabled)"

DAEMON_USER="$(uci get icryptonode.@info[0].daemon_user)"
DAEMON_PASS="$(uci get icryptonode.@info[0].daemon_pass)"
DAEMON_RPC_PORT="$(uci get icryptonode.@info[0].daemon_rpc_port)"

CMD="$1"

litecoin_stop () {
PIDOF=$(ps aux | egrep litecoind.-daemon | egrep -v grep | awk '{print $2}')
if [ -n "$PIDOF" ]; then
echo "Stopping litecoin (PID = $PIDOF)"
$DAEMON_CLI_FILE -rpcuser=$DAEMON_USER -rpcpassword=$DAEMON_PASS -rpcport=$DAEMON_RPC_PORT stop
fi
}

litecoin_start () {

if [ "$DAEMON_ENABLED" = "no" ]; then
echo "DAEMON_ENABLED = no, not starting litecoin"
exit 1
fi
echo "Starting litecoin"
$DAEMON_FILE -daemon -debuglogfile=$LOG_FILE -datadir=$BLOCKCHAIN_DIR -debug=1 -shrinkdebugfile -rpcallowip=0.0.0.0/0 -rpcbind=0.0.0.0 -rpcuser=$DAEMON_USER -rpcpassword=$DAEMON_PASS -rpcport=$DAEMON_RPC_PORT -server
}

litecoin_restart () {
litecoin_stop
sleep 6
litecoin_start
}

if [ "$CMD" = "logs" ]; then

tail -n"$LOG_ROWS" "$LOG_FILE"

elif [ "$CMD" = "status" ]; then

PIDOF=$(ps aux | egrep litecoind.-daemon | egrep -v grep | awk '{print $2}')

if [ -n "$PIDOF" ]; then
echo "Litecoin running (PIDOF = $PIDOF)"
exit 5
else
exit 4
fi

elif [ "$CMD" = "stop" ]; then

litecoin_stop
exit 0

elif [ "$CMD" = "start" ]; then

litecoin_start
exit 0

elif [ "$CMD" = "restart" ]; then

litecoin_restart
exit 0

elif [ "$CMD" = "version" ]; then

$DAEMON_FILE -version

else
exit 9
fi

Binary file added icryptonode/public/img/bitcoin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icryptonode/public/img/litecoin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions icryptonode/system_commands/update_daemon
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/bin/sh
#!/bin/bash

# Cleans out old folder, extracts the new daemon, ensures perms are correct
sudo rm -rf /etc/icryptonode/daemon/*

# Pass in path to compressed daemon
tar -xjf $1 -C /etc/icryptonode/daemon/
if [[ $1 = *.tar.bz2 ]]; then
tar -xjf $1 -C /etc/icryptonode/daemon/

elif [[ $1 = *.tar.gz ]]; then
tar -xzf $1 -C /etc/icryptonode/daemon/

fi

sudo chown -R www-data:www-data /etc/icryptonode/daemon/*
Loading

0 comments on commit ccee801

Please sign in to comment.