This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Add submitpackage
support
#23
Open
tnull
wants to merge
5
commits into
rust-bitcoin:master
Choose a base branch
from
tnull:2024-08-add-submitpackage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bd6863c
Add `submitpackage` RPC support
tnull 7041357
f Include `into_model` implementations
tnull 9491250
f Drop `serde` stuff from model
tnull 0517507
f Don't use `rust-bitcoin` types in non-model
tnull 156be9c
f Drop `submitpackage` RPC example output comment
tnull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
//! Macros for implementing JSON-RPC methods on a client. | ||
//! | ||
//! Specifically this is methods found under the `== Rawtransactions ==` section of the | ||
//! API docs of `bitcoind v28.0`. | ||
//! | ||
//! All macros require `Client` to be in scope. | ||
//! | ||
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. | ||
|
||
/// Implements bitcoind JSON-RPC API method `submitpackage` | ||
#[macro_export] | ||
macro_rules! impl_client_v28__submitpackage { | ||
() => { | ||
impl Client { | ||
/// Submit a package of transactions to local node. | ||
/// | ||
/// The package will be validated according to consensus and mempool policy rules. If any transaction passes, it will be accepted to mempool. | ||
/// | ||
/// ## Arguments: | ||
/// 1. `package`: An array of raw transactions. | ||
/// The package must solely consist of a child and its parents. None of the parents may depend on each other. | ||
/// The package must be topologically sorted, with the child being the last element in the array. | ||
/// 2. `maxfeerate`: Reject transactions whose fee rate is higher than the specified value. | ||
/// Fee rates larger than 1BTC/kvB are rejected. | ||
/// Set to 0 to accept any fee rate. | ||
/// If unset, will default to 0.10 BTC/kvb. | ||
/// 3. `maxburnamount` If set, reject transactions with provably unspendable outputs (e.g. 'datacarrier' outputs that use the OP_RETURN opcode) greater than the specified value. | ||
/// If burning funds through unspendable outputs is desired, increase this value. | ||
/// This check is based on heuristics and does not guarantee spendability of outputs. | ||
pub fn submit_package( | ||
&self, | ||
package: &[bitcoin::Transaction], | ||
max_fee_rate: Option<bitcoin::FeeRate>, | ||
max_burn_amount: Option<bitcoin::Amount>, | ||
) -> Result<SubmitPackage> { | ||
let package_txs = package | ||
.into_iter() | ||
.map(|tx| bitcoin::consensus::encode::serialize_hex(tx)) | ||
.collect::<Vec<_>>(); | ||
let max_fee_rate_btc_kvb = | ||
max_fee_rate.map(|r| r.to_sat_per_vb_floor() as f64 / 100_000.0); | ||
let max_burn_amount_btc = max_burn_amount.map(|a| a.to_btc()); | ||
self.call( | ||
"submitpackage", | ||
&[package_txs.into(), max_fee_rate_btc_kvb.into(), max_burn_amount_btc.into()], | ||
) | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
//! Macros for implementing test methods on a JSON-RPC client for `bitcoind v28.0`. | ||
|
||
pub mod raw_transactions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
//! Macros for implementing test methods on a JSON-RPC client. | ||
//! | ||
//! Specifically this is methods found under the `== Rawtransactions ==` section of the | ||
//! API docs of `bitcoind v28.0`. | ||
|
||
/// Requires `Client` to be in scope | ||
#[macro_export] | ||
macro_rules! impl_test_v28__submitpackage { | ||
() => { | ||
#[test] | ||
fn submitpackage() { | ||
//let bitcoind = $crate::bitcoind_no_wallet(); | ||
|
||
let bitcoind = $crate::bitcoind_with_default_wallet(); | ||
|
||
// Submitting the empty package should simply fail. | ||
assert!(bitcoind.client.submit_package(&[], None, None).is_err()); | ||
|
||
// Premine to get some funds | ||
let address = bitcoind.client.new_address().expect("failed to get new address"); | ||
let json = | ||
bitcoind.client.generate_to_address(101, &address).expect("generatetoaddress"); | ||
json.into_model().unwrap(); | ||
|
||
// Send to ourselves, mine, send again to generate two transactions. | ||
let (tx_0, tx_1) = { | ||
let new_address = bitcoind.client.new_address().expect("failed to get new address"); | ||
let txid = bitcoind | ||
.client | ||
.send_to_address(&new_address, bitcoin::Amount::from_sat(1000000)) | ||
.unwrap() | ||
.into_model() | ||
.unwrap() | ||
.txid; | ||
|
||
let _ = | ||
bitcoind.client.generate_to_address(1, &address).expect("generatetoaddress"); | ||
|
||
let best_block_hash = bitcoind.client.best_block_hash().unwrap(); | ||
let best_block = bitcoind.client.get_block(best_block_hash).unwrap(); | ||
let tx_0 = best_block.txdata[1].clone(); | ||
|
||
let new_address = bitcoind.client.new_address().expect("failed to get new address"); | ||
let txid = bitcoind | ||
.client | ||
.send_to_address(&new_address, bitcoin::Amount::from_sat(1000000)) | ||
.unwrap() | ||
.into_model() | ||
.unwrap() | ||
.txid; | ||
|
||
let _ = | ||
bitcoind.client.generate_to_address(1, &address).expect("generatetoaddress"); | ||
|
||
let best_block_hash = bitcoind.client.best_block_hash().unwrap(); | ||
let best_block = bitcoind.client.get_block(best_block_hash).unwrap(); | ||
let tx_1 = best_block.txdata[1].clone(); | ||
(tx_0, tx_1) | ||
}; | ||
|
||
// The call for submitting this package should succeed, but yield an 'already known' | ||
// error for all transactions. | ||
let res = bitcoind | ||
.client | ||
.submit_package(&[tx_0, tx_1], None, None) | ||
.expect("failed to submit package") | ||
.into_model() | ||
.expect("failed to submit package"); | ||
for (_, tx_result) in &res.tx_results { | ||
assert!(tx_result.error.is_some()); | ||
} | ||
assert!(res.replaced_transactions.is_empty()); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error type needs to go over in
v28/raw_transactions.rs
(the conversion is coupled with theinto_model
function). Also the error needs a few more things implementing, seev17/blockchain.rs
for an example. FTR the v17 stuff is in the best state because its the part of the crate I've been working on lately, if something is non-uniform favour the stuff inv17
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, well that's surprising to me. In fact I started the error type in
v28
but then realized it is / needs to be part of the stablemodel
conversion API, and hence shouldn't / can't be version-specific, no?