openassets-ruby 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1bf5ca70ee3d56eb275492e20de8af986e6da15
4
- data.tar.gz: 54c38aaafbfeb618ed5ad35510074b6adacea338
3
+ metadata.gz: 762cb76ac06beeb46aac132bcb5ac714edf67976
4
+ data.tar.gz: 421ce1356c464b70c927b37cf79297b9383329d8
5
5
  SHA512:
6
- metadata.gz: 1a175cb0af22f388f5e372c2df4c532b065d011deae294692a41384e2ae09d1439f600d17e9841a796a531351dc9a4a46219fb4278df99231ce00aa527c51f92
7
- data.tar.gz: 07ea55a4edd0bab117c3b4cfb2d4cb9242aa2cc1ff101dec7cf840e65264beab53c1acda1608a6a4de6430c26927dabd0c0d60eca73fe1680afc22f63a31de34
6
+ metadata.gz: f2d91da9ed7a58efe8eb8139a0e3779fccf6c5c721fd762f901cfe512abb82bdf6cf1558905836c4ee1a012b7833461beba9cab41afb54a35106cde5fccec2dc
7
+ data.tar.gz: 23df64ea454a114ca8f2bbd6d3bd851f716db29008c03166e108b940cdd74efecf32b2aa803756cf6a29adfca572d5e465bc55b9cebf1b7c0cc14883d1fd642a
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.5.0
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.5.0
3
4
  - 2.4.1
4
5
  - 2.4.0
5
6
  - 2.3.0
6
- - 2.2.2
7
7
 
8
8
  bundler_args: --jobs=2
9
9
 
data/README.md CHANGED
@@ -12,51 +12,81 @@ gem install openassets-ruby
12
12
  Initialize the connection information to the Bitcoin Core server.
13
13
 
14
14
  * **use mainnet**
15
- ```ruby
16
- require 'openassets'
17
-
18
- api = OpenAssets::Api.new({
19
- network: 'mainnet',
20
- provider: 'bitcoind',
21
- cache: 'cache.db',
22
- dust_limit: 600,
23
- default_fees: 10000,
24
- min_confirmation: 1,
25
- max_confirmation: 9999999,
26
- rpc: {
27
- user: 'xxx',
28
- password: 'xxx',
29
- schema: 'http',
30
- port: 8332,
31
- host: 'localhost',
32
- timeout: 60,
33
- open_timeout: 60 }
34
- })
35
- ```
15
+
16
+ ```ruby
17
+ require 'openassets'
18
+
19
+ api = OpenAssets::Api.new({
20
+ network: 'mainnet',
21
+ provider: 'bitcoind',
22
+ cache: 'cache.db',
23
+ dust_limit: 600,
24
+ default_fees: 10000,
25
+ min_confirmation: 1,
26
+ max_confirmation: 9999999,
27
+ rpc: {
28
+ user: 'xxx',
29
+ password: 'xxx',
30
+ schema: 'http',
31
+ port: 8332,
32
+ host: 'localhost',
33
+ timeout: 60,
34
+ open_timeout: 60 }
35
+ })
36
+ ```
36
37
 
37
38
  * **use testnet**
