nanook 2.2.0 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a13b3163d4646a6b2be0f571fff5b848a7bb235
4
- data.tar.gz: 07ecc5c01111b031717e8f2296405598997adda1
3
+ metadata.gz: 4453793303eb12685b219bed3586cfe92f09909f
4
+ data.tar.gz: 0b4a3a21470ba6b7916a8fe7304234be89fd6234
5
5
  SHA512:
6
- metadata.gz: 386623ddde38720cb70b25dfb3c24dfbdc05b77ef47f0d977ac0f4e8486a5f0b00b05aee8993f61ece0c47fe1bc827208a1fddf74b5161e149f2e0052d1862b8
7
- data.tar.gz: 3c7911c97fb02a1b8b5b449be32e916abfc6f585f3942546933ef6762528aad1bfed3b09abd35735b5451ec984ad5c7ea6133b6756d5c501ab513ad4fe2ae3e2
6
+ metadata.gz: 1dc885c8cf50d2773de155e3b970cdf3f400641d9cc5a378996cc544ba18b96eab0a97dfc01592a33bf027fac2df6fa3f29bdf886e8c7fecaf827f4bcc848968
7
+ data.tar.gz: ff5a87c994fa30e96730336a9ea5ee6c14939302ee2dd329dd83faa01a4479cbd0dfcd79dc0374a44d9c7562813e6799038d532b0c0f05c75fd30aa5c3214ebc
data/CHANGELOG.md CHANGED
@@ -4,16 +4,21 @@ 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.3.0
8
+
9
+ ### Added
10
+
11
+ - New `Nanook::Wallet#default_representative` method.
12
+ - New `Nanook::Wallet#change_default_representative` method.
13
+ - New `Nanook::Wallet#info` method.
14
+
7
15
  ## 2.2.0
8
16
 
9
17
  ### Added
10
18
 
11
19
  - 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
20
  - `Nanook::Node#block_count_type` is now an alias to the preferred `#block_count_by_type`
15
21
  method.
16
- - `Nanook::Node#representatives` now takes `unit` argument.
17
22
  - new `Nanook::Node#representatives_online` method.
18
23
  - `Nanook::Node#synchronizing_blocks` aliased by `#unchecked`, for people familiar with
19
24
  what the RPC calls it.
@@ -28,6 +33,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
28
33
 
29
34
  ### Changed
30
35
 
36
+ - `Nanook::Account#delegators` now takes `unit` argument.
37
+ - `Nanook::Account#ledger` now takes `unit` and `modified_since` arguments.
38
+ - `Nanook::Node#representatives` now takes `unit` argument.
31
39
  - `Nanook::Node#synced?` is deprecated with a `warn`. Nodes never seem to reach 100%
32
40
  synchronized, so this method is useless.
