raiblocks_rpc 0.3.0 → 0.4.0

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: 1ebc2824ca4cfba5c8d93ff4c0bfd2f07227f010c9cd95d6658cbf516f2d8ab6
4
- data.tar.gz: 41ed59397e6ea7787de9d18c03d7350e6d2541666bd1f1f2b90fd5d3d880f90b
3
+ metadata.gz: 59e7a8aaac7c10d6376abdd0aaf840ff90d8e22d67acffa0a5920ce1e1848e2d
4
+ data.tar.gz: be96b5e6188593865f80507fd92cae0c218790c91a1dbf9fedf13a5a6397c43d
5
5
  SHA512:
6
- metadata.gz: da8e69145e83defd6738c4a2ee2e1cdd747665240d9f1c585963f233ab92c685269bf2e36933166d2a1fb70a97c4cb58ce164d722b512a3ec0e6fc6b9f4b1612
7
- data.tar.gz: 36ddcf6cb3b46c221169751135d7a81e6f163ed3d6ffa082a5846d0315b74f5a9bc24e2c724a6b10fd0a58e4be75096c28e6c314181ff9bb84b0b868b3150c33
6
+ metadata.gz: 9c7482203fbeed536648a9c67b4f07284a0953b774abc6be17ec92159badb2956fb95385c430a4598af2822684b83458e522649d4ac5a669d2fda6c94ee98586
7
+ data.tar.gz: 229ea7d13d2aca576da81fc439d5c47bff6064e388ab2be56962c76e456a10b525d0d72907711d32fd8ac74cc455099aea5da5f50d873b8a74de7f0d7c865070
data/Gemfile CHANGED
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
  gemspec
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # RaiBlocksRpc
1
+ # Raiblocks RPC
2
2
 
3
- An RPC wrapper for RaiBlocks written in Ruby. It connects to an individual node that you control. There's a client object you can use to make explicit RPC calls as well as proxy objects with logically grouped methods.
3
+ An RPC wrapper for RaiBlocks written in Ruby. It connects to an individual node that you control. There's a client object you can use to make explicit RPC calls as well as proxy objects with logically grouped convenience methods.
4
4
 