38
- Change `network` and `port` depending on your server setting.
39
- ```ruby
40
- require 'openassets'
41
-
42
- api = OpenAssets::Api.new({
43
- network: 'testnet',
44
- provider: 'bitcoind',
45
- cache: 'testnet.db',
46
- dust_limit: 600,
47
- default_fees: 10000,
48
- min_confirmation: 1,
49
- max_confirmation: 9999999,
50
- rpc: {
51
- user: 'xxx',
52
- password: 'xxx',
53
- schema: 'http',
54
- port: 18332,
55
- host: 'localhost',
56
- timeout: 60,
57
- open_timeout: 60 }
58
- })
59
- ```
39
+
40
+ Change `network` and `port` depending on your server setting.
41
+
42
+ ```ruby
43
+ require 'openassets'
44
+
45
+ api = OpenAssets::Api.new({
46
+ network: 'testnet',
47
+ provider: 'bitcoind',
48
+ cache: 'testnet.db',
49
+ dust_limit: 600,
50
+ default_fees: 10000,
51
+ min_confirmation: 1,
52
+ max_confirmation: 9999999,
53
+ rpc: {
54
+ user: 'xxx',
55
+ password: 'xxx',
56
+ schema: 'http',
57
+ port: 18332,
58
+ host: 'localhost',
59
+ timeout: 60,
60
+ open_timeout: 60 }
61
+ })
62
+ ```
63
+
64
+ * **with [multi-wallet support](https://github.com/bitcoin/bitcoin/blob/0.15/doc/release-notes/release-notes-0.15.0.md#multi-wallet-support)**
65
+
66
+ From Bitcoin Core version 0.15 onwards, change `wallet` depending on wallet settings.
67
+
68
+ ```ruby
69
+ require 'openassets'
70
+
71
+ api = OpenAssets::Api.new({
72
+ network: 'testnet',
73
+ provider: 'bitcoind',
74
+ cache: 'testnet.db',
75
+ dust_limit: 600,
76
+ default_fees: 10000,
77
+ min_confirmation: 1,
78
+ max_confirmation: 9999999,
79
+ rpc: {
80
+ user: 'xxx',
81
+ password: 'xxx',
82
+ schema: 'http',
83
+ port: 18332,
84
+ host: 'localhost',
85
+ wallet: 'wallet.dat',
86
+ timeout: 60,
87
+ open_timeout: 60 }
88
+ })
89
+ ```
60
90
 
61
91
  The configuration options are as follows:
62
92
 
@@ -64,13 +94,61 @@ The configuration options are as follows:
64
94
  |---|---|---|
65
95
  |**network**|The using network. "mainnet" or "testnet" or "regtest" or "litecoin" or "litecoin_testnet" |mainnet|
66
96
  |**provider**|The RPC server. "bitcoind" is the only option for now.|bitcoind|
67
- |**cache**|The path to the database file. Specify ':memory: to use in-memory database.|cache.db|
97
+ |**cache**|The path to the database file. Specify `':memory:'` to use in-memory database.|cache.db|
68
98
  |**dust_limit**|The amount of Bitcoin, which is set to the each output of the Open Assets Protocol (issue or transfer).|600 (satoshi)|
69
- |**default_fees**|The default transaction fee in satoshi. Specify ':auto' to use auto fee settings. (used by issue_asset and send_asset, send_bitcoin )|10000 (satoshi)|
99
+ |**default_fees**|The default transaction fee in satoshi. Specify `:auto` to use auto fee settings. (used by issue_asset and send_asset, send_bitcoin )|10000 (satoshi)|
70
100
  |**min_confirmation**|The minimum number of confirmations the transaction containing an output that used to get UTXO.|1|
71
101
  |**max_confirmation**|The maximum number of confirmations the transaction containing an output that used to get UTXO.|9999999|
72
102
  |**rpc**|The access information to the RPC server of Bitcoin Core.|N/A|
73
103
 
104
+ ### Using the API with multi-wallet support
105
+
106
+ To use the Bitcoin Core multi-wallet support ([version 0.15 onwards](https://github.com/bitcoin/bitcoin/blob/0.15/doc/release-notes/release-notes-0.15.0.md#multi-wallet-support)), you should use multiple instances of API, for example:
107
+
108
+ ```ruby
109
+ @apis = Hash.new
110
+ @apis[1] = OpenAssets::Api.new({
111
+ network: 'testnet',
112
+ provider: 'bitcoind',
113
+ cache: 'testnet.db',
114
+ dust_limit: 600,
115
+ default_fees: 10000,
116
+ min_confirmation: 1,
117
+ max_confirmation: 9999999,
118
+ rpc: {
119
+ user: 'xxx',
120
+ password: 'xxx',
121
+ schema: 'http',
122
+ port: 18332,
123
+ host: 'localhost',
124
+ wallet: 'wallet001.dat',
125
+ timeout: 60,
126
+ open_timeout: 60 }
127
+ })
128
+ @apis[2] = OpenAssets::Api.new({
129
+ network: 'testnet',
130
+ provider: 'bitcoind',
131
+ cache: 'testnet.db',
132
+ dust_limit: 600,
133
+ default_fees: 10000,
134
+ min_confirmation: 1,
135
+ max_confirmation: 9999999,
136
+ rpc: {
137
+ user: 'xxx',
138
+ password: 'xxx',
139
+ schema: 'http',
140
+ port: 18332,
141
+ host: 'localhost',
142
+ wallet: 'wallet002.dat',
143
+ timeout: 60,
144
+ open_timeout: 60 }
145
+ })
146
+ # More wallets perhaps...
147
+ # Then call API selectively
148
+ @apis[1].provider.list_unspent
149
+ @apis[2].provider.list_unspent
150
+ ```
151
+
74
152
  ## API
75
153
 
76
154
  Currently openassets-ruby support the following API.
@@ -183,10 +261,10 @@ Creates a transaction for issuing an asset.
183
261
  api.issue_asset(address, 150, 'u=https://goo.gl/bmVEuw', address, nil, 'broadcast')
184
262
  ```
185
263
  If specified ``output_qty``, the issue output is divided by the number of output_qty.
186
- Ex, amount = 125 and output_qty = 2, the marker output asset quantity is [62, 63] and issue TxOut is two.
264
+ For example, amount = 125 and output_qty = 2, the marker output asset quantity is [62, 63] and issue TxOut is two.
187
265
 
188
266
  * **send_asset**
189
- Creates a transaction for sending an asset from the open asset address to another.
267
+ Creates a transaction for sending an asset from the open asset address to another.
190
268
  ```ruby
191
269
  # send asset
192
270
  # api.send_asset(<from open asset address>,
@@ -316,7 +394,8 @@ This API is to burn the asset by spending the all UTXO of specified asset as Bit
316
394
  asset_id = 'oGu4VXx2TU97d9LmPP8PMCkHckkcPqC5RY'
317
395
  tx = api.burn_asset(oa_address, asset_id)
318
396
  ```
319
- **Note:** Burned asset will not be able to again get.
397
+
398
+ **Note:** Burnt asset will be lost forever.
320
399
 
321
400
  ## Command line interface
322
401
 
@@ -328,10 +407,10 @@ Openassets-ruby comes with a `openassets` command line interface that allows eas
328
407
 
329
408
  Options:
330
409
  -c path to config JSON which is passed to OpenAssets::Api.new - see Configuration for details
331
- -e load conifg from ENV variables (look at the exe/openassets file for details)
410
+ -e load config from ENV variables (look at the exe/openassets file for details)
332
411
 
333
412
  commands:
334
- * console runs an IRB console and gives you an initialized Api instance to interact with OpenAssets
413
+ * console runs an IRB console and gives you an initialized API instance to interact with OpenAssets
335
414
  * any method on the API instance, helpful for get_balance, list_unspent
336
415
 
337
416
 
@@ -18,7 +18,8 @@ module OpenAssets
18
18
  @config = {:network => 'mainnet',
19
19
  :provider => 'bitcoind', :cache => 'cache.db',
20
20
  :dust_limit => 600, :default_fees => 10000, :min_confirmation => 1, :max_confirmation => 9999999,
21
- :rpc => { :host => 'localhost', :port => 8332 , :user => '', :password => '', :schema => 'https', :timeout => 60, :open_timeout => 60}}
21
+ :rpc => {:host => 'localhost', :port => 8332 , :user => '', :password => '', :wallet => '',
22
+ :schema => 'https', :timeout => 60, :open_timeout => 60}}
22
23
  if config
23
24
  @config.update(config)
24
25
  end
@@ -73,7 +74,7 @@ module OpenAssets
73
74
  }
74
75
  {
75
76
  'address' => btc_address,
76
- 'oa_address' => btc_address.nil? ? nil : address_to_oa_address(btc_address),
77
+ 'oa_address' => (btc_address.nil? || btc_address.is_a?(Array)) ? nil : address_to_oa_address(btc_address),
77
78
  'value' => satoshi_to_coin(v.inject(0) { |sum, o|sum + o.value}),
78
79
  'assets' => assets,
79
80
  'account' => v[0].account
@@ -218,6 +219,7 @@ module OpenAssets
218
219
  cached = output_cache.get(txid, output_index)
219
220
  return cached unless cached.nil?
220
221
  end
222
+ puts "#{txid}:[#{output_index}]"
221
223
  decode_tx = load_cached_tx(txid)
222
224
  tx = Bitcoin::Protocol::Tx.new(decode_tx.htb)
223
225
  colored_outputs = get_color_outputs_from_tx(tx)
@@ -95,6 +95,9 @@ module OpenAssets
95
95
  url = "#{@config[:schema]}://"
96
96
  url.concat "#{@config[:user]}:#{@config[:password]}@"
97
97
  url.concat "#{@config[:host]}:#{@config[:port]}"
98
+ if !@config[:wallet].nil? && !@config[:wallet].empty?
99
+ url.concat "/wallet/#{@config[:wallet]}"
100
+ end
98
101
  url
99
102
  end
100
103
 
@@ -15,12 +15,16 @@ module OpenAssets
15
15
  # @param [String] btc_address The Bitcoin address.
16
16
  # @return [String] The Open Assets Address.
17
17
  def address_to_oa_address(btc_address)
18
- btc_hex = decode_base58(btc_address)
19
- btc_hex = '0' +btc_hex if btc_hex.size==47
20
- address = btc_hex[0..-9] # bitcoin address without checksum
21
- named_addr = OA_NAMESPACE.to_s(16) + address
22
- oa_checksum = checksum(named_addr)
23
- encode_base58(named_addr + oa_checksum)
18
+ begin
19
+ btc_hex = decode_base58(btc_address)
20
+ btc_hex = '0' +btc_hex if btc_hex.size==47
21
+ address = btc_hex[0..-9] # bitcoin address without checksum
22
+ named_addr = OA_NAMESPACE.to_s(16) + address
23
+ oa_checksum = checksum(named_addr)
24
+ encode_base58(named_addr + oa_checksum)
25
+ rescue ArgumentError
26
+ nil # bech32 format fails to decode. TODO define OA address for segwit
27
+ end
24
28
  end
25
29
 
26
30
  # convert open assets address to bitcoin address
@@ -95,11 +99,7 @@ module OpenAssets
95
99
  # @param [Bitcoin::Script] script The output script.
96
100
  # @return [String] The Bitcoin address. if the script dose not contains address, return nil.
97
101
  def script_to_address(script)
98
- return script.get_pubkey_address if script.is_pubkey?
99
- return script.get_hash160_address if script.is_hash160?
100
- return script.get_multisig_addresses if script.is_multisig?
101
- return script.get_p2sh_address if script.is_p2sh?
102
- nil
102
+ script.is_multisig? ? script.get_multisig_addresses : script.get_addresses.first
103
103
  end
104
104
 
105
105
  # validate bitcoin address
@@ -1,3 +1,3 @@
1
1
  module OpenAssets
2
- VERSION = '0.6.6'
2
+ VERSION = '0.6.7'
3
3
  end
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.bindir = "exe"
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
- spec.add_runtime_dependency "bitcoin-ruby", "~> 0.0.11"
21
+ spec.add_runtime_dependency "bitcoin-ruby", "~> 0.0.18"
22
22
  spec.add_runtime_dependency "ffi", "~>1.9.8"
23
- spec.add_runtime_dependency "rest-client", "~>1.8.0"
23
+ spec.add_runtime_dependency "rest-client", "2.0"
24
24
  spec.add_runtime_dependency "httpclient"
25
25
  spec.add_runtime_dependency "sqlite3"
26
26
  spec.add_runtime_dependency "leb128", '~> 1.0.0'
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.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2018-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bitcoin-ruby
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.11
19
+ version: 0.0.18
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.11
26
+ version: 0.0.18
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ffi
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rest-client
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.8.0
47
+ version: '2.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 1.8.0
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: httpclient
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  version: '0'
240
240
  requirements: []
241
241
  rubyforge_project:
242
- rubygems_version: 2.6.13
242
+ rubygems_version: 2.6.14
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: The implementation of the Open Assets Protocol for Ruby.