Commit 899b294
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: 33e1353ecd0c74df2915509fe24cbd56b5fe9c7b7ce412e4adfa59245c4e4f904e514785ffa0c345b9c3bdffce4c76cb3f9d4d3ce4c9372a80f4b4ce1e9dfa481 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
0 commit comments