banano 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 11765178fb87fa12d30b11dbe6c454af09e87c2b2ba389e368669698809ee256
4
- data.tar.gz: dee6f73a715b2b9e400491fbef8fdfbbb732051ad3d297e1dc49a3803306a0c9
3
+ metadata.gz: 142f940e2f3c62e5d2c5d1b4e41947f4bb3aa4d09afa6ef7499692538e43cc96
4
+ data.tar.gz: 8738e7a8e8675e595901e55e2ff2d7acd3841c0695460ca5b66e1e382ec3eddd
5
5
  SHA512:
6
- metadata.gz: b1cca559663f4ec639fe847d5425c1babf9be16d0d8477af593b9034f3f2093e24e6ea109e7ae6a30b53cc9af3246f061c703d3e6b5f87f2c37ec5d7bebd9c7e
7
- data.tar.gz: 37b0964c5ff8a431f403ef81f3eba4df3b44a9238026e3e6b28b993fccf8cd2aff1087ad386597a17a5f0bf1f83fac36ae4f2d193315d3a8ca4178aaea08ba4a
6
+ metadata.gz: abbacfa91f2ebd5b1cad6e736bc43b63ba65e4c4a0d1b4828624ae1807135f73c2ac6ee40d431e25ebf13f8ade1b480c038f0f8b19854521417e1dc5a74b67d2
7
+ data.tar.gz: b3e36db244547b823e407536c7951fc2d224502c2abf260eeb1cee0df2b76426831d2916c8c988609b3c7b3f2b621dca2fbe88191a4c87ccc7a2d89bea789d1c
@@ -1,2 +1,12 @@
1
+ ## v0.1.1
2
+
3
+ - Pending payments fixes - block\_id is mandatory
4
+ - Unit conversion on payment bug fixed
5
+ - Some artifacts cleaned up
6
+ - Banano::Key usage added
7
+ - Stringify keys and remove zero balances for Node RPC call responses
8
+
9
+ ## v0.1.0
10
+
1
11
  - Initial import
2
12
  - Gem packaging
data/README.md CHANGED
@@ -40,9 +40,10 @@ The code is divided on following the parts:
40
40
  - `Banano::Protocol` - including all other parts. Can be used also for some syntax sugar (to avoid sending node parameter to constructors)
