fix ens contenthash resolution
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
3d1a1c5be9
commit
430a8fb27c
|
@ -7,7 +7,8 @@
|
||||||
(:refer-clojure :exclude [name])
|
(:refer-clojure :exclude [name])
|
||||||
(:require [clojure.string :as string]
|
(:require [clojure.string :as string]
|
||||||
[status-im.ethereum.core :as ethereum]
|
[status-im.ethereum.core :as ethereum]
|
||||||
[status-im.ethereum.json-rpc :as json-rpc]))
|
[status-im.ethereum.json-rpc :as json-rpc]
|
||||||
|
[status-im.ethereum.abi-spec :as abi-spec]))
|
||||||
|
|
||||||
;; this is the addresses of ens registries for the different networks
|
;; this is the addresses of ens registries for the different networks
|
||||||
(def ens-registries
|
(def ens-registries
|
||||||
|
@ -105,10 +106,21 @@
|
||||||
:on-success
|
:on-success
|
||||||
(fn [raw-hash]
|
(fn [raw-hash]
|
||||||
;; NOTE: it would be better if our abi-spec/decode was able to do that
|
;; NOTE: it would be better if our abi-spec/decode was able to do that
|
||||||
(let [hash (subs raw-hash 130)
|
(let [;; ignore hex prefix
|
||||||
[cid & hash-and-zeros] (string/split hash "1b20")
|
[_ raw-hash-rest] (split-at 2 raw-hash)
|
||||||
hash (str "0x" cid "1b20" (subs (apply str hash-and-zeros) 0 64))]
|
;; the first field gives us the length of the next one in hex and has
|
||||||
(cb hash)))}))
|
;; a length of 32 bytes
|
||||||
|
;; 1 byte is 2 chars here
|
||||||
|
[next-field-length-hex raw-hash-rest] (split-at 64 raw-hash-rest)
|
||||||
|
next-field-length (* ^number (abi-spec/hex-to-number (string/join next-field-length-hex)) 2)
|
||||||
|
;; we get the next field which is the length of the hash and is
|
||||||
|
;; expected to be 32 bytes as well
|
||||||
|
[hash-field-length-hex raw-hash-rest] (split-at next-field-length
|
||||||
|
raw-hash-rest)
|
||||||
|
hash-field-length (* ^number (abi-spec/hex-to-number (string/join hash-field-length-hex)) 2)
|
||||||
|
;; we get the hash
|
||||||
|
[hash _] (split-at hash-field-length raw-hash-rest)]
|
||||||
|
(cb (string/join "0x" hash))))}))
|
||||||
|
|
||||||
(defn content
|
(defn content
|
||||||
[resolver ens-name cb]
|
[resolver ens-name cb]
|
||||||
|
|
|
@ -32,10 +32,9 @@
|
||||||
(cond
|
(cond
|
||||||
(and (string/starts-with? hex "0xe40101"))
|
(and (string/starts-with? hex "0xe40101"))
|
||||||
;; content type can be 2 or 4 bytes
|
;; content type can be 2 or 4 bytes
|
||||||
;; we expect 1b20 (hash algorithm and hash length 64)
|
;; we expect 1b20 (hash algorithm keccak256 and hash length 64)
|
||||||
;; before the hash so we split the contenthash there
|
;; before the hash so we split the contenthash there
|
||||||
(when-let [hash (second (string/split hex "1b20"))]
|
(when-let [hash (second (string/split hex "1b20"))]
|
||||||
(when (= 0x20 (count hash)))
|
|
||||||
{:namespace :swarm
|
{:namespace :swarm
|
||||||
:hash hash})
|
:hash hash})
|
||||||
(and (= 78 (count hex))
|
(and (= 78 (count hex))
|
||||||
|
|
Loading…
Reference in New Issue