diff options
author | zelig <viktor.tron@gmail.com> | 2015-03-31 08:57:17 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-04-20 03:57:48 +0800 |
commit | 97a602864a485bb3a79f460077052bd76cdbff99 (patch) | |
tree | 8c3e7de5e87cb40fe16e34b4e9075c22d6497890 /common | |
parent | 45676382b6cdf3720600647bdd76e4a89fa4495f (diff) | |
download | go-tangerine-97a602864a485bb3a79f460077052bd76cdbff99.tar.gz go-tangerine-97a602864a485bb3a79f460077052bd76cdbff99.tar.zst go-tangerine-97a602864a485bb3a79f460077052bd76cdbff99.zip |
add common/resolver skeleton
Diffstat (limited to 'common')
-rw-r--r-- | common/resolver/resolver.go | 45 | ||||
-rw-r--r-- | common/resolver/resolver_test.go | 17 |
2 files changed, 62 insertions, 0 deletions
diff --git a/common/resolver/resolver.go b/common/resolver/resolver.go new file mode 100644 index 000000000..aa54a689b --- /dev/null +++ b/common/resolver/resolver.go @@ -0,0 +1,45 @@ +package resolver + +import ( + "fmt" + "net/url" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/xeth" +) + +/* +Resolver implements the Ethereum DNS mapping +NameReg : Domain Name (or Code hash of Contract) -> Content Hash +UrlHint : Content Hash -> Url Hint +*/ +const ( + urlHintContractAddress = "urlhint" + nameRegContractAddress = "nameReg" +) + +type Resolver struct { + xeth *xeth.XEth +} + +func (self *Resolver) NameToContentHash(name string) (hash common.Hash, err error) { + // look up in nameReg + copy(hash[:], []byte(name)[:32]) + return +} + +func (self *Resolver) ContentHashToUrl(hash common.Hash) (uri *url.URL, err error) { + // look up in nameReg + rawurl := fmt.Sprintf("bzz://%x/my/path/mycontract.sud", hash[:]) + // mime type? + return url.Parse(rawurl) +} + +func (self *Resolver) NameToUrl(name string) (uri *url.URL, err error) { + // look up in urlHint + hash, err := self.NameToContentHash(name) + if err != nil { + return + } + return self.ContentHashToUrl(hash) +} diff --git a/common/resolver/resolver_test.go b/common/resolver/resolver_test.go new file mode 100644 index 000000000..ce0116664 --- /dev/null +++ b/common/resolver/resolver_test.go @@ -0,0 +1,17 @@ +package resolver + +import ( + "testing" +) + +func TestNameToContentHash(t *testing.T) { + +} + +func TestContentHashToUrl(t *testing.T) { + +} + +func TestNameToUrl(t *testing.T) { + +} |