xrbp 0.2.2 → 0.2.3

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/examples/nodestore1.rb +3 -1
  3. data/lib/xrbp/common.rb +6 -0
  4. data/lib/xrbp/core_ext.rb +21 -0
  5. data/lib/xrbp/nodestore/format.rb +76 -26
  6. data/lib/xrbp/nodestore/ledger.rb +46 -14
  7. data/lib/xrbp/nodestore/parser.rb +47 -14
  8. data/lib/xrbp/nodestore/protocol/indexes.rb +11 -8
  9. data/lib/xrbp/nodestore/protocol/issue.rb +15 -0
  10. data/lib/xrbp/nodestore/protocol/rate.rb +13 -1
  11. data/lib/xrbp/nodestore/shamap/node_factory.rb +6 -1
  12. data/lib/xrbp/nodestore/shamap/node_id.rb +2 -2
  13. data/lib/xrbp/nodestore/sle/st_amount.rb +46 -181
  14. data/lib/xrbp/nodestore/sle/st_amount_arithmatic.rb +126 -0
  15. data/lib/xrbp/nodestore/sle/st_amount_comparison.rb +49 -0
  16. data/lib/xrbp/nodestore/sle/st_amount_conversion.rb +203 -0
  17. data/lib/xrbp/nodestore/sqldb.rb +69 -4
  18. data/lib/xrbp/overlay/handshake.rb +1 -1
  19. data/lib/xrbp/version.rb +1 -1
  20. data/spec/xrbp/crypto/account_spec.rb +7 -2
  21. data/spec/xrbp/nodestore/amendments_spec.rb +11 -0
  22. data/spec/xrbp/nodestore/db_parser.rb +64 -1
  23. data/spec/xrbp/nodestore/fees_spec.rb +3 -0
  24. data/spec/xrbp/nodestore/ledger_access.rb +87 -2
  25. data/spec/xrbp/nodestore/protocol/indexes_spec.rb +43 -0
  26. data/spec/xrbp/nodestore/protocol/rate_spec.rb +12 -0
  27. data/spec/xrbp/nodestore/shamap/inner_node_spec.rb +44 -0
  28. data/spec/xrbp/nodestore/shamap/node_factory_spec.rb +9 -0
  29. data/spec/xrbp/nodestore/shamap/node_id_spec.rb +6 -0
  30. data/spec/xrbp/nodestore/shamap/node_spec.rb +25 -0
  31. data/spec/xrbp/nodestore/shamap_spec.rb +144 -0
  32. data/spec/xrbp/nodestore/sle/st_amount_arithmatic_spec.rb +7 -0
  33. data/spec/xrbp/nodestore/sle/st_amount_comparison_spec.rb +11 -0
  34. data/spec/xrbp/nodestore/sle/st_amount_conversion_spec.rb +64 -0
  35. data/spec/xrbp/nodestore/sle/st_amount_spec.rb +47 -0
  36. data/spec/xrbp/nodestore/sle/st_ledger_entry_spec.rb +5 -0
  37. data/spec/xrbp/nodestore/sle/st_object_spec.rb +29 -0
  38. metadata +20 -2
@@ -0,0 +1,3 @@
1
+ describe XRBP::NodeStore::Fees do
2
+ it "returns account reserve"
3
+ end
@@ -6,10 +6,95 @@ shared_examples "ledger access" do |opts={}|
6
6
  let(:iou1) { {:currency => 'USD', :account => issuer} }
7
7
  let(:iou2) { {:currency => 'EUR', :account => issuer} }
