diff --git a/contrib/MockBTCD.md b/contrib/MockBTCD.md deleted file mode 100644 index 5909ee2..0000000 --- a/contrib/MockBTCD.md +++ /dev/null @@ -1,67 +0,0 @@ -# Run btcd simnet mode - -## Install btcd and btcwallet - -Follow the instruction in [btcd README.md](https://github.com/btcsuite/btcd?tab=readme-ov-file#installation) -and [btcwallet README](https://github.com/btcsuite/btcwallet?tab=readme-ov-file#installation-and-updating) to install btcd and btcwallet - -## Run btcd with simnet mode - -### Bootstrap the wallet and btc node - -First you need to start the btcd in simnet mode - -```bash -btcd --simnet --rpcuser=user --rpcpass=password -``` - -Create btc wallet. Please remember the password. - -```bash -btcwallet --simnet --create -``` - -Connect you wallet to btcd simmode. The password and user here must be the btcd password/user pair. -Open a new terminal and run: - -```bash -btcwallet --simnet -u=user -P=password -``` - -Create a new address. We will use it as the `--miningaddr` parameter - an address that receives btc when mining a new block. -Open a new terminal and run: - -```bash -btcctl --simnet --wallet --rpcuser=user --rpcpass=password getnewaddress -``` - -Copy the address created by the command above. Shutdown the btcd service and run: - -```bash -btcd --simnet --rpcuser=user --rpcpass=password --miningaddr=
-``` - -Right now, everytime we mine a new block, the minner address should receive some bitcoin. -We can use this for testing and development. - -## Generate a new block - -Generate 100 blocks - -```bash -btcctl --simnet --wallet --rpcuser=user --rpcpass=password generate 100 -``` - -## Check information - -Blockchain information - -```bash -btcctl --simnet --wallet --rpcuser=user --rpcpass=password getblockchaininfo -``` - -Miner balance - -```bash -btcctl --simnet --wallet --rpcuser=user --rpcpass=password getbalance -``` diff --git a/contrib/MockBitcoind.md b/contrib/MockBitcoind.md deleted file mode 100644 index 1266d1a..0000000 --- a/contrib/MockBitcoind.md +++ /dev/null @@ -1,60 +0,0 @@ -# Run bitcoind regtest node - -## Requirements - -Make sure you have docker and docker-compose-plugin installed, and the docker service is running. - -- docker-compose version >= 2.30.0. - -## Initialization - -```sh -make bitcoind-init -``` - -Start a new terminal where you will run a container with bitcoind, by default the nativewallet will be loaded: - -```sh -cd contrib; docker compose up -``` - -## Stop bitcoind node - -To stop the node just press `ctrl-c` in the terminal running a node. - -To remove a container: - -```sh -docker compose down -``` - -## Interact with the bitcoind node - -```sh -docker exec -it bitcoind-node bitcoin-cli -regtest -``` - -Or enter bash in the container: - -```sh -docker exec -it bitcoind-node /bin/bash -``` - -Then you can generate a block: - -```sh -bitcoin-cli -regtest generate -``` - -If RPC params are required, you can provide them: - -```sh -bitcoin-cli -regtest -rpcuser=user -rpcpassword=password generate -``` - -More information in [developer.bitcoin.org -> testing](https://developer.bitcoin.org/examples/testing.html). - -## Reference - -- [Running Bitcoind with ZMQ](https://bitcoindev.network/accessing-bitcoins-zeromq-interface/) -- [Bitlights Labs dev env](https://blog.bitlightlabs.com/posts/setup-local-development-env-regtest) diff --git a/contrib/bitcoin-mock.md b/contrib/bitcoin-mock.md new file mode 100644 index 0000000..d8f57b9 --- /dev/null +++ b/contrib/bitcoin-mock.md @@ -0,0 +1,138 @@ +# Run bitcoind regtest node + +## Requirements + +- Docker Engine >= 27.0 +- docker-compose-plugin (don't use the legacy python docker-compose) +- docker service running; [install instructions](https://docs.docker.com/engine/install/). + +There are two leading Bitcoin implementation, each comes with a mode to run simulations that helps to use it +as a mock, with predefined snapshot and data: + +- [Bitcoind](https://github.com/bitcoin/bitcoin) with the `-regtest` mode +- [Btcd](https://github.com/btcsuite/btcd) with the `-simtest` mode + +## Bitcoind + +Bitcoind is a binary from the reference implementation + +### Setting up + +Firstly we need to copy the snapshot (to have a shared data): + +```sh +make bitcoind-init +``` + +Start a new terminal where you will run a container with bitcoind, by default the nativewallet will be loaded: + +```sh +cd contrib; docker compose up +``` + +To stop the node just press `ctrl-c` in the terminal running a node. + +To remove a container: + +```sh +docker compose down +``` + +### Interact with the bitcoind node + +```sh +docker exec -it bitcoind-node bitcoin-cli -regtest +``` + +Or enter bash in the container: + +```sh +docker exec -it bitcoind-node /bin/bash +``` + +Then you can generate a block: + +```sh +bitcoin-cli -regtest generate +``` + +If RPC params are required, you can provide them: + +```sh +bitcoin-cli -regtest -rpcuser=user -rpcpassword=password generate +``` + +More information in [developer.bitcoin.org -> testing](https://developer.bitcoin.org/examples/testing.html). + +### Reference + +- [Running Bitcoind with ZMQ](https://bitcoindev.network/accessing-bitcoins-zeromq-interface/) +- [Bitlights Labs dev env](https://blog.bitlightlabs.com/posts/setup-local-development-env-regtest) + +## Btcd + +alternatively to Bitcoind we can use btcd. + +### Install btcd and btcwallet + +Follow the instruction in [btcd README.md](https://github.com/btcsuite/btcd?tab=readme-ov-file#installation) +and [btcwallet README](https://github.com/btcsuite/btcwallet?tab=readme-ov-file#installation-and-updating) to install btcd and btcwallet + +### Bootstrap the wallet and btc node + +First you need to start the btcd in simnet mode + +```bash +btcd --simnet --rpcuser=user --rpcpass=password +``` + +Create btc wallet. Please remember the password. + +```bash +btcwallet --simnet --create +``` + +Connect you wallet to btcd simmode. The password and user here must be the btcd password/user pair. +Open a new terminal and run: + +```bash +btcwallet --simnet -u=user -P=password +``` + +Create a new address. We will use it as the `--miningaddr` parameter - an address that receives btc when mining a new block. +Open a new terminal and run: + +```bash +btcctl --simnet --wallet --rpcuser=user --rpcpass=password getnewaddress +``` + +Copy the address created by the command above. Shutdown the btcd service and run: + +```bash +btcd --simnet --rpcuser=user --rpcpass=password --miningaddr=
+``` + +Right now, everytime we mine a new block, the minner address should receive some bitcoin. +We can use this for testing and development. + +### Generate a new block + +Generate 100 blocks + +```bash +btcctl --simnet --wallet --rpcuser=user --rpcpass=password generate 100 +``` + +## Check information + +Blockchain information + +```bash +btcctl --simnet --wallet --rpcuser=user --rpcpass=password getblockchaininfo +``` + +Miner balance + +```bash +btcctl --simnet --wallet --rpcuser=user --rpcpass=password getbalance +``` diff --git a/contrib/docker-compose.yaml b/contrib/docker-compose.yaml index c435c9c..56a52f9 100644 --- a/contrib/docker-compose.yaml +++ b/contrib/docker-compose.yaml @@ -1,20 +1,23 @@ services: bitcoind: container_name: bitcoind-node - hostname: bitcoind-node + # hostname: bitcoind-node image: kylemanna/bitcoind@sha256:2400e64960457b22be55299a2d7fa2aaa217f3dfc4afb84387e5511fe8ce5055 # restart: unless-stopped volumes: - ./bitcoind-data:/bitcoin/.bitcoin ports: - - 18333:18333 - - 127.0.0.1:18332:18332 - command: - -printtoconsole + # regtest ports + - 127.0.0.1:18443:18443 # json-rpc + - 127.0.0.1:18444:18444 + - 127.0.0.1:18445:18445 + command: -printtoconsole -rpcuser=user -rpcpassword=password -regtest -rest + -rpcbind=0.0.0.0:18443 + -rpcallowip=0.0.0.0/0 post_start: - command: "sleep 0.5" - command: "bitcoin-cli -regtest loadwallet nativewallet"