Skip to content

Commit d980067

Browse files
committed
Export Instantiate2AddressError and make it usable
1 parent f4d5053 commit d980067

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/std/src/addresses.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use sha2::{
77
use std::borrow::Cow;
88
use std::fmt;
99
use std::ops::Deref;
10+
use thiserror::Error;
1011

1112
use crate::{binary::Binary, HexBinary};
1213

@@ -275,14 +276,23 @@ impl fmt::Display for CanonicalAddr {
275276
}
276277
}
277278

278-
#[derive(Debug)]
279+
#[derive(Error, Debug, PartialEq, Eq)]
279280
pub enum Instantiate2AddressError {
280281
/// Checksum must be 32 bytes
281282
InvalidChecksumLength,
282283
/// Salt must be between 1 and 64 bytes
283284
InvalidSaltLength,
284285
}
285286

287+
impl fmt::Display for Instantiate2AddressError {
288+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
289+
match self {
290+
Instantiate2AddressError::InvalidChecksumLength => write!(f, "invalid checksum length"),
291+
Instantiate2AddressError::InvalidSaltLength => write!(f, "invalid salt length"),
292+
}
293+
}
294+
}
295+
286296
/// Creates a contract address using the predictable address format introduced with
287297
/// wasmd 0.29. When using instantiate2, this is a way to precompute the address.
288298
/// When using instantiate, the contract address will use a different algorithm and

packages/std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod timestamp;
2626
mod traits;
2727
mod types;
2828

29-
pub use crate::addresses::{instantiate2_address, Addr, CanonicalAddr};
29+
pub use crate::addresses::{instantiate2_address, Addr, CanonicalAddr, Instantiate2AddressError};
3030
pub use crate::binary::Binary;
3131
pub use crate::coin::{coin, coins, has_coins, Coin};
3232
pub use crate::deps::{Deps, DepsMut, OwnedDeps};

0 commit comments

Comments
 (0)