Add litecoin blockbook implementation
This commit is contained in:
parent
4d874eae95
commit
914a8140a9
@ -7,6 +7,7 @@ import (
|
||||
"blockbook/bchain/coins/btg"
|
||||
"blockbook/bchain/coins/dash"
|
||||
"blockbook/bchain/coins/eth"
|
||||
"blockbook/bchain/coins/litecoin"
|
||||
"blockbook/bchain/coins/zec"
|
||||
"blockbook/common"
|
||||
"context"
|
||||
@ -35,6 +36,8 @@ func init() {
|
||||
blockChainFactories["Bgold"] = btg.NewBGoldRPC
|
||||
blockChainFactories["Dash"] = dash.NewDashRPC
|
||||
blockChainFactories["Dash Testnet"] = dash.NewDashRPC
|
||||
blockChainFactories["Litecoin"] = litecoin.NewLitecoinRPC
|
||||
blockChainFactories["Litecoin Testnet"] = litecoin.NewLitecoinRPC
|
||||
}
|
||||
|
||||
// GetCoinNameFromConfig gets coin name from config file
|
||||
|
||||
66
bchain/coins/litecoin/litecoinparser.go
Normal file
66
bchain/coins/litecoin/litecoinparser.go
Normal file
@ -0,0 +1,66 @@
|
||||
package litecoin
|
||||
|
||||
import (
|
||||
"blockbook/bchain/coins/btc"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
)
|
||||
|
||||
const (
|
||||
MainnetMagic wire.BitcoinNet = 0xdbb6c0fb
|
||||
TestnetMagic wire.BitcoinNet = 0xf1c8d2fd
|
||||
RegtestMagic wire.BitcoinNet = 0xdab5bffa
|
||||
)
|
||||
|
||||
var (
|
||||
MainNetParams chaincfg.Params
|
||||
TestNetParams chaincfg.Params
|
||||
RegtestParams chaincfg.Params
|
||||
)
|
||||
|
||||
func init() {
|
||||
MainNetParams = chaincfg.MainNetParams
|
||||
MainNetParams.Net = MainnetMagic
|
||||
MainNetParams.PubKeyHashAddrID = 48
|
||||
MainNetParams.ScriptHashAddrID = 5
|
||||
MainNetParams.Bech32HRPSegwit = "ltc"
|
||||
|
||||
TestNetParams = chaincfg.TestNet3Params
|
||||
TestNetParams.Net = TestnetMagic
|
||||
TestNetParams.PubKeyHashAddrID = 111
|
||||
TestNetParams.ScriptHashAddrID = 196
|
||||
TestNetParams.Bech32HRPSegwit = "tltc"
|
||||
|
||||
err := chaincfg.Register(&MainNetParams)
|
||||
if err == nil {
|
||||
err = chaincfg.Register(&TestNetParams)
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// LitecoinParser handle
|
||||
type LitecoinParser struct {
|
||||
*btc.BitcoinParser
|
||||
}
|
||||
|
||||
// NewLitecoinParser returns new LitecoinParser instance
|
||||
func NewLitecoinParser(params *chaincfg.Params, c *btc.Configuration) *LitecoinParser {
|
||||
return &LitecoinParser{BitcoinParser: btc.NewBitcoinParser(params, c)}
|
||||
}
|
||||
|
||||
// GetChainParams contains network parameters for the main Litecoin network,
|
||||
// the regression test Litecoin network, the test Litecoin network and
|
||||
// the simulation test Litecoin network, in this order
|
||||
func GetChainParams(chain string) *chaincfg.Params {
|
||||
switch chain {
|
||||
case "test":
|
||||
return &TestNetParams
|
||||
case "regtest":
|
||||
return &RegtestParams
|
||||
default:
|
||||
return &MainNetParams
|
||||
}
|
||||
}
|
||||
56
bchain/coins/litecoin/litecoinrpc.go
Normal file
56
bchain/coins/litecoin/litecoinrpc.go
Normal file
@ -0,0 +1,56 @@
|
||||
package litecoin
|
||||
|
||||
import (
|
||||
"blockbook/bchain"
|
||||
"blockbook/bchain/coins/btc"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// LitecoinRPC is an interface to JSON-RPC bitcoind service.
|
||||
type LitecoinRPC struct {
|
||||
*btc.BitcoinRPC
|
||||
}
|
||||
|
||||
// NewLitecoinRPC returns new LitecoinRPC instance.
|
||||
func NewLitecoinRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
|
||||
b, err := btc.NewBitcoinRPC(config, pushHandler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s := &LitecoinRPC{
|
||||
b.(*btc.BitcoinRPC),
|
||||
}
|
||||
s.RPCMarshaler = btc.JSONMarshalerV2{}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Initialize initializes LitecoinRPC instance.
|
||||
func (b *LitecoinRPC) Initialize() error {
|
||||
chainName, err := b.GetChainInfoAndInitializeMempool(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
glog.Info("Chain name ", chainName)
|
||||
params := GetChainParams(chainName)
|
||||
|
||||
// always create parser
|
||||
b.Parser = NewLitecoinParser(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
|
||||
}
|
||||
1
build/deb/debian/blockbook-litecoin-testnet.conffiles
Normal file
1
build/deb/debian/blockbook-litecoin-testnet.conffiles
Normal file
@ -0,0 +1 @@
|
||||
/opt/coins/blockbook/litecoin_testnet/config/blockchaincfg.json
|
||||
2
build/deb/debian/blockbook-litecoin-testnet.cron.daily
Normal file
2
build/deb/debian/blockbook-litecoin-testnet.cron.daily
Normal file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
/opt/coins/blockbook/litecoin_testnet/bin/logrotate.sh
|
||||
2
build/deb/debian/blockbook-litecoin-testnet.dirs
Normal file
2
build/deb/debian/blockbook-litecoin-testnet.dirs
Normal file
@ -0,0 +1,2 @@
|
||||
/opt/coins/data/litecoin_testnet/blockbook
|
||||
/opt/coins/blockbook/litecoin_testnet/logs
|
||||
6
build/deb/debian/blockbook-litecoin-testnet.install
Executable file
6
build/deb/debian/blockbook-litecoin-testnet.install
Executable file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/dh-exec
|
||||
blockbook /opt/coins/blockbook/litecoin_testnet/bin
|
||||
cert /opt/coins/blockbook/litecoin_testnet
|
||||
static /opt/coins/blockbook/litecoin_testnet
|
||||
configs/litecoin_testnet.json => /opt/coins/blockbook/litecoin_testnet/config/blockchaincfg.json
|
||||
logrotate.sh /opt/coins/blockbook/litecoin_testnet/bin
|
||||
2
build/deb/debian/blockbook-litecoin-testnet.links
Normal file
2
build/deb/debian/blockbook-litecoin-testnet.links
Normal file
@ -0,0 +1,2 @@
|
||||
/opt/coins/blockbook/litecoin_testnet/cert/testcert.crt /opt/coins/blockbook/litecoin_testnet/cert/blockbook.crt
|
||||
/opt/coins/blockbook/litecoin_testnet/cert/testcert.key /opt/coins/blockbook/litecoin_testnet/cert/blockbook.key
|
||||
23
build/deb/debian/blockbook-litecoin-testnet.postinst
Normal file
23
build/deb/debian/blockbook-litecoin-testnet.postinst
Normal file
@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
case "$1" in
|
||||
|
||||
configure)
|
||||
if ! id -u blockbook-litecoin &> /dev/null
|
||||
then
|
||||
useradd --system -M -U blockbook-litecoin -s /bin/false
|
||||
fi
|
||||
|
||||
for dir in /opt/coins/data/litecoin_testnet/blockbook /opt/coins/blockbook/litecoin_testnet/logs
|
||||
do
|
||||
if [ "$(stat -c '%U' $dir)" != "blockbook-litecoin" ]
|
||||
then
|
||||
chown -R blockbook-litecoin:blockbook-litecoin $dir
|
||||
fi
|
||||
done
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
#DEBHELPER#
|
||||
43
build/deb/debian/blockbook-litecoin-testnet.service
Normal file
43
build/deb/debian/blockbook-litecoin-testnet.service
Normal 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-litecoin-testnet.service
|
||||
# See "man systemd.service" for details.
|
||||
|
||||
[Unit]
|
||||
Description=Blockbook daemon (Litecoin testnet)
|
||||
After=network.target
|
||||
Wants=backend-litecoin-testnet.service
|
||||
|
||||
[Service]
|
||||
ExecStart=/opt/coins/blockbook/litecoin_testnet/bin/blockbook -blockchaincfg=/opt/coins/blockbook/litecoin_testnet/config/blockchaincfg.json -datadir=/opt/coins/data/litecoin_testnet/blockbook/db -sync -httpserver=:19033 -socketio=:19133 -certfile=/opt/coins/blockbook/litecoin_testnet/cert/blockbook -explorer=https://ltc-explorer.trezor.io/ -log_dir=/opt/coins/blockbook/litecoin_testnet/logs
|
||||
User=blockbook-litecoin
|
||||
Type=simple
|
||||
Restart=on-failure
|
||||
WorkingDirectory=/opt/coins/blockbook/litecoin_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
|
||||
1
build/deb/debian/blockbook-litecoin.conffiles
Normal file
1
build/deb/debian/blockbook-litecoin.conffiles
Normal file
@ -0,0 +1 @@
|
||||
/opt/coins/blockbook/litecoin/config/blockchaincfg.json
|
||||
2
build/deb/debian/blockbook-litecoin.cron.daily
Normal file
2
build/deb/debian/blockbook-litecoin.cron.daily
Normal file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
/opt/coins/blockbook/litecoin/bin/logrotate.sh
|
||||
2
build/deb/debian/blockbook-litecoin.dirs
Normal file
2
build/deb/debian/blockbook-litecoin.dirs
Normal file
@ -0,0 +1,2 @@
|
||||
/opt/coins/data/litecoin/blockbook
|
||||
/opt/coins/blockbook/litecoin/logs
|
||||
6
build/deb/debian/blockbook-litecoin.install
Executable file
6
build/deb/debian/blockbook-litecoin.install
Executable file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/dh-exec
|
||||
blockbook /opt/coins/blockbook/litecoin/bin
|
||||
cert /opt/coins/blockbook/litecoin
|
||||
static /opt/coins/blockbook/litecoin
|
||||
configs/litecoin.json => /opt/coins/blockbook/litecoin/config/blockchaincfg.json
|
||||
logrotate.sh /opt/coins/blockbook/litecoin/bin
|
||||
2
build/deb/debian/blockbook-litecoin.links
Normal file
2
build/deb/debian/blockbook-litecoin.links
Normal file
@ -0,0 +1,2 @@
|
||||
/opt/coins/blockbook/litecoin/cert/testcert.crt /opt/coins/blockbook/litecoin/cert/blockbook.crt
|
||||
/opt/coins/blockbook/litecoin/cert/testcert.key /opt/coins/blockbook/litecoin/cert/blockbook.key
|
||||
23
build/deb/debian/blockbook-litecoin.postinst
Normal file
23
build/deb/debian/blockbook-litecoin.postinst
Normal file
@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
case "$1" in
|
||||
|
||||
configure)
|
||||
if ! id -u blockbook-litecoin &> /dev/null
|
||||
then
|
||||
useradd --system -M -U blockbook-litecoin -s /bin/false
|
||||
fi
|
||||
|
||||
for dir in /opt/coins/data/litecoin/blockbook /opt/coins/blockbook/litecoin/logs
|
||||
do
|
||||
if [ "$(stat -c '%U' $dir)" != "blockbook-litecoin" ]
|
||||
then
|
||||
chown -R blockbook-litecoin:blockbook-litecoin $dir
|
||||
fi
|
||||
done
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
#DEBHELPER#
|
||||
43
build/deb/debian/blockbook-litecoin.service
Normal file
43
build/deb/debian/blockbook-litecoin.service
Normal 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-litecoin.service
|
||||
# See "man systemd.service" for details.
|
||||
|
||||
[Unit]
|
||||
Description=Blockbook daemon (Litecoin mainnet)
|
||||
After=network.target
|
||||
Wants=backend-litecoin.service
|
||||
|
||||
[Service]
|
||||
ExecStart=/opt/coins/blockbook/litecoin/bin/blockbook -blockchaincfg=/opt/coins/blockbook/litecoin/config/blockchaincfg.json -datadir=/opt/coins/data/litecoin/blockbook/db -sync -httpserver=:9033 -socketio=:9133 -certfile=/opt/coins/blockbook/litecoin/cert/blockbook -explorer=https://ltc-explorer.trezor.io/ -log_dir=/opt/coins/blockbook/litecoin/logs
|
||||
User=blockbook-litecoin
|
||||
Type=simple
|
||||
Restart=on-failure
|
||||
WorkingDirectory=/opt/coins/blockbook/litecoin
|
||||
|
||||
# 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
|
||||
@ -54,3 +54,13 @@ Package: blockbook-dash-testnet
|
||||
Architecture: amd64
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, backend-dash-testnet
|
||||
Description: Satoshilabs blockbook server (Dash testnet)
|
||||
|
||||
Package: blockbook-litecoin
|
||||
Architecture: amd64
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, backend-litecoin
|
||||
Description: Satoshilabs blockbook server (Litecoin mainnet)
|
||||
|
||||
Package: blockbook-litecoin-testnet
|
||||
Architecture: amd64
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, backend-litecoin-testnet
|
||||
Description: Satoshilabs blockbook server (Litecoin testnet)
|
||||
|
||||
12
configs/litecoin.json
Normal file
12
configs/litecoin.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"coin_name": "Litecoin",
|
||||
"rpcURL": "http://localhost:8034",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
"rpcTimeout": 25,
|
||||
"parse": true,
|
||||
"zeroMQBinding": "tcp://localhost:38334",
|
||||
"mempoolWorkers": 8,
|
||||
"mempoolSubWorkers": 2,
|
||||
"blockAddressesToKeep": 300
|
||||
}
|
||||
12
configs/litecoin_testnet.json
Normal file
12
configs/litecoin_testnet.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"coin_name": "Litecoin Testnet",
|
||||
"rpcURL": "http://localhost:18034",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
"rpcTimeout": 25,
|
||||
"parse": true,
|
||||
"zeroMQBinding": "tcp://localhost:48334",
|
||||
"mempoolWorkers": 8,
|
||||
"mempoolSubWorkers": 2,
|
||||
"blockAddressesToKeep": 300
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user