Skip to content

Commit

Permalink
Add generate block rpc call to bitcoin node
Browse files Browse the repository at this point in the history
  • Loading branch information
ercecan committed Jan 8, 2025
1 parent f75fe92 commit 72dd813
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
time::{Duration, Instant},
};

use anyhow::{bail, Context};
use anyhow::{anyhow, bail, Context};
use async_trait::async_trait;
use bitcoin::Address;
use bitcoincore_rpc::{json::AddressType::Bech32m, Auth, Client, RpcApi};
Expand Down Expand Up @@ -165,6 +165,16 @@ impl BitcoinNode {
) -> bitcoincore_rpc::Result<Vec<bitcoin::BlockHash>> {
RpcApi::generate(self, block_num, None).await
}

pub async fn generate_block(
&self,
// Address to send the block reward to
output: String,
// Either raw txs or txids, should be in mempool and in correct order
transactions: Vec<String>,
) -> bitcoincore_rpc::Result<bitcoin::BlockHash> {
RpcApi::call(self, "generateblock", &[output.into(), transactions.into()]).await
}
}

#[async_trait]
Expand Down

0 comments on commit 72dd813

Please sign in to comment.