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.
data/docs/mosaic.md ADDED
@@ -0,0 +1,10 @@
1
+ ## Mosaic attachment definition
2
+
3
+ ```ruby
4
+ class MyMosaic < Nem::Mosaic::Base
5
+ namespace_id 'my'
6
+ name 'moz'
7
+ divisibility 3
8
+ initial_supply 1_234_567_890
9
+ end
10
+ ```
@@ -0,0 +1,17 @@
1
+ require 'nem'
2
+
3
+ # Library configuration
4
+ Nem.configure do |conf|
5
+ # set logger
6
+ conf.logger = Logger.new('./nem-ruby.log')
7
+ conf.logger.level = Logger::DEBUG
8
+
9
+ # debug flag
10
+ conf.debug = true
11
+
12
+ # you can set deadline(sec)
13
+ conf.default_deadline = 7200
14
+
15
+ # set :mainnet if you'd like to use on mainnet!
16
+ conf.default_network = :mainnet # use on mainnet!
17
+ end
@@ -38,7 +38,10 @@ pp account_endpoint.namespace('TDPICOQ7GIEMIDJOOMIQSOYIJKG3C7V7OP2DUFIR')
38
38
  pp account_endpoint.mosaic_definition('TDPICOQ7GIEMIDJOOMIQSOYIJKG3C7V7OP2DUFIR')
39
39
 
40
40
  # fetch owned mosaics of account
41
- pp account_endpoint.mosaic_owned('TDPICOQ7GIEMIDJOOMIQSOYIJKG3C7V7OP2DUFIR')
41
+ mosaics = account_endpoint.mosaic_owned('TDPICOQ7GIEMIDJOOMIQSOYIJKG3C7V7OP2DUFIR')
42
+ pp mosaics
43
+ pp mosaics.find_by_namespace_id('tpico')
44
+ pp mosaics.find_by_fqn('tpico:test')
42
45
 
43
46
  # transfers
44
47
 
@@ -1,15 +1,7 @@
1
1
  require 'pp'
2
2
  require 'nem'
3
3
 
4
- # Library configuration
5
- Nem.configure do |conf|
6
- # conf.logger = Logger.new('./nem-ruby.log')
7
- # conf.logger.level = Logger::DEBUG
8
- # you can set deadline(sec)
9
- # conf.deadline = 7200
10
- # set :mainnet if you'd like to use on mainnet!
11
- # conf.default_network = :mainnet # use on mainnet!
12
- end
4
+ Nem.logger.level = Logger::DEBUG
13
5
 
14
6
  # multisig
15
7
  M_PUBLIC_KEY = '6d72b57d2bc199d328e7ea3e24775f7f614760bc18f3f8501cd3daa9870cc40c'
@@ -1,15 +1,7 @@
1
1
  require 'pp'
2
2
  require 'nem'
3
3
 
4
- # Library configuration
5
- Nem.configure do |conf|
6
- conf.logger = Logger.new('./nem-ruby.log')
7
- conf.logger.level = Logger::DEBUG
8
- # you can set deadline(sec)
9
- # conf.deadline = 7200
10
- # set :mainnet if you'd like to use on mainnet!
11
- # conf.default_network = :mainnet # use on mainnet!
12
- end
4
+ Nem.logger.level = Logger::DEBUG
13
5
 
14
6
  # sender
15
7
  A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
@@ -30,3 +22,13 @@ res = tx_endpoint.announce(req)
30
22
 
31
23
  pp "Message: #{res.message}"
32
24
  pp "TransactionHash: #{res.transaction_hash}"
25
+
26
+ # with hexdecimal message
27
+ tx = Nem::Transaction::Transfer.new(B_ADDRESS, 0, 'febaadfooddeadbeaf')
28
+ pp "Fee: #{tx.fee.to_i}"
29
+
30
+ req = Nem::Request::Announce.new(tx, kp)
31
+ res = tx_endpoint.announce(req)
32
+
33
+ pp "Message: #{res.message}"
34
+ pp "TransactionHash: #{res.transaction_hash}"
@@ -1,15 +1,7 @@
1
1
  require 'pp'
2
2
  require 'nem'
3
3
 