5
- To run a RaiBlocks node locally, see [Docker documentation](https://github.com/clemahieu/raiblocks/wiki/Docker-node).
5
+ To run a RaiBlocks node locally, see [RaiBlocks Docker Docs](https://github.com/clemahieu/raiblocks/wiki/Docker-node).
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,32 +22,32 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- There are two ways to use this gem. You can make direct calls to the RPC client or use the provided proxy objects.
25
+ There are two ways to use this gem. You can make direct calls to the RPC client using Ruby hashes or you can use proxy objects that provide helper methods for terser code.
26
26
 
27
- In either case, the client should first be configured to connect to a RaiBlocks node and instantiated. If you do not specify host or port, then `localhost:7076` will be used by default.
27
+ ### Raw RPC Calls
28
28
 
29
- ```ruby
30
- client = RaiblocksRpc::Client.new(host: 'myraiblocksnode', port: 1234)
31
- ````
29
+ The RCP client exposes raw Remote Procedure Call methods according to the [RaiBlocks RPC Docs](https://github.com/clemahieu/raiblocks/wiki/RPC-protocol).
32
30
 
33
- If you're just using the default configuration, you can use the shorter
31
+ Every method requires an `action`, which is passed as the first argument to `call`. Depending on the action, there may be additional required or optional parameters that are passed as an options hash.
34
32
 
35
- ```ruby
36
- client = RaiblocksRpc.Client
37
- ````
33
+ First setup the client:
38
34
 
39
- ### Raw RPC Calls
35
+ ```ruby
36
+ # Connect to localhost:7076
37
+ client = Raiblocks.client
40
38
 
41
- You can use the RPC client to make raw RPC calls to a RaiBlocks node according to the [documentation](https://github.com/clemahieu/raiblocks/wiki/RPC-protocol).
39
+ # Connect to custom host
40
+ client = Raiblocks::Client.new(host: 'myraiblocksnode', port: 1234)
41
+ ```
42
42
 
43
- Every call requires an `action`, which is passed as the first argument to `call`. Depending on the action, there may be additional required or optional parameters that are passed as an options hash.
43
+ Then make a `call`, passing the the action and the data:
44
44
 
45
45
  ```ruby
46
46
  client.call(:account_balance, account: 'xrb_someaddress1234')
47
47
  # => {"balance"=>100, "pending"=>0}
48
48
  ````
49
49
 
50
- Response data are provided as `Hashie` objects with integer coercion, indifferent access, and method access included so you have several options for accessing values.
50
+ Response data are provided as `Hashie` objects with integer coercion, indifferent access, and method access so you have several options for accessing returned values.
51
51
 
52
52
  ```ruby
53
53
  data = client.call(:account_balance, account: 'xrb_someaddress1234')
@@ -62,41 +62,71 @@ Response data are provided as `Hashie` objects with integer coercion, indifferen
62
62
 
63
63
  ### Proxy Objects
64
64
 
65
- A few proxy objects are provided as a means to logically group RPC calls. Here we do not strictly follow the grouping as expressed in the [RaiBlocks RPC documentation](https://github.com/clemahieu/raiblocks/wiki/RPC-protocol). Instead, the following objects are provided:
65
+ Proxy objects are provided to ease interaction with the API by providing logically grouped helper methods. Here we do not strictly follow the grouping as expressed in the [RaiBlocks RPC Docs](https://github.com/clemahieu/raiblocks/wiki/RPC-protocol). Instead, the following objects are provided:
66
66
 
67
67
  ```ruby
68
- RaiblocksRpc::Account # { account: 'xrb_address12345' }
69
- RaiblocksRpc::Accounts # { accounts: ['xrb_address12345', 'xrb_address67890] }
70
- RaiblocksRpc::Wallet # { wallet: 'F3093AB' }
71
- RaiblocksRpc::Network
72
- RaiblocksRpc::Node
73
- RaiblocksRpc::Util
68
+ Raiblocks::Account # { account: 'xrb_address12345' }
69
+ Raiblocks::Accounts # { accounts: %w[xrb_address12345 xrb_address67890] }
70
+ Raiblocks::Node
71
+ Raiblocks::Wallet # { wallet: 'F3093AB' }
74
72
  ```
75
73
 
76
- `Account`, `Accounts`, and `Wallet` each require parameters to be passed during initialization. You can then make calls on these objects without needing to pass in the params for subsequent calls.
77
-
78
- Methods whose prefix matches the class name, such as `account_balance`, also have an abbreviated version, in this case `balance`.
79
-
74
+ `Account`, `Accounts`, and `Wallet` each require a single parameter to be passed during initialization. You can then make calls on these objects without needing to pass in the param for subsequent calls. All RPC methods are provided directly as methods.
80
75
 
81
76
  ```ruby
82
- account = RaiblocksRpc::Account.new('xrb_someaddress1234')
77
+ account = Raiblocks::Account.new('xrb_someaddress1234')
83
78
 
84
- account.balance
85
- # => {"balance"=>100, "pending"=>0}
86
79
  account.account_balance
87
80
  # => {"balance"=>100, "pending"=>0}
81
+ account.account_balance.balance
82
+ # 100
83
+ account.balance # Fastest to use #balance helper method
84
+ # 100
85
+ ```
86
+
87
+ You can ask an object what raw RPC methods it provides using `proxy_methods`:
88
+
89
+ ```ruby
90
+ account.proxy_methods
91
+ # => [:account_balance, :account_block_count, :account_create, :account_history, :account_info, :account_key, :account_list, :account_move, :account_remove, :account_representative, :account_representative_set, :account_weight, :accounts_balances, :accounts_create, :accounts_frontiers, :accounts_pending, :delegators, :delegators_count, :frontier_count, :frontiers, :ledger, :payment_wait, :pending, :validate_account_number]
92
+ ```
93
+
94
+ Helper methods are provided for frequently used calls:
95
+
96
+ ```ruby
97
+ Raiblocks::Account.helper_methods
98
+ # => [:balance]
99
+
100
+ Raiblocks::Account.new('xrb_someaddress1234').balance
101
+ # => 250
88
102
  ```
89
103
 
90
- Some methods appear on multiple objects for convenience.
104
+ `Node` methods are provided at both the instance and class levels:
91
105
 
92
106
  ```ruby
93
- RaiblocksRpc::Node.new.block_count
94
- # => {"count"=>314848, "unchecked"=>4793586}
107
+ Raiblocks::Node.version
108
+ # => {"rpc_version"=>1, "store_version"=>10, "node_vendor"=>"RaiBlocks 9.0"}
109
+
110
+ node = Raiblocks::Node.new
111
+ version.rpc_version
112
+ # => 1
113
+ node.peers
114
+ # => {"peers"=>{"[::ffff:2.80.5.202]:64317"=>"5", "[::ffff:2.249.74.58]:7075"=>"5", "[::ffff:5.9.31.82]:7077"=>"4", ... }
115
+ node.available_supply
116
+ # => {"available"=>132596127030666124778600855847014518457}
117
+ node.block_count.unchecked
118
+ # => 4868605
119
+ ```
95
120
 
96
- RaiblocksRpc::Network.new.block_count
97
- # => {"count"=>314848, "unchecked"=>4793642}
121
+ To connect to a custom node, instantiate a client and pass it into the proxy object as `client`:
122
+
123
+ ```ruby
124
+ client = Raiblocks::Client.new(host: 'myraiblocksnode', port: 1234)
125
+ account = Raiblocks::Account.new('xrb_someaddress1234', client: client)
98
126
  ```
99
127
 
128
+ For a more comprehensive guide, see the [Wiki](https://github.com/jcraigk/ruby_raiblocks_rpc/wiki).
129
+
100
130
  ## License
101
131
 
102
132
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/bin/console CHANGED
@@ -2,6 +2,3 @@
2
2
 
3
3
  require 'bundler/setup'
4
4
  require 'raiblocks_rpc'
5
-
6
- require 'pry'
7
- Pry.start
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+ require 'rest-client'
3
+ require 'json'
4
+
5
+ module Raiblocks
6
+ def self.client
7
+ @client ||= Client.new
8
+ end
9
+
10
+ class Client
11
+ attr_accessor :host, :port
12
+
13
+ def initialize(host: 'localhost', port: 7076)
14
+ @host = host
15
+ @port = port
16
+ end
17
+
18
+ def call(action, params = {})
19
+ args = { action: action }
20
+ args.merge!(params) if params.is_a?(Hash)
21
+ post(args)
22
+ end
23
+
24
+ private
25
+
26
+ def post(params)
27
+ response = rest_client_post(url, params)
28
+ ensure_status_success!(response)
29
+
30
+ data = Raiblocks::Response.new(JSON[response.body])
31
+ ensure_valid_response!(data)
32
+
33
+ data
34
+ end
35
+
36
+ def rest_client_post(url, params)
37
+ RestClient.post(url, params.to_json)
38
+ rescue Errno::ECONNREFUSED
39
+ raise Raiblocks::NodeConnectionFailure,
40
+ "Node connection failure at #{url}"
41
+ end
42
+
43
+ def url
44
+ "http://#{host}:#{port}"
45
+ end
46
+
47
+ def ensure_status_success!(response)
48
+ return if response.code == 200
49
+ raise Raiblocks::BadRequest,
50
+ "Error response from node: #{JSON[response.body]}"
51
+ end
52
+
53
+ def ensure_valid_response!(data)
54
+ return unless data['error']
55
+ raise Raiblocks::InvalidRequest,
56
+ "Invalid request: #{data['error']}"
57
+ end
58
+ end
59
+ end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
- module RaiblocksRpc
2
+ module Raiblocks
3
3
  class Error < StandardError; end
4
4
 
5
+ class NodeConnectionFailure < Error; end
5
6
  class BadRequest < Error; end
6
7
  class InvalidRequest < Error; end
7
8
  class InvalidParameterType < Error; end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+ module Raiblocks::AccountProxyHelper
3
+ def balance
4
+ account_balance.balance
5
+ end
6
+
7
+ def block_count
8
+ account_block_count.block_count
9
+ end
10
+
11
+ def create(wallet:, work:)
12
+ account_create(wallet: wallet, work: work).account
13
+ end
14
+
15
+ def history(count:)
16
+ account_history(count: count).history
17
+ end
18
+
19
+ def info
20
+ account_info
21
+ end
22
+
23
+ def key
24
+ account_key.key
25
+ end
26
+
27
+ def list
28
+ account_list.accounts
29
+ end
30
+
31
+ def move(wallet:, source:, accounts:)
32
+ account_move(wallet: wallet, source: source, accounts: accounts).moved == 1
33
+ end
34
+
35
+ def wallet_work(wallet:)
36
+ work_get(wallet: wallet).work
37
+ end
38
+
39
+ def wallet_work_set(wallet:, work:)
40
+ work_set(wallet: wallet, work: work).work[:success] == ''
41
+ end
42
+
43
+ def pending_balance
44
+ account_balance.pending
45
+ end
46
+ alias balance_pending pending_balance
47
+
48
+ def pending_blocks(count:, threshold: nil, exists: nil)
49
+ pending(count: count, threshold: threshold, exists: exists).locks
50
+ end
51
+ alias blocks_pending pending_blocks
52
+
53
+ def remove(wallet:)
54
+ account_remove(wallet: wallet).removed == 1
55
+ end
56
+
57
+ def representative
58
+ account_representative.representative
59
+ end
60
+
61
+ def representative_set(wallet:, representative:)
62
+ account_representative_set(
63
+ wallet: wallet, representative: representative
64
+ ).set == 1
65
+ end
66
+
67
+ def weight
68
+ account_weight.weight
69
+ end
70
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+ module Raiblocks::AccountsProxyHelper
3
+ def frontiers
4
+ accounts_frontiers.frontiers
5
+ end
6
+
7
+ def balances
8
+ accounts_balances.balances
9
+ end
10
+
11
+ def create(wallet:, count:, work: nil)
12
+ accounts_create(wallet: wallet, count: count, work: work).accounts
13
+ end
14
+
15
+ def pending(count:, threshold: nil, source: nil)
16
+ accounts_pending(count: count, threshold: threshold, source: source).blocks
17
+ end
18
+ alias pending_blocks pending
19
+
20
+ # Array-like access for Raiblocks::Account
21
+ def [](idx)
22
+ return unless @addresses[idx]
23
+ @account_objects ||= []
24
+ @account_objects[idx] ||= Raiblocks::Account.new(@addresses[idx])
25
+ end
26
+
27
+ def <<(val)
28
+ @addresses << val
29
+ end
30
+
31
+ def each(&_block)
32
+ @addresses.each do |address|
33
+ yield Raiblocks::Account.new(address)
34
+ end
35
+ end
36
+
37
+ def first
38
+ self[0]
39
+ end
40
+
41
+ def second
42
+ self[1]
43
+ end
44
+
45
+ def third
46
+ self[2]
47
+ end
48
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ module Raiblocks::NodeProxyHelper
3
+ def account_containing_block(hash)
4
+ block_account(hash: hash).account
5
+ end
6
+
7
+ def available
8
+ available_supply.available
9
+ end
10
+
11
+ def krai_from(amount:)
12
+ krai_from_raw(amount: amount).amount
13
+ end
14
+
15
+ def krai_to(amount:)
16
+ krai_to_raw(amount: amount).amount
17
+ end
18
+
19
+ def mrai_from(amount:)
20
+ mrai_from_raw(amount: amount).amount
21
+ end
22
+
23
+ def mrai_to(amount:)
24
+ mrai_to_raw(amount: amount).amount
25
+ end
26
+
27
+ def pending_exists?(hash:)
28
+ pending_exists(hash: hash).exists == 1
29
+ end
30
+
31
+ def rai_from(amount:)
32
+ rai_from_raw(amount: amount).amount
33
+ end
34
+
35
+ def rai_to(amount:)
36
+ rai_to_raw(amount: amount).amount
37
+ end
38
+
39
+ def work_valid?(work:, hash:)
40
+ work_validate(work: work, hash: hash).valid == 1
41
+ end
42
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+ module Raiblocks::WalletProxyHelper
3
+ def account_work(account:)
4
+ work_get.work(account: account).work
5
+ end
6
+
7
+ def add(key:, work: nil)
8
+ wallet_add(key: key, work: work).account
9
+ end
10
+
11
+ def balance
12
+ wallet_balance_total.balance
13
+ end
14
+
15
+ def balances(threshold: nil)
16
+ wallet_balances(threshold: threshold).balances
17
+ end
18
+
19
+ def begin_payment
20
+ payment_begin.account
21
+ end
22
+
23
+ def change_password(new_password:)
24
+ password_change(password: new_password).changed == 1
25
+ end
26
+
27
+ def change_seed(new_seed:)
28
+ wallet_change_seed(seed: new_seed)[:success] == ''
29
+ end
30
+
31
+ def contains?(account:)
32
+ wallet_contains(account: account).exists == 1
33
+ end
34
+
35
+ def create
36
+ wallet_create.wallet
37
+ end
38
+
39
+ def destroy
40
+ wallet_destroy
41
+ end
42
+
43
+ def enter_password(password)
44
+ password_enter(password: password).valid == 1
45
+ end
46
+
47
+ def export
48
+ JSON[wallet_export.json]
49
+ end
50
+
51
+ def frontiers
52
+ wallet_frontiers.frontiers
53
+ end
54
+
55
+ def init_payment
56
+ payment_init.status == 'Ready'
57
+ end
58
+
59
+ def locked?
60
+ wallet_locked.locked == 1
61
+ end
62
+
63
+ def password_valid?(password:)
64
+ password_valid(password: password).valid == 1
65
+ end
66
+
67
+ def pending_balance
68
+ wallet_balance_total.pending
69
+ end
70
+
71
+ def pending_blocks(count:, threshold: nil, source: nil)
72
+ wallet_pending(count: count, threshold: threshold, source: source).blocks
73
+ end
74
+
75
+ def receive_block(account:, block:)
76
+ receive.block(account: account, block: block).block
77
+ end
78
+
79
+ def representative
80
+ wallet_representative.representative
81
+ end
82
+
83
+ def republish(count:)
84
+ wallet_republish(count: count).blocks
85
+ end
86
+
87
+ def account_work_set(account:, work:)
88
+ work_set(account: account, work: work).work[:success] == ''
89
+ end
90
+ alias set_account_work account_work_set
91
+
92
+ def representative_set(representative:)
93
+ wallet_representative_set(representative: representative).set == 1
94
+ end
95
+ alias set_representative representative_set
96
+
97
+ def send_tx(source:, destination:, amount:)
98
+ rai_send(source: source, destination: destination, amount: amount).block
99
+ end
100
+ alias send_transaction send_tx
101
+
102
+ def work
103
+ wallet_work_get.works
104
+ end
105
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ class Raiblocks::Account
3
+ include Raiblocks::Proxy
4
+ include Raiblocks::AccountProxyHelper
5
+
6
+ attr_accessor :address
7
+
8
+ def initialize(address = nil, opts = {})
9
+ unless address.is_a?(String)
10
+ raise Raiblocks::MissingParameters,
11
+ 'Missing argument: address (str)'
12
+ end
13
+
14
+ @address = address
15
+ @client = opts[:client] || Raiblocks.client
16
+ end
17
+
18
+ proxy_params account: :address
19
+
20
+ proxy_method :account_balance
21
+ proxy_method :account_block_count
22
+ proxy_method :account_info
23
+ proxy_method :account_create, required: %i[wallet], optional: %i[work]
24
+ proxy_method :account_history, required: %i[count]
25
+ proxy_method :account_list
26
+ proxy_method :account_move, required: %i[wallet source accounts]
27
+ proxy_method :account_key
28
+ proxy_method :account_remove, required: %i[wallet]
29
+ proxy_method :account_representative
30
+ proxy_method :account_representative_set, required: %i[wallet representative]
31
+ proxy_method :account_weight
32
+ proxy_method :delegators
33
+ proxy_method :delegators_count
34
+ proxy_method :frontiers, required: %i[count]
35
+ proxy_method :frontier_count
36
+ proxy_method :ledger,
37
+ required: %i[count],
38
+ optional: %i[representative weight pending sorting]
39
+ proxy_method :validate_account_number
40
+ proxy_method :pending, required: %i[count], optional: %i[threshold exists]
41
+ proxy_method :payment_wait, required: %i[amount timeout]
42
+ proxy_method :work_get
43
+ proxy_method :work_set
44
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ class Raiblocks::Accounts
3
+ include Raiblocks::Proxy
4
+ include Raiblocks::AccountsProxyHelper
5
+
6
+ attr_accessor :addresses
7
+
8
+ def initialize(addresses = nil, client = nil)
9
+ unless addresses.is_a?(Array)
10
+ raise Raiblocks::MissingParameters,
11
+ 'Missing argument: addresses (str[])'
12
+ end
13
+
14
+ @addresses = addresses
15
+ @client = client || Raiblocks.client
16
+ end
17
+
18
+ proxy_params accounts: :addresses
19
+
20
+ proxy_method :accounts_balances
21
+ proxy_method :accounts_create, required: %i[wallet count], optional: %i[work]
22
+ proxy_method :accounts_frontiers
23
+ proxy_method :accounts_pending,
24
+ required: %i[count], optional: %i[threshold source]
25
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ class Raiblocks::Node
3
+ include Raiblocks::Proxy
4
+ include Raiblocks::NodeProxyHelper
5
+
6
+ proxy_method :available_supply
7
+ proxy_method :block, required: %i[hash]
8
+ proxy_method :block_account, required: %i[hash]
9
+ proxy_method :block_count
10
+ proxy_method :block_count_type
11
+ proxy_method :block_create,
12
+ required: %i[type key representative source], optional: %i[work]
13
+ proxy_method :blocks, required: %i[hashes]
14
+ proxy_method :blocks_info,
15
+ required: %i[hashes], optional: %i[pending source]
16
+ proxy_method :bootstrap, required: %i[address port]
17
+ proxy_method :bootstrap_any
18
+ proxy_method :chain, required: %i[block count]
19
+ proxy_method :deterministic_key, required: %i[seed index]
20
+ proxy_method :history, required: %i[hash count]
21
+ proxy_method :keepalive, required: %i[address port]
22
+ proxy_method :key_create
23
+ proxy_method :key_expand, required: %i[key]
24
+ proxy_method :krai_from_raw, required: %i[amount]
25
+ proxy_method :krai_to_raw, required: %i[amount]
26
+ proxy_method :mrai_from_raw, required: %i[amount]
27
+ proxy_method :mrai_to_raw, required: %i[amount]
28
+ proxy_method :payment_wait, required: %i[account amount timeout]
29
+ proxy_method :peers
30
+ proxy_method :pending_exists, required: %i[hash]
31
+ proxy_method :process, required: %i[block]
32
+ proxy_method :rai_from_raw, required: %i[amount]
33
+ proxy_method :rai_to_raw, required: %i[amount]
34
+ proxy_method :receive_minimum
35
+ proxy_method :receive_minimum_set, required: %i[amount]
36
+ proxy_method :representatives
37
+ proxy_method :republish,
38
+ required: %i[hash],
39
+ optional: %i[count sources destinations]
40
+ proxy_method :search_pending, required: %i[wallet]
41
+ proxy_method :search_pending_all
42
+ proxy_method :stop
43
+ proxy_method :successors, required: %i[block count]
44
+ proxy_method :unchecked, required: %i[count]
45
+ proxy_method :unchecked_clear
46
+ proxy_method :unchecked_get, required: %i[hash]
47
+ proxy_method :unchecked_keys, required: %i[key count]
48
+ proxy_method :version
49
+ proxy_method :work_cancel, required: %i[hash]
50
+ proxy_method :work_generate, required: %i[hash]
51
+ proxy_method :work_peer_add, required: %i[address port]
52
+ proxy_method :work_peers
53
+ proxy_method :work_peers_clear
54
+ proxy_method :work_validate, required: %i[work hash]
55
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+ class Raiblocks::Wallet
3
+ include Raiblocks::Proxy
4
+ include Raiblocks::WalletProxyHelper
5
+
6
+ attr_accessor :seed
7
+
8
+ def initialize(wallet_seed = nil, opts = {})
9
+ unless wallet_seed.is_a?(String)
10
+ raise Raiblocks::MissingParameters,
11
+ 'Missing argument: address (str)'
12
+ end
13
+
14
+ @seed = wallet_seed
15
+ @client = opts[:client] || Raiblocks.client
16
+ end
17
+
18
+ proxy_params wallet: :seed
19
+
20
+ proxy_method :wallet_add, required: %i[key], optional: %i[work]
21
+ proxy_method :wallet_balance_total
22
+ proxy_method :wallet_balances, optional: %i[threshold]
23
+ proxy_method :wallet_change_seed, required: %i[seed]
24
+ proxy_method :wallet_contains, required: %i[account]
25
+ proxy_method :wallet_create
26
+ proxy_method :wallet_destroy
27
+ proxy_method :wallet_export
28
+ proxy_method :wallet_frontiers
29
+ proxy_method :wallet_locked
30
+ proxy_method :wallet_pending,
31
+ required: %i[count], optional: %i[threshold source]
32
+ proxy_method :wallet_representative
33
+ proxy_method :wallet_representative_set, required: %i[representative]
34
+ proxy_method :wallet_republish, required: %i[count]
35
+ proxy_method :wallet_work_get
36
+ proxy_method :work_get
37
+ proxy_method :work_set
38
+ proxy_method :password_change, required: %i[password]
39
+ proxy_method :password_enter, required: %i[password]
40
+ proxy_method :password_valid
41
+ proxy_method :payment_begin
42
+ proxy_method :payment_init
43
+ proxy_method :payment_end, required: %i[account]
44
+ proxy_method :receive, required: %i[account block]
45
+ proxy_method :send, required: %i[wallet source destination amount]
46
+ proxy_method :search_pending
47
+ end