glueby 0.7.0 → 0.8.0
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/lib/glueby/active_record/system_information.rb +19 -1
- data/lib/glueby/contract/errors.rb +1 -0
- data/lib/glueby/contract/token.rb +47 -21
- data/lib/glueby/contract/tx_builder.rb +41 -22
- data/lib/glueby/utxo_provider.rb +22 -9
- data/lib/glueby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2f53ca4e5784495dc9ddc7669bc021985614b3719205247c42005ec5d12a5c4
|
4
|
+
data.tar.gz: d5bb0540f3db7cf5ccdb96d4487ff627c4090f69e8719f746badae31689f864d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 037ac4f566439facb0971a34c086bb128afd4b00566b7ab0f9013d4b4c357082c88a620eb8262221a245586429387228811e940077868b254b1ec82d155de8ab
|
7
|
+
data.tar.gz: 9a031d6505750f550abe9948ff977cd01f4fbcad8ab9b733f0b322101cc77d9856c6d2e3f633e61c9e49b4657dc7f286db1abdd4df0511cedf96dba9c27a2d3d
|
@@ -3,7 +3,25 @@ module Glueby
|
|
3
3
|
class SystemInformation < ::ActiveRecord::Base
|
4
4
|
|
5
5
|
def self.synced_block_height
|
6
|
-
|
6
|
+
find_by(info_key: "synced_block_number")
|
7
|
+
end
|
8
|
+
|
9
|
+
# Return if wallet allows to use only finalized utxo.
|
10
|
+
# @return [Boolean] true if wallet allows to use only finalized utxo, otherwise false.
|
11
|
+
def self.use_only_finalized_utxo?
|
12
|
+
find_by(info_key: "use_only_finalized_utxo")&.int_value != 0
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return default value of the utxo provider
|
16
|
+
# @return [Integer] default value of utxo provider
|
17
|
+
def self.utxo_provider_default_value
|
18
|
+
find_by(info_key: "utxo_provider_default_value")&.int_value
|
19
|
+
end
|
20
|
+
|
21
|
+
# Return pool size of the utxo provider
|
22
|
+
# @return [Integer] pool size of utxo provider
|
23
|
+
def self.utxo_provider_pool_size
|
24
|
+
find_by(info_key: "utxo_provider_pool_size")&.int_value
|
7
25
|
end
|
8
26
|
|
9
27
|
def int_value
|
@@ -4,6 +4,7 @@ module Glueby
|
|
4
4
|
class InsufficientFunds < StandardError; end
|
5
5
|
class InsufficientTokens < StandardError; end
|
6
6
|
class InvalidAmount < StandardError; end
|
7
|
+
class InvalidSplit < StandardError; end
|
7
8
|
class InvalidTokenType < StandardError; end
|
8
9
|
class InvalidTimestampType < StandardError; end
|
9
10
|
class TxAlreadyBroadcasted < StandardError; end
|
@@ -56,18 +56,21 @@ module Glueby
|
|
56
56
|
# @param issuer [Glueby::Wallet]
|
57
57
|
# @param token_type [TokenTypes]
|
58
58
|
# @param amount [Integer]
|
59
|
+
# @param split [Integer] The tx outputs should be split by specified number.
|
59
60
|
# @return [Array<token, Array<tx>>] Tuple of tx array and token object
|
60
61
|
# @raise [InsufficientFunds] if wallet does not have enough TPC to send transaction.
|
61
62
|
# @raise [InvalidAmount] if amount is not positive integer.
|
63
|
+
# @raise [InvalidSplit] if split is greater than 1 for NFT token.
|
62
64
|
# @raise [UnspportedTokenType] if token is not supported.
|
63
|
-
def issue!(issuer:, token_type: Tapyrus::Color::TokenTypes::REISSUABLE, amount: 1)
|
65
|
+
def issue!(issuer:, token_type: Tapyrus::Color::TokenTypes::REISSUABLE, amount: 1, split: 1)
|
64
66
|
raise Glueby::Contract::Errors::InvalidAmount unless amount.positive?
|
67
|
+
raise Glueby::Contract::Errors::InvalidSplit if token_type == Tapyrus::Color::TokenTypes::NFT && split > 1
|
65
68
|
|
66
69
|
txs, color_id = case token_type
|
67
70
|
when Tapyrus::Color::TokenTypes::REISSUABLE
|
68
|
-
issue_reissuable_token(issuer: issuer, amount: amount)
|
71
|
+
issue_reissuable_token(issuer: issuer, amount: amount, split: split)
|
69
72
|
when Tapyrus::Color::TokenTypes::NON_REISSUABLE
|
70
|
-
issue_non_reissuable_token(issuer: issuer, amount: amount)
|
73
|
+
issue_non_reissuable_token(issuer: issuer, amount: amount, split: split)
|
71
74
|
when Tapyrus::Color::TokenTypes::NFT
|
72
75
|
issue_nft_token(issuer: issuer)
|
73
76
|
else
|
@@ -77,10 +80,14 @@ module Glueby
|
|
77
80
|
[new(color_id: color_id), txs]
|
78
81
|
end
|
79
82
|
|
83
|
+
def only_finalized?
|
84
|
+
Glueby::AR::SystemInformation.use_only_finalized_utxo?
|
85
|
+
end
|
86
|
+
|
80
87
|
private
|
81
88
|
|
82
|
-
def issue_reissuable_token(issuer:, amount:)
|
83
|
-
funding_tx = create_funding_tx(wallet: issuer)
|
89
|
+
def issue_reissuable_token(issuer:, amount:, split: 1)
|
90
|
+
funding_tx = create_funding_tx(wallet: issuer, only_finalized: only_finalized?)
|
84
91
|
script_pubkey = funding_tx.outputs.first.script_pubkey
|
85
92
|
color_id = Tapyrus::Color::ColorIdentifier.reissuable(script_pubkey)
|
86
93
|
|
@@ -89,17 +96,17 @@ module Glueby
|
|
89
96
|
Glueby::Contract::AR::ReissuableToken.create!(color_id: color_id.to_hex, script_pubkey: script_pubkey.to_hex)
|
90
97
|
|
91
98
|
funding_tx = issuer.internal_wallet.broadcast(funding_tx)
|
92
|
-
tx = create_issue_tx_for_reissuable_token(funding_tx: funding_tx, issuer: issuer, amount: amount)
|
99
|
+
tx = create_issue_tx_for_reissuable_token(funding_tx: funding_tx, issuer: issuer, amount: amount, split: split)
|
93
100
|
tx = issuer.internal_wallet.broadcast(tx)
|
94
101
|
[[funding_tx, tx], color_id]
|
95
102
|
end
|
96
103
|
end
|
97
104
|
|
98
|
-
def issue_non_reissuable_token(issuer:, amount:)
|
99
|
-
funding_tx = create_funding_tx(wallet: issuer) if Glueby.configuration.use_utxo_provider?
|
105
|
+
def issue_non_reissuable_token(issuer:, amount:, split: 1)
|
106
|
+
funding_tx = create_funding_tx(wallet: issuer, only_finalized: only_finalized?) if Glueby.configuration.use_utxo_provider?
|
100
107
|
funding_tx = issuer.internal_wallet.broadcast(funding_tx) if funding_tx
|
101
108
|
|
102
|
-
tx = create_issue_tx_for_non_reissuable_token(funding_tx: funding_tx, issuer: issuer, amount: amount)
|
109
|
+
tx = create_issue_tx_for_non_reissuable_token(funding_tx: funding_tx, issuer: issuer, amount: amount, split: split)
|
103
110
|
tx = issuer.internal_wallet.broadcast(tx)
|
104
111
|
|
105
112
|
out_point = tx.inputs.first.out_point
|
@@ -112,7 +119,7 @@ module Glueby
|
|
112
119
|
end
|
113
120
|
|
114
121
|
def issue_nft_token(issuer:)
|
115
|
-
funding_tx = create_funding_tx(wallet: issuer) if Glueby.configuration.use_utxo_provider?
|
122
|
+
funding_tx = create_funding_tx(wallet: issuer, only_finalized: only_finalized?) if Glueby.configuration.use_utxo_provider?
|
116
123
|
funding_tx = issuer.internal_wallet.broadcast(funding_tx) if funding_tx
|
117
124
|
|
118
125
|
tx = create_issue_tx_for_nft_token(funding_tx: funding_tx, issuer: issuer)
|
@@ -134,19 +141,20 @@ module Glueby
|
|
134
141
|
# A wallet can issue the token only when it is REISSUABLE token.
|
135
142
|
# @param issuer [Glueby::Wallet]
|
136
143
|
# @param amount [Integer]
|
144
|
+
# @param split [Integer]
|
137
145
|
# @return [Array<String, tx>] Tuple of color_id and tx object
|
138
146
|
# @raise [InsufficientFunds] if wallet does not have enough TPC to send transaction.
|
139
147
|
# @raise [InvalidAmount] if amount is not positive integer.
|
140
148
|
# @raise [InvalidTokenType] if token is not reissuable.
|
141
149
|
# @raise [UnknownScriptPubkey] when token is reissuable but it doesn't know script pubkey to issue token.
|
142
|
-
def reissue!(issuer:, amount:)
|
150
|
+
def reissue!(issuer:, amount:, split: 1)
|
143
151
|
raise Glueby::Contract::Errors::InvalidAmount unless amount.positive?
|
144
152
|
raise Glueby::Contract::Errors::InvalidTokenType unless token_type == Tapyrus::Color::TokenTypes::REISSUABLE
|
145
153
|
|
146
154
|
if validate_reissuer(wallet: issuer)
|
147
|
-
funding_tx = create_funding_tx(wallet: issuer, script: @script_pubkey)
|
155
|
+
funding_tx = create_funding_tx(wallet: issuer, script: @script_pubkey, only_finalized: only_finalized?)
|
148
156
|
funding_tx = issuer.internal_wallet.broadcast(funding_tx)
|
149
|
-
tx = create_reissue_tx(funding_tx: funding_tx, issuer: issuer, amount: amount, color_id: color_id)
|
157
|
+
tx = create_reissue_tx(funding_tx: funding_tx, issuer: issuer, amount: amount, color_id: color_id, split: split)
|
150
158
|
tx = issuer.internal_wallet.broadcast(tx)
|
151
159
|
|
152
160
|
[color_id, tx]
|
@@ -167,10 +175,17 @@ module Glueby
|
|
167
175
|
def transfer!(sender:, receiver_address:, amount: 1)
|
168
176
|
raise Glueby::Contract::Errors::InvalidAmount unless amount.positive?
|
169
177
|
|
170
|
-
funding_tx = create_funding_tx(wallet: sender) if Glueby.configuration.use_utxo_provider?
|
178
|
+
funding_tx = create_funding_tx(wallet: sender, only_finalized: only_finalized?) if Glueby.configuration.use_utxo_provider?
|
171
179
|
funding_tx = sender.internal_wallet.broadcast(funding_tx) if funding_tx
|
172
180
|
|
173
|
-
tx = create_transfer_tx(
|
181
|
+
tx = create_transfer_tx(
|
182
|
+
funding_tx: funding_tx,
|
183
|
+
color_id: color_id,
|
184
|
+
sender: sender,
|
185
|
+
receiver_address: receiver_address,
|
186
|
+
amount: amount,
|
187
|
+
only_finalized: only_finalized?
|
188
|
+
)
|
174
189
|
sender.internal_wallet.broadcast(tx)
|
175
190
|
[color_id, tx]
|
176
191
|
end
|
@@ -187,10 +202,16 @@ module Glueby
|
|
187
202
|
receivers.each do |r|
|
188
203
|
raise Glueby::Contract::Errors::InvalidAmount unless r[:amount].positive?
|
189
204
|
end
|
190
|
-
funding_tx = create_funding_tx(wallet: sender) if Glueby.configuration.use_utxo_provider?
|
205
|
+
funding_tx = create_funding_tx(wallet: sender, only_finalized: only_finalized?) if Glueby.configuration.use_utxo_provider?
|
191
206
|
funding_tx = sender.internal_wallet.broadcast(funding_tx) if funding_tx
|
192
207
|
|
193
|
-
tx = create_multi_transfer_tx(
|
208
|
+
tx = create_multi_transfer_tx(
|
209
|
+
funding_tx: funding_tx,
|
210
|
+
color_id: color_id,
|
211
|
+
sender: sender,
|
212
|
+
receivers: receivers,
|
213
|
+
only_finalized: only_finalized?
|
214
|
+
)
|
194
215
|
sender.internal_wallet.broadcast(tx)
|
195
216
|
[color_id, tx]
|
196
217
|
end
|
@@ -205,7 +226,7 @@ module Glueby
|
|
205
226
|
# @raise [InvalidAmount] if amount is not positive integer.
|
206
227
|
def burn!(sender:, amount: 0)
|
207
228
|
raise Glueby::Contract::Errors::InvalidAmount unless amount.positive?
|
208
|
-
balance = sender.balances[color_id.to_hex]
|
229
|
+
balance = sender.balances(only_finalized?)[color_id.to_hex]
|
209
230
|
raise Glueby::Contract::Errors::InsufficientTokens unless balance
|
210
231
|
raise Glueby::Contract::Errors::InsufficientTokens if balance < amount
|
211
232
|
|
@@ -219,13 +240,14 @@ module Glueby
|
|
219
240
|
# because change outputs is not necessary. Transactions needs one output at least.
|
220
241
|
# At that time, set true to this option to get more value to be created change output to
|
221
242
|
# the tx.
|
222
|
-
need_value_for_change_output: burn_all_amount_flag
|
243
|
+
need_value_for_change_output: burn_all_amount_flag,
|
244
|
+
only_finalized: only_finalized?
|
223
245
|
)
|
224
246
|
end
|
225
247
|
|
226
248
|
funding_tx = sender.internal_wallet.broadcast(funding_tx) if funding_tx
|
227
249
|
|
228
|
-
tx = create_burn_tx(funding_tx: funding_tx, color_id: color_id, sender: sender, amount: amount)
|
250
|
+
tx = create_burn_tx(funding_tx: funding_tx, color_id: color_id, sender: sender, amount: amount, only_finalized: only_finalized?)
|
229
251
|
sender.internal_wallet.broadcast(tx)
|
230
252
|
end
|
231
253
|
|
@@ -234,7 +256,7 @@ module Glueby
|
|
234
256
|
# @return [Integer] amount of utxo value associated with this token.
|
235
257
|
def amount(wallet:)
|
236
258
|
# collect utxo associated with this address
|
237
|
-
utxos = wallet.internal_wallet.list_unspent
|
259
|
+
utxos = wallet.internal_wallet.list_unspent(only_finalized?)
|
238
260
|
_, results = collect_colored_outputs(utxos, color_id)
|
239
261
|
results.sum { |result| result[:amount] }
|
240
262
|
end
|
@@ -282,6 +304,10 @@ module Glueby
|
|
282
304
|
|
283
305
|
private
|
284
306
|
|
307
|
+
def only_finalized?
|
308
|
+
@only_finalized ||= Token.only_finalized?
|
309
|
+
end
|
310
|
+
|
285
311
|
# Verify that wallet is the issuer of the reissuable token
|
286
312
|
# reutrn [Boolean]
|
287
313
|
def validate_reissuer(wallet:)
|
@@ -8,7 +8,7 @@ module Glueby
|
|
8
8
|
end
|
9
9
|
|
10
10
|
# Create new public key, and new transaction that sends TPC to it
|
11
|
-
def create_funding_tx(wallet:, script: nil, fee_estimator: FixedFeeEstimator.new, need_value_for_change_output: false)
|
11
|
+
def create_funding_tx(wallet:, script: nil, fee_estimator: FixedFeeEstimator.new, need_value_for_change_output: false, only_finalized: true)
|
12
12
|
if Glueby.configuration.use_utxo_provider?
|
13
13
|
utxo_provider = UtxoProvider.new
|
14
14
|
script_pubkey = script ? script : Tapyrus::Script.parse_from_addr(wallet.internal_wallet.receive_address)
|
@@ -17,8 +17,8 @@ module Glueby
|
|
17
17
|
else
|
18
18
|
txb = Tapyrus::TxBuilder.new
|
19
19
|
fee = fee_estimator.fee(dummy_tx(txb.build))
|
20
|
-
|
21
|
-
sum, outputs = wallet.internal_wallet.collect_uncolored_outputs(
|
20
|
+
amount = fee + funding_tx_amount(need_value_for_change_output: need_value_for_change_output)
|
21
|
+
sum, outputs = wallet.internal_wallet.collect_uncolored_outputs(amount, nil, only_finalized)
|
22
22
|
outputs.each do |utxo|
|
23
23
|
txb.add_utxo({
|
24
24
|
script_pubkey: Tapyrus::Script.parse_from_payload(utxo[:script_pubkey].htb),
|
@@ -37,7 +37,7 @@ module Glueby
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def create_issue_tx_for_reissuable_token(funding_tx:, issuer:, amount:, fee_estimator: FixedFeeEstimator.new)
|
40
|
+
def create_issue_tx_for_reissuable_token(funding_tx:, issuer:, amount:, split: 1, fee_estimator: FixedFeeEstimator.new)
|
41
41
|
tx = Tapyrus::Tx.new
|
42
42
|
|
43
43
|
out_point = Tapyrus::OutPoint.from_txid(funding_tx.txid, 0)
|
@@ -47,7 +47,8 @@ module Glueby
|
|
47
47
|
receiver_script = Tapyrus::Script.parse_from_payload(output.script_pubkey.to_payload)
|
48
48
|
color_id = Tapyrus::Color::ColorIdentifier.reissuable(receiver_script)
|
49
49
|
receiver_colored_script = receiver_script.add_color(color_id)
|
50
|
-
|
50
|
+
|
51
|
+
add_split_output(tx, amount, split, receiver_colored_script)
|
51
52
|
|
52
53
|
fee = fee_estimator.fee(dummy_tx(tx))
|
53
54
|
fill_change_tpc(tx, issuer, output.value - fee)
|
@@ -60,15 +61,15 @@ module Glueby
|
|
60
61
|
issuer.internal_wallet.sign_tx(tx, prev_txs)
|
61
62
|
end
|
62
63
|
|
63
|
-
def create_issue_tx_for_non_reissuable_token(funding_tx: nil, issuer:, amount:, fee_estimator: FixedFeeEstimator.new)
|
64
|
-
create_issue_tx_from_out_point(funding_tx: funding_tx, token_type: Tapyrus::Color::TokenTypes::NON_REISSUABLE, issuer: issuer, amount: amount, fee_estimator: fee_estimator)
|
64
|
+
def create_issue_tx_for_non_reissuable_token(funding_tx: nil, issuer:, amount:, split: 1, fee_estimator: FixedFeeEstimator.new, only_finalized: true)
|
65
|
+
create_issue_tx_from_out_point(funding_tx: funding_tx, token_type: Tapyrus::Color::TokenTypes::NON_REISSUABLE, issuer: issuer, amount: amount, split: split, fee_estimator: fee_estimator, only_finalized: only_finalized)
|
65
66
|
end
|
66
67
|
|
67
|
-
def create_issue_tx_for_nft_token(funding_tx: nil, issuer:, fee_estimator: FixedFeeEstimator.new)
|
68
|
-
create_issue_tx_from_out_point(funding_tx: funding_tx, token_type: Tapyrus::Color::TokenTypes::NFT, issuer: issuer, amount: 1, fee_estimator: fee_estimator)
|
68
|
+
def create_issue_tx_for_nft_token(funding_tx: nil, issuer:, fee_estimator: FixedFeeEstimator.new, only_finalized: true)
|
69
|
+
create_issue_tx_from_out_point(funding_tx: funding_tx, token_type: Tapyrus::Color::TokenTypes::NFT, issuer: issuer, amount: 1, fee_estimator: fee_estimator, only_finalized: only_finalized)
|
69
70
|
end
|
70
71
|
|
71
|
-
def create_issue_tx_from_out_point(funding_tx: nil, token_type:, issuer:, amount:, fee_estimator: FixedFeeEstimator.new)
|
72
|
+
def create_issue_tx_from_out_point(funding_tx: nil, token_type:, issuer:, amount:, split: 1, fee_estimator: FixedFeeEstimator.new, only_finalized: true)
|
72
73
|
tx = Tapyrus::Tx.new
|
73
74
|
|
74
75
|
fee = fee_estimator.fee(dummy_issue_tx_from_out_point)
|
@@ -77,7 +78,7 @@ module Glueby
|
|
77
78
|
tx.inputs << Tapyrus::TxIn.new(out_point: out_point)
|
78
79
|
funding_tx.outputs.first.value
|
79
80
|
else
|
80
|
-
sum, outputs = issuer.internal_wallet.collect_uncolored_outputs(fee)
|
81
|
+
sum, outputs = issuer.internal_wallet.collect_uncolored_outputs(fee, nil, only_finalized)
|
81
82
|
fill_input(tx, outputs)
|
82
83
|
sum
|
83
84
|
end
|
@@ -93,7 +94,7 @@ module Glueby
|
|
93
94
|
|
94
95
|
receiver_script = Tapyrus::Script.parse_from_addr(issuer.internal_wallet.receive_address)
|
95
96
|
receiver_colored_script = receiver_script.add_color(color_id)
|
96
|
-
tx
|
97
|
+
add_split_output(tx, amount, split, receiver_colored_script)
|
97
98
|
|
98
99
|
fill_change_tpc(tx, issuer, sum - fee)
|
99
100
|
prev_txs = if funding_tx
|
@@ -110,7 +111,7 @@ module Glueby
|
|
110
111
|
issuer.internal_wallet.sign_tx(tx, prev_txs)
|
111
112
|
end
|
112
113
|
|
113
|
-
def create_reissue_tx(funding_tx:, issuer:, amount:, color_id:, fee_estimator: FixedFeeEstimator.new)
|
114
|
+
def create_reissue_tx(funding_tx:, issuer:, amount:, color_id:, split: 1, fee_estimator: FixedFeeEstimator.new)
|
114
115
|
tx = Tapyrus::Tx.new
|
115
116
|
|
116
117
|
out_point = Tapyrus::OutPoint.from_txid(funding_tx.txid, 0)
|
@@ -119,7 +120,7 @@ module Glueby
|
|
119
120
|
|
120
121
|
receiver_script = Tapyrus::Script.parse_from_payload(output.script_pubkey.to_payload)
|
121
122
|
receiver_colored_script = receiver_script.add_color(color_id)
|
122
|
-
tx
|
123
|
+
add_split_output(tx, amount, split, receiver_colored_script)
|
123
124
|
|
124
125
|
fee = fee_estimator.fee(dummy_tx(tx))
|
125
126
|
fill_change_tpc(tx, issuer, output.value - fee)
|
@@ -132,16 +133,23 @@ module Glueby
|
|
132
133
|
issuer.internal_wallet.sign_tx(tx, prev_txs)
|
133
134
|
end
|
134
135
|
|
135
|
-
def create_transfer_tx(funding_tx:nil, color_id:, sender:, receiver_address:, amount:, fee_estimator: FixedFeeEstimator.new)
|
136
|
+
def create_transfer_tx(funding_tx:nil, color_id:, sender:, receiver_address:, amount:, fee_estimator: FixedFeeEstimator.new, only_finalized: true)
|
136
137
|
receivers = [{ address: receiver_address, amount: amount }]
|
137
|
-
create_multi_transfer_tx(
|
138
|
+
create_multi_transfer_tx(
|
139
|
+
funding_tx: funding_tx,
|
140
|
+
color_id: color_id,
|
141
|
+
sender: sender,
|
142
|
+
receivers: receivers,
|
143
|
+
fee_estimator: fee_estimator,
|
144
|
+
only_finalized: only_finalized
|
145
|
+
)
|
138
146
|
end
|
139
147
|
|
140
|
-
def create_multi_transfer_tx(funding_tx:nil, color_id:, sender:, receivers:, fee_estimator: FixedFeeEstimator.new)
|
148
|
+
def create_multi_transfer_tx(funding_tx:nil, color_id:, sender:, receivers:, fee_estimator: FixedFeeEstimator.new, only_finalized: true)
|
141
149
|
tx = Tapyrus::Tx.new
|
142
150
|
|
143
151
|
amount = receivers.reduce(0) { |sum, r| sum + r[:amount].to_i }
|
144
|
-
utxos = sender.internal_wallet.list_unspent
|
152
|
+
utxos = sender.internal_wallet.list_unspent(only_finalized)
|
145
153
|
sum_token, outputs = collect_colored_outputs(utxos, color_id, amount)
|
146
154
|
fill_input(tx, outputs)
|
147
155
|
|
@@ -159,7 +167,7 @@ module Glueby
|
|
159
167
|
tx.inputs << Tapyrus::TxIn.new(out_point: out_point)
|
160
168
|
funding_tx.outputs.first.value
|
161
169
|
else
|
162
|
-
sum_tpc, outputs = sender.internal_wallet.collect_uncolored_outputs(fee)
|
170
|
+
sum_tpc, outputs = sender.internal_wallet.collect_uncolored_outputs(fee, nil, only_finalized)
|
163
171
|
fill_input(tx, outputs)
|
164
172
|
sum_tpc
|
165
173
|
end
|
@@ -179,10 +187,10 @@ module Glueby
|
|
179
187
|
sender.internal_wallet.sign_tx(tx, prev_txs)
|
180
188
|
end
|
181
189
|
|
182
|
-
def create_burn_tx(funding_tx:nil, color_id:, sender:, amount: 0, fee_estimator: FixedFeeEstimator.new)
|
190
|
+
def create_burn_tx(funding_tx:nil, color_id:, sender:, amount: 0, fee_estimator: FixedFeeEstimator.new, only_finalized: true)
|
183
191
|
tx = Tapyrus::Tx.new
|
184
192
|
|
185
|
-
utxos = sender.internal_wallet.list_unspent
|
193
|
+
utxos = sender.internal_wallet.list_unspent(only_finalized)
|
186
194
|
sum_token, outputs = collect_colored_outputs(utxos, color_id, amount)
|
187
195
|
fill_input(tx, outputs)
|
188
196
|
|
@@ -195,7 +203,7 @@ module Glueby
|
|
195
203
|
tx.inputs << Tapyrus::TxIn.new(out_point: out_point)
|
196
204
|
funding_tx.outputs.first.value
|
197
205
|
else
|
198
|
-
sum_tpc, outputs = sender.internal_wallet.collect_uncolored_outputs(fee + DUST_LIMIT)
|
206
|
+
sum_tpc, outputs = sender.internal_wallet.collect_uncolored_outputs(fee + DUST_LIMIT, nil, only_finalized)
|
199
207
|
fill_input(tx, outputs)
|
200
208
|
sum_tpc
|
201
209
|
end
|
@@ -215,6 +223,17 @@ module Glueby
|
|
215
223
|
sender.internal_wallet.sign_tx(tx, prev_txs)
|
216
224
|
end
|
217
225
|
|
226
|
+
def add_split_output(tx, amount, split, script_pubkey)
|
227
|
+
if amount < split
|
228
|
+
split = amount
|
229
|
+
value = 1
|
230
|
+
else
|
231
|
+
value = (amount/split).to_i
|
232
|
+
end
|
233
|
+
(split - 1).times { tx.outputs << Tapyrus::TxOut.new(value: value, script_pubkey: script_pubkey) }
|
234
|
+
tx.outputs << Tapyrus::TxOut.new(value: amount - value * (split - 1), script_pubkey: script_pubkey)
|
235
|
+
end
|
236
|
+
|
218
237
|
def fill_input(tx, outputs)
|
219
238
|
outputs.each do |output|
|
220
239
|
out_point = Tapyrus::OutPoint.new(output[:txid].rhex, output[:vout])
|
data/lib/glueby/utxo_provider.rb
CHANGED
@@ -25,11 +25,9 @@ module Glueby
|
|
25
25
|
@wallet = load_wallet
|
26
26
|
validate_config!
|
27
27
|
@fee_estimator = (UtxoProvider.config && UtxoProvider.config[:fee_estimator]) || Glueby::Contract::FixedFeeEstimator.new
|
28
|
-
@default_value = (UtxoProvider.config && UtxoProvider.config[:default_value]) || DEFAULT_VALUE
|
29
|
-
@utxo_pool_size = (UtxoProvider.config && UtxoProvider.config[:utxo_pool_size]) || DEFAULT_UTXO_POOL_SIZE
|
30
28
|
end
|
31
29
|
|
32
|
-
attr_reader :wallet, :fee_estimator
|
30
|
+
attr_reader :wallet, :fee_estimator
|
33
31
|
|
34
32
|
# Provide a UTXO
|
35
33
|
# @param [Tapyrus::Script] script_pubkey The script to be provided
|
@@ -62,6 +60,24 @@ module Glueby
|
|
62
60
|
[signed_tx, 0]
|
63
61
|
end
|
64
62
|
|
63
|
+
def default_value
|
64
|
+
@default_value ||=
|
65
|
+
(
|
66
|
+
Glueby::AR::SystemInformation.utxo_provider_default_value ||
|
67
|
+
(UtxoProvider.config && UtxoProvider.config[:default_value]) ||
|
68
|
+
DEFAULT_VALUE
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def utxo_pool_size
|
73
|
+
@utxo_pool_size ||=
|
74
|
+
(
|
75
|
+
Glueby::AR::SystemInformation.utxo_provider_pool_size ||
|
76
|
+
(UtxoProvider.config && UtxoProvider.config[:utxo_pool_size]) ||
|
77
|
+
DEFAULT_UTXO_POOL_SIZE
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
65
81
|
private
|
66
82
|
|
67
83
|
# Create wallet for provider
|
@@ -74,7 +90,7 @@ module Glueby
|
|
74
90
|
end
|
75
91
|
|
76
92
|
def collect_uncolored_outputs(wallet, amount)
|
77
|
-
utxos = wallet.list_unspent.select { |o| !o[:color_id] && o[:amount] ==
|
93
|
+
utxos = wallet.list_unspent.select { |o| !o[:color_id] && o[:amount] == default_value }
|
78
94
|
utxos.shuffle!
|
79
95
|
|
80
96
|
utxos.inject([0, []]) do |sum, output|
|
@@ -88,11 +104,8 @@ module Glueby
|
|
88
104
|
end
|
89
105
|
|
90
106
|
def validate_config!
|
91
|
-
if
|
92
|
-
utxo_pool_size
|
93
|
-
if utxo_pool_size && (!utxo_pool_size.is_a?(Integer) || utxo_pool_size > MAX_UTXO_POOL_SIZE)
|
94
|
-
raise Glueby::Configuration::Errors::InvalidConfiguration, "utxo_pool_size(#{utxo_pool_size}) should not be greater than #{MAX_UTXO_POOL_SIZE}"
|
95
|
-
end
|
107
|
+
if !utxo_pool_size.is_a?(Integer) || utxo_pool_size > MAX_UTXO_POOL_SIZE
|
108
|
+
raise Glueby::Configuration::Errors::InvalidConfiguration, "utxo_pool_size(#{utxo_pool_size}) should not be greater than #{MAX_UTXO_POOL_SIZE}"
|
96
109
|
end
|
97
110
|
end
|
98
111
|
end
|
data/lib/glueby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glueby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tapyrus
|