nanook 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1c2a7e556469efac09a609f78e8f3a4e0533a89
4
- data.tar.gz: 12d86898565f21e0c483c891be2b36f1c838216e
3
+ metadata.gz: 5a13b3163d4646a6b2be0f571fff5b848a7bb235
4
+ data.tar.gz: 07ecc5c01111b031717e8f2296405598997adda1
5
5
  SHA512:
6
- metadata.gz: 47b9839217c59af70980fb20b1f8cefe716654170d15c908dc25f24bcba7ba34ef8b9bc5dc0b50912b447e6a779d022dbc264b2a469219c383fae754d8828843
7
- data.tar.gz: 94d4e68c2a9a8debbd06c48b98e3b30d8ec2fac6d567e5c40dba50044c82cd894b11051b9b7df32ae818dbc830b1a27b2826b0a5267e959f415dd9e90c2069bb
6
+ metadata.gz: 386623ddde38720cb70b25dfb3c24dfbdc05b77ef47f0d977ac0f4e8486a5f0b00b05aee8993f61ece0c47fe1bc827208a1fddf74b5161e149f2e0052d1862b8
7
+ data.tar.gz: 3c7911c97fb02a1b8b5b449be32e916abfc6f585f3942546933ef6762528aad1bfed3b09abd35735b5451ec984ad5c7ea6133b6756d5c501ab513ad4fe2ae3e2
@@ -4,9 +4,42 @@ 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.2.0
8
+
9
+ ### Added
10
+
11
+ - New `Nanook::Account#block_count` method returns number of blocks in ledger for an account.
12
+ - `Account#delegators` now takes `unit` argument.
13
+ - `Account#ledger` now takes `unit` and `modified_since` arguments.
14
+ - `Nanook::Node#block_count_type` is now an alias to the preferred `#block_count_by_type`
15
+ method.
16
+ - `Nanook::Node#representatives` now takes `unit` argument.
17
+ - new `Nanook::Node#representatives_online` method.
18
+ - `Nanook::Node#synchronizing_blocks` aliased by `#unchecked`, for people familiar with
19
+ what the RPC calls it.
20
+ - `Nanook::Node#version` now an aliased by `#info`
21
+ method.
22
+ - `Nanook::WalletAccount#exists?` now aliased by `#open?`
23
+
24
+ ### Removed
25
+
26
+ - `Nanook::WalletAccount#account_id` Removed, as there was already an `id` method that returned this.
27
+ - `Nanook::WalletAccount#wallet_id` Removed, as the `WalletAccount` object should be considered a kind of Account.
28
+
29
+ ### Changed
30
+
31
+ - `Nanook::Node#synced?` is deprecated with a `warn`. Nodes never seem to reach 100%
32
+ synchronized, so this method is useless.
33
+ - `Nanook::Rpc::DEFAULT_TIMEOUT` reduced from 500 to 60.
34
+
7
35
  ## 2.1.0
8
36
 
9
- - Payment methods check the account id of the recipient is valid, raises ArgumentError if not.
37
+ ### Changed
38
+
39
+ - Payment methods no longer check that recipient account has an open block, as this prevents
40
+ funds being sent to accounts about to be opened.
41
+ - Payment methods now check the account id of the recipient is valid, raises ArgumentError if not.
42
+ - Payment methods now return a Nanook::Error if the RPC returns an error when trying to pay, instead of a String.
10
43
 
11
44
  ## 2.0.0
12
45
 
@@ -24,6 +57,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
24
57
  - Added ruby version requirement >= 2.0 to gemspec.
25
58
 
26
59
  ### Changed
60
+
27
61
  - `Nanook::Rpc#inspect` displays full hostname with scheme and port.
28
62
  - `Nanook::Account#new` `account` param is now required.
29
63
  - `Nanook::Account#info` now also returns the `id` of the account.
@@ -41,6 +75,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
41
75
  - Changed documentation generating tool from rdoc to yard.
42
76
 
43
77
  ### Fixed
