xrbp 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a8b3814b38bdb314bd9c69b5d9f3363b4f0a090f6d41a5849516cc1638d5abe
4
- data.tar.gz: fc1ba94351b215389efaacb5013bfa9498a269cf12d7fde3e6958a5fb3f6273a
3
+ metadata.gz: d19910e3c88e5a509e3ed8e763bfd30ae764c6a7e31464b36e66ea7f03ce6929
4
+ data.tar.gz: 8105339c1ba88f6cc9e52b18bb72a44434ff3646f4fa1f6cfdde2691654e2ed0
5
5
  SHA512:
6
- metadata.gz: b8e9e87bc83b3bd361bef7d1deffd87c7637285e15fca3bb5b25f87b34091ebb792137178b06c71d8ac1566a75aadf5ed74fe85d1fc414c5070edecfddce78d4
7
- data.tar.gz: 8e8cbea5804ff5f852584be3a699caee69169ad3563bb2a0696e8a3ea9492faa89ae937138bb64c7b65804adc72f49f24538659b85a018b2444b038c4b0b0558
6
+ metadata.gz: 439f2a90a8eb76f1e3ac28f6bb08fd0bbbdb7ec1c600df52199cc56db1738c1cbe2cfae45c484c5d1b1d7635c00db88d38428ffa98c77977c9e36252f9a7962a
7
+ data.tar.gz: 9f87cdb439e262527cbec2181d86a21931fc44d29fb4a9900ad479ad385479921f06d2ba9a6cda245894de51b98607a21f39ed2d8921fe8b75dab2e1e2859546
data/examples/sandbox.rb CHANGED
@@ -5,7 +5,7 @@ require 'xrbp/nodestore/backends/nudb'
5
5
  db = XRBP::NodeStore::Backends::NuDB.new "/var/lib/rippled/nudb/"
6
6
  store = db.instance_variable_get(:@store)
7
7
 
8
- key = [173, 159, 139, 114, 152, 207, 218, 221, 216, 149, 123, 11, 7, 224, 137, 139, 4, 190, 176, 89, 215, 228, 145, 13, 7, 45, 165, 249, 162, 83, 43, 241].pack("C*")
8
+ key = [85, 128, 20, 72, 146, 231, 227, 37, 187, 39, 215, 214, 137, 172, 74, 102, 212, 160, 121, 146, 42, 165, 122, 58, 253, 41, 102, 206, 69, 144, 37, 66].pack("C*")
9
9
  val = store.fetch(key).first
10
10
  puts val.unpack("C*").join " "
11
11
  decompressed = db.send(:decompress, val)
@@ -40,9 +40,9 @@ module XRBP
40
40
  end
41
41
 
42
42
  def parse_encoding(encoding)
43
- enc = encoding.unpack("C").first
44
- type = enc >> 4
45
- field = enc & 0xF
43
+ enc = encoding.unpack("C").first
44
+ type = enc >> 4
45
+ field = enc & 0xF
46
46
  encoding = encoding[1..-1]
47
47
 
48
48
  if type == 0
@@ -130,98 +130,20 @@ module XRBP
130
130
  return data.unpack("H40").first, data[20..-1]
131
131
  when :hash256
132
132
  return data.unpack("H64").first, data[32..-1]
133
-
134
133
  when :amount
135
- amount = data[0..7].unpack("Q>").first
136
- xrp = amount < 0x8000000000000000
137
- return (amount & 0x3FFFFFFFFFFFFFFF), data[8..-1] if xrp
138
-
139
- sign = (amount & 0x4000000000000000) >> 62 # 0 = neg / 1 = pos
140
- exp = (amount & 0x3FC0000000000000) >> 54
141
- mant = (amount & 0x003FFFFFFFFFFFFF)
142
-
143
- data = data[8..-1]
144
- currency = Format::CURRENCY_CODE.decode(data)
145
-
146
- data = data[Format::CURRENCY_CODE.size..-1]
147
- issuer, data = parse_account(data, 20)
148
-
149
- # TODO calculate value
150
- return { :sign => sign,
151
- :exp => exp,
152
- :mantissa => mant,
153
- :currency => currency,
154
- :issuer => issuer }, data
155
-
134
+ return parse_amount(data)
156
135
  when :vl
157
136
  vl, offset = parse_vl(data)
158
137
  return data[offset..vl+offset-1], data[vl+offset..-1]
159
138
 
160
139
  when :account
161
140
  return parse_account(data)
162
-
163
141
  when :array
164
- e = Format::ENCODINGS[encoding]
165
- return nil, data if e == :end_of_array
166
-
167
- array = []
168
- until data == "" || data.nil?
169
- aencoding, data = parse_encoding(data)
170
- break if aencoding.first.nil?
171
-
172
- e = Format::ENCODINGS[aencoding]
173
- break if e == :end_of_array
174
-
175
- value, data = parse_field(data, aencoding)
176
- break unless value
177
- array << value
178
- end
179
-
180
- return array, data
181
-
142
+ return parse_array(data, encoding)
182
143
  when :object
