diff --git a/public/abi.html b/public/abi.html
index 10bc967..3c79519 100644
--- a/public/abi.html
+++ b/public/abi.html
@@ -11,14 +11,46 @@
extend AbiCoderRb
end
+ class String
+ def binary?
+ self.each_char do |char|
+ return true if char.ord < 32 || char.ord > 126
+ end
+ false
+ end
+ end
+
+ def transform_item(item)
+ if item.is_a?(String)
+ item.binary? ? ABI.bin_to_hex(item) : item
+ elsif item.is_a?(Array)
+ item.map { |i| transform_item(i) }
+ elsif item.is_a?(Hash)
+ item.transform_values { |v| transform_item(v) }
+ elsif item.is_a?(Integer)
+ item
+ else
+ item
+ end
+ end
+
document = JS.global[:document]
- search_button = document.getElementById "btnEncode"
- search_button.addEventListener "click" do
+ btn_encode = document.getElementById "btnEncode"
+ btn_encode.addEventListener "click" do
types = JSON.parse(document.getElementById("types")[:value].to_s)
values = JSON.parse(document.getElementById("values")[:value].to_s)
result = ABI.encode(types, values)
- document.getElementById("result")[:innerHTML] = ABI.bin_to_hex(result)
+ document.getElementById("data")[:value] = ABI.bin_to_hex(result)
+ end
+
+ btn_decode = document.getElementById "btnDecode"
+ btn_decode.addEventListener "click" do
+ types = JSON.parse(document.getElementById("types")[:value].to_s)
+ data = document.getElementById("data")[:value].to_s.strip
+ result = ABI.decode(types, ABI.hex_to_bin(data))
+ document.getElementById("values")[:value] = transform_item(result).to_json
end
+