etheruby 0.9.7 → 0.9.8

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: 7c811a2ccafa2d598947e5e1a0cbe902a1ce7032
4
- data.tar.gz: 1c9f9002b6161d692b0119aee0c8e5c19c2b9ef4
3
+ metadata.gz: e1a876972cf55f4558f1fc345718c70f356cafbc
4
+ data.tar.gz: bf1a77caf62874d48134b0a878179385b509297b
5
5
  SHA512:
6
- metadata.gz: acc9489c709e4ac3929f12f3910ae383400c9fe963e8b5392eb69f88393a98dd91ae0ad9e01fd5dc6b10dd40900776f6884b00aaf02e6aea538c6a89765e8243
7
- data.tar.gz: a9a8a27cbcf4a03677247fe10d6566a862c98fdb1eea11dd116c7e7713c59d72055831988f61a55added40e54412ca5be750dd5de0aa46f46078f59dacddefc6
6
+ metadata.gz: 6d51f05ba07bab799c41a86394c6443ca90d9f78e099a2763655bbe876c7730ee718c62c94923e07ee4f4ee8a63fac7769d8bd8d7558cccefe9614c233d5a606
7
+ data.tar.gz: 137e7ea4cb2a7e63698d6abd7a4c2bce1019aed8b9fc8a875971a8011e42343e73a3a8312977ac6f5b25872ac39b0dec53260242c9e34be474b9e1ce1c795354
data/lib/etheruby.rb CHANGED
@@ -2,4 +2,5 @@ require 'logger'
2
2
  require_relative 'etheruby/client'
3
3
  require_relative 'etheruby/contract'
4
4
  require_relative 'etheruby/ether_multipliable'
5
+ require_relative 'etheruby/configuration'
5
6
  require_relative 'etheruby/railtie' if defined?(Rails)
@@ -0,0 +1,15 @@
1
+ module Etheruby
2
+
3
+ class Configuration
4
+
5
+ def self.conf=(value)
6
+ @@conf = value
7
+ end
8
+
9
+ def self.method_missing(sym, *arg)
10
+ return @@conf[sym.to_s]
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -7,21 +7,6 @@ module Etheruby
7
7
  class NoContractMethodError < StandardError; end
8
8
  class NoPasswordForAddress < StandardError; end
9
9
 
10
- class TransactionInformation
11
- @@info = nil
12
- def self.information=(_info)
13
- @@info = _info
14
- end
15
- def self.set?() @@set end
16
- def self.default_from() @@info[:default_from] end
17
- def self.address_password(address)
18
- unless @@info
19
- raise NoPasswordForAddress.new("No password for address #{address}")
20
- end
21
- @@info[:addresses][address]
22
- end
23
- end
24
-
25
10
  def contract
26
11
  Class.new do
27
12
  def self.inherited(subclass)
@@ -95,17 +80,25 @@ module Etheruby
95
80
  end
96
81
 
97
82
  def self.do_eth_call(composed_body)
98
- Client.eth.call(composed_body, "latest")
83
+ Client.eth.call(composed_body, Configuration.default_height || "latest")
99
84
  end
100
85
 
101
86
  def self.do_eth_transaction(composed_body)
102
- from_address = composed_body[:from] || TransactionInformation.default_from
103
- pwd = TransactionInformation.address_password(from_address)
104
- return Client.personal.sendTransaction(composed_body.merge({from: from_address}), pwd)
87
+ from_address = composed_body[:from] || Configuration.default_from
88
+ pwd = Configuration.addresses[from_address]
89
+ Client.personal.sendTransaction(composed_body.merge({from: address_fix(from_address)}), pwd)
105
90
  end
106
91
 
107
92
  def self.address
108
- "0x#{@@address.to_s(16)}"
93
+ address_fix(@@address)
94
+ end
95
+
96
+ def self.address_fix(addr)
97
+ if addr.is_a? ::String
98
+ addr
99
+ else
100
+ "0x#{@@address.to_s(16)}"
101
+ end
109
102
  end
110
103
  end
111
104
  end
@@ -1,17 +1,22 @@
1
1
  Dir["./app/contracts/**/*.rb"].each { |f| require f }
2
2
 
3
+ require 'yaml'
4
+
3
5
  module Etheruby
4
6
 
5
7
  class Railtie < Rails::Railtie
8
+ # Loads configuration
6
9
  initializer "etheruby.configure" do |app|
7
- if app.config.respond_to? :etheruby_uri
8
- Etheruby::Client.uri = app.config.etheruby_uri
10
+ Etheruby::Configuration.conf = if File.exist? './config/etheruby.yml'
11
+ YAML.load_file('./config/etheruby.yml')
12
+ else
13
+ {}
9
14
  end
15
+ end
10
16
 
11
- if app.config.respond_to? :etheruby_enable_transactions
12
- Etheruby::TransactionInformation.information = \
13
- app.config.etheruby_enable_transactions
14
- end
17
+ # Create setup rake task
18
+ rake_tasks do
19
+ load File.join(File.dirname(__FILE__), '../../tasks/etheruby/setup.task')
15
20
  end
16
21
  end
17
22
 
@@ -0,0 +1,4 @@
1
+ default_from: 0x0000000000000000000000000000000000000000
2
+ default_height: latest
3
+ addresses:
4
+ 0x0000000000000000000000000000000000000000: my_address_passwd
@@ -0,0 +1,9 @@
1
+ namespace :etheruby do
2
+ desc "Creates etheruby scaffold for rails"
3
+ task :setup => :environment do
4
+ require 'fileutils'
5
+ FileUtils.mkdir('./app/contracts') unless Dir.exist? './app/contracts'
6
+ FileUtils.touch('./app/contracts/.keep')
7
+ FileUtils.cp(File.join(File.dirname(__FILE__), 'etheruby.yml'), './config/etheruby.yml')
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etheruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérémy SEBAN
@@ -90,6 +90,7 @@ files:
90
90
  - lib/etheruby.rb
91
91
  - lib/etheruby/arguments_generator.rb
92
92
  - lib/etheruby/client.rb
93
+ - lib/etheruby/configuration.rb
93
94
  - lib/etheruby/contract.rb
94
95
  - lib/etheruby/contract_method_dsl.rb
95
96
  - lib/etheruby/encoders/address.rb
@@ -106,6 +107,8 @@ files:
106
107
  - lib/etheruby/response_parser.rb
107
108
  - lib/etheruby/treat_variable.rb
108
109
  - lib/etheruby/type_matchers.rb
110
+ - tasks/etheruby/etheruby.yml
111
+ - tasks/etheruby/setup.task
109
112
  homepage: https://github.com/MechanicalSloth/etheruby
110
113
  licenses:
111
114
  - MIT