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
Update to bitcoin 0.30 ecosystem #41
Open
sanket1729
wants to merge
1
commit into
stevenroose:master
Choose a base branch
from
sanket1729:master
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
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
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
|
||
use std::str::FromStr; | ||
|
||
use bitcoin::address::NetworkUnchecked; | ||
use bitcoin::hashes::Hash; | ||
use bitcoin::hashes::hex::FromHex; | ||
use bitcoin::{Address, WPubkeyHash, WScriptHash}; | ||
use bitcoin::{Address, WPubkeyHash, WScriptHash, Script, AddressType}; | ||
use clap; | ||
|
||
use hal; | ||
use hal::address::addr_unchecked; | ||
use secp256k1::XOnlyPublicKey; | ||
|
||
use crate::prelude::*; | ||
|
||
|
@@ -67,9 +70,9 @@ fn exec_create<'a>(args: &clap::ArgMatches<'a>) { | |
args.print_output(&addr) | ||
} else if let Some(script_hex) = args.value_of("script") { | ||
let script_bytes = hex::decode(script_hex).need("invalid script hex"); | ||
let script = script_bytes.into(); | ||
let script = Script::from_bytes(&script_bytes); | ||
|
||
let mut ret = hal::address::Addresses::from_script(&script, network); | ||
let mut ret = hal::address::Addresses::from_script(script, network); | ||
|
||
// If the user provided NUMS information we can add a p2tr address. | ||
if util::more_than_one(&[ | ||
|
@@ -94,7 +97,7 @@ fn exec_create<'a>(args: &clap::ArgMatches<'a>) { | |
}; | ||
if let Some(pk) = nums { | ||
let spk = script.to_v1_p2tr(&SECP, pk.into()); | ||
ret.p2tr = Some(Address::from_script(&spk, network).unwrap()); | ||
ret.p2tr = Some(addr_unchecked(Address::from_script(&spk, network).unwrap())); | ||
} | ||
|
||
args.print_output(&ret) | ||
|
@@ -111,26 +114,30 @@ fn cmd_inspect<'a>() -> clap::App<'a, 'a> { | |
|
||
fn exec_inspect<'a>(args: &clap::ArgMatches<'a>) { | ||
let address_str = args.value_of("address").need("no address provided"); | ||
let address: Address = address_str.parse().need("invalid address format"); | ||
let address: Address<NetworkUnchecked> = address_str.parse().need("invalid address format"); | ||
let address = address.require_network(args.network()).unwrap(); | ||
let script_pk = address.script_pubkey(); | ||
|
||
let mut info = hal::address::AddressInfo { | ||
network: address.network, | ||
script_pub_key: hal::tx::OutputScriptInfo { | ||
hex: Some(script_pk.to_bytes().into()), | ||
asm: Some(script_pk.asm()), | ||
asm: Some(script_pk.to_asm_string()), | ||
address: None, | ||
type_: None, | ||
}, | ||
type_: None, | ||
witness_program_version: None, | ||
pubkey_hash: None, | ||
script_hash: None, | ||
witness_pubkey_hash: None, | ||
witness_script_hash: None, | ||
witness_program_version: None, | ||
taproot_output_key: None, | ||
}; | ||
|
||
use bitcoin::util::address::Payload; | ||
|
||
use bitcoin::address::Payload; | ||
let addr_ty = address.address_type(); | ||
match address.payload { | ||
Payload::PubkeyHash(pkh) => { | ||
info.type_ = Some("p2pkh".to_owned()); | ||
|
@@ -140,28 +147,31 @@ fn exec_inspect<'a>(args: &clap::ArgMatches<'a>) { | |
info.type_ = Some("p2sh".to_owned()); | ||
info.script_hash = Some(sh); | ||
} | ||
Payload::WitnessProgram { | ||
version, | ||
program, | ||
} => { | ||
Payload::WitnessProgram(prog) => { | ||
let (version, program) = (prog.version(), prog.program()); | ||
let version = version.to_num() as usize; | ||
info.witness_program_version = Some(version); | ||
|
||
if version == 0 { | ||
if program.len() == 20 { | ||
info.type_ = Some("p2wpkh".to_owned()); | ||
info.witness_pubkey_hash = | ||
Some(WPubkeyHash::from_slice(&program).need("size 20")); | ||
} else if program.len() == 32 { | ||
info.type_ = Some("p2wsh".to_owned()); | ||
info.witness_script_hash = | ||
Some(WScriptHash::from_slice(&program).need("size 32")); | ||
} else { | ||
info.type_ = Some("invalid-witness-program".to_owned()); | ||
} | ||
} else { | ||
info.type_ = Some("unknown-witness-program-version".to_owned()); | ||
} | ||
match addr_ty { | ||
Some(ty) => { | ||
info.type_ = Some(ty.to_string()); | ||
match ty { | ||
AddressType::P2pkh => unreachable!("Dealt earlier"), | ||
AddressType::P2sh => unreachable!("Dealt earlier"), | ||
AddressType::P2wpkh => | ||
info.witness_pubkey_hash = Some(WPubkeyHash::from_slice(program.as_bytes()).need("size 20")), | ||
AddressType::P2wsh => | ||
info.witness_script_hash = Some(WScriptHash::from_slice(program.as_bytes()).need("size 32")), | ||
AddressType::P2tr => | ||
info.taproot_output_key = Some(XOnlyPublicKey::from_slice(program.as_bytes()).need("size 32")), | ||
_ => {}, | ||
} | ||
}, | ||
None => info.type_ = Some("unknown-witness-program-version".to_owned()), | ||
}; | ||
} | ||
_ => { | ||
info.type_ = Some("unknown payload".to_owned()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this because of non-exhaustive? |
||
} | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use std::str::FromStr; | ||
|
||
use bitcoin::util::bip32; | ||
use bitcoin::bip32; | ||
use clap; | ||
|
||
use crate::prelude::*; | ||
|
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.
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.
Uff this is a bit annoying..