glueby 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea6c9da8fdd46b8e2d82e7d403580d160f8eded28723f7ee33c14e002be5428f
4
- data.tar.gz: d74cc716d2ce35f19eb0ed5d9eb6d46cd464fa3a19a87073dd61a1e2180ef5fe
3
+ metadata.gz: 017fd6425f25bc8b48e36ff46456ff42a88dedd43c9e0359c7b39bc06e1fc8df
4
+ data.tar.gz: e617c0e9e5d931f795a4ead6d929aac46f2b70f3da5eefbd74434814d85884b2
5
5
  SHA512:
6
- metadata.gz: 6c6c75c349edfd4c5ee5fc0e752ce9c65f1ad2f5b323d38f2a51b2ab5d91de8786daf67f1bfb1fdd221a7cc10cf891b6f6551fd58afe8059593a81536027d25c
7
- data.tar.gz: 38c2b4a8e2a085bf238ca37fd1a39930e2b337d0f80a9695adb45116dc8e2cc4478c3c0041c08b0def00cdf15235664bee9d4c6beb9e7a285c1320f8f1b768c2
6
+ metadata.gz: 5f93eee936244581432347212864661160c5c9f282009ae1bcb4d0870f344f951d93b2a06df2f680e1ab3227b0be87face08eba17c6539fc286c24b719d8f68e
7
+ data.tar.gz: 18df860bc145726f1cbf133f9f3df9f099c01bcba6f3f8c2817e19686c906938df455c2346dd55d21a5ebed99e30e9204ae4dd50ea0bf18043f0ee6a83caec08
@@ -2,7 +2,10 @@ module Glueby
2
2
  module Contract
3
3
  module AR
4
4
  class Timestamp < ::ActiveRecord::Base
5
+ include Glueby::GluebyLogger
5
6
  include Glueby::Contract::Timestamp::Util
7
+ include Glueby::Contract::TxBuilder
8
+
6
9
  enum status: { init: 0, unconfirmed: 1, confirmed: 2 }
7
10
  enum timestamp_type: { simple: 0, trackable: 1 }
8
11
 
@@ -21,6 +24,33 @@ module Glueby
21
24
  def latest
22
25
  trackable?
23
26
  end
27
+
28
+ # Broadcast and save timestamp
29
+ # @param [Glueby::Contract::FixedFeeEstimator] fee_estimator
30
+ # @return true if tapyrus transactions were broadcasted and the timestamp was updated successfully, otherwise false.
31
+ def save_with_broadcast(fee_estimator: Glueby::Contract::FixedFeeEstimator.new)
32
+ utxo_provider = Glueby::UtxoProvider.new if Glueby.configuration.use_utxo_provider?
33
+ wallet = Glueby::Wallet.load(wallet_id)
34
+ funding_tx, tx, p2c_address, payment_base = create_txs(wallet, prefix, content_hash, fee_estimator, utxo_provider, type: timestamp_type.to_sym)
35
+ if funding_tx
36
+ ::ActiveRecord::Base.transaction(joinable: false, requires_new: true) do
37
+ wallet.internal_wallet.broadcast(funding_tx)
38
+ logger.info("funding tx was broadcasted(id=#{id}, funding_tx.txid=#{funding_tx.txid})")
39
+ end
40
+ end
41
+ ::ActiveRecord::Base.transaction(joinable: false, requires_new: true) do
42
+ wallet.internal_wallet.broadcast(tx) do |tx|
43
+ assign_attributes(txid: tx.txid, status: :unconfirmed, p2c_address: p2c_address, payment_base: payment_base)
44
+ save!
45
+ end
46
+ logger.info("timestamp tx was broadcasted (id=#{id}, txid=#{tx.txid})")
47
+ end
48
+ true
49
+ rescue => e
50
+ logger.error("failed to broadcast (id=#{id}, reason=#{e.message})")
51
+ errors.add(:base, "failed to broadcast (id=#{id}, reason=#{e.message})")
52
+ false
53
+ end
24
54
  end
25
55
  end
26
56
  end
@@ -1,3 +1,3 @@
1
1
  module Glueby
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
data/lib/glueby.rb CHANGED
@@ -17,6 +17,16 @@ module Glueby
17
17
  require 'glueby/railtie'
18
18
  end
19
19
 
20
+ module GluebyLogger
21
+ def logger
22
+ if defined?(Rails)
23
+ Rails.logger
24
+ else
25
+ Logger.new(STDOUT)
26
+ end
27
+ end
28
+ end
29
+
20
30
  # Add prefix to activerecord table names
21
31
  def self.table_name_prefix
22
32
  'glueby_'
@@ -8,27 +8,8 @@ module Glueby
8
8
 
9
9
  def create
10
10
  timestamps = Glueby::Contract::AR::Timestamp.where(status: :init)
11
- utxo_provider = Glueby::UtxoProvider.new if Glueby.configuration.use_utxo_provider?
12
- timestamps.each do |t|
13
- begin
14
- wallet = Glueby::Wallet.load(t.wallet_id)
15
- funding_tx, tx, p2c_address, payment_base = create_txs(wallet, t.prefix, t.content_hash, Glueby::Contract::FixedFeeEstimator.new, utxo_provider, type: t.timestamp_type.to_sym)
16
- if funding_tx
17
- ::ActiveRecord::Base.transaction do
18
- wallet.internal_wallet.broadcast(funding_tx)
19
- puts "funding tx was broadcasted(id=#{t.id}, funding_tx.txid=#{funding_tx.txid})"
20
- end
21
- end
22
- ::ActiveRecord::Base.transaction do
23
- wallet.internal_wallet.broadcast(tx) do |tx|
24
- t.update(txid: tx.txid, status: :unconfirmed, p2c_address: p2c_address, payment_base: payment_base)
25
- end
26
- puts "timestamp tx was broadcasted (id=#{t.id}, txid=#{tx.txid})"
27
- end
28
- rescue => e
29
- puts "failed to broadcast (id=#{t.id}, reason=#{e.message})"
30
- end
31
- end
11
+ fee_estimator = Glueby::Contract::FixedFeeEstimator.new
12
+ timestamps.each { |t| t.save_with_broadcast(fee_estimator: fee_estimator) }
32
13
  end
33
14
  end
34
15
  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.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-22 00:00:00.000000000 Z
11
+ date: 2022-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tapyrus