From a9aed92a4bfbd1a84f1e236d1736a179e99ed544 Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 2 Jun 2015 17:56:38 +0100 Subject: [PATCH] make natspec/contractinfo fetching to try looking up content via bzz if docserver has the scheme registered, if fails, falls back to urlhint --- common/docserver/docserver.go | 2 ++ common/natspec/natspec.go | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/common/docserver/docserver.go b/common/docserver/docserver.go index f719c71566..e900b45f5a 100644 --- a/common/docserver/docserver.go +++ b/common/docserver/docserver.go @@ -71,6 +71,8 @@ func (self *DocServer) GetAuthContent(uri string, hash common.Hash) (content []b } +// Get(uri, path) downloads the document at uri, if path is non-empty it +// is interpreted as a filepath to which the contents are saved func (self *DocServer) Get(uri, path string) (content []byte, err error) { // retrieve content resp, err := self.Client().Get(uri) diff --git a/common/natspec/natspec.go b/common/natspec/natspec.go index 7e5f053c70..dcd1fba477 100644 --- a/common/natspec/natspec.go +++ b/common/natspec/natspec.go @@ -88,7 +88,7 @@ func New(xeth *xeth.XEth, jsontx string, http *docserver.DocServer) (self *NatSp } // also called by admin.contractInfo.get -func FetchDocsForContract(contractAddress string, xeth *xeth.XEth, http *docserver.DocServer) (content []byte, err error) { +func FetchDocsForContract(contractAddress string, xeth *xeth.XEth, ds *docserver.DocServer) (content []byte, err error) { // retrieve contract hash from state codehex := xeth.CodeAt(contractAddress) codeb := xeth.CodeAtBytes(contractAddress) @@ -102,17 +102,29 @@ func FetchDocsForContract(contractAddress string, xeth *xeth.XEth, http *docserv res := resolver.New(xeth) // resolve host via HashReg/UrlHint Resolver - uri, hash, err := res.KeyToUrl(codehash) + hash, err := res.KeyToContentHash(codehash) + if err != nil { + return + } + if ds.HasScheme("bzz") { + content, err = ds.Get("bzz://"+hash.Hex(), "") + if err == nil { // non-fatal + return + } + err = nil + //falling back to urlhint + } + + uri, err := res.ContentHashToUrl(hash) if err != nil { return } // get content via http client and authenticate content using hash - content, err = http.GetAuthContent(uri, hash) + content, err = ds.GetAuthContent(uri, hash) if err != nil { return } - return }