nanook 1.0.2 → 2.0.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.
@@ -1,25 +1,22 @@
1
1
  class Nanook
2
2
  class WalletAccount
3
3
 
4
- UNITS = [:raw, :nano]
5
- DEFAULT_UNIT = :nano
6
-
7
4
  def initialize(rpc, wallet, account)
8
5
  @rpc = rpc
9
6
  @wallet = wallet
10
7
  @account = account
11
-
12
- # An object to delegate account methods that don't
13
- # expect a wallet param in the RPC call, to allow this
14
- # class to support all methods that can be called on Nanook::Account
15
- @nanook_account_instance = Nanook::Account.new(@rpc, @account)
16
-
17
- # Wallet instance to call contains? on to check account
18
- # is in wallet
19
- @nanook_wallet_instance = Nanook::Wallet.new(@rpc, @wallet)
20
-
21
- if @account
22
- account_must_belong_to_wallet!
8
+ @nanook_account_instance = nil
9
+
10
+ unless @account.nil?
11
+ # Wallet must contain the account
12
+ unless Nanook::Wallet.new(@rpc, @wallet).contains?(@account)
13
+ raise ArgumentError.new("Account does not exist in wallet. Account: #{@account}, wallet: #{@wallet}")
14
+ end
15
+
16
+ # An object to delegate account methods that don't
17
+ # expect a wallet param in the RPC call, to allow this
18
+ # class to support all methods that can be called on Nanook::Account
19
+ @nanook_account_instance = Nanook::Account.new(@rpc, @account)
23
20
  end
24
21
  end
25
22
 
@@ -27,26 +24,43 @@ class Nanook
27
24
  @account
28
25
  end
29
26
 
30
- def create
31
- wallet_required!
32
- rpc(:account_create)[:account]
27
+ # Create a new account in this wallet.
28
+ #
29
+ # ==== Example:
30
+ #
31
+ # wallet.create # => Create 1 account, and return the {Nanook::WalletAccount}
32
+ # wallet.create(2) # => Create 2 accounts, and return an Array of {Nanook::WalletAccount}
33
+ #
34
+ # @param n [Integer] number of accounts to create (default is 1)
35
+ #
36
+ # @return [Nanook::WalletAccount] will return a single {Nanook::WalletAccount}
37
+ # unless method was called with
38
+ # @return [Array<Nanook::WalletAccount>] will return an Array of {Nanook::WalletAccount}
39
+ # if method was called with
40
+ def create(n=1)
41
+ if n < 1
42
+ raise ArgumentError.new("number of accounts must be greater than 1")
43
+ end
44
+
45
+ if n == 1
46
+ Nanook::WalletAccount.new(@rpc, @wallet, rpc(:account_create)[:account])
47
+ else
48
+ Array(rpc(:accounts_create, count: n)[:accounts]).map do |account|
49
+ Nanook::WalletAccount.new(@rpc, @wallet, account)
50
+ end
51
+ end
33
52
  end
34
53
 
35
54
  def destroy
36
- wallet_required!
37
- (rpc(:account_remove)[:removed] == 1).tap do |success|
38
- @known_valid_accounts.delete(@account) if success
39
- end
55
+ rpc(:account_remove)[:removed] == 1
40
56
  end
41
57
 
42
- def inspect # :nodoc:
58
+ def inspect
43
59
  "#{self.class.name}(wallet_id: #{wallet_id}, account_id: #{account_id}, object_id: \"#{"0x00%x" % (object_id << 1)}\")"
44
60
  end
45
61
 
46
- def pay(to:, amount:, unit: DEFAULT_UNIT, id:)
47
- wallet_required!
48
-
49
- unless UNITS.include?(unit)
62
+ def pay(to:, amount:, unit: Nanook::default_unit, id:)
63
+ unless Nanook::UNITS.include?(unit)
50
64
  raise ArgumentError.new("Unsupported unit: #{unit}")
51
65
  end
52
66
 
@@ -81,8 +95,6 @@ class Nanook
81
95
 
82
96
  # Returns false if no block to receive
83
97
  def receive(block=nil)
84
- wallet_required!
85
-
86
98
  if block.nil?
87
99
  _receive_without_block
88
100
  else
@@ -90,6 +102,39 @@ class Nanook
90
102
  end
91
103
  end
92
104
 