41
41
  - `Banano::Client` - very thin wrapper around [Faraday HTTP Client](https://github.com/lostisland/faraday) for easy JSON-based communications
42
42
  - `Banano::Node` - Banano Node abstraction - mostly encapsulate JSON communications
43
- - `Bananp::Wallet` - wallets holding for Banano accounts on the current node
44
- - `Bananp::Account` - uniq 'ban_...' addresses used for currency tokens exchange
45
- - `Bananp::WalletAccount` - link between `Account` and `Wallet` - check if account exists in the wallet etc.
43
+ - `Banano::Wallet` - wallets holding for Banano accounts on the current node
44
+ - `Banano::Account` - uniq 'ban_...' addresses used for currency tokens exchange
45
+ - `Banano::WalletAccount` - link between `Account` and `Wallet` - check if account exists in the wallet etc.
46
+ - `Banano::Key` - account key management
46
47
 
47
48
  ### Banano::Protocol
48
49
 
@@ -56,6 +57,7 @@ BETA_URL = 'https://api-beta.banano.cc'
56
57
  wallet = @banano.wallet('WALLET15263636...')
57
58
  account = @banano.account('ban_1...')
58
59
  ```
60
+
59
61
  ### Banano::Client
60
62
 
61
63
  Not used directly, better use `Banano::Node` instead
@@ -67,7 +69,7 @@ client.rpc_call(action: :version)
67
69
 
68
70
  ### Banano::Node
69
71
 
70
- Most of the information about the running node is encapsulated here. The other parts using mostly the `Banano::Node.rpc()` method, not the low level client one:
72
+ Most of the information about the running node is encapsulated here. The other parts using mostly the `Banano::Node.rpc()` method, not the low level client one:
71
73
 
72
74
  ```rb
73
75
  Banano::Node.account_count # number of node accounts
@@ -144,6 +146,23 @@ wallet_other_acc.receive # receive some banano
144
146
 
145
147
  ```
146
148
 
149
+ ### Banano::Key
150
+
151
+ Most of the information is identicat with the [NANO currency docs](https://docs.nano.org/integration-guides/key-management/).
152
+
153
+ ```rb
154
+ key_builder = @banano.key # create new key (still unpopulated, cannot be used)
155
+ key_builder.generate # generate private, public key and account address
156
+ {:private=>"43E6B...",
157
+ :public=>"7EBC0C...",
158
+ :account=>"ban_1zow3..."}
159
+ SEED = 'ABF56EBB...' # Random seed
160
+ key_builder.generate(seed: SEED, index: 0) # will always generate SAME pair of keys and address
161
+ key_builder.generate(seed: SEED, index: 1)
162
+ new_builder = @banano.key(saved_private_key) # generate keys from saved private key
163
+ new_builder.expand # return private, public key and account address
164
+ ```
165
+
147
166
  ### Banano::Unit
148
167
 
149
168
  Using [Ruby bigdecimal library](https://apidock.com/ruby/BigDecimal) for all operations:
@@ -104,7 +104,7 @@ module Banano
104
104
  params = {count: limit}
105
105
  params[:source] = true if detailed
106
106
 
107
- response = rpc(action: :pending, params: params)[:blocks]
107
+ response = rpc(action: :wallet_pending, params: params)[:blocks]
108
108
  return response unless detailed && !response.empty?
109
109
 
110
110
  response.map do |key, val|
@@ -45,7 +45,8 @@ module Banano
45
45
 
46
46
  # @return [Hash{Symbol=>String}] information about the node peers
47
47
  def peers
48
- rpc(action: :peers)[:peers]
48
+ h = -> (h) { Hash[h.map{ |k,v| [k.to_s, v] }] }
49
+ h.call(rpc(action: :peers)[:peers])
49
50
  end
50
51
 
51
52
  # All representatives and their voting weight.
@@ -54,6 +55,7 @@ module Banano
54
55
  # @return [Hash{Symbol=>Integer}] known representatives and their voting weight
55
56
  def representatives(raw = true)
56
57
  response = rpc(action: :representatives)[:representatives]
58
+ response = response.delete_if {|_, balance| balance.to_s == '0' } # remove 0 balance reps
57
59
  return response if raw == true
58
60
 
59
61
  r = response.map do |address, balance|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Banano
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -70,7 +70,7 @@ module Banano
70
70
  # wallet.account.create # => Banano::WalletAccount
71
71
  #
72
72
  # @param [String] account optional String of an account (starting with
73
- # <tt>"xrb..."</tt>) to start working with. Must be an account within
73
+ # <tt>"ban_..."</tt>) to start working with. Must be an account within
74
74
  # the wallet. When no account is given, the instance returned only
75
75
  # allows you to call +create+ on it, to create a new account.
76
76
  # @raise [ArgumentError] if the wallet does no contain the account
@@ -357,17 +357,12 @@ module Banano
357
357
 
358
358
  # Receives a pending payment into an account in the wallet.
359
359
  #
360
- # When called with no +block+ argument, the latest pending payment
361
- # for the account will be received.
362
- #
363
360
  # Returns a <i>receive</i> block hash id if a receive was successful,
364
361
  # or +false+ if there were no pending payments to receive.
365
362
  #
366
- # You can receive a specific pending block if you know it by
367
- # passing the block has in as an argument.
363
+ # Receive a specific pending block by passing block_id as an argument
368
364
  # ==== Examples:
369
365
  #
370
- # wallet.receive(into: "ban_..") # => "9AE2311..."
371
366
  # wallet.receive("718CC21...", into: "ban_..") # => "9AE2311..."
372
367
  #
373
368
  # @param block (see Banano::WalletAccount#receive)
@@ -375,7 +370,7 @@ module Banano
375
370
  # payment into
376
371
  #
377
372
  # @return (see Banano::WalletAccount#receive)
378
- def receive(block: nil, into:)
373
+ def receive(block:, into:)
379
374
  wallet_required!
380
375
  validate_wallet_contains_account!(into)
381
376
  # account(into) will return Banano::WalletAccount
@@ -388,7 +383,7 @@ module Banano
388
383
  #
389
384
  # ==== Example:
390
385
  #
391
- # Banano::Protocol.new.wallet.restore(seed) # => Nanook::Wallet
386
+ # Banano::Protocol.new.wallet.restore(seed: seed, accounts: 1) # => Banano::Wallet
392
387
  #
393
388
  # @param seed [String] the wallet seed to restore.
394
389
  # @param accounts [Integer] optionally restore the given number of accounts for the wallet.
@@ -398,7 +393,7 @@ module Banano
398
393
  def restore(seed:, accounts: 0)
399
394
  create
400
395
 
401
- raise Nanook::Error, "Unable to set seed for wallet" unless change_seed(seed)
396
+ raise Banano::Error, "Unable to set seed for wallet" unless change_seed(seed)
402
397
 
403
398
  account.create(accounts) if accounts > 0
404
399
  self
@@ -7,6 +7,8 @@ require 'forwardable'
7
7
  #
8
8
  module Banano
9
9
  class WalletAccount
10
+ attr_accessor :account, :wallet
11
+
10
12
  extend Forwardable
11
13
  # @!method balance(raw: true)
12
14
  # (see Banano::Account#balance)
@@ -128,7 +130,7 @@ module Banano
128
130
  response = rpc(action: :validate_account_number, params: {account: to})
129
131
  raise ArgumentError, "Account address is invalid: #{to}" unless response[:valid] == '1'
130
132
 
131
- raw_amount = raw ? amount : Banano::Unit.ban_to_raw(amount)
133
+ raw_amount = raw ? amount : Banano::Unit.ban_to_raw(amount).to_s
132
134
  # account is called source, so don't use the normal rpc method
133
135
  p = {
134
136
  wallet: @wallet,
@@ -157,20 +159,15 @@ module Banano
157
159
  #
158
160
  # ==== Examples:
159
161
  #
160
- # account.receive # => "9AE2311..."
161
162
  # account.receive("718CC21...") # => "9AE2311..."
162
163
  #
163
- # @param block [String] optional block id of pending payment. If
164
- # not provided, the latest pending payment will be received
164
+ # @param block [String] block id of pending payment.
165
165
  #
166
166
  # @return [String] the receive block id
167
167
  # @return [false] if there was no block to receive
168
- def receive(block = nil)
169
- if block.nil?
170
- _receive_without_block
171
- else
172
- _receive_with_block(block)
173
- end
168
+ def receive(block)
169
+ response = rpc(action: :receive, params: {block: block})[:block]
170
+ response.nil? ? false : response
174
171
  end
175
172
 
176
173
  # Sets the representative for the account.
@@ -198,22 +195,6 @@ module Banano
198
195
 
199
196
  private
200
197
 
201
- def _receive_without_block
202
- # Discover the first pending block
203
- pending_blocks = rpc(action: :pending, params: {account: @account, count: 1})
204
-
205
- return false if pending_blocks[:blocks].empty?
206
-
207
- # Then call receive_with_block as normal
208
- _receive_with_block(pending_blocks[:blocks][0])
209
- end
210
-
211
- # Returns block if successful, otherwise false
212
- def _receive_with_block(block)
213
- response = rpc(action: :receive, params: {block: block})[:block]
214
- response.nil? ? false : response
215
- end
216
-
217
198
  def rpc(action:, params: {})
218
199
  p = {}
219
200
  return p unless @wallet
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: banano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stoyan Zhekov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-21 00:00:00.000000000 Z
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday