This crate allows Bitcoin to function as a data availability layer, supporting both write
and read
operations. It's been developed with Rust sequencers in mind, particularly for integration with Madara. It's modeled after rollkit's bitcoin-da.
Before you can proceed with using or testing this crate, there are a few setup steps you need to follow:
-
Installation: Ensure
bitcoind
&bitcoin-cli
are installed. -
Setting up a Bitcoin Daemon:
-
Start a bitcoin daemon with:
bitcoind -conf=path_to/bitcoin.conf
-
If you're setting up for the first time and don't have a wallet yet:
bitcoin-cli createwallet test
-
Mine some blocks (especially useful for regtest):
bitcoin-cli -regtest -generate 150
-
Note: These steps are for both manual and automatic testing. For both cases you will still need to start bitcoind
separately. Additionally, automated tests will only handle some bitcoin-cli
operations such as loadwallet
and setting the test
label for the wallet in use.
git clone git@github.com:KasarLabs/bitcoin-da.git
cd da
cargo build
For more detailed instructions on building Rust projects, refer to the cargo documentation.
Here's a simple example to demonstrate how to use the library:
fn test_write() {
let embedded_data = b"Hello, world!";
let relayer = Relayer::new(&Config::new(
"localhost:8332".to_owned(),
"rpcuser".to_owned(),
"rpcpass".to_owned(),
))
.unwrap();
// get network, should be regtest
let blockchain_info = relayer.client.get_blockchain_info().unwrap();
let network_name = &blockchain_info.chain;
let network = Network::from_core_arg(network_name)
.map_err(|_| BitcoinError::InvalidNetwork)
.unwrap();
match relayer.write(&embedded_data) {
Ok(txid) => {
println!("Txid: {}", txid);
println!("Successful write");
}
Err(e) => panic!("Write failed with error: {:?}", e),
}
}
This repo comes with an automation script (run_tests.sh
) which simplifies the testing process by handling node operations and test configurations. The script assumes a bitcoin node is already running.
- Grant the script execute permissions:
chmod +x run_tests.sh
-
Setup: Ensure a Bitcoin node is running on the desired network (
regtest
orsignet
), and modify the RPC URL in your configuration as necessary. Depending on the test, you might also need to comment/uncomment the required network in the test function. -
Command Usage:
./run_tests.sh -l [log level] -b [backtrace] -t [test name] -L --signet|--regtest
-l
or--log-level
: Specify the log level. Valid options areinfo
,debug
, ornone
.-b
or--backtrace
: Enable (1) or Disable (0) backtrace.-t
or--test-name
: Specify a test name (optional).-L
or--long-tests
: Include tests that take a long time to complete in signet due to the time it takes to complete a block. These tests run fast in regtest.--signet
: Use the signet network.--regtest
: Use the regtest network.
Note: there should be no quotations on any of the argument flags when used.
Run all tests with debug
logs and backtrace:
./run_tests.sh -l debug -b 1
Run the test_example
with info
logs:
./run_tests.sh -l info -t test_example
If you prefer manual testing:
-
Setup: Ensure a Bitcoin node is running on the desired network (
regtest
orsignet
), and modify the RPC URL in your configuration as necessary. Depending on the test, you might also need to comment/uncomment the required network in the test function. -
Running Tests:
-
regtest:
cargo test --features regtest
-
Signet:
cargo test --features signet
-
With Logs:
RUST_LOG=debug cargo test
-
Logs + Backtrace:
RUST_LOG=debug RUST_BACKTRACE=1 cargo test --features regtest
-
Logs + Backtrace + long tests: RUST_LOG=debug RUST_BACKTRACE=1 cargo test --features regtest,long_tests
This project is under the Apache 2.0 license. Detailed information can be found in LICENSE.
Collaborative work by Kasar and Taproot Wizards π§ββοΈ.
Antoine π» |
Antiyro π» |
Betacod π» |
Sparqet π» |
Axel Izsak π» |
Zarboq π» |