105
+ # Sets the representative for the account.
106
+ #
107
+ # A representative is an account that will vote on your account's
108
+ # behalf on the nano network if your account is offline and there is
109
+ # a fork of the network that requires voting on.
110
+ #
111
+ # Returns a String of the <em>change block</em> that was
112
+ # broadcast to the nano network. The block contains the information
113
+ # about the representative change for your account.
114
+ #
115
+ # Will throw an +ArgumentError+ if the representative account does not
116
+ # exist.
117
+ #
118
+ # ==== Arguments
119
+ # [+representative+] String of a representative account (starting with
120
+ # <tt>"xrb..."</tt>) to set as this account's representative.
121
+ #
122
+ # ==== Example
123
+ #
124
+ # account.change_representative("xrb_...")
125
+ #
126
+ # ==== Example response
127
+ #
128
+ # "000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F"
129
+ def change_representative(representative)
130
+ # Check that representative is valid
131
+ unless Nanook::Account.new(@rpc, representative).exists?
132
+ raise ArgumentError.new("Representative account does not exist (#{representative})")
133
+ end
134
+
135
+ rpc(:account_representative_set, representative: representative)[:block]
136
+ end
137
+
93
138
  def wallet_id
94
139
  @wallet
95
140
  end
@@ -132,28 +177,5 @@ class Nanook
132
177
  @rpc.call(action, p.merge(params))
133
178
  end
134
179
 
135
- def wallet_required!
136
- if @wallet.nil?
137
- raise ArgumentError.new("Wallet must be present")
138
- end
139
- end
140
-
141
- def account_must_belong_to_wallet!
142
- if @account.nil?
143
- raise ArgumentError.new("Account must be present")
144
- end
145
-
146
- @known_valid_accounts ||= []
147
-
148
- # validate account is in wallet
149
- return if @known_valid_accounts.include?(@account)
150
-
151
- if @nanook_wallet_instance.contains?(@account)
152
- @known_valid_accounts << @account
153
- else
154
- raise ArgumentError.new("Account does not exist in wallet. Account: #{@account}, wallet: #{@wallet}")
155
- end
156
- end
157
-
158
180
  end
159
181
  end
@@ -13,7 +13,7 @@ class Nanook
13
13
  rpc(:work_peers_clear).has_key?(:success)
14
14
  end
15
15
 
16
- def inspect # :nodoc:
16
+ def inspect
17
17
  "#{self.class.name}(object_id: \"#{"0x00%x" % (object_id << 1)}\")"
18
18
  end
19
19
 
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: 1.0.2
4
+ version: 2.0.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-03-15 00:00:00.000000000 Z
11
+ date: 2018-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
@@ -95,33 +95,33 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.3'
97
97
  - !ruby/object:Gem::Dependency
98
- name: sdoc
98
+ name: webmock
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.0'
103
+ version: '3.3'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.0'
110
+ version: '3.3'
111
111
  - !ruby/object:Gem::Dependency
112
- name: webmock
112
+ name: yard
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '3.3'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '3.3'
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: symbolized
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -144,18 +144,11 @@ executables: []
144
144
  extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
- - ".circleci/config.yml"
148
- - ".gitignore"
149
- - ".rspec"
150
147
  - CHANGELOG.md
151
- - Gemfile
152
- - Gemfile.lock
153
148
  - LICENSE.txt
154
149
  - README.md
155
- - Rakefile
156
150
  - bin/console
157
151
  - bin/setup
158
- - img/qr.png
159
152
  - lib/nanook.rb
160
153
  - lib/nanook/account.rb
161
154
  - lib/nanook/block.rb
@@ -168,11 +161,11 @@ files:
168
161
  - lib/nanook/wallet.rb
169
162
  - lib/nanook/wallet_account.rb
170
163
  - lib/nanook/work_peer.rb
171
- - nanook.gemspec
172
164
  homepage: https://github.com/lukes/nanook
173
165
  licenses:
174
166
  - MIT
175
- metadata: {}
167
+ metadata:
168
+ yard.run: yri
176
169
  post_install_message:
177
170
  rdoc_options: []
178
171
  require_paths:
@@ -181,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
174
  requirements:
182
175
  - - ">="
183
176
  - !ruby/object:Gem::Version
184
- version: '0'
177
+ version: '2.0'
185
178
  required_rubygems_version: !ruby/object:Gem::Requirement
186
179
  requirements:
187
180
  - - ">="
@@ -192,6 +185,6 @@ rubyforge_project:
192
185
  rubygems_version: 2.4.5.1
193
186
  signing_key:
194
187
  specification_version: 4
195
- summary: Ruby library for managing a nano currency node, including making and receiving
188
+ summary: Library for managing a nano currency node, including making and receiving
196
189
  payments, using the nano RPC protocol
197
190
  test_files: []
