nem-ruby 0.0.10 → 0.0.11
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 +5 -5
- data/lib/nem/mixin/mosaic_attachable.rb +1 -1
- data/lib/nem/transaction/transfer.rb +1 -1
- data/lib/nem/util/deserializer.rb +86 -89
- data/lib/nem/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a3d08ddab8d97a89125da8160e6f7e1495652eab
|
4
|
+
data.tar.gz: f58d5a8984b9e9ba2b059e4439b600aa13b3eea2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2a60386d49ef6345fa6a7cdb421ea28b3b57075d85bc31fcf23a231e76ce63e752fe82ab44e0d43240fee03c4a182aa0d35694439cfbf320db7d21cd7fcc668
|
7
|
+
data.tar.gz: bb4a8a197890bfbc11cf413cdaa0cfbcc265bacc4298b94b61e0b1ec18e86136a92ffc26431e81dfff2986351a2958e01918d498a84419eff751a56fd42d5dea
|
@@ -5,71 +5,92 @@ module Nem
|
|
5
5
|
# @param [String] serialized
|
6
6
|
# @return [Hash]
|
7
7
|
def self.deserialize(serialized)
|
8
|
-
s =
|
9
|
-
|
8
|
+
s = serialized.scan(/../)
|
9
|
+
transaction(s)
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
+
def self.transaction(s)
|
15
|
+
comm = s[0, 60]
|
16
|
+
spec = s[60, s.size]
|
17
|
+
type = hexa2int(comm[0, 4])
|
18
|
+
method = switch_method(type)
|
19
|
+
common(comm).merge(method.call(spec))
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.hexa2int(hexa)
|
23
|
+
[hexa.join].pack('H*').unpack('i*').first
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.hexa2ascii(hexa)
|
27
|
+
hexa.inject('') { |memo, el| memo << el.hex.chr }
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.hexa2utf8(hexa)
|
31
|
+
[hexa.join].pack('H*').force_encoding('UTF-8')
|
32
|
+
end
|
33
|
+
|
14
34
|
def self.switch_method(type)
|
15
35
|
case type
|
16
|
-
when 0x0101 then method(:
|
17
|
-
when 0x0801 then method(:
|
18
|
-
when 0x1001 then method(:
|
19
|
-
when 0x1002 then method(:
|
20
|
-
when 0x1004 then method(:
|
21
|
-
when 0x2001 then method(:
|
22
|
-
when 0x4001 then method(:
|
23
|
-
when 0x4002 then method(:
|
36
|
+
when 0x0101 then method(:transfer)
|
37
|
+
when 0x0801 then method(:importance_transfer)
|
38
|
+
when 0x1001 then method(:multisig_aggregate_modification)
|
39
|
+
when 0x1002 then method(:multisig_signature)
|
40
|
+
when 0x1004 then method(:multisig)
|
41
|
+
when 0x2001 then method(:provision_namespace)
|
42
|
+
when 0x4001 then method(:mosaic_definition_creation)
|
43
|
+
when 0x4002 then method(:mosaic_supply_change)
|
24
44
|
else raise "Not implemented entity type: #{type}"
|
25
45
|
end
|
26
46
|
end
|
27
47
|
|
28
|
-
# Deserialize
|
48
|
+
# Deserialize transaction common part
|
29
49
|
# @param [String] serialized
|
30
50
|
# @return [Hash]
|
31
|
-
def self.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
51
|
+
def self.common(s)
|
52
|
+
{
|
53
|
+
type: hexa2int(s[0, 4]),
|
54
|
+
version: hexa2int(s[4, 4]),
|
55
|
+
timeStamp: hexa2int(s[8, 4]),
|
56
|
+
signer: s[16, 32].join,
|
57
|
+
fee: hexa2int(s[48, 8]),
|
58
|
+
deadline: hexa2int(s[56, 4])
|
59
|
+
}
|
38
60
|
end
|
39
61
|
|
40
62
|
# Deserialize a transfer transaction object
|
41
63
|
# @param [String] serialized
|
42
64
|
# @return [Hash]
|
43
|
-
def self.
|
65
|
+
def self.transfer(s)
|
44
66
|
tx = {}
|
45
|
-
tx[:recipient] =
|
46
|
-
tx[:amount] =
|
67
|
+
tx[:recipient] = hexa2ascii(s[4, 40])
|
68
|
+
tx[:amount] = hexa2int(s[44, 8])
|
47
69
|
tx[:message] = {}
|
48
|
-
msg_len =
|
70
|
+
msg_len = hexa2int(s[52, 4])
|
49
71
|
if msg_len > 0
|
50
|
-
payload_len =
|
72
|
+
payload_len = hexa2int(s[60, 4])
|
51
73
|
tx[:message] = {
|
52
|
-
type:
|
53
|
-
payload:
|
74
|
+
type: hexa2int(s[56, 4]),
|
75
|
+
payload: hexa2utf8(s[64, payload_len])
|
54
76
|
}
|
55
77
|
else
|
56
78
|
tx[:message] = { type: 1, payload: '' }
|
57
79
|
end
|
58
80
|
|
59
|
-
mosaic_cnt =
|
81
|
+
mosaic_cnt = hexa2int(s[56 + msg_len, 4])
|
60
82
|
return tx unless mosaic_cnt
|
61
83
|
|
62
84
|
# mosaic section
|
63
85
|
tx[:mosaics] = []
|
64
86
|
offset = 0
|
65
87
|
mosaic_cnt.times do |i|
|
66
|
-
mo_len =
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
quantity = deserialize_int(s[offset + 76 + msg_len + ns_name_len + mo_name_len, 8])
|
88
|
+
mo_len = hexa2int(s[offset + 60 + msg_len, 4])
|
89
|
+
ns_name_len = hexa2int(s[offset + 68 + msg_len, 4])
|
90
|
+
mo_name_len = hexa2int(s[offset + 72 + msg_len + ns_name_len, 4])
|
91
|
+
ns = hex2ascii(s[offset + 72 + msg_len, ns_name_len])
|
92
|
+
name = hex2ascii(s[offset + 76 + msg_len + ns_name_len, mo_name_len])
|
93
|
+
quantity = hexa2int(s[offset + 76 + msg_len + ns_name_len + mo_name_len, 8])
|
73
94
|
attachment = {
|
74
95
|
mosaicId: { namespaceId: ns, name: name },
|
75
96
|
quantity: quantity
|
@@ -83,25 +104,25 @@ module Nem
|
|
83
104
|
# Deserialize a importance transaction object
|
84
105
|
# @param [String] serialized
|
85
106
|
# @return [Hash]
|
86
|
-
def self.
|
107
|
+
def self.importance_transfer(s)
|
87
108
|
{
|
88
|
-
mode:
|
89
|
-
remoteAccount:
|
109
|
+
mode: hexa2int(s[0, 4]),
|
110
|
+
remoteAccount: s[8, 32].join
|
90
111
|
}
|
91
112
|
end
|
92
113
|
|
93
114
|
# Deserialize a multisig aggregate modification transaction object
|
94
115
|
# @param [String] serialized
|
95
116
|
# @return [Hash]
|
96
|
-
def self.
|
117
|
+
def self.multisig_aggregate_modification(s)
|
97
118
|
mods = []
|
98
|
-
mod_count =
|
119
|
+
mod_count = hexa2int(s[0, 4])
|
99
120
|
offset = 4
|
100
121
|
mod_count.times do |i|
|
101
|
-
mod_len =
|
122
|
+
mod_len = hexa2int(s[offset, 4])
|
102
123
|
mods << {
|
103
|
-
modificationType:
|
104
|
-
cosignatoryAccount:
|
124
|
+
modificationType: hexa2int(s[offset + 4, 4]),
|
125
|
+
cosignatoryAccount: s[offset + 12, 32].join
|
105
126
|
}
|
106
127
|
offset += 4 + mod_len
|
107
128
|
end
|
@@ -112,7 +133,7 @@ module Nem
|
|
112
133
|
if s[offset + 4, 4]
|
113
134
|
tx.merge(
|
114
135
|
minCosignatories: {
|
115
|
-
relativeChange:
|
136
|
+
relativeChange: hexa2int(s[offset + 4, 4])
|
116
137
|
}
|
117
138
|
)
|
118
139
|
else
|
@@ -123,36 +144,36 @@ module Nem
|
|
123
144
|
# Deserialize a multisig signature transaction object
|
124
145
|
# @param [String] serialized
|
125
146
|
# @return [Hash]
|
126
|
-
def self.
|
147
|
+
def self.multisig_signature(s)
|
127
148
|
{
|
128
|
-
otherHash: { data:
|
129
|
-
otherAccount:
|
149
|
+
otherHash: { data: s[8, 32].join },
|
150
|
+
otherAccount: hexa2ascii(s[44, 40])
|
130
151
|
}
|
131
152
|
end
|
132
153
|
|
133
154
|
# Deserialize a multisig transfer transaction object
|
134
155
|
# @param [String] serialized
|
135
156
|
# @return [Hash]
|
136
|
-
def self.
|
137
|
-
msig_len =
|
157
|
+
def self.multisig(s)
|
158
|
+
msig_len = hexa2int(s[0, 4])
|
138
159
|
inner = s[4, msig_len]
|
139
|
-
inner_tx =
|
160
|
+
inner_tx = transaction(inner)
|
140
161
|
{ otherTrans: inner_tx }
|
141
162
|
end
|
142
163
|
|
143
164
|
# Deserialize a provision namespace transaction object
|
144
165
|
# @param [String] serialized
|
145
166
|
# @return [Hash]
|
146
|
-
def self.
|
167
|
+
def self.provision_namespace(s)
|
147
168
|
tx = {}
|
148
|
-
tx[:rentalFeeSink] =
|
149
|
-
tx[:rentalFee] =
|
150
|
-
newpart_len =
|
151
|
-
tx[:newPart] =
|
152
|
-
parent_len =
|
153
|
-
|
154
|
-
|
155
|
-
tx[:parent] =
|
169
|
+
tx[:rentalFeeSink] = hexa2ascii(s[4, 40])
|
170
|
+
tx[:rentalFee] = hexa2int(s[44, 8])
|
171
|
+
newpart_len = hexa2int(s[52, 4])
|
172
|
+
tx[:newPart] = hexa2ascii(s[56, newpart_len])
|
173
|
+
parent_len = hexa2int(s[56 + newpart_len, 4])
|
174
|
+
unless parent_len == -1
|
175
|
+
parent = s[56 + newpart_len, parent_len]
|
176
|
+
tx[:parent] = hexa2ascii(parent)
|
156
177
|
end
|
157
178
|
tx
|
158
179
|
end
|
@@ -160,7 +181,7 @@ module Nem
|
|
160
181
|
# Deserialize a mosaic definition creation transaction object
|
161
182
|
# @param [String] serialized
|
162
183
|
# @return [Hash]
|
163
|
-
def self.
|
184
|
+
def self.mosaic_definition_creation(s)
|
164
185
|
raise 'Not yet implimented.'
|
165
186
|
# TODO: deserializing
|
166
187
|
tx = {}
|
@@ -170,43 +191,19 @@ module Nem
|
|
170
191
|
# Deserialize a mosaic supply change transaction object
|
171
192
|
# @param [String] serialized
|
172
193
|
# @return [Hash]
|
173
|
-
def self.
|
194
|
+
def self.mosaic_supply_change(s)
|
174
195
|
tx = {}
|
175
196
|
# s[0, 4] # Length of mosaic id structure
|
176
|
-
ns_len =
|
177
|
-
mo_len =
|
197
|
+
ns_len = hexa2int(s[4, 4])
|
198
|
+
mo_len = hexa2int(s[8 + ns_len, 4])
|
178
199
|
tx[:mosaicId] = {
|
179
|
-
namespaceId:
|
180
|
-
name:
|
200
|
+
namespaceId: hexa2ascii(s[8, ns_len]),
|
201
|
+
name: hexa2ascii(s[8 + ns_len + mo_len, mo_len])
|
181
202
|
}
|
182
|
-
tx[:supplyType] =
|
183
|
-
tx[:delta] =
|
203
|
+
tx[:supplyType] = hexa2int(s[8 + ns_len + 4 + mo_len, 4])
|
204
|
+
tx[:delta] = hexa2int(s[8 + ns_len + 4 + mo_len + 4, 8])
|
184
205
|
tx
|
185
206
|
end
|
186
|
-
|
187
|
-
def self.deserialize_common(s)
|
188
|
-
{
|
189
|
-
type: deserialize_int(s[0, 4]),
|
190
|
-
version: deserialize_int(s[4, 4]),
|
191
|
-
timeStamp: deserialize_int(s[8, 4]),
|
192
|
-
# s[12,4] # length of public key,
|
193
|
-
signer: deserialize_hex(s[16, 32]),
|
194
|
-
fee: deserialize_int(s[48, 8]),
|
195
|
-
deadline: deserialize_int(s[56, 4])
|
196
|
-
}
|
197
|
-
end
|
198
|
-
|
199
|
-
def self.deserialize_int(ua)
|
200
|
-
Nem::Util::Convert.ua2hex(ua.reverse).to_i(16)
|
201
|
-
end
|
202
|
-
|
203
|
-
def self.deserialize_hex(ua)
|
204
|
-
Nem::Util::Convert.ua2hex(ua)
|
205
|
-
end
|
206
|
-
|
207
|
-
def self.deserialize_a(ua)
|
208
|
-
Nem::Util::Convert.hex2a(deserialize_hex(ua))
|
209
|
-
end
|
210
207
|
end
|
211
208
|
end
|
212
209
|
end
|
data/lib/nem/version.rb
CHANGED
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.11
|
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-
|
11
|
+
date: 2018-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -380,7 +380,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
380
380
|
version: '0'
|
381
381
|
requirements: []
|
382
382
|
rubyforge_project:
|
383
|
-
rubygems_version: 2.
|
383
|
+
rubygems_version: 2.6.11
|
384
384
|
signing_key:
|
385
385
|
specification_version: 4
|
386
386
|
summary: Ruby gem for communicating with the nem
|