mirror of
https://github.com/status-im/status-react.git
synced 2025-02-18 13:58:24 +00:00
[Fixes #6784] Fixed some ABI codec issues
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
parent
f78f98ff6f
commit
ee4cafbbe3
@ -51,7 +51,7 @@
|
|||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:extensions/ethereum-send-transaction
|
:extensions/ethereum-send-transaction
|
||||||
(fn [{db :db} [_ {:keys [method params on-result] :as arguments}]]
|
(fn [{db :db} [_ _ {:keys [method params on-result] :as arguments}]]
|
||||||
(let [tx-object (assoc (select-keys arguments [:to :gas :gas-price :value :nonce])
|
(let [tx-object (assoc (select-keys arguments [:to :gas :gas-price :value :nonce])
|
||||||
:data (when (and method params) (abi-spec/encode method params)))
|
:data (when (and method params) (abi-spec/encode method params)))
|
||||||
transaction (prepare-extension-transaction tx-object (:contacts/contacts db) on-result)]
|
transaction (prepare-extension-transaction tx-object (:contacts/contacts db) on-result)]
|
||||||
@ -59,7 +59,7 @@
|
|||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:extensions/ethereum-call
|
:extensions/ethereum-call
|
||||||
(fn [_ [_ {:keys [to method params outputs on-result]}]]
|
(fn [_ [_ _ {:keys [to method params outputs on-result]}]]
|
||||||
(let [tx-object {:to to :data (when method (abi-spec/encode method params))}]
|
(let [tx-object {:to to :data (when method (abi-spec/encode method params))}]
|
||||||
{:browser/call-rpc [{"jsonrpc" "2.0"
|
{:browser/call-rpc [{"jsonrpc" "2.0"
|
||||||
"method" "eth_call"
|
"method" "eth_call"
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
(.hexToUtf8 utils (str "0x" x)))
|
(.hexToUtf8 utils (str "0x" x)))
|
||||||
|
|
||||||
(defn hex-to-number [x]
|
(defn hex-to-number [x]
|
||||||
(.hexToNumber utils (str "0x" x)))
|
(.toNumber (dependencies/Web3.prototype.toBigNumber (str "0x" x) 16)))
|
||||||
|
|
||||||
(defn sha3 [s]
|
(defn sha3 [s]
|
||||||
(.sha3 utils (str s)))
|
(.sha3 utils (str s)))
|
||||||
@ -59,21 +59,20 @@
|
|||||||
;; higher-order (left) side with 0xff for negative X and with zero bytes for
|
;; higher-order (left) side with 0xff for negative X and with zero bytes for
|
||||||
;; positive X such that the length is 32 bytes.
|
;; positive X such that the length is 32 bytes.
|
||||||
(defmethod enc :int
|
(defmethod enc :int
|
||||||
[{:keys [value]
|
[{:keys [value]}]
|
||||||
:or {size 256}}]
|
|
||||||
(to-two-complement value))
|
(to-two-complement value))
|
||||||
|
|
||||||
;; uint<M>: enc(X) is the big-endian encoding of X, padded on the
|
;; uint<M>: enc(X) is the big-endian encoding of X, padded on the
|
||||||
;; higher-order (left) side with zero-bytes such that the length is 32 bytes.
|
;; higher-order (left) side with zero-bytes such that the length is 32 bytes.
|
||||||
(defmethod enc :uint
|
(defmethod enc :uint
|
||||||
[{:keys [value]
|
[{:keys [value]}]
|
||||||
:or {size 256}}]
|
|
||||||
(left-pad (number-to-hex value)))
|
(left-pad (number-to-hex value)))
|
||||||
|
|
||||||
;; address: as in the uint160 case
|
;; address: as in the uint160 case
|
||||||
(defmethod enc :address
|
(defmethod enc :address
|
||||||
[{:keys [value]}]
|
[{:keys [value]}]
|
||||||
(right-pad value))
|
(when value
|
||||||
|
(left-pad (string/replace value "0x" ""))))
|
||||||
|
|
||||||
;; bytes, of length k (which is assumed to be of type uint256):
|
;; bytes, of length k (which is assumed to be of type uint256):
|
||||||
;; enc(X) = enc(k) pad_right(X), i.e. the number of bytes is encoded as a
|
;; enc(X) = enc(k) pad_right(X), i.e. the number of bytes is encoded as a
|
||||||
@ -85,7 +84,7 @@
|
|||||||
(defmethod enc :bytes
|
(defmethod enc :bytes
|
||||||
[{:keys [value size dynamic?]
|
[{:keys [value size dynamic?]
|
||||||
:or {size 256}}]
|
:or {size 256}}]
|
||||||
;; in the exemples of the abi specifications strings are passed for
|
;; in the examples of the abi specifications strings are passed for
|
||||||
;; bytes parameters, in our ens resolver we pass encoded bytes directly
|
;; bytes parameters, in our ens resolver we pass encoded bytes directly
|
||||||
;; for namehash, this handles both cases by checking if the value is already
|
;; for namehash, this handles both cases by checking if the value is already
|
||||||
;; hex
|
;; hex
|
||||||
@ -160,9 +159,9 @@
|
|||||||
(defmethod enc :tuple
|
(defmethod enc :tuple
|
||||||
[{:keys [value]}]
|
[{:keys [value]}]
|
||||||
(let [[len x] (reduce
|
(let [[len x] (reduce
|
||||||
(fn [[len acc] {:keys [type value] :as x}]
|
(fn [[len acc] {:keys [dynamic?] :as x}]
|
||||||
(let [enc-x (enc x)]
|
(let [enc-x (enc x)]
|
||||||
(if (:dynamic? x)
|
(if dynamic?
|
||||||
[(+ len 32)
|
[(+ len 32)
|
||||||
(conj acc (assoc x :tail enc-x))]
|
(conj acc (assoc x :tail enc-x))]
|
||||||
[(+ len (/ (count enc-x) 2))
|
[(+ len (/ (count enc-x) 2))
|
||||||
|
@ -16,7 +16,10 @@
|
|||||||
"0x8be6524600000000000000000000000000000000000000000000000000000000000001230000000000000000000000000000000000000000000000000000000000000080313233343536373839300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004560000000000000000000000000000000000000000000000000000000000000789000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000"))
|
"0x8be6524600000000000000000000000000000000000000000000000000000000000001230000000000000000000000000000000000000000000000000000000000000080313233343536373839300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004560000000000000000000000000000000000000000000000000000000000000789000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000"))
|
||||||
|
|
||||||
(is (= (abi-spec/encode "g(uint[][],string[])" [[[1 2] [3]] ["one" "two" "three"]])
|
(is (= (abi-spec/encode "g(uint[][],string[])" [[[1 2] [3]] ["one" "two" "three"]])
|
||||||
"0xad6a3446000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000036f6e650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000374776f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000057468726565000000000000000000000000000000000000000000000000000000")))
|
"0xad6a3446000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000036f6e650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000374776f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000057468726565000000000000000000000000000000000000000000000000000000"))
|
||||||
|
|
||||||
|
(is (= (abi-spec/encode "getExpectedRate(address,address,uint256)" ["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" 1000])
|
||||||
|
"0x809a9e55000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee00000000000000000000000000000000000000000000000000000000000003e8")))
|
||||||
|
|
||||||
(deftest test-decode
|
(deftest test-decode
|
||||||
(is (= (abi-spec/decode "000000000000000000000000000000000000000000000000000000005bc741cd00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000013b86dbf1a83c9e6a492914a0ee39e8a5b7eb60700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e516d533152484e4a57414b356e426f6f57454d34654d644268707a35666e325764557473457357754a4b79356147000000000000000000000000000000000000"
|
(is (= (abi-spec/decode "000000000000000000000000000000000000000000000000000000005bc741cd00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000013b86dbf1a83c9e6a492914a0ee39e8a5b7eb60700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e516d533152484e4a57414b356e426f6f57454d34654d644268707a35666e325764557473457357754a4b79356147000000000000000000000000000000000000"
|
||||||
@ -27,6 +30,14 @@
|
|||||||
0
|
0
|
||||||
0)))
|
0)))
|
||||||
|
|
||||||
|
(is (= (abi-spec/decode "0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000d7621dc58210000"
|
||||||
|
["uint256" "uint256"])
|
||||||
|
'(1000000000000000000 970000000000000000)))
|
||||||
|
|
||||||
|
(is (= (abi-spec/decode "000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee00000000000000000000000000000000000000000000000000000000000003e8"
|
||||||
|
["address" "address" "uint256"])
|
||||||
|
'("0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" 1000)))
|
||||||
|
|
||||||
(is (= (abi-spec/decode "00000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001"
|
(is (= (abi-spec/decode "00000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001"
|
||||||
["uint32" "bool"])
|
["uint32" "bool"])
|
||||||
'(69 true)))
|
'(69 true)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user