mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
make natspec/contractinfo fetching to try looking up content via bzz if docserver has the scheme registered, if fails, falls back to urlhint
This commit is contained in:
parent
618c5d7053
commit
a9aed92a4b
2 changed files with 18 additions and 4 deletions
|
|
@ -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) {
|
func (self *DocServer) Get(uri, path string) (content []byte, err error) {
|
||||||
// retrieve content
|
// retrieve content
|
||||||
resp, err := self.Client().Get(uri)
|
resp, err := self.Client().Get(uri)
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ func New(xeth *xeth.XEth, jsontx string, http *docserver.DocServer) (self *NatSp
|
||||||
}
|
}
|
||||||
|
|
||||||
// also called by admin.contractInfo.get
|
// 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
|
// retrieve contract hash from state
|
||||||
codehex := xeth.CodeAt(contractAddress)
|
codehex := xeth.CodeAt(contractAddress)
|
||||||
codeb := xeth.CodeAtBytes(contractAddress)
|
codeb := xeth.CodeAtBytes(contractAddress)
|
||||||
|
|
@ -102,17 +102,29 @@ func FetchDocsForContract(contractAddress string, xeth *xeth.XEth, http *docserv
|
||||||
res := resolver.New(xeth)
|
res := resolver.New(xeth)
|
||||||
|
|
||||||
// resolve host via HashReg/UrlHint Resolver
|
// 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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// get content via http client and authenticate content using hash
|
// 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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue