diff --git a/contracts/ens/ens.go b/contracts/ens/ens.go index 8c356e6be2..62ccc76081 100644 --- a/contracts/ens/ens.go +++ b/contracts/ens/ens.go @@ -27,7 +27,6 @@ import ( "fmt" "strings" - mh "github.com/multiformats/go-multihash" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -35,7 +34,6 @@ import ( "github.com/ethereum/go-ethereum/contracts/ens/fallback_contract" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - "github.com/ipfs/go-cid" ) var ( @@ -266,27 +264,6 @@ func (ens *ENS) SetContentHash(name string, hash []byte) (*types.Transaction, er return resolver.Contract.SetContenthash(&opts, node, hash) } -func decodeMultiCodec(b []byte) (common.Hash, error) { - - // Create a cid from a marshaled string - _, err := cid.Decode(string(b)) - if err != nil { - return common.Hash{}, err - } - - return common.Hash{}, nil - /* from the EIP documentation - storage system: Swarm (0xe4) - CID version: 1 (0x01) - content type: swarm-manifest (0x??) - hash function: keccak-256 (0x1B) - hash length: 32 bytes (0x20) - hash: 29f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f - */ - // - -} - func manualDecode(buf []byte) (common.Hash, error) { if len(buf) < 2 { return common.Hash{}, errors.New("buffer too short") @@ -332,7 +309,7 @@ func manualDecode(buf []byte) (common.Hash, error) { } // encodeCid encodes a swarm hash into an IPLD CID -func encodeCid(h common.Hash) (cid.Cid, error) { +/*func encodeCid(h common.Hash) (cid.Cid, error) { b := []byte{0x1b, 0x20} //0x1b = keccak256 (should be changed to bmt), 0x20 = 32 bytes hash length b = append(b, h.Bytes()...) // append actual hash bytes multi, err := mh.Cast(b) @@ -343,4 +320,4 @@ func encodeCid(h common.Hash) (cid.Cid, error) { c := cid.NewCidV1(cid.Raw, multi) //todo: cid.Raw should be swarm manifest return c, nil -} +}*/ diff --git a/contracts/ens/ens_test.go b/contracts/ens/ens_test.go index 17600a05ac..132bf73d29 100644 --- a/contracts/ens/ens_test.go +++ b/contracts/ens/ens_test.go @@ -31,9 +31,6 @@ import ( "github.com/ethereum/go-ethereum/contracts/ens/fallback_contract" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/crypto" - "github.com/ipfs/go-cid" - "github.com/multiformats/go-multibase" - mh "github.com/multiformats/go-multihash" ) var ( @@ -130,24 +127,39 @@ func TestENS(t *testing.T) { func TestManuelCidDecode(t *testing.T) { // call cid encode method with hash. expect byte slice returned, compare according to spec bb := []byte{} - buf := make([]byte, binary.MaxVarintLen64) - for _, v := range []byte{0xe4, 0x01, 0x99, 0x1b, 0x20} { - n := binary.PutUvarint(buf, uint64(v)) - bb = append(bb, buf[:n]...) - } - h := common.HexToHash("29f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f") - bb = append(bb, h[:]...) - str := hex.EncodeToString(bb) - fmt.Println(str) - decodedHash, e := manualDecode(bb) - if e != nil { - t.Fatal(e) + for _, v := range []struct { + name string + headerBytes []byte + fails bool + }{ + { + name: "w00t", + headerBytes: []byte{0xe4, 0x01, 0x99, 0x1b, 0x20}, + fails: false, + }, + } { + buf := make([]byte, binary.MaxVarintLen64) + for _, vv := range v.headerBytes { + n := binary.PutUvarint(buf, uint64(vv)) + bb = append(bb, buf[:n]...) + } + + h := common.HexToHash("29f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f") + bb = append(bb, h[:]...) + str := hex.EncodeToString(bb) + fmt.Println(str) + decodedHash, e := manualDecode(bb) + if e != nil { + t.Fatal(e) + } + + if !bytes.Equal(decodedHash[:], h[:]) { + t.Fatal("hashes not equal") + } + } - if !bytes.Equal(decodedHash[:], h[:]) { - t.Fatal("hashes not equal") - } /* from the EIP documentation storage system: Swarm (0xe4) CID version: 1 (0x01) @@ -173,6 +185,7 @@ func TestManuelCidEncode(t *testing.T) { } +/* func TestCIDSanity(t *testing.T) { hashStr := "d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162" hash := common.HexToHash(hashStr) //this always yields a 32 byte long hash @@ -216,4 +229,4 @@ func TestCIDSanity(t *testing.T) { fmt.Sprintf("Got CID: %v", c) fmt.Println("Got CID:", c.Prefix()) -} +}*/