ethereum 0.4.61 → 0.4.62
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ethereum/contract.rb +25 -6
- data/lib/ethereum/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7167e08de3db947aa03d0552b7ba34921124411a
|
4
|
+
data.tar.gz: c5ebedb054a9f7bd457601ab695609512269b6c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca9324dbc0687a680fd8502c45ed5705fb9acfea004be6e776ca5b8c6b1749ad7dcb581ffedbd8c6dcab7931f504973b5150dc4562c60dc21768e11560d50c21
|
7
|
+
data.tar.gz: 902db7a87860f4e962ad7857cabccbd48109a168d12f4a6dc8cf6dc483ec81ffb133057a9839e2cfd1b671d0a3a6adfc9973207cf5c9f0b9d9472e81a9604b7d
|
data/lib/ethereum/contract.rb
CHANGED
@@ -23,6 +23,7 @@ module Ethereum
|
|
23
23
|
functions = @functions
|
24
24
|
constructor_inputs = @constructor_inputs
|
25
25
|
code = @code
|
26
|
+
|
26
27
|
class_methods = Class.new do
|
27
28
|
|
28
29
|
define_method "connection".to_sym do
|
@@ -88,8 +89,16 @@ module Ethereum
|
|
88
89
|
|
89
90
|
fun_count = functions.select {|x| x.name == fun.name }.count
|
90
91
|
derived_function_name = (fun_count == 1) ? "#{fun.name.underscore}" : "#{fun.name.underscore}__#{fun.inputs.collect {|x| x.type}.join("__")}"
|
91
|
-
|
92
|
-
|
92
|
+
call_function_name = "call_#{derived_function_name}".to_sym
|
93
|
+
call_function_name_alias = "c_#{derived_function_name}".to_sym
|
94
|
+
call_raw_function_name = "call_raw_#{derived_function_name}".to_sym
|
95
|
+
call_raw_function_name_alias = "cr_#{derived_function_name}".to_sym
|
96
|
+
transact_function_name = "transact_#{derived_function_name}".to_sym
|
97
|
+
transact_function_name_alias = "t_#{derived_function_name}".to_sym
|
98
|
+
transact_and_wait_function_name = "transact_and_wait_#{derived_function_name}".to_sym
|
99
|
+
transact_and_wait_function_name_alias = "tw_#{derived_function_name}".to_sym
|
100
|
+
|
101
|
+
define_method call_raw_function_name do |*args|
|
93
102
|
formatter = Ethereum::Formatter.new
|
94
103
|
arg_types = fun.inputs.collect(&:type)
|
95
104
|
connection = self.connection
|
@@ -102,15 +111,20 @@ module Ethereum
|
|
102
111
|
raw_result = connection.call({to: self.address, from: self.sender, data: payload.join()})["result"]
|
103
112
|
formatted_result = fun.outputs.collect {|x| x.type }.zip(raw_result.gsub(/^0x/,'').scan(/.{64}/))
|
104
113
|
output = formatted_result.collect {|x| formatter.from_payload(x) }
|
105
|
-
|
106
|
-
|
114
|
+
return {data: payload.join(), raw: raw_result, formatted: output}
|
115
|
+
end
|
116
|
+
|
117
|
+
define_method call_function_name do |*args|
|
118
|
+
data = self.send(call_raw_function_name, *args)
|
119
|
+
output = data[:formatted]
|
120
|
+
if output.length == 1
|
107
121
|
return output[0]
|
108
122
|
else
|
109
123
|
return output
|
110
124
|
end
|
111
125
|
end
|
112
126
|
|
113
|
-
define_method
|
127
|
+
define_method transact_function_name do |*args|
|
114
128
|
formatter = Ethereum::Formatter.new
|
115
129
|
arg_types = fun.inputs.collect(&:type)
|
116
130
|
connection = self.connection
|
@@ -124,13 +138,18 @@ module Ethereum
|
|
124
138
|
return Ethereum::Transaction.new(txid, self.connection, payload.join(), args)
|
125
139
|
end
|
126
140
|
|
127
|
-
define_method
|
141
|
+
define_method transact_and_wait_function_name do |*args|
|
128
142
|
function_name = "transact_#{derived_function_name}".to_sym
|
129
143
|
tx = self.send(function_name, *args)
|
130
144
|
tx.wait_for_miner
|
131
145
|
return tx
|
132
146
|
end
|
133
147
|
|
148
|
+
alias_method call_function_name_alias, call_function_name
|
149
|
+
alias_method call_raw_function_name_alias, call_raw_function_name
|
150
|
+
alias_method transact_function_name_alias, transact_function_name
|
151
|
+
alias_method transact_and_wait_function_name_alias, transact_and_wait_function_name
|
152
|
+
|
134
153
|
end
|
135
154
|
end
|
136
155
|
Object.const_set(class_name, class_methods) unless Object.const_defined?(class_name)
|
data/lib/ethereum/version.rb
CHANGED