Class: OpenAssets::Cache::TransactionCache
- Inherits:
-
SQLiteBase
- Object
- SQLiteBase
- OpenAssets::Cache::TransactionCache
- Defined in:
- lib/openassets/cache/transaction_cache.rb
Overview
An object that can be used for caching serialized transaction in a Sqlite database.
Instance Attribute Summary
Attributes inherited from SQLiteBase
Instance Method Summary collapse
-
#get(txid) ⇒ Object
Return the serialized transaction.
-
#put(txid, serialized_tx) ⇒ Object
Saves a serialized transaction in cache.
- #setup ⇒ Object
Methods inherited from SQLiteBase
Constructor Details
This class inherits a constructor from OpenAssets::Cache::SQLiteBase
Instance Method Details
#get(txid) ⇒ Object
19 20 21 22 |
# File 'lib/openassets/cache/transaction_cache.rb', line 19 def get(txid) rows = db.execute('SELECT SerializedTx FROM Tx WHERE TransactionHash = ?', [txid]) rows.empty? ? nil : rows[0][0] end |
#put(txid, serialized_tx) ⇒ Object
27 28 29 |
# File 'lib/openassets/cache/transaction_cache.rb', line 27 def put(txid, serialized_tx) db.execute('INSERT INTO Tx (TransactionHash, SerializedTx) VALUES (?, ?)', [txid, serialized_tx]) end |
#setup ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/openassets/cache/transaction_cache.rb', line 7 def setup db.execute <<-SQL CREATE TABLE IF NOT EXISTS Tx( TransactionHash BLOB, SerializedTx BLOB, PRIMARY KEY (TransactionHash)) SQL end |