8
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")) } }
9
+ let(:order1) { {
10
+ :ledger_entry_type=>:offer,
11
+ :flags=>131072,
12
+ :sequence=>219,
13
+ :previous_txn_lgr_seq=>47926685,
14
+ :book_node=>0,
15
+ :owner_node=>0,
16
+ :previous_txn_id=>"e43add1bd4ac2049e0d9de6bc279b7fd95a99c8de2c4694a4a7623f6d9aaae29",
17
+ :book_directory=>"7e5f614417c2d0a7cefeb73c4aa773ed5b078de2b5771f6d56038d7ea4c68000",
18
+ :taker_pays=>XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("USD", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"), :mantissa => 2459108753792364, :exponent => -14),
19
+ :taker_gets => XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("EUR", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"), :mantissa => 2459108753792364, :exponent => -15),
20
+ :account=>"rnixnrMHHvR7ejMpJMRCWkaNrq3qREwMDu",
21
+ :owner_funds => XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("EUR", XRBP::Crypto.no_account), :mantissa => 2872409153061363, :exponent => -15),
22
+ :quality => XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore.no_issue, :mantissa => 1000000000000000, :exponent => -14),
23
+ } }
24
+
25
+ let(:order2) { {
26
+ :ledger_entry_type=>:offer,
27
+ :flags=>131072,
28
+ :sequence=>19,
29
+ :previous_txn_lgr_seq=>43166305,
30
+ :book_node=>0,
31
+ :owner_node=>0,
32
+ :previous_txn_id=>"b63b2ecd124fe6b02bc2998929517266bd221a02fee51dde4992c1bcb7e86cd3",
33
+ :book_directory=>"7e5f614417c2d0a7cefeb73c4aa773ed5b078de2b5771f6d56038d7ea4c68000",
34
+ :taker_pays=>XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("USD", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"), :mantissa => 3520000000000000, :exponent => -14),
35
+ :taker_pays_funded=>XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("USD", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"), :mantissa => 3516160294182094, :exponent => -14),
36
+ :taker_gets => XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("EUR", "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"), :mantissa => 3520000000000000, :exponent => -15), :account=>"rKwjWCKBaASEvtHCxtvReNd2i9n8DxSihk",
37
+ :taker_gets_funded => XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("EUR", XRBP::Crypto.no_account), :mantissa => 3516160294182094, :exponent => -15), :account=>"rKwjWCKBaASEvtHCxtvReNd2i9n8DxSihk",
38
+ :owner_funds => XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore::Issue.new("EUR", XRBP::Crypto.no_account), :mantissa => 3523192614770459, :exponent => -15),
39
+ :quality => XRBP::NodeStore::STAmount.new(:issue => XRBP::NodeStore.no_issue, :mantissa => 1000000000000000, :exponent => -14),
40
+ } }
41
+
11
42
  let(:order_book) { [order1, order2] }
12
43
 
44
+ it "provides access to ledger state map"
45
+
46
+ it "provides access to ledger tx map"
47
+
48
+ it "provides access to ledger info"
49
+
50
+ describe "#global_frozen?" do
51
+ context "account globally frozen in ledger" do
52
+ it "returns true"
53
+ end
54
+
55
+ context "account not globally frozen in ledger" do
56
+ it "returns false"
57
+ end
58
+ end
59
+
60
+ describe "#frozen?" do
61
+ context "account trust line frozen" do
62
+ it "returns true"
63
+ end
64
+
65
+ context "account trust line not frozen" do
66
+ it "returns false"
67
+ end
68
+ end
69
+
70
+ describe "#account_holds" do
71
+ it "returns balance of account iou trust line"
72
+
73
+ context "currency == 'XRP'" do
74
+ it "returns liquid xrp"
75
+ end
76
+ end
77
+
78
+ describe "#xrp_liquid" do
79
+ context "account not found" do
80
+ it "returns zero amount minus reserve"
81
+ end
82
+
83
+ it "returns xrp account balance minus reserve"
84
+
85
+ context "fix1141 in effect" do
86
+ it "confines owner account"
87
+ end
88
+ end
89
+
90
+ describe "#confine_owner_account" do
91
+ it "adjusts and returns amount"
92
+ end
93
+
94
+ describe "#transfer_rate" do
95
+ it "returns transfer rate for specified issuer"
96
+ end
97
+
13
98
  it "provides access to order book" do
14
99
  actual = ledger.order_book(iou1, iou2)
15
100
  expect(actual).to eq(order_book)
