nanook 2.1.0 → 2.2.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/CHANGELOG.md +36 -1
- data/README.md +20 -9
- data/lib/nanook.rb +4 -4
- data/lib/nanook/account.rb +169 -111
- data/lib/nanook/error.rb +1 -0
- data/lib/nanook/node.rb +131 -4
- data/lib/nanook/rpc.rb +23 -2
- data/lib/nanook/util.rb +19 -0
- data/lib/nanook/version.rb +1 -1
- data/lib/nanook/wallet.rb +111 -75
- data/lib/nanook/wallet_account.rb +44 -40
- metadata +2 -2
@@ -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
|
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
|
-
# ====
|
69
|
+
# ==== Examples:
|
58
70
|
#
|
59
|
-
# wallet.create
|
60
|
-
# wallet.create(2)
|
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
|
-
#
|
85
|
-
#
|
97
|
+
# ==== Example:
|
98
|
+
#
|
99
|
+
# account.destroy # => true
|
86
100
|
#
|
87
|
-
# @return [Boolean]
|
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: #{
|
108
|
+
"#{self.class.name}(wallet_id: #{@wallet}, account_id: #{id}, object_id: \"#{"0x00%x" % (object_id << 1)}\")"
|
95
109
|
end
|
96
110
|
|
97
|
-
#
|
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
|
115
|
+
# Note, there may be a delay in receiving a response due to Proof
|
116
|
+
# of Work being done. From the {Nano RPC}[https://github.com/nanocurrency/raiblocks/wiki/RPC-protocol#account-create]:
|
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
122
|
# account.pay(to: "xrb_...", amount: 1.1, id: "myUniqueId123") # => "9AE2311..."
|
108
|
-
# account.pay(to: "xrb_...", amount: 54000000000000,
|
123
|
+
# account.pay(to: "xrb_...", 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
|
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
|
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,26 @@ 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
|
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
|
-
#
|
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
|
202
|
-
#
|
203
|
-
# account.change_representative("xrb_...")
|
209
|
+
# ==== Example:
|
204
210
|
#
|
205
|
-
#
|
211
|
+
# account.change_representative("xrb_...") # => "000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F"
|
206
212
|
#
|
207
|
-
#
|
213
|
+
# @param [String] representative the id of the representative account
|
214
|
+
# to set as this account's representative
|
215
|
+
# @return [String] id of the <i>change</i> block created
|
216
|
+
# @raise [ArgumentError] if the representative account does not exist
|
208
217
|
def change_representative(representative)
|
209
|
-
# Check that representative is valid
|
210
218
|
unless Nanook::Account.new(@rpc, representative).exists?
|
211
|
-
raise ArgumentError.new("Representative account does not exist
|
219
|
+
raise ArgumentError.new("Representative account does not exist: #{representative}")
|
212
220
|
end
|
213
221
|
|
214
222
|
rpc(:account_representative_set, representative: representative)[:block]
|
215
223
|
end
|
216
224
|
|
217
|
-
def wallet_id
|
218
|
-
@wallet
|
219
|
-
end
|
220
|
-
|
221
225
|
private
|
222
226
|
|
223
227
|
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.
|
4
|
+
version: 2.2.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-
|
11
|
+
date: 2018-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|