xrbp 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/nodestore1.rb +12 -7
- data/lib/xrbp/core_ext.rb +27 -0
- data/lib/xrbp/crypto/account.rb +28 -3
- data/lib/xrbp/nodestore.rb +6 -0
- data/lib/xrbp/nodestore/amendments.rb +13 -0
- data/lib/xrbp/nodestore/backends/decompressor.rb +8 -6
- data/lib/xrbp/nodestore/backends/nudb.rb +2 -0
- data/lib/xrbp/nodestore/backends/rocksdb.rb +1 -0
- data/lib/xrbp/nodestore/db.rb +5 -387
- data/lib/xrbp/nodestore/fees.rb +19 -0
- data/lib/xrbp/nodestore/format.rb +72 -1
- data/lib/xrbp/nodestore/ledger.rb +272 -0
- data/lib/xrbp/nodestore/parser.rb +407 -0
- data/lib/xrbp/nodestore/protocol.rb +5 -0
- data/lib/xrbp/nodestore/protocol/currency.rb +11 -0
- data/lib/xrbp/nodestore/protocol/indexes.rb +109 -0
- data/lib/xrbp/nodestore/protocol/issue.rb +26 -0
- data/lib/xrbp/nodestore/protocol/quality.rb +10 -0
- data/lib/xrbp/nodestore/protocol/rate.rb +21 -0
- data/lib/xrbp/nodestore/shamap.rb +447 -0
- data/lib/xrbp/nodestore/shamap/errors.rb +8 -0
- data/lib/xrbp/nodestore/shamap/inner_node.rb +98 -0
- data/lib/xrbp/nodestore/shamap/item.rb +14 -0
- data/lib/xrbp/nodestore/shamap/node.rb +49 -0
- data/lib/xrbp/nodestore/shamap/node_factory.rb +120 -0
- data/lib/xrbp/nodestore/shamap/node_id.rb +83 -0
- data/lib/xrbp/nodestore/shamap/tagged_cache.rb +20 -0
- data/lib/xrbp/nodestore/shamap/tree_node.rb +21 -0
- data/lib/xrbp/nodestore/sle.rb +4 -0
- data/lib/xrbp/nodestore/sle/st_account.rb +8 -0
- data/lib/xrbp/nodestore/sle/st_amount.rb +226 -0
- data/lib/xrbp/nodestore/sle/st_ledger_entry.rb +24 -0
- data/lib/xrbp/nodestore/sle/st_object.rb +46 -0
- data/lib/xrbp/nodestore/sqldb.rb +23 -0
- data/lib/xrbp/nodestore/uint.rb +7 -0
- data/lib/xrbp/version.rb +1 -1
- data/spec/xrbp/nodestore/backends/nudb_spec.rb +3 -1
- data/spec/xrbp/nodestore/backends/rocksdb_spec.rb +1 -1
- data/spec/xrbp/nodestore/{backends/db_parser.rb → db_parser.rb} +2 -2
- data/spec/xrbp/nodestore/ledger_access.rb +17 -0
- metadata +30 -3
@@ -0,0 +1,24 @@
|
|
1
|
+
module XRBP
|
2
|
+
module NodeStore
|
3
|
+
# Special type of Serialized Object whose type is identified
|
4
|
+
# through the 'ledger_entry_type' field
|
5
|
+
class STLedgerEntry < STObject
|
6
|
+
attr_reader :key
|
7
|
+
|
8
|
+
def initialize(args={})
|
9
|
+
super
|
10
|
+
@key = args[:key]
|
11
|
+
end
|
12
|
+
|
13
|
+
def type_code
|
14
|
+
@type_code ||= field(:uint16, :ledger_entry_type)
|
15
|
+
end
|
16
|
+
|
17
|
+
def type
|
18
|
+
@type ||= Format::LEDGER_ENTRY_TYPE_CODES[type_code]
|
19
|
+
end
|
20
|
+
end # class STLedgerEntry
|
21
|
+
|
22
|
+
SLE = STLedgerEntry
|
23
|
+
end # module NodeStore
|
24
|
+
end # module XRBP
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative '../parser'
|
2
|
+
|
3
|
+
module XRBP
|
4
|
+
module NodeStore
|
5
|
+
# Seralized Type containing fields associated with ids
|
6
|
+
class STObject
|
7
|
+
# NodeStore Parser
|
8
|
+
include Parser
|
9
|
+
|
10
|
+
attr_reader :item, :fields
|
11
|
+
|
12
|
+
def initialize(args={})
|
13
|
+
@item = args[:item]
|
14
|
+
|
15
|
+
@fields, remaining = parse_fields(item.data)
|
16
|
+
raise unless remaining.size == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def flags
|
20
|
+
@flags ||= fields[:flags]
|
21
|
+
end
|
22
|
+
|
23
|
+
def flag?(flag)
|
24
|
+
flag = NodeStore::Format::SERIALIZED_FLAGS[flag] if flag.is_a?(Symbol)
|
25
|
+
flags & flag == flag
|
26
|
+
end
|
27
|
+
|
28
|
+
def field?(id)
|
29
|
+
fields.key?(id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def field(type, id)
|
33
|
+
fields[id]
|
34
|
+
# type should already be converted in parsing process (TODO verify?)
|
35
|
+
end
|
36
|
+
|
37
|
+
def amount(field)
|
38
|
+
field(STAmount, field)
|
39
|
+
end
|
40
|
+
|
41
|
+
def account_id(field)
|
42
|
+
field(STAccount, field)
|
43
|
+
end
|
44
|
+
end # class STObject
|
45
|
+
end # module NodeStore
|
46
|
+
end # module XRBP
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
|
3
|
+
module XRBP
|
4
|
+
module NodeStore
|
5
|
+
class SQLDB
|
6
|
+
def initialize(dir)
|
7
|
+
@dir = dir
|
8
|
+
end
|
9
|
+
|
10
|
+
def ledger_db
|
11
|
+
@ledger_db ||= SQLite3::Database.new File.join(@dir, "ledger.db")
|
12
|
+
end
|
13
|
+
|
14
|
+
def tx_db
|
15
|
+
@ledger_db ||= SQLite3::Database.new File.join(@dir, "transaction.db")
|
16
|
+
end
|
17
|
+
|
18
|
+
def ledger_hash_for_seq(seq)
|
19
|
+
ledger_db.execute("select LedgerHash from ledgers where LedgerSeq = ?", seq).first.first
|
20
|
+
end
|
21
|
+
end # class SQLDB
|
22
|
+
end # module NodeStore
|
23
|
+
end # module XRBP
|
data/lib/xrbp/version.rb
CHANGED
@@ -3,7 +3,8 @@ require 'xrbp/nodestore/backends/nudb'
|
|
3
3
|
require_relative "./db_access"
|
4
4
|
#require_relative "./db_iterator_access"
|
5
5
|
#require_relative "./db_decompression"
|
6
|
-
require_relative "
|
6
|
+
require_relative "../db_parser"
|
7
|
+
require_relative "../ledger_access"
|
7
8
|
|
8
9
|
describe XRBP::NodeStore::Backends::NuDB do
|
9
10
|
before(:each) do
|
@@ -22,4 +23,5 @@ describe XRBP::NodeStore::Backends::NuDB do
|
|
22
23
|
# it_provides "database iterator access"
|
23
24
|
# it_provides "database decompression"
|
24
25
|
it_provides "a database parser"
|
26
|
+
it_provides "ledger access"
|
25
27
|
end
|
@@ -3,10 +3,10 @@ shared_examples "a database parser" do |opts={}|
|
|
3
3
|
let(:ledger) { {"nt_ledger"=>1, "hp_ledger_master"=>"4c575200", "index"=>47508432, "total_coins"=>18248035087498961665, "parent_hash"=>"C4FAD6EB19F6A6089E7AEBC73AF596DB471305BC0EBB99D9D1414BD4DB8C9D43", "tx_hash"=>"934A5E57C598F0505664F9349DA87FD32AFBE1C315A2CB6CFB5B690AECC6B1A3", "account_hash"=>"FEA269DAAA66C820978AC95F0399ECACA7A3ABAC91402C9FC7961A53D053332F", "parent_close_time"=>Time.parse("2019-05-25T20:12:20Z").utc, "close_time"=>Time.parse("2019-05-25T20:12:21Z").utc, "close_time_resolution"=>10, "close_flags"=>0} }
|
4
4
|
|
5
5
|
let(:tx_key) { ["003b960d5e30ff91a91f7c900509a99a8a6b89441b76158e5ed295ad1d27b0e7"].pack("H*") }
|
6
|
-
let(:tx) { {:node=>{:transaction_type=>:payment, :flags=>2147942400, :sequence=>3366484, :last_ledger_sequence=>47713577, :amount=>
|
6
|
+
let(:tx) { {:node=>{:transaction_type=>:payment, :flags=>2147942400, :sequence=>3366484, :last_ledger_sequence=>47713577, :amount=>XRBP::NodeStore::STAmount.new(:mantissa => 1000000000000000, :exponent => 86, :issue => XRBP::NodeStore::Issue.new("XCN", "rPFLkxQk6xUGdGYEykqe7PR25Gr7mLHDc8")), :fee=>XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore.xrp_issue, :mantissa => 11), :send_max=>XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore.xrp_issue, :mantissa => 10000000000), :signing_pub_key=>"030ac4f2ba6e1ff86beb234b639918dafdf0675032ae264d2b39641503822373fe", :txn_signature=>"304402207ac9c62a6e8a876e67945edebcd3f6c71c36c95fbbb0ce05a85871d0794b1b8c0220297fe7195beb083a78ff9de4d822b5e4cb42be7e5a8662bcbc2f42c737e264bf", :account=>"rKLpjpCoXgLQQYQyj13zgay73rsgmzNH13", :destination=>"rKLpjpCoXgLQQYQyj13zgay73rsgmzNH13", :paths=>[[{:currency=>"CNY", :issuer=>"rKiCet8SdvWxPXnAgYarFUXMh1zCPz432Y"}, {:currency=>"USD", :issuer=>"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq"}, {:currency=>"\x00\x00\x00"}, {:currency=>"XCN", :issuer=>"rPFLkxQk6xUGdGYEykqe7PR25Gr7mLHDc8"}], [{:currency=>"USD", :issuer=>"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq"}, {:currency=>"CNY", :issuer=>"rKiCet8SdvWxPXnAgYarFUXMh1zCPz432Y"}, {:currency=>"\x00\x00\x00"}, {:currency=>"XCN", :issuer=>"rPFLkxQk6xUGdGYEykqe7PR25Gr7mLHDc8"}], [{:currency=>"CNY", :issuer=>"rKiCet8SdvWxPXnAgYarFUXMh1zCPz432Y"}, {:currency=>"CNY", :issuer=>"razqQKzJRdB4UxFPWf5NEpEG3WMkmwgcXA"}, {:currency=>"\x00\x00\x00"}, {:currency=>"XCN", :issuer=>"rPFLkxQk6xUGdGYEykqe7PR25Gr7mLHDc8"}], [{:currency=>"CNY", :issuer=>"razqQKzJRdB4UxFPWf5NEpEG3WMkmwgcXA"}, {:currency=>"CNY", :issuer=>"rKiCet8SdvWxPXnAgYarFUXMh1zCPz432Y"}, {:currency=>"\x00\x00\x00"}, {:currency=>"XCN", :issuer=>"rPFLkxQk6xUGdGYEykqe7PR25Gr7mLHDc8"}], [{:currency=>"CNY", :issuer=>"rKiCet8SdvWxPXnAgYarFUXMh1zCPz432Y"}, {:currency=>"EUR", :issuer=>"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq"}, {:currency=>"\x00\x00\x00"}, {:currency=>"XCN", :issuer=>"rPFLkxQk6xUGdGYEykqe7PR25Gr7mLHDc8"}], [{:currency=>"EUR", :issuer=>"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq"}, {:currency=>"CNY", :issuer=>"rKiCet8SdvWxPXnAgYarFUXMh1zCPz432Y"}, {:currency=>"\x00\x00\x00"}, {:currency=>"XCN", :issuer=>"rPFLkxQk6xUGdGYEykqe7PR25Gr7mLHDc8"}]]}, :meta=>{:transaction_index=>30, :affected_nodes=>[{:ledger_entry_type=>:account_root, :previous_txn_lgr_seq=>47713575, :previous_txn_id=>"2e397e516ccde852e829d36eb7d0d195dd9a974a188e213ad256c3ae3c131e58", :ledger_index=>"792ba4e4659c27cf3b63f96b34f158748b081cf532f6746a1e3ebd07acba1a0e", :previous_fields=>{:sequence=>3366484, :balance=>XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore.xrp_issue, :mantissa => 1920887273)}, :final_fields=>{:flags=>0, :sequence=>3366485, :owner_count=>5, :balance=>XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore.xrp_issue, :mantissa => 1920887262), :account=>"rKLpjpCoXgLQQYQyj13zgay73rsgmzNH13"}}], :transaction_result=>128}, :index=>"5C28E293E88CCEEFBBAB3EF58C1F8C1C02A5194F42A42349597DDCBC86BFEB0D"} }
|
7
7
|
|
8
8
|
let(:ledger_entry_key) { ["002989b414eff398027fce4045f643d68aca440aeea11518a950550ca02c18dd"].pack("H*") }
|
9
|
-
let(:ledger_entry) { {:type=>:account_root, :index=>"9A34C6D1C46168ECE90EB867C78AB2BECE80FAF5D86D09082017E2C89BD68E56", :fields=>{:flags=>0, :sequence=>2, :previous_txn_lgr_seq=>45017187, :owner_count=>0, :previous_txn_id=>"3133839f2401cc9a719778f53319486d11e7ad7ec7891ac083e2aa7eb924516a", :balance=>20000000, :account=>"r4HW4bomLvvzA22dACJwUq95ZRr8ZAcXXs"}} }
|
9
|
+
let(:ledger_entry) { {:type=>:account_root, :index=>"9A34C6D1C46168ECE90EB867C78AB2BECE80FAF5D86D09082017E2C89BD68E56", :fields=>{:flags=>0, :sequence=>2, :previous_txn_lgr_seq=>45017187, :owner_count=>0, :previous_txn_id=>"3133839f2401cc9a719778f53319486d11e7ad7ec7891ac083e2aa7eb924516a", :balance=>XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore.xrp_issue, :mantissa => 20000000), :account=>"r4HW4bomLvvzA22dACJwUq95ZRr8ZAcXXs"}} }
|
10
10
|
|
11
11
|
let(:inner_node_key) { ["001b46daaea7a40d9dcdc30f83918db8c8f9110c22e1207bcd8f9145dbe032dd"].pack("H*") }
|
12
12
|
# XXX - see: https://github.com/ripple/rippled/issues/2960
|
@@ -0,0 +1,17 @@
|
|
1
|
+
shared_examples "ledger access" do |opts={}|
|
2
|
+
let(:ledger_hash) { ["32E073D7E4D722D956F7FDE095F756FBB86DC9CA487EB0D9ABF5151A8D88F912"].pack("H*") }
|
3
|
+
let(:ledger) { XRBP::NodeStore::Ledger.new(:db => db, :hash => ledger_hash) }
|
4
|
+
|
5
|
+
let(:issuer) { 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' }
|
6
|
+
let(:iou1) { {:currency => 'USD', :account => issuer} }
|
7
|
+
let(:iou2) { {:currency => 'EUR', :account => issuer} }
|
8
|
+
|
9
|
+
let(:order1) { { :ledger_entry_type=>:offer, :flags=>131072, :sequence=>219, :previous_txn_lgr_seq=>47926685, :book_node=>0, :owner_node=>0, :previous_txn_id=>"e43add1bd4ac2049e0d9de6bc279b7fd95a99c8de2c4694a4a7623f6d9aaae29", :book_directory=>"7e5f614417c2d0a7cefeb73c4aa773ed5b078de2b5771f6d56038d7ea4c68000", :taker_pays=>XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("USD", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"), :mantissa => 2459108753792364, :exponent => 83), :taker_gets => XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("EUR", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"), :mantissa => 2459108753792364, :exponent => 82), :account=>"rnixnrMHHvR7ejMpJMRCWkaNrq3qREwMDu", :taker_gets_funded=> XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("USD", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B")), :taker_pays_funded => XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("EUR", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B")) } }
|
10
|
+
let(:order2) { { :ledger_entry_type=>:offer, :flags=>131072, :sequence=>19, :previous_txn_lgr_seq=>43166305, :book_node=>0, :owner_node=>0, :previous_txn_id=>"b63b2ecd124fe6b02bc2998929517266bd221a02fee51dde4992c1bcb7e86cd3", :book_directory=>"7e5f614417c2d0a7cefeb73c4aa773ed5b078de2b5771f6d56038d7ea4c68000", :taker_pays=>XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("USD", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"), :mantissa => 3520000000000000, :exponent => 83), :taker_gets => XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("EUR", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"), :mantissa => 3520000000000000, :exponent => 82), :account=>"rKwjWCKBaASEvtHCxtvReNd2i9n8DxSihk", :taker_gets_funded=>XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("USD", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B")), :taker_pays_funded => XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("EUR", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B")) } }
|
11
|
+
let(:order_book) { [order1, order2] }
|
12
|
+
|
13
|
+
it "provides access to order book" do
|
14
|
+
actual = ledger.order_book(iou1, iou2)
|
15
|
+
expect(actual).to eq(order_book)
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xrbp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dev Null Productions
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -230,11 +230,37 @@ files:
|
|
230
230
|
- lib/xrbp/model/parsers/validator.rb
|
231
231
|
- lib/xrbp/model/validator.rb
|
232
232
|
- lib/xrbp/nodestore.rb
|
233
|
+
- lib/xrbp/nodestore/amendments.rb
|
233
234
|
- lib/xrbp/nodestore/backends/decompressor.rb
|
234
235
|
- lib/xrbp/nodestore/backends/nudb.rb
|
235
236
|
- lib/xrbp/nodestore/backends/rocksdb.rb
|
236
237
|
- lib/xrbp/nodestore/db.rb
|
238
|
+
- lib/xrbp/nodestore/fees.rb
|
237
239
|
- lib/xrbp/nodestore/format.rb
|
240
|
+
- lib/xrbp/nodestore/ledger.rb
|
241
|
+
- lib/xrbp/nodestore/parser.rb
|
242
|
+
- lib/xrbp/nodestore/protocol.rb
|
243
|
+
- lib/xrbp/nodestore/protocol/currency.rb
|
244
|
+
- lib/xrbp/nodestore/protocol/indexes.rb
|
245
|
+
- lib/xrbp/nodestore/protocol/issue.rb
|
246
|
+
- lib/xrbp/nodestore/protocol/quality.rb
|
247
|
+
- lib/xrbp/nodestore/protocol/rate.rb
|
248
|
+
- lib/xrbp/nodestore/shamap.rb
|
249
|
+
- lib/xrbp/nodestore/shamap/errors.rb
|
250
|
+
- lib/xrbp/nodestore/shamap/inner_node.rb
|
251
|
+
- lib/xrbp/nodestore/shamap/item.rb
|
252
|
+
- lib/xrbp/nodestore/shamap/node.rb
|
253
|
+
- lib/xrbp/nodestore/shamap/node_factory.rb
|
254
|
+
- lib/xrbp/nodestore/shamap/node_id.rb
|
255
|
+
- lib/xrbp/nodestore/shamap/tagged_cache.rb
|
256
|
+
- lib/xrbp/nodestore/shamap/tree_node.rb
|
257
|
+
- lib/xrbp/nodestore/sle.rb
|
258
|
+
- lib/xrbp/nodestore/sle/st_account.rb
|
259
|
+
- lib/xrbp/nodestore/sle/st_amount.rb
|
260
|
+
- lib/xrbp/nodestore/sle/st_ledger_entry.rb
|
261
|
+
- lib/xrbp/nodestore/sle/st_object.rb
|
262
|
+
- lib/xrbp/nodestore/sqldb.rb
|
263
|
+
- lib/xrbp/nodestore/uint.rb
|
238
264
|
- lib/xrbp/overlay.rb
|
239
265
|
- lib/xrbp/overlay/connection.rb
|
240
266
|
- lib/xrbp/overlay/frame.rb
|
@@ -293,9 +319,10 @@ files:
|
|
293
319
|
- spec/xrbp/crypto/node_spec.rb
|
294
320
|
- spec/xrbp/crypto/seed_spec.rb
|
295
321
|
- spec/xrbp/nodestore/backends/db_access.rb
|
296
|
-
- spec/xrbp/nodestore/backends/db_parser.rb
|
297
322
|
- spec/xrbp/nodestore/backends/nudb_spec.rb
|
298
323
|
- spec/xrbp/nodestore/backends/rocksdb_spec.rb
|
324
|
+
- spec/xrbp/nodestore/db_parser.rb
|
325
|
+
- spec/xrbp/nodestore/ledger_access.rb
|
299
326
|
- spec/xrbp/websocket/client_spec.rb
|
300
327
|
- spec/xrbp/websocket/command_spec.rb
|
301
328
|
- spec/xrbp/websocket/connection_spec.rb
|