@@ -0,0 +1,43 @@
1
+ describe XRBP::NodeStore::Indexes do
2
+ it "returns quality for base" do
3
+ base = 57159940697819848473151736347809673846048755675063285491534159019684120657920.byte_string
4
+ described_class.get_quality(base).should eq(6197953087261802496)
5
+ end
6
+
7
+ it "returns next quality for base" do
8
+ base = 57159940697819848473151736347809673846048755675063285491534159019684120657920.byte_string
9
+ nxt = 57159940697819848473151736347809673846048755675063285491552605763757830209536
10
+ described_class.get_quality_next(base).to_bn.should eq(nxt)
11
+ end
12
+
13
+ it "returns directory node index"
14
+
15
+ it "returns page index"
16
+
17
+ it "returns account index" do
18
+ account = "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
19
+ described_class.account(account).to_bn.should eq(83149858826312963445632044328430706857892442949720032032422519427184563347763)
20
+ end
21
+
22
+ context "account > issuer" do
23
+ it "returns trust line index" do
24
+ account = "rnixnrMHHvR7ejMpJMRCWkaNrq3qREwMDu"
25
+ iou = {:currency=>"EUR", :account=>"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"}
26
+ described_class.line(account, iou).to_bn.should eq(45370088078399581796930875479259405419767996706903582207576813674682296859050)
27
+ end
28
+ end
29
+
30
+ context "account < issuer" do
31
+ it "returns trust line index" do
32
+ account = "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
33
+ iou = {:currency=>"EUR", :account=>"rnixnrMHHvR7ejMpJMRCWkaNrq3qREwMDu"}
34
+ described_class.line(account, iou).to_bn.should eq(45370088078399581796930875479259405419767996706903582207576813674682296859050)
35
+ end
36
+ end
37
+
38
+ it "returns order book index" do
39
+ input = {:currency=>"USD", :account=>"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"}
40
+ output = {:currency=>"EUR", :account=>"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"}
41
+ described_class.order_book(input, output).to_bn.should eq(57159940697819848473151736347809673846048755675063285491527961066596858855424)
42
+ end
43
+ end
@@ -0,0 +1,12 @@
1
+ describe XRBP::NodeStore::Rate do
2
+ it "is convertable to an amount" do
3
+ rate = described_class.new 2000000000
4
+ amount = rate.to_amount
5
+
6
+ amount.issue.should be(XRBP::NodeStore.no_issue)
7
+ amount.mantissa.should eq(2000000000000000)
8
+ amount.exponent.should eq(-15)
9
+
10
+ amount.iou_amount.should eq(2)
11
+ end
12
+ end
@@ -0,0 +1,44 @@
1
+ describe XRBP::SHAMap::InnerNode do
2
+ context "no branches" do
3
+ it "is empty"
4
+
5
+ it "always returns true empty_branch?"
6
+
7
+ it "always returns nil child hash"
8
+
9
+ it "always returns nil child"
10
+ end
11
+
12
+ context "child branches" do
13
+ before(:each) do
14
+ end
15
+
16
+ it "is not empty"
17
+
18
+ context "querying for non-empty child" do
19
+ it "returns false empty_branch?"
20
+
21
+ it "it returns child hash"
22
+
23
+ it "returns child"
24
+ end
25
+
26
+ context "querying for empty child" do
27
+ it "returns true empty_branch?"
28
+
29
+ it "returns nil child hash"
30
+
31
+ it "returns nil child"
32
+ end
33
+
34
+ context "querying for invalid branch" do
35
+ it "always return true empty_child?"
36
+
37
+ it "raises error when retrieving child hash"
38
+
39
+ it "raises error when retrieving child"
40
+ end
41
+ end
42
+
43
+ it "updates hash"
44
+ end # describe XRBP::SHAMap::InnerNode
@@ -0,0 +1,9 @@
1
+ describe XRBP::SHAMap::Node do
2
+ it "makes tx_id node"
3
+
4
+ it "makes leaf_node node"
5
+
6
+ it "makes inner_node node"
7
+
8
+ it "makes tx_node node"
9
+ end # describe XRBP::SHAMap::Node
@@ -0,0 +1,6 @@
1
+ describe XRBP::SHAMap::NodeID do
2
+ it "returns masks for depth"
3
+ it "returns mask for depth"
4
+ it "returns branch for given hash"
5
+ it "returns child node id for given branch"
6
+ end # describe XRBP::SHAMap::NodeID
@@ -0,0 +1,25 @@
1
+ describe XRBP::SHAMap::Node do
2
+ it "is not a tree_node?" do
3
+ expect(described_class.new).to_not be_a_tree_node
4
+ end
5
+
6
+ it "is not an inner?" do
7
+ expect(described_class.new).to_not be_an_inner
8
+ end
9
+
10
+ it "does not allow hash to be updated" do
11
+ expect { described_class.new.update_hash }.to raise_error("abstract: must be called on a subclass")
12
+ end
13
+
14
+ context "leaf type" do
15
+ it "is a leaf?" do
16
+ expect(described_class.new(:type => :transaction_nm)).to be_a_leaf
17
+ end
18
+ end
19
+
20
+ context "non leaf type" do
21
+ it "is not a leaf?" do
22
+ expect(described_class.new(:type => :infer)).to_not be_a_leaf
23
+ end
24
+ end
25
+ end # describe XRBP::SHAMap::Node
@@ -0,0 +1,144 @@
1
+ describe XRBP::SHAMap do
2
+ describe "#each" do
3
+ it "iterates over all SHAMap items"
4
+ end
5
+
6
+ describe "#succ" do
7
+ it "returns next key in tree greater than specified one"
8
+
9
+ context "next item is map end" do
10
+ it "returns nil"
11
+ end
12
+
13
+ context "next item is >= last" do
14
+ it "returns nil"
15
+ end
16
+ end
17
+
18
+ describe "#read" do
19
+ it "returns SLE read from database"
20
+
21
+ context "specified key is zero" do
22
+ it "raises error"
23
+ end
24
+
25
+ context "not found" do
26
+ it "returns nil"
27
+ end
28
+ end
29
+
30
+ describe "#peek_item" do
31
+ it "returns item corresponding to database key"
32
+
33
+ context "item not found" do
34
+ it "returns nil"
35
+ end
36
+ end
37
+
38
+ describe "#peek_first_item" do
39
+ it "returns first item below root and stack"
40
+
41
+ context "no item" do
42
+ it "returns nil"
43
+ end
44
+ end
45
+
46
+ describe "#peek_next_item" do
47
+ it "returns next item in map"
48
+
49
+ context "specified stack is empty" do
50
+ it "raises error"
51
+ end
52
+
53
+ context "top of stack is not leaf" do
54
+ it "raises error"
55
+ end
56
+ end
57
+
58
+ describe "#fetch_node" do
59
+ it "retrieves node from db"
60
+
61
+ context "node not found" do
62
+ it "raises error"
63
+ end
64
+ end
65
+
66
+ describe "#fetch_node_nt" do
67
+ it "retrieves node from db"
68
+
69
+ context "node not found" do
70
+ it "does not raise error"
71
+ end
72
+ end
73
+
74
+ describe "#fetch_root" do
75
+ it "sets @root database node and returns true"
76
+
77
+ context "root already set" do
78
+ it "returns true"
79
+ end
80
+
81
+ context "node not found" do
82
+ it "returns false"
83
+ end
84
+ end
85
+
86
+ describe "#find_key" do
87
+ it "finds node corresponding to key in map"
88
+
89
+ context "key not found" do
90
+ it "returns nil"
91
+ end
92
+ end
93
+
94
+ describe "#fetch_node_from_db" do
95
+ it "retrieves key from nodestore"
96
+ it "creates corresponding node"
97
+ end
98
+
99
+ describe "#upper_bound" do
100
+ it "returns first item in tree with key > given key"
101
+ end
102
+
103
+ describe "#walk_towards_key" do
104
+ it "returns path stack of node traversal to key"
105
+ end
106
+
107
+ describe "#descend_throw" do
108
+ it "descends to parent branch"
109
+
110
+ context "could not descend to non-empty branch" do
111
+ it "raises error"
112
+ end
113
+ end
114
+
115
+ describe "#descend" do
116
+ it "retrieve cached child node at parent branch"
117
+
118
+ context "parent branch child node not set" do
119
+ it "fetches and returns node"
120
+
121
+ context "not not able to be retrieved" do
122
+ it "returns nil"
123
+ end
124
+
125
+ context "node is inconsistent" do
126
+ it "returns nil"
127
+ end
128
+
129
+ it "stores child in parent"
130
+ end
131
+ end
132
+
133
+ describe "#first_below" do
134
+ it "returns first leaf node at or below the specified node"
135
+ end
136
+
137
+ describe "#cdir_first" do
138
+ it "returns the first directory index in the node specified by index"
139
+ end
140
+
141
+ describe "#cdir_next" do
142
+ it "returns the next directory index in the node specified by index"
143
+ end
144
+ end # describe XRBP::SHAMap
@@ -0,0 +1,7 @@
1
+ describe XRBP::NodeStore::STAmount do
2
+ it "is addable"
3
+ it "is subtactable"
4
+ it "is divisable"
5
+ it "is multiplicable"
6
+ it "is negatable"
7
+ end # describe XRBP::NodeStore::STAmount
@@ -0,0 +1,11 @@
1
+ describe XRBP::NodeStore::STAmount do
2
+ it "is < other amount"
3
+
4
+ it "is > other amount"
5
+
6
+ it "is >= other amount"
7
+
8
+ it "is == other amount"
9
+
10
+ it "is <=> other amount"
11
+ end # describe XRBP::NodeStore::STAmount
@@ -0,0 +1,64 @@
1
+ describe XRBP::NodeStore::STAmount do
2
+ it "is negatable"
3
+
4
+ it "is convertable to/from wire format" do
5
+ v = 1000000000000
6
+ s = described_class.new(:mantissa => v)
7
+ expect(described_class.from_wire(s.to_wire).to_h).to eq(s.to_h)
8
+
9
+ s = described_class.new(:mantissa => v,
10
+ :issue => XRBP::NodeStore.xrp_issue)
11
+ expect(described_class.from_wire(s.to_wire).to_h).to eq(s.to_h)
12
+ end
13
+
14
+ it "can be parsed from string" do
15
+ s = "12345.6789"
16
+ expect(described_class.parse(s).iou_amount.to_f).to eq(s.to_f)
17
+
18
+ expect { described_class.parse("whatever") }.to raise_error("Number 'whatever' is not valid")
19
+ end
20
+
21
+ context "canonicalize" do
22
+ context "native amount" do
23
+ context "zero mantissa" do
24
+ it "zeros exponent"
25
+ it "is not negative"
26
+ end
27
+
28
+ it "zeros exponent"
29
+ end
30
+
31
+ context "zero mantissa" do
32
+ it "sets exponent to -100"
33
+ it "is not negative"
34
+ end
35
+
36
+ it "increases mantissa to >= MIN_VAL"
37
+ it "increases mantissa to <= MAX_VAL"
38
+
39
+ it "increases exponent to >= MIN_OFFSET"
40
+ it "descreases exponent to <= MAX_OFFSET"
41
+
42
+ context "offset cannot be set appropriately" do
43
+ it "raises value overflow"
44
+ end
45
+
46
+ context "manitssa out of bounds" do
47
+ it "raises error"
48
+ end
49
+
50
+ context "exponent out of bounds" do
51
+ it "raises error"
52
+ end
53
+
54
+ context "invalid mantissa / exponent combination" do
55
+ it "raises error"
56
+ end
57
+ end # describe #canoncialize
58
+
59
+ it "clears amount"
60
+
61
+ it "returns sn_value"
62
+ it "returns xrp_amount"
63
+ it "returns iou_amount"
64
+ end # describe XRBP::NodeStore::STAmount