eth_tool 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/eth_tool.gemspec +30 -0
- data/lib/eth_tool.rb +229 -0
- data/lib/eth_tool/version.rb +3 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0d39009c73c72ae1efc9514d64fc8604adc71ab4
|
4
|
+
data.tar.gz: 9eb045ee35fe673a92638a9554afcee04c0b6e09
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b9dc1275802f494eb411042609d1668e7d9e8eb2cd4d7c429998a910adc9022953133ec52c6677906b60337ae4b0317dffc819f1103f7d2da8bf9f37874be98
|
7
|
+
data.tar.gz: bd07deeb2f188b8aea0f77fb46d344dd5b2d53da357bcdb2a07b6b897dda563f28e8b7a9c6683b54e29277e753699d1d620026053c3c60df0c93e2d8a2b796f6
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at wuminzhe@126.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
eth_tool (0.1.2)
|
5
|
+
bip44 (~> 0.2.14)
|
6
|
+
ethereum.rb (~> 2.1.8)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (5.1.5)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (~> 0.7)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
bip44 (0.2.14)
|
17
|
+
bip_mnemonic
|
18
|
+
digest-sha3 (~> 1.1.0)
|
19
|
+
ecdsa (~> 1.2.0)
|
20
|
+
eth
|
21
|
+
money-tree
|
22
|
+
rlp (~> 0.7.3)
|
23
|
+
bip_mnemonic (0.0.2)
|
24
|
+
concurrent-ruby (1.0.5)
|
25
|
+
digest-sha3 (1.1.0)
|
26
|
+
ecdsa (1.2.0)
|
27
|
+
eth (0.4.6)
|
28
|
+
digest-sha3 (~> 1.1)
|
29
|
+
ffi (~> 1.0)
|
30
|
+
money-tree (~> 0.9)
|
31
|
+
rlp (~> 0.7.3)
|
32
|
+
scrypt (~> 3.0.5)
|
33
|
+
ethereum.rb (2.1.8)
|
34
|
+
activesupport (~> 5.0)
|
35
|
+
digest-sha3 (~> 1.1)
|
36
|
+
ffi (1.9.22)
|
37
|
+
ffi-compiler (1.0.1)
|
38
|
+
ffi (>= 1.0.0)
|
39
|
+
rake
|
40
|
+
i18n (0.9.5)
|
41
|
+
concurrent-ruby (~> 1.0)
|
42
|
+
minitest (5.11.3)
|
43
|
+
money-tree (0.9.0)
|
44
|
+
ffi
|
45
|
+
rake (10.5.0)
|
46
|
+
rlp (0.7.3)
|
47
|
+
scrypt (3.0.5)
|
48
|
+
ffi-compiler (>= 1.0, < 2.0)
|
49
|
+
thread_safe (0.3.6)
|
50
|
+
tzinfo (1.2.5)
|
51
|
+
thread_safe (~> 0.1)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
bundler (~> 1.16)
|
58
|
+
eth_tool!
|
59
|
+
rake (~> 10.0)
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Wu Minzhe
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# EthTool
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/eth_tool`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'eth_tool'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install eth_tool
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/eth_tool. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the EthTool project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/eth_tool/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "eth_tool"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/eth_tool.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "eth_tool/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "eth_tool"
|
8
|
+
spec.version = EthTool::VERSION
|
9
|
+
spec.authors = ["Wu Minzhe"]
|
10
|
+
spec.email = ["wuminzhe@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "my eth tool"
|
13
|
+
spec.description = "my eth tool"
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_dependency "bip44", "~> 0.2.14"
|
27
|
+
spec.add_dependency "ethereum.rb", "~> 2.1.8"
|
28
|
+
|
29
|
+
|
30
|
+
end
|
data/lib/eth_tool.rb
ADDED
@@ -0,0 +1,229 @@
|
|
1
|
+
require "eth_tool/version"
|
2
|
+
require 'bip44'
|
3
|
+
require 'ethereum.rb'
|
4
|
+
require 'eth'
|
5
|
+
require 'bigdecimal'
|
6
|
+
|
7
|
+
module EthTool
|
8
|
+
@@gas_limit = 60000
|
9
|
+
@@gas_price = 5_000_000_000
|
10
|
+
|
11
|
+
def self.rpc=(url)
|
12
|
+
@@rpc = Ethereum::HttpClient.new(url)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.rpc
|
16
|
+
@@rpc
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.gas_limit=(gas_limit)
|
20
|
+
@@gas_limit = gas_limit
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.gas_price=(gas_price)
|
24
|
+
@@gas_price = gas_price
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.fee
|
28
|
+
BigDecimal(@@gas_limit) * BigDecimal(@@gas_price) / 10**18.to_f
|
29
|
+
end
|
30
|
+
|
31
|
+
class << self
|
32
|
+
attr_accessor :logger
|
33
|
+
end
|
34
|
+
|
35
|
+
############################################################################
|
36
|
+
|
37
|
+
def self.get_token_balance(address, token_contract_address, token_decimals)
|
38
|
+
data = '0x70a08231' + padding(address) # Ethereum::Function.calc_id('balanceOf(address)') # 70a08231
|
39
|
+
|
40
|
+
result = @@rpc.eth_call({to: token_contract_address, data: data})['result'].to_i(16)
|
41
|
+
BigDecimal(result) / BigDecimal(10**token_decimals)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.get_eth_balance(address)
|
45
|
+
result = @@rpc.eth_get_balance(address)['result'].to_i(16)
|
46
|
+
BigDecimal(result) / BigDecimal(10**18)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.generate_raw_transaction(private_key, value, data, gas_limit, gas_price = nil, to = nil, nonce = nil)
|
50
|
+
key = ::Eth::Key.new priv: private_key
|
51
|
+
address = key.address
|
52
|
+
|
53
|
+
gas_price_in_dec = gas_price.nil? ? @@rpc.eth_gas_price["result"].to_i(16) : gas_price
|
54
|
+
nonce = nonce.nil? ? @@rpc.eth_get_transaction_count(address, 'pending')["result"].to_i(16) : nonce
|
55
|
+
|
56
|
+
args = {
|
57
|
+
from: address,
|
58
|
+
value: 0,
|
59
|
+
data: '0x0',
|
60
|
+
nonce: nonce,
|
61
|
+
gas_limit: gas_limit,
|
62
|
+
gas_price: gas_price_in_dec
|
63
|
+
}
|
64
|
+
|
65
|
+
args[:value] = (value * 10**18).to_i if value
|
66
|
+
args[:data] = data if data
|
67
|
+
args[:to] = to if to
|
68
|
+
tx = Eth::Tx.new(args)
|
69
|
+
tx.sign key
|
70
|
+
tx.hex
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.transfer_token(private_key, token_contract_address, token_decimals, amount, gas_limit, gas_price, to)
|
74
|
+
if amount < (1.0/10**token_decimals)
|
75
|
+
logger.info "转账金额不能小于精度最小单位(#{token_contract_address}, #{token_decimals})"
|
76
|
+
return
|
77
|
+
end
|
78
|
+
|
79
|
+
# 生成raw transaction
|
80
|
+
amount_in_wei = (amount * (10**token_decimals)).to_i
|
81
|
+
data = '0xa9059cbb' + padding(to) + padding(dec_to_hex(amount_in_wei)) # Ethereum::Function.calc_id('transfer(address,uint256)') # a9059cbb
|
82
|
+
rawtx = generate_raw_transaction(private_key, 0, data, gas_limit, gas_price, token_contract_address)
|
83
|
+
|
84
|
+
@@rpc.eth_send_raw_transaction(rawtx)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.transfer_eth(private_key, amount, gas_limit, gas_price, to)
|
88
|
+
if amount < (1.0/10**18)
|
89
|
+
logger.info "转账金额不能小于以太坊最小单位"
|
90
|
+
return
|
91
|
+
end
|
92
|
+
rawtx = generate_raw_transaction(private_key, amount, nil, gas_limit, gas_price, to)
|
93
|
+
@@rpc.eth_send_raw_transaction(rawtx)
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
def self.sweep_token(private_key, token_contract_address, token_decimals, to)
|
98
|
+
address = ::Eth::Key.new(priv: private_key).address
|
99
|
+
token_balance = get_token_balance(address, token_contract_address, token_decimals)
|
100
|
+
return if token_balance == 0
|
101
|
+
transfer_token(private_key, token_contract_address, token_decimals, token_balance, @@gas_limit, @@gas_price, to)
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.sweep_eth(private_key, to)
|
105
|
+
address = ::Eth::Key.new(priv: private_key).address
|
106
|
+
eth_balance = get_eth_balance(address)
|
107
|
+
keep = BigDecimal(@@gas_limit) * BigDecimal(@@gas_price) / 10**18
|
108
|
+
amount = eth_balance - keep
|
109
|
+
return if amount <= 0
|
110
|
+
transfer_eth(private_key, amount, @@gas_limit, @@gas_price, to)
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.fill_eth(private_key, to)
|
114
|
+
# 目标地址上现有eth
|
115
|
+
eth_balance = get_eth_balance(to)
|
116
|
+
|
117
|
+
# 目标地址上需要填充满这么多eth
|
118
|
+
amount = BigDecimal(@@gas_limit) * BigDecimal(@@gas_price) / 10**18
|
119
|
+
|
120
|
+
return unless eth_balance < amount # 如果有足够多的eth,就直接返回
|
121
|
+
|
122
|
+
transfer_eth(private_key, (amount-eth_balance), @@gas_limit, @@gas_price, to)
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.tx_replace(private_key, txhash, gas_price)
|
126
|
+
tx = @@rpc.eth_get_transaction_by_hash(txhash)["result"]
|
127
|
+
return if tx.nil?
|
128
|
+
|
129
|
+
value = tx["value"].to_i(16)
|
130
|
+
data = tx["input"]
|
131
|
+
gas_limit = tx["gas"].to_i(16)
|
132
|
+
gas_price = gas_price
|
133
|
+
to = tx["to"]
|
134
|
+
nonce = tx["nonce"].to_i(16)
|
135
|
+
|
136
|
+
rawtx = generate_raw_transaction(private_key, value, data, gas_limit, gas_price, to, nonce)
|
137
|
+
@@rpc.eth_send_raw_transaction(rawtx)
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.get_private_key_from_keystore(dir, address, passphrase)
|
141
|
+
path = File.join(dir, '*')
|
142
|
+
Dir[path].each do |file|
|
143
|
+
if file.end_with?(address[2..-1])
|
144
|
+
key = ::Eth::Key.decrypt(File.read(file), passphrase)
|
145
|
+
return key.private_key.to_hex
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def self.generate_addresses_from_xprv(xprv, amount)
|
151
|
+
result = []
|
152
|
+
wallet = Bip44::Wallet.from_xprv(xprv)
|
153
|
+
amount.times do |i|
|
154
|
+
sub_wallet = wallet.sub_wallet("m/#{i}")
|
155
|
+
result << sub_wallet.ethereum_address
|
156
|
+
end
|
157
|
+
result
|
158
|
+
end
|
159
|
+
|
160
|
+
def self.get_private_key_from_xprv(xprv, index)
|
161
|
+
wallet = Bip44::Wallet.from_xprv(xprv)
|
162
|
+
sub_wallet = wallet.sub_wallet("m/#{index}")
|
163
|
+
return sub_wallet.private_key, sub_wallet.ethereum_address
|
164
|
+
end
|
165
|
+
|
166
|
+
def self.wait_for_miner(txhash, timeout: 1200, step: 20)
|
167
|
+
start_time = Time.now
|
168
|
+
loop do
|
169
|
+
raise Timeout::Error if ((Time.now - start_time) > timeout)
|
170
|
+
return true if mined?(txhash)
|
171
|
+
sleep step
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.mined?(txhash)
|
176
|
+
tx = @@rpc.eth_get_transaction_by_hash(txhash)["result"]
|
177
|
+
tx and (not tx['blockNumber'].nil?)
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.confirmed?(txhash, number)
|
181
|
+
tx = @@rpc.eth_get_transaction_by_hash(txhash)["result"]
|
182
|
+
|
183
|
+
return false unless (tx and (not tx['blockNumber'].nil?))
|
184
|
+
|
185
|
+
block_number = tx['blockNumber'].to_i(16)
|
186
|
+
current_block_number = @@rpc.eth_block_number["result"].to_i(16)
|
187
|
+
confirmations = current_block_number - block_number
|
188
|
+
|
189
|
+
confirmations >= number
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.confirmations(txhash)
|
193
|
+
tx = @@rpc.eth_get_transaction_by_hash(txhash)["result"]
|
194
|
+
|
195
|
+
return 0 unless (tx and (not tx['blockNumber'].nil?))
|
196
|
+
|
197
|
+
block_number = tx['blockNumber'].to_i(16)
|
198
|
+
current_block_number = @@rpc.eth_block_number["result"].to_i(16)
|
199
|
+
current_block_number - block_number
|
200
|
+
end
|
201
|
+
|
202
|
+
def self.token_transfer_success?(txhash)
|
203
|
+
tx = @@rpc.eth_get_transaction_by_hash(txhash)["result"]
|
204
|
+
return false unless (tx and (not tx['blockNumber'].nil?))
|
205
|
+
|
206
|
+
receipt = @@rpc.eth_get_transaction_receipt(txhash)["result"]
|
207
|
+
return false unless receipt
|
208
|
+
|
209
|
+
return false if (receipt['status'] && receipt['status'] == '0x0')
|
210
|
+
end
|
211
|
+
|
212
|
+
# helper methods #########################################################
|
213
|
+
|
214
|
+
def self.dec_to_hex(value)
|
215
|
+
'0x'+value.to_s(16)
|
216
|
+
end
|
217
|
+
|
218
|
+
def self.padding(str)
|
219
|
+
if str =~ /^0x[a-f0-9]*/
|
220
|
+
str = str[2 .. str.length-1]
|
221
|
+
end
|
222
|
+
str.rjust(64, '0')
|
223
|
+
end
|
224
|
+
|
225
|
+
def self.wputs(file, text)
|
226
|
+
File.open(file, 'a') { |f| f.puts(text) }
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eth_tool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wu Minzhe
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bip44
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.14
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.14
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ethereum.rb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.8
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.1.8
|
69
|
+
description: my eth tool
|
70
|
+
email:
|
71
|
+
- wuminzhe@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- CODE_OF_CONDUCT.md
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- eth_tool.gemspec
|
86
|
+
- lib/eth_tool.rb
|
87
|
+
- lib/eth_tool/version.rb
|
88
|
+
homepage: ''
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.6.14
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: my eth tool
|
112
|
+
test_files: []
|