eth_tool 0.1.2 → 0.1.5
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/.DS_Store +0 -0
- data/Gemfile.lock +6 -6
- data/lib/.DS_Store +0 -0
- data/lib/eth_tool.rb +48 -29
- data/lib/eth_tool/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 42582922f086da93a06a03794c5f7fc8dc597d99
|
|
4
|
+
data.tar.gz: b47aba46aa564894485d3e9d3972f3c12767bd96
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d063fbb0bbeaf4193e40ecbe494c96cf44c294916be0c5fda3144875f245c8ef579b1aff156c24f27947c85e1079bb43dee88bd60ee5c3223055d75934ef7f6a
|
|
7
|
+
data.tar.gz: 2e8393d5a93f7008fde1380cdc29fb18fb7e6e290d7618ce2d1d8f8d49b44e5a211a60d3ff4b5467d763dec4e708b1ced04e7f63566af500b7d83f585334a53d
|
data/.DS_Store
ADDED
|
Binary file
|
data/Gemfile.lock
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
eth_tool (0.1.
|
|
4
|
+
eth_tool (0.1.5)
|
|
5
5
|
bip44 (~> 0.2.14)
|
|
6
6
|
ethereum.rb (~> 2.1.8)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
activesupport (5.
|
|
11
|
+
activesupport (5.2.0)
|
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
13
|
-
i18n (
|
|
13
|
+
i18n (>= 0.7, < 2)
|
|
14
14
|
minitest (~> 5.1)
|
|
15
15
|
tzinfo (~> 1.1)
|
|
16
|
-
bip44 (0.2.
|
|
16
|
+
bip44 (0.2.15)
|
|
17
17
|
bip_mnemonic
|
|
18
18
|
digest-sha3 (~> 1.1.0)
|
|
19
19
|
ecdsa (~> 1.2.0)
|
|
@@ -33,11 +33,11 @@ GEM
|
|
|
33
33
|
ethereum.rb (2.1.8)
|
|
34
34
|
activesupport (~> 5.0)
|
|
35
35
|
digest-sha3 (~> 1.1)
|
|
36
|
-
ffi (1.9.
|
|
36
|
+
ffi (1.9.23)
|
|
37
37
|
ffi-compiler (1.0.1)
|
|
38
38
|
ffi (>= 1.0.0)
|
|
39
39
|
rake
|
|
40
|
-
i18n (0.
|
|
40
|
+
i18n (1.0.1)
|
|
41
41
|
concurrent-ruby (~> 1.0)
|
|
42
42
|
minitest (5.11.3)
|
|
43
43
|
money-tree (0.9.0)
|
data/lib/.DS_Store
ADDED
|
Binary file
|
data/lib/eth_tool.rb
CHANGED
|
@@ -5,8 +5,6 @@ require 'eth'
|
|
|
5
5
|
require 'bigdecimal'
|
|
6
6
|
|
|
7
7
|
module EthTool
|
|
8
|
-
@@gas_limit = 60000
|
|
9
|
-
@@gas_price = 5_000_000_000
|
|
10
8
|
|
|
11
9
|
def self.rpc=(url)
|
|
12
10
|
@@rpc = Ethereum::HttpClient.new(url)
|
|
@@ -16,16 +14,8 @@ module EthTool
|
|
|
16
14
|
@@rpc
|
|
17
15
|
end
|
|
18
16
|
|
|
19
|
-
def self.
|
|
20
|
-
|
|
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
|
|
17
|
+
def self.fee(gas_limit, gas_price)
|
|
18
|
+
BigDecimal(gas_limit) * BigDecimal(gas_price) / 10**18.to_f
|
|
29
19
|
end
|
|
30
20
|
|
|
31
21
|
class << self
|
|
@@ -33,6 +23,7 @@ module EthTool
|
|
|
33
23
|
end
|
|
34
24
|
|
|
35
25
|
############################################################################
|
|
26
|
+
|
|
36
27
|
|
|
37
28
|
def self.get_token_balance(address, token_contract_address, token_decimals)
|
|
38
29
|
data = '0x70a08231' + padding(address) # Ethereum::Function.calc_id('balanceOf(address)') # 70a08231
|
|
@@ -70,7 +61,39 @@ module EthTool
|
|
|
70
61
|
tx.hex
|
|
71
62
|
end
|
|
72
63
|
|
|
73
|
-
def self.
|
|
64
|
+
# def self.wputs(text)
|
|
65
|
+
# File.open('/Users/wuminzhe/Projects/eth_tool/scripts/fuck.txt', 'a') { |f| f.puts(text) }
|
|
66
|
+
# end
|
|
67
|
+
|
|
68
|
+
def self.estimate_gas(to, data)
|
|
69
|
+
@@rpc.eth_estimate_gas({to: to, data: data})["result"].to_i(16)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.build_airdrop_data(token_contract_address, addresses, values)
|
|
73
|
+
data = "0xad8733ca"
|
|
74
|
+
data = data + padding(token_contract_address)
|
|
75
|
+
data = data + "0000000000000000000000000000000000000000000000000000000000000060"
|
|
76
|
+
data = data + "0000000000000000000000000000000000000000000000000000000000001840"
|
|
77
|
+
data = data + "00000000000000000000000000000000000000000000000000000000000000be"
|
|
78
|
+
addresses.each do |address|
|
|
79
|
+
data = data + padding(address.downcase)
|
|
80
|
+
end
|
|
81
|
+
data = data + "00000000000000000000000000000000000000000000000000000000000000be"
|
|
82
|
+
values.each do |value|
|
|
83
|
+
data = data + padding(value.to_i.to_s(16))
|
|
84
|
+
end
|
|
85
|
+
return data
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def self.airdrop(private_key, airdrop_contract_address, token_contract_address, addresses, values, gas_limit, gas_price)
|
|
89
|
+
data = build_airdrop_data(token_contract_address, addresses, values)
|
|
90
|
+
|
|
91
|
+
rawtx = generate_raw_transaction(private_key, 0, data, gas_limit, gas_price, airdrop_contract_address)
|
|
92
|
+
|
|
93
|
+
@@rpc.eth_send_raw_transaction(rawtx)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.transfer_token(private_key, token_contract_address, token_decimals, amount, gas_limit, gas_price, to, nonce=nil)
|
|
74
97
|
if amount < (1.0/10**token_decimals)
|
|
75
98
|
logger.info "转账金额不能小于精度最小单位(#{token_contract_address}, #{token_decimals})"
|
|
76
99
|
return
|
|
@@ -79,7 +102,7 @@ module EthTool
|
|
|
79
102
|
# 生成raw transaction
|
|
80
103
|
amount_in_wei = (amount * (10**token_decimals)).to_i
|
|
81
104
|
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)
|
|
105
|
+
rawtx = generate_raw_transaction(private_key, 0, data, gas_limit, gas_price, token_contract_address, nonce)
|
|
83
106
|
|
|
84
107
|
@@rpc.eth_send_raw_transaction(rawtx)
|
|
85
108
|
end
|
|
@@ -93,33 +116,33 @@ module EthTool
|
|
|
93
116
|
@@rpc.eth_send_raw_transaction(rawtx)
|
|
94
117
|
end
|
|
95
118
|
|
|
96
|
-
#
|
|
97
|
-
def self.sweep_token(private_key, token_contract_address, token_decimals, to)
|
|
119
|
+
# sweep
|
|
120
|
+
def self.sweep_token(private_key, token_contract_address, token_decimals, to, gas_limit=60000, gas_price=5_000_000_000)
|
|
98
121
|
address = ::Eth::Key.new(priv: private_key).address
|
|
99
122
|
token_balance = get_token_balance(address, token_contract_address, token_decimals)
|
|
100
123
|
return if token_balance == 0
|
|
101
|
-
transfer_token(private_key, token_contract_address, token_decimals, token_balance,
|
|
124
|
+
transfer_token(private_key, token_contract_address, token_decimals, token_balance, gas_limit, gas_price, to)
|
|
102
125
|
end
|
|
103
126
|
|
|
104
|
-
def self.sweep_eth(private_key, to)
|
|
127
|
+
def self.sweep_eth(private_key, to, gas_limit=60000, gas_price=5_000_000_000)
|
|
105
128
|
address = ::Eth::Key.new(priv: private_key).address
|
|
106
129
|
eth_balance = get_eth_balance(address)
|
|
107
|
-
|
|
130
|
+
# 转eth不能都转,要留一点作为gas费用
|
|
131
|
+
keep = BigDecimal(gas_limit) * BigDecimal(gas_price) / 10**18
|
|
108
132
|
amount = eth_balance - keep
|
|
109
133
|
return if amount <= 0
|
|
110
|
-
transfer_eth(private_key, amount,
|
|
134
|
+
transfer_eth(private_key, amount, gas_limit, gas_price, to)
|
|
111
135
|
end
|
|
112
136
|
|
|
113
|
-
|
|
137
|
+
# 目标地址上需要填充满这么多eth
|
|
138
|
+
# amount = BigDecimal(gas_limit) * BigDecimal(gas_price) / 10**18
|
|
139
|
+
def self.fill_eth(private_key, to, amount, gas_limit=60000, gas_price=5_000_000_000)
|
|
114
140
|
# 目标地址上现有eth
|
|
115
141
|
eth_balance = get_eth_balance(to)
|
|
116
142
|
|
|
117
|
-
# 目标地址上需要填充满这么多eth
|
|
118
|
-
amount = BigDecimal(@@gas_limit) * BigDecimal(@@gas_price) / 10**18
|
|
119
|
-
|
|
120
143
|
return unless eth_balance < amount # 如果有足够多的eth,就直接返回
|
|
121
144
|
|
|
122
|
-
transfer_eth(private_key, (amount-eth_balance),
|
|
145
|
+
transfer_eth(private_key, (amount-eth_balance), gas_limit, gas_price, to)
|
|
123
146
|
end
|
|
124
147
|
|
|
125
148
|
def self.tx_replace(private_key, txhash, gas_price)
|
|
@@ -221,9 +244,5 @@ module EthTool
|
|
|
221
244
|
end
|
|
222
245
|
str.rjust(64, '0')
|
|
223
246
|
end
|
|
224
|
-
|
|
225
|
-
def self.wputs(file, text)
|
|
226
|
-
File.open(file, 'a') { |f| f.puts(text) }
|
|
227
|
-
end
|
|
228
247
|
|
|
229
248
|
end
|
data/lib/eth_tool/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: eth_tool
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Wu Minzhe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-05-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -73,6 +73,7 @@ executables: []
|
|
|
73
73
|
extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
|
75
75
|
files:
|
|
76
|
+
- ".DS_Store"
|
|
76
77
|
- ".gitignore"
|
|
77
78
|
- CODE_OF_CONDUCT.md
|
|
78
79
|
- Gemfile
|
|
@@ -83,6 +84,7 @@ files:
|
|
|
83
84
|
- bin/console
|
|
84
85
|
- bin/setup
|
|
85
86
|
- eth_tool.gemspec
|
|
87
|
+
- lib/.DS_Store
|
|
86
88
|
- lib/eth_tool.rb
|
|
87
89
|
- lib/eth_tool/version.rb
|
|
88
90
|
homepage: ''
|