etherlite 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/etherlite.gemspec +1 -0
- data/lib/etherlite.rb +1 -0
- data/lib/etherlite/account.rb +27 -11
- data/lib/etherlite/pk_account.rb +74 -0
- data/lib/etherlite/types/address.rb +1 -1
- data/lib/etherlite/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc3672a5fe74a7af2cd535015ad05b291e5d07c0
|
4
|
+
data.tar.gz: b67bf5d1345c35d4a4a60da6a8b87d5266607768
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b10b9675ff4a41b94e7dba7cfac2797b01008164fab0ac7a1d65ec1b89abb294d57d1ee8c4660dcbdb38470a7f5f1524ad66040fce9366d167aa146b1519db65
|
7
|
+
data.tar.gz: 0ab16b1be44be94cdbb0a6f6c78bc03154eaeae30c6ce14bcf1f2afd41e68a55c3e1a4cd2873e62ea78443c0fcc80d932dcee91147b7df2eb4b4cefc3e5757f1
|
data/etherlite.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_dependency "digest-sha3", "~> 1.1"
|
23
23
|
spec.add_dependency "power-types", "~> 0.1"
|
24
|
+
spec.add_dependency "eth", "~> 0.4.4"
|
24
25
|
spec.add_dependency "activesupport"
|
25
26
|
|
26
27
|
spec.add_development_dependency "bundler", "~> 1.12"
|
data/lib/etherlite.rb
CHANGED
data/lib/etherlite/account.rb
CHANGED
@@ -31,26 +31,42 @@ module Etherlite
|
|
31
31
|
_function = Utils.parse_function(_function) unless _function.is_a? Contract::Function
|
32
32
|
options = _params.last.is_a?(Hash) ? _params.pop : {}
|
33
33
|
|
34
|
-
|
34
|
+
if _function.constant?
|
35
|
+
call_constant _target, _function, _params, options
|
36
|
+
else
|
37
|
+
send_function_transaction _target, _function, _params, options
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_reader :normalized_address
|
44
|
+
|
45
|
+
def call_constant(_target, _function, _params, _options)
|
46
|
+
ipc_params = {
|
35
47
|
from: json_encoded_address,
|
36
48
|
to: Utils.encode_address_param(_target),
|
37
49
|
data: _function.encode(_params)
|
38
50
|
}
|
39
51
|
|
40
|
-
|
41
|
-
_function.decode @connection, @connection.ipc_call(:eth_call, params, "latest")
|
42
|
-
else
|
43
|
-
if _function.payable? && options.key?(:pay)
|
44
|
-
params[:value] = Utils.encode_quantity_param options[:pay]
|
45
|
-
end
|
52
|
+
block = Utils.encode_block_param _options.fetch(:block, :latest)
|
46
53
|
|
47
|
-
|
48
|
-
end
|
54
|
+
_function.decode @connection, @connection.ipc_call(:eth_call, ipc_params, block)
|
49
55
|
end
|
50
56
|
|
51
|
-
|
57
|
+
def send_function_transaction(_target, _function, _params, _options)
|
58
|
+
ipc_params = {
|
59
|
+
from: json_encoded_address,
|
60
|
+
to: Utils.encode_address_param(_target),
|
61
|
+
data: _function.encode(_params)
|
62
|
+
}
|
52
63
|
|
53
|
-
|
64
|
+
value = _options.fetch(:pay, 0)
|
65
|
+
raise 'function is not payable' if value > 0 && !_function.payable?
|
66
|
+
ipc_params[:value] = value
|
67
|
+
|
68
|
+
send_transaction(ipc_params, _options)
|
69
|
+
end
|
54
70
|
|
55
71
|
def send_transaction(_params, _opt)
|
56
72
|
_params[:gas] = Utils.encode_quantity_param(_opt[:gas]) if _opt.key? :gas
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'eth'
|
2
|
+
|
3
|
+
module Etherlite
|
4
|
+
class PkAccount
|
5
|
+
include Etherlite::Api::Address
|
6
|
+
|
7
|
+
attr_reader :connection
|
8
|
+
|
9
|
+
def initialize(_connection, _pk)
|
10
|
+
@connection = _connection
|
11
|
+
@key = Eth::Key.new priv: _pk
|
12
|
+
end
|
13
|
+
|
14
|
+
def normalized_address
|
15
|
+
@normalized_address ||= Utils.normalize_address @key.address
|
16
|
+
end
|
17
|
+
|
18
|
+
def transfer_to(_target, _options = {})
|
19
|
+
send_transaction(
|
20
|
+
_options.fetch(:amount, 0), '', Utils.encode_address_param(_target), _options
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(_target, _function, *_params)
|
25
|
+
_function = Utils.parse_function(_function) unless _function.is_a? Contract::Function
|
26
|
+
options = _params.last.is_a?(Hash) ? _params.pop : {}
|
27
|
+
|
28
|
+
if _function.constant?
|
29
|
+
call_constant _target, _function, _params, options
|
30
|
+
else
|
31
|
+
value = options.fetch(:pay, 0)
|
32
|
+
raise 'function is not payable' if value > 0 && !_function.payable?
|
33
|
+
|
34
|
+
send_transaction(
|
35
|
+
value, _function.encode(_params), Utils.encode_address_param(_target), options
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def call_constant(_target, _function, _params, _options)
|
43
|
+
ipc_params = {
|
44
|
+
from: json_encoded_address,
|
45
|
+
to: Utils.encode_address_param(_target),
|
46
|
+
data: _function.encode(_params)
|
47
|
+
}
|
48
|
+
|
49
|
+
block = Utils.encode_block_param _options.fetch(:block, :latest)
|
50
|
+
|
51
|
+
_function.decode @connection, @connection.ipc_call(:eth_call, ipc_params, block)
|
52
|
+
end
|
53
|
+
|
54
|
+
def send_transaction(_value, _hex_data, _hex_address, _opt)
|
55
|
+
tx = Eth::Tx.new(
|
56
|
+
value: _value,
|
57
|
+
data: _hex_data,
|
58
|
+
gas_limit: _opt.fetch(:gas, 90_000),
|
59
|
+
gas_price: _opt.fetch(:gas_price, gas_price),
|
60
|
+
to: _hex_address,
|
61
|
+
nonce: 0
|
62
|
+
)
|
63
|
+
|
64
|
+
tx.sign @key
|
65
|
+
|
66
|
+
@connection.ipc_call(:eth_sendRawTransaction, tx.hex)
|
67
|
+
end
|
68
|
+
|
69
|
+
def gas_price
|
70
|
+
# TODO: improve on this
|
71
|
+
@gas_price ||= Etherlite::Utils.hex_to_uint @connection.ipc_call(:eth_gasPrice)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/etherlite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etherlite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignacio Baixas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: digest-sha3
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: eth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.4.4
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.4.4
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: activesupport
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,6 +175,7 @@ files:
|
|
161
175
|
- lib/etherlite/contract/event_base.rb
|
162
176
|
- lib/etherlite/contract/event_input.rb
|
163
177
|
- lib/etherlite/contract/function.rb
|
178
|
+
- lib/etherlite/pk_account.rb
|
164
179
|
- lib/etherlite/railtie.rb
|
165
180
|
- lib/etherlite/railties/configuration_extensions.rb
|
166
181
|
- lib/etherlite/railties/utils.rb
|