Skip to content

Commit 86278c0

Browse files
author
Elias Rohrer
committed
Add 'submitblock' RPC call.
1 parent 9bbca7f commit 86278c0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

client/src/client.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,27 @@ pub trait RpcApi: Sized {
11551155
self.call("uptime", &[])
11561156
}
11571157

1158+
/// Submit a block
1159+
fn submit_block(&self, block: &bitcoin::Block) -> Result<()> {
1160+
let block_hex: String = bitcoin::consensus::encode::serialize_hex(block);
1161+
self.submit_block_hex(&block_hex)
1162+
}
1163+
1164+
/// Submit a raw block
1165+
fn submit_block_bytes(&self, block_bytes: &[u8]) -> Result<()> {
1166+
let block_hex: String = block_bytes.to_hex();
1167+
self.submit_block_hex(&block_hex)
1168+
}
1169+
1170+
/// Submit a block as a hex string
1171+
fn submit_block_hex(&self, block_hex: &str) -> Result<()> {
1172+
match self.call("submitblock", &[into_json(&block_hex)?]) {
1173+
Ok(serde_json::Value::Null) => Ok(()),
1174+
Ok(res) => Err(Error::ReturnedError(res.to_string())),
1175+
Err(err) => Err(err.into()),
1176+
}
1177+
}
1178+
11581179
fn scan_tx_out_set_blocking(
11591180
&self,
11601181
descriptors: &[json::ScanTxOutRequest],

client/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub enum Error {
2929
InvalidCookieFile,
3030
/// The JSON result had an unexpected structure.
3131
UnexpectedStructure,
32+
/// The daemon returned an error string.
33+
ReturnedError(String),
3234
}
3335

3436
impl From<jsonrpc::error::Error> for Error {
@@ -85,6 +87,7 @@ impl fmt::Display for Error {
8587
Error::InvalidAmount(ref e) => write!(f, "invalid amount: {}", e),
8688
Error::InvalidCookieFile => write!(f, "invalid cookie file"),
8789
Error::UnexpectedStructure => write!(f, "the JSON result had an unexpected structure"),
90+
Error::ReturnedError(ref s) => write!(f, "the daemon returned an error string: {}", s),
8891
}
8992
}
9093
}

0 commit comments

Comments
 (0)