glueby 1.2.0.beta.2 → 1.2.0.beta.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7615df66be0078e89e4ed0aedd30bcfdb45b86ad9eac3c67fd9d6b65b93e9276
4
- data.tar.gz: ca247aec2c3951be9b294055d43dbe042bebd1d435d5e05dd763e11152bc355b
3
+ metadata.gz: 54e185040a780b540882ac101e5d3cf97c93e07ed9c2cee89f64cf60a719ea5c
4
+ data.tar.gz: ef69570ceac19def04d68651282ee266daf06c1d873d3013bde2b52eafe917c7
5
5
  SHA512:
6
- metadata.gz: 92d9640a75627b4513729a96b870d7b056a1f09ef5716bbcc708a6bc60b04ceea786963569792810a40acceb5f8e2eeb318a07a059b4d1e7e606f83119b68919
7
- data.tar.gz: f035ad6414ae3bf17a8cab97ea1c90a5ab3effbd9e876165151a786846080a619c979bc8f211371488adf4d383d5c5719235c9ece38c07949d8db0c2623ccfe2
6
+ metadata.gz: c7079b2946060fb03586abd351867f68d39b3d18b392ee97dffa90a22d870f95711f6549aa82129d59beafd510a0faa2ff864fa39abecdee957cdd1ef9f7cd77
7
+ data.tar.gz: 730c5a815598e7b590f4eb7fef0e491502e74239c9593840714a94dd38cc60728c20bfe226a12edbef55dec485aa2fbb05b8d2cda2087aa6ada24445eb60bbb5
@@ -1,8 +1,8 @@
1
- # Edit configuration for connection to tapyrus core
2
- Glueby.configure do |config|
3
- config.wallet_adapter = :activerecord
4
- config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'user', password: 'pass' }
5
- end
6
-
7
- # Uncomment next line when using timestamp feature
8
- # Glueby::BlockSyncer.register_syncer(Glueby::Contract::Timestamp::Syncer)
1
+ # Edit configuration for connection to tapyrus core
2
+ Glueby.configure do |config|
3
+ config.wallet_adapter = :activerecord
4
+ config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'user', password: 'pass' }
5
+ end
6
+
7
+ # Uncomment next line when using timestamp feature
8
+ # Glueby::BlockSyncer.register_syncer(Glueby::Contract::Timestamp::Syncer)
@@ -1,16 +1,16 @@
1
- class CreateKey < ActiveRecord::Migration<%= migration_version %>
2
- def change
3
- create_table :glueby_keys<%= table_options %> do |t|
4
- t.string :private_key
5
- t.string :public_key
6
- t.string :script_pubkey
7
- t.string :label, index: true
8
- t.integer :purpose
9
- t.belongs_to :wallet
10
- t.timestamps
11
- end
12
-
13
- add_index :glueby_keys, [:script_pubkey], unique: true
14
- add_index :glueby_keys, [:private_key], unique: true
15
- end
16
- end
1
+ class CreateKey < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :glueby_keys<%= table_options %> do |t|
4
+ t.string :private_key
5
+ t.string :public_key
6
+ t.string :script_pubkey
7
+ t.string :label, index: true
8
+ t.integer :purpose
9
+ t.belongs_to :wallet
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :glueby_keys, [:script_pubkey], unique: true
14
+ add_index :glueby_keys, [:private_key], unique: true
15
+ end
16
+ end
@@ -1,98 +1,98 @@
1
- module Glueby
2
- # You can use BlockSyncer when you need to synchronize the state of
3
- # an application with the state of a blockchain. When BlockSyncer
4
- # detects the generation of a new block, it executes the registered
5
- # syncer code on a block-by-block or transaction-by-transaction basis.
6
- # By using this, an application can detect that the issued transaction
7
- # has been captured in blocks, receive a new remittance, and so on.
8
- #
9
- # # Syncer logic registration
10
- #
11
- # For registration, create a class that implements the method that performs
12
- # synchronization processing and registers it in BlockSyncer. Implement
13
- # methods with the following name in that class.
14
- #
15
- # Method name | Arguments | Call conditions
16
- # ------------------ | --------------------- | ------------------------------
17
- # block_sync (block) | block: Tapyrus::Block | When a new block is created
18
- # block_tx (tx) | tx: Tapyrus::Tx | When a new block is created, it is executed for each tx contained in that block.
19
- #
20
- # @example Register a synchronous logic
21
- # class Syncer
22
- # def block_sync (block)
23
- # # sync a block
24
- # end
25
- #
26
- # def tx_sync (tx)
27
- # # sync a tx
28
- # end
29
- # end
30
- # BlockSyncer.register_syncer(Syncer)
31
- #
32
- # @example Unregister the synchronous logic
33
- # BlockSyncer.unregister_syncer(Syncer)
34
- #
35
- # # Run BlockSyncer
36
- #
37
- # Run the `glueby: block_syncer: start` rake task periodically with a program
38
- # for periodic execution such as cron. If it detects the generation of a new
39
- # block when it is executed, the synchronization process will be executed.
40
- # Determine the execution interval according to the requirements of the application.
41
- class BlockSyncer
42
- # @!attribute [r] height
43
- # @return [Integer] The block height to be synced
44
- attr_reader :height
45
-
46
- class << self
47
- # @!attribute r syncers
48
- # @return [Array<Class>] The syncer classes that is registered
49
- attr_reader :syncers
50
-
51
- # Register syncer class
52
- # @param [Class] syncer The syncer to be registered.
53
- def register_syncer(syncer)
54
- @syncers ||= []
55
- @syncers << syncer
56
- end
57
-
58
- # Unregister syncer class
59
- # @param [Class] syncer The syncer to be unregistered.
60
- def unregister_syncer(syncer)
61
- @syncers ||= []
62
- @syncers.delete(syncer)
63
- end
64
- end
65
-
66
- # @param [Integer] height The block height to be synced in the instance
67
- def initialize(height)
68
- @height = height
69
- end
70
-
71
- # Run a block synchronization
72
- def run
73
- return if self.class.syncers.nil?
74
-
75
- self.class.syncers.each do |syncer|
76
- instance = syncer.new
77
- instance.block_sync(block) if instance.respond_to?(:block_sync)
78
-
79
- if instance.respond_to?(:tx_sync)
80
- block.transactions.each { |tx| instance.tx_sync(tx) }
81
- end
82
- end
83
- end
84
-
85
- private
86
-
87
- def block
88
- @block ||= begin
89
- block = Glueby::Internal::RPC.client.getblock(block_hash, 0)
90
- Tapyrus::Block.parse_from_payload(block.htb)
91
- end
92
- end
93
-
94
- def block_hash
95
- @block_hash ||= Glueby::Internal::RPC.client.getblockhash(height)
96
- end
97
- end
1
+ module Glueby
2
+ # You can use BlockSyncer when you need to synchronize the state of
3
+ # an application with the state of a blockchain. When BlockSyncer
4
+ # detects the generation of a new block, it executes the registered
5
+ # syncer code on a block-by-block or transaction-by-transaction basis.
6
+ # By using this, an application can detect that the issued transaction
7
+ # has been captured in blocks, receive a new remittance, and so on.
8
+ #
9
+ # # Syncer logic registration
10
+ #
11
+ # For registration, create a class that implements the method that performs
12
+ # synchronization processing and registers it in BlockSyncer. Implement
13
+ # methods with the following name in that class.
14
+ #
15
+ # Method name | Arguments | Call conditions
16
+ # ------------------ | --------------------- | ------------------------------
17
+ # block_sync (block) | block: Tapyrus::Block | When a new block is created
18
+ # block_tx (tx) | tx: Tapyrus::Tx | When a new block is created, it is executed for each tx contained in that block.
19
+ #
20
+ # @example Register a synchronous logic
21
+ # class Syncer
22
+ # def block_sync (block)
23
+ # # sync a block
24
+ # end
25
+ #
26
+ # def tx_sync (tx)
27
+ # # sync a tx
28
+ # end
29
+ # end
30
+ # BlockSyncer.register_syncer(Syncer)
31
+ #
32
+ # @example Unregister the synchronous logic
33
+ # BlockSyncer.unregister_syncer(Syncer)
34
+ #
35
+ # # Run BlockSyncer
36
+ #
37
+ # Run the `glueby: block_syncer: start` rake task periodically with a program
38
+ # for periodic execution such as cron. If it detects the generation of a new
39
+ # block when it is executed, the synchronization process will be executed.
40
+ # Determine the execution interval according to the requirements of the application.
41
+ class BlockSyncer
42
+ # @!attribute [r] height
43
+ # @return [Integer] The block height to be synced
44
+ attr_reader :height
45
+
46
+ class << self
47
+ # @!attribute r syncers
48
+ # @return [Array<Class>] The syncer classes that is registered
49
+ attr_reader :syncers
50
+
51
+ # Register syncer class
52
+ # @param [Class] syncer The syncer to be registered.
53
+ def register_syncer(syncer)
54
+ @syncers ||= []
55
+ @syncers << syncer
56
+ end
57
+
58
+ # Unregister syncer class
59
+ # @param [Class] syncer The syncer to be unregistered.
60
+ def unregister_syncer(syncer)
61
+ @syncers ||= []
62
+ @syncers.delete(syncer)
63
+ end
64
+ end
65
+
66
+ # @param [Integer] height The block height to be synced in the instance
67
+ def initialize(height)
68
+ @height = height
69
+ end
70
+
71
+ # Run a block synchronization
72
+ def run
73
+ return if self.class.syncers.nil?
74
+
75
+ self.class.syncers.each do |syncer|
76
+ instance = syncer.new
77
+ instance.block_sync(block) if instance.respond_to?(:block_sync)
78
+
79
+ if instance.respond_to?(:tx_sync)
80
+ block.transactions.each { |tx| instance.tx_sync(tx) }
81
+ end
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ def block
88
+ @block ||= begin
89
+ block = Glueby::Internal::RPC.client.getblock(block_hash, 0)
90
+ Tapyrus::Block.parse_from_payload(block.htb)
91
+ end
92
+ end
93
+
94
+ def block_hash
95
+ @block_hash ||= Glueby::Internal::RPC.client.getblockhash(height)
96
+ end
97
+ end
98
98
  end
