Skip to content

How to get value to put in &[GetBlockTemplateCapabilities] as an argument for get_block_template()? #219

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

Closed
matthiasdebernardini opened this issue Apr 23, 2022 · 4 comments

Comments

@matthiasdebernardini
Copy link

matthiasdebernardini commented Apr 23, 2022

I am trying to get the block template of my core node so I can implement this in rust.

https://code.samourai.io/oxt/one_dollar_fee_estimator/-/blob/master/one_dollar_fee_estimator/estimator.py

Below is my code that wont compile and I can't figure out how to use the rpc call correctly just from looking at the docs.

How would I supply the get block template call with the correct capabilities? Looks like I need to get a value from the enum to put in the array but I can't figure out how to invoke one from the docs.

This is the function signature that I copied from the docs.
fn get_block_template(
&self,
mode: GetBlockTemplateModes,
rules: &GetBlockTemplateRules[],
capabilities: &GetBlockTemplateCapabilities[]
) -> Result<GetBlockTemplateResult>

This is my code that I am trying to get running.

use std::error::Error;
use bitcoincore_rpc::RpcApi;
fn main() -> Result<(), Box<dyn Error>> {
    let client = bitcoincore_rpc::Client::new("http://127.0.0.1:38333",bitcoincore_rpc::Auth::UserPass("".to_string(), "".to_string()))?;
    let mode = bitcoincore_rpc::json::GetBlockTemplateModes::Template;
    let rules = &[bitcoincore_rpc::json::GetBlockTemplateRules::Signet, bitcoincore_rpc::json::GetBlockTemplateRules::Taproot, bitcoincore_rpc::json::GetBlockTemplateRules::SegWit, bitcoincore_rpc::json::GetBlockTemplateRules::Csv];
    let capabilities = bitcoincore_rpc::json::GetBlockTemplateCapabilities;
    let rpc = client.get_block_template(mode, rules, capabilities);
    Ok(())
}

I also tried lookind up this example but I think its no longer valid (or at least it wont compile for me.

#163 (comment)

this is my cargo.toml for reference

[package]
name = "one-dollar-estimator"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
statistical = "1.0.0"
ringbuf = "0.2.8"
bitcoincore-rpc = "0.14.0"
bitcoincore-rpc-json = "0.14.0"

Appreciate any pointers, not sure what I am doing wrong here.

@0xB10C
Copy link
Contributor

0xB10C commented May 4, 2022

Have a look at e.g.

https://github.com/0xB10C/miningpool-observer/blob/e8eb52dea2c15527c9784fd431b03ac951a44647/daemon/src/main.rs#L233-L239

but I think the result you get form that RPC call to a v0.21 or newer node is currently broken. See #176. I'm running a patched version of this crate as the fix hasn't been merged yet.

@0xB10C
Copy link
Contributor

0xB10C commented May 4, 2022

Also see the integration tests

fn test_getblocktemplate(cl: &Client) {
// We want to have a transaction in the mempool so the GetBlockTemplateResult
// contains an entry in the vector of GetBlockTemplateResultTransaction.
// Otherwise the GetBlockTemplateResultTransaction deserialization wouldn't
// be tested.
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap();
cl.get_block_template(GetBlockTemplateModes::Template, &[GetBlockTemplateRules::SegWit], &[])
.unwrap();

@matthiasdebernardini
Copy link
Author

matthiasdebernardini commented May 20, 2022

@0xB10C thank you very much, I was able to get it running.

I'll share it here for good measure.

If it belongs elsewhere, let me know.

use bitcoincore_rpc::json::GetBlockTemplateModes::Template;
use bitcoincore_rpc::json::GetBlockTemplateRules::{Csv, SegWit, Signet, Taproot};
use bitcoincore_rpc::RpcApi;
use bitcoincore_rpc::{Auth, Client};
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let client = Client::new(
        "http://127.0.0.1:38332",
        Auth::UserPass("hello".to_string(), "there".to_string()),
    )?;
    let mode = Template;
    let rules = &[Signet, SegWit, Taproot, Csv];
    let capabilities = &[];
    let rpc = client.get_block_template(mode, rules, capabilities)?;
    rpc.transactions.iter().for_each(|a| println!("{:?}", a));
    Ok(())
}

@0xB10C
Copy link
Contributor

0xB10C commented May 20, 2022

Awesome! Feel free to close this issues if it's solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants