Skip to content

Commit 899b294

Browse files
committed
Merge #225: Make AssetId::from_inner a const function
1f3b402 Make AssetId::from_inner a const function (Pavel Kokolemin) Pull request description: This will allow constructing `AssetId` values like this: ``` const TESTNET_ASSET: elemets::AssetId = const_asset_id("144c654344aa716d6f3abcc1ca90e5641e4e2a7f633bc09fe3baf64585819a49"); /// Panics if the asset id string has wrong length or format pub const fn const_asset_id(s: &str) -> elements::AssetId { let mut data: [u8; 32] = hex_literal::decode::<32>(&[s.as_bytes()]); let mut left = 0; let mut right = data.len() - 1; while left < right { let tmp = data[left]; data[left] = data[right]; data[right] = tmp; left += 1; right -= 1; } elements::AssetId::from_inner(bitcoin::hashes::sha256::Midstate(data)) } ``` It's a bit of a hack because `hex_literal::decode` should not be used directly. ACKs for top commit: apoelstra: ACK 1f3b402; successfully ran local tests; nice, good call Tree-SHA512: 33e1353ecd0c74df2915509fe24cbd56b5fe9c7b7ce412e4adfa59245c4e4f904e514785ffa0c345b9c3bdffce4c76cb3f9d4d3ce4c9372a80f4b4ce1e9dfa48
2 parents 51028fa + 1f3b402 commit 899b294

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/issuance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl AssetId {
7676
]));
7777

7878
/// Create an [AssetId] from its inner type.
79-
pub fn from_inner(midstate: sha256::Midstate) -> AssetId {
79+
pub const fn from_inner(midstate: sha256::Midstate) -> AssetId {
8080
AssetId(midstate)
8181
}
8282

0 commit comments

Comments
 (0)