fn encode_intkey(map: BTreeMap<String, u32>) -> Result<String, ApplyError> {
    // First two characters should be A followed by the number of elements.
    // Only check for A as this will be a map with 15 or less elements
    // It is unlikely that an address will have that many hash collisions
    let mut hex_string = "A".to_string();
    let map_length = map.len() as u32;
    hex_string = hex_string + &format!("{:X}", map_length);

    let keys: Vec<_> = map.keys().cloned().collect();
    for key in keys {
        // Keys need to have a length between 1 and 20
        let key_length = key.len();
        if key_length < 1 || key_length > 20 {
            return Err(ApplyError::InvalidTransaction(String::from(
                "Key must be at least 1 character and no more than 20",
            )));
        }

        // 96 is equal to 60 hex and is the starting byte for strings.
        let length = 96 + key_length;

        // If value is less then 23, the hex of that number is used as the value.
        // If the value is more then 23 the first two bytes start at hex 18 and increment
        // for more bytes. 18 = 2, 19 = 4, 1A = 8. Should not exeed 8 bytes.
        let encoded_key = encode_upper(key.clone());
        let raw_value = map
            .get(&key)
            .ok_or_else(|| ApplyError::InvalidTransaction("Value from map".into()))?;
        if *raw_value > (23 as u32) {
            let mut value = format!("{:02X}", raw_value);
            if value.len() % 2 == 1 {
                value = "0".to_string() + &value.clone();
            }

            let value_length = match value.len() {
                2 => "18",
                4 => "19",
                8 => "1A",
                _ => {
                    return Err(ApplyError::InvalidTransaction(String::from(
                        "Value is too large",
                    )));
                }
            };
            hex_string =
                hex_string + &format!("{:X}", length) + &encoded_key + value_length + &value;
        } else {
            hex_string = hex_string
                + &format!("{:X}", length)
                + &encoded_key
                + &format!("{:02X}", raw_value);
        }
    }
    Ok(hex_string)
}
// helper function to convert intkey_state to cbor. This is required becasue cbor does not compile
// into wasm at the time this was written.
helper function to convert intkey_state to cbor. This is required becasue cbor does not compile
into wasm at the time this was written.
helper function to convert intkey_state to cbor . This is required becasue cbor does not compile into wasm at the time this was written .
fn encode_intkey(map: BTreeMap<String, u32>) -> Result<String, ApplyError> {
    // First two characters should be A followed by the number of elements.
    // Only check for A as this will be a map with 15 or less elements
    // It is unlikely that an address will have that many hash collisions
    let mut hex_string = "A".to_string();
    let map_length = map.len() as u32;
    hex_string = hex_string + &format!("{:X}", map_length);
    let keys: Vec<_> = map.keys().cloned().collect();
    for key in keys {
        // Keys need to have a length between 1 and 20
        let key_length = key.len();
        if key_length < 1 || key_length > 20 {
            return Err(ApplyError::InvalidTransaction(String::from(
                "Key must be at least 1 character and no more than 20",
            )));
        }
        // 96 is equal to 60 hex and is the starting byte for strings.
        let length = 96 + key_length;
        // If value is less then 23, the hex of that number is used as the value.
        // If the value is more then 23 the first two bytes start at hex 18 and increment
        // for more bytes. 18 = 2, 19 = 4, 1A = 8. Should not exeed 8 bytes.
        let encoded_key = encode_upper(key.clone());
        let raw_value = map
            .get(&key)
            .ok_or_else(|| ApplyError::InvalidTransaction("Value from map".into()))?;
        if *raw_value > (23 as u32) {
            let mut value = format!("{:02X}", raw_value);
            if value.len() % 2 == 1 {
                value = "0".to_string() + &value.clone();
            }
            let value_length = match value.len() {
                2 => "18",
                4 => "19",
                8 => "1A",
                _ => {
                    return Err(ApplyError::InvalidTransaction(String::from(
                        "Value is too large",
                    )));
                }
            };
            hex_string =
                hex_string + &format!("{:X}", length) + &encoded_key + value_length + &value;
        } else {
            hex_string = hex_string
                + &format!("{:X}", length)
                + &encoded_key
                + &format!("{:02X}", raw_value);
        }
    }
    Ok(hex_string)
}
fn encode_intkey ( map : BTreeMap < String , u32 > ) -> Result < String , ApplyError > { // First two characters should be A followed by the number of elements. // Only check for A as this will be a map with 15 or less elements // It is unlikely that an address will have that many hash collisions let mut hex_string = " " . to_string ( ) ; let map_length = map . len ( ) as u32 ; hex_string = hex_string + & format ! ( " " map_length ) ; let keys : Vec < _ > = map . keys ( ) . cloned ( ) . collect ( ) ; for key in keys { // Keys need to have a length between 1 and 20 let key_length = key . len ( ) ; if key_length < 1 || key_length > 20 { return Err ( ApplyError :: InvalidTransaction ( String :: from ( " " , ) ) ) ; } // 96 is equal to 60 hex and is the starting byte for strings. let length = 96 + key_length ; // If value is less then 23, the hex of that number is used as the value. // If the value is more then 23 the first two bytes start at hex 18 and increment // for more bytes. 18 = 2, 19 = 4, 1A = 8. Should not exeed 8 bytes. let encoded_key = encode_upper ( key . clone ( ) ) ; let raw_value = map . get ( & key ) . ok_or_else ( | | ApplyError :: InvalidTransaction ( " " . into ( ) ) ) ? ; if * raw_value > ( 23 as u32 ) { let mut value = format ! ( " " raw_value ) ; if value . len ( ) % 2 == 1 { value = " " . to_string ( ) + & value . clone ( ) ; } let value_length = match value . len ( ) { 2 => " " , 4 => " " , 8 => " " , _ => { return Err ( ApplyError :: InvalidTransaction ( String :: from ( " " , ) ) ) ; } } ; hex_string = hex_string + & format ! ( " " length ) + & encoded_key + value_length + & value ; } else { hex_string = hex_string + & format ! ( " " length ) + & encoded_key + & format ! ( " " raw_value ) ; } } Ok ( hex_string ) }
helper function to convert intkey_state to cbor.
helper function to convert intkey_state to cbor .
map
BTreeMap<String, u32>
map
BTreeMap<String, u32>