glueby 1.1.2 → 1.2.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,5 @@
1
1
  module Glueby
2
2
  class UtxoProvider
3
- include Glueby::Contract::TxBuilder
4
3
  include Singleton
5
4
 
6
5
  autoload :Tasks, 'glueby/utxo_provider/tasks'
@@ -77,26 +76,20 @@ module Glueby
77
76
  # @return [Integer] current_amount The final amount of the tx inputs
78
77
  # @return [Array<Hash>] provided_utxos The utxos that are added to the tx inputs
79
78
  def fill_inputs(tx, target_amount: , current_amount: 0, fee_estimator: Contract::FeeEstimator::Fixed.new)
80
- fee = fee_estimator.fee(Contract::FeeEstimator.dummy_tx(tx, dummy_input_count: 0))
81
- provided_utxos = []
82
-
83
- # If the change output value is less than DUST_LIMIT, tapyrus core returns "dust" error while broadcasting.
84
- target_amount += DUST_LIMIT if target_amount < DUST_LIMIT
85
-
86
- while current_amount - fee < target_amount
87
- sum, utxos = collect_uncolored_outputs(wallet, fee + target_amount - current_amount, provided_utxos)
88
-
89
- utxos.each do |utxo|
90
- tx.inputs << Tapyrus::TxIn.new(out_point: Tapyrus::OutPoint.from_txid(utxo[:txid], utxo[:vout]))
91
- provided_utxos << utxo
92
- end
93
- current_amount += sum
94
-
95
- new_fee = fee_estimator.fee(Contract::FeeEstimator.dummy_tx(tx, dummy_input_count: 0))
96
- fee = new_fee
79
+ wallet.fill_uncolored_inputs(
80
+ tx,
81
+ target_amount: target_amount,
82
+ current_amount: current_amount,
83
+ fee_estimator: fee_estimator
84
+ ) do |utxo|
85
+ # It must use only UTXOs that has defalut_value amount.
86
+ utxo[:amount] == default_value
97
87
  end
88
+ end
89
+ alias fill_uncolored_inputs fill_inputs
98
90
 
99
- [tx, fee, current_amount, provided_utxos]
91
+ def change_address
92
+ wallet.change_address
100
93
  end
101
94
 
102
95
  def default_value
@@ -153,22 +146,10 @@ module Glueby
153
146
  # @return [Integer] sum The sum amount of the funds
154
147
  # @return [Array<Hash>] outputs The UTXO set of the funds
155
148
  def collect_uncolored_outputs(wallet, amount, excludes = [])
156
- utxos = wallet.list_unspent.select do |o|
157
- !o[:color_id] &&
158
- o[:amount] == default_value &&
159
- !excludes.find { |i| i[:txid] == o[:txid] && i[:vout] == o[:vout] }
160
- end
161
- utxos.shuffle!
162
-
163
- utxos.inject([0, []]) do |(sum, outputs), output|
164
- if wallet.lock_unspent(output)
165
- sum += output[:amount]
166
- outputs << output
167
- return [sum, outputs] if sum >= amount
168
- end
169
- [sum, outputs]
149
+ wallet.collect_uncolored_outputs(amount, nil, true, true, true) do |utxo|
150
+ utxo[:amount] == default_value &&
151
+ !excludes.find { |i| i[:txid] == utxo[:txid] && i[:vout] == utxo[:vout] }
170
152
  end
171
- raise Glueby::Contract::Errors::InsufficientFunds
172
153
  end
173
154
 
174
155
  def validate_config!
@@ -1,3 +1,3 @@
1
1
  module Glueby
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0.beta.1"
3
3
  end
@@ -3,7 +3,6 @@ module Glueby
3
3
  module Task
4
4
  module Timestamp
5
5
  module_function
6
- extend Glueby::Contract::TxBuilder
7
6
 
8
7
  def create
9
8
  timestamps = Glueby::Contract::AR::Timestamp.where(status: :init)
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: 1.1.2
4
+ version: 1.2.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-07 00:00:00.000000000 Z
11
+ date: 2023-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tapyrus
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 6.1.3
33
+ version: 7.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 6.1.3
40
+ version: 7.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 6.1.3
75
+ version: 7.0.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 6.1.3
82
+ version: 7.0.0
83
83
  description: A Ruby library of smart contracts that can be used on Tapyrus.
84
84
  email:
85
85
  - azuchi@chaintope.com
@@ -142,6 +142,7 @@ files:
142
142
  - lib/glueby/generator.rb
143
143
  - lib/glueby/generator/migrate_generator.rb
144
144
  - lib/glueby/internal.rb
145
+ - lib/glueby/internal/contract_builder.rb
145
146
  - lib/glueby/internal/rpc.rb
146
147
  - lib/glueby/internal/wallet.rb
147
148
  - lib/glueby/internal/wallet/abstract_wallet_adapter.rb
@@ -172,7 +173,7 @@ metadata:
172
173
  homepage_uri: https://github.com/chaintope/glueby
173
174
  source_code_uri: https://github.com/chaintope/glueby
174
175
  changelog_uri: https://github.com/chaintope/glueby
175
- post_install_message:
176
+ post_install_message:
176
177
  rdoc_options: []
177
178
  require_paths:
178
179
  - lib
@@ -180,15 +181,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
181
  requirements:
181
182
  - - ">="
182
183
  - !ruby/object:Gem::Version
183
- version: 2.3.0
184
+ version: 2.7.0
184
185
  required_rubygems_version: !ruby/object:Gem::Requirement
185
186
  requirements:
186
- - - ">="
187
+ - - ">"
187
188
  - !ruby/object:Gem::Version
188
- version: '0'
189
+ version: 1.3.1
189
190
  requirements: []
190
- rubygems_version: 3.2.3
191
- signing_key:
191
+ rubygems_version: 3.4.10
192
+ signing_key:
192
193
  specification_version: 4
193
194
  summary: A Ruby library of smart contracts that can be used on Tapyrus.
194
195
  test_files: []