33
41
  - `Nanook::Rpc::DEFAULT_TIMEOUT` reduced from 500 to 60.
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.2"
14
+ gem 'nanook', "~> 2.3"
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.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).
123
+ Below is a quick reference list of commands. See the [full Nanook documentation](https://lukes.github.io/nanook/2.3.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.2.0/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.3.0/Nanook/Wallet.html) for a detailed description of each method and example responses.
128
128
 
129
129
  #### Create wallet:
130
130
 
@@ -162,6 +162,10 @@ wallet.account.create
162
162
  wallet.accounts
163
163
  wallet.contains?(account_id)
164
164
 
165
+ wallet.default_representative
166
+ wallet.change_default_representative(new_representative)
167
+ wallet.info
168
+ wallet.info(unit: :raw)
165
169
  wallet.export
166
170
  wallet.locked?
167
171
  wallet.unlock(password)
@@ -185,7 +189,7 @@ Nanook.new.wallet(wallet_id).account.create(5)
185
189
 
186
190
  #### Working with a single account:
187
191
 
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.
192
+ See the [full documentation for Nanook::WalletAccount](https://lukes.github.io/nanook/2.3.0/Nanook/WalletAccount.html) for a detailed description of each method and example responses.
189
193
 
190
194
  ```ruby
191
195
  account = Nanook.new.wallet(wallet_id).account(account_id)
@@ -225,7 +229,7 @@ account.destroy
225
229
 
226
230
  #### Working with any account (not necessarily in your wallet):
227
231
 
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.
232
+ See the [full documentation for Nanook::Account](https://lukes.github.io/nanook/2.3.0/Nanook/Account.html) for a detailed description of each method and example responses.
229
233
 
230
234
  ```ruby
231
235
  account = Nanook.new.account(account_id)
@@ -258,7 +262,7 @@ account.weight
258
262
 
259
263
  ### Blocks
260
264
 
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.
265
+ See the [full documentation for Nanook::Block](https://lukes.github.io/nanook/2.3.0/Nanook/Block.html) for a detailed description of each method and example responses.
262
266
 
263
267
  ```ruby
264
268
  block = Nanook.new.block(block_id)
@@ -285,7 +289,7 @@ block.is_valid_work?(work_id)
285
289
 
286
290
  ### Managing your nano node
287
291
 
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.
292
+ See the [full documentation for Nanook::Node](https://lukes.github.io/nanook/2.3.0/Nanook/Node.html) for a detailed description of each method and example responses.
289
293
 
290
294
  ```ruby
291
295
  node = Nanook.new.node
@@ -141,7 +141,7 @@ class Nanook
141
141
  end
142
142
 
143
143
  # The representative account id for the account.
144
- # Representatives are accounts which cast votes in the case of a
144
+ # Representatives are accounts that cast votes in the case of a
145
145
  # fork in the network.
146
146
  #
147
147
  # ==== Example:
@@ -1,3 +1,3 @@
1
1
  class Nanook
2
- VERSION = "2.2.0"
2
+ VERSION = "2.3.0"
3
3
  end
data/lib/nanook/wallet.rb CHANGED
@@ -18,7 +18,7 @@ class Nanook
18
18
  # person needs to know your wallet id as well as have access to run
19
19
  # RPC commands against your nano node to be able to control your accounts.
20
20
  #
21
- # A _seed_ on the otherhand can be used to link any wallet to another
21
+ # A _seed_ on the other hand can be used to link any wallet to another
22
22
  # wallet's accounts, from anywhere in the nano network. This happens
23
23
  # by setting a wallet's seed to be the same as a previous wallet's seed.
24
24
  # When a wallet has the same seed as another wallet, any accounts
@@ -387,6 +387,50 @@ class Nanook
387
387
  account(into).receive(block)
388
388
  end
389
389
 
390
+ # The default representative account id for the wallet. This is the
391
+ # representative that all new accounts created in this wallet will have.
392
+ #
393
+ # Changing the default representative for a wallet does not change
394
+ # the representatives for any accounts that have been created.
395
+ #
396
+ # ==== Example:
397
+ #
398
+ # wallet.default_representative # => "xrb_3pc..."
399
+ #
400
+ # @return [String] Representative account of the account
401
+ def default_representative
402
+ rpc(:wallet_representative)[:representative]
403
+ end
404
+ alias_method :representative, :default_representative
405
+
406
+ # Sets the default representative for the wallet. A wallet's default
407
+ # representative is the representative all new accounts created in
408
+ # the wallet will have. Changing the default representative for a
409
+ # wallet does not change the representatives for existing accounts
410
+ # in the wallet.
411
+ #
412
+ # ==== Example:
413
+ #
414
+ # wallet.change_default_representative("xrb_...") # => "xrb_..."
415
+ #
416
+ # @param [String] representative the id of the representative account
417
+ # to set as this account's representative
418
+ # @return [String] the representative account id
419
+ # @raise [ArgumentError] if the representative account does not exist
420
+ # @raise [Nanook::Error] if setting the representative fails
421
+ def change_default_representative(representative)
422
+ unless Nanook::Account.new(@rpc, representative).exists?
423
+ raise ArgumentError.new("Representative account does not exist: #{representative}")
424
+ end
425
+
426
+ if rpc(:wallet_representative_set, representative: representative)[:set] == 1
427
+ representative
428
+ else
429
+ raise Nanook::Error.new("Setting the representative failed")
430
+ end
431
+ end
432
+ alias_method :change_representative, :change_default_representative
433
+
390
434
  # Restores a previously created wallet by its seed.
391
435
  # A new wallet will be created on your node (with a new wallet id)
392
436
  # and will have its seed set to the given seed.
@@ -414,6 +458,53 @@ class Nanook
414
458
  self
415
459
  end
416
460
 
461
+ # Information about this wallet and all of its accounts.
462
+ #
463
+ # ==== Examples:
464
+ #
465
+ # wallet.info
466
+ #
467
+ # Example response:
468
+ #
469
+ # {
470
+ # id: "2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570",
471
+ # accounts: [
472
+ # {
473
+ # id: "xrb_11119gbh8hb4hj1duf7fdtfyf5s75okzxdgupgpgm1bj78ex3kgy7frt3s9n"
474
+ # frontier: "E71AF3E9DD86BBD8B4620EFA63E065B34D358CFC091ACB4E103B965F95783321",
475
+ # open_block: "643B77F1ECEFBDBE1CC909872964C1DBBE23A6149BD3CEF2B50B76044659B60F",
476
+ # representative_block: "643B77F1ECEFBDBE1CC909872964C1DBBE23A6149BD3CEF2B50B76044659B60F",
477
+ # balance: 1.45,
478
+ # modified_timestamp: 1511476234,
479
+ # block_count: 2
480
+ # },
481
+ # { ... }
482
+ # ]
483
+ # }
484
+ #
485
+ # @param unit (see #balance)
486
+ # @return [Hash{Symbol=>String|Array<Hash{Symbol=>String|Integer|Float}>}] information about the wallet.
487
+ # See {Nanook::Account#info} for details of what is returned for each account.
488
+ def info(unit: Nanook.default_unit)
489
+ unless Nanook::UNITS.include?(unit)
490
+ raise ArgumentError.new("Unsupported unit: #{unit}")
491
+ end
492
+
493
+ wallet_required!
494
+ accounts = rpc(:wallet_ledger)[:accounts].map do |account_id, payload|
495
+ payload[:id] = account_id
496
+ if unit == :nano
497
+ payload[:balance] = Nanook::Util.raw_to_NANO(payload[:balance])
498
+ end
499
+ payload
500
+ end
501
+
502
+ {
503
+ id: @wallet,
504
+ accounts: accounts
505
+ }.to_symbolized_hash
506
+ end
507
+
417
508
  # Returns +true+ if the wallet is locked.
418
509
  #
419
510
  # ==== Example:
@@ -206,6 +206,9 @@ class Nanook
206
206
  # broadcast to the nano network. The block contains the information
207
207
  # about the representative change for your account.
208
208
  #
209
+ # Also see {Nanook::Wallet#change_default_representative} for how to set a default
210
+ # representative for all new accounts created in a wallet.
211
+ #
209
212
  # ==== Example:
210
213
  #
211
214
  # account.change_representative("xrb_...") # => "000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanook
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Duncalfe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-16 00:00:00.000000000 Z
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,18 +126,18 @@ dependencies:
126
126
  name: symbolized
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - '='
130
130
  - !ruby/object:Gem::Version
131
131
  version: 0.0.1
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - '='
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.0.1
139
- description: Ruby library for managing a nano currency node, including making and
140
- receiving payments, using the nano RPC protocol
139
+ description: Library for managing a nano currency node, including making and receiving
140
+ payments, using the nano RPC protocol
141
141
  email:
142
142
  - lduncalfe@eml.cc
143
143
  executables: []