78
+
44
79
  - Missing `Nanook#rpc` accessor.
45
80
  - `Nanook::Block#publish` can return false when publish fails.
46
81
  - `Nanook::Block#info` correctly handles `allow_unchecked: true` errors.
data/README.md CHANGED
@@ -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', "~> 2.1"
14
+ gem 'nanook', "~> 2.2"
15
15
  ```
16
16
 
17
17
  And then execute:
@@ -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.0.0/) 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).
123
+ Below is a quick reference list of commands. See the [full Nanook documentation](https://lukes.github.io/nanook/2.2.0/) 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.0.0/classes/Nanook/Wallet.html) for a detailed description of each method and example responses.
127
+ See the [full documentation for Nanook::Wallet](https://lukes.github.io/nanook/2.2.0/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, unit: :raw, id: unique_id)
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)
@@ -185,13 +185,15 @@ Nanook.new.wallet(wallet_id).account.create(5)
185
185
 
186
186
  #### Working with a single account:
187
187
 
188
+ See the [full documentation for Nanook::WalletAccount](https://lukes.github.io/nanook/2.2.0/Nanook/WalletAccount.html) for a detailed description of each method and example responses.
189
+
188
190
  ```ruby
189
191
  account = Nanook.new.wallet(wallet_id).account(account_id)
190
192
 
191
193
  account.balance
192
194
  account.balance(unit: :raw)
193
195
  account.pay(to: recipient_account_id, amount: 2, id: unique_id)
194
- account.pay(to: recipient_account_id, amount: 2, unit: :raw, id: unique_id)
196
+ account.pay(to: recipient_account_id, amount: 2, id: unique_id, unit: :raw)
195
197
  account.pending
196
198
  account.pending(limit: 1)
197
199
  account.pending(detailed: true)
@@ -206,11 +208,14 @@ account.info(unit: :raw)
206
208
  account.last_modified_at
207
209
  account.ledger
208
210
  account.ledger(limit: 10)
211
+ account.ledger(modified_since: Time.now)
212
+ account.ledger(unit: :raw)
209
213
  account.history
210
214
  account.history(limit: 1)
211
215
  account.history(unit: :raw)
212
216
  account.public_key
213
217
  account.delegators
218
+ account.delegators(unit: :raw)
214
219
  account.representative
215
220
  account.change_representative(new_representative)
216
221
  account.weight
@@ -220,7 +225,7 @@ account.destroy
220
225
 
221
226
  #### Working with any account (not necessarily in your wallet):
222
227
 
