glueby 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -2
- data/lib/glueby/configuration.rb +9 -3
- data/lib/glueby/contract/active_record/timestamp.rb +4 -4
- data/lib/glueby/contract/fee_estimator/auto.rb +34 -0
- data/lib/glueby/contract/fee_estimator/fixed.rb +30 -0
- data/lib/glueby/contract/fee_estimator.rb +25 -21
- data/lib/glueby/contract/payment.rb +2 -2
- data/lib/glueby/contract/timestamp/tx_builder/simple.rb +1 -1
- data/lib/glueby/contract/timestamp.rb +1 -1
- data/lib/glueby/contract/tx_builder.rb +18 -37
- data/lib/glueby/utxo_provider/tasks.rb +3 -2
- data/lib/glueby/utxo_provider.rb +6 -3
- data/lib/glueby/version.rb +1 -1
- data/lib/tasks/glueby/contract/timestamp.rake +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 959a9d1dfbdea6b4b18e969b07399a9228fce31e80c7defcb9c393b71df1607b
|
4
|
+
data.tar.gz: efe95c4c0ef08692d30fb1ff9dfeeea13d777f809d71f19d329b9b50d4406a31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66f61489f313fcaf4c3fe22486cd2e13307a9b9ab78e9a47a1f61e60928d65455b0691c52f3e3461930f052d41e53c7c5a5f57ff7eab12ed52b95025c89e52ba
|
7
|
+
data.tar.gz: 744f83c4d6211e7643f21f53d823490cc9e0235bd318f603c1b1a08e8cfda70d1e23a328287457b3591dc57ed9079e8b47ac150f546b5c56576c3228bf98d58a
|
data/README.md
CHANGED
@@ -445,9 +445,9 @@ Configuration:
|
|
445
445
|
|
446
446
|
## Other configurations
|
447
447
|
|
448
|
-
### Default fixed fee for the
|
448
|
+
### Default fixed fee for the FeeEstimator::Fixed
|
449
449
|
|
450
|
-
The architecture of Glueby accepts any fee estimation strategies for paying transactions fee. However, we officially support only one strategy: the fixed fee strategy.
|
450
|
+
The architecture of Glueby accepts any fee estimation strategies for paying transactions fee. However, we officially support only one strategy: the fixed fee strategy to contract transactions.
|
451
451
|
It just returns a fixed fee value without any estimation.
|
452
452
|
Here provides a configuration to modify the default fixed fee value it returns like this:
|
453
453
|
|
@@ -457,6 +457,19 @@ Glueby.configure do |config|
|
|
457
457
|
end
|
458
458
|
```
|
459
459
|
|
460
|
+
### Default fee rate for the FeeEstimator::Auto
|
461
|
+
|
462
|
+
Glueby provide automate fee estimator `Glueby::Contract::FeeEstimator::Auto` that calculate minimum fee possible to broadcast from fee rate and tx size.
|
463
|
+
This method can be used in UTXO provider's management task so far. In other place where creates txs is not tested with this yet.
|
464
|
+
|
465
|
+
Here provides a configuration to modify the default fee rate it returns like this:
|
466
|
+
|
467
|
+
```ruby
|
468
|
+
Glueby.configure do |config|
|
469
|
+
config.default_fee_rate = 1_000
|
470
|
+
end
|
471
|
+
```
|
472
|
+
|
460
473
|
## Error handling
|
461
474
|
|
462
475
|
Glueby has base error classes like `Glueby::Error` and `Glueby::ArgumentError`.
|
data/lib/glueby/configuration.rb
CHANGED
@@ -83,10 +83,16 @@ module Glueby
|
|
83
83
|
UtxoProvider.configure(config)
|
84
84
|
end
|
85
85
|
|
86
|
-
# Set default fixed fee to the
|
87
|
-
# @param [Integer] fee The default fee value in tapyrus to the
|
86
|
+
# Set default fixed fee to the FeeEstimator::Fixed
|
87
|
+
# @param [Integer] fee The default fee value in tapyrus to the FeeEstimator::Fixed
|
88
88
|
def default_fixed_fee=(fee)
|
89
|
-
Contract::
|
89
|
+
Contract::FeeEstimator::Fixed.default_fixed_fee = fee
|
90
|
+
end
|
91
|
+
|
92
|
+
# Set default fee rate to the FeeEstimator::Auto
|
93
|
+
# @param [Integer] fee_rate The default fee rate in tapyrus/kB to the FeeEstimator::Auto
|
94
|
+
def default_fee_rate=(fee_rate)
|
95
|
+
Contract::FeeEstimator::Auto.default_fee_rate = fee_rate
|
90
96
|
end
|
91
97
|
end
|
92
98
|
end
|
@@ -71,10 +71,10 @@ module Glueby
|
|
71
71
|
end
|
72
72
|
|
73
73
|
# Broadcast and save timestamp
|
74
|
-
# @param [Glueby::Contract::
|
74
|
+
# @param [Glueby::Contract::FeeEstimator] fee_estimator
|
75
75
|
# @param [Glueby::UtxoProvider] utxo_provider
|
76
76
|
# @return true if tapyrus transactions were broadcasted and the timestamp was updated successfully, otherwise false.
|
77
|
-
def save_with_broadcast(fee_estimator: Glueby::Contract::
|
77
|
+
def save_with_broadcast(fee_estimator: Glueby::Contract::FeeEstimator::Fixed.new, utxo_provider: nil)
|
78
78
|
save_with_broadcast!(fee_estimator: fee_estimator, utxo_provider: utxo_provider)
|
79
79
|
rescue Errors::FailedToBroadcast => e
|
80
80
|
logger.error("failed to broadcast (id=#{id}, reason=#{e.message})")
|
@@ -85,14 +85,14 @@ module Glueby
|
|
85
85
|
end
|
86
86
|
|
87
87
|
# Broadcast and save timestamp, and it raises errors
|
88
|
-
# @param [Glueby::Contract::
|
88
|
+
# @param [Glueby::Contract::FeeEstimator] fee_estimator
|
89
89
|
# @param [Glueby::UtxoProvider] utxo_provider
|
90
90
|
# @return true if tapyrus transactions were broadcasted and the timestamp was updated successfully
|
91
91
|
# @raise [Glueby::Contract::Errors::FailedToBroadcast] If the broadcasting is failure
|
92
92
|
# @raise [Glueby::Contract::Errors::PrevTimestampNotFound] If it is not available that the timestamp record which correspond with the prev_id attribute
|
93
93
|
# @raise [Glueby::Contract::Errors::PrevTimestampIsNotTrackable] If the timestamp record by prev_id is not trackable
|
94
94
|
# @raise [Glueby::Contract::Errors::PrevTimestampAlreadyUpdated] If the previous timestamp was already updated
|
95
|
-
def save_with_broadcast!(fee_estimator: Glueby::Contract::
|
95
|
+
def save_with_broadcast!(fee_estimator: Glueby::Contract::FeeEstimator::Fixed.new, utxo_provider: nil)
|
96
96
|
validate_prev!
|
97
97
|
utxo_provider = Glueby::UtxoProvider.new if !utxo_provider && Glueby.configuration.use_utxo_provider?
|
98
98
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Glueby
|
2
|
+
module Contract
|
3
|
+
module FeeEstimator
|
4
|
+
# It calculates actual minimum fee to broadcast txs.
|
5
|
+
class Auto
|
6
|
+
include FeeEstimator
|
7
|
+
|
8
|
+
# This is same with Tapyrus Core's default min_relay_fee value.(tapyrus/kB)
|
9
|
+
DEFAULT_FEE_RATE = 1_000
|
10
|
+
|
11
|
+
# @!attribute [r] fee_rate
|
12
|
+
# @return [Integer] the fee rate(tapyrus/kB) that is used actual fee calculation
|
13
|
+
attr_reader :fee_rate
|
14
|
+
|
15
|
+
class << self
|
16
|
+
# @!attribute [rw] default_fee_rate
|
17
|
+
# @return [Integer] The global fee rate configuration. All instances use this value as the default.
|
18
|
+
attr_accessor :default_fee_rate
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param [Integer] fee_rate
|
22
|
+
def initialize(fee_rate: Auto.default_fee_rate || DEFAULT_FEE_RATE)
|
23
|
+
@fee_rate = fee_rate
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def estimate_fee(tx)
|
29
|
+
((tx.to_payload.bytesize / 1000.0) * fee_rate).ceil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Glueby
|
2
|
+
module Contract
|
3
|
+
module FeeEstimator
|
4
|
+
class Fixed
|
5
|
+
include FeeEstimator
|
6
|
+
|
7
|
+
# Default fee in tapyrus that is used if it is not configured
|
8
|
+
DEFAULT_FEE = 10_000
|
9
|
+
|
10
|
+
attr_reader :fixed_fee
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :default_fixed_fee
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(fixed_fee: Fixed.default_fixed_fee || DEFAULT_FEE)
|
17
|
+
@fixed_fee = fixed_fee
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# @private
|
23
|
+
# @return fee by tapyrus(not TPC).
|
24
|
+
def estimate_fee(_tx)
|
25
|
+
@fixed_fee
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module Glueby
|
2
2
|
module Contract
|
3
3
|
module FeeEstimator
|
4
|
+
autoload :Fixed, 'glueby/contract/fee_estimator/fixed'
|
5
|
+
autoload :Auto, 'glueby/contract/fee_estimator/auto'
|
6
|
+
|
4
7
|
# @param [Tapyrus::Tx] tx - The target tx
|
5
8
|
# @return fee by tapyrus(not TPC).
|
6
9
|
def fee(tx)
|
@@ -8,37 +11,38 @@ module Glueby
|
|
8
11
|
estimate_fee(tx)
|
9
12
|
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# @abstract Override in subclasses. This is would be implemented an actual estimation logic.
|
15
|
-
# @param [Tapyrus::Tx] tx - The target tx
|
16
|
-
# @return fee by tapyrus(not TPC).
|
17
|
-
def estimate_fee(tx)
|
18
|
-
raise NotImplementedError
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class FixedFeeEstimator
|
23
|
-
include FeeEstimator
|
14
|
+
# Add dummy inputs and outputs to tx
|
15
|
+
def dummy_tx(tx)
|
16
|
+
dummy = Tapyrus::Tx.parse_from_payload(tx.to_payload)
|
24
17
|
|
25
|
-
|
18
|
+
# dummy input for tpc
|
19
|
+
out_point = Tapyrus::OutPoint.new('00' * 32, 0)
|
20
|
+
dummy.inputs << Tapyrus::TxIn.new(out_point: out_point)
|
26
21
|
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
# Add script_sig to all intpus
|
23
|
+
dummy.inputs.each do |input|
|
24
|
+
input.script_sig = Tapyrus::Script.parse_from_payload('000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'.htb)
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
27
|
+
# dummy output to return change
|
28
|
+
change_script = Tapyrus::Script.to_p2pkh('0000000000000000000000000000000000000000')
|
29
|
+
dummy.outputs << Tapyrus::TxOut.new(value: 0, script_pubkey: change_script)
|
30
|
+
dummy
|
33
31
|
end
|
32
|
+
module_function :dummy_tx
|
34
33
|
|
35
34
|
private
|
36
35
|
|
37
36
|
# @private
|
37
|
+
# @abstract Override in subclasses. This is would be implemented an actual estimation logic.
|
38
|
+
# @param [Tapyrus::Tx] tx - The target tx
|
38
39
|
# @return fee by tapyrus(not TPC).
|
39
|
-
def estimate_fee(
|
40
|
-
|
40
|
+
def estimate_fee(tx)
|
41
|
+
raise NotImplementedError
|
41
42
|
end
|
42
43
|
end
|
44
|
+
|
45
|
+
# Create alias name of FeeEstimator::Fixed class for backward compatibility
|
46
|
+
FixedFeeEstimator = FeeEstimator::Fixed
|
43
47
|
end
|
44
48
|
end
|
@@ -32,11 +32,11 @@ module Glueby
|
|
32
32
|
extend Glueby::Contract::TxBuilder
|
33
33
|
|
34
34
|
class << self
|
35
|
-
def transfer(sender:, receiver_address:, amount:, fee_estimator:
|
35
|
+
def transfer(sender:, receiver_address:, amount:, fee_estimator: FeeEstimator::Fixed.new)
|
36
36
|
raise Glueby::Contract::Errors::InvalidAmount unless amount.positive?
|
37
37
|
|
38
38
|
tx = Tapyrus::Tx.new
|
39
|
-
dummy_fee = fee_estimator.fee(dummy_tx(tx))
|
39
|
+
dummy_fee = fee_estimator.fee(FeeEstimator.dummy_tx(tx))
|
40
40
|
|
41
41
|
sum, outputs = sender.internal_wallet.collect_uncolored_outputs(dummy_fee + amount)
|
42
42
|
fill_input(tx, outputs)
|
@@ -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:
|
11
|
+
def create_funding_tx(wallet:, script: nil, fee_estimator: FeeEstimator::Fixed.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)
|
@@ -16,7 +16,7 @@ module Glueby
|
|
16
16
|
utxo_provider.wallet.sign_tx(funding_tx)
|
17
17
|
else
|
18
18
|
txb = Tapyrus::TxBuilder.new
|
19
|
-
fee = fee_estimator.fee(dummy_tx(txb.build))
|
19
|
+
fee = fee_estimator.fee(FeeEstimator.dummy_tx(txb.build))
|
20
20
|
amount = fee + funding_tx_amount(need_value_for_change_output: need_value_for_change_output)
|
21
21
|
sum, outputs = wallet.internal_wallet.collect_uncolored_outputs(amount, nil, only_finalized)
|
22
22
|
outputs.each do |utxo|
|
@@ -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:, split: 1, fee_estimator:
|
40
|
+
def create_issue_tx_for_reissuable_token(funding_tx:, issuer:, amount:, split: 1, fee_estimator: FeeEstimator::Fixed.new)
|
41
41
|
tx = Tapyrus::Tx.new
|
42
42
|
|
43
43
|
out_point = Tapyrus::OutPoint.from_txid(funding_tx.txid, 0)
|
@@ -50,7 +50,7 @@ module Glueby
|
|
50
50
|
|
51
51
|
add_split_output(tx, amount, split, receiver_colored_script)
|
52
52
|
|
53
|
-
fee = fee_estimator.fee(dummy_tx(tx))
|
53
|
+
fee = fee_estimator.fee(FeeEstimator.dummy_tx(tx))
|
54
54
|
fill_change_tpc(tx, issuer, output.value - fee)
|
55
55
|
prev_txs = [{
|
56
56
|
txid: funding_tx.txid,
|
@@ -61,15 +61,15 @@ module Glueby
|
|
61
61
|
issuer.internal_wallet.sign_tx(tx, prev_txs)
|
62
62
|
end
|
63
63
|
|
64
|
-
def create_issue_tx_for_non_reissuable_token(funding_tx: nil, issuer:, amount:, split: 1, fee_estimator:
|
64
|
+
def create_issue_tx_for_non_reissuable_token(funding_tx: nil, issuer:, amount:, split: 1, fee_estimator: FeeEstimator::Fixed.new, only_finalized: true)
|
65
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)
|
66
66
|
end
|
67
67
|
|
68
|
-
def create_issue_tx_for_nft_token(funding_tx: nil, issuer:, fee_estimator:
|
68
|
+
def create_issue_tx_for_nft_token(funding_tx: nil, issuer:, fee_estimator: FeeEstimator::Fixed.new, only_finalized: true)
|
69
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)
|
70
70
|
end
|
71
71
|
|
72
|
-
def create_issue_tx_from_out_point(funding_tx: nil, token_type:, issuer:, amount:, split: 1, fee_estimator:
|
72
|
+
def create_issue_tx_from_out_point(funding_tx: nil, token_type:, issuer:, amount:, split: 1, fee_estimator: FeeEstimator::Fixed.new, only_finalized: true)
|
73
73
|
tx = Tapyrus::Tx.new
|
74
74
|
|
75
75
|
fee = fee_estimator.fee(dummy_issue_tx_from_out_point)
|
@@ -111,7 +111,7 @@ module Glueby
|
|
111
111
|
issuer.internal_wallet.sign_tx(tx, prev_txs)
|
112
112
|
end
|
113
113
|
|
114
|
-
def create_reissue_tx(funding_tx:, issuer:, amount:, color_id:, split: 1, fee_estimator:
|
114
|
+
def create_reissue_tx(funding_tx:, issuer:, amount:, color_id:, split: 1, fee_estimator: FeeEstimator::Fixed.new)
|
115
115
|
tx = Tapyrus::Tx.new
|
116
116
|
|
117
117
|
out_point = Tapyrus::OutPoint.from_txid(funding_tx.txid, 0)
|
@@ -122,7 +122,7 @@ module Glueby
|
|
122
122
|
receiver_colored_script = receiver_script.add_color(color_id)
|
123
123
|
add_split_output(tx, amount, split, receiver_colored_script)
|
124
124
|
|
125
|
-
fee = fee_estimator.fee(dummy_tx(tx))
|
125
|
+
fee = fee_estimator.fee(FeeEstimator.dummy_tx(tx))
|
126
126
|
fill_change_tpc(tx, issuer, output.value - fee)
|
127
127
|
prev_txs = [{
|
128
128
|
txid: funding_tx.txid,
|
@@ -133,7 +133,7 @@ module Glueby
|
|
133
133
|
issuer.internal_wallet.sign_tx(tx, prev_txs)
|
134
134
|
end
|
135
135
|
|
136
|
-
def create_transfer_tx(funding_tx:nil, color_id:, sender:, receiver_address:, amount:, fee_estimator:
|
136
|
+
def create_transfer_tx(funding_tx:nil, color_id:, sender:, receiver_address:, amount:, fee_estimator: FeeEstimator::Fixed.new, only_finalized: true)
|
137
137
|
receivers = [{ address: receiver_address, amount: amount }]
|
138
138
|
create_multi_transfer_tx(
|
139
139
|
funding_tx: funding_tx,
|
@@ -145,7 +145,7 @@ module Glueby
|
|
145
145
|
)
|
146
146
|
end
|
147
147
|
|
148
|
-
def create_multi_transfer_tx(funding_tx:nil, color_id:, sender:, receivers:, fee_estimator:
|
148
|
+
def create_multi_transfer_tx(funding_tx:nil, color_id:, sender:, receivers:, fee_estimator: FeeEstimator::Fixed.new, only_finalized: true)
|
149
149
|
tx = Tapyrus::Tx.new
|
150
150
|
|
151
151
|
amount = receivers.reduce(0) { |sum, r| sum + r[:amount].to_i }
|
@@ -161,7 +161,7 @@ module Glueby
|
|
161
161
|
|
162
162
|
fill_change_token(tx, sender, sum_token - amount, color_id)
|
163
163
|
|
164
|
-
fee = fee_estimator.fee(dummy_tx(tx))
|
164
|
+
fee = fee_estimator.fee(FeeEstimator.dummy_tx(tx))
|
165
165
|
sum_tpc = if funding_tx
|
166
166
|
out_point = Tapyrus::OutPoint.from_txid(funding_tx.txid, 0)
|
167
167
|
tx.inputs << Tapyrus::TxIn.new(out_point: out_point)
|
@@ -187,7 +187,7 @@ module Glueby
|
|
187
187
|
sender.internal_wallet.sign_tx(tx, prev_txs)
|
188
188
|
end
|
189
189
|
|
190
|
-
def create_burn_tx(funding_tx:nil, color_id:, sender:, amount: 0, fee_estimator:
|
190
|
+
def create_burn_tx(funding_tx:nil, color_id:, sender:, amount: 0, fee_estimator: FeeEstimator::Fixed.new, only_finalized: true)
|
191
191
|
tx = Tapyrus::Tx.new
|
192
192
|
|
193
193
|
utxos = sender.internal_wallet.list_unspent(only_finalized)
|
@@ -196,7 +196,7 @@ module Glueby
|
|
196
196
|
|
197
197
|
fill_change_token(tx, sender, sum_token - amount, color_id) if amount.positive?
|
198
198
|
|
199
|
-
fee = fee_estimator.fee(dummy_tx(tx))
|
199
|
+
fee = fee_estimator.fee(FeeEstimator.dummy_tx(tx))
|
200
200
|
|
201
201
|
sum_tpc = if funding_tx
|
202
202
|
out_point = Tapyrus::OutPoint.from_txid(funding_tx.txid, 0)
|
@@ -281,45 +281,26 @@ module Glueby
|
|
281
281
|
results
|
282
282
|
end
|
283
283
|
|
284
|
-
# Add dummy inputs and outputs to tx
|
285
|
-
def dummy_tx(tx)
|
286
|
-
dummy = Tapyrus::Tx.parse_from_payload(tx.to_payload)
|
287
|
-
|
288
|
-
# dummy input for tpc
|
289
|
-
out_point = Tapyrus::OutPoint.new('00' * 32, 0)
|
290
|
-
dummy.inputs << Tapyrus::TxIn.new(out_point: out_point)
|
291
|
-
|
292
|
-
# Add script_sig to all intpus
|
293
|
-
dummy.inputs.each do |input|
|
294
|
-
input.script_sig = Tapyrus::Script.parse_from_payload('000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'.htb)
|
295
|
-
end
|
296
|
-
|
297
|
-
# dummy output to return change
|
298
|
-
change_script = Tapyrus::Script.to_p2pkh('0000000000000000000000000000000000000000')
|
299
|
-
dummy.outputs << Tapyrus::TxOut.new(value: 0, script_pubkey: change_script)
|
300
|
-
dummy
|
301
|
-
end
|
302
|
-
|
303
284
|
# Add dummy inputs and outputs to tx for issue non-reissuable transaction and nft transaction
|
304
285
|
def dummy_issue_tx_from_out_point
|
305
286
|
tx = Tapyrus::Tx.new
|
306
287
|
receiver_colored_script = Tapyrus::Script.parse_from_payload('21c20000000000000000000000000000000000000000000000000000000000000000bc76a914000000000000000000000000000000000000000088ac'.htb)
|
307
288
|
tx.outputs << Tapyrus::TxOut.new(value: 0, script_pubkey: receiver_colored_script)
|
308
|
-
dummy_tx(tx)
|
289
|
+
FeeEstimator.dummy_tx(tx)
|
309
290
|
end
|
310
291
|
|
311
292
|
private
|
312
293
|
|
313
294
|
# The amount of output in funding tx
|
314
|
-
# It returns same amount with
|
295
|
+
# It returns same amount with FeeEstimator::Fixed's fixed fee. Because it is enough for paying fee for consumer
|
315
296
|
# transactions of the funding transactions.
|
316
297
|
#
|
317
298
|
# @option [Boolean] need_value_for_change_output If it is true, adds more value than the fee for producing change output.
|
318
299
|
def funding_tx_amount(need_value_for_change_output: false)
|
319
300
|
if need_value_for_change_output
|
320
|
-
|
301
|
+
FeeEstimator::Fixed.new.fixed_fee + DUST_LIMIT
|
321
302
|
else
|
322
|
-
|
303
|
+
FeeEstimator::Fixed.new.fixed_fee
|
323
304
|
end
|
324
305
|
end
|
325
306
|
end
|
@@ -24,6 +24,7 @@ module Glueby
|
|
24
24
|
# value is configurable by :default_value. This method do the management to the pool.
|
25
25
|
def manage_utxo_pool
|
26
26
|
txb = Tapyrus::TxBuilder.new
|
27
|
+
fee_estimator = utxo_provider.fee_estimator_for_manage
|
27
28
|
|
28
29
|
sum, utxos = collect_outputs
|
29
30
|
return if utxos.empty?
|
@@ -35,7 +36,7 @@ module Glueby
|
|
35
36
|
|
36
37
|
added_outputs = 0
|
37
38
|
shortage.times do
|
38
|
-
fee =
|
39
|
+
fee = fee_estimator.fee(Contract::FeeEstimator.dummy_tx(txb.build))
|
39
40
|
break if (sum - fee) < utxo_provider.default_value
|
40
41
|
txb.pay(utxo_provider.address, utxo_provider.default_value)
|
41
42
|
sum -= utxo_provider.default_value
|
@@ -44,7 +45,7 @@ module Glueby
|
|
44
45
|
|
45
46
|
return if added_outputs == 0
|
46
47
|
|
47
|
-
fee =
|
48
|
+
fee = fee_estimator.fee(Contract::FeeEstimator.dummy_tx(txb.build))
|
48
49
|
tx = txb.change_address(utxo_provider.address)
|
49
50
|
.fee(fee)
|
50
51
|
.build
|
data/lib/glueby/utxo_provider.rb
CHANGED
@@ -16,6 +16,8 @@ module Glueby
|
|
16
16
|
# @option config [Integer] :default_value
|
17
17
|
# @option opts [Integer] :utxo_pool_size
|
18
18
|
# @option opts [Glueby::Contract::FeeEstimator] :fee_estimator
|
19
|
+
# @option opts [Glueby::Contract::FeeEstimator] :fee_estimator_for_manage It uses this estimator in glueby:utxo_provider:manage_utxo_pool rake task.
|
20
|
+
# If it is nil, it uses same as :fee_estimator instead.
|
19
21
|
def configure(config)
|
20
22
|
@config = config
|
21
23
|
end
|
@@ -24,10 +26,11 @@ module Glueby
|
|
24
26
|
def initialize
|
25
27
|
@wallet = load_wallet
|
26
28
|
validate_config!
|
27
|
-
@fee_estimator = (UtxoProvider.config && UtxoProvider.config[:fee_estimator]) || Glueby::Contract::
|
29
|
+
@fee_estimator = (UtxoProvider.config && UtxoProvider.config[:fee_estimator]) || Glueby::Contract::FeeEstimator::Fixed.new
|
30
|
+
@fee_estimator_for_manage = UtxoProvider.config && UtxoProvider.config[:fee_estimator_for_manage] || @fee_estimator
|
28
31
|
end
|
29
32
|
|
30
|
-
attr_reader :wallet, :fee_estimator, :address
|
33
|
+
attr_reader :wallet, :fee_estimator, :fee_estimator_for_manage, :address
|
31
34
|
|
32
35
|
# Provide a UTXO
|
33
36
|
# @param [Tapyrus::Script] script_pubkey The script to be provided
|
@@ -40,7 +43,7 @@ module Glueby
|
|
40
43
|
txb = Tapyrus::TxBuilder.new
|
41
44
|
txb.pay(script_pubkey.addresses.first, value)
|
42
45
|
|
43
|
-
fee = fee_estimator.fee(dummy_tx(txb.build))
|
46
|
+
fee = fee_estimator.fee(Contract::FeeEstimator.dummy_tx(txb.build))
|
44
47
|
# The outputs need to be shuffled so that no utxos are spent twice as possible.
|
45
48
|
sum, outputs = collect_uncolored_outputs(wallet, fee + value)
|
46
49
|
|
data/lib/glueby/version.rb
CHANGED
@@ -7,7 +7,7 @@ module Glueby
|
|
7
7
|
|
8
8
|
def create
|
9
9
|
timestamps = Glueby::Contract::AR::Timestamp.where(status: :init)
|
10
|
-
fee_estimator = Glueby::Contract::
|
10
|
+
fee_estimator = Glueby::Contract::FeeEstimator::Fixed.new
|
11
11
|
timestamps.each { |t| t.save_with_broadcast(fee_estimator: fee_estimator) }
|
12
12
|
end
|
13
13
|
end
|
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.12.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-03-
|
11
|
+
date: 2022-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tapyrus
|
@@ -110,6 +110,8 @@ files:
|
|
110
110
|
- lib/glueby/contract/active_record/timestamp.rb
|
111
111
|
- lib/glueby/contract/errors.rb
|
112
112
|
- lib/glueby/contract/fee_estimator.rb
|
113
|
+
- lib/glueby/contract/fee_estimator/auto.rb
|
114
|
+
- lib/glueby/contract/fee_estimator/fixed.rb
|
113
115
|
- lib/glueby/contract/payment.rb
|
114
116
|
- lib/glueby/contract/timestamp.rb
|
115
117
|
- lib/glueby/contract/timestamp/syncer.rb
|