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.
@@ -1,10 +1,26 @@
1
1
  class Nanook
2
+
3
+ # The <tt>Nanook::WalletAccount</tt> class lets you manage your nano accounts,
4
+ # including paying and receiving payment.
5
+ #
6
+ # === Initializing
7
+ #
8
+ # Initialize this class through an instance of {Nanook::Wallet} like this:
9
+ #
10
+ # account = Nanook.new.wallet(wallet_id).account(account_id)
11
+ #
12
+ # Or compose the longhand way like this:
13
+ #
14
+ # rpc_conn = Nanook::Rpc.new
15
+ # account = Nanook::WalletAccount.new(rpc_conn, wallet_id, account_id)
2
16
  class WalletAccount
3
17
 
4
18
  extend Forwardable
5
19
  # @!method balance(unit: Nanook.default_unit)
6
20
  # (see Nanook::Account#balance)
7
- # @!method delegators
21
+ # @!method block_count
22
+ # (see Nanook::Account#block_count)
23
+ # @!method delegators(unit: Nanook.default_unit)
8
24
  # (see Nanook::Account#delegators)
9
25
  # @!method exists?
10
26
  # (see Nanook::Account#exists?)
@@ -16,7 +32,7 @@ class Nanook
16
32
  # (see Nanook::Account#info)
17
33
  # @!method last_modified_at
18
34
  # (see Nanook::Account#last_modified_at)
19
- # @!method ledger(limit: 1)
35
+ # @!method ledger(limit: 1, modified_since: nil, unit: Nanook.default_unit)
20
36
  # (see Nanook::Account#ledger)
21
37
  # @!method pending(limit: 1000, detailed: false, unit: Nanook.default_unit)
22
38
  # (see Nanook::Account#pending)
@@ -27,6 +43,7 @@ class Nanook
27
43
  # @!method weight
28
44
  # (see Nanook::Account#weight)
29
45
  def_delegators :@nanook_account_instance, :balance, :delegators, :exists?, :history, :id, :info, :last_modified_at, :ledger, :pending, :public_key, :representative, :weight
46
+ alias_method :open?, :exists?
30
47
 
31
48
  def initialize(rpc, wallet, account)
32
49
  @rpc = rpc
@@ -47,17 +64,12 @@ class Nanook
47
64
  end
48
65
  end
49
66
 
50
- # @return [String] the account id of this account
51
- def account_id
52
- @account
53
- end
54
-
55
67
  # Creates a new account, or multiple new accounts, in this wallet.
56
68
  #
57
- # ==== Example:
69
+ # ==== Examples:
58
70
  #
59
- # wallet.create # => Creates 1 account, and return a {Nanook::WalletAccount}
60
- # wallet.create(2) # => Creates 2 accounts, and return an Array of {Nanook::WalletAccount}
71
+ # wallet.create # => Nanook::WalletAccount
72
+ # wallet.create(2) # => [Nanook::WalletAccount, Nanook::WalletAccount]
61
73
  #
62
74
  # @param n [Integer] number of accounts to create
63
75
  #
@@ -65,6 +77,7 @@ class Nanook
65
77
  # if invoked with no argument
66
78
  # @return [Array<Nanook::WalletAccount>] returns an Array of {Nanook::WalletAccount}
67
79
  # if method was called with argument +n+ > 1
80
+ # @raise [ArgumentError] if +n+ is less than 1
68
81
  def create(n=1)
69
82
  if n < 1
70
83
  raise ArgumentError.new("number of accounts must be greater than 0")
@@ -81,31 +94,33 @@ class Nanook
81
94
 
82
95
  # Unlinks the account from the wallet.
83
96
  #
84
- # Note, it's impossible to truly destroy an account. Calling this
85
- # method on a wallet causes the wallet to "forget" the account.
97
+ # ==== Example:
98
+ #
99
+ # account.destroy # => true
86
100
  #
87
- # @return [Boolean] returns true if action was successful, otherwise +false+
101
+ # @return [Boolean] +true+ if action was successful, otherwise +false+
88
102
  def destroy
89
103
  rpc(:account_remove)[:removed] == 1
90
104
  end
91
105
 
92
106
  # @return [String]
93
107
  def inspect
94
- "#{self.class.name}(wallet_id: #{wallet_id}, account_id: #{account_id}, object_id: \"#{"0x00%x" % (object_id << 1)}\")"
108
+ "#{self.class.name}(wallet_id: #{@wallet}, account_id: #{id}, object_id: \"#{"0x00%x" % (object_id << 1)}\")"
95
109
  end
96
110
 
97
- # Make a payment from an account in this wallet to another account
111
+ # Makes a payment from this account to another account
98
112
  # on the nano network. Returns a <i>send</i> block hash
99
113
  # if successful, or a {Nanook::Error} if unsuccessful.
100
114
  #
