Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instructions for creating a wallet and corresponding config entries #34

Merged
merged 2 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 65 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,84 @@ To do that we use the btcd `gencerts` utility,
gencerts -d $TESTNET_PATH/bitcoin/ -H host.docker.internal
```

Then, launch a simnet Bitcoin node,
which listens for RPC connections at port `18554` and
stores the RPC certificate under the above directory.
The mining address is an arbitrary address.
#### Running a Bitcoin simnet with an arbitrary mining address

Launch a simnet Bitcoin node
which listens for RPC connections at port `18556` and
stores the RPC certificate under the `$TESTNET_PATH/bitcoin` directory.
The mining address is arbitrary.

```shell
btcd --simnet --rpclisten 127.0.0.1:18554 --rpcuser rpcuser --rpcpass rpcpass \
btcd --simnet --rpclisten 127.0.0.1:18556 --rpcuser rpcuser --rpcpass rpcpass \
--rpccert $TESTNET_PATH/bitcoin/rpc.cert --rpckey $TESTNET_PATH/bitcoin/rpc.key \
--miningaddr SQqHYFTSPh8WAyJvzbAC8hoLbF12UVsE5s
```

#### Running a Bitcoin simnet with a wallet

Launch a simnet Bitcoin node
which listens for RPC connections at port `18556` and
stores the RPC certificate under the `$TESTNET_PATH/bitcoin` directory.

```shell
btcd --simnet --rpclisten 127.0.0.1:18556 --rpcuser rpcuser --rpcpass rpcpass \
--rpccert $TESTNET_PATH/bitcoin/rpc.cert --rpckey $TESTNET_PATH/bitcoin/rpc.key
```

Leave this process running.

Then, create a simnet Bitcoin wallet.
If you want to use the default vigilante file, then give the password `walletpass`.
Otherwise, make sure to edit the `vigilante.yaml` to reflect the correct password.
```shell
btcwallet --simnet -u rpcuser -P rpcpass \
--rpccert $TESTNET_PATH/bitcoin/rpc-wallet.cert --rpckey $TESTNET_PATH/bitcoin/rpc-wallet.key \
--cafile $TESTNET_PATH/bitcoin/rpc.cert \
--create
```

The above instruction is going to prompt you for a password and going to give you the seed.
Store those securely.

Afterwards, start the wallet service listening to port `18554`:
```shell
btcwallet --simnet -u rpcuser -P rpcpass --rpclisten=127.0.0.1:18554 \
--rpccert $TESTNET_PATH/bitcoin/rpc-wallet.cert --rpckey $TESTNET_PATH/bitcoin/rpc-wallet.key \
--cafile $TESTNET_PATH/bitcoin/rpc.cert
```
Leave this process running. If you get an error that a wallet already exists and you still want
to create one, delete the `wallet.db` file located in the path displayed by the error message.

Create an address that will be later used for mining. The output below is a sample one.
```shell
$ btcctl --simnet --wallet -u rpcuser -P rpcpass \
--rpccert $TESTNET_PATH/bitcoin/rpc-wallet.cert \
--rpcserver 127.0.0.1 getnewaddress

SQqHYFTSPh8WAyJvzbAC8hoLbF12UVsE5s
```

Finally, restart the btcd service with the new address.
First, kill the `btcd` process that you started in the first step, and then:
```sh
btcd --simnet --rpclisten 127.0.0.1:18556 --rpcuser rpcuser --rpcpass rpcpass \
--rpccert $TESTNET_PATH/bitcoin/rpc.cert --rpckey $TESTNET_PATH/bitcoin/rpc.key \
--miningaddr $MINING_ADDRESS
```
where `$MINING_ADDRESS` is the address that you got as an output in the previous command.


#### Generating BTC blocks

While running this setup, one might want to generate BTC blocks.
We accomplish that through the btcd `btcctl` utility and the use
of the parameters we defined above.
```shell
btcctl --simnet --wallet --skipverify \
--rpcuser=rpcuser --rpcpass=rpcpass --rpccert=$TESTNET_PATH/bitcoin/rpc.cert \
generate 1
btcctl --simnet --wallet --rpcuser=rpcuser --rpcpass=rpcpass \
--rpccert=$TESTNET_PATH/bitcoin/rpc-wallet.cert \
generate $NUM_BLOCKS
```
where `$NUM_BLOCKS` is the number of blocks you want to generate.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add a note that to spend the first coinbase tx, we need $NUM_BLOCKS to be more than 100? See here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!


### Vigilante configuration

Expand Down
10 changes: 9 additions & 1 deletion config/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ type BTCConfig struct {
DisableClientTLS bool `mapstructure:"no-client-tls"`
CAFile string `mapstructure:"ca-file"`
Endpoint string `mapstructure:"endpoint"`
WalletEndpoint string `mapstructure:"wallet-endpoint"`
WalletPassword string `mapstructure:"wallet-password"`
WalletName string `mapstructure:"wallet-name"`
WalletCAFile string `mapstructure:"wallet-ca-file"`
NetParams string `mapstructure:"net-params"`
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
Expand All @@ -24,7 +28,11 @@ func DefaultBTCConfig() BTCConfig {
return BTCConfig{
DisableClientTLS: false,
CAFile: defaultBtcCAFile,
Endpoint: "localhost:18554",
Endpoint: "localhost:18556",
WalletEndpoint: "localhost:18554",
WalletPassword: "walletpass",
WalletName: "default",
WalletCAFile: defaultBtcWalletCAFile,
NetParams: "simnet",
Username: "user",
Password: "pass",
Expand Down
13 changes: 7 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ const (
)

var (
defaultBtcCAFile = filepath.Join(btcutil.AppDataDir("btcd", false), "rpc.cert")
defaultAppDataDir = btcutil.AppDataDir("babylon-vigilante", false)
defaultConfigFile = filepath.Join(defaultAppDataDir, defaultConfigFilename)
defaultRPCKeyFile = filepath.Join(defaultAppDataDir, "rpc.key")
defaultRPCCertFile = filepath.Join(defaultAppDataDir, "rpc.cert")
defaultLogDir = filepath.Join(defaultAppDataDir, defaultLogDirname)
defaultBtcCAFile = filepath.Join(btcutil.AppDataDir("btcd", false), "rpc.cert")
defaultBtcWalletCAFile = filepath.Join(btcutil.AppDataDir("btcwallet", false), "rpc.cert")
defaultAppDataDir = btcutil.AppDataDir("babylon-vigilante", false)
defaultConfigFile = filepath.Join(defaultAppDataDir, defaultConfigFilename)
defaultRPCKeyFile = filepath.Join(defaultAppDataDir, "rpc.key")
defaultRPCCertFile = filepath.Join(defaultAppDataDir, "rpc.cert")
defaultLogDir = filepath.Join(defaultAppDataDir, defaultLogDirname)
)

// Config defines the server's top level configuration
Expand Down
6 changes: 5 additions & 1 deletion sample-vigilante.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ base:
btc:
no-client-tls: false
ca-file: $TESTNET_PATH/bitcoin/rpc.cert
endpoint: localhost:18554
endpoint: localhost:18556
wallet-endpoint: localhost:18554
wallet-password: walletpass
wallet-name: default
wallet-ca-file: $TESTNET_PATH/bitcoin/rpc-wallet.cert
net-params: simnet
username: rpcuser
password: rpcpass
Expand Down