openassets-ruby 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -2
- data/lib/openassets.rb +1 -0
- data/lib/openassets/api.rb +21 -2
- data/lib/openassets/send_asset_param.rb +15 -0
- data/lib/openassets/transaction/transaction_builder.rb +7 -1
- data/lib/openassets/util.rb +11 -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: d5a79cc924492696e02f90d9b2921b0753d9e619
|
4
|
+
data.tar.gz: 875977bc89c76903f923b20f1ca15da38e881345
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f27081be1ef5c68114410337396fb78e65ca3f7535ab40758111971fc66b72760ce7bcdb7ff899d467bfbd90dc60a0b21d5484e6d74eeb573e80579493e4822
|
7
|
+
data.tar.gz: dfc1b43a7acb7f8a8191c2c938f88cb3446fc8e5575381ead4574fda5c69caaf7d1ec00be5237dadb40a02e5e35bb9dd2a72dd31441ea4e64ee9ea7c42a99fab
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ require 'openassets'
|
|
17
17
|
|
18
18
|
api = OpenAssets::Api.new({:network => 'mainnet',
|
19
19
|
:provider => 'bitcoind',
|
20
|
-
:dust_limit => 600,
|
20
|
+
:dust_limit => 600, :default_fees => 10000,
|
21
21
|
:rpc => {:user => 'xxx', :password => 'xxx', :schema => 'http', :port => 8332, :host => 'localhost'}})
|
22
22
|
```
|
23
23
|
|
@@ -28,10 +28,20 @@ require 'openassets'
|
|
28
28
|
|
29
29
|
api = OpenAssets::Api.new({:network => 'testnet',
|
30
30
|
:provider => 'bitcoind',
|
31
|
-
:dust_limit => 600,
|
31
|
+
:dust_limit => 600, :default_fees => 10000,
|
32
32
|
:rpc => {:user => 'xxx', :password => 'xxx', :schema => 'http', :port => 18332, :host => 'localhost'}})
|
33
33
|
```
|
34
34
|
|
35
|
+
The configuration options are as follows:
|
36
|
+
|
37
|
+
|option|describe|default|
|
38
|
+
|---|---|---|
|
39
|
+
|**network**|The using network. "mainnet" or "testnet" |mainnet|
|
40
|
+
|**provider**|The RPC server. Specify possible now only "bitcoind".|bitcoind|
|
41
|
+
|**dust_limit**|The amount of Bitcoin, which is set to the each output of the Open Assets Protocol(issue or transfer).|600 (satoshi)|
|
42
|
+
|**default_fees**|The transaction fee. (used by issue_asset and send_asset, send_bitcoin )|10000 (satoshi)|
|
43
|
+
|**rpc**|The access information to the RPC server of Bitcoin Core.|N/A|
|
44
|
+
|
35
45
|
## API
|
36
46
|
|
37
47
|
Currently openassets-ruby support the following API.
|
@@ -183,6 +193,21 @@ Get tx outputs. (use for debug)
|
|
183
193
|
},..
|
184
194
|
```
|
185
195
|
|
196
|
+
* **send_assets**
|
197
|
+
Creates a transaction for sending **multiple** asset from the open asset address to another.
|
198
|
+
```ruby
|
199
|
+
# send assets
|
200
|
+
# api.send_assets(<from open asset address>, <The array of send Asset information(see OpenAssets::SendAssetParam).>, <fees (The fess in satoshis for the transaction. use 10000 satoshi if specified nil)>, <mode=('broadcast', 'signed', 'unsigned')>, <output_qty default value is 1.>)
|
201
|
+
|
202
|
+
# example
|
203
|
+
from = address_to_oa_address('mrxpeizRrF8ymNx5FrvcGGZVecZjtUFVP3')
|
204
|
+
to = address_to_oa_address('n4MEsSUN8GktDFZzU3V55mP3jWGMN7e4wE')
|
205
|
+
params = []
|
206
|
+
params << OpenAssets::SendAssetParam.new('oGu4VXx2TU97d9LmPP8PMCkHckkcPqC5RY', 50, to)
|
207
|
+
params << OpenAssets::SendAssetParam.new('oUygwarZqNGrjDvcZUpZdvEc7es6dcs1vs', 4, to)
|
208
|
+
tx = api.send_assets(from, params)
|
209
|
+
```
|
210
|
+
|
186
211
|
## License
|
187
212
|
|
188
213
|
The MIT License (MIT)
|
data/lib/openassets.rb
CHANGED
data/lib/openassets/api.rb
CHANGED
@@ -7,7 +7,7 @@ module OpenAssets
|
|
7
7
|
include Util
|
8
8
|
include MethodFilter
|
9
9
|
|
10
|
-
before_filter :change_network, {:include => [:list_unspent, :get_balance, :issue_asset, :send_asset, :send_bitcoin]}
|
10
|
+
before_filter :change_network, {:include => [:list_unspent, :get_balance, :issue_asset, :send_asset, :send_assets, :send_bitcoin]}
|
11
11
|
|
12
12
|
attr_reader :config
|
13
13
|
attr_reader :provider
|
@@ -114,7 +114,26 @@ module OpenAssets
|
|
114
114
|
builder = OpenAssets::Transaction::TransactionBuilder.new(@config[:dust_limit])
|
115
115
|
colored_outputs = get_unspent_outputs([oa_address_to_address(from)])
|
116
116
|
asset_transfer_spec = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount, output_qty)
|
117
|
-
tx = builder.
|
117
|
+
tx = builder.transfer_asset(asset_id, asset_transfer_spec, from, fees.nil? ? @config[:default_fees]: fees)
|
118
|
+
tx = process_transaction(tx, mode)
|
119
|
+
tx
|
120
|
+
end
|
121
|
+
|
122
|
+
# Creates a transaction for sending multiple asset from an address to another.
|
123
|
+
# @param[String] from The open asset address to send the asset from.
|
124
|
+
# @param[Array[OpenAssets::SendAssetParams]] send_asset_params The send Asset information(asset_id, amount, to).
|
125
|
+
# @param[Integer] fees The fess in satoshis for the transaction.
|
126
|
+
# @param[String] mode 'broadcast' (default) for signing and broadcasting the transaction,
|
127
|
+
# 'signed' for signing the transaction without broadcasting,
|
128
|
+
# 'unsigned' for getting the raw unsigned transaction without broadcasting"""='broadcast'
|
129
|
+
# @return[Bitcoin::Protocol:Tx] The resulting transaction.
|
130
|
+
def send_assets(from, send_asset_params, fees = nil, mode = 'broadcast')
|
131
|
+
builder = OpenAssets::Transaction::TransactionBuilder.new(@config[:dust_limit])
|
132
|
+
colored_outputs = get_unspent_outputs([oa_address_to_address(from)])
|
133
|
+
transfer_specs = send_asset_params.map{|param|
|
134
|
+
[param.asset_id, OpenAssets::Transaction::TransferParameters.new(colored_outputs, param.to, from, param.amount)]
|
135
|
+
}
|
136
|
+
tx = builder.transfer_assets(transfer_specs, from, fees.nil? ? @config[:default_fees]: fees)
|
118
137
|
tx = process_transaction(tx, mode)
|
119
138
|
tx
|
120
139
|
end
|
@@ -45,12 +45,18 @@ module OpenAssets
|
|
45
45
|
# @param[String] btc_change_script The script where to send bitcoin change, if any.
|
46
46
|
# @param[Integer] fees The fees to include in the transaction.
|
47
47
|
# @return[Bitcoin::Protocol:Tx] The resulting unsigned transaction.
|
48
|
-
def
|
48
|
+
def transfer_asset(asset_id, asset_transfer_spec, btc_change_script, fees)
|
49
49
|
btc_transfer_spec = OpenAssets::Transaction::TransferParameters.new(
|
50
50
|
asset_transfer_spec.unspent_outputs, nil, oa_address_to_address(btc_change_script), 0)
|
51
51
|
transfer([[asset_id, asset_transfer_spec]], btc_transfer_spec, fees)
|
52
52
|
end
|
53
53
|
|
54
|
+
def transfer_assets(transfer_specs, btc_change_script, fees)
|
55
|
+
btc_transfer_spec = OpenAssets::Transaction::TransferParameters.new(
|
56
|
+
transfer_specs[0][1].unspent_outputs, nil, oa_address_to_address(btc_change_script), 0)
|
57
|
+
transfer(transfer_specs, btc_transfer_spec, fees)
|
58
|
+
end
|
59
|
+
|
54
60
|
# Creates a transaction for sending bitcoins.
|
55
61
|
# @param[OpenAssets::Transaction::TransferParameters] btc_transfer_spec The parameters of the bitcoins being transferred.
|
56
62
|
# @param[Integer] fees The fees to include in the transaction.
|
data/lib/openassets/util.rb
CHANGED
@@ -91,6 +91,17 @@ module OpenAssets
|
|
91
91
|
}
|
92
92
|
end
|
93
93
|
|
94
|
+
# generate Asset ID from open asset address.
|
95
|
+
def oa_address_to_asset_id(oa_address)
|
96
|
+
address_to_asset_id(oa_address_to_address(oa_address))
|
97
|
+
end
|
98
|
+
|
99
|
+
# generate Asset ID from bitcoin address.
|
100
|
+
def address_to_asset_id(btc_address)
|
101
|
+
pubkey_hash = hash160_from_address(btc_address)
|
102
|
+
pubkey_hash_to_asset_id(pubkey_hash)
|
103
|
+
end
|
104
|
+
|
94
105
|
private
|
95
106
|
def oa_version_byte
|
96
107
|
Bitcoin.network[:address_version] == "6f" ? OA_VERSION_BYTE_TESTNET : OA_VERSION_BYTE
|
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.2.
|
4
|
+
version: 0.2.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-01-
|
11
|
+
date: 2016-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bitcoin-ruby
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/openassets/provider/api_error.rb
|
127
127
|
- lib/openassets/provider/bitcoin_core_provider.rb
|
128
128
|
- lib/openassets/provider/block_chain_provider_base.rb
|
129
|
+
- lib/openassets/send_asset_param.rb
|
129
130
|
- lib/openassets/transaction.rb
|
130
131
|
- lib/openassets/transaction/dust_output_error.rb
|
131
132
|
- lib/openassets/transaction/insufficient_asset_quantity_error.rb
|