Skip to content

Commit 1bbf576

Browse files
committed
solve errors; only warnings for now
1 parent 83cd2c6 commit 1bbf576

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/cli/csv.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use chia::protocol::Bytes32;
2+
use chia_wallet_sdk::decode_address;
23
use csv::ReaderBuilder;
34
use hex::FromHex;
45
use serde::Deserialize;
@@ -7,18 +8,18 @@ use std::fs::File;
78
use std::path::Path;
89

910
#[derive(Debug, Deserialize)]
10-
struct CatalogPremineRecord {
11+
pub struct CatalogPremineRecord {
1112
#[serde(with = "hex_string")]
12-
asset_id: Bytes32,
13+
pub asset_id: Bytes32,
1314
#[serde(deserialize_with = "decode_bech32m")]
14-
owner: Bytes32,
15-
code: String,
16-
name: String,
17-
precision: u8,
15+
pub owner: Bytes32,
16+
pub code: String,
17+
pub name: String,
18+
pub precision: u8,
1819
#[serde(deserialize_with = "deserialize_string_array")]
19-
image_uris: Vec<String>,
20+
pub image_uris: Vec<String>,
2021
#[serde(with = "hex_string")]
21-
image_hash: Bytes32,
22+
pub image_hash: Bytes32,
2223
}
2324

2425
mod hex_string {
@@ -40,21 +41,13 @@ where
4041
D: serde::Deserializer<'de>,
4142
{
4243
let s: &str = Deserialize::deserialize(deserializer)?;
43-
let (hrp, data, _) = bech32::decode(s).map_err(serde::de::Error::custom)?;
44+
let (res, hrp) = decode_address(s).map_err(serde::de::Error::custom)?;
4445

4546
if hrp != "xch" && hrp != "txch" {
46-
return Err(serde::de::Error::custom("Invalid Bech32m prefix"));
47+
return Err(serde::de::Error::custom("Invalid bech32m prefix"));
4748
}
4849

49-
let bytes = Vec::from_base32(&data).map_err(serde::de::Error::custom)?;
50-
let mut result = [0u8; 32];
51-
if bytes.len() != 32 {
52-
return Err(serde::de::Error::custom(
53-
"Decoded Bech32m does not match expected length of 32 bytes",
54-
));
55-
}
56-
result.copy_from_slice(&bytes[..32]);
57-
Ok(Bytes32(result))
50+
Ok(Bytes32::new(res))
5851
}
5952

6053
fn deserialize_string_array<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>

0 commit comments

Comments
 (0)