223
- See the [full documentation for Nanook::Account](https://lukes.github.io/nanook/2.0.0/classes/Nanook/Account.html) for a detailed description of each method and example responses.
228
+ See the [full documentation for Nanook::Account](https://lukes.github.io/nanook/2.2.0/Nanook/Account.html) for a detailed description of each method and example responses.
224
229
 
225
230
  ```ruby
226
231
  account = Nanook.new.account(account_id)
@@ -239,18 +244,21 @@ account.info(unit: :raw)
239
244
  account.last_modified_at
240
245
  account.ledger
241
246
  account.ledger(limit: 10)
247
+ account.ledger(modified_since: Time.now)
248
+ account.ledger(unit: :raw)
242
249
  account.history
243
250
  account.history(limit: 1)
244
251
  account.history(unit: :raw)
245
252
  account.public_key
246
253
  account.delegators
254
+ account.delegators(unit: :raw)
247
255
  account.representative
248
256
  account.weight
249
257
  ```
250
258
 
251
259
  ### Blocks
252
260
 
253
- See the [full documentation for Nanook::Block](https://lukes.github.io/nanook/2.0.0/classes/Nanook/Block.html) for a detailed description of each method and example responses.
261
+ See the [full documentation for Nanook::Block](https://lukes.github.io/nanook/2.2.0/Nanook/Block.html) for a detailed description of each method and example responses.
254
262
 
255
263
  ```ruby
256
264
  block = Nanook.new.block(block_id)
@@ -277,20 +285,23 @@ block.is_valid_work?(work_id)
277
285
 
278
286
  ### Managing your nano node
279
287
 
288
+ See the [full documentation for Nanook::Node](https://lukes.github.io/nanook/2.2.0/Nanook/Node.html) for a detailed description of each method and example responses.
289
+
280
290
  ```ruby
281
291
  node = Nanook.new.node
282
292
 
283
293
  node.account_count
284
294
  node.block_count
285
- node.block_count_type
295
+ node.block_count_by_type
286
296
  node.bootstrap_any
287
297
  node.bootstrap(address: "::ffff:138.201.94.249", port: 7075)
288
298
  node.peers
289
299
  node.representatives
300
+ node.representatives(unit: :raw)
301
+ node.representatives_online
290
302
  node.synchronizing_blocks
291
303
  node.synchronizing_blocks(limit: 1)
292
304
  node.sync_progress
293
- node.synced?
294
305
  node.version
295
306
 
296
307
  node.stop
@@ -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 600s:
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: 600)
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: 600)
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
@@ -21,23 +21,43 @@ class Nanook
21
21
  @account = account
22
22
  end
23
23
 
24
- # Returns information about this account's delegators.
25
- # === Example response:
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
33
  # :xrb_13bqhi1cdqq8yb9szneoc38qk899d58i5rcrgdk5mkdm86hekpoez3zxw5sd=>500000000000000000000000000000000000,
28
34
  # :xrb_17k6ug685154an8gri9whhe5kb5z1mf5w6y39gokc1657sh95fegm8ht1zpn=>961647970820730000000000000000000000
29
35
  # }
30
36
  #
31
- # @return [Hash{Symbol=>String}] Delegators
32
- def delegators
33
- rpc(:delegators)[:delegators]
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 a boolean indicating if the account exists.
57
+ # Returns true if the account has an <i>open</i> block.
37
58
  #
38
- # Existence is determined by if the account has an _open_ block.
39
- # An _open_ block is a special kind of block that gets published when
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
- # @return [Boolean] Indicates if this account exists in the nano network
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
- # Returns an account's history of send and receive payments.
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
- # ==== Example response:
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
- # :type=>"send",
79
- # :account=>"xrb_1kdc5u48j3hr5r7eof9iao47szqh81ndqgq5e5hrsn1g9a3sa4hkkcotn3uq",
80
- # :amount=>2000000000000000000000000000000,
81
- # :hash=>"2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570"
91
+ # type: "send",
92
+ # account: "xrb_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
- # @return [Time] last modified time of the account in UTC time zone.
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
- # Returns the public key belonging to an account.
132
+ # The public key of the account.
112
133
  #
113
- # ==== Example response:
114
- # "3068BB1CA04525BB0E416C485FE6A67FD52540227D267CC8B6E8DA958A7FA039"
134
+ # ==== Example:
135
+ #
136
+ # account.public_key # => "3068BB1..."
115
137
  #
116
- # @return [String] public key of this account
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
- # Returns the representative account for the account.
143
+ # The representative account id for the account.
122
144
  # Representatives are accounts which cast votes in the case of a
123
145
  # fork in the network.
124
146
  #
125
- # ==== Example response
147
+ # ==== Example:
126
148
  #
127
- # "xrb_3pczxuorp48td8645bs3m6c3xotxd3idskrenmi65rbrga5zmkemzhwkaznh"
149
+ # account.representative # => "xrb_3pc..."
128
150
  #
129
- # @return [String] Representative account of this account
151
+ # @return [String] Representative account of the account
130
152
  def representative
131
153
  rpc(:account_representative)[:representative]
132
154
  end
133
155
 
134
- # Returns a Hash containing the account's balance.
156
+ # The account's balance, including pending (unreceived payments).
157
+ # To receive a pending amount see {WalletAccount#receive}.
135
158
  #
136
- # ==== Example:
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
- # ==== Example balance returned in raw:
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
- # # balance: 2000000000000000000000000000000,
153
- # # pending: 1100000000000000000000000000000
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
- # Returns the id of the account.
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 # => "xrb_16u..."
213
+ #
178
214
  # @return [String] the id of the account
179
215
  def id
180
216
  @account
181
217
  end
182
218
 
183
- # Returns a Hash containing information about the account.
219
+ # Information about the account.
184
220
  #
185
- # ==== Example 1
221
+ # ==== Examples:
186
222
  #
187
223
  # account.info
188
224
  #
189
- # ==== Example 1 response
225
+ # Example response:
226
+ #
190
227
  # {
191
- # :id=>"xrb_16u1uufyoig8777y6r8iqjtrw8sg8maqrm36zzcm95jmbd9i9aj5i8abr8u5"
192
- # :balance=>11.439597000000001,
193
- # :block_count=>4
194
- # :frontier=>"2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570",
195
- # :modified_timestamp=>1520500357,
196
- # :open_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
197
- # :representative_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
228
+ # id: "xrb_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
- # ==== Example 2
237
+ # Asking for more detail to be returned:
201
238
  #
202
239
  # account.info(detailed: true)
203
240
  #
204
- # ==== Example 2 response
241
+ # Example response:
242
+ #
205
243
  # {
206
- # :id=>"xrb_16u1uufyoig8777y6r8iqjtrw8sg8maqrm36zzcm95jmbd9i9aj5i8abr8u5"
207
- # :balance=>11.439597000000001,
208
- # :block_count=>4,
209
- # :frontier=>"2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570",
210
- # :modified_timestamp=>1520500357,
211
- # :open_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
212
- # :pending=>0,
213
- # :public_key=>"A82C906460046D230D7D37C6663723DC3EFCECC4B3254EBF45294B66746F4FEF",
214
- # :representative=>"xrb_3pczxuorp48td8645bs3m6c3xotxd3idskrenmi65rbrga5zmkemzhwkaznh",
215
- # :representative_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
216
- # :weight=>0
244
+ # id: "xrb_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: "xrb_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 {NANO}[https://nano.org/en/faq#what-are-nano-units-]
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,22 +305,16 @@ class Nanook
267
305
  "#{self.class.name}(id: \"#{id}\", object_id: \"#{"0x00%x" % (object_id << 1)}\")"
268
306
  end
269
307
 
270
- # Returns information about the given account as well as other
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
- # The information in each Hash is the same as what the
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
- # ==== Example response
316
+ # Example response:
317
+ #
286
318
  # {
287
319
  # :xrb_3c3ek3k8135f6e8qtfy8eruk9q3yzmpebes7btzncccdest8ymzhjmnr196j=>{
288
320
  # :frontier=>"2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570",
@@ -294,40 +326,65 @@ class Nanook
294
326
  # },
295
327
  # :xrb_3c3ettq59kijuuad5fnaq35itc9schtr4r7r6rjhmwjbairowzq3wi5ap7h8=>{ ... }
296
328
  # }
297
- def ledger(limit: 1)
298
- rpc(:ledger, count: limit)[:accounts]
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
- # Returns information about pending blocks (payments) that are
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 of this class for how to receive a pending payment.
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
- # ==== Example 1:
369
+ # ==== Examples:
312
370
  #
313
- # account.pending # => ["000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F"]
371
+ # account.pending # => ["000D1BA..."]
314
372
  #
315
- # ==== Example 2:
373
+ # Asking for more detail to be returned:
316
374
  #
317
375
  # account.pending(detailed: true)
318
- # # =>
319
- # # [
320
- # # {
321
- # # :block=>"000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F",
322
- # # :amount=>6,
323
- # # :source=>"xrb_3dcfozsmekr1tr9skf1oa5wbgmxt81qepfdnt7zicq5x3hk65fg4fqj58mbr"
324
- # # },
325
- # # { ... }
326
- # # ]
327
- #
328
- # ==== Example 3:
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: "xrb_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
- # Returns the account's weight.
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