nis-ruby 0.0.16 → 0.0.17
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/README.md +43 -33
- data/examples/account/generate.rb +29 -0
- data/examples/account/get.rb +26 -0
- data/examples/account/harvests.rb +8 -0
- data/examples/account/historical.rb +13 -0
- data/examples/account/importances.rb +8 -0
- data/examples/account/lock.rb +8 -0
- data/examples/account/mosaic.rb +9 -0
- data/examples/account/namespace.rb +8 -0
- data/examples/account/status.rb +8 -0
- data/examples/account/transfers.rb +16 -0
- data/examples/account/unconfirmed_transactions.rb +8 -0
- data/examples/account/unlock.rb +8 -0
- data/examples/account/unlocked.rb +8 -0
- data/examples/block/at_public.rb +4 -0
- data/examples/block/get.rb +4 -0
- data/examples/debug/connections.rb +13 -0
- data/examples/debug/time_synchronization.rb +6 -0
- data/examples/local/account_transfers.rb +20 -0
- data/examples/local/chain_blocks_after.rb +8 -0
- data/examples/namespace/mosaic_definition.rb +6 -0
- data/examples/namespace/root.rb +6 -0
- data/examples/nis.rb +11 -7
- data/examples/node/active_peers.rb +6 -0
- data/examples/node/boot.rb +25 -0
- data/examples/node/info.rb +8 -0
- data/examples/node/peerlist.rb +14 -0
- data/examples/time_sync/network_time.rb +6 -0
- data/examples/transactions/get.rb +42 -0
- data/examples/transactions/importance_transfer.rb +6 -4
- data/examples/transactions/mosaic_definition_creation.rb +6 -4
- data/examples/transactions/mosaic_supply_change.rb +6 -4
- data/examples/transactions/multisig.rb +6 -4
- data/examples/transactions/multisig_add_cosignatory.rb +3 -1
- data/examples/transactions/multisig_aggregate_modification.rb +6 -4
- data/examples/transactions/multisig_signature.rb +6 -3
- data/examples/transactions/provision_namespace.rb +6 -4
- data/examples/transactions/transfer.rb +14 -7
- data/examples/transactions/transfer_mosaic.rb +5 -3
- data/examples/transactions/transfer_remote.rb +6 -4
- data/lib/nis.rb +6 -0
- data/lib/nis/client.rb +11 -0
- data/lib/nis/configuration.rb +23 -0
- data/lib/nis/endpoint/account/transfers.rb +24 -0
- data/lib/nis/endpoint/debug/connections.rb +17 -0
- data/lib/nis/endpoint/local/account/transfers.rb +14 -0
- data/lib/nis/endpoint/node/peer_list.rb +20 -0
- data/lib/nis/endpoint/time_sync.rb +4 -0
- data/lib/nis/endpoint/time_sync/network_time.rb +10 -0
- data/lib/nis/endpoint/transaction/get.rb +12 -0
- data/lib/nis/keypair.rb +13 -7
- data/lib/nis/struct.rb +1 -0
- data/lib/nis/struct/importance_transfer_transaction.rb +10 -0
- data/lib/nis/struct/message.rb +9 -2
- data/lib/nis/struct/mosaic_definition_creation_transaction.rb +15 -0
- data/lib/nis/struct/mosaic_supply_change_transaction.rb +12 -0
- data/lib/nis/struct/multisig_aggregate_modification_transaction.rb +10 -0
- data/lib/nis/struct/multisig_signature_transaction.rb +12 -0
- data/lib/nis/struct/multisig_transaction.rb +15 -0
- data/lib/nis/struct/network_time.rb +17 -0
- data/lib/nis/struct/provision_namespace_transaction.rb +16 -0
- data/lib/nis/struct/transaction.rb +4 -81
- data/lib/nis/struct/transaction_meta_data_pair.rb +17 -1
- data/lib/nis/struct/transfer_transaction.rb +11 -0
- data/lib/nis/unit/address.rb +11 -4
- data/lib/nis/util.rb +3 -1
- data/lib/nis/util/convert.rb +44 -51
- data/lib/nis/util/deserializer.rb +62 -77
- data/lib/nis/util/ed25519.rb +10 -12
- data/lib/nis/util/serializer.rb +117 -185
- data/lib/nis/version.rb +1 -1
- data/nis.gemspec +0 -3
- metadata +43 -26
- data/bin/nis +0 -60
- data/examples/account.rb +0 -44
- data/examples/block.rb +0 -9
- data/examples/debug.rb +0 -33
- data/examples/local.rb +0 -19
- data/examples/namespace.rb +0 -9
- data/examples/node.rb +0 -44
- data/examples/shutdown.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59a90524a4fe746f16a6fafe9d971f266d0b61e4
|
4
|
+
data.tar.gz: 56759ab22da26c82ce149a160d0265e7ac49638c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1860f26e59c0bfe83b9f6aec5f904de94c65448dc7a8a286d92ab0506ad55a3f338985f9fb70a0465f945dbe4ceed7a85b55f9d87f6f60c1c6edaad3242eb4a8
|
7
|
+
data.tar.gz: a6d46edcbf71a03f5fe9d5221912d49184ec841f3fc04630d8db97649bb0da28320e08d02ef7d3855ab17302c4a17cb2d0d08958b46d960b7300ff66c05b7a43
|
data/README.md
CHANGED
@@ -9,15 +9,16 @@
|
|
9
9
|
|
10
10
|
Ruby client library for the NEM Infrastructure Server(NIS) API.
|
11
11
|
|
12
|
-
- [NEM \- Distributed Ledger Technology \(Blockchain\)](https://www.nem.io/)
|
13
|
-
- [NEM NIS API Documentation](https://nemproject.github.io/)
|
14
|
-
- [NEM Forum](https://forum.nem.io/)
|
15
|
-
|
16
12
|
*The gem is under development. Incompatible changes can be made.*
|
17
13
|
|
18
|
-
*
|
14
|
+
*Not recommended for production use because of lack of testing, needed more improvement.*
|
15
|
+
|
16
|
+
For further development of nem with ruby, [feel free to send me your feedback!](#feedback-and-contact)
|
19
17
|
|
20
|
-
|
18
|
+
* [NEM \- Distributed Ledger Technology \(Blockchain\)](https://www.nem.io/)
|
19
|
+
* [NEM NIS API Documentation](https://nemproject.github.io/)
|
20
|
+
* [NEM Forum](https://forum.nem.io/)
|
21
|
+
* [NEM Testnet Faucet \- You can get Testnet XEM for development / testing.](http://test-nem-faucet.44uk.net/)
|
21
22
|
|
22
23
|
## Installation
|
23
24
|
|
@@ -42,6 +43,11 @@ More specific example codes are in **[examples/](examples/)** directory.
|
|
42
43
|
```ruby
|
43
44
|
require 'rubygems'
|
44
45
|
require 'nis'
|
46
|
+
# turn on output request information
|
47
|
+
Nis.logger.level = Logger::DEBUG
|
48
|
+
|
49
|
+
A_PRIVATE_KEY = '__put_your_private_key__'
|
50
|
+
|
45
51
|
nis = Nis.new
|
46
52
|
|
47
53
|
nis.heartbeat
|
@@ -52,11 +58,12 @@ nis.status
|
|
52
58
|
# => {code: 6, type: 4, message: "status"}
|
53
59
|
# See https://nemproject.github.io/#status-request
|
54
60
|
|
55
|
-
kp = Nis::Keypair.new(
|
61
|
+
kp = Nis::Keypair.new(A_PRIVATE_KEY)
|
56
62
|
tx = Nis::Transaction::Transfer.new(
|
57
63
|
RECIPIENT_ADDRESS,
|
58
64
|
1, # send 1xem
|
59
|
-
'Message'
|
65
|
+
'Message',
|
66
|
+
network: :testnet # :mainnet (default is :testnet)
|
60
67
|
)
|
61
68
|
req = Nis::Request::PrepareAnnounce.new(tx, kp)
|
62
69
|
# Request to local node.
|
@@ -65,7 +72,8 @@ nis.transaction_prepare_announce(req)
|
|
65
72
|
# => {innerTransactionHash: {}, code: 1, type: 1, message: "SUCCESS", transactionHash: {data: "9da41fd6c6886740ae6a15c869df0470015d78103e5b216971aa09fdbcce9cde"}}
|
66
73
|
|
67
74
|
# Request to remote node.
|
68
|
-
# nis = Nis.new(host: '
|
75
|
+
# nis = Nis.new(host: '23.228.67.85')
|
76
|
+
# req = Nis::Request::Announce.new(tx, kp)
|
69
77
|
# nis.transaction_announce(req)
|
70
78
|
```
|
71
79
|
|
@@ -89,22 +97,6 @@ nis.request(:post, '/account/unlock',
|
|
89
97
|
# See https://nemproject.github.io/#locking-and-unlocking-accounts
|
90
98
|
```
|
91
99
|
|
92
|
-
## Commandline
|
93
|
-
|
94
|
-
```bash
|
95
|
-
$ nis status
|
96
|
-
# => {"code":6,"type":4,"message":"status"}
|
97
|
-
|
98
|
-
$ nis heartbeat
|
99
|
-
# => {"code":1,"type":2,"message":"ok"}
|
100
|
-
|
101
|
-
$ nis request get account/get --params=address:TALICELCD3XPH4FFI5STGGNSNSWPOTG5E4DS2TOS
|
102
|
-
# => [AccountMetaDataPair structure]
|
103
|
-
|
104
|
-
$ nis request get account/harvests --params=address:TALICELCD3XPH4FFI5STGGNSNSWPOTG5E4DS2TOS hash:81d52a7df4abba8bb1613bcc42b6b93cf3114524939035d88ae8e864cd2c34c8
|
105
|
-
# => [Array <HervestInfo structure>]
|
106
|
-
```
|
107
|
-
|
108
100
|
## Connection
|
109
101
|
|
110
102
|
You can choose nodes from [NEM Node Rewards](https://supernodes.nem.io/).
|
@@ -113,32 +105,50 @@ You can choose nodes from [NEM Node Rewards](https://supernodes.nem.io/).
|
|
113
105
|
|
114
106
|
```ruby
|
115
107
|
# Passing hostname
|
116
|
-
Nis.new(host: '
|
108
|
+
Nis.new(host: '23.228.67.85')
|
117
109
|
|
118
110
|
# Passing url
|
119
|
-
Nis.new(url: 'http://
|
111
|
+
Nis.new(url: 'http://23.228.67.85:7890')
|
120
112
|
```
|
121
113
|
|
122
114
|
### Environment Variable
|
123
115
|
|
124
116
|
```bash
|
125
|
-
$ export NIS_URL=http://
|
126
|
-
$ nis heartbeat # => {"code":1,"type":2,"message":"ok"}
|
117
|
+
$ export NIS_URL=http://23.228.67.85:7890
|
127
118
|
```
|
128
119
|
|
129
120
|
Environment variable used as default value.
|
130
121
|
|
131
|
-
##
|
122
|
+
## Logging
|
132
123
|
|
133
|
-
|
124
|
+
```ruby
|
125
|
+
# custom loggin output (default is STDOUT)
|
126
|
+
Nis.logger = Logger.new('/path/to/nis-ruby.log')
|
127
|
+
# custom log level
|
128
|
+
Nis.logger.level = Logger::DEBUG
|
129
|
+
|
130
|
+
# or configuration
|
131
|
+
Nis.configure do |conf|
|
132
|
+
conf.logger = Logger.new('/path/to/nis-ruby.log')
|
133
|
+
conf.logger.level = Logger::DEBUG
|
134
|
+
end
|
135
|
+
```
|
134
136
|
|
135
|
-
|
137
|
+
```
|
138
|
+
D, [2017-09-26T08:03:54.752718 #78207] DEBUG -- : host:http://127.0.0.1:7890/ method:post path:/transaction/prepare-announce params:{:transaction=>{:type=>257, :network=>:testnet, :recipient=>"TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF", :amount=>1000000, :message=>{:payload=>"476f6f64206c75636b21", :type=>1}, :fee=>100000, :timeStamp=>78793049, :deadline=>78796649, :version=>2550136833, :signer=>"be2ba9cb15a547110d511a4d43c0482fbb584d78781abac01fb053d18f4a0033"}, :privateKey=>"4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214"}
|
139
|
+
```
|
136
140
|
|
137
|
-
|
141
|
+
## Feedback and Contact
|
142
|
+
|
143
|
+
For further development of nem with ruby, feel free to send me your feedback!
|
138
144
|
|
139
145
|
* [@44uk_i3 - Twitter](https://twitter.com/44uk_i3)
|
140
146
|
* [44uk/nis-ruby - gitter](https://gitter.im/44uk/nis-ruby)
|
141
147
|
|
148
|
+
## For More Information
|
149
|
+
|
150
|
+
* [Documentation for nis-ruby - rubydoc.info](http://www.rubydoc.info/gems/nis-ruby)
|
151
|
+
|
142
152
|
## Contributing
|
143
153
|
|
144
154
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nis-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'nis'
|
2
|
+
Nis.logger.level = Logger::DEBUG
|
3
|
+
|
4
|
+
nis = Nis.new
|
5
|
+
|
6
|
+
keypair = nis.account_generate
|
7
|
+
|
8
|
+
p keypair
|
9
|
+
|
10
|
+
# Access properties.
|
11
|
+
# Names are same API response.
|
12
|
+
p keypair.address
|
13
|
+
p keypair.privateKey
|
14
|
+
p keypair.publicKey
|
15
|
+
|
16
|
+
# Ruby style access.
|
17
|
+
# Also can be access property by snakecase.
|
18
|
+
p keypair.private_key
|
19
|
+
p keypair.public_key
|
20
|
+
|
21
|
+
# hash like access.
|
22
|
+
# Also can be access property like hash.
|
23
|
+
p keypair[:privateKey]
|
24
|
+
p keypair[:private_key]
|
25
|
+
|
26
|
+
# Address object
|
27
|
+
# Properties wrapped by value object.
|
28
|
+
p address = keypair.address
|
29
|
+
p address.testnet?
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'nis'
|
2
|
+
Nis.logger.level = Logger::DEBUG
|
3
|
+
|
4
|
+
A_ADDRESS = 'TDPP2C4XQLMESBMCYGWN4NRAJAKZEYRV75KGYSOB'
|
5
|
+
A_PUBLIC_KEY = 'cc63b4dcdec745417043c3fa0992ec3a1695461a26d90264744648abbd5caa0d'
|
6
|
+
|
7
|
+
nis = Nis.new(host: '23.228.67.85')
|
8
|
+
|
9
|
+
p nis.account_get(address: A_ADDRESS)
|
10
|
+
p nis.account_get_from_public_key(public_key: A_PUBLIC_KEY)
|
11
|
+
|
12
|
+
p nis.account_get_forwarded(address: A_ADDRESS)
|
13
|
+
p nis.account_get_forwarded_from_public_key(public_key: A_PUBLIC_KEY)
|
14
|
+
|
15
|
+
# /account/get?address={address}
|
16
|
+
# -> account_get address: {address}
|
17
|
+
# Passing parameters by keyword arguments.
|
18
|
+
account_meta_pair = nis.account_get(address: keypair.address)
|
19
|
+
account = account_meta_pair[:account]
|
20
|
+
p account.balance
|
21
|
+
|
22
|
+
# /account/get/from-public-key?public-key={key}
|
23
|
+
# -> account_get_public_key public_key: {key}
|
24
|
+
account_meta_pair = nis.account_get_from_public_key(public_key: keypair.public_key)
|
25
|
+
account = account_meta_pair.account
|
26
|
+
p account.address
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'nis'
|
2
|
+
Nis.logger.level = Logger::DEBUG
|
3
|
+
|
4
|
+
A_ADDRESS = 'TDPP2C4XQLMESBMCYGWN4NRAJAKZEYRV75KGYSOB'
|
5
|
+
|
6
|
+
nis = Nis.new(host: '23.228.67.85')
|
7
|
+
|
8
|
+
p nis.account_historical_get(
|
9
|
+
address: A_ADDRESS,
|
10
|
+
start_height: 17592,
|
11
|
+
end_height: 17592,
|
12
|
+
increment: 1
|
13
|
+
)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'nis'
|
2
|
+
Nis.logger.level = Logger::DEBUG
|
3
|
+
|
4
|
+
A_ADDRESS = 'TDPP2C4XQLMESBMCYGWN4NRAJAKZEYRV75KGYSOB'
|
5
|
+
|
6
|
+
nis = Nis.new(host: '23.228.67.85')
|
7
|
+
|
8
|
+
# mapped methods
|
9
|
+
p nis.account_transfers_incoming(address: A_ADDRESS)
|
10
|
+
p nis.account_transfers_outgoing(address: A_ADDRESS)
|
11
|
+
p nis.account_transfers_all(address: A_ADDRESS)
|
12
|
+
|
13
|
+
# another way
|
14
|
+
p nis.account_transfers(:in, address: A_ADDRESS)
|
15
|
+
p nis.account_transfers(:out, address: A_ADDRESS)
|
16
|
+
p nis.account_transfers(:all, address: A_ADDRESS)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'nis'
|
2
|
+
Nis.logger.level = Logger::DEBUG
|
3
|
+
|
4
|
+
nis = Nis.new(host: '23.228.67.85')
|
5
|
+
|
6
|
+
# mapped methods
|
7
|
+
p nis.debug_connections_incoming
|
8
|
+
p nis.debug_connections_outgoing
|
9
|
+
p nis.debug_connections_timers
|
10
|
+
|
11
|
+
# another way
|
12
|
+
p nis.debug_connections(:in)
|
13
|
+
p nis.debug_connections(:out)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'nis'
|
2
|
+
Nis.logger.level = Logger::DEBUG
|
3
|
+
|
4
|
+
A_ADDRESS = 'TDPP2C4XQLMESBMCYGWN4NRAJAKZEYRV75KGYSOB'
|
5
|
+
|
6
|
+
nis = Nis.new
|
7
|
+
|
8
|
+
page = Nis::Struct::AccountPrivateKeyTransactionsPage.new(
|
9
|
+
value: '00b4a68d16dc505302e9631b860664ba43a8183f0903bc5782a2403b2f9eb3c8a1'
|
10
|
+
)
|
11
|
+
|
12
|
+
# mapped methods
|
13
|
+
p nis.local_account_transfers_incoming(page: page)
|
14
|
+
p nis.local_account_transfers_outgoing(page: page)
|
15
|
+
p nis.local_account_transfers_all(page: page)
|
16
|
+
|
17
|
+
# another way
|
18
|
+
p nis.local_account_transfers(:in, page: page)
|
19
|
+
p nis.local_account_transfers(:out, page: page)
|
20
|
+
p nis.local_account_transfers(:all, page: page)
|
data/examples/nis.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
require 'nis'
|
2
|
+
Nis.logger.level = Logger::DEBUG
|
2
3
|
|
3
4
|
# Create NIS instance.
|
4
5
|
# By default, connect to local NIS.
|
5
6
|
# You also can connect to remote.
|
6
|
-
|
7
|
-
nis = Nis.new
|
7
|
+
nis = Nis.new(host: '23.228.67.85')
|
8
8
|
|
9
9
|
# API path /heartbeat, /status are mapped into methods.
|
10
10
|
# It returns Nis::Struct::NemRequestResult object.
|
11
|
-
|
12
|
-
|
11
|
+
p nis.heartbeat.inspect
|
12
|
+
p nis.status.inspect
|
13
13
|
|
14
14
|
# Also call Nis#request method.
|
15
15
|
# The method receive [HTTP Method], [API Path], [Parameters]
|
16
16
|
# It returns hash which converted API JSON response.
|
17
17
|
|
18
18
|
# Nis#request returns hash,
|
19
|
-
|
20
|
-
|
19
|
+
p nis.request :get, 'heartbeat'
|
20
|
+
p nis.request :get, 'status'
|
21
21
|
|
22
22
|
# Nis#request! can raise Error when NIS returns error.
|
23
|
-
|
23
|
+
p nis.request! :get, 'account/get', address: 'INVALID_ADDRESS'
|
24
|
+
|
25
|
+
# only accept local node
|
26
|
+
# nis = Nis.new
|
27
|
+
# nis.shutdown
|