zilliqa 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/zilliqa.rb +1 -1
- data/lib/zilliqa/jsonrpc/provider.rb +6 -0
- data/lib/zilliqa/util/bech32.rb +26 -1
- data/lib/zilliqa/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '018bc423c0476dc0362faa4d0df9b4a7f37c4aad76f383bd863fa4100b016b61'
|
4
|
+
data.tar.gz: d1dfcff519bbd42412f4b14796d70151e09583a63ff4485c16007c0387d6422e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11617320444c963cdf226d50c0abe47ed6a6e67e8f99a9300618999975ad1d58656b75d4d2d3544cd02e459290bf486968ae67d8b92cab5a81cba238614cdbed
|
7
|
+
data.tar.gz: 499f210816b57de86c731100cab5c0ed8b2d89e64339938066527e09818e4789267a4a1a3c32a71817c86d49850c4b87eafaf4b599d6b2d9f4158df7f18a6ca5
|
data/.gitignore
CHANGED
data/lib/zilliqa.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'jsonrpc-client'
|
2
|
+
require 'zilliqa/util/bech32'
|
2
3
|
|
3
4
|
module JSONRPC
|
4
5
|
class Base
|
@@ -19,6 +20,11 @@ module Zilliqa
|
|
19
20
|
@endpoint = endpoint
|
20
21
|
end
|
21
22
|
|
23
|
+
def GetBalance(*args)
|
24
|
+
formatted = args.map { |addr| Util::Bech32.to_checksum_address(addr).downcase.sub('0x', '') }
|
25
|
+
@client.invoke('GetBalance', formatted)
|
26
|
+
end
|
27
|
+
|
22
28
|
def method_missing(sym, *args)
|
23
29
|
@client.invoke(sym.to_s, args)
|
24
30
|
end
|
data/lib/zilliqa/util/bech32.rb
CHANGED
@@ -11,7 +11,7 @@ module Zilliqa
|
|
11
11
|
|
12
12
|
ret = Bitcoin::Bech32.convert_bits(Util.decode_hex(address).bytes, from_bits: 8, to_bits: 5, pad: false)
|
13
13
|
|
14
|
-
Bitcoin::Bech32.encode('zil', ret)
|
14
|
+
Bitcoin::Bech32.encode('zil', ret)
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.from_bech32(address)
|
@@ -23,6 +23,31 @@ module Zilliqa
|
|
23
23
|
|
24
24
|
Zilliqa::Account::Wallet.to_checksum_address(Util.encode_hex(ret.pack('c*'))).sub('0x', '')
|
25
25
|
end
|
26
|
+
|
27
|
+
# to_checksum_address
|
28
|
+
#
|
29
|
+
# takes hex-encoded string and returns the corresponding address
|
30
|
+
#
|
31
|
+
# @param {string} address
|
32
|
+
# @returns {string}
|
33
|
+
def self.to_checksum_address(address)
|
34
|
+
return from_bech32(address) if Validator.bech32?(address)
|
35
|
+
|
36
|
+
address = address.downcase.gsub('0x', '')
|
37
|
+
s1 = Digest::SHA256.hexdigest(Util.decode_hex(address))
|
38
|
+
v = s1.to_i(16)
|
39
|
+
|
40
|
+
ret = ['0x']
|
41
|
+
address.each_char.each_with_index do |c, idx|
|
42
|
+
if '1234567890'.include?(c)
|
43
|
+
ret << c
|
44
|
+
else
|
45
|
+
ret << ((v & (2 ** (255 - 6 * idx))) < 1 ? c.downcase : c.upcase)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
ret.join
|
50
|
+
end
|
26
51
|
end
|
27
52
|
end
|
28
53
|
end
|
data/lib/zilliqa/version.rb
CHANGED