nanook 2.1.0 → 2.5.1
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 +5 -5
- data/CHANGELOG.md +79 -1
- data/README.md +47 -19
- data/lib/nanook.rb +5 -5
- data/lib/nanook/account.rb +176 -118
- data/lib/nanook/block.rb +62 -11
- data/lib/nanook/error.rb +1 -0
- data/lib/nanook/node.rb +261 -3
- data/lib/nanook/rpc.rb +23 -2
- data/lib/nanook/util.rb +21 -2
- data/lib/nanook/version.rb +1 -1
- data/lib/nanook/wallet.rb +228 -86
- data/lib/nanook/wallet_account.rb +47 -40
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d03d4611714f05048845e583058c3d99216e0d7bc4e82994556f7abd6bc94d4e
|
4
|
+
data.tar.gz: 404045d0de5f045400897c648e22267c0981ff9d498e9404f08ef77aaadfbfac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b5a0bf64ca64119b0e692b527677154a291c8080ade14c52624e41d59fb772c9e5f55c0f58bd8a460ea806fdcbbeebd0009f248547771f228f48a4829e2a014
|
7
|
+
data.tar.gz: d78534084ba296713af7e3384222319916d3e6e61977d044d8cd724a46b70469c7df7299ba6ed35118dc491aa9de8cb9766a9fb42ab6a16e4543a95e30d76793
|
data/CHANGELOG.md
CHANGED
@@ -4,9 +4,85 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## 2.5.1
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
|
11
|
+
- undefined method 'new' for `BigDecimal:Class` (thank you @MihaiVoinea)
|
12
|
+
|
13
|
+
## 2.5.0
|
14
|
+
|
15
|
+
### Added
|
16
|
+
|
17
|
+
- New `Nanook::Node#bootstrap_lazy` method.
|
18
|
+
- New `Nanook::Node#bootstrap_status` method.
|
19
|
+
- New `Nanook::Node#difficulty` method.
|
20
|
+
- New `Nanook::Node#uptime` method.
|
21
|
+
- New `Nanook::Wallet#lock` method.
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
|
25
|
+
- `Nanook::Node#chain` now takes optional `offset` argument.
|
26
|
+
- `Nanook::Node#successors` now takes optional `offset` argument.
|
27
|
+
- `Nanook::Node#successors` now aliased as `Nanook::Node#ancestors`
|
28
|
+
- Updated docs to use `nano_` prefixed addresses.
|
29
|
+
|
30
|
+
## 2.4.0
|
31
|
+
|
32
|
+
### Added
|
33
|
+
|
34
|
+
- New `Nanook::Node#confirmation_history` method.
|
35
|
+
- New `Nanook::Block#confirm` method.
|
36
|
+
- New `Nanook::Block#confirmed_recently?` method.
|
37
|
+
|
38
|
+
### Changed
|
39
|
+
|
40
|
+
- `Nanook::Block#generate_work` now can take optional `use_peers` argument.
|
41
|
+
|
42
|
+
## 2.3.0
|
43
|
+
|
44
|
+
### Added
|
45
|
+
|
46
|
+
- New `Nanook::Wallet#default_representative` method.
|
47
|
+
- New `Nanook::Wallet#change_default_representative` method.
|
48
|
+
- New `Nanook::Wallet#info` method.
|
49
|
+
|
50
|
+
## 2.2.0
|
51
|
+
|
52
|
+
### Added
|
53
|
+
|
54
|
+
- New `Nanook::Account#block_count` method returns number of blocks in ledger for an account.
|
55
|
+
- `Nanook::Node#block_count_type` is now an alias to the preferred `#block_count_by_type`
|
56
|
+
method.
|
57
|
+
- new `Nanook::Node#representatives_online` method.
|
58
|
+
- `Nanook::Node#synchronizing_blocks` aliased by `#unchecked`, for people familiar with
|
59
|
+
what the RPC calls it.
|
60
|
+
- `Nanook::Node#version` now an aliased by `#info`
|
61
|
+
method.
|
62
|
+
- `Nanook::WalletAccount#exists?` now aliased by `#open?`
|
63
|
+
|
64
|
+
### Removed
|
65
|
+
|
66
|
+
- `Nanook::WalletAccount#account_id` Removed, as there was already an `id` method that returned this.
|
67
|
+
- `Nanook::WalletAccount#wallet_id` Removed, as the `WalletAccount` object should be considered a kind of Account.
|
68
|
+
|
69
|
+
### Changed
|
70
|
+
|
71
|
+
- `Nanook::Account#delegators` now takes `unit` argument.
|
72
|
+
- `Nanook::Account#ledger` now takes `unit` and `modified_since` arguments.
|
73
|
+
- `Nanook::Node#representatives` now takes `unit` argument.
|
74
|
+
- `Nanook::Node#synced?` is deprecated with a `warn`. Nodes never seem to reach 100%
|
75
|
+
synchronized, so this method is useless.
|
76
|
+
- `Nanook::Rpc::DEFAULT_TIMEOUT` reduced from 500 to 60.
|
77
|
+
|
7
78
|
## 2.1.0
|
8
79
|
|
9
|
-
|
80
|
+
### Changed
|
81
|
+
|
82
|
+
- Payment methods no longer check that recipient account has an open block, as this prevents
|
83
|
+
funds being sent to accounts about to be opened.
|
84
|
+
- Payment methods now check the account id of the recipient is valid, raises ArgumentError if not.
|
85
|
+
- Payment methods now return a Nanook::Error if the RPC returns an error when trying to pay, instead of a String.
|
10
86
|
|
11
87
|
## 2.0.0
|
12
88
|
|
@@ -24,6 +100,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
24
100
|
- Added ruby version requirement >= 2.0 to gemspec.
|
25
101
|
|
26
102
|
### Changed
|
103
|
+
|
27
104
|
- `Nanook::Rpc#inspect` displays full hostname with scheme and port.
|
28
105
|
- `Nanook::Account#new` `account` param is now required.
|
29
106
|
- `Nanook::Account#info` now also returns the `id` of the account.
|
@@ -41,6 +118,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
41
118
|
- Changed documentation generating tool from rdoc to yard.
|
42
119
|
|
43
120
|
### Fixed
|
121
|
+
|
44
122
|
- Missing `Nanook#rpc` accessor.
|
45
123
|
- `Nanook::Block#publish` can return false when publish fails.
|
46
124
|
- `Nanook::Block#info` correctly handles `allow_unchecked: true` errors.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Nanook
|
2
2
|
|
3
|
-
This is a Ruby library for managing a [nano currency](https://nano.org/) node, including making and receiving payments, using the [nano RPC protocol](https://
|
3
|
+
This is a Ruby library for managing a [nano currency](https://nano.org/) node, including making and receiving payments, using the [nano RPC protocol](https://docs.nano.org/commands/rpc-protocol). Nano is a fee-less, fast, environmentally-friendly cryptocurrency. It's awesome. See [https://nano.org](https://nano.org/).
|
4
4
|
|
5
5
|
[](https://badge.fury.io/rb/nanook)
|
6
6
|
[](https://circleci.com/gh/lukes/nanook/tree/master)
|
@@ -11,7 +11,7 @@ This is a Ruby library for managing a [nano currency](https://nano.org/) node, i
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem 'nanook'
|
14
|
+
gem 'nanook'
|
15
15
|
```
|
16
16
|
|
17
17
|
And then execute:
|
@@ -76,7 +76,7 @@ wallet = Nanook.new.wallet(wallet_id)
|
|
76
76
|
wallet.pay(from: your_account_id, to: recipient_account_id, amount: 0.2, id: unique_id)
|
77
77
|
```
|
78
78
|
|
79
|
-
The `id` can be any string and needs to be unique per payment. It serves an important purpose; it allows you to make this call multiple times with the same `id` and be reassured that you will only ever send that nano payment once. From the [Nano RPC](https://
|
79
|
+
The `id` can be any string and needs to be unique per payment. It serves an important purpose; it allows you to make this call multiple times with the same `id` and be reassured that you will only ever send that nano payment once. From the [Nano RPC](https://docs.nano.org/commands/rpc-protocol/#send):
|
80
80
|
|
81
81
|
> You can (and should) specify a unique id for each spend to provide idempotency. That means that if you [make the payment call] two times with the same id, the second request won't send any additional Nano.
|
82
82
|
|
@@ -86,7 +86,7 @@ The unit of the `amount` is NANO (which is currently technically Mnano — s
|
|
86
86
|
account.pay(to: recipient_account_id, amount: 999, unit: :raw, id: unique_id)
|
87
87
|
```
|
88
88
|
|
89
|
-
Note, there may be a delay in receiving a response due to Proof of Work being done. From the [Nano RPC](https://
|
89
|
+
Note, there may be a delay in receiving a response due to Proof of Work being done. From the [Nano RPC](https://docs.nano.org/commands/rpc-protocol/#send):
|
90
90
|
|
91
91
|
> Proof of Work is precomputed for one transaction in the background. If it has been a while since your last transaction it will send instantly, the next one will need to wait for Proof of Work to be generated.
|
92
92
|
|
@@ -120,11 +120,11 @@ wallet.receive(block_id, into: account_id)
|
|
120
120
|
|
121
121
|
## All commands
|
122
122
|
|
123
|
-
Below is a quick reference list of commands. See the [full Nanook documentation](https://lukes.github.io/nanook/2.
|
123
|
+
Below is a quick reference list of commands. See the [full Nanook documentation](https://lukes.github.io/nanook/2.5.1/) for a searchable detailed description of every class and method, what the arguments mean, and example responses (Tip: the classes are listed under the "**Nanook** < Object" item in the sidebar).
|
124
124
|
|
125
125
|
### Wallets
|
126
126
|
|
127
|
-
See the [full documentation for Nanook::Wallet](https://lukes.github.io/nanook/2.
|
127
|
+
See the [full documentation for Nanook::Wallet](https://lukes.github.io/nanook/2.5.1/Nanook/Wallet.html) for a detailed description of each method and example responses.
|
128
128
|
|
129
129
|
#### Create wallet:
|
130
130
|
|
@@ -150,7 +150,7 @@ wallet.balance
|
|
150
150
|
wallet.balance(account_break_down: true)
|
151
151
|
wallet.balance(unit: :raw)
|
152
152
|
wallet.pay(from: your_account_id, to: recipient_account_id, amount: 2, id: unique_id)
|
153
|
-
wallet.pay(from: your_account_id, to: recipient_account_id, amount: 2,
|
153
|
+
wallet.pay(from: your_account_id, to: recipient_account_id, amount: 2, id: unique_id, unit: :raw)
|
154
154
|
wallet.pending
|
155
155
|
wallet.pending(limit: 1)
|
156
156
|
wallet.pending(detailed: true)
|
@@ -159,10 +159,16 @@ wallet.receive(into: account_id)
|
|
159
159
|
wallet.receive(pending_block_id, into: account_id)
|
160
160
|
|
161
161
|
wallet.account.create
|
162
|
+
wallet.account.create(5)
|
162
163
|
wallet.accounts
|
163
164
|
wallet.contains?(account_id)
|
164
165
|
|
166
|
+
wallet.default_representative
|
167
|
+
wallet.change_default_representative(new_representative)
|
168
|
+
wallet.info
|
169
|
+
wallet.info(unit: :raw)
|
165
170
|
wallet.export
|
171
|
+
wallet.lock
|
166
172
|
wallet.locked?
|
167
173
|
wallet.unlock(password)
|
168
174
|
wallet.change_password(password)
|
@@ -185,13 +191,15 @@ Nanook.new.wallet(wallet_id).account.create(5)
|
|
185
191
|
|
186
192
|
#### Working with a single account:
|
187
193
|
|
194
|
+
See the [full documentation for Nanook::WalletAccount](https://lukes.github.io/nanook/2.5.1/Nanook/WalletAccount.html) for a detailed description of each method and example responses.
|
195
|
+
|
188
196
|
```ruby
|
189
197
|
account = Nanook.new.wallet(wallet_id).account(account_id)
|
190
198
|
|
191
199
|
account.balance
|
192
200
|
account.balance(unit: :raw)
|
193
201
|
account.pay(to: recipient_account_id, amount: 2, id: unique_id)
|
194
|
-
account.pay(to: recipient_account_id, amount: 2,
|
202
|
+
account.pay(to: recipient_account_id, amount: 2, id: unique_id, unit: :raw)
|
195
203
|
account.pending
|
196
204
|
account.pending(limit: 1)
|
197
205
|
account.pending(detailed: true)
|
@@ -206,11 +214,14 @@ account.info(unit: :raw)
|
|
206
214
|
account.last_modified_at
|
207
215
|
account.ledger
|
208
216
|
account.ledger(limit: 10)
|
217
|
+
account.ledger(modified_since: Time.now)
|
218
|
+
account.ledger(unit: :raw)
|
209
219
|
account.history
|
210
220
|
account.history(limit: 1)
|
211
221
|
account.history(unit: :raw)
|
212
222
|
account.public_key
|
213
223
|
account.delegators
|
224
|
+
account.delegators(unit: :raw)
|
214
225
|
account.representative
|
215
226
|
account.change_representative(new_representative)
|
216
227
|
account.weight
|
@@ -220,7 +231,7 @@ account.destroy
|
|
220
231
|
|
221
232
|
#### Working with any account (not necessarily in your wallet):
|
222
233
|
|
223
|
-
See the [full documentation for Nanook::Account](https://lukes.github.io/nanook/2.
|
234
|
+
See the [full documentation for Nanook::Account](https://lukes.github.io/nanook/2.5.1/Nanook/Account.html) for a detailed description of each method and example responses.
|
224
235
|
|
225
236
|
```ruby
|
226
237
|
account = Nanook.new.account(account_id)
|
@@ -239,18 +250,21 @@ account.info(unit: :raw)
|
|
239
250
|
account.last_modified_at
|
240
251
|
account.ledger
|
241
252
|
account.ledger(limit: 10)
|
253
|
+
account.ledger(modified_since: Time.now)
|
254
|
+
account.ledger(unit: :raw)
|
242
255
|
account.history
|
243
256
|
account.history(limit: 1)
|
244
257
|
account.history(unit: :raw)
|
245
258
|
account.public_key
|
246
259
|
account.delegators
|
260
|
+
account.delegators(unit: :raw)
|
247
261
|
account.representative
|
248
262
|
account.weight
|
249
263
|
```
|
250
264
|
|
251
265
|
### Blocks
|
252
266
|
|
253
|
-
See the [full documentation for Nanook::Block](https://lukes.github.io/nanook/2.
|
267
|
+
See the [full documentation for Nanook::Block](https://lukes.github.io/nanook/2.5.1/Nanook/Block.html) for a detailed description of each method and example responses.
|
254
268
|
|
255
269
|
```ruby
|
256
270
|
block = Nanook.new.block(block_id)
|
@@ -260,6 +274,9 @@ block.info(allow_unchecked: true) # Verified blocks AND unchecked synchronizing
|
|
260
274
|
block.account
|
261
275
|
block.chain
|
262
276
|
block.chain(limit: 10)
|
277
|
+
block.chain(offset: 10)
|
278
|
+
block.confirm
|
279
|
+
block.confirmed_recently?
|
263
280
|
block.history
|
264
281
|
block.history(limit: 10)
|
265
282
|
block.republish
|
@@ -269,28 +286,39 @@ block.pending?
|
|
269
286
|
block.publish
|
270
287
|
block.successors
|
271
288
|
block.successors(limit: 10)
|
289
|
+
block.successors(offset: 10)
|
272
290
|
|
273
291
|
block.generate_work
|
292
|
+
block.generate_work(use_peers: true)
|
274
293
|
block.cancel_work
|
275
294
|
block.is_valid_work?(work_id)
|
276
295
|
```
|
277
296
|
|
278
297
|
### Managing your nano node
|
279
298
|
|
299
|
+
See the [full documentation for Nanook::Node](https://lukes.github.io/nanook/2.5.1/Nanook/Node.html) for a detailed description of each method and example responses.
|
300
|
+
|
280
301
|
```ruby
|
281
302
|
node = Nanook.new.node
|
282
303
|
|
283
304
|
node.account_count
|
284
305
|
node.block_count
|
285
|
-
node.
|
286
|
-
node.bootstrap_any
|
306
|
+
node.block_count_by_type
|
287
307
|
node.bootstrap(address: "::ffff:138.201.94.249", port: 7075)
|
308
|
+
node.bootstrap_any
|
309
|
+
node.bootstrap_lazy(block_id)
|
310
|
+
node.bootstrap_lazy(block_id, force: true)
|
311
|
+
node.bootstrap_status
|
312
|
+
node.confirmation_history
|
313
|
+
node.difficulty
|
314
|
+
node.difficulty(include_trend: true)
|
288
315
|
node.peers
|
289
316
|
node.representatives
|
317
|
+
node.representatives(unit: :raw)
|
318
|
+
node.representatives_online
|
290
319
|
node.synchronizing_blocks
|
291
320
|
node.synchronizing_blocks(limit: 1)
|
292
321
|
node.sync_progress
|
293
|
-
node.synced?
|
294
322
|
node.version
|
295
323
|
|
296
324
|
node.stop
|
@@ -325,12 +353,12 @@ key.info
|
|
325
353
|
|
326
354
|
## Nanook Metal
|
327
355
|
|
328
|
-
You can do any call listed in the [Nano RPC](https://
|
356
|
+
You can do any call listed in the [Nano RPC](https://docs.nano.org/commands/rpc-protocol) directly through the `rpc` method. The first argument should match the `action` of the RPC call, and then all remaining parameters are passed in as arguments.
|
329
357
|
|
330
|
-
E.g., the [accounts_create command](https://
|
358
|
+
E.g., the [accounts_create command](https://docs.nano.org/commands/rpc-protocol/#accounts_create) can be called like this:
|
331
359
|
|
332
360
|
```ruby
|
333
|
-
|
361
|
+
Nanook.new.rpc.call(:accounts_create, wallet: wallet_id, count: 2)
|
334
362
|
```
|
335
363
|
|
336
364
|
## Contributing
|
@@ -351,11 +379,11 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
351
379
|
|
352
380
|
## Buy me a nano coffee
|
353
381
|
|
354
|
-
This library is totally free to use, but feel free to send some nano [my way](https://www.nanode.co/account/
|
382
|
+
This library is totally free to use, but feel free to send some nano [my way](https://www.nanode.co/account/nano_3c3ek3k8135f6e8qtfy8eruk9q3yzmpebes7btzncccdest8ymzhjmnr196j) if you'd like to!
|
355
383
|
|
356
|
-
|
384
|
+
nano_3c3ek3k8135f6e8qtfy8eruk9q3yzmpebes7btzncccdest8ymzhjmnr196j
|
357
385
|
|
358
|
-

|
359
387
|
|
360
388
|
|
361
389
|
|
data/lib/nanook.rb
CHANGED
@@ -2,7 +2,7 @@ require 'net/http'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'forwardable'
|
4
4
|
|
5
|
-
Dir[File.dirname(__FILE__) + '/nanook/*.rb'].each {|file| require file }
|
5
|
+
Dir[File.dirname(__FILE__) + '/nanook/*.rb'].each { |file| require file }
|
6
6
|
|
7
7
|
# ==== Initializing
|
8
8
|
#
|
@@ -42,12 +42,12 @@ class Nanook
|
|
42
42
|
# Returns a new instance of {Nanook}.
|
43
43
|
#
|
44
44
|
# ==== Examples:
|
45
|
-
# Connecting to http://localhost:7076 with the default timeout of
|
45
|
+
# Connecting to http://localhost:7076 with the default timeout of 10s:
|
46
46
|
# Nanook.new
|
47
47
|
# Setting a custom timeout:
|
48
|
-
# Nanook.new(timeout:
|
48
|
+
# Nanook.new(timeout: 10)
|
49
49
|
# Connecting to a custom RPC host and setting a timeout:
|
50
|
-
# Nanook.new("http://ip6-localhost.com:7076", timeout:
|
50
|
+
# Nanook.new("http://ip6-localhost.com:7076", timeout: 10)
|
51
51
|
#
|
52
52
|
# @param uri [String] default is {Nanook::Rpc::DEFAULT_URI}. The RPC host to connect to
|
53
53
|
# @param timeout [Integer] default is {Nanook::Rpc::DEFAULT_TIMEOUT}. Connection timeout in number of seconds
|
@@ -58,7 +58,7 @@ class Nanook
|
|
58
58
|
# Returns a new instance of {Nanook::Account}.
|
59
59
|
#
|
60
60
|
# ==== Example:
|
61
|
-
# account = Nanook.new.account("
|
61
|
+
# account = Nanook.new.account("nano_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpi00000000")
|
62
62
|
#
|
63
63
|
# @param account [String] the id of the account you want to work with
|
64
64
|
# @return [Nanook::Account]
|
data/lib/nanook/account.rb
CHANGED
@@ -8,12 +8,12 @@ class Nanook
|
|
8
8
|
# Initialize this class through the convenient {Nanook#account} method:
|
9
9
|
#
|
10
10
|
# nanook = Nanook.new
|
11
|
-
# account = nanook.account("
|
11
|
+
# account = nanook.account("nano_...")
|
12
12
|
#
|
13
13
|
# Or compose the longhand way like this:
|
14
14
|
#
|
15
15
|
# rpc_conn = Nanook::Rpc.new
|
16
|
-
# account = Nanook::Account.new(rpc_conn, "
|
16
|
+
# account = Nanook::Account.new(rpc_conn, "nano_...")
|
17
17
|
class Account
|
18
18
|
|
19
19
|
def initialize(rpc, account)
|
@@ -21,23 +21,43 @@ class Nanook
|
|
21
21
|
@account = account
|
22
22
|
end
|
23
23
|
|
24
|
-
#
|
25
|
-
#
|
24
|
+
# Information about this accounts that have set this account as their representative.
|
25
|
+
#
|
26
|
+
# === Example:
|
27
|
+
#
|
28
|
+
# account.delegators
|
29
|
+
#
|
30
|
+
# Example response:
|
31
|
+
#
|
26
32
|
# {
|
27
|
-
# :
|
28
|
-
# :
|
33
|
+
# :nano_13bqhi1cdqq8yb9szneoc38qk899d58i5rcrgdk5mkdm86hekpoez3zxw5sd=>500000000000000000000000000000000000,
|
34
|
+
# :nano_17k6ug685154an8gri9whhe5kb5z1mf5w6y39gokc1657sh95fegm8ht1zpn=>961647970820730000000000000000000000
|
29
35
|
# }
|
30
36
|
#
|
31
|
-
# @
|
32
|
-
|
33
|
-
|
37
|
+
# @param unit (see #balance)
|
38
|
+
# @return [Hash{Symbol=>Integer}] account ids which delegate to this account, and their account balance
|
39
|
+
def delegators(unit: Nanook.default_unit)
|
40
|
+
unless Nanook::UNITS.include?(unit)
|
41
|
+
raise ArgumentError.new("Unsupported unit: #{unit}")
|
42
|
+
end
|
43
|
+
|
44
|
+
response = rpc(:delegators)[:delegators]
|
45
|
+
|
46
|
+
return response if unit == :raw
|
47
|
+
|
48
|
+
r = response.map do |account_id, balance|
|
49
|
+
balance = Nanook::Util.raw_to_NANO(balance)
|
50
|
+
|
51
|
+
[account_id, balance]
|
52
|
+
end
|
53
|
+
|
54
|
+
Hash[r].to_symbolized_hash
|
34
55
|
end
|
35
56
|
|
36
|
-
# Returns
|
57
|
+
# Returns true if the account has an <i>open</i> block.
|
37
58
|
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# an account receives a payment for the first time.
|
59
|
+
# An open block gets published when an account receives a payment
|
60
|
+
# for the first time.
|
41
61
|
#
|
42
62
|
# The reliability of this check depends on the node host having
|
43
63
|
# synchronized itself with most of the blocks on the nano network,
|
@@ -45,40 +65,33 @@ class Nanook
|
|
45
65
|
# You can check if a node's synchronization is particular low
|
46
66
|
# using {Nanook::Node#sync_progress}.
|
47
67
|
#
|
48
|
-
#
|
68
|
+
# ==== Example:
|
69
|
+
#
|
70
|
+
# account.exists? # => true
|
71
|
+
# # or
|
72
|
+
# account.open? # => true
|
73
|
+
#
|
74
|
+
# @return [Boolean] Indicates if this account has an open block
|
49
75
|
def exists?
|
50
76
|
response = rpc(:account_info)
|
51
77
|
!response.empty? && !response[:open_block].nil?
|
52
78
|
end
|
79
|
+
alias_method :open?, :exists?
|
53
80
|
|
54
|
-
#
|
81
|
+
# An account's history of send and receive payments.
|
55
82
|
#
|
56
83
|
# ==== Example:
|
57
84
|
#
|
58
85
|
# account.history
|
59
|
-
# account.history(limit: 1)
|
60
86
|
#
|
61
|
-
#
|
62
|
-
# [
|
63
|
-
# {
|
64
|
-
# :type=>"send",
|
65
|
-
# :account=>"xrb_1kdc5u48j3hr5r7eof9iao47szqh81ndqgq5e5hrsn1g9a3sa4hkkcotn3uq",
|
66
|
-
# :amount=>2,
|
67
|
-
# :hash=>"2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570"
|
68
|
-
# }
|
69
|
-
# ]
|
70
|
-
# ==== Example:
|
71
|
-
#
|
72
|
-
# account.history
|
73
|
-
# account.history(unit: :raw)
|
87
|
+
# Example response:
|
74
88
|
#
|
75
|
-
# ==== Example response:
|
76
89
|
# [
|
77
90
|
# {
|
78
|
-
# :
|
79
|
-
# :
|
80
|
-
# :
|
81
|
-
# :
|
91
|
+
# type: "send",
|
92
|
+
# account: "nano_1kdc5u48j3hr5r7eof9iao47szqh81ndqgq5e5hrsn1g9a3sa4hkkcotn3uq",
|
93
|
+
# amount: 2,
|
94
|
+
# hash: "2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570"
|
82
95
|
# }
|
83
96
|
# ]
|
84
97
|
#
|
@@ -102,65 +115,78 @@ class Nanook
|
|
102
115
|
end
|
103
116
|
end
|
104
117
|
|
105
|
-
#
|
118
|
+
# The last modified time of the account in the time zone of
|
119
|
+
# your nano node (usually UTC).
|
120
|
+
#
|
121
|
+
# ==== Example:
|
122
|
+
#
|
123
|
+
# account.last_modified_at # => Time
|
124
|
+
#
|
125
|
+
# @return [Time] last modified time of the account in the time zone of
|
126
|
+
# your nano node (usually UTC).
|
106
127
|
def last_modified_at
|
107
128
|
response = rpc(:account_info)
|
108
129
|
Time.at(response[:modified_timestamp])
|
109
130
|
end
|
110
131
|
|
111
|
-
#
|
132
|
+
# The public key of the account.
|
112
133
|
#
|
113
|
-
# ==== Example
|
114
|
-
#
|
134
|
+
# ==== Example:
|
135
|
+
#
|
136
|
+
# account.public_key # => "3068BB1..."
|
115
137
|
#
|
116
|
-
# @return [String] public key of
|
138
|
+
# @return [String] public key of the account
|
117
139
|
def public_key
|
118
140
|
rpc(:account_key)[:key]
|
119
141
|
end
|
120
142
|
|
121
|
-
#
|
122
|
-
# Representatives are accounts
|
143
|
+
# The representative account id for the account.
|
144
|
+
# Representatives are accounts that cast votes in the case of a
|
123
145
|
# fork in the network.
|
124
146
|
#
|
125
|
-
# ==== Example
|
147
|
+
# ==== Example:
|
126
148
|
#
|
127
|
-
# "
|
149
|
+
# account.representative # => "nano_3pc..."
|
128
150
|
#
|
129
|
-
# @return [String] Representative account of
|
151
|
+
# @return [String] Representative account of the account
|
130
152
|
def representative
|
131
153
|
rpc(:account_representative)[:representative]
|
132
154
|
end
|
133
155
|
|
134
|
-
#
|
156
|
+
# The account's balance, including pending (unreceived payments).
|
157
|
+
# To receive a pending amount see {WalletAccount#receive}.
|
135
158
|
#
|
136
|
-
# ====
|
159
|
+
# ==== Examples:
|
137
160
|
#
|
138
161
|
# account.balance
|
139
162
|
#
|
140
|
-
#
|
141
|
-
# # {
|
142
|
-
# # balance=>2, # Account balance
|
143
|
-
# # pending=>1.1 # Amount pending and not yet received by the account
|
144
|
-
# # }
|
163
|
+
# Example response:
|
145
164
|
#
|
146
|
-
#
|
165
|
+
# {
|
166
|
+
# balance: 2,
|
167
|
+
# pending: 1.1
|
168
|
+
# }
|
169
|
+
#
|
170
|
+
# Asking for the balance to be returned in raw instead of NANO:
|
147
171
|
#
|
148
172
|
# account.balance(unit: :raw)
|
149
173
|
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
174
|
+
# Example response:
|
175
|
+
#
|
176
|
+
# {
|
177
|
+
# balance: 2000000000000000000000000000000,
|
178
|
+
# pending: 1100000000000000000000000000000
|
179
|
+
# }
|
155
180
|
#
|
156
181
|
# @param unit [Symbol] default is {Nanook.default_unit}.
|
157
182
|
# Must be one of {Nanook::UNITS}.
|
158
183
|
# Represents the unit that the balances will be returned in.
|
159
184
|
# Note: this method interprets
|
160
|
-
# +:nano+ as NANO, which is technically Mnano
|
185
|
+
# +:nano+ as NANO, which is technically Mnano.
|
161
186
|
# See {https://nano.org/en/faq#what-are-nano-units- What are Nano's Units}
|
162
187
|
#
|
163
188
|
# @raise ArgumentError if an invalid +unit+ was given.
|
189
|
+
# @return [Hash{Symbol=>Integer|Float}]
|
164
190
|
def balance(unit: Nanook.default_unit)
|
165
191
|
unless Nanook::UNITS.include?(unit)
|
166
192
|
raise ArgumentError.new("Unsupported unit: #{unit}")
|
@@ -174,57 +200,69 @@ class Nanook
|
|
174
200
|
end
|
175
201
|
end
|
176
202
|
|
177
|
-
#
|
203
|
+
# @return [Integer] number of blocks for this account
|
204
|
+
def block_count
|
205
|
+
rpc(:account_block_count)[:block_count]
|
206
|
+
end
|
207
|
+
|
208
|
+
# The id of the account.
|
209
|
+
#
|
210
|
+
# ==== Example:
|
211
|
+
#
|
212
|
+
# account.id # => "nano_16u..."
|
213
|
+
#
|
178
214
|
# @return [String] the id of the account
|
179
215
|
def id
|
180
216
|
@account
|
181
217
|
end
|
182
218
|
|
183
|
-
#
|
219
|
+
# Information about the account.
|
184
220
|
#
|
185
|
-
# ====
|
221
|
+
# ==== Examples:
|
186
222
|
#
|
187
223
|
# account.info
|
188
224
|
#
|
189
|
-
#
|
225
|
+
# Example response:
|
226
|
+
#
|
190
227
|
# {
|
191
|
-
# :
|
192
|
-
# :
|
193
|
-
# :
|
194
|
-
# :
|
195
|
-
# :
|
196
|
-
# :
|
197
|
-
# :
|
228
|
+
# id: "nano_16u1uufyoig8777y6r8iqjtrw8sg8maqrm36zzcm95jmbd9i9aj5i8abr8u5",
|
229
|
+
# balance: 11.439597000000001,
|
230
|
+
# block_count: 4,
|
231
|
+
# frontier: "2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570",
|
232
|
+
# modified_timestamp: 1520500357,
|
233
|
+
# open_block: "C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
|
234
|
+
# representative_block: "C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9"
|
198
235
|
# }
|
199
236
|
#
|
200
|
-
#
|
237
|
+
# Asking for more detail to be returned:
|
201
238
|
#
|
202
239
|
# account.info(detailed: true)
|
203
240
|
#
|
204
|
-
#
|
241
|
+
# Example response:
|
242
|
+
#
|
205
243
|
# {
|
206
|
-
# :
|
207
|
-
# :
|
208
|
-
# :
|
209
|
-
# :
|
210
|
-
# :
|
211
|
-
# :
|
212
|
-
# :
|
213
|
-
# :
|
214
|
-
# :
|
215
|
-
# :
|
216
|
-
# :
|
244
|
+
# id: "nano_16u1uufyoig8777y6r8iqjtrw8sg8maqrm36zzcm95jmbd9i9aj5i8abr8u5",
|
245
|
+
# balance: 11.439597000000001,
|
246
|
+
# block_count: 4,
|
247
|
+
# frontier: "2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570",
|
248
|
+
# modified_timestamp: 1520500357,
|
249
|
+
# open_block: "C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
|
250
|
+
# pending: 0,
|
251
|
+
# public_key: "A82C906460046D230D7D37C6663723DC3EFCECC4B3254EBF45294B66746F4FEF",
|
252
|
+
# representative: "nano_3pczxuorp48td8645bs3m6c3xotxd3idskrenmi65rbrga5zmkemzhwkaznh",
|
253
|
+
# representative_block: "C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
|
254
|
+
# weight: 0
|
217
255
|
# }
|
218
256
|
#
|
219
257
|
# @param detailed [Boolean] (default is false). When +true+, four
|
220
258
|
# additional calls are made to the RPC to return more information
|
221
259
|
# @param unit (see #balance)
|
222
|
-
# @return [Hash] information about the account containing:
|
223
|
-
# [+id] The account id
|
260
|
+
# @return [Hash{Symbol=>String|Integer|Float}] information about the account containing:
|
261
|
+
# [+id+] The account id
|
224
262
|
# [+frontier+] The latest block hash
|
225
263
|
# [+open_block+] The first block in every account's blockchain. When this block was published the account was officially open
|
226
264
|
# [+representative_block+] The block that named the representative for the account
|
227
|
-
# [+balance+] Amount in
|
265
|
+
# [+balance+] Amount in either NANO or raw (depending on the <tt>unit:</tt> argument)
|
228
266
|
# [+last_modified+] Unix timestamp
|
229
267
|
# [+block_count+] Number of blocks in the account's blockchain
|
230
268
|
#
|
@@ -267,24 +305,18 @@ class Nanook
|
|
267
305
|
"#{self.class.name}(id: \"#{id}\", object_id: \"#{"0x00%x" % (object_id << 1)}\")"
|
268
306
|
end
|
269
307
|
|
270
|
-
#
|
308
|
+
# Information about the given account as well as other
|
271
309
|
# accounts up the ledger. The number of accounts returned is determined
|
272
310
|
# by the <tt>limit:</tt> argument.
|
273
311
|
#
|
274
|
-
#
|
275
|
-
# #info(detailed: false) method returns.
|
276
|
-
#
|
277
|
-
# ==== Arguments
|
278
|
-
#
|
279
|
-
# [+limit:+] Number of accounts to return in the ledger (default is 1)
|
280
|
-
#
|
281
|
-
# ==== Example
|
312
|
+
# ==== Example:
|
282
313
|
#
|
283
314
|
# account.ledger(limit: 2)
|
284
315
|
#
|
285
|
-
#
|
316
|
+
# Example response:
|
317
|
+
#
|
286
318
|
# {
|
287
|
-
# :
|
319
|
+
# :nano_3c3ek3k8135f6e8qtfy8eruk9q3yzmpebes7btzncccdest8ymzhjmnr196j=>{
|
288
320
|
# :frontier=>"2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570",
|
289
321
|
# :open_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
|
290
322
|
# :representative_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
|
@@ -292,42 +324,67 @@ class Nanook
|
|
292
324
|
# :modified_timestamp=>1520500357,
|
293
325
|
# :block_count=>4
|
294
326
|
# },
|
295
|
-
# :
|
327
|
+
# :nano_3c3ettq59kijuuad5fnaq35itc9schtr4r7r6rjhmwjbairowzq3wi5ap7h8=>{ ... }
|
296
328
|
# }
|
297
|
-
|
298
|
-
|
329
|
+
#
|
330
|
+
# @param [Integer] limit number of accounts to return in the ledger (default is 1)
|
331
|
+
# @param [Time] modified_since return only accounts modified in the local database after this time
|
332
|
+
# @param unit (see #balance)
|
333
|
+
# @return [Hash{Symbol=>String|Integer}]
|
334
|
+
def ledger(limit: 1, modified_since:nil, unit: Nanook.default_unit)
|
335
|
+
unless Nanook::UNITS.include?(unit)
|
336
|
+
raise ArgumentError.new("Unsupported unit: #{unit}")
|
337
|
+
end
|
338
|
+
|
339
|
+
params = { count: limit }
|
340
|
+
|
341
|
+
unless modified_since.nil?
|
342
|
+
params[:modified_since] = modified_since.to_i
|
343
|
+
end
|
344
|
+
|
345
|
+
response = rpc(:ledger, params)[:accounts]
|
346
|
+
|
347
|
+
return response if unit == :raw
|
348
|
+
|
349
|
+
r = response.map do |account_id, l|
|
350
|
+
l[:balance] = Nanook::Util.raw_to_NANO(l[:balance])
|
351
|
+
|
352
|
+
[account_id, l]
|
353
|
+
end
|
354
|
+
|
355
|
+
Hash[r].to_symbolized_hash
|
299
356
|
end
|
300
357
|
|
301
|
-
#
|
358
|
+
# Information about pending blocks (payments) that are
|
302
359
|
# waiting to be received by the account.
|
303
360
|
#
|
304
|
-
# See also the #receive method
|
361
|
+
# See also the {Nanook::WalletAccount#receive} method for how to
|
362
|
+
# receive a pending payment.
|
305
363
|
#
|
306
364
|
# The default response is an Array of block ids.
|
307
365
|
#
|
308
366
|
# With the +detailed:+ argument, the method returns an Array of Hashes,
|
309
367
|
# which contain the source account id, amount pending and block id.
|
310
368
|
#
|
311
|
-
# ====
|
369
|
+
# ==== Examples:
|
312
370
|
#
|
313
|
-
# account.pending # => ["
|
371
|
+
# account.pending # => ["000D1BA..."]
|
314
372
|
#
|
315
|
-
#
|
373
|
+
# Asking for more detail to be returned:
|
316
374
|
#
|
317
375
|
# account.pending(detailed: true)
|
318
|
-
#
|
319
|
-
#
|
320
|
-
#
|
321
|
-
#
|
322
|
-
#
|
323
|
-
#
|
324
|
-
#
|
325
|
-
#
|
326
|
-
#
|
327
|
-
#
|
328
|
-
#
|
329
|
-
#
|
330
|
-
# account.pending(detailed: true, unit: raw).first[:amount] # => 6000000000000000000000000000000
|
376
|
+
#
|
377
|
+
# Example response:
|
378
|
+
#
|
379
|
+
# [
|
380
|
+
# {
|
381
|
+
# block: "000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F",
|
382
|
+
# amount: 6,
|
383
|
+
# source: "nano_3dcfozsmekr1tr9skf1oa5wbgmxt81qepfdnt7zicq5x3hk65fg4fqj58mbr"
|
384
|
+
# },
|
385
|
+
# { ... }
|
386
|
+
# ]
|
387
|
+
#
|
331
388
|
# @param limit [Integer] number of pending blocks to return (default is 1000)
|
332
389
|
# @param detailed [Boolean]return a more complex Hash of pending block information (default is +false+)
|
333
390
|
# @param unit (see #balance)
|
@@ -358,13 +415,14 @@ class Nanook
|
|
358
415
|
end
|
359
416
|
end
|
360
417
|
|
361
|
-
#
|
418
|
+
# The account's weight.
|
362
419
|
#
|
363
420
|
# Weight is determined by the account's balance, and represents
|
364
421
|
# the voting weight that account has on the network. Only accounts
|
365
422
|
# with greater than 256 weight can vote.
|
366
423
|
#
|
367
424
|
# ==== Example:
|
425
|
+
#
|
368
426
|
# account.weight # => 0
|
369
427
|
#
|
370
428
|
# @return [Integer] the account's weight
|