Added support for DASH

pull/7/head
Jakub Matys 2018-06-08 15:23:28 +02:00
parent 09b1dd1dd2
commit 19e394b05a
20 changed files with 329 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"blockbook/bchain/coins/bch"
"blockbook/bchain/coins/btc"
"blockbook/bchain/coins/btg"
"blockbook/bchain/coins/dash"
"blockbook/bchain/coins/eth"
"blockbook/bchain/coins/zec"
"blockbook/common"
@ -32,6 +33,8 @@ func init() {
blockChainFactories["Bcash"] = bch.NewBCashRPC
blockChainFactories["Bcash Testnet"] = bch.NewBCashRPC
blockChainFactories["Bgold"] = btg.NewBGoldRPC
blockChainFactories["Dash"] = dash.NewDashRPC
blockChainFactories["Dash Testnet"] = dash.NewDashRPC
}
// GetCoinNameFromConfig gets coin name from config file

View File

@ -0,0 +1,78 @@
package dash
import (
"blockbook/bchain/coins/btc"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/wire"
)
const (
MainnetMagic wire.BitcoinNet = 0xbd6b0cbf
TestnetMagic wire.BitcoinNet = 0xffcae2ce
RegtestMagic wire.BitcoinNet = 0xdcb7c1fc
)
var (
MainNetParams chaincfg.Params
TestNetParams chaincfg.Params
RegtestParams chaincfg.Params
)
func init() {
MainNetParams = chaincfg.MainNetParams
MainNetParams.Net = MainnetMagic
// Address encoding magics
MainNetParams.PubKeyHashAddrID = 76 // base58 prefix: X
MainNetParams.ScriptHashAddrID = 16 // base58 prefix: 7
TestNetParams = chaincfg.TestNet3Params
TestNetParams.Net = TestnetMagic
// Address encoding magics
TestNetParams.PubKeyHashAddrID = 140 // base58 prefix: y
TestNetParams.ScriptHashAddrID = 19 // base58 prefix: 8 or 9
RegtestParams = chaincfg.RegressionNetParams
RegtestParams.Net = RegtestMagic
// Address encoding magics
RegtestParams.PubKeyHashAddrID = 140 // base58 prefix: y
RegtestParams.ScriptHashAddrID = 19 // base58 prefix: 8 or 9
err := chaincfg.Register(&MainNetParams)
if err == nil {
err = chaincfg.Register(&TestNetParams)
}
if err == nil {
err = chaincfg.Register(&RegtestParams)
}
if err != nil {
panic(err)
}
}
// DashParser handle
type DashParser struct {
*btc.BitcoinParser
}
// NewDashParser returns new DashParser instance
func NewDashParser(params *chaincfg.Params, c *btc.Configuration) *DashParser {
return &DashParser{BitcoinParser: btc.NewBitcoinParser(params, c)}
}
// GetChainParams contains network parameters for the main Dash network,
// the regression test Dash network, the test Dash network and
// the simulation test Dash network, in this order
func GetChainParams(chain string) *chaincfg.Params {
switch chain {
case "test":
return &TestNetParams
case "regtest":
return &RegtestParams
default:
return &MainNetParams
}
}

View File

@ -0,0 +1,54 @@
package dash
import (
"blockbook/bchain"
"blockbook/bchain/coins/btc"
"encoding/json"
"github.com/golang/glog"
)
// DashRPC is an interface to JSON-RPC bitcoind service.
type DashRPC struct {
*btc.BitcoinRPC
}
// NewDashRPC returns new DashRPC instance.
func NewDashRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
b, err := btc.NewBitcoinRPC(config, pushHandler)
if err != nil {
return nil, err
}
s := &DashRPC{
b.(*btc.BitcoinRPC),
}
return s, nil
}
// Initialize initializes DashRPC instance.
func (b *DashRPC) Initialize() error {
chainName, err := b.GetChainInfoAndInitializeMempool(b)
if err != nil {
return err
}
params := GetChainParams(chainName)
// always create parser
b.Parser = NewDashParser(params, b.ChainConfig)
// parameters for getInfo request
if params.Net == MainnetMagic {
b.Testnet = false
b.Network = "livenet"
} else {
b.Testnet = true
b.Network = "testnet"
}
glog.Info("rpc: block chain ", params.Name)
return nil
}

View File

@ -0,0 +1 @@
/opt/coins/blockbook/dash_testnet/config/blockchaincfg.json

View File

@ -0,0 +1,2 @@
#!/bin/sh
/opt/coins/blockbook/dash_testnet/bin/logrotate.sh

View File

@ -0,0 +1,2 @@
/opt/coins/data/dash_testnet/blockbook
/opt/coins/blockbook/dash_testnet/logs

View File

@ -0,0 +1,6 @@
#!/usr/bin/dh-exec
blockbook /opt/coins/blockbook/dash_testnet/bin
cert /opt/coins/blockbook/dash_testnet
static /opt/coins/blockbook/dash_testnet
configs/dash_testnet.json => /opt/coins/blockbook/dash_testnet/config/blockchaincfg.json
logrotate.sh /opt/coins/blockbook/dash_testnet/bin

View File

@ -0,0 +1,2 @@
/opt/coins/blockbook/dash_testnet/cert/testcert.crt /opt/coins/blockbook/dash_testnet/cert/blockbook.crt
/opt/coins/blockbook/dash_testnet/cert/testcert.key /opt/coins/blockbook/dash_testnet/cert/blockbook.key

View File