@@ -94,7 +94,7 @@ module Glueby
94
94
  # @raise [Glueby::Contract::Errors::PrevTimestampAlreadyUpdated] If the previous timestamp was already updated
95
95
  def save_with_broadcast!(fee_estimator: Glueby::Contract::FeeEstimator::Fixed.new, utxo_provider: nil)
96
96
  validate_prev!
97
- utxo_provider = Glueby::UtxoProvider.instance if !utxo_provider && Glueby.configuration.use_utxo_provider?
97
+ utxo_provider = Glueby::UtxoProvider.new if !utxo_provider && Glueby.configuration.use_utxo_provider?
98
98
 
99
99
  funding_tx, tx, p2c_address, payment_base = create_txs(fee_estimator, utxo_provider)
100
100
 
@@ -11,7 +11,7 @@ module Glueby
11
11
  # Create new public key, and new transaction that sends TPC to it
12
12
  def create_funding_tx(wallet:, script: nil, fee_estimator: FeeEstimator::Fixed.new, only_finalized: true)
13
13
  if Glueby.configuration.use_utxo_provider?
14
- utxo_provider = UtxoProvider.instance
14
+ utxo_provider = UtxoProvider.new
15
15
  script_pubkey = script ? script : Tapyrus::Script.parse_from_addr(wallet.internal_wallet.receive_address)