4
- # Library configuration
5
- Nem.configure do |conf|
6
- conf.logger = Logger.new('./nem-ruby.log')
7
- conf.logger.level = Logger::DEBUG
8
- # you can set deadline(sec)
9
- # conf.deadline = 7200
10
- # set :mainnet if you'd like to use on mainnet!
11
- # conf.default_network = :mainnet
12
- end
4
+ Nem.logger.level = Logger::DEBUG
13
5
 
14
6
  # sender
15
7
  A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
@@ -1,15 +1,7 @@
1
1
  require 'pp'
2
2
  require 'nem'
3
3
 
4
- # Library configuration
5
- Nem.configure do |conf|
6
- conf.logger = Logger.new('./nem-ruby.log')
7
- conf.logger.level = Logger::DEBUG
8
- # you can set deadline(sec)
9
- # conf.deadline = 7200
10
- # set :mainnet if you'd like to use on mainnet!
11
- # conf.default_network = :mainnet # use on mainnet!
12
- end
4
+ Nem.logger.level = Logger::DEBUG
13
5
 
14
6
  # sender
15
7
  A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
@@ -2,15 +2,17 @@ require 'logger'
2
2
 
3
3
  module Nem
4
4
  module Configuration
5
- DEADLINE = 3600
5
+ DEADLINE = 3600 # 1 hour
6
6
 
7
- attr_accessor :logger, :deadline, :default_network, :debug
7
+ attr_accessor :logger, :debug,
8
+ :default_deadline,
9
+ :default_network
8
10
 
9
11
  def self.extended(base)
10
12
  base.logger = Logger.new($stdout).tap { |l| l.level = Logger::INFO }
11
- base.deadline = DEADLINE
12
- base.default_network = :testnet
13
13
  base.debug = false
14
+ base.default_deadline = DEADLINE
15
+ base.default_network = :testnet
14
16
  end
15
17
 
16
18
  # @yield [self]
@@ -18,7 +20,7 @@ module Nem
18
20
  # Nem.configure do |conf|
19
21
  # conf.logger = Logger.new('path/to/nem-ruby.log')
20
22
  # conf.logger.level = Logger::DEBUG
21
- # conf.deadline = 7200
23
+ # conf.default_deadline = 7200
22
24
  # conf.default_network = :mainnet
23
25
  # end
24
26
  def configure
@@ -121,9 +121,9 @@ module Nem
121
121
  # @see https://nemproject.github.io/#retrieving-mosaics-that-an-account-owns
122
122
  def mosaic_owned(address)
123
123
  request!(:get, '/account/mosaic/owned', address: address) do |res|
124
- res[:data].map do |moa|
125
- Nem::Model::Mosaic.new_from_mosaic(moa)
126
- end
124
+ Nem::Model::MosaicCollection.new(
125
+ res[:data].map { |moa| Nem::Model::Mosaic.new_from_mosaic(moa) }
126
+ )
127
127
  end
128
128
  end
129
129
 
@@ -2,7 +2,6 @@ module Nem
2
2
  module Model
3
3
  # @attr [String] value
4
4
  # @attr [Integer] type
5
- # @attr [String] payload
6
5
  # @attr [String] public_key
7
6
  # @attr [String] private_key
8
7
  class Message
@@ -62,9 +61,14 @@ module Nem
62
61
  bytesize <= 1024
63
62
  end
64
63
 
64
+ # @return [Boolean]
65
+ def hex?
66
+ !!(value =~ /\Afe\h+\Z/)
67
+ end
68
+
65
69
  # @return [Hash]
66
70
  def to_hash
67
- { payload: payload, type: @type }
71
+ { payload: payload, type: type }
68
72
  end
69
73
 
70
74
  # @return [String]
@@ -79,7 +83,7 @@ module Nem
79
83
 
80
84
  # @return [String]
81
85
  def payload
82
- (value =~ /\Afe/ || encrypted?) ? value : value.unpack('H*').first
86
+ (hex? || encrypted?) ? value : value.unpack('H*').first
83
87
  end
84
88
 
85
89
  private
@@ -4,8 +4,7 @@ module Nem
4
4
  include Nem::Mixin::Assignable
5
5
 
6
6
  extend Forwardable
7
-
8
- def_delegators :@mosaic_id, :fqn
7
+ def_delegators :@mosaic_id, :fqn, :namespace_id, :name
9
8
 
10
9
  attr_reader :mosaic_id, :quantity
11
10
 
@@ -12,7 +12,7 @@ module Nem
12
12
  :supply_mutable,
13
13
  :transferable
14
14
 
15
- attr_reader :mosaic_id, :properties, :quantity
15
+ attr_reader :mosaic_id, :quantity, :properties
16
16
 
17
17
  def amount
18
18
  return quantity * (10**properties.divisibility)
@@ -0,0 +1,31 @@
1
+ module Nem
2
+ module Model
3
+ class MosaicCollection
4
+ include Enumerable
5
+ extend Forwardable
6
+ def_delegators :@attachments, :size, :empty?,
7
+ :each, :map, :find, :sort_by
8
+
9
+ attr_reader :attachments
10
+
11
+ # @param [Array] attachments
12
+ def initialize(attachments)
13
+ @attachments = attachments
14
+ end
15
+
16
+ # @param [String] fqn
17
+ # @return [Nem::Model::MosaicAttachment]
18
+ def find_by_fqn(fqn)
19
+ attachments.find {|a| a.fqn == fqn }
20
+ end
21
+
22
+ alias :[] :find_by_fqn
23
+
24
+ # @param [String] namespace_id
25
+ # @return [Nem::Model::MosaicCollection]
26
+ def find_by_namespace_id(namespace_id)
27
+ self.class.new(attachments.select {|a| a.namespace_id == namespace_id })
28
+ end
29
+ end
30
+ end
31
+ end
@@ -14,7 +14,7 @@ module Nem
14
14
  :height
15
15
 
16
16
  def version?(num)
17
- num == 1 ? true : false # TODO: version
17
+ version & 0x00000003 == num ? true : false
18
18
  end
19
19
 
20
20
  def self.new_from_account_transaction(hash)
@@ -40,6 +40,8 @@ module Nem
40
40
  klass.new_from_transaction_meta_data_pair(hash)
41
41
  end
42
42
 
43
+ private
44
+
43
45
  def self.common_part(hash)
44
46
  {
45
47
  timestamp: hash[:timeStamp],
@@ -53,18 +55,11 @@ module Nem
53
55
 
54
56
  def self.common_part_meta_data_pair(hash)
55
57
  meta = hash[:meta]
56
- transaction = hash[:transaction]
57
- {
58
+ common_part(hash[:transaction]).merge(
58
59
  id: meta[:id],
59
60
  hash: meta[:hash] ? meta[:hash][:data] : meta[:data],
60
- height: meta[:height],
61
- timestamp: transaction[:timeStamp],
62
- version: transaction[:version],
63
- type: transaction[:type],
64
- signer: transaction[:signer],
65
- fee: transaction[:fee],
66
- deadline: transaction[:deadline]
67
- }
61
+ height: meta[:height]
62
+ )
68
63
  end
69
64
  end
70
65
  end
@@ -1,13 +1,11 @@
1
1
  module Nem
2
2
  module Request
3
- # @attr [Nem::Struct::Transaction] transaction
3
+ # @attr [Nem::Model::Transaction] transaction
4
4
  # @attr [Nem::Keypair] keypair
5
- # @attr [String] data
6
- # @attr [String] signature
7
5
  # @see https://nemproject.github.io/#requestAnnounce
8
6
  # @see https://nemproject.github.io/#requestPrepareAnnounce
9
7
  class Announce
10
- attr_reader :transaction, :keypair, :data, :signature
8
+ attr_reader :transaction, :keypair
11
9
 
12
10
  def initialize(transaction, keypair)
13
11
  @transaction = transaction
@@ -47,7 +45,7 @@ module Nem
47
45
  type: tx.other_trans.type,
48
46
  fee: tx.other_trans.fee.to_i,
49
47
  timeStamp: Nem::Util.timestamp,
50
- deadline: Nem::Util.deadline(Nem.deadline),
48
+ deadline: Nem::Util.deadline(Nem.default_deadline),
51
49
  signer: tx.signer,
52
50
  version: tx.other_trans.version
53
51
  )
@@ -61,7 +59,7 @@ module Nem
61
59
  type: transaction.type,
62
60
  fee: transaction.fee.to_i,
63
61
  timeStamp: Nem::Util.timestamp,
64
- deadline: Nem::Util.deadline(Nem.deadline),
62
+ deadline: Nem::Util.deadline(Nem.default_deadline),
65
63
  signer: keypair.public,
66
64
  version: transaction.version
67
65
  )
data/lib/nem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nem
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
data/mkdocs.yml ADDED
@@ -0,0 +1,28 @@
1
+ site_url: https://44uk.github.io/nem-ruby/
2
+ site_name: nem-ruby
3
+ site_description: Ruby client library for the NEM Infrastructure Server API
4
+ repo_url: https://github.com/44uk/nem-ruby
5
+ copyright: Copyright &copy; 2017, <a href="https://github.com/44uk">Yoshiyuki Ieyama</a>, <a href="https://twitter.com/44uk_i3">44uk_i3</a>.
6
+ theme: readthedocs
7
+ extra_css:
8
+ - custom.css
9
+ pages:
10
+ - Home: index.md
11
+ - Examples:
12
+ - examples/configure.md
13
+ - examples/nis.md
14
+ - examples/account.md
15
+ - examples/block.md
16
+ - examples/chain.md
17
+ - examples/mosaic.md
18
+ - examples/namespace.md
19
+ - examples/node.md
20
+ - examples/transactions.md
21
+ - examples/define_mosaic_attachment.md
22
+ - examples/timesync.md
23
+ - examples/debug.md
24
+ - examples/local.md
25
+ - examples/apostille.md
26
+ - examples/offline.md
27
+ - examples/util.md
28
+ - About: about.md
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.49'
37
+ spec.add_development_dependency 'rubocop', '~> 0.50'
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiyuki Ieyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-03 00:00:00.000000000 Z
11
+ date: 2018-01-05 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.49'
75
+ version: '0.50'
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.49'
82
+ version: '0.50'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: timecop
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -194,9 +194,30 @@ files:
194
194
  - LICENSE
195
195
  - README.md
196
196
  - Rakefile
197
+ - docs/about.md
198
+ - docs/custom.css
199
+ - docs/examples/account.md
200
+ - docs/examples/apostille.md
201
+ - docs/examples/block.md
202
+ - docs/examples/chain.md
203
+ - docs/examples/configure.md
204
+ - docs/examples/debug.md
205
+ - docs/examples/define_mosaic_attachment.md
206
+ - docs/examples/local.md
207
+ - docs/examples/mosaic.md
208
+ - docs/examples/namespace.md
209
+ - docs/examples/nis.md
210
+ - docs/examples/node.md
211
+ - docs/examples/offline.md
212
+ - docs/examples/timesync.md
213
+ - docs/examples/transactions.md
214
+ - docs/examples/util.md
215
+ - docs/index.md
216
+ - docs/mosaic.md
197
217
  - examples/apostille/audit.rb
198
218
  - examples/apostille/create.rb
199
219
  - examples/apostille/create_private.rb
220
+ - examples/configure.rb
200
221
  - examples/endpoint/account.rb
201
222
  - examples/endpoint/account_local.rb
202
223
  - examples/endpoint/block.rb
@@ -273,6 +294,7 @@ files:
273
294
  - lib/nem/model/message.rb
274
295
  - lib/nem/model/mosaic.rb
275
296
  - lib/nem/model/mosaic_attachment.rb
297
+ - lib/nem/model/mosaic_collection.rb
276
298
  - lib/nem/model/mosaic_definition.rb
277
299
  - lib/nem/model/mosaic_definition_creation_transaction.rb
278
300
  - lib/nem/model/mosaic_id.rb
@@ -326,6 +348,7 @@ files:
326
348
  - lib/nem/util/ed25519.rb
327
349
  - lib/nem/util/serializer.rb
328
350
  - lib/nem/version.rb
351
+ - mkdocs.yml
329
352
  - nem-ruby.gemspec
330
353
  homepage: https://github.com/44uk/nem-ruby
331
354
  licenses: