nem-ruby 0.0.9 → 0.0.10

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: '0280ea3ed19d1f11f874b5443e59eeba0a21eb4fec27e31d578250c74c377730'
4
- data.tar.gz: 3d9621bfe402f975ef08c2265a28dd3132ca86631a0ee14268fb1f5c2e340fa3
3
+ metadata.gz: af0488dcad2793275e0bc42b4613730c63c6d11e6c8c9815605137b1c60788ad
4
+ data.tar.gz: 93ddce86c953c3b220b2d81b24d83d806c05fbbb3e06ece73dac7ef429fcd396
5
5
  SHA512:
6
- metadata.gz: d2983c53b1edb903c83571e2403dee0611848a644b21b3a4f5bbacaabb227a8b08c707ec2d10cdeda2e91be84e346b828ec72c40ad0509e15e9ad71ae117dc09
7
- data.tar.gz: f887982de7c646a1604ad2c790db4f618141190750bf73cdbc912a1bb7a5ab5a569d3e136fb29a380f6ff81d9ee9fbbb92816b6f3fb24d9c30f344d49756eb76
6
+ metadata.gz: 6706e148b2ded5c9443ba9e0d5a5bfeac9d472965d167d0611ed6ca6765a63b4319fe3161a1c52da060bce2bc982ded779af2287b3bfe2abeee6f09604975ddc
7
+ data.tar.gz: 03afec67c11f6a77a6575072fa39dcbc0d875d7feaf1477bcde766adb59f5e2bae8d62c09abd298991c9eb9a55116b4f94462cb1f66f4e2db85fd535c5f43aa2
@@ -181,7 +181,7 @@ tx = Nem::Transaction::MultisigAggregateModification.new(msig_cosignatories, rel
181
181
  pp "Fee: #{tx.fee.to_i}"
182
182
 
183
183
  req = Nem::Request::Announce.new(tx, kp)
184
- res = endpoint.prepare_announce(req)
184
+ res = endpoint.announce(req)
185
185
 
186
186
  pp "Message: #{res.message}"
187
187
  pp "TransactionHash: #{res.transaction_hash}"
@@ -19,6 +19,6 @@ data = req.to_entity[:data]
19
19
  pp data
20
20
 
21
21
  # deserialize data into hash
22
- hash = Nem::Util::Deserializer.deserialize_transaction(data)
22
+ hash = Nem::Util::Deserializer.deserialize(data)
23
23
  pp Nem::Model::Transaction.new_from_account_transaction(hash)
24
24
  ```
@@ -25,6 +25,9 @@ pp tx_endpoint.find(hash)
25
25
  hash = '4185cad053f0bc7a2b3b9e5adc493e81a5af2f0a431f3d34ba2a25c937731629'
26
26
  pp tx_endpoint.find(hash)
27
27
 
28
+ # if tx has a message, convert hex to string
29
+ # Nem::Util::Convert.hex_to_utf8(res.message.value)
30
+
28
31
  # aggregate (multisig)
29
32
  hash = 'f7d385a4c8b78d8a6a91c7b778df4ae793394c9c8bfeeca1393bf43770328a06'
30
33
  pp tx_endpoint.find(hash)
@@ -20,9 +20,11 @@ msig_cosigratories = [
20
20
  Nem::Transaction::MultisigCosignatoryModification.new(:add, B_PUBLIC_KEY)
21
21
  ]
22
22
  relative_change = 1
23
- mtx = Nem::Transaction::MultisigAggregateModification.new(msig_cosigratories, relative_change)
23
+ mtx = Nem::Transaction::MultisigAggregateModification.new(
24
+ msig_cosigratories,
25
+ relative_change
26
+ )
24
27
  tx = Nem::Transaction::Multisig.new(mtx, M_PUBLIC_KEY)
25
- tx_endpoint = Nem::Endpoint::Transaction.new(node)
26
28
 
27
29
  req = Nem::Request::Announce.new(tx, kp)
28
30
  res = tx_endpoint.announce(req)
@@ -17,11 +17,14 @@ msig_cosignatories = [
17
17
  Nem::Transaction::MultisigCosignatoryModification.new(:add, A_PUBLIC_KEY)
18
18
  ]
19
19
  relative_change = 1
20
- tx = Nem::Transaction::MultisigAggregateModification.new(msig_cosignatories, relative_change)
20
+ tx = Nem::Transaction::MultisigAggregateModification.new(
21
+ msig_cosignatories,
22
+ relative_change
23
+ )
21
24
  pp "Fee: #{tx.fee.to_i}"
22
25
 
23
26
  req = Nem::Request::Announce.new(tx, kp)
24
- res = tx_endpoint.prepare_announce(req)
27
+ res = tx_endpoint.announce(req)
25
28
 
26
29
  pp "Message: #{res.message}"
27
30
  pp "TransactionHash: #{res.transaction_hash}"
@@ -13,7 +13,7 @@ A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b83421
13
13
  B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
14
14
 
15
15
  kp = Nem::Keypair.new(A_PRIVATE_KEY)
16
- node = Nem::Node.new
16
+ node = Nem::Node.new(host: 'bigalice2.nem.ninja')
17
17
  tx_endpoint = Nem::Endpoint::Transaction.new(node)
18
18
 
19
19
  ttx = Nem::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
@@ -21,7 +21,7 @@ tx = Nem::Transaction::Multisig.new(ttx, M_PUBLIC_KEY)
21
21
  pp "Fee: #{tx.fee.to_i}"
22
22
 
23
23
  req = Nem::Request::Announce.new(tx, kp)
24
- res = tx_endpoint.prepare_announce(req)
24
+ res = tx_endpoint.announce(req)
25
25
 
26
26
  pp "Message: #{res.message}"
27
27
  pp "TransactionHash: #{res.transaction_hash}"
@@ -22,5 +22,5 @@ data = req.to_entity[:data]
22
22
  pp data
23
23
 
24
24
  # deserialize data into hash
25
- hash = Nem::Util::Deserializer.deserialize_transaction(data)
25
+ hash = Nem::Util::Deserializer.deserialize(data)
26
26
  pp Nem::Model::Transaction.new_from_account_transaction(hash)
@@ -32,6 +32,7 @@ module Nem
32
32
  bin_pk = (public_key || @public_key).scan(/../).map(&:hex).pack('C*')
33
33
  @value = Nem::Util::Ed25519.encrypt(bin_sk, bin_pk, value)
34
34
  @type = TYPE_ENCRYPTED
35
+ self
35
36
  end
36
37
 
37
38
  def decrypt!
@@ -39,6 +40,7 @@ module Nem
39
40
  bin_pk = (public_key || @public_key).scan(/../).map(&:hex).pack('C*')
40
41
  @value = Nem::Util::Ed25519.decrypt(bin_sk, bin_pk, payload)
41
42
  @type = TYPE_PLAIN
43
+ self
42
44
  end
43
45
 
44
46
  # @return [Boolean]
@@ -8,7 +8,7 @@ module Nem
8
8
 
9
9
  attr_reader :modifications, :relative_change, :min_cosignatories
10
10
 
11
- def initialize(modifications, relative_change, timestamp: nil, deadline: nil, network: nil)
11
+ def initialize(modifications, relative_change = 0, timestamp: nil, deadline: nil, network: nil)
12
12
  @modifications = modifications
13
13
  @relative_change = relative_change
14
14
 
@@ -19,6 +19,14 @@ module Nem
19
19
  @deadline = deadline || Time.now + Nem.default_deadline
20
20
  end
21
21
 
22
+ def has_relative_change?
23
+ relative_change != 0
24
+ end
25
+
26
+ def version
27
+ network(hex: true) + (has_relative_change? ? 2 : 1)
28
+ end
29
+
22
30
  # attributes must be CAMEL CASE for NIS params
23
31
  # @return [Hash]
24
32
  def to_hash
@@ -4,27 +4,39 @@ module Nem
4
4
  # Deserialize a transaction object
5
5
  # @param [String] serialized
6
6
  # @return [Hash]
7
- def self.deserialize_transaction(serialized)
7
+ def self.deserialize(serialized)
8
8
  s = Nem::Util::Convert.hex2ua(serialized)
9
+ deserialize_transaction(s)
10
+ end
11
+
12
+ private
13
+
14
+ def self.switch_method(type)
15
+ case type
16
+ when 0x0101 then method(:deserialize_transfer)
17
+ when 0x0801 then method(:deserialize_importance_transfer)
18
+ when 0x1001 then method(:deserialize_multisig_aggregate_modification)
19
+ when 0x1002 then method(:deserialize_multisig_signature)
20
+ when 0x1004 then method(:deserialize_multisig)
21
+ when 0x2001 then method(:deserialize_provision_namespace)
22
+ when 0x4001 then method(:deserialize_mosaic_definition_creation)
23
+ when 0x4002 then method(:deserialize_mosaic_supply_change)
24
+ else raise "Not implemented entity type: #{type}"
25
+ end
26
+ end
27
+
28
+ # Deserialize a transaction object
29
+ # @param [String] serialized
30
+ # @return [Hash]
31
+ def self.deserialize_transaction(s)
9
32
  common = s[0, 60]
10
33
  specific = s[60, s.size]
11
34
  type = deserialize_int(common[0, 4])
12
- method = case type
13
- when 0x0101 then method(:deserialize_transfer)
14
- when 0x0801 then method(:deserialize_importance_transfer)
15
- when 0x1001 then method(:deserialize_multisig_aggregate_modification)
16
- when 0x1002 then method(:deserialize_multisig_signature)
17
- when 0x1004 then method(:deserialize_multisig)
18
- when 0x2001 then method(:deserialize_provision_namespace)
19
- when 0x4001 then method(:deserialize_mosaic_definition_creation)
20
- when 0x4002 then method(:deserialize_mosaic_supply_change)
21
- else raise "Not implemented entity type: #{type}"
22
- end
35
+ method = switch_method(type)
36
+ # require 'pry'; binding.pry
23
37
  deserialize_common(common).merge(method.call(specific))
24
38
  end
25
39
 
26
- private
27
-
28
40
  # Deserialize a transfer transaction object
29
41
  # @param [String] serialized
30
42
  # @return [Hash]
@@ -82,10 +94,30 @@ module Nem
82
94
  # @param [String] serialized
83
95
  # @return [Hash]
84
96
  def self.deserialize_multisig_aggregate_modification(s)
85
- raise 'Not yet implimented.'
86
- # TODO: deserializing
87
- tx = {}
88
- tx
97
+ mods = []
98
+ mod_count = deserialize_int(s[0, 4])
99
+ offset = 4
100
+ mod_count.times do |i|
101
+ mod_len = deserialize_int(s[offset, 4])
102
+ mods << {
103
+ modificationType: deserialize_int(s[offset + 4, 4]),
104
+ cosignatoryAccount: deserialize_hex(s[offset + 12, 32])
105
+ }
106
+ offset += 4 + mod_len
107
+ end
108
+ tx = {
109
+ modifications: mods,
110
+ }
111
+
112
+ if s[offset + 4, 4]
113
+ tx.merge(
114
+ minCosignatories: {
115
+ relativeChange: deserialize_int(s[offset + 4, 4])
116
+ }
117
+ )
118
+ else
119
+ tx
120
+ end
89
121
  end
90
122
 
91
123
  # Deserialize a multisig signature transaction object
@@ -102,10 +134,10 @@ module Nem
102
134
  # @param [String] serialized
103
135
  # @return [Hash]
104
136
  def self.deserialize_multisig(s)
105
- raise 'Not yet implimented.'
106
- # TODO: deserializing
107
- tx = {}
108
- tx
137
+ msig_len = deserialize_int(s[0, 4])
138
+ inner = s[4, msig_len]
139
+ inner_tx = deserialize_transaction(inner)
140
+ { otherTrans: inner_tx }
109
141
  end
110
142
 
111
143
  # Deserialize a provision namespace transaction object
@@ -60,17 +60,9 @@ module Nem
60
60
  end
61
61
  a.concat mods
62
62
 
63
- # The following part describes the minimum cosignatories modification.
64
- # The part is optional. Version 1 aggregate modification transactions should omit this part.
65
- # Version 2 aggregate modification transactions with no minimum cosignatories modification
66
- # should only write the length field with value 0x00, 0x00, 0x00, 0x00.
67
- if true # only version2
68
- if entity[:minCosignatories][:relativeChange] > 0
69
- a.concat serialize_int(4)
70
- a.concat serialize_int(entity[:minCosignatories][:relativeChange])
71
- else
72
- a.concat [0, 0, 0, 0]
73
- end
63
+ if true # TODO: append only version2
64
+ a.concat serialize_int(4)
65
+ a.concat serialize_int(entity[:minCosignatories][:relativeChange])
74
66
  end
75
67
  a
76
68
  end
data/lib/nem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nem
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
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.9
4
+ version: 0.0.10
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-02-17 00:00:00.000000000 Z
11
+ date: 2018-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler