1
1
use chia:: protocol:: Bytes32 ;
2
+ use chia_wallet_sdk:: decode_address;
2
3
use csv:: ReaderBuilder ;
3
4
use hex:: FromHex ;
4
5
use serde:: Deserialize ;
@@ -7,18 +8,18 @@ use std::fs::File;
7
8
use std:: path:: Path ;
8
9
9
10
#[ derive( Debug , Deserialize ) ]
10
- struct CatalogPremineRecord {
11
+ pub struct CatalogPremineRecord {
11
12
#[ serde( with = "hex_string" ) ]
12
- asset_id : Bytes32 ,
13
+ pub asset_id : Bytes32 ,
13
14
#[ 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 ,
18
19
#[ serde( deserialize_with = "deserialize_string_array" ) ]
19
- image_uris : Vec < String > ,
20
+ pub image_uris : Vec < String > ,
20
21
#[ serde( with = "hex_string" ) ]
21
- image_hash : Bytes32 ,
22
+ pub image_hash : Bytes32 ,
22
23
}
23
24
24
25
mod hex_string {
@@ -40,21 +41,13 @@ where
40
41
D : serde:: Deserializer < ' de > ,
41
42
{
42
43
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) ?;
44
45
45
46
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" ) ) ;
47
48
}
48
49
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) )
58
51
}
59
52
60
53
fn deserialize_string_array < ' de , D > ( deserializer : D ) -> Result < Vec < String > , D :: Error >
0 commit comments