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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aae5f568ca199560178c8e3b3912a3c1e140fb8fcc428e831f145d3cd370a06c
4
- data.tar.gz: 61cb4faa119e00d0bf082f93a0c14c418e6ba8851d2e944cb8fc35263de4337f
3
+ metadata.gz: '018bc423c0476dc0362faa4d0df9b4a7f37c4aad76f383bd863fa4100b016b61'
4
+ data.tar.gz: d1dfcff519bbd42412f4b14796d70151e09583a63ff4485c16007c0387d6422e
5
5
  SHA512:
6
- metadata.gz: 7cd8fef9f9e361ffa887ab73eb248a608f739f33c0d8e8848507de46a17169ece879420198173261793f90b7cc60d1fa4a404a17f4ae3e0fc53af9cde0fc1ace
7
- data.tar.gz: 2fa1ffcbaf023535bd2c717bf6bbc6bca5f91de2155c4d1fc3edd939541a3b31ab75ad53337644a6665aa6cd05f33da13f619c7db203e8b63ffb788386f2627c
6
+ metadata.gz: 11617320444c963cdf226d50c0abe47ed6a6e67e8f99a9300618999975ad1d58656b75d4d2d3544cd02e459290bf486968ae67d8b92cab5a81cba238614cdbed
7
+ data.tar.gz: 499f210816b57de86c731100cab5c0ed8b2d89e64339938066527e09818e4789267a4a1a3c32a71817c86d49850c4b87eafaf4b599d6b2d9f4158df7f18a6ca5
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
@@ -17,5 +17,5 @@ require 'zilliqa/util/bech32'
17
17
 
18
18
 
19
19
  module Zilliqa
20
-
20
+ MAINNET = 65_537
21
21
  end
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Zilliqa
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zilliqa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - snuff