Module: XRBP::NodeStore::Indexes
- Defined in:
- lib/xrbp/nodestore/protocol/indexes.rb
Overview
Return DB lookup indices for the following artifacts
Class Method Summary collapse
-
.account(id) ⇒ Object
Account index from id.
- .dir_node_index(root, index) ⇒ Object
- .get_quality(base) ⇒ Object
- .get_quality_next(base) ⇒ Object
-
.line(account, iou) ⇒ Object
Trust line for account/iou.
-
.offer_index(id, seq) ⇒ Object
TODO: Offer Index for account id and seq.
-
.order_book(input, output) ⇒ Object
Order book index for given input/output.
-
.owner_dir(id) ⇒ Object
TODO: Account Owner Dir from id.
- .page(key, index) ⇒ Object
Class Method Details
.account(id) ⇒ Object
Account index from id
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/xrbp/nodestore/protocol/indexes.rb', line 36 def self.account(id) id = Crypto.account_id(id) sha512 = OpenSSL::Digest::SHA512.new sha512 << "\0" sha512 << Format::LEDGER_NAMESPACE[:account] sha512 << id sha512.digest[0..31] end |
.dir_node_index(root, index) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/xrbp/nodestore/protocol/indexes.rb', line 19 def self.dir_node_index(root, index) return root if index == 0 sha512 = OpenSSL::Digest::SHA512.new sha512 << "\0" sha512 << Format::LEDGER_NAMESPACE[:dir_node] sha512 << root sha512 << index.bytes.rjust!(8, 0).pack("C*") sha512.digest[0..31] end |
.get_quality(base) ⇒ Object
6 7 8 9 10 |
# File 'lib/xrbp/nodestore/protocol/indexes.rb', line 6 def self.get_quality(base) # FIXME: assuming native platform is big endian, # need to account for all platforms base[-8..-1].to_bn end |
.get_quality_next(base) ⇒ Object
12 13 14 15 |
# File 'lib/xrbp/nodestore/protocol/indexes.rb', line 12 def self.get_quality_next(base) nxt = "10000000000000000".to_i(16) (base.to_bn + nxt).byte_string end |
.line(account, iou) ⇒ Object
Trust line for account/iou
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/xrbp/nodestore/protocol/indexes.rb', line 56 def self.line(account, iou) account = Crypto.account_id(account) issuer = Crypto.account_id(iou[:account]) sha512 = OpenSSL::Digest::SHA512.new sha512 << "\0" sha512 << Format::LEDGER_NAMESPACE[:ripple] if account.to_bn < issuer.to_bn sha512 << account sha512 << issuer else sha512 << issuer sha512 << account end sha512 << Format.encode_currency(iou[:currency]) sha512.digest[0..31] end |
.offer_index(id, seq) ⇒ Object
TODO: Offer Index for account id and seq
52 53 |
# File 'lib/xrbp/nodestore/protocol/indexes.rb', line 52 def self.offer_index(id, seq) end |
.order_book(input, output) ⇒ Object
Order book index for given input/output
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/xrbp/nodestore/protocol/indexes.rb', line 79 def self.order_book(input, output) input = Hash[input] output = Hash[output] # Currency always upcase input[:currency].upcase! output[:currency].upcase! # If currency == 'XRP' set corresponding issuer input[:account] = Crypto.xrp_account if input[:currency] == 'XRP' output[:account] = Crypto.xrp_account if output[:currency] == 'XRP' # Convert currency to binary representation input[:currency] = Format.encode_currency(input[:currency]) output[:currency] = Format.encode_currency(output[:currency]) # convert input / output account to binary representation input[:account] = Crypto.account_id(input[:account]) output[:account] = Crypto.account_id(output[:account]) book_base = ["\0", Format::LEDGER_NAMESPACE[:book_dir], input[:currency], output[:currency], input[:account], output[:account]].join sha512 = OpenSSL::Digest::SHA512.new book_base = sha512.digest(book_base)[0..31] # XXX: get_quality_index shorthand: book_base[-8..-1] = [0, 0, 0, 0, 0, 0, 0, 0].pack("C*") book_base end |
.owner_dir(id) ⇒ Object
TODO: Account Owner Dir from id
48 49 |
# File 'lib/xrbp/nodestore/protocol/indexes.rb', line 48 def self.owner_dir(id) end |
.page(key, index) ⇒ Object
31 32 33 |
# File 'lib/xrbp/nodestore/protocol/indexes.rb', line 31 def self.page(key, index) dir_node_index key, index end |