@@ -1,56 +0,0 @@
1
- # Ruby CircleCI 2.0 configuration file
2
- #
3
- # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
- #
5
- version: 2
6
- jobs:
7
- build:
8
- docker:
9
- # specify the version you desire here
10
- - image: circleci/ruby:2.4.1-node-browsers
11
-
12
- # Specify service dependencies here if necessary
13
- # CircleCI maintains a library of pre-built images
14
- # documented at https://circleci.com/docs/2.0/circleci-images/
15
- # - image: circleci/postgres:9.4
16
-
17
- working_directory: ~/repo
18
-
19
- steps:
20
- - checkout
21
-
22
- # Download and cache dependencies
23
- - restore_cache:
24
- keys:
25
- - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
- # fallback to using the latest cache if no exact match is found
27
- - v1-dependencies-
28
-
29
- - run:
30
- name: install dependencies
31
- command: |
32
- bundle install --jobs=4 --retry=3 --path vendor/bundle
33
-
34
- - save_cache:
35
- paths:
36
- - ./vendor/bundle
37
- key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
-
39
- # Database setup
40
- # - run: bundle exec rake db:create
41
- # - run: bundle exec rake db:schema:load
42
-
43
- # run tests!
44
- - run:
45
- name: run tests
46
- command: |
47
- mkdir /tmp/test-results
48
-
49
- bundle exec rspec spec --format progress --format RspecJunitFormatter --out /tmp/test-results/rspec.xml
50
-
51
- # collect reports
52
- - store_test_results:
53
- path: /tmp/test-results
54
- - store_artifacts:
55
- path: /tmp/test-results
56
- destination: test-results
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /pkg/
6
- /spec/reports/
7
- /spec/examples.txt
8
- /tmp/
9
- .ruby-version
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --require spec_helper
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in nanook.gemspec
6
- gemspec
@@ -1,65 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- nanook (1.0.2)
5
- symbolized (~> 0.0.1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- addressable (2.5.2)
11
- public_suffix (>= 2.0.2, < 4.0)
12
- coderay (1.1.2)
13
- crack (0.4.3)
14
- safe_yaml (~> 1.0.0)
15
- diff-lcs (1.3)
16
- hashdiff (0.3.7)
17
- method_source (0.9.0)
18
- pry (0.11.3)
19
- coderay (~> 1.1.0)
20
- method_source (~> 0.9.0)
21
- public_suffix (3.0.2)
22
- rake (10.5.0)
23
- rdoc (6.0.1)
24
- rspec (3.7.0)
25
- rspec-core (~> 3.7.0)
26
- rspec-expectations (~> 3.7.0)
27
- rspec-mocks (~> 3.7.0)
28
- rspec-collection_matchers (1.1.3)
29
- rspec-expectations (>= 2.99.0.beta1)
30
- rspec-core (3.7.1)
31
- rspec-support (~> 3.7.0)
32
- rspec-expectations (3.7.0)
33
- diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.7.0)
35
- rspec-mocks (3.7.0)
36
- diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.7.0)
38
- rspec-support (3.7.1)
39
- rspec_junit_formatter (0.3.0)
40
- rspec-core (>= 2, < 4, != 2.12.0)
41
- safe_yaml (1.0.4)
42
- sdoc (1.0.0)
43
- rdoc (>= 5.0)
44
- symbolized (0.0.1)
45
- webmock (3.3.0)
46
- addressable (>= 2.3.6)
47
- crack (>= 0.3.2)
48
- hashdiff
49
-
50
- PLATFORMS
51
- ruby
52
-
53
- DEPENDENCIES
54
- bundler (~> 1.16)
55
- nanook!
56
- pry
57
- rake (~> 10.0)
58
- rspec (~> 3.2)
59
- rspec-collection_matchers (~> 1.1)
60
- rspec_junit_formatter (~> 0.3)
61
- sdoc (~> 1.0)
62
- webmock (~> 3.3)
63
-
64
- BUNDLED WITH
65
- 1.16.1
data/Rakefile DELETED
@@ -1,20 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
3
-
4
- require 'sdoc' # sdoc https://github.com/zzak/sdoc
5
- require 'rdoc/task'
6
- require 'nanook/version'
7
-
8
- #
9
- # Note: `rake rerdoc`` forces a fresh generation of docs
10
- #
11
-
12
- RDoc::Task.new do |rdoc|
13
- rdoc.main = 'README.md' # index page
14
- rdoc.title = "Nanook #{Nanook::VERSION} Documentation"
15
- rdoc.rdoc_files.include("README.md")
16
- rdoc.rdoc_files.include('lib/**/*.rb')
17
- rdoc.rdoc_dir = "docs/#{Nanook::VERSION}" # name of output directory
18
- rdoc.generator = 'sdoc' # explictly set the sdoc generator
19
- rdoc.template = 'rails' # template used on api.rubyonrails.org
20
- end