Skip to content

Commit

Permalink
Merge branch 'stan/68-update-docs' of https://github.com/gonative-cc/…
Browse files Browse the repository at this point in the history
…relayer into stan/68-update-docs
  • Loading branch information
sczembor committed Dec 23, 2024
2 parents 5051093 + 42cae18 commit e018ff8
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 132 deletions.
67 changes: 0 additions & 67 deletions contrib/MockBTCD.md

This file was deleted.

60 changes: 0 additions & 60 deletions contrib/MockBitcoind.md

This file was deleted.

138 changes: 138 additions & 0 deletions contrib/bitcoin-mock.md
Original file line number Diff line number Diff line change
@@ -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 <args>
```

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 <number-block>
```

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=<address>
```

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
```
13 changes: 8 additions & 5 deletions contrib/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit e018ff8

Please sign in to comment.