etherlite 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd54c39f71674af50c15e5b2c1a75c9c972083d3
4
- data.tar.gz: 3d7afe1cdf25b667e2d6365b3c786458fd1a37c2
3
+ metadata.gz: 1b367f296ffd50994239be945e0e546b3e7dbdb0
4
+ data.tar.gz: f6b56c996e394c582dc2262f0b7a14f7034b28b3
5
5
  SHA512:
6
- metadata.gz: 523fd7b998e5ce21dee58c5bbd1290e5fe5f73c26cab92ac3f5fe67935d65a45e025a7cc813bc0f829b63bf1d516d461f62f3e74d2dd4ce037cdf75f80a4c00c
7
- data.tar.gz: 0cfaf81870210ac15218299f99602312828e1f5a8b758667567f4a07d0ff7bc976d62ef992990a6b80194cdafb952ae5d26a1254e61b76cbda5b6b91b0d59bf4
6
+ metadata.gz: 1b8ddbb397d7c8c988a9619f9919bacbd5688a83cf691b1563a454a9a1c20ed7059df406e25d2bf17c4045ca43c868b9f7a081355b53997cc6b63b7ae0bf0c82
7
+ data.tar.gz: 7a2c9922d666eaaed434f184f9122193535d52f4c22098f780098c5b8ebdb2bbfe175d788830c338b19029e2071bc78d18ccec9020937b0b9672b380481d9090
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ *.gem
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
@@ -17,11 +17,11 @@ module Etherlite
17
17
  @passphrase = nil
18
18
  end
19
19
 
20
- def send_to(_target, _options = {})
20
+ def transfer_to(_target, _options = {})
21
21
  params = {
22
- from: '0x' + @normalized_address,
22
+ from: json_encoded_address,
23
23
  to: Utils.encode_address_param(_target),
24
- value: Utils.encode_quantity_param(_options[:amount] || 0)
24
+ value: Utils.encode_quantity_param(_options.fetch(:amount, 0))
25
25
  }
26
26
 
27
27
  send_transaction params, _options
@@ -32,7 +32,7 @@ module Etherlite
32
32
  options = _params.last.is_a?(Hash) ? _params.pop : {}
33
33
 
34
34
  params = {
35
- from: '0x' + @normalized_address,
35
+ from: json_encoded_address,
36
36
  to: Utils.encode_address_param(_target),
37
37
  data: _function.encode(_params)
38
38
  }
@@ -2,20 +2,16 @@ module Etherlite
2
2
  class Address
3
3
  include Etherlite::Api::Address
4
4
 
5
- attr_reader :connection, :address
5
+ attr_reader :connection, :normalized_address
6
6
 
7
7
  def initialize(_connection, _normalized_address)
8
8
  @connection = _connection
9
- @address = _normalized_address
9
+ @normalized_address = _normalized_address
10
10
  end
11
11
 
12
12
  def to_s
13
13
  # TODO: format address using case-chechsum
14
14
  address
15
15
  end
16
-
17
- private
18
-
19
- attr_reader :normalized_address
20
16
  end
21
17
  end
@@ -1,21 +1,25 @@
1
1
  module Etherlite
2
2
  module Api
3
3
  module Address
4
- extend Forwardable
5
-
6
4
  def address
7
- normalized_address
5
+ '0x' + normalized_address
8
6
  end
9
7
 
10
8
  def get_balance(block: :latest)
11
9
  Etherlite::Utils.hex_to_uint(
12
10
  connection.ipc_call(
13
11
  :eth_getBalance,
14
- '0x' + normalized_address,
12
+ json_encoded_address,
15
13
  Etherlite::Utils.encode_block_param(block)
16
14
  )
17
15
  )
18
16
  end
17
+
18
+ private
19
+
20
+ def json_encoded_address
21
+ '0x' + normalized_address
22
+ end
19
23
  end
20
24
  end
21
25
  end
@@ -2,6 +2,7 @@ module Etherlite
2
2
  module Api
3
3
  module Node
4
4
  extend Forwardable
5
+ include Address
5
6
 
6
7
  def get_block_number
7
8
  Etherlite::Utils.hex_to_uint connection.ipc_call(:eth_blockNumber)
@@ -30,7 +31,7 @@ module Etherlite
30
31
  @first_account ||= accounts.first
31
32
  end
32
33
 
33
- def_delegators :first_account, :unlock, :lock, :get_balance, :send_to, :call
34
+ def_delegators :first_account, :unlock, :lock, :normalized_address, :transfer_to, :call
34
35
  end
35
36
  end
36
37
  end
@@ -4,8 +4,8 @@ module Etherlite
4
4
 
5
5
  attr_reader :connection
6
6
 
7
- def initialize
8
- @connection = Connection.new
7
+ def initialize(_connection)
8
+ @connection = _connection
9
9
  end
10
10
  end
11
11
  end
@@ -52,7 +52,7 @@ module Etherlite::Abi
52
52
 
53
53
  event_class = Class.new(Etherlite::Contract::EventBase) do
54
54
  event_inputs.each do |input|
55
- define_method(input.name) { attributes[input.name] }
55
+ define_method(input.name) { attributes[input.original_name] }
56
56
  end
57
57
  end
58
58
 
@@ -8,11 +8,11 @@ class Etherlite::Contract::EventBase
8
8
  @inputs.each { |i| (i.indexed? ? indexed : non_indexed) << i }
9
9
 
10
10
  @json['data'][2..-1].scan(/.{64}/).each_with_index do |data, i|
11
- attributes[non_indexed[i].name] = non_indexed[i].type.decode(@connection, data)
11
+ attributes[non_indexed[i].original_name] = non_indexed[i].type.decode(@connection, data)
12
12
  end
13
13
 
14
14
  @json['topics'][1..-1].each_with_index do |topic, i|
15
- attributes[indexed[i].name] = indexed[i].type.decode(@connection, topic[2..-1])
15
+ attributes[indexed[i].original_name] = indexed[i].type.decode(@connection, topic[2..-1])
16
16
  end
17
17
 
18
18
  attributes
@@ -1,6 +1,6 @@
1
1
  module Etherlite::Utils
2
2
  class ValidateAddress < PowerTypes::Command.new(:address)
3
- MATCHER = /^(0x)?[0-9a-fA-F]{40}$/
3
+ MATCHER = /^0x[0-9a-fA-F]{40}$/
4
4
 
5
5
  def perform
6
6
  return false unless MATCHER === @address
@@ -30,7 +30,7 @@ module Etherlite::Contract
30
30
 
31
31
  def get_logs(events: nil, from_block: :earliest, to_block: :latest)
32
32
  params = {
33
- address: '0x' + @normalized_address,
33
+ address: json_encoded_address,
34
34
  fromBlock: Etherlite::Utils.encode_block_param(from_block),
35
35
  toBlock: Etherlite::Utils.encode_block_param(to_block)
36
36
  }
@@ -38,8 +38,8 @@ module Etherlite
38
38
  end
39
39
 
40
40
  def normalize_address_param(_value)
41
- if _value.respond_to? :address
42
- _value.address
41
+ if _value.respond_to? :normalized_address
42
+ _value.normalized_address
43
43
  else
44
44
  _value = _value.to_s
45
45
  raise ArgumentError, 'invalid address' unless valid_address? _value
@@ -1,3 +1,3 @@
1
1
  module Etherlite
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etherlite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-07 00:00:00.000000000 Z
11
+ date: 2017-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: digest-sha3