16
16
  funding_tx, _index = utxo_provider.get_utxo(script_pubkey, funding_tx_amount)
17
17
  utxo_provider.wallet.sign_tx(funding_tx)
@@ -61,8 +61,10 @@ module Glueby
61
61
  amount: output.value
62
62
  }]
63
63
 
64
+ utxo_provider = nil
65
+
64
66
  if Glueby.configuration.use_utxo_provider?
65
- utxo_provider = UtxoProvider.instance
67
+ utxo_provider = UtxoProvider.new
66
68
  tx, fee, input_amount, provided_utxos = utxo_provider.fill_inputs(
67
69
  tx,
68
70
  target_amount: 0,
@@ -77,7 +79,7 @@ module Glueby
77
79
 
78
80
  fill_change_tpc(tx, issuer, input_amount - fee)
79
81
 
80
- UtxoProvider.instance.wallet.sign_tx(tx, prev_txs) if Glueby.configuration.use_utxo_provider?
82
+ utxo_provider.wallet.sign_tx(tx, prev_txs) if Glueby.configuration.use_utxo_provider?
81
83
  issuer.internal_wallet.sign_tx(tx, prev_txs)
82
84
  end
83
85
 
@@ -128,8 +130,10 @@ module Glueby
128
130
  []
129
131
  end
130
132
 
133
+ utxo_provider = nil
134
+
131
135
  if Glueby.configuration.use_utxo_provider?
132
- utxo_provider = UtxoProvider.instance
136
+ utxo_provider = UtxoProvider.new
133
137
  tx, fee, sum, provided_utxos = utxo_provider.fill_inputs(
134
138
  tx,
135
139
  target_amount: 0,
@@ -141,7 +145,7 @@ module Glueby
141
145
 
142
146
  fill_change_tpc(tx, issuer, sum - fee)
143
147
 
144
- UtxoProvider.instance.wallet.sign_tx(tx, prev_txs) if Glueby.configuration.use_utxo_provider?
148
+ utxo_provider.wallet.sign_tx(tx, prev_txs) if Glueby.configuration.use_utxo_provider?
145
149
  issuer.internal_wallet.sign_tx(tx, prev_txs)
146
150
  end
147
151
 
@@ -165,8 +169,10 @@ module Glueby
165
169
  amount: output.value
166
170
  }]
