nem-ruby 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 748ca73f087e9f567496b5c698b6d1b81bbbd192601e8bbdb17efdb202eede92
4
- data.tar.gz: 2e9f12cc146d126bcd67b37b68dacaac5c62fbc02e36923ce3e1fdbffd73831f
3
+ metadata.gz: 1a80d96a7c25cccb9215c5f05af2651ab5573a7f2f767a420a1a97cb156c4cbb
4
+ data.tar.gz: 6ef2b946c1088bdf76828b4252e83f15d57a7489de035fca2cedbaa920ac3db8
5
5
  SHA512:
6
- metadata.gz: 9b7d3becf508d3eff05b8031b443bfc36673a703cc68cd867f0c18c891802e1a2e9d02677875122ddb595c822e75db63691c9f0a2b1938cc1f1ca62f15bd0240
7
- data.tar.gz: a0e386cd6014fc1e6f24908bd6129cc8f44c1789e098a076153f26ba85cde49f8dc485fd1f5ffa3bfca4642c48194ab8e5d0516d6552268fbd484979484f3a85
6
+ metadata.gz: fc780b27ec580dbe40ecd22de3972b98794fefa751f194012c49f7a15682ee68feb998e26c932e80dc0698037fe256532210c82abba5a501856c232b7a7e1a9c
7
+ data.tar.gz: 6b01deeb6257603d93fd406ffe90ab54b97f33234cc2929e411ac8d6e3009c12112f709b1e52716f324c3ac2d44cfbc0d59726e368573f36c459ef781e38d639
@@ -12,42 +12,30 @@ B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
12
12
  kp = Nem::Keypair.new(A_PRIVATE_KEY)
13
13
  node = Nem::Node.new(host: 'bigalice2.nem.ninja')
14
14
  tx_endpoint = Nem::Endpoint::Transaction.new(node)
15
- # ns_endpoint = Nem::Endpoint::Namespace.new(node)
16
15
 
17
- # TODO:
16
+ tx = Nem::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
18
17
 
19
- # fetch mosaic definition
20
- # mo_dmdps = ns_endpoint.mosaic_definition('kon')
21
- # mo_def = mo_dmdps.first.mosaic
18
+ tx.mosaics << Nem::Mosaic::Xem.new(1)
22
19
 
23
- # define custom mosaic attachment
24
- # class MyMosaic < Nem::Model::MosaicAttachment
25
- # def initialize(quantity)
26
- # # set values what you defined
27
- # mosaic_id = Nem::Model::MosaicId.new(
28
- # namespace_id: 'my',
29
- # name: 'mosaic'
30
- # )
31
- # # set values what you defined
32
- # properties = Nem::Model::MosaicProperties.new(
33
- # divisibility: 3,
34
- # initial_supply: 123_456_789
35
- # )
36
- # super(
37
- # mosaic_id: mosaic_id,
38
- # properties: properties,
39
- # quantity: quantity
40
- # )
41
- # end
42
- # end
20
+ # fetch mosaic definition
21
+ ns_endpoint = Nem::Endpoint::Namespace.new(node)
22
+ mo_def = ns_endpoint.mosaic_definition('kon').first
23
+ moa = Nem::Model::MosaicAttachment.new(
24
+ mosaic_id: mo_def.id,
25
+ properties: mo_def.properties,
26
+ quantity: 1
27
+ )
28
+ tx.mosaics << moa
43
29
 
44
30
  # define custom mosaic attachment
45
31
  class KonHeart < Nem::Model::MosaicAttachment
46
32
  def initialize(quantity)
33
+ # set values what you defined
47
34
  mosaic_id = Nem::Model::MosaicId.new(
48
35
  namespace_id: 'kon',
49
36
  name: 'heart'
50
37
  )
38
+ # set values what you defined
51
39
  properties = Nem::Model::MosaicProperties.new(
52
40
  divisibility: 3,
53
41
  initial_supply: 100_000_000
@@ -59,10 +47,8 @@ class KonHeart < Nem::Model::MosaicAttachment
59
47
  )
60
48
  end
61
49
  end
62
-
63
- tx = Nem::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
64
- tx.mosaics << Nem::Mosaic::Xem.new(1)
65
50
  tx.mosaics << KonHeart.new(1)
51
+
66
52
  pp "Fee: #{tx.fee.to_i}"
67
53
 
68
54
  req = Nem::Request::Announce.new(tx, kp)
@@ -10,7 +10,7 @@ module Nem
10
10
  attr_reader :mosaic_id, :quantity
11
11
 
12
12
  def self.new_from_mosaic(hash)
