web3_lib 0.4.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 +7 -0
- data/lib/eth_calls.rb +293 -0
- data/lib/miner_calls.rb +44 -0
- data/lib/net_calls.rb +20 -0
- data/lib/personal_calls.rb +55 -0
- data/lib/shh_calls.rb +62 -0
- data/lib/txpool_calls.rb +9 -0
- data/lib/web3.rb +177 -0
- data/lib/web3_calls.rb +14 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f9299ed6878ebfa8a9751561aec086e23d4ee175
|
4
|
+
data.tar.gz: 6b94fe6b4ec85bd054ed4d852b88ecd0d40824a6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 451c77e8b68a632410e9009452204fd15b35351eb3478e40450a685cc69c313bb5b7d5656c1a72d0a4d71a55e6abb2b9fe53a4e79cea4768141e13fd026b49df
|
7
|
+
data.tar.gz: 505fd5c7d8d76f36a58a63fc10c3720f669056d97b8242e71824ce51d62d6aa83e4e899052ab035a6da55ed5cea5d65f88752abbd1a565715da5ba0ddd1d14a6
|
data/lib/eth_calls.rb
ADDED
@@ -0,0 +1,293 @@
|
|
1
|
+
module Web3::EthCalls
|
2
|
+
|
3
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_protocolversion
|
4
|
+
def eth_protocolVersion()
|
5
|
+
raise NotImplementedError.new "JSON-RPC call to eth_protocolVersion is not currently supported"
|
6
|
+
end
|
7
|
+
|
8
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_syncing
|
9
|
+
def eth_syncing()
|
10
|
+
response = do_request("eth_syncing")
|
11
|
+
response["result"]
|
12
|
+
end
|
13
|
+
|
14
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_coinbase
|
15
|
+
def eth_coinbase()
|
16
|
+
response = do_request("eth_coinbase")
|
17
|
+
response["result"]
|
18
|
+
end
|
19
|
+
|
20
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_mining
|
21
|
+
def eth_mining()
|
22
|
+
response = do_request("eth_mining")
|
23
|
+
response["result"]
|
24
|
+
end
|
25
|
+
|
26
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_hashrate
|
27
|
+
def eth_hashrate()
|
28
|
+
response = do_request("eth_hashrate")
|
29
|
+
to_decimal response["result"]
|
30
|
+
end
|
31
|
+
|
32
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gasprice
|
33
|
+
def eth_gasPrice()
|
34
|
+
response = do_request("eth_gasPrice")
|
35
|
+
to_decimal response["result"]
|
36
|
+
end
|
37
|
+
|
38
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_accounts
|
39
|
+
def eth_accounts()
|
40
|
+
response = do_request("eth_accounts")
|
41
|
+
response["result"]
|
42
|
+
end
|
43
|
+
|
44
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_blocknumber
|
45
|
+
def eth_blockNumber()
|
46
|
+
response = do_request("eth_blockNumber")
|
47
|
+
to_decimal response["result"]
|
48
|
+
end
|
49
|
+
|
50
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getbalance
|
51
|
+
def eth_getBalance(address, block = "latest")
|
52
|
+
response = do_request("eth_getBalance",[address, block])
|
53
|
+
to_decimal response["result"]
|
54
|
+
end
|
55
|
+
|
56
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getstorageat
|
57
|
+
def eth_getStorageAt(storage_address, position, block = "latest")
|
58
|
+
response = do_request("eth_getStorageAt",[storage_address, to_hex(position), block])
|
59
|
+
response["result"]
|
60
|
+
end
|
61
|
+
|
62
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactioncount
|
63
|
+
def eth_getTransactionCount(address, block = "latest")
|
64
|
+
response = do_request("eth_getTransactionCount",[address, block])
|
65
|
+
to_decimal response["result"]
|
66
|
+
end
|
67
|
+
|
68
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblocktransactioncountbyhash
|
69
|
+
def eth_getBlockTransactionCountByHash(data)
|
70
|
+
response = do_request("eth_getBlockTransactionCountByHash",[data])
|
71
|
+
to_decimal response["result"]
|
72
|
+
end
|
73
|
+
|
74
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblocktransactioncountbynumber
|
75
|
+
def eth_getBlockTransactionCountByNumber(block = "latest")
|
76
|
+
response = do_request("eth_getBlockTransactionCountByNumber",[block])
|
77
|
+
to_decimal response["result"]
|
78
|
+
end
|
79
|
+
|
80
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclecountbyblockhash
|
81
|
+
def eth_getUncleCountByBlockHash(data)
|
82
|
+
response = do_request("eth_getUncleCountByBlockHash",[data])
|
83
|
+
to_decimal response["result"]
|
84
|
+
end
|
85
|
+
|
86
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclecountbyblocknumber
|
87
|
+
def eth_getUncleCountByBlockNumber(data)
|
88
|
+
response = do_request("eth_getUncleCountByBlockNumber",[data])
|
89
|
+
to_decimal response["result"]
|
90
|
+
end
|
91
|
+
|
92
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcode
|
93
|
+
def eth_getCode(address, block = "latest")
|
94
|
+
response = do_request("eth_getCode",[address, block])
|
95
|
+
response["result"]
|
96
|
+
end
|
97
|
+
|
98
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
|
99
|
+
def eth_sign(address, data)
|
100
|
+
response = do_request("eth_sign",[address, data])
|
101
|
+
response["result"]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Sends a transaction for posting to the ethereum network. The transaction_object
|
105
|
+
# that is sent should look something like this:
|
106
|
+
#
|
107
|
+
# {"from"=> accounts[0], "to" => accounts[1], "value" => w3.ether_to_0xwei(0.001)}
|
108
|
+
#
|
109
|
+
# Other 0x-fomatted attributes that can be included in the transaction_object are:
|
110
|
+
# "data" : formatted as hex
|
111
|
+
# "gas", "gasPrice", "value", and "nonce" : formatted as "0x" + hex
|
112
|
+
#
|
113
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendtransaction
|
114
|
+
def eth_sendTransaction(transaction_object)
|
115
|
+
response = do_request("eth_sendTransaction",[transaction_object])
|
116
|
+
response["result"]
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns pending transactions that belong to any of the users accounts
|
120
|
+
# See https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console#ethpendingtransactions
|
121
|
+
def eth_pendingTransactions()
|
122
|
+
response = do_request("eth_pendingTransactions")
|
123
|
+
response["result"]
|
124
|
+
end
|
125
|
+
|
126
|
+
# Resends a transaction. These can ge retrieved from eth_pendingTransactions().
|
127
|
+
# gasPrice and gasLimit can be included together if the gas settings are being changed from
|
128
|
+
# their original settings in the pending_transaction object
|
129
|
+
# See https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console#ethresend
|
130
|
+
def eth_resend(pending_transaction, gasPrice=nil, gasLimit=nil)
|
131
|
+
package = [pending_transaction]
|
132
|
+
if gasPrice != nil
|
133
|
+
package += [gasPrice, gasLimit]
|
134
|
+
end
|
135
|
+
response = do_request("eth_resend", package)
|
136
|
+
response["result"]
|
137
|
+
end
|
138
|
+
|
139
|
+
# This sends a transaction that looks something like this:
|
140
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendrawtransaction
|
141
|
+
def eth_sendRawTransaction(data)
|
142
|
+
response = do_request("eth_sendRawTransaction",[data])
|
143
|
+
response["result"]
|
144
|
+
end
|
145
|
+
|
146
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_call
|
147
|
+
def eth_call(trans_object,block="latest")
|
148
|
+
response = do_request("eth_call",[trans_object, block])
|
149
|
+
response["result"]
|
150
|
+
end
|
151
|
+
|
152
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_estimategas
|
153
|
+
def eth_estimateGas(trans_object)
|
154
|
+
response = do_request("eth_estimateGas",[trans_object])
|
155
|
+
response["result"]
|
156
|
+
end
|
157
|
+
|
158
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblockbyhash
|
159
|
+
def eth_getBlockByHash(hash, full_transactions = true)
|
160
|
+
response = do_request("eth_getBlockByHash",[hash, full_transactions])
|
161
|
+
response["result"]
|
162
|
+
end
|
163
|
+
|
164
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblockbynumber
|
165
|
+
def eth_getBlockByNumber(number, full_transactions = true)
|
166
|
+
response = do_request("eth_getBlockByNumber",[number, full_transactions])
|
167
|
+
response["result"]
|
168
|
+
end
|
169
|
+
|
170
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyhash
|
171
|
+
def eth_getTransactionByHash(hash)
|
172
|
+
response = do_request("eth_getTransactionByHash",[hash])
|
173
|
+
response["result"]
|
174
|
+
end
|
175
|
+
|
176
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyblockhashandindex
|
177
|
+
def eth_getTransactionByBlockHashAndIndex(hash, index)
|
178
|
+
response = do_request("eth_getTransactionByBlockHashAndIndex",[hash, index])
|
179
|
+
response["result"]
|
180
|
+
end
|
181
|
+
|
182
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyblocknumberandindex
|
183
|
+
def eth_getTransactionByBlockNumberAndIndex(number, index)
|
184
|
+
response = do_request("eth_getTransactionByBlockNumberAndIndex",[number, index])
|
185
|
+
response["result"]
|
186
|
+
end
|
187
|
+
|
188
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionreceipt
|
189
|
+
def eth_getTransactionReceipt(hash)
|
190
|
+
response = do_request("eth_getTransactionReceipt",[hash])
|
191
|
+
response["result"]
|
192
|
+
end
|
193
|
+
|
194
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclebyblockhashandindex
|
195
|
+
def eth_getUncleByBlockHashAndIndex(hash, index)
|
196
|
+
response = do_request("eth_getUncleByBlockHashAndIndex",[hash, index])
|
197
|
+
response["result"]
|
198
|
+
end
|
199
|
+
|
200
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclebyblocknumberandindex
|
201
|
+
def eth_getUncleByBlockNumberAndIndex(number, index)
|
202
|
+
response = do_request("eth_getUncleByBlockNumberAndIndex",[number, index])
|
203
|
+
response["result"]
|
204
|
+
end
|
205
|
+
|
206
|
+
# deprecated
|
207
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcompilers
|
208
|
+
def eth_getCompilers()
|
209
|
+
response = do_request("eth_getCompilers")
|
210
|
+
response["result"]
|
211
|
+
end
|
212
|
+
|
213
|
+
#deprecated
|
214
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compilelll
|
215
|
+
def eth_compileLLL(code)
|
216
|
+
response = do_request("eth_compileLLL",[code])
|
217
|
+
response["result"]
|
218
|
+
end
|
219
|
+
|
220
|
+
# deprecated
|
221
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compilesolidity
|
222
|
+
def eth_compileSolidity(code)
|
223
|
+
response = do_request("eth_compileSolidity",[code])
|
224
|
+
response["result"]
|
225
|
+
end
|
226
|
+
|
227
|
+
# deprecated
|
228
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compileserpent
|
229
|
+
def eth_compileSerpent(code)
|
230
|
+
response = do_request("eth_compileSerpent",[code])
|
231
|
+
response["result"]
|
232
|
+
end
|
233
|
+
|
234
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter
|
235
|
+
def eth_newFilter(fromBlock, toBlock, address, topics)
|
236
|
+
response = do_request("$CODE",[fromBlock, toBlock, address, topics])
|
237
|
+
to_decimal response["result"]
|
238
|
+
end
|
239
|
+
|
240
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newblockfilter
|
241
|
+
def eth_newBlockFilter()
|
242
|
+
response = do_request("eth_newBlockFilter")
|
243
|
+
to_decimal response["result"]
|
244
|
+
end
|
245
|
+
|
246
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newpendingtransactionfilter
|
247
|
+
def eth_newPendingTransactionFilter()
|
248
|
+
response = do_request("eth_newPendingTransactionFilter")
|
249
|
+
to_decimal response["result"]
|
250
|
+
end
|
251
|
+
|
252
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_uninstallfilter
|
253
|
+
def eth_uninstallFilter(id)
|
254
|
+
response = do_request("eth_uninstallFilter",[id])
|
255
|
+
response["result"]
|
256
|
+
end
|
257
|
+
|
258
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterchanges
|
259
|
+
def eth_getFilterChanges(id)
|
260
|
+
response = do_request("eth_getFilterChanges",[id])
|
261
|
+
response["result"]
|
262
|
+
end
|
263
|
+
|
264
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterlogs
|
265
|
+
def eth_getFilterLogs(id)
|
266
|
+
response = do_request("eth_getFilterLogs",[id])
|
267
|
+
response["result"]
|
268
|
+
end
|
269
|
+
|
270
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs
|
271
|
+
def eth_getLogs(filter_obj)
|
272
|
+
response = do_request("eth_getLogs",[filter_obj])
|
273
|
+
response["result"]
|
274
|
+
end
|
275
|
+
|
276
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getwork
|
277
|
+
def eth_getWork()
|
278
|
+
response = do_request("eth_getWork")
|
279
|
+
response["result"]
|
280
|
+
end
|
281
|
+
|
282
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_submitwork
|
283
|
+
def eth_submitWork(nonce, powHash, mixDigest)
|
284
|
+
response = do_request("eth_submitWork",[nonce, powHash, mixDigest])
|
285
|
+
response["result"]
|
286
|
+
end
|
287
|
+
|
288
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_submithashrate
|
289
|
+
def eth_submitHashrate(hashrate, id)
|
290
|
+
response = do_request("eth_submitHashrate",[hashrate, id])
|
291
|
+
response["result"]
|
292
|
+
end
|
293
|
+
end
|
data/lib/miner_calls.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Web3::MinerCalls
|
2
|
+
|
3
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#miner_makedag
|
4
|
+
def miner_makeDAG(number)
|
5
|
+
response = do_request("miner_makeDAG",[number])
|
6
|
+
response["result"]
|
7
|
+
end
|
8
|
+
|
9
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#miner_setextra
|
10
|
+
def miner_setExtra(extra)
|
11
|
+
response = do_request("miner_setExtra",[extra])
|
12
|
+
response["result"]
|
13
|
+
end
|
14
|
+
|
15
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#miner_setgasprice
|
16
|
+
def miner_setGasPrice(gasPrice)
|
17
|
+
response = do_request("miner_setGasPrice",[gasPrice])
|
18
|
+
response["result"]
|
19
|
+
end
|
20
|
+
|
21
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#miner_start
|
22
|
+
def miner_start(threads)
|
23
|
+
response = do_request("miner_start",[threads])
|
24
|
+
response["result"]
|
25
|
+
end
|
26
|
+
|
27
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#miner_startautodag
|
28
|
+
def miner_startAutoDAG(number)
|
29
|
+
response = do_request("miner_startAutoDAG",[number])
|
30
|
+
response["result"]
|
31
|
+
end
|
32
|
+
|
33
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#miner_stop
|
34
|
+
def miner_stop()
|
35
|
+
response = do_request("miner_stop")
|
36
|
+
response["result"]
|
37
|
+
end
|
38
|
+
|
39
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#miner_stopautodag
|
40
|
+
def miner_stopAutoDAG()
|
41
|
+
response = do_request("miner_stopAutoDAG")
|
42
|
+
response["result"]
|
43
|
+
end
|
44
|
+
end
|
data/lib/net_calls.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Web3::NetCalls
|
2
|
+
|
3
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#net_version
|
4
|
+
def net_version()
|
5
|
+
response = do_request("net_version")
|
6
|
+
response["result"]
|
7
|
+
end
|
8
|
+
|
9
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#net_peercount
|
10
|
+
def net_peerCount()
|
11
|
+
response = do_request("net_peerCount")
|
12
|
+
to_decimal response["result"]
|
13
|
+
end
|
14
|
+
|
15
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#net_listening
|
16
|
+
def net_listening()
|
17
|
+
response = do_request("net_listening")
|
18
|
+
response["result"]
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Web3::PersonalCalls
|
2
|
+
|
3
|
+
# See https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_listaccounts
|
4
|
+
def personal_listAccounts()
|
5
|
+
response = do_request("personal_listAccounts")
|
6
|
+
response["result"]
|
7
|
+
end
|
8
|
+
|
9
|
+
# See https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_importrawkey
|
10
|
+
def personal_importRawKey(key, passphrase)
|
11
|
+
response = do_request("personal_importRawKey",[key, passphrase])
|
12
|
+
response["result"]
|
13
|
+
end
|
14
|
+
|
15
|
+
# See https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_newaccount
|
16
|
+
def personal_newAccount(password)
|
17
|
+
response = do_request("personal_newAccount",[password])
|
18
|
+
response["result"]
|
19
|
+
end
|
20
|
+
|
21
|
+
# See https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_signandsendtransaction
|
22
|
+
def personal_signAndSendTransaction(transaction, passphrase)
|
23
|
+
response = do_request("personal_signAndSendTransaction",[transaction, passphrase])
|
24
|
+
response["result"]
|
25
|
+
end
|
26
|
+
|
27
|
+
# See https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_lockaccount
|
28
|
+
def personal_lockAccount(account)
|
29
|
+
response = do_request("personal_lockAccount",[account])
|
30
|
+
response["result"]
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# Be careful with this method. Do not leave an account unlocked, as that creates
|
35
|
+
# an opportunity for an attacker to make transactions from that account. In general
|
36
|
+
# personal_signAndSendTransaction is a better option than unlock -> send -> lock
|
37
|
+
# See https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_unlockaccount
|
38
|
+
def personal_unlockAccount(account, passphrase, duration)
|
39
|
+
response = do_request("personal_unlockAccount",[account, passphrase, duration])
|
40
|
+
response["result"]
|
41
|
+
end
|
42
|
+
|
43
|
+
# See https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
|
44
|
+
def personal_sign(message, account, password)
|
45
|
+
response = do_request("personal_sign",[message, account, password])
|
46
|
+
response["result"]
|
47
|
+
end
|
48
|
+
|
49
|
+
# See https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecrecover
|
50
|
+
def personal_ecRecover(message, signature)
|
51
|
+
response = do_request("personal_ecRecover",[message, signature])
|
52
|
+
response["result"]
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/lib/shh_calls.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Web3::ShhCalls
|
2
|
+
|
3
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_version
|
4
|
+
def shh_version()
|
5
|
+
response = do_request("shh_version")
|
6
|
+
response["result"]
|
7
|
+
end
|
8
|
+
|
9
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_post
|
10
|
+
def shh_post(post_object)
|
11
|
+
response = do_request("shh_post",[post_object])
|
12
|
+
response["result"]
|
13
|
+
end
|
14
|
+
|
15
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_newidentity
|
16
|
+
def shh_newIdentity()
|
17
|
+
response = do_request("shh_newIdentity")
|
18
|
+
response["result"]
|
19
|
+
end
|
20
|
+
|
21
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_hasidentity
|
22
|
+
def shh_hasIdentity(address)
|
23
|
+
response = do_request("shh_hasIdentity",[address])
|
24
|
+
response["result"]
|
25
|
+
end
|
26
|
+
|
27
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_newgroup
|
28
|
+
def shh_newGroup()
|
29
|
+
response = do_request("shh_newGroup")
|
30
|
+
response["result"]
|
31
|
+
end
|
32
|
+
|
33
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_addtogroup
|
34
|
+
def shh_addToGroup(address)
|
35
|
+
response = do_request("shh_addToGroup",[address])
|
36
|
+
response["result"]
|
37
|
+
end
|
38
|
+
|
39
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_newfilter
|
40
|
+
def shh_newFilter(filter_object)
|
41
|
+
response = do_request("shh_newFilter",[filter_object])
|
42
|
+
to_decimal response["result"]
|
43
|
+
end
|
44
|
+
|
45
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_uninstallfilter
|
46
|
+
def shh_uninstallFilter(id)
|
47
|
+
response = do_request("shh_uninstallFilter",[id])
|
48
|
+
response["result"]
|
49
|
+
end
|
50
|
+
|
51
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_getfilterchanges
|
52
|
+
def shh_getFilterChanges(id)
|
53
|
+
response = do_request("shh_getFilterChanges",[id])
|
54
|
+
response["result"]
|
55
|
+
end
|
56
|
+
|
57
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_getmessages
|
58
|
+
def shh_getMessages(id)
|
59
|
+
response = do_request("shh_getMessages",[id])
|
60
|
+
response["result"]
|
61
|
+
end
|
62
|
+
end
|
data/lib/txpool_calls.rb
ADDED
data/lib/web3.rb
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
# A client to Ethereum JSON-RPC https://github.com/ethereum/wiki/wiki/JSON-RPC
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
class Web3
|
7
|
+
attr_accessor :address, :endpoint, :id, :debug
|
8
|
+
|
9
|
+
@@jsonrpc = "2.0"
|
10
|
+
@@debug = ENV["ETH_DEBUG"] || false
|
11
|
+
|
12
|
+
# the default endpoint is http://localhost:8545 and default client id is 999
|
13
|
+
# these can be set as envioronment variables - ETH_ENDPOINT and ETH_DEFAULT_CLIENT_ID
|
14
|
+
def initialize( endpoint = ENV["ETH_ENDPOINT"] || "http://localhost:8545",
|
15
|
+
id = ENV["ETH_DEFAULT_CLIENT_ID"] || 999)
|
16
|
+
@endpoint = endpoint
|
17
|
+
@id = id
|
18
|
+
end
|
19
|
+
|
20
|
+
# this is the method responsible for communicating with the endpoint
|
21
|
+
# it gets called by all the action-specific methods
|
22
|
+
def do_request(method, params = [], id = @id)
|
23
|
+
request_json = { :jsonrpc => @@jsonrpc,
|
24
|
+
:method => method,
|
25
|
+
:params => params,
|
26
|
+
:id => @id
|
27
|
+
}.to_json
|
28
|
+
|
29
|
+
if @@debug
|
30
|
+
puts "Request to " + @endpoint + ": " + request_json + " ...."
|
31
|
+
end
|
32
|
+
|
33
|
+
response = HTTParty.post(@endpoint,
|
34
|
+
:body => request_json,
|
35
|
+
:headers => { 'Content-Type' => 'application/json' } )
|
36
|
+
|
37
|
+
if @@debug
|
38
|
+
puts "Response: " + response.to_s()
|
39
|
+
end
|
40
|
+
|
41
|
+
if response.bad_gateway?
|
42
|
+
raise "Unable to connect to JSON-RPC endpont" + @endpoint
|
43
|
+
end
|
44
|
+
|
45
|
+
if !response.success?
|
46
|
+
raise "JSON-RPC endpoint " + @endpoint + " returned http code " + response.code.to_s()
|
47
|
+
end
|
48
|
+
|
49
|
+
if response["error"]
|
50
|
+
code = response["error"]["code"]
|
51
|
+
message = response["error"]["message"]
|
52
|
+
raise "In response to " + method + " request, JSON-RPC endpoint returned error #" + code.to_s() + ": " + message
|
53
|
+
end
|
54
|
+
response
|
55
|
+
end
|
56
|
+
|
57
|
+
# JSON RPC FUNCTION CALLS INCLUDED HERE
|
58
|
+
# require_relative "generated_web3_methods.rb"
|
59
|
+
# include GeneratedWeb3Methods
|
60
|
+
|
61
|
+
require_relative "web3_calls.rb"
|
62
|
+
include Web3::Web3Calls
|
63
|
+
|
64
|
+
require_relative "net_calls.rb"
|
65
|
+
include Web3::NetCalls
|
66
|
+
|
67
|
+
require_relative "eth_calls.rb"
|
68
|
+
include Web3::EthCalls
|
69
|
+
|
70
|
+
require_relative "shh_calls.rb"
|
71
|
+
include Web3::ShhCalls
|
72
|
+
|
73
|
+
require_relative "personal_calls.rb"
|
74
|
+
include Web3::PersonalCalls
|
75
|
+
|
76
|
+
require_relative "txpool_calls.rb"
|
77
|
+
include Web3::TxpoolCalls
|
78
|
+
|
79
|
+
require_relative "miner_calls.rb"
|
80
|
+
include Web3::MinerCalls
|
81
|
+
|
82
|
+
#Utility methods
|
83
|
+
# Converts a hex string or int to a decimal integer
|
84
|
+
def to_decimal(hex)
|
85
|
+
if hex == nil
|
86
|
+
return nil
|
87
|
+
end
|
88
|
+
if hex.is_a?(Integer)
|
89
|
+
return hex
|
90
|
+
end
|
91
|
+
hex.to_i(16)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Converts a decimal integer to a hex string
|
95
|
+
def to_hex(decimal)
|
96
|
+
if decimal == nil
|
97
|
+
return nil
|
98
|
+
end
|
99
|
+
if decimal.is_a?(String)
|
100
|
+
return decimal
|
101
|
+
end
|
102
|
+
decimal.to_s(16) #this will throw an error if a non-integer is used
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
# Converts a decimal integer to a hex string that starts with a 0x marker
|
107
|
+
def to_0x(decimal)
|
108
|
+
"0x" + to_hex(decimal)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Converts wei to ether
|
112
|
+
def wei_to_ether(wei)
|
113
|
+
1.0 * wei / 10**18
|
114
|
+
end
|
115
|
+
|
116
|
+
# Converts either to wei
|
117
|
+
def ether_to_wei(ether)
|
118
|
+
(ether * 10**18).round()
|
119
|
+
end
|
120
|
+
|
121
|
+
# Converts either to wei a hex-formatted string, including the 0x indicator
|
122
|
+
def ether_to_0xwei(ether)
|
123
|
+
to_0x(ether_to_wei(ether))
|
124
|
+
end
|
125
|
+
|
126
|
+
# Convenience function to simply send ether from one account to another, using
|
127
|
+
# the default gas settings.
|
128
|
+
# This requires the personal api to be active. See https://github.com/ethereum/go-ethereum/wiki/Management-APIs
|
129
|
+
def sendEther(from_address, to_address, ether, password)
|
130
|
+
trans = {}
|
131
|
+
trans["from"] = from_address
|
132
|
+
trans["to"] = to_address
|
133
|
+
trans["value"] = ether_to_0xwei(ether)
|
134
|
+
# if gas != nil
|
135
|
+
# trans["gas"] = to_hex(gas) #should this to_hex or to_0x?
|
136
|
+
# end
|
137
|
+
# if gasPrice != nil
|
138
|
+
# trans["gasPrice"] = to_hex(gasPrice)
|
139
|
+
# end
|
140
|
+
personal_signAndSendTransaction(trans, password)
|
141
|
+
end
|
142
|
+
|
143
|
+
def createContract(from_address, bin_file, password)
|
144
|
+
trans = {}
|
145
|
+
trans["from"] = from_address
|
146
|
+
trans["data"] = File.read(bin_file)
|
147
|
+
gas = eth_estimateGas[trans]
|
148
|
+
trans["gas"] = ether_to_0xwei(ether)
|
149
|
+
personal_signAndSendTransaction(trans, password)
|
150
|
+
end
|
151
|
+
|
152
|
+
def getContractAddress(tx_number)
|
153
|
+
receipt = eth_getTransactionReceipt tx_number
|
154
|
+
receipt["contract"]
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
w3 = Web3. new
|
162
|
+
#w3.address =
|
163
|
+
#puts w3. web3_clientVersion
|
164
|
+
#puts w3. net_version
|
165
|
+
#puts w3. eth_protocolVersion
|
166
|
+
#puts "ds"
|
167
|
+
#puts w3. eth_coinbase #testme
|
168
|
+
#puts w3. eth_getBlockTransactionCountByNumber 3267552
|
169
|
+
# w3. eth_getBlockTransactionCountByHash '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238'
|
170
|
+
|
171
|
+
#puts w3. eth_blockNumber
|
172
|
+
#puts w3. eth_mining
|
173
|
+
#puts w3. eth_getTransactionCount
|
174
|
+
#puts w3. eth_getBalance
|
175
|
+
#puts w3. eth_accounts
|
176
|
+
#puts w3. eth_gasPrice
|
177
|
+
#puts do_request(@method, @params)
|
data/lib/web3_calls.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Web3::Web3Calls
|
2
|
+
|
3
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_clientversion
|
4
|
+
def web3_clientVersion()
|
5
|
+
response = do_request("web3_clientVersion")
|
6
|
+
response["result"]
|
7
|
+
end
|
8
|
+
|
9
|
+
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_sha3
|
10
|
+
def web3_sha3(data)
|
11
|
+
response = do_request("web3_sha3",[data])
|
12
|
+
response["result"]
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: web3_lib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Spike Williams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hanna-nouveau
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.14'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
description: A client library for connecting to an Ethereum Web3 JSON RPC service
|
56
|
+
email: spikewilliams@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/eth_calls.rb
|
62
|
+
- lib/miner_calls.rb
|
63
|
+
- lib/net_calls.rb
|
64
|
+
- lib/personal_calls.rb
|
65
|
+
- lib/shh_calls.rb
|
66
|
+
- lib/txpool_calls.rb
|
67
|
+
- lib/web3.rb
|
68
|
+
- lib/web3_calls.rb
|
69
|
+
homepage: https://github.com/InfraexDev/vtada-ethereum/
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.4.5.3
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: A client library for connecting to an Ethereum Web3 JSON RPC service
|
93
|
+
test_files: []
|