167
171
 
172
+ utxo_provider = nil
173
+
168
174
  if Glueby.configuration.use_utxo_provider?
169
- utxo_provider = UtxoProvider.instance
175
+ utxo_provider = UtxoProvider.new
170
176
  tx, fee, input_amount, provided_utxos = utxo_provider.fill_inputs(
171
177
  tx,
172
178
  target_amount: 0,
@@ -181,7 +187,7 @@ module Glueby
181
187
 
182
188
  fill_change_tpc(tx, issuer, input_amount - fee)
183
189
 
184
- UtxoProvider.instance.wallet.sign_tx(tx, prev_txs) if Glueby.configuration.use_utxo_provider?
190
+ utxo_provider.wallet.sign_tx(tx, prev_txs) if Glueby.configuration.use_utxo_provider?
185
191
  issuer.internal_wallet.sign_tx(tx, prev_txs)
186
192
  end
187
193
 
@@ -214,10 +220,12 @@ module Glueby
214
220
 
215
221
  fee = fee_estimator.fee(FeeEstimator.dummy_tx(tx))
216
222
 
223
+ utxo_provider = nil
224
+
217
225
  # Fill inputs for paying fee
218
226
  prev_txs = []
219
227
  if Glueby.configuration.use_utxo_provider?
220
- utxo_provider = UtxoProvider.instance
228
+ utxo_provider = UtxoProvider.new
221
229
  tx, fee, sum_tpc, provided_utxos = utxo_provider.fill_inputs(
222
230
  tx,
223
231
  target_amount: 0,
@@ -232,7 +240,7 @@ module Glueby
232
240
  end
233
241
 
234
242
  fill_change_tpc(tx, sender, sum_tpc - fee)
235
- UtxoProvider.instance.wallet.sign_tx(tx, prev_txs) if Glueby.configuration.use_utxo_provider?
243
+ utxo_provider.wallet.sign_tx(tx, prev_txs) if Glueby.configuration.use_utxo_provider?
236
244
  sender.internal_wallet.sign_tx(tx, prev_txs)
237
245
  end
238
246
 
@@ -247,12 +255,15 @@ module Glueby
247
255
  fee = fee_estimator.fee(FeeEstimator.dummy_tx(tx))
248
256
 
249
257
  provided_utxos = []
258
+ utxo_provider = nil
259
+
250
260
  if Glueby.configuration.use_utxo_provider?
261
+ utxo_provider = UtxoProvider.new
251
262
  # When it burns all the amount of the color id, burn tx is not going to have any output
252
263
  # because change outputs are not necessary, though such a transaction is not 'standard' and would be rejected by the Tapyrus node.
253
264
  # UtxoProvider#fill_inputs method provides an extra output with a DUST_LIMIT value in this case
254
265
  # , so that it created at least one output to the burn tx.
255
- tx, fee, sum_tpc, provided_utxos = UtxoProvider.instance.fill_inputs(
266
+ tx, fee, sum_tpc, provided_utxos = utxo_provider.fill_inputs(
256
267
  tx,
257
268
  target_amount: 0,
258
269
  current_amount: 0,
@@ -263,7 +274,7 @@ module Glueby
263
274
  fill_input(tx, outputs)
264
275
  end
265
276
  fill_change_tpc(tx, sender, sum_tpc - fee)
266
- UtxoProvider.instance.wallet.sign_tx(tx, provided_utxos) if Glueby.configuration.use_utxo_provider?
277
+ utxo_provider.wallet.sign_tx(tx, provided_utxos) if Glueby.configuration.use_utxo_provider?
267
278
  sender.internal_wallet.sign_tx(tx, provided_utxos)
268
279
  end
269
280
 
@@ -289,7 +300,7 @@ module Glueby
289
300
  return unless change.positive?
290
301
 
291
302
  if Glueby.configuration.use_utxo_provider?
292
- change_script = Tapyrus::Script.parse_from_addr(UtxoProvider.instance.wallet.change_address)
303
+ change_script = Tapyrus::Script.parse_from_addr(UtxoProvider.new.wallet.change_address)
293
304
  else
294
305
  change_script = Tapyrus::Script.parse_from_addr(wallet.internal_wallet.change_address)
295
306
  end
@@ -131,7 +131,7 @@ module Glueby
131
131
  tx, index = nil
132
132
 
133
133
  if Glueby.configuration.use_utxo_provider? || utxo_provider
134
- utxo_provider ||= UtxoProvider.instance
134
+ utxo_provider ||= UtxoProvider.new
135
135
  script_pubkey = Tapyrus::Script.parse_from_addr(address)
136
136
  tx, index = utxo_provider.get_utxo(script_pubkey, amount)
137
137
  else
@@ -265,14 +265,14 @@ module Glueby
265
265
  end
266
266
 
267
267
  # Sign inputs from UtxoProvider
268
- Glueby::UtxoProvider.instance.wallet.sign_tx(tx, utxos) if Glueby.configuration.use_utxo_provider?
268
+ Glueby::UtxoProvider.new.wallet.sign_tx(tx, utxos) if Glueby.configuration.use_utxo_provider?
269
269
 
270
270
  tx
271
271
  end
272
272
 
273
273
  def set_tpc_change_address
274
274
  if Glueby.configuration.use_utxo_provider?
275
- change_address(UtxoProvider.instance.wallet.change_address)
275
+ change_address(UtxoProvider.new.wallet.change_address)
276
276
  else
277
277
  change_address(@sender_wallet.change_address)
278
278
  end
@@ -319,7 +319,7 @@ module Glueby
319
319
  target_amount = @outgoings[Tapyrus::Color::ColorIdentifier.default] || 0
320
320
 
321
321
  provider = if Glueby.configuration.use_utxo_provider?
322
- UtxoProvider.instance
322
+ UtxoProvider.new
323
323
  else
324
324
  sender_wallet
325
325
  end
@@ -13,7 +13,7 @@ module Glueby
13
13
  }
14
14
 
15
15
  def initialize
16
- @utxo_provider = Glueby::UtxoProvider.instance
16
+ @utxo_provider = Glueby::UtxoProvider.new
17
17
  end
18
18
 
19
19
  # Create UTXOs for paying tpc
@@ -1,7 +1,5 @@
1
1
  module Glueby
2
2
  class UtxoProvider
3
- include Singleton
4
-
5
3
  autoload :Tasks, 'glueby/utxo_provider/tasks'
6
4
 
7
5
  WALLET_ID = 'UTXO_PROVIDER_WALLET'
@@ -1,3 +1,3 @@
1
1
  module Glueby
2
- VERSION = "1.2.0.beta.2"
2
+ VERSION = "1.2.0.beta.3"
3
3
  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: 1.2.0.beta.2
4
+ version: 1.2.0.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-05 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tapyrus