13
- mosaic_id = Nem::Model::MosaicId.new_from_mosaic_id(hash[:mosaicId])
13
+ mosaic_id = MosaicId.new_from_mosaic_id(hash[:mosaicId])
14
14
  new(
15
15
  quantity: hash[:quantity],
16
16
  mosaic_id: mosaic_id
@@ -19,9 +19,9 @@ module Nem
19
19
  :meta_id
20
20
 
21
21
  def self.new_from_mosaic_definition(hash)
22
- id = Nem::Model::MosaicId.new_from_mosaic_id(hash[:id])
23
- props = Nem::Model::MosaicProperties.new_from_mosaic_properties(hash[:properties])
24
- levy = Nem::Model::MosaicLevy.new_from_mosaic_levy(hash[:levy])
22
+ id = MosaicId.new_from_mosaic_id(hash[:id])
23
+ props = MosaicProperties.new_from_mosaic_properties(hash[:properties])
24
+ levy = MosaicLevy.new_from_mosaic_levy(hash[:levy])
25
25
  new(
26
26
  creator: hash[:creator],
27
27
  description: hash[:description],
@@ -34,13 +34,13 @@ module Nem
34
34
  def self.new_from_mosaic_definition_meta_data_pair(hash)
35
35
  meta = hash[:meta]
36
36
  mosaic = hash[:mosaic]
37
- id = Nem::Model::MosaicId.new_from_mosaic_id(mosaic[:id])
38
- props = Nem::Model::MosaicProperties.new_from_mosaic_properties(mosaic[:properties])
39
- levy = Nem::Model::MosaicLevy.new_from_mosaic_levy(mosaic[:levy])
37
+ id = MosaicId.new_from_mosaic_id(mosaic[:id])
38
+ props = MosaicProperties.new_from_mosaic_properties(mosaic[:properties])
39
+ levy = MosaicLevy.new_from_mosaic_levy(mosaic[:levy])
40
40
  new(
41
41
  meta_id: meta[:id],
42
- creator: hash[:creator],
43
- description: hash[:description],
42
+ creator: mosaic[:creator],
43
+ description: mosaic[:description],
44
44
  id: id,
45
45
  properties: props,
46
46
  levy: levy
@@ -10,7 +10,7 @@ module Nem
10
10
 
11
11
  def self.new_from_mosaic_levy(hash)
12
12
  return nil if hash.empty?
13
- mosaic_id = Nem::Model::MosaicId.new_from_mosaic_id(hash[:mosaicId])
13
+ mosaic_id = MosaicId.new_from_mosaic_id(hash[:mosaicId])
14
14
  new(
15
15
  fee: hash[:fee],
16
16
  recipient: hash[:recipient],
@@ -7,7 +7,7 @@ module Nem
7
7
 
8
8
  def self.new_from_mosaic_owned(hash)
9
9
  mosaics = hash[:data].inject({}) do |memo, mos|
10
- mosaic = Nem::Model::Mosaic.new_from_mosaic(mos)
10
+ mosaic = Mosaic.new_from_mosaic(mos)
11
11
  memo[mosaic.fqn] = mosaic
12
12
  memo
13
13
  end
@@ -10,7 +10,7 @@ module Nem
10
10
  attr_reader :id, :supply
11
11
 
12
12
  def self.new_from_mosaic_supply(hash)
13
- id = Nem::Model::MosaicId.new_from_mosaic_id(hash[:mosaicId])
13
+ id = MosaicId.new_from_mosaic_id(hash[:mosaicId])
14
14
  new(
15
15
  id: id,
16
16
  supply: hash[:supply]
@@ -10,7 +10,7 @@ module Nem
10
10
  amount: transaction[:amount],
11
11
  )
12
12
  unless transaction[:message].empty?
13
- attrs[:message] = Nem::Model::Message.new_from_message(transaction[:message])
13
+ attrs[:message] = Message.new_from_message(transaction[:message])
14
14
  end
15
15
  if transaction[:mosaics]
16
16
  attrs[:mosaics] = transaction[:mosaics].map do |mo|
@@ -1,5 +1,11 @@
1
1
  module Nem
2
2
  module Transaction
3
+ # @attr [Integer] type
4
+ # @attr [Integer] fee
5
+ # @attr [Integer] timestamp
6
+ # @attr [Integer] deadline
7
+ # @attr [String] signer
8
+ # @attr [String] signature
3
9
  class Base
4
10
  attr_reader :type, :fee,
5
11
  :timestamp, :deadline, :signer, :signature
@@ -33,6 +39,7 @@ module Nem
33
39
  end
34
40
 
35
41
  # it can be override by child class
42
+ # @return [Integer]
36
43
  def version
37
44
  network(hex: true) + 1
38
45
  end
@@ -21,6 +21,7 @@ module Nem
21
21
  end
22
22
 
23
23
  # attributes must be CAMEL CASE for NIS params
24
+ # @return [Hash]
24
25
  def to_hash
25
26
  {
26
27
  mode: parse_mode,
@@ -20,6 +20,7 @@ module Nem
20
20
  end
21
21
 
22
22
  # attributes must be CAMEL CASE for NIS params
23
+ # @return [Hash]
23
24
  def to_hash
24
25
  {
25
26
  mosaicDefinition: mosaic_definition.to_hash,
@@ -23,6 +23,7 @@ module Nem
23
23
  end
24
24
 
25
25
  # attributes must be CAMEL CASE for NIS params
26
+ # @return [Hash]
26
27
  def to_hash
27
28
  {
28
29
  mosaicId: mosaic_id.to_hash,
@@ -18,6 +18,7 @@ module Nem
18
18
  end
19
19
 
20
20
  # attributes must be CAMEL CASE for NIS params
21
+ # @return [Hash]
21
22
  def to_hash
22
23
  {
23
24
  otherTrans: other_trans.to_hash,
@@ -2,6 +2,7 @@ module Nem
2
2
  module Transaction
3
3
  # @attr [Array <Nem::Model::MultisigCosignatoryModification>] modifications
4
4
  # @attr [Interger] relative_change
5
+ # @attr [Interger] min_cosignatories
5
6
  class MultisigAggregateModification < Nem::Transaction::Base
6
7
  TYPE = 0x1001 # 4097 (multisig aggregate modification transfer transaction)
7
8
 
@@ -17,6 +18,7 @@ module Nem
17
18
  end
18
19
 
19
20
  # attributes must be CAMEL CASE for NIS params
21
+ # @return [Hash]
20
22
  def to_hash
21
23
  {
22
24
  modifications: modifications.map(&:to_hash),
@@ -1,5 +1,7 @@
1
1
  module Nem
2
2
  module Transaction
3
+ # @attr [Interger] modification_type
4
+ # @attr [Interger] cosignatory_account
3
5
  class MultisigCosignatoryModification
4
6
  attr_reader :modification_type, :cosignatory_account
5
7
 
@@ -12,6 +14,7 @@ module Nem
12
14
  end
13
15
 
14
16
  # attributes must be CAMEL CASE for NIS params
17
+ # @return [Hash]
15
18
  def to_hash
16
19
  {
17
20
  modificationType: parse_type,
@@ -19,6 +19,7 @@ module Nem
19
19
  end
20
20
 
21
21
  # attributes must be CAMEL CASE for NIS params
22
+ # @return [Hash]
22
23
  def to_hash
23
24
  {
24
25
  otherHash: { data: other_hash },
@@ -1,14 +1,14 @@
1
1
  module Nem
2
2
  module Transaction
3
+ # @attr [String] new_part
4
+ # @attr [String] parent
5
+ # @attr [String] rental_fee_sink
6
+ # @attr [Integer] rental_fee
3
7
  class ProvisionNamespace < Nem::Transaction::Base
4
8
  TYPE = 0x2001 # 8193 (provision namespace transaction)
5
9
 
6
10
  attr_reader :new_part, :parent, :rental_fee_sink, :rental_fee
7
11
 
8
- # @attr [String] new_part
9
- # @attr [String] parent
10
- # @attr [String] rental_fee_sink
11
- # @attr [Integer] rental_fee
12
12
  def initialize(new_part, parent = nil, network: nil)
13
13
  @new_part = new_part
14
14
  @parent = parent
@@ -20,15 +20,18 @@ module Nem
20
20
  @fee = Nem::Fee::ProvisionNamespace.new(self)
21
21
  end
22
22
 
23
+ # @return [Boolean]
23
24
  def root?
24
25
  !!(@parent == nil)
25
26
  end
26
27
 
28
+ # @return [Boolean]
27
29
  def sub?
28
30
  !!(@parent && @new_part)
29
31
  end
30
32
 
31
33
  # attributes must be CAMEL CASE for NIS params
34
+ # @return [Hash]
32
35
  def to_hash
33
36
  {
34
37
  newPart: new_part,
@@ -26,10 +26,12 @@ module Nem
26
26
  @fee = Nem::Fee::Transfer.new(self)
27
27
  end
28
28
 
29
+ # @return [Boolean]
29
30
  def has_message?
30
31
  @message.bytesize > 0
31
32
  end
32
33
 
34
+ # @return [Boolean]
33
35
  def has_mosaics?
34
36
  @mosaics.size > 0
35
37
  end
@@ -39,6 +41,8 @@ module Nem
39
41
  end
40
42
 
41
43
  # attributes must be CAMEL CASE for NIS params
44
+ # @return [Hash]
45
+ # Mosaics need to be sorted by fqn. if not it will occur FAILURE_SIGNATURE_NOT_VERIFIABLE
42
46
  def to_hash
43
47
  tmp = {
44
48
  amount: amount * 1_000_000,
@@ -46,7 +50,9 @@ module Nem
46
50
  message: message.to_hash
47
51
  }
48
52
  unless mosaics.empty?
49
- tmp[:mosaics] = mosaics.map do |moa|
53
+ tmp[:mosaics] = mosaics
54
+ .sort_by { |mo| mo.fqn }
55
+ .map do |moa|
50
56
  {
51
57
  mosaicId: {
52
58
  namespaceId: moa.mosaic_id.namespace_id,
@@ -33,16 +33,38 @@ module Nem
33
33
  tx[:recipient] = deserialize_a(s[4, 40])
34
34
  tx[:amount] = deserialize_int(s[44, 8])
35
35
  tx[:message] = {}
36
- message_len = deserialize_int(s[52, 4])
37
- if message_len > 0
38
- # s[60, 4] # length of payload
36
+ msg_len = deserialize_int(s[52, 4])
37
+ if msg_len > 0
38
+ payload_len = deserialize_int(s[60, 4])
39
39
  tx[:message] = {
40
40
  type: deserialize_int(s[56, 4]),
41
- payload: Nem::Util::Convert.hex_to_utf8(deserialize_hex(s[64, s.size]))
41
+ payload: Nem::Util::Convert.hex_to_utf8(deserialize_hex(s[64, payload_len]))
42
42
  }
43
43
  else
44
44
  tx[:message] = { type: 1, payload: '' }
45
45
  end
46
+
47
+ mosaic_cnt = deserialize_int(s[56 + msg_len, 4])
48
+ return tx unless mosaic_cnt
49
+
50
+ # mosaic section
51
+ tx[:mosaics] = []
52
+ offset = 0
53
+ mosaic_cnt.times do |i|
54
+ mo_len = deserialize_int(s[offset + 60 + msg_len, 4])
55
+ # ns_len = deserialize_int(s[offset+64+msg_len, 4])
56
+ ns_name_len = deserialize_int(s[offset + 68 + msg_len, 4])
57
+ mo_name_len = deserialize_int(s[offset + 72 + msg_len + ns_name_len, 4])
58
+ ns = Nem::Util::Convert.hex_to_utf8 deserialize_hex(s[offset + 72 + msg_len, ns_name_len])
59
+ name = Nem::Util::Convert.hex_to_utf8 deserialize_hex(s[offset + 76 + msg_len + ns_name_len, mo_name_len])
60
+ quantity = deserialize_int(s[offset + 76 + msg_len + ns_name_len + mo_name_len, 8])
61
+ attachment = {
62
+ mosaicId: { namespaceId: ns, name: name },
63
+ quantity: quantity
64
+ }
65
+ tx[:mosaics] << attachment
66
+ offset += mo_len + 4
67
+ end
46
68
  tx
47
69
  end
48
70
 
@@ -180,10 +180,13 @@ module Nem
180
180
 
181
181
  # @param [Nem::Struct::Mosaic] mosaic
182
182
  # @return [Array]
183
- def self.serialize_mosaic_and_quantity(mosaic_attachment)
183
+ def self.serialize_mosaic_attachment(mosaic_attachment)
184
184
  a = []
185
- a.concat serialize_mosaic_id(mosaic_attachment[:mosaicId])
186
- a.concat serialize_long(mosaic_attachment[:quantity])
185
+ mosaic_id = serialize_mosaic_id(mosaic_attachment[:mosaicId])
186
+ quantity = serialize_long(mosaic_attachment[:quantity])
187
+ a.concat serialize_int((mosaic_id + quantity).size)
188
+ a.concat mosaic_id
189
+ a.concat quantity
187
190
  end
188
191
 
189
192
  # @param [Array <Nem::Struct::Mosaic>] entities
@@ -192,9 +195,8 @@ module Nem
192
195
  a = []
193
196
  a.concat serialize_int(entities.size)
194
197
  mosaics = entities.inject([]) do |memo, ent|
195
- memo.concat serialize_mosaic_and_quantity(ent)
198
+ memo.concat serialize_mosaic_attachment(ent)
196
199
  end
197
- a.concat serialize_int(mosaics.size)
198
200
  a.concat mosaics
199
201
  end
200
202
 
data/lib/nem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nem
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
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.3
4
+ version: 0.0.4
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-29 00:00:00.000000000 Z
11
+ date: 2017-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler