ethereum.rb 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ethereum/abi.rb +6 -1
- data/lib/ethereum/contract.rb +2 -5
- data/lib/ethereum/encoder.rb +20 -4
- data/lib/ethereum/function.rb +1 -1
- data/lib/ethereum/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 118a182e1fe6df35ead4dd24f452ab8dbe163f1b
|
4
|
+
data.tar.gz: 95b4a183b908e5c835f95af4772069603c08fb38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6353836a9589c7517beacb7bb29c402c08cc942e774954653eaf4f69d4202002f4cd67edc8c458cd29a4479bf4528fcb38b326ce16bb9b3838bfeab739a616f
|
7
|
+
data.tar.gz: 1bcf61ed8af8111c10045e3a17e07011a8892f5db6d523d9a9863fc95078eee9856a398b82b3a6d1ec840d4ba22ea4af30a3f30ed4355e7ad75b0bfd30ca7d9a
|
data/lib/ethereum/abi.rb
CHANGED
@@ -2,7 +2,12 @@ module Ethereum
|
|
2
2
|
class Abi
|
3
3
|
|
4
4
|
def self.parse_abi(abi)
|
5
|
-
|
5
|
+
constructor = abi.detect {|x| x["type"] == "constructor"}
|
6
|
+
if constructor.present?
|
7
|
+
constructor_inputs = constructor["inputs"].map { |input| Ethereum::FunctionInput.new(input) }
|
8
|
+
else
|
9
|
+
constructor_inputs = []
|
10
|
+
end
|
6
11
|
functions = abi.select {|x| x["type"] == "function" }.map { |fun| Ethereum::Function.new(fun) }
|
7
12
|
events = abi.select {|x| x["type"] == "event" }.map { |evt| Ethereum::ContractEvent.new(evt) }
|
8
13
|
[constructor_inputs, functions, events]
|
data/lib/ethereum/contract.rb
CHANGED
@@ -48,7 +48,7 @@ module Ethereum
|
|
48
48
|
if @constructor_inputs.present?
|
49
49
|
raise "Missing constructor parameter" and return if params.length != @constructor_inputs.length
|
50
50
|
end
|
51
|
-
deploy_arguments = @
|
51
|
+
deploy_arguments = @encoder.encode_arguments(@constructor_inputs, params)
|
52
52
|
payload = "0x" + @code + deploy_arguments
|
53
53
|
tx = @client.eth_send_transaction({from: sender, data: payload})["result"]
|
54
54
|
raise "Failed to deploy, did you unlock #{sender} account? Transaction hash: #{deploytx}" if tx.nil? || tx == "0x0000000000000000000000000000000000000000000000000000000000000000"
|
@@ -69,10 +69,7 @@ module Ethereum
|
|
69
69
|
deploy_arguments = ""
|
70
70
|
if @constructor_inputs.present?
|
71
71
|
raise "Wrong number of arguments in a constructor" and return if params.length != @constructor_inputs.length
|
72
|
-
@constructor_inputs
|
73
|
-
args = [@constructor_inputs[i]["type"], params[i]]
|
74
|
-
deploy_arguments << @formatter.to_payload(args)
|
75
|
-
end
|
72
|
+
deploy_arguments = @encoder.encode_arguments(@constructor_inputs, params)
|
76
73
|
end
|
77
74
|
deploy_payload = @code + deploy_arguments
|
78
75
|
result = @client.eth_estimate_gas({from: @sender, data: "0x" + deploy_payload})
|
data/lib/ethereum/encoder.rb
CHANGED
@@ -38,17 +38,17 @@ module Ethereum
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def encode_dynamic_bytes(value)
|
41
|
-
location = encode_uint(32)
|
41
|
+
location = encode_uint(@inputs ? @inputs.size * 32 : 32)
|
42
42
|
size = encode_uint(value.size)
|
43
43
|
content = encode_bytes(value)
|
44
|
-
location
|
44
|
+
[location, size + content]
|
45
45
|
end
|
46
46
|
|
47
47
|
def encode_string(value)
|
48
|
-
location = encode_uint(32)
|
48
|
+
location = encode_uint(@inputs ? @inputs.size * 32 : 32)
|
49
49
|
size = encode_uint(value.bytes.size)
|
50
50
|
content = value.bytes.map {|x| x.to_s(16)}.join("").ljust(64, '0')
|
51
|
-
location
|
51
|
+
[location, size + content]
|
52
52
|
end
|
53
53
|
|
54
54
|
def encode_address(value)
|
@@ -61,6 +61,22 @@ module Ethereum
|
|
61
61
|
value.start_with?("0x") ? value : ("0x" + value)
|
62
62
|
end
|
63
63
|
|
64
|
+
def encode_arguments(inputs, args)
|
65
|
+
@head = ""
|
66
|
+
@tail = ""
|
67
|
+
@inputs = inputs
|
68
|
+
inputs.each.with_index do |input, index|
|
69
|
+
encoded = encode(input.type, args[index])
|
70
|
+
if encoded.is_a? Array
|
71
|
+
@head << encoded[0]
|
72
|
+
@tail << encoded[1]
|
73
|
+
else
|
74
|
+
@head << encoded
|
75
|
+
end
|
76
|
+
end
|
77
|
+
@head + @tail
|
78
|
+
end
|
79
|
+
|
64
80
|
private
|
65
81
|
def to_twos_complement(number)
|
66
82
|
(number & ((1 << 256) - 1))
|
data/lib/ethereum/function.rb
CHANGED
@@ -6,7 +6,7 @@ module Ethereum
|
|
6
6
|
def initialize(data)
|
7
7
|
@name = data["name"]
|
8
8
|
@constant = data["constant"]
|
9
|
-
@inputs = data["inputs"].
|
9
|
+
@inputs = data["inputs"].map do |input|
|
10
10
|
Ethereum::FunctionInput.new(input)
|
11
11
|
end
|
12
12
|
@outputs = data["outputs"].collect do |output|
|
data/lib/ethereum/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ethereum.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marek Kirejczyk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|