Skip to content

Commit

Permalink
Use bech32grs
Browse files Browse the repository at this point in the history
  • Loading branch information
gruve-p committed Feb 12, 2024
1 parent d9d1325 commit 0fd8809
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
7 changes: 4 additions & 3 deletions Cargo-minimal.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53"

[[package]]
name = "bech32"
name = "bech32grs"
version = "0.10.0-beta"
source = "git+https://github.com/Groestlcoin/rust-bech32#7fa28249c554c52bb7a14257d91109a8652b9dd6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e190aad8fbe17cf8d2d68ba93844c33a2ef9544e05945da83df0bf81078f044"

[[package]]
name = "bincode"
Expand Down Expand Up @@ -126,7 +127,7 @@ name = "groestlcoin"
version = "0.31.0"
dependencies = [
"base64",
"bech32",
"bech32grs",
"bincode",
"core2",
"groestlcoin-internals",
Expand Down
7 changes: 4 additions & 3 deletions Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53"

[[package]]
name = "bech32"
name = "bech32grs"
version = "0.10.0-beta"
source = "git+https://github.com/Groestlcoin/rust-bech32#7fa28249c554c52bb7a14257d91109a8652b9dd6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e190aad8fbe17cf8d2d68ba93844c33a2ef9544e05945da83df0bf81078f044"

[[package]]
name = "bincode"
Expand Down Expand Up @@ -125,7 +126,7 @@ name = "groestlcoin"
version = "0.31.0"
dependencies = [
"base64",
"bech32",
"bech32grs",
"bincode",
"core2",
"groestlcoin-internals",
Expand Down
6 changes: 3 additions & 3 deletions groestlcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ groestlcoinconsensus-std = ["groestlcoinconsensus/std", "std"]
# The no-std feature doesn't disable std - you need to turn off the std feature for that by disabling default.
# Instead no-std enables additional features required for this crate to be usable without std.
# As a result, both can be enabled without conflict.
std = ["secp256k1/std", "hashes/std", "bech32/std", "internals/std", "hex/std"]
no-std = ["core2", "hashes/alloc", "hashes/core2", "bech32/alloc", "secp256k1/alloc", "hex/alloc", "hex/core2"]
std = ["secp256k1/std", "hashes/std", "bech32grs/std", "internals/std", "hex/std"]
no-std = ["core2", "hashes/alloc", "hashes/core2", "bech32grs/alloc", "secp256k1/alloc", "hex/alloc", "hex/core2"]

[package.metadata.docs.rs]
all-features = true
Expand All @@ -36,7 +36,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
internals = { package = "groestlcoin-internals", version = "0.2.0" }
hex = { package = "hex-conservative", version = "0.1.1", default-features = false }
bech32 = { git = "https://github.com/Groestlcoin/rust-bech32", default-features = false }
bech32grs = { version = "0.10.0-beta", default-features = false }
hashes = { package = "groestlcoin_hashes", version = "0.13.0", default-features = false }
secp256k1 = { version = "0.28.0", default-features = false } # do not use bitcoin-hashes feature
hex_lit = "0.1.1"
Expand Down
6 changes: 3 additions & 3 deletions groestlcoin/src/address/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub enum ParseError {
/// Base58 error.
Base58(base58::Error),
/// Bech32 segwit decoding error.
Bech32(bech32::segwit::DecodeError),
Bech32(bech32grs::segwit::DecodeError),
/// A witness version conversion/parsing error.
WitnessVersion(witness_version::TryFromError),
/// A witness program error.
Expand Down Expand Up @@ -141,8 +141,8 @@ impl From<base58::Error> for ParseError {
fn from(e: base58::Error) -> Self { Self::Base58(e) }
}

impl From<bech32::segwit::DecodeError> for ParseError {
fn from(e: bech32::segwit::DecodeError) -> Self { Self::Bech32(e) }
impl From<bech32grs::segwit::DecodeError> for ParseError {
fn from(e: bech32grs::segwit::DecodeError) -> Self { Self::Bech32(e) }
}

impl From<witness_version::TryFromError> for ParseError {
Expand Down
8 changes: 4 additions & 4 deletions groestlcoin/src/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use core::fmt;
use core::marker::PhantomData;
use core::str::FromStr;

use bech32::primitives::hrp::{self, Hrp};
use bech32grs::primitives::hrp::{self, Hrp};
use hashes::{sha256, Hash, HashEngine};
use secp256k1::{Secp256k1, Verification, XOnlyPublicKey};

Expand Down Expand Up @@ -264,9 +264,9 @@ impl<'a> fmt::Display for AddressEncoding<'a> {
let program = witness_program.program().as_bytes();

if fmt.alternate() {
bech32::segwit::encode_upper_to_fmt_unchecked(fmt, hrp, version, program)
bech32grs::segwit::encode_upper_to_fmt_unchecked(fmt, hrp, version, program)
} else {
bech32::segwit::encode_lower_to_fmt_unchecked(fmt, hrp, version, program)
bech32grs::segwit::encode_lower_to_fmt_unchecked(fmt, hrp, version, program)
}
}
}
Expand Down Expand Up @@ -798,7 +798,7 @@ impl FromStr for Address<NetworkUnchecked> {
_ => None,
};
if let Some(network) = bech32_network {
let (_hrp, version, data) = bech32::segwit::decode(s)?;
let (_hrp, version, data) = bech32grs::segwit::decode(s)?;
let version = WitnessVersion::try_from(version).expect("we know this is in range 0-16");
let program = PushBytesBuf::try_from(data).expect("decode() guarantees valid length");
let witness_program = WitnessProgram::new(version, program)?;
Expand Down
4 changes: 2 additions & 2 deletions groestlcoin/src/blockdata/script/witness_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use core::convert::TryFrom;
use core::fmt;
use core::str::FromStr;

use bech32::Fe32;
use bech32grs::Fe32;
use internals::write_err;

use crate::blockdata::opcodes::all::*;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl FromStr for WitnessVersion {
}
}

impl TryFrom<bech32::Fe32> for WitnessVersion {
impl TryFrom<bech32grs::Fe32> for WitnessVersion {
type Error = TryFromError;

fn try_from(value: Fe32) -> Result<Self, Self::Error> { Self::try_from(value.to_u8()) }
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extern crate alloc;
pub extern crate base64;

/// Encodes and decodes the Bech32 forrmat.
pub extern crate bech32;
pub extern crate bech32grs;

#[cfg(feature = "groestlcoinconsensus")]
/// Groestlcoin's libgroestlcoinconsensus with Rust binding.
Expand Down

0 comments on commit 0fd8809

Please sign in to comment.