From 51d10bccd207e61eb0ed32702635b6f3f8ea33de Mon Sep 17 00:00:00 2001 From: vdovhanych Date: Mon, 26 Jul 2021 11:43:50 +0200 Subject: [PATCH] feat: add bitcoin regtest support --- bchain/coins/blockchain.go | 1 + .../backend/config/bitcoin_regtest.conf | 36 ++++++++++ configs/coins/bitcoin_regtest.json | 69 +++++++++++++++++++ docs/ports.md | 1 + 4 files changed, 107 insertions(+) create mode 100644 build/templates/backend/config/bitcoin_regtest.conf create mode 100644 configs/coins/bitcoin_regtest.json diff --git a/bchain/coins/blockchain.go b/bchain/coins/blockchain.go index 38cae788..824d3c63 100644 --- a/bchain/coins/blockchain.go +++ b/bchain/coins/blockchain.go @@ -63,6 +63,7 @@ func init() { BlockChainFactories["Bitcoin"] = btc.NewBitcoinRPC BlockChainFactories["Testnet"] = btc.NewBitcoinRPC BlockChainFactories["Signet"] = btc.NewBitcoinRPC + BlockChainFactories["Regtest"] = btc.NewBitcoinRPC BlockChainFactories["Zcash"] = zec.NewZCashRPC BlockChainFactories["Zcash Testnet"] = zec.NewZCashRPC BlockChainFactories["Ethereum"] = eth.NewEthereumRPC diff --git a/build/templates/backend/config/bitcoin_regtest.conf b/build/templates/backend/config/bitcoin_regtest.conf new file mode 100644 index 00000000..0fb7aef2 --- /dev/null +++ b/build/templates/backend/config/bitcoin_regtest.conf @@ -0,0 +1,36 @@ +{{define "main" -}} +daemon=0 +server=1 +nolisten=1 +txindex=1 +disablewallet=0 + +zmqpubhashtx={{template "IPC.MessageQueueBindingTemplate" .}} +zmqpubhashblock={{template "IPC.MessageQueueBindingTemplate" .}} + +rpcworkqueue=1100 +maxmempool=2000 +dbcache=1000 + +{{- if .Backend.AdditionalParams}} +# generated from additional_params +{{- range $name, $value := .Backend.AdditionalParams}} +{{- if eq $name "addnode"}} +{{- range $index, $node := $value}} +addnode={{$node}} +{{- end}} +{{- else}} +{{$name}}={{$value}} +{{- end}} +{{- end}} +{{- end}} + +regtest=1 + +{{if .Backend.Mainnet}}[main]{{else}}[regtest]{{end}} +rpcallowip=0.0.0.0/0 +rpcbind=0.0.0.0 +{{generateRPCAuth .IPC.RPCUser .IPC.RPCPass -}} +rpcport={{.Ports.BackendRPC}} + +{{end}} diff --git a/configs/coins/bitcoin_regtest.json b/configs/coins/bitcoin_regtest.json new file mode 100644 index 00000000..bde735f1 --- /dev/null +++ b/configs/coins/bitcoin_regtest.json @@ -0,0 +1,69 @@ +{ + "coin": { + "name": "Regtest", + "shortcut": "rBTC", + "label": "Bitcoin Regtest", + "alias": "bitcoin_regtest" + }, + "ports": { + "backend_rpc": 18021, + "backend_message_queue": 48321, + "blockbook_internal": 19021, + "blockbook_public": 19121 + }, + "ipc": { + "rpc_url_template": "http://127.0.0.1:{{.Ports.BackendRPC}}", + "rpc_user": "rpc", + "rpc_pass": "rpc", + "rpc_timeout": 25, + "message_queue_binding_template": "tcp://127.0.0.1:{{.Ports.BackendMessageQueue}}" + }, + "backend": { + "package_name": "backend-bitcoin-regtest", + "package_revision": "satoshilabs-1", + "system_user": "bitcoin", + "version": "0.21.1", + "binary_url": "https://bitcoincore.org/bin/bitcoin-core-0.21.1/bitcoin-0.21.1-x86_64-linux-gnu.tar.gz", + "verification_type": "gpg-sha256", + "verification_source": "https://bitcoincore.org/bin/bitcoin-core-0.21.1/SHA256SUMS.asc", + "extract_command": "tar -C backend --strip 1 -xf", + "exclude_files": [ + "bin/bitcoin-qt" + ], + "exec_command_template": "{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/bin/bitcoind -datadir={{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend -conf={{.Env.BackendInstallPath}}/{{.Coin.Alias}}/{{.Coin.Alias}}.conf -pid=/run/{{.Coin.Alias}}/{{.Coin.Alias}}.pid", + "logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/regtest3/*.log", + "postinst_script_template": "", + "service_type": "forking", + "service_additional_params_template": "", + "mainnet": false, + "protect_memory": true, + "server_config_file": "bitcoin_regtest.conf", + "client_config_file": "bitcoin_client.conf", + "additional_params": { + "deprecatedrpc": "estimatefee" + } + }, + "blockbook": { + "package_name": "blockbook-bitcoin-regtest", + "system_user": "blockbook-bitcoin", + "internal_binding_template": ":{{.Ports.BlockbookInternal}}", + "public_binding_template": ":{{.Ports.BlockbookPublic}}", + "explorer_url": "", + "additional_params": "", + "block_chain": { + "parse": true, + "mempool_workers": 8, + "mempool_sub_workers": 2, + "block_addresses_to_keep": 300, + "xpub_magic": 70617039, + "xpub_magic_segwit_p2sh": 71979618, + "xpub_magic_segwit_native": 73342198, + "slip44": 1, + "additional_params": {} + } + }, + "meta": { + "package_maintainer": "IT", + "package_maintainer_email": "it@satoshilabs.com" + } +} diff --git a/docs/ports.md b/docs/ports.md index d38a9f03..ce6a0453 100644 --- a/docs/ports.md +++ b/docs/ports.md @@ -46,6 +46,7 @@ | BitZeny | 9095 | 9195 | 8095 | 38395 | | Trezarcoin | 9096 | 9196 | 8096 | 38396 | | Bitcoin Signet | 19020 | 19120 | 18020 | 48320 | +| Bitcoin Regtest | 19021 | 19121 | 18021 | 48321 | | Ethereum Goerli | 19026 | 19126 | 18026 | 48326 p2p | | Bitcoin Testnet | 19030 | 19130 | 18030 | 48330 | | Bitcoin Cash Testnet | 19031 | 19131 | 18031 | 48331 |