// Resolve does the following:
// 1. If data is provided (not nil), then it will be stored via the local CAS. That data passed in will then simply be
//    returned back to the caller, along with the hashlink of the stored data.
// 2. If data is not provided (is nil), then the local CAS will be checked to see if it has data at the cid provided.
//    If it does, then it is returned. If it doesn't, and a webCASURL is provided, then the data will be retrieved by
//    querying the webCASURL. This data will then get stored in the local CAS.
//    Finally, the data is returned to the caller, along with the hashlink of the stored data.
// In both cases above, the CID produced by the local CAS will be checked against the cid passed in to ensure they are
// the same.
Resolve does the following:
1. If data is provided (not nil), then it will be stored via the local CAS. That data passed in will then simply be
returned back to the caller, along with the hashlink of the stored data.
2. If data is not provided (is nil), then the local CAS will be checked to see if it has data at the cid provided.
If it does, then it is returned. If it doesn't, and a webCASURL is provided, then the data will be retrieved by
querying the webCASURL. This data will then get stored in the local CAS.
Finally, the data is returned to the caller, along with the hashlink of the stored data.
In both cases above, the CID produced by the local CAS will be checked against the cid passed in to ensure they are
the same.
// Resolve does the following : // 1 . If data is provided ( not nil ) then it will be stored via the local CAS . That data passed in will then simply be // returned back to the caller along with the hashlink of the stored data . // 2 . If data is not provided ( is nil ) then the local CAS will be checked to see if it has data at the cid provided . // If it does then it is returned . If it doesn ' t and a webCASURL is provided then the data will be retrieved by // querying the webCASURL . This data will then get stored in the local CAS . // Finally the data is returned to the caller along with the hashlink of the stored data . // In both cases above the CID produced by the local CAS will be checked against the cid passed in to ensure they are // the same .
func (h *Resolver) Resolve(_ *url.URL, hashWithPossibleHint string, data []byte) ([]byte, string, error) { 
	startTime := time.Now()
	defer func() { h.metrics.CASResolveTime(time.Since(startTime)) }()
	resourceHash, domain, links, err := h.getResourceHashWithPossibleDomainAndLinks(hashWithPossibleHint)
	if err != nil {
		return nil, "", fmt.Errorf("failed to get resource hash from[%s]: %w", hashWithPossibleHint, err)
	}
	if data != nil {
		localHL, e := h.storeLocallyAndVerifyHash(data, resourceHash)
		if e != nil {
			return nil, "", fmt.Errorf("failed to store the data in the local CAS: %w", e)
		}
		return data, localHL, nil
	}
	casLinks, ipfsLinks := separateLinks(links)
	logger.Debugf("resolving hashWithPossibleHint[%s], resource hash[%s], domain[%s], cas links%s, ipfs links%s", hashWithPossibleHint, resourceHash, domain, casLinks, ipfsLinks) 
	if h.localCAS.GetPrimaryWriterType() == "ipfs" && len(ipfsLinks) > 0 {
		cid := ipfsLinks[0][len(ipfsPrefix):]
		data, e := h.localCAS.Read(cid)
		if e != nil {
			return nil, "", fmt.Errorf("read from IPFS: %w", e)
		}
		return data, "", nil
	}
	dataFromLocal, err := h.localCAS.Read(resourceHash)
	if err != nil { 
		if errors.Is(err, orberrors.ErrContentNotFound) {
			if len(casLinks) > 0 {
				dataFromRemote, localHL, errGetAndStoreRemoteData := h.getAndStoreDataFromWebCASEndpoints(casLinks, resourceHash)
				if errGetAndStoreRemoteData != nil {
					return nil, "", fmt.Errorf("failure while getting and storing data from the remote "+
						"WebCAS endpoints: %w", errGetAndStoreRemoteData)
				}
				return dataFromRemote, localHL, nil
			}
			if h.ipfsReader != nil && len(ipfsLinks) > 0 {
				return h.getAndStoreDataFromIPFS(ipfsLinks[0][len(ipfsPrefix):], resourceHash)
			}
			if domain != "" {
				return h.getAndStoreDataFromDomain(domain, resourceHash)
			}
		}
		return nil, "", fmt.Errorf("failed to get data stored at %s from the local CAS: %w", resourceHash, err)
	}
	return dataFromLocal, "", nil
}
func ( h * Resolver ) Resolve ( _ * url . URL , hashWithPossibleHint string , data [ ] byte ) ( [ ] byte , string , error ) { startTime := time . Now ( ) defer func ( ) { h . metrics . CASResolveTime ( time . Since ( startTime ) ) } ( ) resourceHash , domain , links , err := h . getResourceHashWithPossibleDomainAndLinks ( hashWithPossibleHint ) if err != nil { return nil , " " , fmt . Errorf ( " " , hashWithPossibleHint , err ) } if data != nil { localHL , e := h . storeLocallyAndVerifyHash ( data , resourceHash ) if e != nil { return nil , " " , fmt . Errorf ( " " , e ) } return data , localHL , nil } casLinks , ipfsLinks := separateLinks ( links ) logger . Debugf ( " " , hashWithPossibleHint , resourceHash , domain , casLinks , ipfsLinks ) if h . localCAS . GetPrimaryWriterType ( ) == " " && len ( ipfsLinks ) > 0 { cid := ipfsLinks [ 0 ] [ len ( ipfsPrefix ) : ] data , e := h . localCAS . Read ( cid ) if e != nil { return nil , " " , fmt . Errorf ( " " , e ) } return data , " " , nil } dataFromLocal , err := h . localCAS . Read ( resourceHash ) if err != nil { if errors . Is ( err , orberrors . ErrContentNotFound ) { if len ( casLinks ) > 0 { dataFromRemote , localHL , errGetAndStoreRemoteData := h . getAndStoreDataFromWebCASEndpoints ( casLinks , resourceHash ) if errGetAndStoreRemoteData != nil { return nil , " " , fmt . Errorf ( " " + " " , errGetAndStoreRemoteData ) } return dataFromRemote , localHL , nil } if h . ipfsReader != nil && len ( ipfsLinks ) > 0 { return h . getAndStoreDataFromIPFS ( ipfsLinks [ 0 ] [ len ( ipfsPrefix ) : ] , resourceHash ) } if domain != " " { return h . getAndStoreDataFromDomain ( domain , resourceHash ) } } return nil , " " , fmt . Errorf ( " " , resourceHash , err ) } return dataFromLocal , " " , nil }
Resolve does the following:
1.
Resolve does the following : 1 .
//nolint:gocyclo,cyclop,lll //nolint:lll // Ensure we have the data stored in the local CAS. //nolint: nestif // Breaking this up seems worse than leaving the nested ifs