Skip to content
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

Including the latest rust-wallet and rust-bitcoin as dependencies causes errors #25

Open
chris-belcher opened this issue Oct 14, 2020 · 5 comments · May be fixed by #35
Open

Including the latest rust-wallet and rust-bitcoin as dependencies causes errors #25

chris-belcher opened this issue Oct 14, 2020 · 5 comments · May be fixed by #35

Comments

@chris-belcher
Copy link

chris-belcher commented Oct 14, 2020

extern crate bitcoin_wallet;                                                    
use bitcoin_wallet::account::MasterAccount;                                     
use bitcoin_wallet::mnemonic;                                                   
                                                                                
extern crate bitcoin;                                                           
use bitcoin::Network;                                                           
                                                                                
fn main() {                                                                     
    const SEED_PHRASE: &str =                                                   
"great rice pitch bitter stay crash among position disease enable sell road";   
    const EXTENSION: &str = "helloworld";                                       
    const PASSPHRASE: &str = "";                                                
                                                                                
    let _master = MasterAccount::from_mnemonic(                                 
        &mnemonic::Mnemonic::from_str(SEED_PHRASE).unwrap(),                    
        0,                                                                      
        Network::Regtest,                                                       
        PASSPHRASE,                                                             
        Some(EXTENSION)                                                         
    ).unwrap();                                                                 
}     
[package]                                                                       
name = "deps-rust-bitcoin"                                                      
version = "0.1.0"                                                               
authors = ["chris-belcher <chris-belcher@users.noreply.github.com>"]            
edition = "2018"                                                                
                                                                                
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
                                                                                
[dependencies]                                                                  
bitcoin-wallet = "1.1.0"                                                        
bitcoin = "0.25"

The resulting error:

$ cargo check
    Checking deps-rust-bitcoin v0.1.0 (/home/user/coding/rust/projects/deps-rust-bitcoin)
error[E0308]: mismatched types
  --> src/main.rs:17:9
   |
17 |         Network::Regtest,
   |         ^^^^^^^^^^^^^^^^ expected enum `bitcoin::network::constants::Network`, found enum `bitcoin::Network`
   |
   = note: perhaps two different versions of crate `bitcoin` are being used?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `deps-rust-bitcoin`.

To learn more, run the command again with --verbose.

Changing the line in Cargo.toml to bitcoin = "0.21" make the code correctly compile, however then you're missing the latest updates of rust-bitcoin. Anything bitcoin = "0.22" or above results in the same error.

What's going on here? (I'm slightly new to rust so would appreciate a explanation) How to fix or work around this?

I've noticed when searching github that everyone actually uses bitcoin = "0.21" in combination with rust-wallet
https://github.com/search?l=&p=2&q=bitcoin-wallet+filename%3ACargo.toml+fork%3Atrue&ref=advsearch&type=Code

@chris-belcher
Copy link
Author

Also, ExtendedPrivateKey from rust-wallet is not compatible with rust-bitcoin, but again this is fixed when using bitcoin = "0.21"

extern crate bitcoin_wallet;                                                    
use bitcoin_wallet::account::{MasterAccount, Unlocker};                         
use bitcoin_wallet::mnemonic;                                                   
                                                                                
extern crate bitcoin;                                                           
use bitcoin::Network;                                                           
use bitcoin::secp256k1::Secp256k1;                                              
use bitcoin::util::bip32::ChildNumber;                                          
                                                                                
fn main() {                                                                     
    const SEED_PHRASE: &str =                                                   
"great rice pitch bitter stay crash among position disease enable sell road";   
    const EXTENSION: &str = "helloworld";                                       
    const PASSPHRASE: &str = "";                                                
                                                                                
    let master = MasterAccount::from_mnemonic(                                  
        &mnemonic::Mnemonic::from_str(SEED_PHRASE).unwrap(),                    
        0,                                                                      
        Network::Regtest,                                                       
        PASSPHRASE,                                                             
        Some(EXTENSION)                                                         
    ).unwrap();                                                                 
                                                                                
    let unlocker = Unlocker::new_for_master(&master, PASSPHRASE).unwrap();      
    let secp = Secp256k1::new();                                                
    let tweakable_pubkey = unlocker.context().private_child(                    
        unlocker.master_private(),                                              
        ChildNumber::from_hardened_idx(0).unwrap()                              
    ).unwrap().private_key.public_key(&secp);                                   
}

Error when bitcoin = "0.25":

$ cargo check
    Updating crates.io index
    Checking deps-rust-bitcoin v0.1.0 (/home/user/coding/rust/projects/deps-rust-bitcoin)
error[E0308]: mismatched types
  --> src/main.rs:19:9
   |
19 |         Network::Regtest,
   |         ^^^^^^^^^^^^^^^^ expected enum `bitcoin::network::constants::Network`, found enum `bitcoin::Network`
   |
   = note: perhaps two different versions of crate `bitcoin` are being used?

error[E0308]: mismatched types
  --> src/main.rs:28:9
   |
28 |         ChildNumber::from_hardened_idx(0).unwrap()
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `bitcoin::util::bip32::ChildNumber`, found a different enum `bitcoin::util::bip32::ChildNumber`
   |
   = note: perhaps two different versions of crate `bitcoin` are being used?

error[E0308]: mismatched types
  --> src/main.rs:29:39
   |
29 |     ).unwrap().private_key.public_key(&secp);
   |                                       ^^^^^ expected struct `secp256k1::Secp256k1`, found struct `bitcoin::secp256k1::Secp256k1`
   |
   = note: expected reference `&secp256k1::Secp256k1<_>`
              found reference `&bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>`
   = note: perhaps two different versions of crate `secp256k1` are being used?

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.
error: could not compile `deps-rust-bitcoin`.

To learn more, run the command again with --verbose.

@chris-belcher
Copy link
Author

I worked around this issue by completely separating rust-bitcoin and rust-wallet. So for example using rust-wallet's seed phrase code to obtain random data as [u8] and then passing that to rust-bitcoin. And never using a struct from rust-wallet like PublicKey and passing it to a function rust-bitcoin. Luckily my project only uses small parts of rust-wallet so this was possible.

@weaming
Copy link

weaming commented Jun 10, 2021

@chris-belcher Have you published your project?

@chris-belcher
Copy link
Author

@urcheon2022
Copy link

Hello everyone, does anyone have any update on this problem? I also ran into it and - frankly - don't really know how to resolve other than downgrading to the last compatible version across my program.

@andrewtoth andrewtoth linked a pull request Jun 8, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants