class OpenAssets::Cache::TransactionCache

An object that can be used for caching serialized transaction in a Sqlite database.

Public Instance Methods

get(txid) click to toggle source

Return the serialized transaction. @param txid The transaction id. @return The serialized transaction. If not found transaction, return nil.

# 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) click to toggle source

Saves a serialized transaction in cache. @param txid A transaction id. @param serialized_tx A a hex-encoded serialized transaction.

# 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() click to toggle source
# 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