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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12c070c1b68b2effbf8d546fe905fd3d184bc26f
4
- data.tar.gz: de4aa5107ea7cd347aabed1848eec9fb9f612f0d
3
+ metadata.gz: 200899891a140cea002a7e7d9c1ac9916908275b
4
+ data.tar.gz: d01b91005637a2ee3543a0d1206a8a59bd265f93
5
5
  SHA512:
6
- metadata.gz: 0c914deee7b439f63d11111e3fe16be892e18da1d115722faab9505ee965d1905ce0d361f6599e8920521237bea1578525e0772278b0cfdb19ef424511c12457
7
- data.tar.gz: 2424d20153c2fa7c0a818c347e9535b197843c8d01d9a36d9f32cb2d285cb3685ed82b653dec7f244e2479806d2a006be2ee3c17ea5cdb93d99cb5f5aa603cc8
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
- def byte_encode(size, arg)
89
- arg.map{ |b| b.to_s(16) }.join.rjust(size,'0')
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
- #Todo
119
+ bytes_encode(arg.codepoints)
106
120
  end
107
121
 
122
+ ##
123
+ # bytes (dynamic size) encoding
108
124
  def bytes_encode(arg)
109
- #Todo
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
- #Todo
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
- 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
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
- def self.at_address(address)
24
- @@address = address
25
- end
23
+ def self.at_address(address)
24
+ @@address = address
25
+ end
26
26
 
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
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
- 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
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
- 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}")
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
- def self.address
59
- "0x#{@@address.to_s(16)}"
60
- end
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.1
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-06 00:00:00.000000000 Z
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.2
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.'