@ -0,0 +1,23 @@
#!/bin/bash
set -e
case "$1" in
configure)
if ! id -u blockbook-dash &> /dev/null
then
useradd --system -M -U blockbook-dash -s /bin/false
fi
for dir in /opt/coins/data/dash_testnet/blockbook /opt/coins/blockbook/dash_testnet/logs
do
if [ "$(stat -c '%U' $dir)" != "blockbook-dash" ]
then
chown -R blockbook-dash:blockbook-dash $dir
fi
done
;;
esac
#DEBHELPER#

View File

@ -0,0 +1,43 @@
# It is not recommended to modify this file in-place, because it will
# be overwritten during package upgrades. If you want to add further
# options or overwrite existing ones then use
# $ systemctl edit blockbook-dash-testnet.service
# See "man systemd.service" for details.
[Unit]
Description=Blockbook daemon (Dash testnet)
After=network.target
Wants=dash-testnet.service
[Service]
ExecStart=/opt/coins/blockbook/dash_testnet/bin/blockbook -blockchaincfg=/opt/coins/blockbook/dash_testnet/config/blockchaincfg.json -datadir=/opt/coins/data/dash_testnet/blockbook/db -sync -httpserver=:19033 -socketio=:19133 -certfile=/opt/coins/blockbook/dash_testnet/cert/blockbook -explorer=https://dash-explorer.trezor.io/ -log_dir=/opt/coins/blockbook/dash_testnet/logs
User=blockbook-dash
Type=simple
Restart=on-failure
WorkingDirectory=/opt/coins/blockbook/dash_testnet
# Resource limits
LimitNOFILE=500000
# Hardening measures
####################
# Provide a private /tmp and /var/tmp.
PrivateTmp=true
# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full
# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true
# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true
# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1 @@
/opt/coins/blockbook/dash/config/blockchaincfg.json

View File

@ -0,0 +1,2 @@
#!/bin/sh
/opt/coins/blockbook/dash/bin/logrotate.sh

View File

@ -0,0 +1,2 @@
/opt/coins/data/dash/blockbook
/opt/coins/blockbook/dash/logs

View File

@ -0,0 +1,6 @@
#!/usr/bin/dh-exec
blockbook /opt/coins/blockbook/dash/bin
cert /opt/coins/blockbook/dash
static /opt/coins/blockbook/dash
configs/dash.json => /opt/coins/blockbook/dash/config/blockchaincfg.json
logrotate.sh /opt/coins/blockbook/dash/bin

View File

@ -0,0 +1,2 @@
/opt/coins/blockbook/dash/cert/testcert.crt /opt/coins/blockbook/dash/cert/blockbook.crt
/opt/coins/blockbook/dash/cert/testcert.key /opt/coins/blockbook/dash/cert/blockbook.key

View File

@ -0,0 +1,23 @@
#!/bin/bash
set -e
case "$1" in
configure)
if ! id -u blockbook-dash &> /dev/null
then
useradd --system -M -U blockbook-dash -s /bin/false
fi
for dir in /opt/coins/data/dash/blockbook /opt/coins/blockbook/dash/logs
do
if [ "$(stat -c '%U' $dir)" != "blockbook-dash" ]
then
chown -R blockbook-dash:blockbook-dash $dir
fi
done
;;
esac
#DEBHELPER#

View File

@ -0,0 +1,43 @@
# It is not recommended to modify this file in-place, because it will
# be overwritten during package upgrades. If you want to add further
# options or overwrite existing ones then use
# $ systemctl edit blockbook-dash.service
# See "man systemd.service" for details.
[Unit]
Description=Blockbook daemon (Dash mainnet)
After=network.target
Wants=dash.service
[Service]
ExecStart=/opt/coins/blockbook/dash/bin/blockbook -blockchaincfg=/opt/coins/blockbook/dash/config/blockchaincfg.json -datadir=/opt/coins/data/dash/blockbook/db -sync -httpserver=:9033 -socketio=:9133 -certfile=/opt/coins/blockbook/dash/cert/blockbook -explorer=https://dash-explorer.trezor.io/ -log_dir=/opt/coins/blockbook/dash/logs
User=blockbook-dash
Type=simple
Restart=on-failure
WorkingDirectory=/opt/coins/blockbook/dash
# Resource limits
LimitNOFILE=500000
# Hardening measures
####################
# Provide a private /tmp and /var/tmp.
PrivateTmp=true
# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full
# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true
# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true
# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true
[Install]
WantedBy=multi-user.target

View File

@ -44,3 +44,13 @@ Package: blockbook-bgold
Architecture: amd64
Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, bgold
Description: Satoshilabs blockbook server (Bitcoin Gold mainnet)
Package: blockbook-dash
Architecture: amd64
Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, dash
Description: Satoshilabs blockbook server (Dash mainnet)
Package: blockbook-dash-testnet
Architecture: amd64
Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, dash-testnet
Description: Satoshilabs blockbook server (Dash testnet)

13
configs/dash.json 100644
View File

@ -0,0 +1,13 @@
{
"coin_name": "Dash",
"rpcURL": "http://127.0.0.1:8033",
"rpcUser": "rpc",
"rpcPass": "rpc",
"rpcTimeout": 25,
"parse": true,
"zeroMQBinding": "tcp://127.0.0.1:38333",
"subversion": "/Dash Core:0.12.2/",
"mempoolWorkers": 8,
"mempoolSubWorkers": 2,
"blockAddressesToKeep": 300
}

View File

@ -0,0 +1,13 @@
{
"coin_name": "Dash Testnet",
"rpcURL": "http://localhost:18033",
"rpcUser": "rpc",
"rpcPass": "rpc",
"rpcTimeout": 25,
"parse": true,
"zeroMQBinding": "tcp://127.0.0.1:48333",
"subversion": "/Dash Core:0.12.2/",
"mempoolWorkers": 8,
"mempoolSubWorkers": 2,
"blockAddressesToKeep": 300
}