nem-ruby 0.0.1 → 0.0.2
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/.travis.yml +4 -7
- data/LICENSE +21 -0
- data/examples/offline/announce_offline_transfer.rb +12 -0
- data/examples/offline/create_offline_transfer.rb +17 -0
- data/examples/util/deserialize.rb +20 -0
- data/lib/nem/endpoint/block.rb +6 -0
- data/lib/nem/endpoint/chain.rb +3 -0
- data/lib/nem/endpoint/local/chain.rb +2 -0
- data/lib/nem/endpoint/mosaic.rb +1 -1
- data/lib/nem/endpoint/namespace.rb +1 -1
- data/lib/nem/endpoint/node.rb +3 -2
- data/lib/nem/endpoint/timesync.rb +1 -0
- data/lib/nem/endpoint/transaction.rb +2 -1
- data/lib/nem/model/account.rb +9 -3
- data/lib/nem/model/account_historical.rb +9 -1
- data/lib/nem/model/block.rb +0 -1
- data/lib/nem/model/explorer_block.rb +4 -1
- data/lib/nem/model/message.rb +2 -1
- data/lib/nem/util/convert.rb +7 -7
- data/lib/nem/util/deserializer.rb +1 -1
- data/lib/nem/version.rb +1 -1
- data/nem-ruby.gemspec +1 -1
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3def2269772e7a42457d616deaadef0c5c672979
|
4
|
+
data.tar.gz: 58ab758cb80d71ada5bf4f53e9a2ad4061d3d733
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 870921a6c9e959461affe9bb8d7615ec2866f2250668c03036fef4db6e7d054933a7360d4776523e406b4a8c79bc65435286c0e307133b42c40967117e9ea40d
|
7
|
+
data.tar.gz: cc1e79f92783b58afbb0c1abe0b5f111cbdcc3b314efe5d01d7c5a7b86a6eecbb5d424c171e66da3c0ac1dbf54008f53cbdac63fbde0fb73ddc84c9d6e6bc570
|
data/.travis.yml
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
sudo: false
|
2
1
|
language: ruby
|
3
2
|
cache: bundler
|
4
|
-
bundler_args: --without development
|
5
3
|
|
6
4
|
rvm:
|
7
5
|
- ruby-head
|
6
|
+
- 2.5.0
|
7
|
+
- 2.4.3
|
8
8
|
- 2.4.0
|
9
|
+
- 2.3.6
|
9
10
|
- 2.3.0
|
11
|
+
- 2.2.9
|
10
12
|
- 2.2.6
|
11
13
|
|
12
14
|
branches:
|
@@ -14,10 +16,5 @@ branches:
|
|
14
16
|
- master
|
15
17
|
- development
|
16
18
|
|
17
|
-
matrix:
|
18
|
-
fast_finish: true
|
19
|
-
|
20
19
|
before_install:
|
21
|
-
# Bundler on Travis may be too out of date
|
22
|
-
# Update bundler to a recent version.
|
23
20
|
- gem install bundler
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Yoshiyuki Ieyama
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'nem'
|
3
|
+
|
4
|
+
node = Nem::Node.new(host: '104.128.226.60')
|
5
|
+
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
6
|
+
|
7
|
+
req = File.read('tx.json')
|
8
|
+
res = tx_endpoint.announce(JSON.parse(req))
|
9
|
+
|
10
|
+
pp res
|
11
|
+
pp "Message: #{res.message}"
|
12
|
+
pp "TransactionHash: #{res.transaction_hash}"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'nem'
|
3
|
+
|
4
|
+
# sender
|
5
|
+
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
6
|
+
|
7
|
+
# recipient
|
8
|
+
B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
|
9
|
+
|
10
|
+
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
11
|
+
tx = Nem::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck! Offline transfer.')
|
12
|
+
req = Nem::Request::Announce.new(tx, kp)
|
13
|
+
|
14
|
+
# signed announce
|
15
|
+
pp data = req.to_entity
|
16
|
+
pp 'save as tx.json'
|
17
|
+
File.write 'tx.json', data.to_json
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'nem'
|
3
|
+
|
4
|
+
# sender
|
5
|
+
A_PRIVATE_KEY = '260206d683962350532408e8774fd14870a173b7fba17f6b504da3dbc5f1cc9f'
|
6
|
+
|
7
|
+
# receiver
|
8
|
+
B_ADDRESS = 'TAWKJTUP4DWKLDKKS534TYP6G324CBNMXKBA4X7B'
|
9
|
+
|
10
|
+
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
11
|
+
tx = Nem::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
|
12
|
+
req = Nem::Request::Announce.new(tx, kp)
|
13
|
+
|
14
|
+
entity = req.to_entity
|
15
|
+
|
16
|
+
# You can also announce to nem Network later.
|
17
|
+
pp entity.to_json
|
18
|
+
|
19
|
+
# deserialize data into hash
|
20
|
+
pp Nem::Util::Deserializer.deserialize_transaction(req.to_entity[:data])
|
data/lib/nem/endpoint/block.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
module Nem
|
2
2
|
module Endpoint
|
3
3
|
class Block < Nem::Endpoint::Base
|
4
|
+
# @param hash
|
5
|
+
# @return [Nem::Model::Block]
|
6
|
+
# @see https://nemproject.github.io/#
|
4
7
|
def find(hash)
|
5
8
|
Nem::Model::Block.new_from_block request!(:get, '/block/get', blockHash: hash)
|
6
9
|
end
|
7
10
|
|
8
11
|
alias get find
|
9
12
|
|
13
|
+
# @param height
|
14
|
+
# @return [Nem::Model::Block]
|
15
|
+
# @see https://nemproject.github.io/#getting-a-block-with-a-given-height
|
10
16
|
def at_public(height)
|
11
17
|
Nem::Model::Block.new_from_block request!(:post, '/block/at/public', height: height)
|
12
18
|
end
|
data/lib/nem/endpoint/chain.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
module Nem
|
2
2
|
module Endpoint
|
3
3
|
class Chain < Nem::Endpoint::Base
|
4
|
+
# @return [Nem::Model::Block]
|
4
5
|
def last_block
|
5
6
|
Nem::Model::Block.new_from_block request!(:get, '/chain/last-block')
|
6
7
|
end
|
7
8
|
|
9
|
+
# @return [Numeric]
|
8
10
|
def height
|
9
11
|
request!(:get, '/chain/height')[:height]
|
10
12
|
end
|
11
13
|
|
14
|
+
# @return [String]
|
12
15
|
def score
|
13
16
|
request!(:get, '/chain/score')[:score]
|
14
17
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Nem
|
2
2
|
module Endpoint
|
3
3
|
module Local
|
4
|
+
# @return [Array <Nem::Model::ExpelorerBlock>]
|
5
|
+
# @see https://nemproject.github.io/#getting-part-of-a-chain
|
4
6
|
class Chain < Nem::Endpoint::Base
|
5
7
|
def blocks_after(height)
|
6
8
|
request!(:post, '/local/chain/blocks-after', height: height) do |res|
|
data/lib/nem/endpoint/mosaic.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Nem
|
2
2
|
module Endpoint
|
3
3
|
class Mosaic < Nem::Endpoint::Base
|
4
|
-
# @return
|
4
|
+
# @return [Nem::Model::MosaicSupply]
|
5
5
|
# @see https://nemproject.github.io/#
|
6
6
|
def supply(mosaic_id)
|
7
7
|
request!(:get, '/mosaic/supply', mosaicId: mosaic_id) do |res|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Nem
|
2
2
|
module Endpoint
|
3
3
|
class Namespace < Nem::Endpoint::Base
|
4
|
-
# @return
|
4
|
+
# @return [Nem::Model::Namespace]
|
5
5
|
# @see https://nemproject.github.io/#retrieving-a-specific-namespace
|
6
6
|
def find(namespace)
|
7
7
|
request!(:get, '/namespace', namespace: namespace) do |res|
|
data/lib/nem/endpoint/node.rb
CHANGED
@@ -13,7 +13,7 @@ module Nem
|
|
13
13
|
Nem::Model::Node.new_from_node request!(:get, '/node/info')
|
14
14
|
end
|
15
15
|
|
16
|
-
# @return [Nem::Model::
|
16
|
+
# @return [Nem::Model::NisNodeInfo]
|
17
17
|
# @see https://nemproject.github.io/#extended-node-information
|
18
18
|
def extended_info
|
19
19
|
Nem::Model::NisNodeInfo.new_from_nis_node_info request!(:get, '/node/extended-info')
|
@@ -39,7 +39,7 @@ module Nem
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
# @return [Struct
|
42
|
+
# @return [Struct]
|
43
43
|
# @see https://nemproject.github.io/#complete-neighborhood
|
44
44
|
PeerlistAll = Struct.new(:inactive, :failure, :busy, :active)
|
45
45
|
def peerlist_all
|
@@ -63,6 +63,7 @@ module Nem
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
# @param type [Symbol]
|
66
67
|
# @return [Array <Nem::Model::Node>]
|
67
68
|
def peerlist(type = :all)
|
68
69
|
case type.to_s
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Nem
|
2
2
|
module Endpoint
|
3
3
|
class Transaction < Nem::Endpoint::Base
|
4
|
+
# @return [Nem::Model::Transaction]
|
4
5
|
def find(hash)
|
5
6
|
request!(:get,
|
6
7
|
'/transaction/get',
|
@@ -15,7 +16,7 @@ module Nem
|
|
15
16
|
def announce(req)
|
16
17
|
request!(:post,
|
17
18
|
'/transaction/announce',
|
18
|
-
req.to_entity
|
19
|
+
req.respond_to?(:to_entity) ? req.to_entity : req.to_hash
|
19
20
|
) do |res|
|
20
21
|
Nem::Model::NemAnnounceResult.new_from_nem_announce_result(res)
|
21
22
|
end
|
data/lib/nem/model/account.rb
CHANGED
@@ -17,8 +17,14 @@ module Nem
|
|
17
17
|
:remote_status
|
18
18
|
|
19
19
|
def self.new_from_account_meta_data_pair(hash)
|
20
|
-
meta = hash[:meta]
|
21
20
|
account = hash[:account]
|
21
|
+
meta = hash[:meta]
|
22
|
+
cosignatory_of = meta[:cosignatoryOf].map do |a|
|
23
|
+
Account.new_from_account_data(a)
|
24
|
+
end
|
25
|
+
cosignatories = meta[:cosignatories].map do |a|
|
26
|
+
Account.new_from_account_data(a)
|
27
|
+
end
|
22
28
|
new(
|
23
29
|
address: account[:address],
|
24
30
|
balance: account[:balance],
|
@@ -27,8 +33,8 @@ module Nem
|
|
27
33
|
public_key: account[:publicKey],
|
28
34
|
label: account[:label],
|
29
35
|
harvested_blocks: account[:harvestedBlocks],
|
30
|
-
cosignatory_of:
|
31
|
-
cosignatories:
|
36
|
+
cosignatory_of: cosignatory_of,
|
37
|
+
cosignatories: cosignatories,
|
32
38
|
status: meta[:status],
|
33
39
|
remote_status: meta[:remoteStatus]
|
34
40
|
)
|
@@ -12,7 +12,15 @@ module Nem
|
|
12
12
|
:height
|
13
13
|
|
14
14
|
def self.new_from_account_historical(hash)
|
15
|
-
new(
|
15
|
+
new(
|
16
|
+
page_rank: hash[:pageRank],
|
17
|
+
address: hash[:address],
|
18
|
+
balance: hash[:balance],
|
19
|
+
importance: hash[:importance],
|
20
|
+
vested_balance: hash[:vestedBalance],
|
21
|
+
unvested_balance: hash[:unvestedBalance],
|
22
|
+
height: hash[:height]
|
23
|
+
)
|
16
24
|
end
|
17
25
|
end
|
18
26
|
end
|
data/lib/nem/model/block.rb
CHANGED
@@ -7,7 +7,10 @@ module Nem
|
|
7
7
|
|
8
8
|
def self.new_from_explorer_block(hash)
|
9
9
|
txes = hash[:txes].map do |tx|
|
10
|
-
Transaction.
|
10
|
+
Transaction.new_from_account_transaction_meta_data_pair(
|
11
|
+
meta: { hash: { data: tx[:hash] } },
|
12
|
+
transaction: tx[:tx]
|
13
|
+
)
|
11
14
|
end
|
12
15
|
new(
|
13
16
|
difficulty: hash[:difficulty],
|
data/lib/nem/model/message.rb
CHANGED
@@ -59,7 +59,7 @@ module Nem
|
|
59
59
|
|
60
60
|
# @return [Boolean]
|
61
61
|
def valid?
|
62
|
-
bytesize <=
|
62
|
+
bytesize <= 1024
|
63
63
|
end
|
64
64
|
|
65
65
|
# @return [Hash]
|
@@ -77,6 +77,7 @@ module Nem
|
|
77
77
|
@value == other.value
|
78
78
|
end
|
79
79
|
|
80
|
+
# @return [String]
|
80
81
|
def payload
|
81
82
|
(value =~ /\Afe/ || encrypted?) ? value : value.unpack('H*').first
|
82
83
|
end
|
data/lib/nem/util/convert.rb
CHANGED
@@ -49,6 +49,13 @@ module Nem
|
|
49
49
|
rstr2utf8(str).bytes.inject('') { |memo, b| memo << b.to_s(16) }
|
50
50
|
end
|
51
51
|
|
52
|
+
# Convert hex to UTF-8
|
53
|
+
# @param [string] str
|
54
|
+
# @return [string]
|
55
|
+
def self.hex_to_utf8(hex_str)
|
56
|
+
[hex_str].pack('H*').force_encoding('UTF-8')
|
57
|
+
end
|
58
|
+
|
52
59
|
# Convert an Array to hex
|
53
60
|
# @param [Array] ua - An Uint8Array
|
54
61
|
# @return [string]
|
@@ -86,8 +93,6 @@ module Nem
|
|
86
93
|
end
|
87
94
|
end
|
88
95
|
|
89
|
-
# Converts a raw javascript string into a string of single byte characters using utf8 encoding.
|
90
|
-
# This makes it easier to perform other encoding operations on the string.
|
91
96
|
# @param [String] str
|
92
97
|
# @return [String]
|
93
98
|
def self.rstr2utf8(str)
|
@@ -102,11 +107,6 @@ module Nem
|
|
102
107
|
end
|
103
108
|
end
|
104
109
|
end
|
105
|
-
|
106
|
-
# Does the reverse of rstr2utf8.
|
107
|
-
def utf82rstr(input)
|
108
|
-
raise 'Not implemented.'
|
109
|
-
end
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
@@ -38,7 +38,7 @@ module Nem
|
|
38
38
|
# s[60, 4] # length of payload
|
39
39
|
tx[:message] = {
|
40
40
|
type: deserialize_int(s[56, 4]),
|
41
|
-
payload: deserialize_hex(s[64, s.size])
|
41
|
+
payload: Nem::Util::Convert.hex_to_utf8(deserialize_hex(s[64, s.size]))
|
42
42
|
}
|
43
43
|
else
|
44
44
|
tx[:message] = { type: 1, payload: '' }
|
data/lib/nem/version.rb
CHANGED
data/nem-ruby.gemspec
CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency 'rake', '~> 10.0'
|
35
35
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
36
|
spec.add_development_dependency 'yard', '~> 0.9'
|
37
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
37
|
+
spec.add_development_dependency 'rubocop', '~> 0.49'
|
38
38
|
spec.add_development_dependency 'timecop', '~> 0.8'
|
39
39
|
spec.add_development_dependency 'webmock', '~> 2.3'
|
40
40
|
spec.add_development_dependency 'pry-byebug', '~> 3'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nem-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshiyuki Ieyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.49'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.49'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: timecop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- ".travis.yml"
|
192
192
|
- CODE_OF_CONDUCT.md
|
193
193
|
- Gemfile
|
194
|
+
- LICENSE
|
194
195
|
- README.md
|
195
196
|
- Rakefile
|
196
197
|
- examples/apostille_audit.rb
|
@@ -209,6 +210,8 @@ files:
|
|
209
210
|
- examples/localnode.rb
|
210
211
|
- examples/nis.rb
|
211
212
|
- examples/node_pool.rb
|
213
|
+
- examples/offline/announce_offline_transfer.rb
|
214
|
+
- examples/offline/create_offline_transfer.rb
|
212
215
|
- examples/transaction/importance_transfer.rb
|
213
216
|
- examples/transaction/mosaic_definition_creation.rb
|
214
217
|
- examples/transaction/mosaic_supply_change.rb
|
@@ -221,6 +224,7 @@ files:
|
|
221
224
|
- examples/transaction/transfer_mosaic.rb
|
222
225
|
- examples/transaction/transfer_with_encrypted_message.rb
|
223
226
|
- examples/transaction/transfer_with_local.rb
|
227
|
+
- examples/util/deserialize.rb
|
224
228
|
- lib/nem.rb
|
225
229
|
- lib/nem/apostille.rb
|
226
230
|
- lib/nem/apostille_audit.rb
|
@@ -343,7 +347,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
343
347
|
version: '0'
|
344
348
|
requirements: []
|
345
349
|
rubyforge_project:
|
346
|
-
rubygems_version: 2.6.
|
350
|
+
rubygems_version: 2.6.11
|
347
351
|
signing_key:
|
348
352
|
specification_version: 4
|
349
353
|
summary: Ruby gem for communicating with the nem
|