ethereum 0.4.85 → 0.4.90

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
  SHA1:
3
- metadata.gz: 1a875891af2a24286d61a1afc6aeecfa7ef4ed34
4
- data.tar.gz: bffe66081bcee30660c07f1a9fe8fe3e818628ee
3
+ metadata.gz: c273633c818965bad5e94bb13d522d2d63d7fbbd
4
+ data.tar.gz: 6c2f39e4f2fb95bf6cfc233e8bd89557abb2469f
5
5
  SHA512:
6
- metadata.gz: 0718eb47a13d68852b5a9295d78e3afee399af8e8d024f5faf6e8f9e16118481f39797aecf0a3819f29c6ef49f7b9beff08b063e358674acd0030fe80de1fbf6
7
- data.tar.gz: 5af94959fdda42e7746d880b3dea6bf5d2045af4d9e5288158d4e9c9ef65b4aa9ffbfebce13451bc463f676c263a4f605fd1abcbe081c4f465ee8184e42046ed
6
+ metadata.gz: bfce182b248aadf1555669cbfbb4b609809a732b5e9f1ab5748d11d9c83a89ee45aefe8317570550d9103538a83fcfc4079dccc88f165daeb9f72340bb78560a
7
+ data.tar.gz: 74d467614918ff44d5411a52c06531bd51d28f60e7eedbba4f7c5581714a4ec1861cec86794db4203ee77f67035bae864ac194a4262f15433c2cf1f9c0561f4c
data/README.md CHANGED
@@ -12,6 +12,7 @@ A simple library for Ethereum.
12
12
  * Expose deployed contracts as Ruby classes
13
13
  * Test solidity contracts with a Ruby testing framework of your choice
14
14
  * Call and wait for the result of Solidity function calls.
15
+ * Contract events
15
16
 
16
17
  ## Ruby Compatibility
17
18
 
@@ -23,6 +23,7 @@ module Ethereum
23
23
  functions = @functions
24
24
  constructor_inputs = @constructor_inputs
25
25
  binary = @code
26
+ events = @events
26
27
 
27
28
  class_methods = Class.new do
28
29
 
@@ -46,6 +47,10 @@ module Ethereum
46
47
  instance_variable_set("@deployment", Ethereum::Deployment.new(deploytx, connection))
47
48
  end
48
49
 
50
+ define_method :events do
51
+ return events
52
+ end
53
+
49
54
  define_method :deployment do
50
55
  instance_variable_get("@deployment")
51
56
  end
@@ -54,10 +59,18 @@ module Ethereum
54
59
  self.deploy(*params)
55
60
  self.deployment.wait_for_deployment(time)
56
61
  instance_variable_set("@address", self.deployment.contract_address)
62
+ self.events.each do |event|
63
+ event.set_address(self.deployment.contract_address)
64
+ event.set_client(connection)
65
+ end
57
66
  end
58
67
 
59
68
  define_method :at do |addr|
60
69
  instance_variable_set("@address", addr)
70
+ self.events.each do |event|
71
+ event.set_address(addr)
72
+ event.set_client(connection)
73
+ end
61
74
  end
62
75
 
63
76
  define_method :address do
@@ -88,6 +101,51 @@ module Ethereum
88
101
  instance_variable_get("@gas") || 3000000
89
102
  end
90
103
 
104
+ events.each do |evt|
105
+ define_method "nf_#{evt.name.underscore}".to_sym do |params = {}|
106
+ params[:to_block] ||= "latest"
107
+ params[:from_block] ||= "0x0"
108
+ params[:address] ||= instance_variable_get("@address")
109
+ params[:topics] = evt.signature
110
+ payload = {topics: [params[:topics]], fromBlock: params[:from_block], toBlock: params[:to_block], address: params[:address]}
111
+ filter_id = connection.new_filter(payload)
112
+ return filter_id["result"]
113
+ end
114
+
115
+ define_method "gfl_#{evt.name.underscore}".to_sym do |filter_id|
116
+ formatter = Ethereum::Formatter.new
117
+ logs = connection.get_filter_logs(filter_id)
118
+ collection = []
119
+ logs["result"].each do |result|
120
+ inputs = evt.input_types
121
+ outputs = inputs.zip(result["topics"][1..-1])
122
+ data = {blockNumber: result["blockNumber"].hex, transactionHash: result["transactionHash"], blockHash: result["blockHash"], transactionIndex: result["transactionIndex"].hex, topics: []}
123
+ outputs.each do |output|
124
+ data[:topics] << formatter.from_payload(output)
125
+ end
126
+ collection << data
127
+ end
128
+ return collection
129
+ end
130
+
131
+ define_method "gfc_#{evt.name.underscore}".to_sym do |filter_id|
132
+ formatter = Ethereum::Formatter.new
133
+ logs = connection.get_filter_changes(filter_id)
134
+ collection = []
135
+ logs["result"].each do |result|
136
+ inputs = evt.input_types
137
+ outputs = inputs.zip(result["topics"][1..-1])
138
+ data = {blockNumber: result["blockNumber"].hex, transactionHash: result["transactionHash"], blockHash: result["blockHash"], transactionIndex: result["transactionIndex"].hex, topics: []}
139
+ outputs.each do |output|
140
+ data[:topics] << formatter.from_payload(output)
141
+ end
142
+ collection << data
143
+ end
144
+ return collection
145
+ end
146
+
147
+ end
148
+
91
149
  functions.each do |fun|
92
150
 
93
151
  fun_count = functions.select {|x| x.name == fun.name }.count
@@ -1,8 +1,7 @@
1
- require 'pry'
2
1
  module Ethereum
3
2
  class ContractEvent
4
3
 
5
- attr_accessor :name, :signature, :input_types, :inputs, :event_string
4
+ attr_accessor :name, :signature, :input_types, :inputs, :event_string, :address, :client
6
5
 
7
6
  def initialize(data)
8
7
  @name = data["name"]
@@ -12,6 +11,18 @@ module Ethereum
12
11
  @signature = Digest::SHA3.hexdigest(@event_string, 256)
13
12
  end
14
13
 
14
+ def set_address(address)
15
+ @address = address
16
+ end
17
+
18
+ def register_filter(*args)
19
+ @client.
20
+ end
21
+
22
+ def set_client(client)
23
+ @client = client
24
+ end
25
+
15
26
  end
16
27
  end
17
28
 
@@ -2,7 +2,7 @@ module Ethereum
2
2
 
3
3
  class ContractInitializer
4
4
 
5
- attr_accessor :abi, :binary, :name, :libraries, :needs_linking, :project_initializer
5
+ attr_accessor :abi, :binary, :name, :libraries, :needs_linking, :project_initializer, :contract
6
6
 
7
7
  def initialize(contract_name, contract, project_initializer)
8
8
  @abi = JSON.parse(contract["abi"]) unless contract.nil?
@@ -40,8 +40,8 @@ module Ethereum
40
40
  end
41
41
 
42
42
  def build(connection)
43
- contract = Ethereum::Contract.new(@name, @binary, @abi)
44
- contract.build(connection)
43
+ @contract = Ethereum::Contract.new(@name, @binary, @abi)
44
+ @contract.build(connection)
45
45
  end
46
46
 
47
47
  def generate_javascripts(path)
@@ -1,3 +1,3 @@
1
1
  module Ethereum
2
- VERSION = "0.4.85"
2
+ VERSION = "0.4.90"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethereum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.85
4
+ version: 0.4.90
5
5
  platform: ruby
6
6
  authors:
7
7
  - DigixGlobal Pte Ltd (https://dgx.io)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-31 00:00:00.000000000 Z
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler