fn mapping_registry_address_to_script_hash(
        &mut self,
        addr: RegistryAddress,
        script_hash: H256,
    ) -> Result<(), Error> {
        // Only support addr len == 20 for now, we can revisit the condition in later version
        if addr.address.len() != 20 {
            return Err(Error::InvalidArgs);
        }
        if script_hash.is_zero() {
            return Err(Error::InvalidArgs);
        }
        if addr.registry_id != ETH_REGISTRY_ACCOUNT_ID {
            return Err(Error::InvalidArgs);
        }
        // Check duplication
        if self
            .get_registry_address_by_script_hash(addr.registry_id, &script_hash)?
            .is_some()
        {
            return Err(Error::DuplicatedRegistryAddress);
        }
        if self.get_script_hash_by_registry_address(&addr)?.is_some() {
            return Err(Error::DuplicatedRegistryAddress);
        }
        // script hash -> registry address
        {
            let key = build_script_hash_to_registry_address_key(&script_hash);
            let mut addr_buf = [0u8; 32];
            addr.write_to_slice(&mut addr_buf)
                .expect("write addr to buf");
            self.update_value(addr.registry_id, &key, addr_buf.into())?;
        }
        // registry address -> script hash
        {
            let key = build_registry_address_to_script_hash_key(&addr);
            self.update_value(addr.registry_id, &key, script_hash)?;
        }
        Ok(())
    }
/// This function create a bi-direction mapping between registry address & script_hash
This function create a bi-direction mapping between registry address & script_hash
This function create a bi - direction mapping between registry address & script_hash
fn mapping_registry_address_to_script_hash(
        &mut self,
        addr: RegistryAddress,
        script_hash: H256,
    ) -> Result<(), Error> {
        // Only support addr len == 20 for now, we can revisit the condition in later version
        if addr.address.len() != 20 {
            return Err(Error::InvalidArgs);
        }
        if script_hash.is_zero() {
            return Err(Error::InvalidArgs);
        }
        if addr.registry_id != ETH_REGISTRY_ACCOUNT_ID {
            return Err(Error::InvalidArgs);
        }
        // Check duplication
        if self
            .get_registry_address_by_script_hash(addr.registry_id, &script_hash)?
            .is_some()
        {
            return Err(Error::DuplicatedRegistryAddress);
        }
        if self.get_script_hash_by_registry_address(&addr)?.is_some() {
            return Err(Error::DuplicatedRegistryAddress);
        }
        // script hash -> registry address
        {
            let key = build_script_hash_to_registry_address_key(&script_hash);
            let mut addr_buf = [0u8; 32];
            addr.write_to_slice(&mut addr_buf)
                .expect("write addr to buf");
            self.update_value(addr.registry_id, &key, addr_buf.into())?;
        }
        // registry address -> script hash
        {
            let key = build_registry_address_to_script_hash_key(&addr);
            self.update_value(addr.registry_id, &key, script_hash)?;
        }
        Ok(())
    }
fn mapping_registry_address_to_script_hash ( & mut self , addr : RegistryAddress , script_hash : H256 , ) -> Result < ( ) , Error > { // Only support addr len == 20 for now, we can revisit the condition in later version if addr . address . len ( ) != 20 { return Err ( Error :: InvalidArgs ) ; } if script_hash . is_zero ( ) { return Err ( Error :: InvalidArgs ) ; } if addr . registry_id != ETH_REGISTRY_ACCOUNT_ID { return Err ( Error :: InvalidArgs ) ; } // Check duplication if self . get_registry_address_by_script_hash ( addr . registry_id , & script_hash ) ? . is_some ( ) { return Err ( Error :: DuplicatedRegistryAddress ) ; } if self . get_script_hash_by_registry_address ( & addr ) ? . is_some ( ) { return Err ( Error :: DuplicatedRegistryAddress ) ; } // script hash -> registry address { let key = build_script_hash_to_registry_address_key ( & script_hash ) ; let mut addr_buf = [ 0u8 ; 32 ] ; addr . write_to_slice ( & mut addr_buf ) . expect ( " " ) ; self . update_value ( addr . registry_id , & key , addr_buf . into ( ) ) ? ; } // registry address -> script hash { let key = build_registry_address_to_script_hash_key ( & addr ) ; self . update_value ( addr . registry_id , & key , script_hash ) ? ; } Ok ( ( ) ) }
This function create a bi-direction mapping between registry address & script_hash
This function create a bi - direction mapping between registry address & script_hash
&mut self
addr
RegistryAddress
script_hash
H256
&mut self
addr
RegistryAddress
script_hash
H256