etheruby 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/etheruby/arguments_generator.rb +25 -7
- data/lib/etheruby.rb +42 -42
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 200899891a140cea002a7e7d9c1ac9916908275b
|
4
|
+
data.tar.gz: d01b91005637a2ee3543a0d1206a8a59bd265f93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76545aa6b9a4f8bf92e18b35556a2b4361607e5628760d940c4badf57e9a564dde5785fd6b3694c409a4800bf2df4e0f5129abbf1f3f1b78d36334015cd3386f
|
7
|
+
data.tar.gz: d7f1fcaf796b041096484d2ba695a5c9acbd4ee1c92cc22dea0822b3664dd807e2035b372751e2d8d968f13a483f1a2933578f5241fdc8ac8bc95c809a96f045
|
@@ -77,40 +77,58 @@ module Etheruby
|
|
77
77
|
arg.to_s(16).rjust(size / 4,'0')
|
78
78
|
end
|
79
79
|
|
80
|
+
##
|
81
|
+
# fixed<X> encoding
|
80
82
|
def fixed_encode(size, arg)
|
81
83
|
#Todo
|
82
84
|
end
|
83
85
|
|
86
|
+
##
|
87
|
+
# ufixed<X> encoding
|
84
88
|
def ufixed_encode(size, arg)
|
85
89
|
#Todo
|
86
90
|
end
|
87
91
|
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
+
##
|
93
|
+
# Encode a static array
|
92
94
|
def static_array(type, size, arg)
|
93
95
|
#Todo
|
94
96
|
end
|
95
97
|
|
98
|
+
##
|
99
|
+
# Creates a dynamic array
|
96
100
|
def dynamic_array(type, arg)
|
97
101
|
#Todo
|
98
102
|
end
|
99
103
|
|
104
|
+
##
|
105
|
+
# byte<X> encodeing
|
106
|
+
def byte_encode(size, arg)
|
107
|
+
arg.map{ |b| b.to_s(16) }.join.rjust(size,'0')
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# address<X> encoding
|
100
112
|
def address_encode(arg)
|
101
113
|
uint_encode(160, arg)
|
102
114
|
end
|
103
115
|
|
116
|
+
##
|
117
|
+
# string<x> encoding (as bytes)
|
104
118
|
def string_encode(arg)
|
105
|
-
|
119
|
+
bytes_encode(arg.codepoints)
|
106
120
|
end
|
107
121
|
|
122
|
+
##
|
123
|
+
# bytes (dynamic size) encoding
|
108
124
|
def bytes_encode(arg)
|
109
|
-
|
125
|
+
uint_encode(256, arg.count) + arg.map{ |b| b.to_s(16) }.join
|
110
126
|
end
|
111
127
|
|
128
|
+
##
|
129
|
+
# boolean encoding (as uint8)
|
112
130
|
def bool_encode(arg)
|
113
|
-
|
131
|
+
uint_encode(8, arg ? 1 : 0)
|
114
132
|
end
|
115
133
|
|
116
134
|
end
|
data/lib/etheruby.rb
CHANGED
@@ -9,55 +9,55 @@ module Etheruby
|
|
9
9
|
|
10
10
|
def contract
|
11
11
|
Class.new do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
@@logger.progname = "Etheruby Contract '#{subclass.name}'"
|
12
|
+
def self.inherited(subclass)
|
13
|
+
@@c_methods = {}
|
14
|
+
@@logger = ::Logger.new(STDOUT)
|
15
|
+
@@logger.level = if ENV.has_key? 'ETHERUBY_DEBUG'
|
16
|
+
::Logger::DEBUG
|
17
|
+
else
|
18
|
+
::Logger::WARN
|
21
19
|
end
|
20
|
+
@@logger.progname = "Etheruby Contract '#{subclass.name}'"
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def self.at_address(address)
|
24
|
+
@@address = address
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
def self.method(name, &blk)
|
28
|
+
cmd = ContractMethodDSL.new(name)
|
29
|
+
cmd.instance_exec &blk if blk
|
30
|
+
@@c_methods[name] = cmd.validate!
|
31
|
+
@@logger.debug("Registred method #{name}")
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
def self.method_missing(sym, *args)
|
35
|
+
raise NoContractMethodError.new (
|
36
|
+
"The method #{sym} does not exist in the #{self.class.to_s} contract."
|
37
|
+
) unless @@c_methods.include? sym
|
38
|
+
execute_contract_method(@@c_methods[sym], args)
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
response['result']
|
41
|
+
def self.execute_contract_method(method_info, args)
|
42
|
+
arguments = ArgumentsGenerator.new(method_info[:params], args).to_s
|
43
|
+
data = "#{method_info[:signature]}#{arguments}"
|
44
|
+
composed_body = { to: self.address, data: data }
|
45
|
+
[ :gas, :gasPrice, :value, :from ].each { |kw|
|
46
|
+
composed_body[kw] = method_info[kw] if method_info.has_key? kw
|
47
|
+
}
|
48
|
+
@@logger.debug("Calling #{method_info[:name]} with parameters #{composed_body.inspect}")
|
49
|
+
response = Client.eth.call composed_body, "latest"
|
50
|
+
if response.has_key? 'error'
|
51
|
+
@@logger.error("Failed contract execution #{response['error']['message']}")
|
52
|
+
else
|
53
|
+
@@logger.debug("Response from API for #{method_info[:name]} : #{response.inspect}")
|
56
54
|
end
|
55
|
+
response['result']
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
def self.address
|
59
|
+
"0x#{@@address.to_s(16)}"
|
60
|
+
end
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etheruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jérémy SEBAN
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: digest-sha3
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.5
|
113
|
+
rubygems_version: 2.4.5
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: 'Etheruby : Ethereum smart-contract classy-describer for Ruby.'
|