openassets-ruby 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openassets/api.rb +5 -0
- data/lib/openassets/cache.rb +1 -0
- data/lib/openassets/cache/output_cache.rb +43 -0
- data/lib/openassets/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60e7e03e2ce20dc31b0b20f7e9d7e4892b63f931
|
4
|
+
data.tar.gz: b8165d84e4d59270055405e88aaeb8cfdd42774f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acaaf6e614f5893c35077949ab08e4116f1848b9239a2f1253267c027f2a692d161441481d301541d479b5030d1565501cc80a2f7be91ca188e2ee16873e3ef9
|
7
|
+
data.tar.gz: a4a5ff1acceb689fef68dbf79681d885c9e8326a5e64f5966967975697d89d051d0a49a2f51644c9308d92a5a4b8bc6a8cc0875b8a3e55c510f02e3ca0bb2256
|
data/lib/openassets/api.rb
CHANGED
@@ -12,6 +12,7 @@ module OpenAssets
|
|
12
12
|
attr_reader :config
|
13
13
|
attr_reader :provider
|
14
14
|
attr_reader :tx_cache
|
15
|
+
attr_reader :output_cache
|
15
16
|
|
16
17
|
def initialize(config = nil)
|
17
18
|
@config = {:network => 'mainnet',
|
@@ -28,6 +29,7 @@ module OpenAssets
|
|
28
29
|
raise OpenAssets::Error, 'specified unsupported provider.'
|
29
30
|
end
|
30
31
|
@tx_cache = Cache::TransactionCache.new(@config[:cache])
|
32
|
+
@output_cache = Cache::OutputCache.new(@config[:cache])
|
31
33
|
end
|
32
34
|
|
33
35
|
def provider
|
@@ -187,9 +189,12 @@ module OpenAssets
|
|
187
189
|
end
|
188
190
|
|
189
191
|
def get_output(txid, output_index)
|
192
|
+
cached = output_cache.get(txid, output_index)
|
193
|
+
return cached unless cached.nil?
|
190
194
|
decode_tx = load_cached_tx(txid)
|
191
195
|
tx = Bitcoin::Protocol::Tx.new(decode_tx.htb)
|
192
196
|
colored_outputs = get_color_outputs_from_tx(tx)
|
197
|
+
colored_outputs.each_with_index { |o, index| output_cache.put(txid, index, o)}
|
193
198
|
colored_outputs[output_index]
|
194
199
|
end
|
195
200
|
|
data/lib/openassets/cache.rb
CHANGED
@@ -3,5 +3,6 @@ module OpenAssets
|
|
3
3
|
autoload :SQLiteBase, 'openassets/cache/sqlite_base'
|
4
4
|
autoload :TransactionCache, 'openassets/cache/transaction_cache'
|
5
5
|
autoload :SSLCertificateCache, 'openassets/cache/ssl_certificate_cache'
|
6
|
+
autoload :OutputCache, 'openassets/cache/output_cache'
|
6
7
|
end
|
7
8
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module OpenAssets
|
2
|
+
module Cache
|
3
|
+
|
4
|
+
# An object that can be used for caching coloring transaction output in a Sqlite database.
|
5
|
+
class OutputCache < SQLiteBase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
db.execute <<-SQL
|
9
|
+
CREATE TABLE IF NOT EXISTS Output(
|
10
|
+
TransactionHash BLOB,
|
11
|
+
OutputIndex INT,
|
12
|
+
Value BigInt,
|
13
|
+
Script BLOB,
|
14
|
+
AssetId BLOB,
|
15
|
+
AssetQuantity INT,
|
16
|
+
OutputType INT,
|
17
|
+
Metadata BLOB,
|
18
|
+
PRIMARY KEY (TransactionHash, OutputIndex))
|
19
|
+
SQL
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get a cached transaction output
|
23
|
+
# @param[String] txid The transaction id.
|
24
|
+
# @param[Integer] index The index of the output in the transaction.
|
25
|
+
# @return[OpenAssets::Protocol::TransactionOutput] The output for the txid and index provided if it is found in the cache, or nil otherwise.
|
26
|
+
def get(txid, index)
|
27
|
+
rows = db.execute('SELECT Value,Script,AssetId,AssetQuantity,OutputType,Metadata FROM Output WHERE TransactionHash = ? AND OutputIndex = ?', [txid, index])
|
28
|
+
return nil if rows.empty?
|
29
|
+
script = Bitcoin::Script.from_string(rows[0][1])
|
30
|
+
OpenAssets::Protocol::TransactionOutput.new(rows[0][0], script, rows[0][2], rows[0][3], rows[0][4], rows[0][5])
|
31
|
+
end
|
32
|
+
|
33
|
+
# Put a transaction output
|
34
|
+
# @param[String] txid The transaction id.
|
35
|
+
# @param[Integer] index The index of the output in the transaction.
|
36
|
+
# @param[OpenAssets::Protocol::TransactionOutput] output The output to save.
|
37
|
+
def put(txid, index, output)
|
38
|
+
db.execute('INSERT INTO Output (TransactionHash, OutputIndex, Value,Script,AssetId,AssetQuantity,OutputType,Metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
|
39
|
+
[txid, index, output.value, output.script.to_string, output.asset_id, output.asset_quantity, output.output_type, output.metadata])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/openassets/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openassets-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bitcoin-ruby
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/openassets.rb
|
161
161
|
- lib/openassets/api.rb
|
162
162
|
- lib/openassets/cache.rb
|
163
|
+
- lib/openassets/cache/output_cache.rb
|
163
164
|
- lib/openassets/cache/sqlite_base.rb
|
164
165
|
- lib/openassets/cache/ssl_certificate_cache.rb
|
165
166
|
- lib/openassets/cache/transaction_cache.rb
|