web3 0.3.0 → 0.4.0
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/lib/generated_web3_methods.rb +0 -385
- data/lib/web3.rb +42 -4
- 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: 170e81fe01c157aa99753de652b20b05963b8c23
|
4
|
+
data.tar.gz: 534d468da62684106ec0fa5d3ed9e929237e8494
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 624a8a9d52fc81f9055eb770dfbc91ff3bdd7d14a832c266a2f3e928622c98c67d31d467ff354d4cb4a8c8b6a4c38f0867d5daa982bc29996f36536cddbc472d
|
7
|
+
data.tar.gz: d0fd4cb84025506b00696b73d62e1ddc8bb394a800b65705496c1b828aebb5300d8b4d9487601f9894174e51923a8a763b8d3117ea004695769dd8a358fb0317
|
@@ -1,389 +1,4 @@
|
|
1
1
|
module GeneratedWeb3Methods
|
2
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
3
|
|
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
|
-
|
15
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#net_version
|
16
|
-
def net_version()
|
17
|
-
response = do_request("net_version")
|
18
|
-
response["result"]
|
19
|
-
end
|
20
|
-
|
21
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#net_peercount
|
22
|
-
def net_peerCount()
|
23
|
-
response = do_request("net_peerCount")
|
24
|
-
to_decimal response["result"]
|
25
|
-
end
|
26
|
-
|
27
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#net_listening
|
28
|
-
def net_listening()
|
29
|
-
response = do_request("net_listening")
|
30
|
-
response["result"]
|
31
|
-
end
|
32
|
-
|
33
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_protocolversion
|
34
|
-
def eth_protocolVersion()
|
35
|
-
raise NotImplementedError.new "JSON-RPC call to eth_protocolVersion is not currently supported"
|
36
|
-
end
|
37
|
-
|
38
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_syncing
|
39
|
-
def eth_syncing()
|
40
|
-
response = do_request("eth_syncing")
|
41
|
-
response["result"]
|
42
|
-
end
|
43
|
-
|
44
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_coinbase
|
45
|
-
def eth_coinbase()
|
46
|
-
response = do_request("eth_coinbase")
|
47
|
-
response["result"]
|
48
|
-
end
|
49
|
-
|
50
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_mining
|
51
|
-
def eth_mining()
|
52
|
-
response = do_request("eth_mining")
|
53
|
-
response["result"]
|
54
|
-
end
|
55
|
-
|
56
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_hashrate
|
57
|
-
def eth_hashrate()
|
58
|
-
response = do_request("eth_hashrate")
|
59
|
-
to_decimal response["result"]
|
60
|
-
end
|
61
|
-
|
62
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gasprice
|
63
|
-
def eth_gasPrice()
|
64
|
-
response = do_request("eth_gasPrice")
|
65
|
-
to_decimal response["result"]
|
66
|
-
end
|
67
|
-
|
68
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_accounts
|
69
|
-
def eth_accounts()
|
70
|
-
response = do_request("eth_accounts")
|
71
|
-
response["result"]
|
72
|
-
end
|
73
|
-
|
74
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_blocknumber
|
75
|
-
def eth_blockNumber()
|
76
|
-
response = do_request("eth_blockNumber")
|
77
|
-
to_decimal response["result"]
|
78
|
-
end
|
79
|
-
|
80
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getbalance
|
81
|
-
def eth_getBalance(address, block = "latest")
|
82
|
-
response = do_request("eth_getBalance",[address, block])
|
83
|
-
to_decimal response["result"]
|
84
|
-
end
|
85
|
-
|
86
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getstorageat
|
87
|
-
def eth_getStorageAt(storage_address, position, block = "latest")
|
88
|
-
response = do_request("eth_getStorageAt",[storage_address, to_hex(position), block])
|
89
|
-
response["result"]
|
90
|
-
end
|
91
|
-
|
92
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactioncount
|
93
|
-
def eth_getTransactionCount(address, block = "latest")
|
94
|
-
response = do_request("eth_getTransactionCount",[address, block])
|
95
|
-
to_decimal response["result"]
|
96
|
-
end
|
97
|
-
|
98
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblocktransactioncountbyhash
|
99
|
-
def eth_getBlockTransactionCountByHash(data)
|
100
|
-
response = do_request("eth_getBlockTransactionCountByHash",[data])
|
101
|
-
to_decimal response["result"]
|
102
|
-
end
|
103
|
-
|
104
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblocktransactioncountbynumber
|
105
|
-
def eth_getBlockTransactionCountByNumber(block = "latest")
|
106
|
-
response = do_request("eth_getBlockTransactionCountByNumber",[block])
|
107
|
-
to_decimal response["result"]
|
108
|
-
end
|
109
|
-
|
110
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclecountbyblockhash
|
111
|
-
def eth_getUncleCountByBlockHash(data)
|
112
|
-
response = do_request("eth_getUncleCountByBlockHash",[data])
|
113
|
-
to_decimal response["result"]
|
114
|
-
end
|
115
|
-
|
116
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclecountbyblocknumber
|
117
|
-
def eth_getUncleCountByBlockNumber(data)
|
118
|
-
response = do_request("eth_getUncleCountByBlockNumber",[data])
|
119
|
-
to_decimal response["result"]
|
120
|
-
end
|
121
|
-
|
122
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcode
|
123
|
-
def eth_getCode(address, block = "latest")
|
124
|
-
response = do_request("eth_getCode",[address, block])
|
125
|
-
response["result"]
|
126
|
-
end
|
127
|
-
|
128
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
|
129
|
-
def eth_sign(address, data)
|
130
|
-
response = do_request("eth_sign",[address, data])
|
131
|
-
response["result"]
|
132
|
-
end
|
133
|
-
|
134
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendtransaction
|
135
|
-
def eth_sendTransaction(trans_object)
|
136
|
-
response = do_request("eth_sendTransaction",[trans_object])
|
137
|
-
response["result"]
|
138
|
-
end
|
139
|
-
|
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)
|
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,block)
|
154
|
-
response = do_request("eth_estimateGas",[trans_object, block])
|
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
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcompilers
|
207
|
-
def eth_getCompilers()
|
208
|
-
response = do_request("eth_getCompilers")
|
209
|
-
response["result"]
|
210
|
-
end
|
211
|
-
|
212
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compilelll
|
213
|
-
def eth_compileLLL(code)
|
214
|
-
response = do_request("eth_compileLLL",[code])
|
215
|
-
response["result"]
|
216
|
-
end
|
217
|
-
|
218
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compilesolidity
|
219
|
-
def eth_compileSolidity(code)
|
220
|
-
response = do_request("eth_compileSolidity",[code])
|
221
|
-
response["result"]
|
222
|
-
end
|
223
|
-
|
224
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compileserpent
|
225
|
-
def eth_compileSerpent(code)
|
226
|
-
response = do_request("eth_compileSerpent",[code])
|
227
|
-
response["result"]
|
228
|
-
end
|
229
|
-
|
230
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter
|
231
|
-
def eth_newFilter(fromBlock, toBlock, address, topics)
|
232
|
-
response = do_request("$CODE",[fromBlock, toBlock, address, topics])
|
233
|
-
to_decimal response["result"]
|
234
|
-
end
|
235
|
-
|
236
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newblockfilter
|
237
|
-
def eth_newBlockFilter()
|
238
|
-
response = do_request("eth_newBlockFilter")
|
239
|
-
to_decimal response["result"]
|
240
|
-
end
|
241
|
-
|
242
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newpendingtransactionfilter
|
243
|
-
def eth_newPendingTransactionFilter()
|
244
|
-
response = do_request("eth_newPendingTransactionFilter")
|
245
|
-
to_decimal response["result"]
|
246
|
-
end
|
247
|
-
|
248
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_uninstallfilter
|
249
|
-
def eth_uninstallFilter(id)
|
250
|
-
response = do_request("eth_uninstallFilter",[id])
|
251
|
-
response["result"]
|
252
|
-
end
|
253
|
-
|
254
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterchanges
|
255
|
-
def eth_getFilterChanges(id)
|
256
|
-
response = do_request("eth_getFilterChanges",[id])
|
257
|
-
response["result"]
|
258
|
-
end
|
259
|
-
|
260
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterlogs
|
261
|
-
def eth_getFilterLogs(id)
|
262
|
-
response = do_request("eth_getFilterLogs",[id])
|
263
|
-
response["result"]
|
264
|
-
end
|
265
|
-
|
266
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs
|
267
|
-
def eth_getLogs(filter_obj)
|
268
|
-
response = do_request("eth_getLogs",[filter_obj])
|
269
|
-
response["result"]
|
270
|
-
end
|
271
|
-
|
272
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getwork
|
273
|
-
def eth_getWork()
|
274
|
-
response = do_request("eth_getWork")
|
275
|
-
response["result"]
|
276
|
-
end
|
277
|
-
|
278
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_submitwork
|
279
|
-
def eth_submitWork(nonce, powHash, mixDigest)
|
280
|
-
response = do_request("eth_submitWork",[nonce, powHash, mixDigest])
|
281
|
-
response["result"]
|
282
|
-
end
|
283
|
-
|
284
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_submithashrate
|
285
|
-
def eth_submitHashrate(hashrate, id)
|
286
|
-
response = do_request("eth_submitHashrate",[hashrate, id])
|
287
|
-
response["result"]
|
288
|
-
end
|
289
|
-
|
290
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_version
|
291
|
-
def shh_version()
|
292
|
-
response = do_request("shh_version")
|
293
|
-
response["result"]
|
294
|
-
end
|
295
|
-
|
296
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_post
|
297
|
-
def shh_post(post_object)
|
298
|
-
response = do_request("shh_post",[post_object])
|
299
|
-
response["result"]
|
300
|
-
end
|
301
|
-
|
302
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_newidentity
|
303
|
-
def shh_newIdentity()
|
304
|
-
response = do_request("shh_newIdentity")
|
305
|
-
response["result"]
|
306
|
-
end
|
307
|
-
|
308
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_hasidentity
|
309
|
-
def shh_hasIdentity(address)
|
310
|
-
response = do_request("shh_hasIdentity",[address])
|
311
|
-
response["result"]
|
312
|
-
end
|
313
|
-
|
314
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_newgroup
|
315
|
-
def shh_newGroup()
|
316
|
-
response = do_request("shh_newGroup")
|
317
|
-
response["result"]
|
318
|
-
end
|
319
|
-
|
320
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_addtogroup
|
321
|
-
def shh_addToGroup(address)
|
322
|
-
response = do_request("shh_addToGroup",[address])
|
323
|
-
response["result"]
|
324
|
-
end
|
325
|
-
|
326
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_newfilter
|
327
|
-
def shh_newFilter(filter_object)
|
328
|
-
response = do_request("shh_newFilter",[filter_object])
|
329
|
-
to_decimal response["result"]
|
330
|
-
end
|
331
|
-
|
332
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_uninstallfilter
|
333
|
-
def shh_uninstallFilter(id)
|
334
|
-
response = do_request("shh_uninstallFilter",[id])
|
335
|
-
response["result"]
|
336
|
-
end
|
337
|
-
|
338
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_getfilterchanges
|
339
|
-
def shh_getFilterChanges(id)
|
340
|
-
response = do_request("shh_getFilterChanges",[id])
|
341
|
-
response["result"]
|
342
|
-
end
|
343
|
-
|
344
|
-
# See https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_getmessages
|
345
|
-
def shh_getMessages(id)
|
346
|
-
response = do_request("shh_getMessages",[id])
|
347
|
-
response["result"]
|
348
|
-
end
|
349
|
-
|
350
|
-
# For web3 personal api - not activated by default in geth
|
351
|
-
def personal_listAccounts()
|
352
|
-
response = do_request("personal_listAccounts")
|
353
|
-
response["result"]
|
354
|
-
end
|
355
|
-
|
356
|
-
# For web3 personal api - not activated by default in geth
|
357
|
-
def personal_importRawKey(key, passphrase)
|
358
|
-
response = do_request("personal_importRawKey",[key, passphrase])
|
359
|
-
response["result"]
|
360
|
-
end
|
361
|
-
|
362
|
-
# For web3 personal api - not activated by default in geth
|
363
|
-
def personal_newAccount(password)
|
364
|
-
response = do_request("personal_newAccount",[password])
|
365
|
-
response["result"]
|
366
|
-
end
|
367
|
-
|
368
|
-
# For web3 personal api - not activated by default in geth
|
369
|
-
def personal_signAndSendTransaction(transaction, passphrase)
|
370
|
-
response = do_request("personal_signAndSendTransaction",[transaction, passphrase])
|
371
|
-
response["result"]
|
372
|
-
end
|
373
|
-
|
374
|
-
# For web3 personal api - not activated by default in geth
|
375
|
-
def personal_lockAccount(account)
|
376
|
-
response = do_request("personal_lockAccount",[account])
|
377
|
-
response["result"]
|
378
|
-
end
|
379
|
-
|
380
|
-
|
381
|
-
# For web3 personal api
|
382
|
-
# Be careful with this method. Do not leave an account unlocked, as that creates
|
383
|
-
# an opportunity for an attacker to make transactions from that account. In general
|
384
|
-
# personal_signAndSendTransaction is a better option than unlock -> send -> lock
|
385
|
-
def personal_unlockAccount(account, passphrase, duration)
|
386
|
-
response = do_request("personal_unlockAccount",[account, passphrase, duration])
|
387
|
-
response["result"]
|
388
|
-
end
|
389
4
|
end
|
data/lib/web3.rb
CHANGED
@@ -9,13 +9,17 @@ class Web3
|
|
9
9
|
@@jsonrpc = "2.0"
|
10
10
|
@@debug = ENV["ETH_DEBUG"] || false
|
11
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
|
12
14
|
def initialize( endpoint = ENV["ETH_ENDPOINT"] || "http://localhost:8545",
|
13
15
|
id = ENV["ETH_DEFAULT_CLIENT_ID"] || 999)
|
14
16
|
@endpoint = endpoint
|
15
17
|
@id = id
|
16
18
|
end
|
17
19
|
|
18
|
-
|
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)
|
19
23
|
request_json = { :jsonrpc => @@jsonrpc,
|
20
24
|
:method => method,
|
21
25
|
:params => params,
|
@@ -51,11 +55,31 @@ class Web3
|
|
51
55
|
end
|
52
56
|
|
53
57
|
# JSON RPC FUNCTION CALLS INCLUDED HERE
|
54
|
-
require_relative "generated_web3_methods.rb"
|
55
|
-
include GeneratedWeb3Methods
|
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
|
56
78
|
|
57
79
|
|
58
80
|
#Utility methods
|
81
|
+
|
82
|
+
# Converts a hex string or int to a decimal integer
|
59
83
|
def to_decimal(hex)
|
60
84
|
if hex == nil
|
61
85
|
return nil
|
@@ -66,6 +90,7 @@ class Web3
|
|
66
90
|
hex.to_i(16)
|
67
91
|
end
|
68
92
|
|
93
|
+
# Converts a decimal integer to a hex string
|
69
94
|
def to_hex(decimal)
|
70
95
|
if decimal == nil
|
71
96
|
return nil
|
@@ -73,21 +98,26 @@ class Web3
|
|
73
98
|
if decimal.is_a?(String)
|
74
99
|
return decimal
|
75
100
|
end
|
76
|
-
decimal.to_s(16)
|
101
|
+
decimal.to_s(16) #this will throw an error if a non-integer is used
|
77
102
|
end
|
78
103
|
|
104
|
+
|
105
|
+
# Converts a decimal integer to a hex string that starts with a 0x marker
|
79
106
|
def to_0x(decimal)
|
80
107
|
"0x" + to_hex(decimal)
|
81
108
|
end
|
82
109
|
|
110
|
+
# Converts wei to ether
|
83
111
|
def wei_to_ether(wei)
|
84
112
|
1.0 * wei / 10**18
|
85
113
|
end
|
86
114
|
|
115
|
+
# Converts either to wei
|
87
116
|
def ether_to_wei(ether)
|
88
117
|
(ether * 10**18).round()
|
89
118
|
end
|
90
119
|
|
120
|
+
# Converts either to wei a hex-formatted string, including the 0x indicator
|
91
121
|
def ether_to_0xwei(ether)
|
92
122
|
to_0x(ether_to_wei(ether))
|
93
123
|
end
|
@@ -109,6 +139,14 @@ class Web3
|
|
109
139
|
personal_signAndSendTransaction(trans, password)
|
110
140
|
end
|
111
141
|
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
112
150
|
end
|
113
151
|
|
114
152
|
w3 = Web3. new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spike Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hanna-nouveau
|