nem-ruby 0.0.5 → 0.0.6
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/.gitignore +1 -0
- data/docs/about.md +30 -0
- data/docs/custom.css +3 -0
- data/docs/examples/account.md +104 -0
- data/docs/examples/apostille.md +58 -0
- data/docs/examples/block.md +12 -0
- data/docs/examples/chain.md +24 -0
- data/docs/examples/configure.md +20 -0
- data/docs/examples/debug.md +25 -0
- data/docs/examples/define_mosaic_attachment.md +10 -0
- data/docs/examples/local.md +28 -0
- data/docs/examples/mosaic.md +12 -0
- data/docs/examples/namespace.md +25 -0
- data/docs/examples/nis.md +23 -0
- data/docs/examples/node.md +61 -0
- data/docs/examples/offline.md +39 -0
- data/docs/examples/timesync.md +12 -0
- data/docs/examples/transactions.md +218 -0
- data/docs/examples/util.md +24 -0
- data/docs/index.md +153 -0
- data/docs/mosaic.md +10 -0
- data/examples/configure.rb +17 -0
- data/examples/endpoint/account.rb +4 -1
- data/examples/transaction/multisig_transfer.rb +1 -9
- data/examples/transaction/transfer.rb +11 -9
- data/examples/transaction/transfer_with_encrypted_message.rb +1 -9
- data/examples/transaction/transfer_with_local.rb +1 -9
- data/lib/nem/configuration.rb +7 -5
- data/lib/nem/endpoint/account.rb +3 -3
- data/lib/nem/model/message.rb +7 -3
- data/lib/nem/model/mosaic.rb +1 -2
- data/lib/nem/model/mosaic_attachment.rb +1 -1
- data/lib/nem/model/mosaic_collection.rb +31 -0
- data/lib/nem/model/transaction.rb +6 -11
- data/lib/nem/request/announce.rb +4 -6
- data/lib/nem/version.rb +1 -1
- data/mkdocs.yml +28 -0
- data/nem-ruby.gemspec +1 -1
- metadata +27 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecc626aa901b8ebab5b35db375fb920ac1a66a9feb2193d79ff34d35eef37904
|
4
|
+
data.tar.gz: 6aa07a4ba05b0757c8e78a25abecbbb3169a726eecabeeb86ac047c8a4de7d75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a051321b5579cee745c6922530f07e0fb30431401e6957a7f56bf598403aa6f9131652d1d04d8cd37172980ed1c416f337b77654b6a36795224a1d66b0811568
|
7
|
+
data.tar.gz: 7946079fc07bb27eaa1631562fb3a444fd94423a35ba9a3e9e1655f23583bf482a4f819c28240f5f55bfde39b6128492384e52a74e8e07be7231922b01c30ec2
|
data/.gitignore
CHANGED
data/docs/about.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
## Feedback and Contact
|
2
|
+
|
3
|
+
For further development of nem with ruby, feel free to send me your feedback, feature requests, bug reports!
|
4
|
+
|
5
|
+
* [44uk/nem-ruby - gitter](https://gitter.im/44uk/nem-ruby)
|
6
|
+
* [@44uk_i3 - Twitter](https://twitter.com/44uk_i3)
|
7
|
+
|
8
|
+
and I would be glad if you could let me know any project using the gem!
|
9
|
+
|
10
|
+
## Donation
|
11
|
+
|
12
|
+
The project gratefully accepts donations via nem:xem.
|
13
|
+
|
14
|
+
```text
|
15
|
+
NCPBJTNKHODIGPDMPKPETJK6YLMUPAW7ISBIQGUP
|
16
|
+
```
|
17
|
+
|
18
|
+
## Thanks
|
19
|
+
|
20
|
+
- [NEM \- Distributed Ledger Technology \(Blockchain\)](https://www.nem.io/)
|
21
|
+
- [NEM NIS API Documentation](https://nemproject.github.io/)
|
22
|
+
- [NEM Forum](https://forum.nem.io/)
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
Bug reports and pull requests are welcome on GitHub at [44uk/nem-ruby](https://github.com/44uk/nem-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.
|
27
|
+
|
28
|
+
## License
|
29
|
+
|
30
|
+
The gem is available as open source under the terms of the [MIT License](https://github.com/44uk/nem-ruby/blob/master/LICENSE).
|
data/docs/custom.css
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
## Endpoint
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
5
|
+
endpoint = Nem::Endpoint::Account.new(node)
|
6
|
+
```
|
7
|
+
|
8
|
+
## Find Address
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
# find by address
|
12
|
+
pp endpoint.find('TBULEAUG2CZQISUR442HWA6UAKGWIXHDABJVIPS4')
|
13
|
+
|
14
|
+
# alias
|
15
|
+
pp endpoint.get('TBULEAUG2CZQISUR442HWA6UAKGWIXHDABJVIPS4')
|
16
|
+
|
17
|
+
# find by public key
|
18
|
+
pp endpoint.find_by_public_key('e59ef184a612d4c3c4d89b5950eb57262c69862b2f96e59c5043bf41765c482f')
|
19
|
+
|
20
|
+
# find forwarded by address
|
21
|
+
pp endpoint.find_forwarded('TBULEAUG2CZQISUR442HWA6UAKGWIXHDABJVIPS4')
|
22
|
+
|
23
|
+
# find forwarded by public key
|
24
|
+
pp endpoint.find_forwarded_by_public_key('e59ef184a612d4c3c4d89b5950eb57262c69862b2f96e59c5043bf41765c482f')
|
25
|
+
```
|
26
|
+
|
27
|
+
## Hervests
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
pp endpoint.harvests('TBULEAUG2CZQISUR442HWA6UAKGWIXHDABJVIPS4')
|
31
|
+
```
|
32
|
+
|
33
|
+
## Namespace / Mosaics
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# namespace
|
37
|
+
pp endpoint.namespace('TDPICOQ7GIEMIDJOOMIQSOYIJKG3C7V7OP2DUFIR')
|
38
|
+
|
39
|
+
# fetch mosaic definition of account
|
40
|
+
pp endpoint.mosaic_definition('TDPICOQ7GIEMIDJOOMIQSOYIJKG3C7V7OP2DUFIR')
|
41
|
+
|
42
|
+
# fetch owned mosaics of account
|
43
|
+
mosaics = account_endpoint.mosaic_owned('TDPICOQ7GIEMIDJOOMIQSOYIJKG3C7V7OP2DUFIR')
|
44
|
+
pp mosaics
|
45
|
+
|
46
|
+
## can find by namespace
|
47
|
+
pp mosaics.find_by_namespace_id('tpico')
|
48
|
+
|
49
|
+
## can find by fqn
|
50
|
+
pp mosaics.find_by_fqn('tpico:test')
|
51
|
+
```
|
52
|
+
|
53
|
+
## Transactions
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
## incomings
|
57
|
+
pp endpoint.transfers_incoming('TBULEAUG2CZQISUR442HWA6UAKGWIXHDABJVIPS4')
|
58
|
+
|
59
|
+
## outgoings
|
60
|
+
pp endpoint.transfers_outgoing('TBULEAUG2CZQISUR442HWA6UAKGWIXHDABJVIPS4')
|
61
|
+
|
62
|
+
## all
|
63
|
+
pp endpoint.transfers_all('TBULEAUG2CZQISUR442HWA6UAKGWIXHDABJVIPS4')
|
64
|
+
|
65
|
+
## unconfirmed
|
66
|
+
pp endpoint.transfers_unconfirmed('TBULEAUG2CZQISUR442HWA6UAKGWIXHDABJVIPS4')
|
67
|
+
```
|
68
|
+
|
69
|
+
## Status
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
pp endpoint.status('TDJNDAQ7F7AQRXKP2YVTH67QYCWWKE6QLSJFWN64')
|
73
|
+
```
|
74
|
+
|
75
|
+
## Unlocked
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
pp endpoint.unlocked_info
|
79
|
+
```
|
80
|
+
|
81
|
+
## Historical
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
pp endpoint.historical('TDWWYDGQNBKSAJBSHZX7QWVX7WNVAWWB7HGPWRB2',
|
85
|
+
start_height: 1245390,
|
86
|
+
end_height: 1245400,
|
87
|
+
increment: 1
|
88
|
+
)
|
89
|
+
```
|
90
|
+
|
91
|
+
## Generate Account / Lock, Unlock
|
92
|
+
|
93
|
+
The APIs allowed only Local NIS.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
## generate account
|
97
|
+
pp endpoint.generate
|
98
|
+
|
99
|
+
## lock account
|
100
|
+
pp endpoint.lock('__private_key__')
|
101
|
+
|
102
|
+
## unlock account
|
103
|
+
pp endpoint.unlock('__private_key__')
|
104
|
+
```
|
@@ -0,0 +1,58 @@
|
|
1
|
+
## Public Apostille
|
2
|
+
|
3
|
+
### Create
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'pp'
|
7
|
+
require 'nem'
|
8
|
+
|
9
|
+
FIXTURES_PATH = File.expand_path('../../spec/fixtures', __FILE__)
|
10
|
+
|
11
|
+
# sender
|
12
|
+
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
13
|
+
|
14
|
+
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
15
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
16
|
+
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
17
|
+
|
18
|
+
file = File.open("#{FIXTURES_PATH}/nemLogoV2.png")
|
19
|
+
apo = Nem::Apostille.new(kp, file, :sha1,
|
20
|
+
multisig: false,
|
21
|
+
signed: false,
|
22
|
+
network: :testnet
|
23
|
+
)
|
24
|
+
tx = apo.transaction
|
25
|
+
pp "Fee: #{tx.fee.to_i}"
|
26
|
+
|
27
|
+
req = Nem::Request::Announce.new(tx, kp)
|
28
|
+
res = tx_endpoint.announce(req)
|
29
|
+
|
30
|
+
pp "Message: #{res.message}"
|
31
|
+
pp "TransactionHash: #{res.transaction_hash}"
|
32
|
+
pp "ApostilleFormat: #{apo.apostille_format(res.transaction_hash)}"
|
33
|
+
|
34
|
+
FileUtils.cp(file.path, apo.apostille_format(res.transaction_hash))
|
35
|
+
```
|
36
|
+
|
37
|
+
### Audit
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'pp'
|
41
|
+
require 'nem'
|
42
|
+
|
43
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
44
|
+
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
45
|
+
|
46
|
+
# transaction hash from Filename
|
47
|
+
tx_hash = 'c035c2603356852687c4730fbc6f8d21da3af7c4c0eb8b3619bc9ecdc833255a'
|
48
|
+
tx = tx_endpoint.find(tx_hash)
|
49
|
+
|
50
|
+
# NOTE: it may return "Hash was not found in cache"
|
51
|
+
# because of NIS not supporting caching transactions.
|
52
|
+
# 'fe4e545902cde315617a435ebfd5fe8875d699e2f2363262f5'
|
53
|
+
apostille_hash = tx.message.payload
|
54
|
+
file = File.open("#{FIXTURES_PATH}/nemLogoV2 -- Apostille TX c035c2603356852687c4730fbc6f8d21da3af7c4c0eb8b3619bc9ecdc833255a -- Date 2017-12-18.png")
|
55
|
+
|
56
|
+
apa = Nem::ApostilleAudit.new(file, apostille_hash)
|
57
|
+
pp apa.valid? ? 'OK, Valid Apostille!' : 'Bad, Invalid Apostille!'
|
58
|
+
```
|
@@ -0,0 +1,24 @@
|
|
1
|
+
## Endpoint
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
5
|
+
endpoint = Nem::Endpoint::Chain.new(node)
|
6
|
+
```
|
7
|
+
|
8
|
+
## height
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
pp endpoint.height
|
12
|
+
```
|
13
|
+
|
14
|
+
## score
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
pp endpoint.score
|
18
|
+
```
|
19
|
+
|
20
|
+
## last block
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
pp endpoint.last_block
|
24
|
+
```
|
@@ -0,0 +1,20 @@
|
|
1
|
+
## Configuration
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
Nem.configure do |conf|
|
5
|
+
# output path
|
6
|
+
conf.logger = Logger.new('./nem-ruby.log')
|
7
|
+
|
8
|
+
# logger level
|
9
|
+
conf.logger.level = Logger::DEBUG
|
10
|
+
|
11
|
+
# output debug log
|
12
|
+
conf.debug = true
|
13
|
+
|
14
|
+
# deadline(sec)
|
15
|
+
conf.default_deadline = 7200
|
16
|
+
|
17
|
+
# :mainnet if you'd like to use on mainnet!
|
18
|
+
conf.default_network = :mainnet
|
19
|
+
end
|
20
|
+
```
|
@@ -0,0 +1,25 @@
|
|
1
|
+
## Endpoint
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
5
|
+
endpoint = Nem::Endpoint::Debug.new(node)
|
6
|
+
```
|
7
|
+
|
8
|
+
## connections
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
# mapped methods
|
12
|
+
pp endpoint.connections_incoming
|
13
|
+
pp endpoint.connections_outgoing
|
14
|
+
pp endpoint.connections_timers
|
15
|
+
|
16
|
+
# another way
|
17
|
+
pp endpoint.debug_connections(:in)
|
18
|
+
pp endpoint.debug_connections(:out)
|
19
|
+
```
|
20
|
+
|
21
|
+
## time synchronization
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
pp endpoint.time_synchronization
|
25
|
+
```
|
@@ -0,0 +1,28 @@
|
|
1
|
+
## Endpoint
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
node = Nem::Node.new
|
5
|
+
endpoint = Nem::Endpoint::Local.new(node)
|
6
|
+
```
|
7
|
+
|
8
|
+
## account transfers
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
value = '00b4a68d16dc505302e9631b860664ba43a8183f0903bc5782a2403b2f9eb3c8a1'
|
12
|
+
|
13
|
+
# mapped methods
|
14
|
+
pp endpoint.transfers_incoming(value)
|
15
|
+
pp endpoint.transfers_outgoing(value)
|
16
|
+
pp endpoint.transfers_all(value)
|
17
|
+
|
18
|
+
# another way
|
19
|
+
pp endpoint.transfers(value, :in)
|
20
|
+
pp endpoint.transfers(value, :out)
|
21
|
+
pp endpoint.transfers(value, :all)
|
22
|
+
```
|
23
|
+
|
24
|
+
##chain blocks after
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
pp endpoint.blocks_after(1_223_559)
|
28
|
+
```
|
@@ -0,0 +1,25 @@
|
|
1
|
+
## Endpoint
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
5
|
+
endpoint = Nem::Endpoint::Namespace.new(node)
|
6
|
+
```
|
7
|
+
|
8
|
+
## find
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
pp ns_endpoint.find('alice')
|
12
|
+
```
|
13
|
+
|
14
|
+
|
15
|
+
## root
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
pp ns_endpoint.root(882, page_size: 1)
|
19
|
+
```
|
20
|
+
|
21
|
+
## mosaic definition page
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
pp ns_endpoint.mosaic_definition('tpico')
|
25
|
+
```
|
@@ -0,0 +1,23 @@
|
|
1
|
+
## Node
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
5
|
+
```
|
6
|
+
|
7
|
+
## heartbeat
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
pp node.heartbeat
|
11
|
+
|
12
|
+
# passing API Path
|
13
|
+
pp node.request :get, 'heartbeat'
|
14
|
+
```
|
15
|
+
|
16
|
+
## status
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
pp node.status
|
20
|
+
|
21
|
+
# passing API Path
|
22
|
+
pp node.request :get, 'status'
|
23
|
+
```
|
@@ -0,0 +1,61 @@
|
|
1
|
+
## Endpoint
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
5
|
+
endpoint = Nem::Endpoint::Node.new(node)
|
6
|
+
```
|
7
|
+
|
8
|
+
## Info
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
pp endpoint.node_info
|
12
|
+
pp endpoint.node_extended_info
|
13
|
+
pp endpoint.node_experiences
|
14
|
+
```
|
15
|
+
|
16
|
+
## Peerlist
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
# mapped methods
|
20
|
+
pp endpoint.node_peerlist_all
|
21
|
+
pp endpoint.node_peerlist_reachable
|
22
|
+
pp endpoint.node_peerlist_active
|
23
|
+
|
24
|
+
# another way
|
25
|
+
pp endpoint.node_peerlist(:all)
|
26
|
+
pp endpoint.node_peerlist(:reachable)
|
27
|
+
pp endpoint.node_peerlist(:active)
|
28
|
+
```
|
29
|
+
|
30
|
+
## Active peers max chain height
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
endpoint = node_endpoint = Nem::Endpoint::Node.new(Nem::Node.new)
|
34
|
+
|
35
|
+
pp endpoint.node_active_peers_max_chain_height
|
36
|
+
```
|
37
|
+
|
38
|
+
## Boot node request
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
bnr = Nis::Struct::BootNodeRequest.new(
|
42
|
+
metaData: {
|
43
|
+
application: 'NIS'
|
44
|
+
},
|
45
|
+
endpoint: {
|
46
|
+
protocol: 'http',
|
47
|
+
port: 7890,
|
48
|
+
host: 'localhost'
|
49
|
+
},
|
50
|
+
identity: {
|
51
|
+
'private-key': 'a6cbd01d04edecfaef51df9486c111abb6299c764a00206eb1d01f4587491b3f',
|
52
|
+
name: 'Alice'
|
53
|
+
}
|
54
|
+
)
|
55
|
+
|
56
|
+
begin
|
57
|
+
pp endpoint.node_boot(boot_node_request: bnr)
|
58
|
+
rescue => ex
|
59
|
+
pp ex
|
60
|
+
end
|
61
|
+
```
|