pub struct Registry { /* private fields */ }Expand description
Try registered decoders in order, ending with the disassembly fallback.
Implementations§
Source§impl Registry
impl Registry
pub fn register(&mut self, decoder: Box<dyn StateDecoder>)
Sourcepub fn decode(&self, spk_version: u16, script: &[u8]) -> Decoded
pub fn decode(&self, spk_version: u16, script: &[u8]) -> Decoded
Examples found in repository?
examples/reg_probe.rs (line 11)
7fn main() {
8 let reg = Registry::default();
9 for path in std::env::args().skip(1) {
10 let bytes = std::fs::read(&path).expect("read");
11 let d = reg.decode(0, &bytes);
12 let digest = blake2b_simd::Params::new().hash_length(32).hash(&bytes);
13 println!(
14 "== {} len={} blake2b={}",
15 path,
16 bytes.len(),
17 hex::encode(digest.as_bytes())
18 );
19 println!(
20 " decoder={} template={:?} fields={}",
21 d.decoder,
22 d.template,
23 d.fields.len()
24 );
25 for f in &d.fields {
26 let v = if f.value.len() > 40 {
27 format!("{}…({}B)", hex::encode(&f.value[..40]), f.value.len())
28 } else {
29 hex::encode(&f.value)
30 };
31 println!(" - {} = {}", f.name, v);
32 }
33 println!(
34 " kcc20.revealed_template = {:?}",
35 kcc20::revealed_template(®, 0, &bytes)
36 );
37 match kcc20::locate_state_block(&bytes) {
38 Some(x) => println!(" kcc20.locate_state_block = {:?}", x),
39 None => println!(" kcc20.locate_state_block = None"),
40 }
41 match kcc20::decode_token_state(®, 0, &bytes) {
42 Some(s) => println!(
43 " token_state owner={} type={} amount={:?} minter={:?}",
44 hex::encode(s.owner),
45 s.identifier_type,
46 s.amount_i64(),
47 s.is_minter()
48 ),
49 None => println!(" token_state = None"),
50 }
51 }
52}More examples
examples/pin-gallery.rs (line 51)
20fn main() {
21 let reg = Registry::default();
22 let fixtures = [
23 fixture!("g0_root_a"),
24 fixture!("g0_slot_mint_413_a"),
25 fixture!("g0_slot_mint_421_b"),
26 fixture!("g0_slot_mint_520_a"),
27 fixture!("g0_slot_mint_565_b"),
28 fixture!("g0_buy_v3_a"),
29 fixture!("g0_list_v3_b"),
30 fixture!("g0_style_list_a"),
31 fixture!("g0_dutch_list_b"),
32 fixture!("g0_auction_a"),
33 fixture!("g0_krc_gate_boot_b"),
34 fixture!("g0_krc_gate_active_a"),
35 fixture!("kw_vault_schnorr_a"),
36 fixture!("kw_vault_pqcold_b"),
37 fixture!("kw_vault_htlc_a"),
38 fixture!("kw_vault_dms_b"),
39 fixture!("kcom_token_b"),
40 fixture!("zealous_launch_a_a"),
41 fixture!("zealous_launch_b_b"),
42 // already-pinned families, for context
43 fixture!("g0_list_v1_a"),
44 fixture!("g0_buy_v1_a"),
45 fixture!("g0_col_a"),
46 fixture!("pure_a"),
47 ];
48
49 let mut out = Vec::new();
50 for (name, program) in fixtures {
51 let d = reg.decode(0, program);
52 let fields: Vec<_> = d
53 .fields
54 .iter()
55 .map(|f| {
56 serde_json::json!({ "name": f.name, "value": hex::encode(&f.value) })
57 })
58 .collect();
59 out.push(serde_json::json!({
60 "fixture": name,
61 "family": d.template,
62 "bytes": program.len(),
63 "instructions": d.instructions.len(),
64 "uses_covenant_ops": d.uses_covenant_ops,
65 "fields": fields,
66 }));
67 }
68 println!(
69 "{}",
70 serde_json::to_string_pretty(&serde_json::json!({
71 "network": "testnet-10",
72 "generated_by": "cargo run -p kascov-decode --example pin-gallery",
73 "note": "Every program here is a verbatim spend-time reveal whose blake2b \
74 matched its committed P2SH hash before capture; the fields are what \
75 kascov's own decoder labels them.",
76 "pins": out,
77 }))
78 .unwrap()
79 );
80}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Registry
impl !UnwindSafe for Registry
impl Freeze for Registry
impl Send for Registry
impl Sync for Registry
impl Unpin for Registry
impl UnsafeUnpin for Registry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more