class OpenAssets::Cache::OutputCache
An object that can be used for caching coloring transaction output in a Sqlite database.
Public Instance Methods
get(txid, index)
click to toggle source
Get a cached transaction output @param txid The transaction id. @param index The index of the output in the transaction. @return The output for the txid and index provided if it is found in the cache, or nil otherwise.
# File lib/openassets/cache/output_cache.rb, line 26 def get(txid, index) rows = db.execute('SELECT Value,Script,AssetId,AssetQuantity,OutputType,Metadata FROM Output WHERE TransactionHash = ? AND OutputIndex = ?', [txid, index]) return nil if rows.empty? script = Bitcoin::Script.from_string(rows[0][1]) OpenAssets::Protocol::TransactionOutput.new(rows[0][0], script, rows[0][2], rows[0][3], rows[0][4], rows[0][5]) end
put(txid, index, output)
click to toggle source
Put a transaction output @param txid The transaction id. @param index The index of the output in the transaction. @param output The output to save.
# File lib/openassets/cache/output_cache.rb, line 37 def put(txid, index, output) db.execute('INSERT INTO Output (TransactionHash, OutputIndex, Value,Script,AssetId,AssetQuantity,OutputType,Metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', [txid, index, output.value, output.script.to_s, output.asset_id, output.asset_quantity, output.output_type, output.metadata]) end
setup()
click to toggle source
# File lib/openassets/cache/output_cache.rb, line 7 def setup db.execute <<-SQL CREATE TABLE IF NOT EXISTS Output( TransactionHash BLOB, OutputIndex INT, Value BigInt, Script BLOB, AssetId BLOB, AssetQuantity INT, OutputType INT, Metadata BLOB, PRIMARY KEY (TransactionHash, OutputIndex)) SQL end