Skip to main content

Registry

Struct Registry 

Source
pub struct Registry { /* private fields */ }
Expand description

Try registered decoders in order, ending with the disassembly fallback.

Implementations§

Source§

impl Registry

Source

pub fn register(&mut self, decoder: Box<dyn StateDecoder>)

Source

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(&reg, 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(&reg, 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
Hide additional 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§

Source§

impl Default for Registry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.