// HashToHash(key) resolves contenthash for key (a hash) using HashReg // resolution is costless non-transactional // implemented as direct retrieval from db func (self *Registrar) HashToHash(khash common.Hash) (chash common.Hash, err error) { // look up in hashReg at := HashRegAddr[2:] key := storageAddress(storageMapping(storageIdx2Addr(1), khash[:])) hash := self.backend.StorageAt(at, key) if hash == "0x0" || len(hash) < 3 || (hash == common.Hash{}.Hex()) { err = fmt.Errorf("content hash not found for '%v'", khash.Hex()) return } copy(chash[:], common.Hex2BytesFixed(hash[2:], 32)) return }
// HashToUrl(contenthash) resolves the url for contenthash using UrlHint // resolution is costless non-transactional // implemented as direct retrieval from db // if we use content addressed storage, this step is no longer necessary func (self *Registrar) HashToUrl(chash common.Hash) (uri string, err error) { // look up in URL reg var str string = " " var idx uint32 for len(str) > 0 { mapaddr := storageMapping(storageIdx2Addr(1), chash[:]) key := storageAddress(storageFixedArray(mapaddr, storageIdx2Addr(idx))) hex := self.backend.StorageAt(UrlHintAddr[2:], key) str = string(common.Hex2Bytes(hex[2:])) l := 0 for (l < len(str)) && (str[l] == 0) { l++ } str = str[l:] uri = uri + str idx++ } if len(uri) == 0 { err = fmt.Errorf("GetURLhint: URL hint not found for '%v'", chash.Hex()) } return }