nano_rpc 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -14
- data/lib/nano/helpers/account_proxy_helper.rb +29 -23
- data/lib/nano/helpers/accounts_proxy_helper.rb +19 -4
- data/lib/nano/helpers/application_helper.rb +8 -0
- data/lib/nano/helpers/node_proxy_helper.rb +32 -16
- data/lib/nano/helpers/wallet_proxy_helper.rb +85 -27
- data/lib/nano/proxies/account.rb +1 -2
- data/lib/nano/proxies/accounts.rb +3 -2
- data/lib/nano/proxies/node.rb +1 -0
- data/lib/nano/proxies/wallet.rb +9 -6
- data/lib/nano/proxy.rb +8 -11
- data/lib/nano/proxy_context.rb +0 -12
- data/lib/nano/response.rb +7 -1
- data/lib/nano/version.rb +1 -1
- data/lib/nano_rpc.rb +1 -0
- data/nano_rpc.gemspec +3 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5505de736e20d672bed90df3856fef48148882a3726f27bb10fa03eb2db5e4b0
|
4
|
+
data.tar.gz: 20a28a63f524ecc1af9a2a94f91b724b5996b767ba35202a7416841ffd98aac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61056e815bf6a31ccb9dbacc4581b4fd99ee9769fba6251c5f84da884f1bb9d430604a09fb053b4a21613e9b318b81f40c9950f1fc718d5bd4ff2656cf60f703
|
7
|
+
data.tar.gz: 03e4d60c84c306ebe878c527d00a3084b083de0e788795995dc0f0d2459f6a48b6e6c49f7a0e4474baaa2f81f9d727bbf9cad9ac0c170b3a03ef004e933d1cf8
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Nano RPC
|
2
2
|
|
3
|
-
An RPC wrapper for Nano
|
3
|
+
An RPC wrapper for Nano digitial currency nodes. Arbitrary RPC access is provided along with proxy objects that expose helper methods ([Wiki](https://github.com/jcraigk/ruby_nano_rpc/wiki/Proxy-Object-Reference)).
|
4
4
|
|
5
5
|
To run a Nano node locally, see [Nano Docker Docs](https://github.com/clemahieu/raiblocks/wiki/Docker-node).
|
6
6
|
|
@@ -65,10 +65,10 @@ Response data are provided as [Hashie](https://github.com/intridea/hashie) objec
|
|
65
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 [Nano RPC Docs](https://github.com/clemahieu/raiblocks/wiki/RPC-protocol). Instead, the following objects are provided:
|
66
66
|
|
67
67
|
```ruby
|
68
|
-
Nano::Account
|
69
|
-
Nano::Accounts
|
68
|
+
Nano::Account
|
69
|
+
Nano::Accounts
|
70
70
|
Nano::Node
|
71
|
-
Nano::Wallet
|
71
|
+
Nano::Wallet
|
72
72
|
```
|
73
73
|
|
74
74
|
`Account`, `Accounts`, and `Wallet` each require a single parameter to be passed during initialization. This parameter is persisted for subsequent calls. All RPC methods are provided directly as methods.
|
@@ -99,13 +99,6 @@ There are also helper methods for terser code:
|
|
99
99
|
# 0
|
100
100
|
```
|
101
101
|
|
102
|
-
You can ask an object what helper methods it provides using `helper_methods` (coming soon):
|
103
|
-
|
104
|
-
```ruby
|
105
|
-
account.helper_methods
|
106
|
-
# => [:balance, :pending_balance, ...]
|
107
|
-
```
|
108
|
-
|
109
102
|
`Node` methods are provided at both the instance and class levels:
|
110
103
|
|
111
104
|
```ruby
|
@@ -113,17 +106,19 @@ You can ask an object what helper methods it provides using `helper_methods` (co
|
|
113
106
|
# => {"rpc_version"=>1, "store_version"=>10, "node_vendor"=>"RaiBlocks 9.0"}
|
114
107
|
|
115
108
|
node = Nano::Node.new
|
116
|
-
version.rpc_version
|
109
|
+
node.version.rpc_version
|
117
110
|
# => 1
|
118
111
|
node.peers
|
119
|
-
# => {"
|
112
|
+
# => {"[::ffff:2.80.5.202]:64317"=>"5", "[::ffff:2.249.74.58]:7075"=>"5", "[::ffff:5.9.31.82]:7077"=>"4", ... }
|
120
113
|
node.available_supply
|
121
114
|
# => {"available"=>132596127030666124778600855847014518457}
|
115
|
+
node.available
|
116
|
+
# => 132596127030666124778600855847014518457
|
122
117
|
node.block_count.unchecked
|
123
118
|
# => 4868605
|
124
119
|
```
|
125
120
|
|
126
|
-
|
121
|
+
You can point each proxy object at its own node by passing a custom client in:
|
127
122
|
|
128
123
|
```ruby
|
129
124
|
client = Nano::Client.new(host: 'mynanonode', port: 1234)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Nano::AccountProxyHelper
|
3
|
+
include Nano::ApplicationHelper
|
4
|
+
|
3
5
|
def balance
|
4
6
|
account_balance.balance
|
5
7
|
end
|
@@ -8,12 +10,10 @@ module Nano::AccountProxyHelper
|
|
8
10
|
account_block_count.block_count
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def history(count:)
|
16
|
-
account_history(count: count).history
|
13
|
+
def history(opts)
|
14
|
+
account_history(
|
15
|
+
count: opts_pluck(opts, :count)
|
16
|
+
).history
|
17
17
|
end
|
18
18
|
|
19
19
|
def info
|
@@ -21,23 +21,22 @@ module Nano::AccountProxyHelper
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def key
|
24
|
-
account_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
|
24
|
+
account_key['key']
|
33
25
|
end
|
34
26
|
|
35
|
-
def
|
36
|
-
|
27
|
+
def move(from:, to:)
|
28
|
+
account_move(
|
29
|
+
wallet: to,
|
30
|
+
source: from,
|
31
|
+
accounts: [address]
|
32
|
+
).moved == 1
|
37
33
|
end
|
38
34
|
|
39
35
|
def wallet_work_set(wallet:, work:)
|
40
|
-
work_set(
|
36
|
+
work_set(
|
37
|
+
wallet: wallet,
|
38
|
+
work: work
|
39
|
+
).success == ''
|
41
40
|
end
|
42
41
|
|
43
42
|
def pending_balance
|
@@ -45,13 +44,19 @@ module Nano::AccountProxyHelper
|
|
45
44
|
end
|
46
45
|
alias balance_pending pending_balance
|
47
46
|
|
48
|
-
def pending_blocks(count:, threshold: nil,
|
49
|
-
pending(
|
47
|
+
def pending_blocks(count:, threshold: nil, source: nil)
|
48
|
+
pending(
|
49
|
+
count: count,
|
50
|
+
threshold: threshold,
|
51
|
+
source: source
|
52
|
+
).blocks
|
50
53
|
end
|
51
54
|
alias blocks_pending pending_blocks
|
52
55
|
|
53
|
-
def remove(
|
54
|
-
account_remove(
|
56
|
+
def remove(opts)
|
57
|
+
account_remove(
|
58
|
+
wallet: opts_pluck(opts, :wallet)
|
59
|
+
).removed == 1
|
55
60
|
end
|
56
61
|
|
57
62
|
def representative
|
@@ -60,7 +65,8 @@ module Nano::AccountProxyHelper
|
|
60
65
|
|
61
66
|
def representative_set(wallet:, representative:)
|
62
67
|
account_representative_set(
|
63
|
-
wallet: wallet,
|
68
|
+
wallet: wallet,
|
69
|
+
representative: representative
|
64
70
|
).set == 1
|
65
71
|
end
|
66
72
|
|
@@ -1,19 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Nano::AccountsProxyHelper
|
3
3
|
def balances
|
4
|
-
accounts_balances
|
4
|
+
accounts_balances
|
5
|
+
.balances
|
6
|
+
.each_with_object({}) do |(k, v), hash|
|
7
|
+
hash[k] = v['balance']
|
8
|
+
end
|
5
9
|
end
|
6
10
|
|
7
|
-
def
|
8
|
-
|
11
|
+
def pending_balances
|
12
|
+
accounts_balances
|
13
|
+
.balances
|
14
|
+
.each_with_object({}) do |(k, v), hash|
|
15
|
+
hash[k] = v['pending']
|
16
|
+
end
|
9
17
|
end
|
18
|
+
alias balances_pending pending_balances
|
10
19
|
|
11
20
|
def frontiers
|
12
21
|
accounts_frontiers.frontiers
|
13
22
|
end
|
14
23
|
|
24
|
+
def move(from:, to:)
|
25
|
+
account_move(wallet: to, source: from).moved == 1
|
26
|
+
end
|
27
|
+
|
15
28
|
def pending(count:, threshold: nil, source: nil)
|
16
|
-
accounts_pending(
|
29
|
+
accounts_pending(
|
30
|
+
count: count, threshold: threshold, source: source
|
31
|
+
).blocks
|
17
32
|
end
|
18
33
|
alias pending_blocks pending
|
19
34
|
|
@@ -1,42 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Nano::NodeProxyHelper
|
3
|
-
|
4
|
-
|
3
|
+
include Nano::ApplicationHelper
|
4
|
+
|
5
|
+
def account_containing_block(opts)
|
6
|
+
block_account(opts_hash(opts)).account
|
5
7
|
end
|
6
8
|
|
7
9
|
def available
|
8
10
|
available_supply.available
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
12
|
-
|
13
|
+
def create_wallet
|
14
|
+
Nano::Wallet.new(wallet_create.wallet)
|
15
|
+
end
|
16
|
+
|
17
|
+
def krai_from(opts)
|
18
|
+
krai_from_raw(opts_amount(opts)).amount
|
13
19
|
end
|
14
20
|
|
15
|
-
def krai_to(
|
16
|
-
krai_to_raw(
|
21
|
+
def krai_to(opts)
|
22
|
+
krai_to_raw(opts_amount(opts)).amount
|
17
23
|
end
|
18
24
|
|
19
|
-
def mrai_from(
|
20
|
-
mrai_from_raw(
|
25
|
+
def mrai_from(opts)
|
26
|
+
mrai_from_raw(opts_amount(opts)).amount
|
21
27
|
end
|
22
28
|
|
23
|
-
def mrai_to(
|
24
|
-
mrai_to_raw(
|
29
|
+
def mrai_to(opts)
|
30
|
+
mrai_to_raw(opts_amount(opts)).amount
|
25
31
|
end
|
26
32
|
|
27
|
-
def pending_exists?(
|
28
|
-
pending_exists(
|
33
|
+
def pending_exists?(opts)
|
34
|
+
pending_exists(opts_hash(opts)).exists == 1
|
29
35
|
end
|
30
36
|
|
31
|
-
def rai_from(
|
32
|
-
rai_from_raw(
|
37
|
+
def rai_from(opts)
|
38
|
+
rai_from_raw(opts_amount(opts)).amount
|
33
39
|
end
|
34
40
|
|
35
|
-
def rai_to(
|
36
|
-
rai_to_raw(
|
41
|
+
def rai_to(opts)
|
42
|
+
rai_to_raw(opts_amount(opts)).amount
|
37
43
|
end
|
38
44
|
|
39
45
|
def work_valid?(work:, hash:)
|
40
46
|
work_validate(work: work, hash: hash).valid == 1
|
41
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def opts_amount(opts)
|
52
|
+
{ amount: opts_pluck(opts, :amount) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def opts_hash(opts)
|
56
|
+
{ hash: opts_pluck(opts, :hash) }
|
57
|
+
end
|
42
58
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Nano::WalletProxyHelper
|
3
|
-
|
4
|
-
|
3
|
+
include Nano::ApplicationHelper
|
4
|
+
|
5
|
+
def account_work(opts)
|
6
|
+
work_get(opts_account(opts)).work
|
5
7
|
end
|
6
8
|
|
7
|
-
def
|
9
|
+
def add_key(key:, work: true)
|
8
10
|
wallet_add(key: key, work: work).account
|
9
11
|
end
|
10
12
|
|
@@ -13,39 +15,53 @@ module Nano::WalletProxyHelper
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def balances(threshold: nil)
|
16
|
-
wallet_balances(threshold: threshold)
|
18
|
+
wallet_balances(threshold: threshold)
|
19
|
+
.balances
|
20
|
+
.each_with_object({}) do |(k, v), hash|
|
21
|
+
hash[k] = v['balance'].to_i
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
def begin_payment
|
20
26
|
payment_begin.account
|
21
27
|
end
|
22
28
|
|
23
|
-
def change_password(
|
24
|
-
password_change(
|
29
|
+
def change_password(opts)
|
30
|
+
password_change(
|
31
|
+
password: opts_pluck(opts, :new_password)
|
32
|
+
).changed == 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def change_seed(opts)
|
36
|
+
wallet_change_seed(
|
37
|
+
seed: opts_pluck(opts, :new_seed)
|
38
|
+
).success == ''
|
25
39
|
end
|
26
40
|
|
27
|
-
def
|
28
|
-
|
41
|
+
def contains?(opts)
|
42
|
+
wallet_contains(opts_account(opts)).exists == 1
|
29
43
|
end
|
30
44
|
|
31
|
-
def
|
32
|
-
|
45
|
+
def create_account(work: true)
|
46
|
+
account_create(work: work).account
|
33
47
|
end
|
34
48
|
|
35
|
-
def
|
36
|
-
|
49
|
+
def create_accounts(count:, work: true)
|
50
|
+
accounts_create(count: count, work: work).accounts
|
37
51
|
end
|
38
52
|
|
39
53
|
def destroy
|
40
54
|
wallet_destroy
|
41
55
|
end
|
42
56
|
|
43
|
-
def enter_password(
|
44
|
-
password_enter(
|
57
|
+
def enter_password(opts)
|
58
|
+
password_enter(
|
59
|
+
password: opts_pluck(opts, :password)
|
60
|
+
).valid == 1
|
45
61
|
end
|
46
62
|
|
47
63
|
def export
|
48
|
-
JSON[wallet_export.json]
|
64
|
+
Nano::Response.new(JSON[wallet_export.json])
|
49
65
|
end
|
50
66
|
|
51
67
|
def frontiers
|
@@ -60,46 +76,88 @@ module Nano::WalletProxyHelper
|
|
60
76
|
wallet_locked.locked == 1
|
61
77
|
end
|
62
78
|
|
63
|
-
def
|
64
|
-
|
79
|
+
def move_accounts(to:, accounts:)
|
80
|
+
account_move(
|
81
|
+
wallet: to,
|
82
|
+
source: seed,
|
83
|
+
accounts: accounts
|
84
|
+
).moved == 1
|
85
|
+
end
|
86
|
+
|
87
|
+
def password_valid?(opts)
|
88
|
+
password_valid(
|
89
|
+
password: opts_pluck(opts, :password)
|
90
|
+
).valid == 1
|
65
91
|
end
|
66
92
|
|
67
93
|
def pending_balance
|
68
94
|
wallet_balance_total.pending
|
69
95
|
end
|
96
|
+
alias balance_pending pending_balance
|
97
|
+
|
98
|
+
def pending_balances(threshold: nil)
|
99
|
+
wallet_balances(threshold: threshold)
|
100
|
+
.balances
|
101
|
+
.each_with_object({}) do |(k, v), hash|
|
102
|
+
hash[k] = v['pending'].to_i
|
103
|
+
end
|
104
|
+
end
|
105
|
+
alias balances_pending pending_balances
|
70
106
|
|
71
107
|
def pending_blocks(count:, threshold: nil, source: nil)
|
72
|
-
wallet_pending(
|
108
|
+
wallet_pending(
|
109
|
+
count: count,
|
110
|
+
threshold: threshold,
|
111
|
+
source: source
|
112
|
+
).blocks
|
73
113
|
end
|
114
|
+
alias blocks_pending pending_blocks
|
74
115
|
|
75
116
|
def receive_block(account:, block:)
|
76
|
-
receive
|
117
|
+
receive(account: account, block: block).block
|
118
|
+
end
|
119
|
+
|
120
|
+
def remove_account(opts)
|
121
|
+
account_remove(opts_account(opts)).removed == 1
|
77
122
|
end
|
78
123
|
|
79
124
|
def representative
|
80
125
|
wallet_representative.representative
|
81
126
|
end
|
82
127
|
|
83
|
-
def republish(
|
84
|
-
wallet_republish(count: count).blocks
|
128
|
+
def republish(opts)
|
129
|
+
wallet_republish(count: opts_pluck(opts, :count)).blocks
|
85
130
|
end
|
86
131
|
|
87
132
|
def account_work_set(account:, work:)
|
88
|
-
work_set(account: account, work: work).
|
133
|
+
work_set(account: account, work: work).success == ''
|
89
134
|
end
|
90
135
|
alias set_account_work account_work_set
|
91
136
|
|
92
|
-
def representative_set(
|
93
|
-
wallet_representative_set(
|
137
|
+
def representative_set(opts)
|
138
|
+
wallet_representative_set(
|
139
|
+
representative: opts_pluck(opts, :representative)
|
140
|
+
).set == 1
|
94
141
|
end
|
95
142
|
alias set_representative representative_set
|
96
143
|
|
97
|
-
def
|
98
|
-
|
144
|
+
def send_nano(from:, to:, amount:, work: nil)
|
145
|
+
send_currency(
|
146
|
+
source: from,
|
147
|
+
destination: to,
|
148
|
+
amount: amount,
|
149
|
+
work: work
|
150
|
+
).block
|
99
151
|
end
|
100
|
-
alias send_transaction
|
152
|
+
alias send_transaction send_nano
|
101
153
|
|
102
154
|
def work
|
103
155
|
wallet_work_get.works
|
104
156
|
end
|
157
|
+
|
158
|
+
private
|
159
|
+
|
160
|
+
def opts_account(opts)
|
161
|
+
{ account: opts_pluck(opts, :account) }
|
162
|
+
end
|
105
163
|
end
|
data/lib/nano/proxies/account.rb
CHANGED
@@ -12,7 +12,7 @@ class Nano::Account
|
|
12
12
|
end
|
13
13
|
|
14
14
|
@address = address
|
15
|
-
|
15
|
+
super(opts)
|
16
16
|
end
|
17
17
|
|
18
18
|
proxy_params account: :address
|
@@ -22,7 +22,6 @@ class Nano::Account
|
|
22
22
|
proxy_method :account_info
|
23
23
|
proxy_method :account_create, required: %i[wallet], optional: %i[work]
|
24
24
|
proxy_method :account_history, required: %i[count]
|
25
|
-
proxy_method :account_list
|
26
25
|
proxy_method :account_move, required: %i[wallet source accounts]
|
27
26
|
proxy_method :account_key
|
28
27
|
proxy_method :account_remove, required: %i[wallet]
|
@@ -5,18 +5,19 @@ class Nano::Accounts
|
|
5
5
|
|
6
6
|
attr_accessor :addresses
|
7
7
|
|
8
|
-
def initialize(addresses = nil,
|
8
|
+
def initialize(addresses = nil, opts = {})
|
9
9
|
unless addresses.is_a?(Array)
|
10
10
|
raise Nano::MissingParameters,
|
11
11
|
'Missing argument: addresses (str[])'
|
12
12
|
end
|
13
13
|
|
14
14
|
@addresses = addresses
|
15
|
-
|
15
|
+
super(opts)
|
16
16
|
end
|
17
17
|
|
18
18
|
proxy_params accounts: :addresses
|
19
19
|
|
20
|
+
proxy_method :account_move, required: %i[wallet source]
|
20
21
|
proxy_method :accounts_balances
|
21
22
|
proxy_method :accounts_create, required: %i[wallet count], optional: %i[work]
|
22
23
|
proxy_method :accounts_frontiers
|
data/lib/nano/proxies/node.rb
CHANGED
@@ -46,6 +46,7 @@ class Nano::Node
|
|
46
46
|
proxy_method :unchecked_get, required: %i[hash]
|
47
47
|
proxy_method :unchecked_keys, required: %i[key count]
|
48
48
|
proxy_method :version
|
49
|
+
proxy_method :wallet_create
|
49
50
|
proxy_method :work_cancel, required: %i[hash]
|
50
51
|
proxy_method :work_generate, required: %i[hash]
|
51
52
|
proxy_method :work_peer_add, required: %i[address port]
|
data/lib/nano/proxies/wallet.rb
CHANGED
@@ -5,25 +5,29 @@ class Nano::Wallet
|
|
5
5
|
|
6
6
|
attr_accessor :seed
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
unless
|
8
|
+
def initialize(seed = nil, opts = {})
|
9
|
+
unless seed.is_a?(String)
|
10
10
|
raise Nano::MissingParameters,
|
11
11
|
'Missing argument: address (str)'
|
12
12
|
end
|
13
13
|
|
14
|
-
@seed =
|
15
|
-
|
14
|
+
@seed = seed
|
15
|
+
super(opts)
|
16
16
|
end
|
17
17
|
|
18
18
|
proxy_params wallet: :seed
|
19
19
|
|
20
|
+
proxy_method :account_create, optional: %i[work]
|
21
|
+
proxy_method :accounts_create, required: %i[count], optional: %i[work]
|
22
|
+
proxy_method :account_list
|
23
|
+
proxy_method :account_remove, required: %i[account]
|
20
24
|
proxy_method :password_change, required: %i[password]
|
21
25
|
proxy_method :password_enter, required: %i[password]
|
22
26
|
proxy_method :password_valid
|
23
27
|
proxy_method :payment_begin
|
24
28
|
proxy_method :payment_init
|
25
29
|
proxy_method :payment_end, required: %i[account]
|
26
|
-
proxy_method :receive, required: %i[account block]
|
30
|
+
proxy_method :receive, required: %i[account block], optional: %i[work]
|
27
31
|
proxy_method :send, required: %i[wallet source destination amount]
|
28
32
|
proxy_method :search_pending
|
29
33
|
proxy_method :wallet_add, required: %i[key], optional: %i[work]
|
@@ -31,7 +35,6 @@ class Nano::Wallet
|
|
31
35
|
proxy_method :wallet_balances, optional: %i[threshold]
|
32
36
|
proxy_method :wallet_change_seed, required: %i[seed]
|
33
37
|
proxy_method :wallet_contains, required: %i[account]
|
34
|
-
proxy_method :wallet_create
|
35
38
|
proxy_method :wallet_destroy
|
36
39
|
proxy_method :wallet_export
|
37
40
|
proxy_method :wallet_frontiers
|
data/lib/nano/proxy.rb
CHANGED
@@ -30,23 +30,25 @@ module Nano::Proxy
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def define_proxy_method(m, singleton = false)
|
33
|
-
send(
|
34
|
-
singleton ? :define_singleton_method : :define_method,
|
35
|
-
method_alias(m)
|
36
|
-
) do |opts = {}|
|
33
|
+
send(method_style(singleton), method_alias(m)) do |opts = {}|
|
37
34
|
params = Nano::ProxyContext.new(
|
38
35
|
singleton ? self : self.class, m, opts
|
39
36
|
).populate_params(singleton ? nil : base_params)
|
40
|
-
data = Nano.client.call(m, params)
|
37
|
+
data = (singleton ? Nano.client : @client).call(m, params)
|
38
|
+
# If single-key response matches method name, expose nested data
|
41
39
|
data.is_a?(Hash) && data.keys.map(&:to_s) == [m.to_s] ? data[m] : data
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
45
43
|
private
|
46
44
|
|
45
|
+
def method_style(singleton)
|
46
|
+
singleton ? :define_singleton_method : :define_method
|
47
|
+
end
|
48
|
+
|
47
49
|
# Nano `send` action is also the method caller in Ruby ;)
|
48
50
|
def method_alias(m)
|
49
|
-
m == :send ? :
|
51
|
+
m == :send ? :send_currency : m
|
50
52
|
end
|
51
53
|
|
52
54
|
def method_missing(m, *args, &_block)
|
@@ -62,11 +64,6 @@ module Nano::Proxy
|
|
62
64
|
def valid_method?(m)
|
63
65
|
proxy_param_def.nil? && methods.include?(m)
|
64
66
|
end
|
65
|
-
|
66
|
-
def proxy_context(m)
|
67
|
-
@proxy_context ||= {}
|
68
|
-
@proxy_context[m] ||= Nano::ProxyContext.new(self, m)
|
69
|
-
end
|
70
67
|
end
|
71
68
|
|
72
69
|
def proxy_methods
|
data/lib/nano/proxy_context.rb
CHANGED
@@ -8,10 +8,6 @@ class Nano::ProxyContext
|
|
8
8
|
@opts = opts
|
9
9
|
end
|
10
10
|
|
11
|
-
def valid_proxy_method?
|
12
|
-
rpc_action?
|
13
|
-
end
|
14
|
-
|
15
11
|
def populate_params(params)
|
16
12
|
opts = validate_opts!
|
17
13
|
opts.merge!(params) if params
|
@@ -69,12 +65,4 @@ class Nano::ProxyContext
|
|
69
65
|
def base_param_keys
|
70
66
|
@param_def.is_a?(Hash) ? @param_def.keys : []
|
71
67
|
end
|
72
|
-
|
73
|
-
def method_expansion
|
74
|
-
"#{action_prefix}#{@m}"
|
75
|
-
end
|
76
|
-
|
77
|
-
def action_prefix
|
78
|
-
@klass.name.split('::').last.downcase + '_'
|
79
|
-
end
|
80
68
|
end
|
data/lib/nano/response.rb
CHANGED
@@ -18,8 +18,14 @@ class Nano::Response < Hash
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_f_or_i_or_s(v)
|
21
|
+
return if v.nil?
|
22
|
+
return v.to_i if big_integer?(v)
|
21
23
|
(float = Float(v)) && (float % 1.0).zero? ? float.to_i : float
|
22
|
-
rescue ArgumentError,
|
24
|
+
rescue ArgumentError, TypeError
|
23
25
|
v
|
24
26
|
end
|
27
|
+
|
28
|
+
def big_integer?(v)
|
29
|
+
v.respond_to?(:to_i) && v.to_i > 1_000_000_000_000_000
|
30
|
+
end
|
25
31
|
end
|
data/lib/nano/version.rb
CHANGED
data/lib/nano_rpc.rb
CHANGED
@@ -5,6 +5,7 @@ require 'nano/errors'
|
|
5
5
|
require 'nano/proxy'
|
6
6
|
require 'nano/proxy_context'
|
7
7
|
require 'nano/response'
|
8
|
+
require 'nano/helpers/application_helper'
|
8
9
|
require 'nano/helpers/account_proxy_helper'
|
9
10
|
require 'nano/helpers/accounts_proxy_helper'
|
10
11
|
require 'nano/helpers/node_proxy_helper'
|
data/nano_rpc.gemspec
CHANGED
@@ -10,10 +10,9 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['jcraigk@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = 'RPC wrapper for Nano digital nodes written in Ruby'
|
13
|
-
spec.description = 'An RPC wrapper for Nano
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'proxy objects provide logically grouped helper methods.'
|
13
|
+
spec.description = 'An RPC wrapper for Nano digitial currency nodes. ' \
|
14
|
+
'Arbitrary RPC access is provided along with proxy ' \
|
15
|
+
'objects that expose helper methods.'
|
17
16
|
spec.homepage = 'https://github.com/jcraigk/ruby_nano_rpc'
|
18
17
|
spec.license = 'MIT'
|
19
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nano_rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Craig-Kuhn (JCK)
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,9 +134,8 @@ dependencies:
|
|
134
134
|
- - ">="
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: 2.0.2
|
137
|
-
description: An RPC wrapper for Nano
|
138
|
-
|
139
|
-
provide logically grouped helper methods.
|
137
|
+
description: An RPC wrapper for Nano digitial currency nodes. Arbitrary RPC access
|
138
|
+
is provided along with proxy objects that expose helper methods.
|
140
139
|
email:
|
141
140
|
- jcraigk@gmail.com
|
142
141
|
executables: []
|
@@ -156,6 +155,7 @@ files:
|
|
156
155
|
- lib/nano/errors.rb
|
157
156
|
- lib/nano/helpers/account_proxy_helper.rb
|
158
157
|
- lib/nano/helpers/accounts_proxy_helper.rb
|
158
|
+
- lib/nano/helpers/application_helper.rb
|
159
159
|
- lib/nano/helpers/node_proxy_helper.rb
|
160
160
|
- lib/nano/helpers/wallet_proxy_helper.rb
|
161
161
|
- lib/nano/proxies/account.rb
|