openassets-ruby 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +3 -3
- data/exe/openassets +1 -0
- data/lib/openassets/api.rb +10 -9
- data/lib/openassets/cache/transaction_cache.rb +39 -0
- data/lib/openassets/cache.rb +5 -0
- data/lib/openassets/version.rb +1 -1
- data/lib/openassets.rb +1 -0
- data/openassets-ruby.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10d7759652e07b134eee52b630c86a5694bf9370
|
4
|
+
data.tar.gz: dacced4d83bbc49aa52cf6aa2eed2a1d6e83d6a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ea0b2089ab5bda555d36b599e080b104b95f86587330f9836e6c07c32151d92b8545e24a2c4badb66597c24af728016b90ac96c328a35850f78562b37a6a0fb
|
7
|
+
data.tar.gz: 93582e63690146c92f6794f72ea6fb590a98e7dc68c848dd4f1fa04dfad1263b9db7705ddd47961592b91362acb9a9b1217c14064317f6d97beced0442d673ce
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Initialize the connection information to the Bitcoin Core server.
|
|
16
16
|
require 'openassets'
|
17
17
|
|
18
18
|
api = OpenAssets::Api.new({:network => 'mainnet',
|
19
|
-
:provider => 'bitcoind',
|
19
|
+
:provider => 'bitcoind', :cache => 'cache.db',
|
20
20
|
:dust_limit => 600, :default_fees => 10000, :min_confirmation => 1, :max_confirmation => 9999999,
|
21
21
|
:rpc => {:user => 'xxx', :password => 'xxx', :schema => 'http', :port => 8332, :host => 'localhost'}})
|
22
22
|
```
|
@@ -27,7 +27,7 @@ change :network and :port(depends on your server setting).
|
|
27
27
|
require 'openassets'
|
28
28
|
|
29
29
|
api = OpenAssets::Api.new({:network => 'testnet',
|
30
|
-
:provider => 'bitcoind',
|
30
|
+
:provider => 'bitcoind', :cache => 'testnet.db',
|
31
31
|
:dust_limit => 600, :default_fees => 10000, :min_confirmation => 1, :max_confirmation => 9999999,
|
32
32
|
:rpc => {:user => 'xxx', :password => 'xxx', :schema => 'http', :port => 18332, :host => 'localhost'}})
|
33
33
|
```
|
@@ -38,6 +38,7 @@ The configuration options are as follows:
|
|
38
38
|
|---|---|---|
|
39
39
|
|**network**|The using network. "mainnet" or "testnet" |mainnet|
|
40
40
|
|**provider**|The RPC server. Specify possible now only "bitcoind".|bitcoind|
|
41
|
+
|**cache**|The path to the database file. If you want to use in-memory database, specify ':memory:'.|cache.db|
|
41
42
|
|**dust_limit**|The amount of Bitcoin, which is set to the each output of the Open Assets Protocol(issue or transfer).|600 (satoshi)|
|
42
43
|
|**default_fees**|The transaction fee. (used by issue_asset and send_asset, send_bitcoin )|10000 (satoshi)|
|
43
44
|
|**min_confirmation**|The minimum number of confirmations the transaction containing an output that used to get UTXO.|1|
|
@@ -227,7 +228,6 @@ This API is to burn the asset by spending the all UTXO of specified asset as Bit
|
|
227
228
|
asset_id = 'oGu4VXx2TU97d9LmPP8PMCkHckkcPqC5RY'
|
228
229
|
tx = api.burn_asset(oa_address, asset_id, 10000)
|
229
230
|
```
|
230
|
-
|
231
231
|
**Note:** Burned asset will not be able to again get.
|
232
232
|
|
233
233
|
## Command line interface
|
data/exe/openassets
CHANGED
@@ -32,6 +32,7 @@ if options[:env]
|
|
32
32
|
config = {
|
33
33
|
:network => ENV['OA_NETWORK'] || 'mainnet',
|
34
34
|
:provider => 'bitcoind',
|
35
|
+
:cache => ENV['OA_CACHE'] || 'cache.db',
|
35
36
|
:dust_limit => (ENV['OA_DUST_LIMIT'] || 600).to_i,
|
36
37
|
:default_fees => (ENV['OA_DEFAULT_FEES'] || 10000).to_i,
|
37
38
|
:rpc => rpc
|
data/lib/openassets/api.rb
CHANGED
@@ -11,12 +11,11 @@ module OpenAssets
|
|
11
11
|
|
12
12
|
attr_reader :config
|
13
13
|
attr_reader :provider
|
14
|
-
attr_reader :
|
14
|
+
attr_reader :tx_cache
|
15
15
|
|
16
16
|
def initialize(config = nil)
|
17
|
-
@cache = {}
|
18
17
|
@config = {:network => 'mainnet',
|
19
|
-
:provider => 'bitcoind',
|
18
|
+
:provider => 'bitcoind', :cache => 'cache.db',
|
20
19
|
:dust_limit => 600, :default_fees => 10000, :min_confirmation => 1, :max_confirmation => 9999999,
|
21
20
|
:rpc => { :host => 'localhost', :port => 8332 , :user => '', :password => '', :schema => 'https'}}
|
22
21
|
if config
|
@@ -27,6 +26,7 @@ module OpenAssets
|
|
27
26
|
else
|
28
27
|
raise OpenAssets::Error, 'specified unsupported provider.'
|
29
28
|
end
|
29
|
+
@tx_cache = Cache::TransactionCache.new(@config[:cache])
|
30
30
|
end
|
31
31
|
|
32
32
|
def provider
|
@@ -186,13 +186,14 @@ module OpenAssets
|
|
186
186
|
end
|
187
187
|
|
188
188
|
def get_output(txid, output_index)
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
189
|
+
decode_tx = tx_cache.get(txid)
|
190
|
+
if decode_tx.nil?
|
191
|
+
decode_tx = provider.get_transaction(txid, 0)
|
192
|
+
raise OpenAssets::Transaction::TransactionBuildError, "txid #{txid} could not be retrieved." if decode_tx.nil?
|
193
|
+
tx_cache.put(txid, decode_tx)
|
194
|
+
end
|
193
195
|
tx = Bitcoin::Protocol::Tx.new(decode_tx.htb)
|
194
196
|
colored_outputs = get_color_outputs_from_tx(tx)
|
195
|
-
colored_outputs.each_with_index { |o, index | @cache[txid + index.to_s] = o}
|
196
197
|
colored_outputs[output_index]
|
197
198
|
end
|
198
199
|
|
@@ -213,7 +214,7 @@ module OpenAssets
|
|
213
214
|
tx.outputs.map{|out| OpenAssets::Protocol::TransactionOutput.new(out.value, out.parsed_script, nil, 0, OpenAssets::Protocol::OutputType::UNCOLORED)}
|
214
215
|
end
|
215
216
|
|
216
|
-
# Get tx outputs.
|
217
|
+
# Get tx outputs. This method will always get the latest transaction without the cache.
|
217
218
|
# @param[String] txid Transaction ID.
|
218
219
|
# @return[Array] Return array of the transaction output Hash with coloring information.
|
219
220
|
def get_outputs_from_txid(txid)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
module OpenAssets
|
3
|
+
module Cache
|
4
|
+
|
5
|
+
# An object that can be used for caching serialized transaction in a Sqlite database.
|
6
|
+
class TransactionCache
|
7
|
+
|
8
|
+
attr_reader :db
|
9
|
+
|
10
|
+
# Initializes the connection to the database, and creates the table if needed.
|
11
|
+
# @param[String] path The path to the database file. Use ':memory:' for an in-memory database.
|
12
|
+
def initialize(path)
|
13
|
+
@db = SQLite3::Database.new path
|
14
|
+
@db.execute <<-SQL
|
15
|
+
CREATE TABLE IF NOT EXISTS Tx(
|
16
|
+
TransactionHash BLOB,
|
17
|
+
SerializedTx BLOB,
|
18
|
+
PRIMARY KEY (TransactionHash))
|
19
|
+
SQL
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return the serialized transaction.
|
23
|
+
# @param[String] txid The transaction id.
|
24
|
+
# @return[String] The serialized transaction. If not found transaction, return nil.
|
25
|
+
def get(txid)
|
26
|
+
rows = db.execute('SELECT SerializedTx FROM Tx WHERE TransactionHash = ?', [txid])
|
27
|
+
rows.empty? ? nil : rows[0][0]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Saves a serialized transaction in cache.
|
31
|
+
# @param[String] txid A transaction id.
|
32
|
+
# @param[String] serialized_tx A a hex-encoded serialized transaction.
|
33
|
+
def put(txid, serialized_tx)
|
34
|
+
db.execute('INSERT INTO Tx (TransactionHash, SerializedTx) VALUES (?, ?)', [txid, serialized_tx])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/lib/openassets/version.rb
CHANGED
data/lib/openassets.rb
CHANGED
data/openassets-ruby.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency "ffi", "~>1.9.8"
|
23
23
|
spec.add_runtime_dependency "rest-client", "~>1.8.0"
|
24
24
|
spec.add_runtime_dependency "httpclient"
|
25
|
+
spec.add_runtime_dependency "sqlite3"
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.9"
|
26
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
28
|
spec.add_development_dependency "rspec"
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bitcoin-ruby
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,6 +145,8 @@ files:
|
|
131
145
|
- exe/openassets
|
132
146
|
- lib/openassets.rb
|
133
147
|
- lib/openassets/api.rb
|
148
|
+
- lib/openassets/cache.rb
|
149
|
+
- lib/openassets/cache/transaction_cache.rb
|
134
150
|
- lib/openassets/error.rb
|
135
151
|
- lib/openassets/medhod_filter.rb
|
136
152
|
- lib/openassets/protocol.rb
|