ethereum 0.3.85 → 0.3.90
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/ethereum/contract.rb +13 -4
- data/lib/ethereum/http_client.rb +3 -2
- 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: ed9c6d551eb9ada508059a23e99f6c14e1549520
|
4
|
+
data.tar.gz: b82d97a1bbce969eafaac85413d6053206896fc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27cedd3b4bd01319c0489d8640a3fa00ee3e24a083e22ffeb0b5cd07eb074f0cf30075bcd8b971d557b4452f1556521d883a6d89c552a36d93d8a2899396eeac
|
7
|
+
data.tar.gz: 1e4c072d0a161fab24ce8b0abc7ed5377fb9c0feb798967b8baf787fa90e3401b412dc4ec92c7afeb69f3843919c02f258a5ff8d5b7c6d74db39cf48130323f8
|
data/README.md
CHANGED
@@ -8,6 +8,7 @@ A simple library for Ethereum.
|
|
8
8
|
* IPC Client with batch calls support
|
9
9
|
* HTTP Client with batch calls support
|
10
10
|
* Compile and deploy Solidity contracts
|
11
|
+
* Deploy contracts with constructor parameters.
|
11
12
|
* Expose deployed contracts as Ruby classes
|
12
13
|
* Test solidity contracts with a Ruby testing framework of your choice
|
13
14
|
* Call and wait for the result of Solidity function calls.
|
@@ -57,7 +58,7 @@ client = Ethereum::IpcClient.new("#{ENV['HOME']}/.ethereum_testnet/geth.ipc")
|
|
57
58
|
init = Ethereum::Initializer.new("#{ENV['PWD']}/spec/fixtures/SimpleNameRegistry.sol", client)
|
58
59
|
init.build_all
|
59
60
|
simple_name_registry_instance = SimpleNameRegistry.new
|
60
|
-
simple_name_registry_instance.deploy_and_wait
|
61
|
+
simple_name_registry_instance.deploy_and_wait(60)
|
61
62
|
```
|
62
63
|
|
63
64
|
### Transacting and Calling Solidity Functions
|
data/lib/ethereum/contract.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
require 'pry'
|
1
2
|
module Ethereum
|
2
3
|
class Contract
|
3
4
|
|
4
|
-
attr_accessor :code, :name, :functions, :abi
|
5
|
+
attr_accessor :code, :name, :functions, :abi, :constructor_inputs
|
5
6
|
|
6
7
|
def initialize(name, code, abi)
|
7
8
|
@name = name
|
8
9
|
@code = code
|
9
10
|
@abi = abi
|
10
11
|
@functions = []
|
12
|
+
@constructor_inputs = @abi.detect {|x| x["type"] == "constructor"}["inputs"]
|
11
13
|
@abi.select {|x| x["type"] == "function" }.each do |abifun|
|
12
14
|
@functions << Ethereum::Function.new(abifun)
|
13
15
|
end
|
@@ -16,6 +18,7 @@ module Ethereum
|
|
16
18
|
def build(connection)
|
17
19
|
class_name = @name
|
18
20
|
functions = @functions
|
21
|
+
constructor_inputs = @constructor_inputs
|
19
22
|
code = @code
|
20
23
|
class_methods = Class.new do
|
21
24
|
|
@@ -23,7 +26,13 @@ module Ethereum
|
|
23
26
|
connection
|
24
27
|
end
|
25
28
|
|
26
|
-
define_method :deploy do
|
29
|
+
define_method :deploy do |*params|
|
30
|
+
raise "Missing constructor parameter" and return if params.length != constructor_inputs.length
|
31
|
+
formatter = Ethereum::Formatter.new
|
32
|
+
constructor_inputs.each_index do |i|
|
33
|
+
args = [constructor_inputs[i]["type"], params[i]]
|
34
|
+
code << formatter.to_payload(args)
|
35
|
+
end
|
27
36
|
deploytx = connection.send_transaction({from: self.sender, gas: 2000000, gasPrice: 60000000000, data: code})["result"]
|
28
37
|
self.instance_variable_set("@deployment", Ethereum::Deployment.new(deploytx, connection))
|
29
38
|
end
|
@@ -32,8 +41,8 @@ module Ethereum
|
|
32
41
|
self.instance_variable_get("@deployment")
|
33
42
|
end
|
34
43
|
|
35
|
-
define_method :deploy_and_wait do |time = 60.seconds|
|
36
|
-
self.deploy
|
44
|
+
define_method :deploy_and_wait do |time = 60.seconds, *params|
|
45
|
+
self.deploy(*params)
|
37
46
|
self.deployment.wait_for_deployment(time)
|
38
47
|
self.instance_variable_set("@address", self.deployment.contract_address)
|
39
48
|
end
|
data/lib/ethereum/http_client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'pry'
|
2
|
+
require 'net/http'
|
2
3
|
module Ethereum
|
3
4
|
class HttpClient < Client
|
4
5
|
attr_accessor :command, :id, :host, :port, :batch, :converted_transactions, :uri
|
@@ -16,9 +17,9 @@ module Ethereum
|
|
16
17
|
define_method method_name do |*args|
|
17
18
|
command = rpc_command
|
18
19
|
payload = {jsonrpc: "2.0", method: command, params: args, id: get_id}
|
19
|
-
http = Net::HTTP.new(@host, @port)
|
20
|
+
http = ::Net::HTTP.new(@host, @port)
|
20
21
|
header = {'Content-Type' => 'application/json'}
|
21
|
-
request = Net::HTTP::Post.new(uri, header)
|
22
|
+
request = ::Net::HTTP::Post.new(uri, header)
|
22
23
|
request.body = payload.to_json
|
23
24
|
response = http.request(request)
|
24
25
|
return JSON.parse(response.body)
|
data/lib/ethereum/version.rb
CHANGED