/// Fetches the last value stored under `key` in the registry and prints it.
Fetches the last value stored under `key` in the registry and prints it.
Fetches the last value stored under ` key ` in the registry and prints it .
async fn print_and_get_last_value<T: Message + Default + serde::Serialize>(
    key: Vec<u8>,
    registry: &RegistryCanister,
) -> T {
    let value = registry.get_value(key.clone(), None).await;
    match value.clone() {
        Ok((bytes, version)) => {
            if key.starts_with(b"subnet_record_") {
                // subnet records are emitted as JSON
                let value = SubnetRecordProto::decode(&bytes[..])
                    .expect("Error decoding value from registry.");
                let subnet_record = SubnetRecord::from(&value);
                let mut registry = Registry {
                    version,
                    ..Default::default()
                };
                let record = RegistryRecord {
                    key: std::str::from_utf8(&key)
                        .expect("key is not a str")
                        .to_string(),
                    version,
                    value: RegistryValue::SubnetRecord(subnet_record),
                };
                registry.records.push(record);
                println!("{}", serde_json::to_string_pretty(&registry).unwrap());
            } else if key == b"provisional_whitelist" {
                let value = ProvisionalWhitelistProto::decode(&bytes[..])
                    .expect("Error decoding value from registry.");
                let provisional_whitelist = ProvisionalWhitelistRecord::from(value);
                let mut registry = Registry {
                    version,
                    ..Default::default()
                };
                let record = RegistryRecord {
                    key: std::str::from_utf8(&key)
                        .expect("key is not a str")
                        .to_string(),
                    version,
                    value: RegistryValue::ProvisionalWhitelistRecord(provisional_whitelist),
                };
                registry.records.push(record);
                println!("{}", serde_json::to_string_pretty(&registry).unwrap());
            } else {
                // Everything is dumped as debug representation
                println!(
                    "Fetching the most recent value for key: {:?}",
                    std::str::from_utf8(&key).unwrap()
                );
                let value = T::decode(&bytes[..]).expect("Error decoding value from registry.");
                println!("Most recent version is {:?}. Value:\n{:?}", version, value);
            }
        }
        Err(error) => {
            let msg = match error {
                Error::KeyNotPresent(key) => format!(
                    "Key not present: {}",
                    std::str::from_utf8(&key).expect("key is not a str")
                ),
                _ => format!("{:?}", error),
            };
            panic!("Error getting value from registry: {}", msg);
        }
    };
    value
        .map(|(bytes, _version)| T::decode(&bytes[..]).unwrap())
        .unwrap()
}
async fn print_and_get_last_value < T : Message + Default + serde :: Serialize > ( key : Vec < u8 > , registry : & RegistryCanister , ) -> T { let value = registry . get_value ( key . clone ( ) , None ) . await ; match value . clone ( ) { Ok ( ( bytes , version ) ) => { if key . starts_with ( b" " ) { // subnet records are emitted as JSON let value = SubnetRecordProto :: decode ( & bytes [ .. ] ) . expect ( " " ) ; let subnet_record = SubnetRecord :: from ( & value ) ; let mut registry = Registry { version , .. Default :: default ( ) } ; let record = RegistryRecord { key : std :: str :: from_utf8 ( & key ) . expect ( " " ) . to_string ( ) , version , value : RegistryValue :: SubnetRecord ( subnet_record ) , } ; registry . records . push ( record ) ; println ! ( " " serde_json to_string_pretty ( registry ) unwrap ( ) ) ; } else if key == b" " { let value = ProvisionalWhitelistProto :: decode ( & bytes [ .. ] ) . expect ( " " ) ; let provisional_whitelist = ProvisionalWhitelistRecord :: from ( value ) ; let mut registry = Registry { version , .. Default :: default ( ) } ; let record = RegistryRecord { key : std :: str :: from_utf8 ( & key ) . expect ( " " ) . to_string ( ) , version , value : RegistryValue :: ProvisionalWhitelistRecord ( provisional_whitelist ) , } ; registry . records . push ( record ) ; println ! ( " " serde_json to_string_pretty ( registry ) unwrap ( ) ) ; } else { // Everything is dumped as debug representation println ! ( " " std str from_utf8 ( key ) unwrap ( ) ) ; let value = T :: decode ( & bytes [ .. ] ) . expect ( " " ) ; println ! ( " \n " version value ) ; } } Err ( error ) => { let msg = match error { Error :: KeyNotPresent ( key ) => format ! ( " " std str from_utf8 ( key ) expect ( " " ) ) , _ => format ! ( " " error ) , } ; panic ! ( " " msg ) ; } } ; value . map ( | ( bytes , _version ) | T :: decode ( & bytes [ .. ] ) . unwrap ( ) ) . unwrap ( ) }
Fetches the last value stored under `key` in the registry and prints it.
Fetches the last value stored under ` key ` in the registry and prints it .
key
Vec<u8>
registry
&RegistryCanister