183
- e = Format::ENCODINGS[encoding]
184
- case e
185
- when :end_of_object
186
- return nil, data
187
-
188
- when :signer, :signer_entry,
189
- :majority, :memo,
190
- :modified_node, :created_node, :deleted_node,
191
- :previous_fields, :final_fields, :new_fields
192
- # TODO instantiate corresponding classes
193
- return parse_fields(data)
194
-
195
- #else:
196
- end
197
-
144
+ return parse_object(data, encoding)
198
145
  when :pathset
199
- pathset = []
200
- until data == "" || data.nil?
201
- segment = data.unpack("C").first
202
- data = data[1..-1]
203
- return pathset, data if segment == 0x00 # end of path
204
-
205
- if segment == 0xFF # path boundry
206
- pathset << []
207
- else
208
- if segment & 0x01 # path account
209
- issuer, data = parse_account(data, 20)
210
- end
211
-
212
- if segment & 0x02 # path currency
213
- currency = Format::CURRENCY_CODE.decode(data)
214
- data = data[Format::CURRENCY_CODE.size..-1]
215
- end
216
-
217
- if segment & 0x03 # path issuer
218
- issuer, data = parse_account(data, 20)
219
- end
220
- end
221
- end
222
-
223
- return pathset, data
224
-
146
+ return parse_pathset(data)
225
147
  when :vector256
226
148
  vl, offset = parse_vl(data)
227
149
  return data[offset..vl+offset-1], data[vl+offset..-1]
@@ -250,6 +172,29 @@ module XRBP
250
172
  raise
251
173
  end
252
174
 
175
+ def parse_amount(data)
176
+ amount = data[0..7].unpack("Q>").first
177
+ xrp = amount < 0x8000000000000000
178
+ return (amount & 0x3FFFFFFFFFFFFFFF), data[8..-1] if xrp
179
+
180
+ sign = (amount & 0x4000000000000000) >> 62 # 0 = neg / 1 = pos
181
+ exp = (amount & 0x3FC0000000000000) >> 54
182
+ mant = (amount & 0x003FFFFFFFFFFFFF)
183
+
184
+ data = data[8..-1]
185
+ currency = Format::CURRENCY_CODE.decode(data)
186
+
187
+ data = data[Format::CURRENCY_CODE.size..-1]
188
+ issuer, data = parse_account(data, 20)
189
+
190
+ # TODO calculate value
191
+ return { :sign => sign,
192
+ :exp => exp,
193
+ :mantissa => mant,
194
+ :currency => currency,
195
+ :issuer => issuer }, data
196
+ end
197
+
253
198
  def parse_account(data, vl=nil)
254
199
  unless vl
255
200
  vl,offset = parse_vl(data)
@@ -264,6 +209,73 @@ module XRBP
264
209
  return Base58.binary_to_base58(acct, :ripple), data[vl..-1]
265
210
  end
266
211
 
212
+ def parse_array(data, encoding)
213
+ e = Format::ENCODINGS[encoding]
214
+ return nil, data if e == :end_of_array
215
+
216
+ array = []
217
+ until data == "" || data.nil?
218
+ aencoding, data = parse_encoding(data)
219
+ break if aencoding.first.nil?
220
+
221
+ e = Format::ENCODINGS[aencoding]
222
+ break if e == :end_of_array
223
+
224
+ value, data = parse_field(data, aencoding)
225
+ break unless value
226
+ array << value
227
+ end
228
+
229
+ return array, data
230
+ end
231
+
232
+ def parse_object(data, encoding)
233
+ e = Format::ENCODINGS[encoding]
234
+ case e
235
+ when :end_of_object
236
+ return nil, data
237
+
238
+ when :signer, :signer_entry,
239
+ :majority, :memo,
240
+ :modified_node, :created_node, :deleted_node,
241
+ :previous_fields, :final_fields, :new_fields
242
+ # TODO instantiate corresponding classes
243
+ return parse_fields(data)
244
+
245
+ #else:
246
+ end
247
+
248
+ raise "unknown object type"
249
+ end
250
+
251
+ def parse_pathset(data)
252
+ pathset = []
253
+ until data == "" || data.nil?
254
+ segment = data.unpack("C").first
255
+ data = data[1..-1]
256
+ return pathset, data if segment == 0x00 # end of path
257
+
258
+ if segment == 0xFF # path boundry
259
+ pathset << []
260
+ else
261
+ if (segment & 0x01) != 0 # path account
262
+ issuer, data = parse_account(data, 20)
263
+ end
264
+
265
+ if (segment & 0x02) != 0 # path currency
266
+ currency = Format::CURRENCY_CODE.decode(data)
267
+ data = data[Format::CURRENCY_CODE.size..-1]
268
+ end
269
+
270
+ if (segment & 0x03) != 0 # path issuer
271
+ issuer, data = parse_account(data, 20)
272
+ end
273
+ end
274
+ end
275
+
276
+ return pathset, data
277
+ end
278
+
267
279
  ###
268
280
 
269
281
  def parse_tx(tx)
data/lib/xrbp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module XRBP
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end # module XRBP
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xrbp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dev Null Productions