101
- # Note, there may be a delay in receiving a response due to Proof of Work being done. From the {Nano RPC}[https://github.com/nanocurrency/raiblocks/wiki/RPC-protocol#account-create]:
115
+ # Note, there may be a delay in receiving a response due to Proof
116
+ # of Work being done. From the {Nano RPC}[https://docs.nano.org/commands/rpc-protocol/#send]:
102
117
  #
103
118
  # <i>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.</i>
104
119
  #
105
120
  # ==== Examples:
106
121
  #
107
- # account.pay(to: "xrb_...", amount: 1.1, id: "myUniqueId123") # => "9AE2311..."
108
- # account.pay(to: "xrb_...", amount: 54000000000000, unit: :raw, id: "myUniqueId123") # => "9AE2311..."
122
+ # account.pay(to: "nano_...", amount: 1.1, id: "myUniqueId123") # => "9AE2311..."
123
+ # account.pay(to: "nano_...", amount: 54000000000000, id: "myUniqueId123", unit: :raw) # => "9AE2311..."
109
124
  #
110
125
  # @param to [String] account id of the recipient of your payment
111
126
  # @param amount [Integer|Float]
@@ -115,7 +130,7 @@ class Nanook
115
130
  # the same +id+ and be reassured that you will only ever send this
116
131
  # nano payment once
117
132
  # @return [String] the send block id for the payment
118
- # @raise [Nanook::Error] if unsuccesful
133
+ # @raise [Nanook::Error] if unsuccessful
119
134
  def pay(to:, amount:, unit: Nanook::default_unit, id:)
120
135
  unless Nanook::UNITS.include?(unit)
121
136
  raise ArgumentError.new("Unsupported unit: #{unit}")
@@ -162,9 +177,9 @@ class Nanook
162
177
  # payments to receive.
163
178
  #
164
179
  # You can receive a specific pending block if you know it by
165
- # passing the block has in as an argument.
180
+ # passing the block in as an argument.
166
181
  #
167
- # ==== Examples
182
+ # ==== Examples:
168
183
  #
169
184
  # account.receive # => "9AE2311..."
170
185
  # account.receive("718CC21...") # => "9AE2311..."
@@ -172,7 +187,7 @@ class Nanook
172
187
  # @param block [String] optional block id of pending payment. If
173
188
  # not provided, the latest pending payment will be received
174
189
  # @return [String] the receive block id
175
- # @return [false] if no block to receive
190
+ # @return [false] if there was no block to receive
176
191
  def receive(block=nil)
177
192
  if block.nil?
178
193
  _receive_without_block
@@ -187,37 +202,29 @@ class Nanook
187
202
  # behalf on the nano network if your account is offline and there is
188
203
  # a fork of the network that requires voting on.
189
204
  #
190
- # Returns a String of the <em>change block</em> that was
205
+ # Returns the <em>change block</em> that was
191
206
  # broadcast to the nano network. The block contains the information
192
207
  # about the representative change for your account.
193
208
  #
194
- # Will throw an +ArgumentError+ if the representative account does not
195
- # exist.
196
- #
197
- # ==== Arguments
198
- # [+representative+] String of a representative account (starting with
199
- # <tt>"xrb..."</tt>) to set as this account's representative.
200
- #
201
- # ==== Example
209
+ # Also see {Nanook::Wallet#change_default_representative} for how to set a default
210
+ # representative for all new accounts created in a wallet.
202
211
  #
203
- # account.change_representative("xrb_...")
212
+ # ==== Example:
204
213
  #
205
- # ==== Example response
214
+ # account.change_representative("nano_...") # => "000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F"
206
215
  #
207
- # "000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F"
216
+ # @param [String] representative the id of the representative account
217
+ # to set as this account's representative
218
+ # @return [String] id of the <i>change</i> block created
219
+ # @raise [ArgumentError] if the representative account does not exist
208
220
  def change_representative(representative)
209
- # Check that representative is valid
210
221
  unless Nanook::Account.new(@rpc, representative).exists?
211
- raise ArgumentError.new("Representative account does not exist (#{representative})")
222
+ raise ArgumentError.new("Representative account does not exist: #{representative}")
212
223
  end
213
224
 
214
225
  rpc(:account_representative_set, representative: representative)[:block]
215
226
  end
216
227
 
217
- def wallet_id
218
- @wallet
219
- end
220
-
221
228
  private
222
229
 
223
230
  def _receive_without_block
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.1.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Duncalfe
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-03 00:00:00.000000000 Z
11
+ date: 2021-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '12.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '12.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -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: []
@@ -166,7 +166,7 @@ licenses:
166
166
  - MIT
167
167
  metadata:
168
168
  yard.run: yri
169
- post_install_message:
169
+ post_install_message:
170
170
  rdoc_options: []
171
171
  require_paths:
172
172
  - lib
@@ -181,9 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
183
  requirements: []
184
- rubyforge_project:
185
- rubygems_version: 2.4.5.1
186
- signing_key:
184
+ rubygems_version: 3.2.3
185
+ signing_key:
187
186
  specification_version: 4
188
187
  summary: Library for managing a nano currency node, including making and receiving
189
188
  payments, using the nano RPC protocol