txcatcher 0.1.99 → 0.1.100

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: e158896889c01b48727dfd95eb5696a0944c6946de501b1ae0580fb0cfe4573a
4
- data.tar.gz: 9c6e3b2906bbda3dfdd55fd26ecbd5e11a2cce85398ed58fc6e9092d31e6a84c
3
+ metadata.gz: 1086c9abb33b98018483d2188efe2318d2c5e326a73eec1bf91056c48dce84e2
4
+ data.tar.gz: 8f39e9d6aad3ed2717c36fa4e276b3aba59ee5b3248d8d1396007fd5606615ae
5
5
  SHA512:
6
- metadata.gz: a79d5a88e5c01480febb6f663d66e7f3abf40ee39d616489b9101caaeed75d0165383143559bbad87444878d9f6ff67d7c84c1569e11349014a799b4a980143e
7
- data.tar.gz: 99264405cdd1a7dde60fadb1d1b13cff00dc601cdf55c524538fbcccbabb8132dd819e0ce92642b8d710fcb5f7a671f7f0a82bf2ee33bda74512350d81ea02a5
6
+ metadata.gz: d282ba132fa8a3a08a4a4a11840e46a2609eea837595a4c47432697cdbb5d105fdba690acff8c5b2c442bb357cbf1618bed68916b02fecb6f37157f6e23f5ef9
7
+ data.tar.gz: 35fd9704e8f5ec349a3fe1e5f3c4acc8c900fdb0c3d99590ed5c9640a24acdd0672c5bf78bdedfd3d7f724ead52ab0b225f8f0c4df95fa03e403493ba0107515
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.99
1
+ 0.1.100
@@ -44,7 +44,7 @@ module TxCatcher
44
44
 
45
45
  # Queries rpc node to check whether the transaction has been included in any of the blocks,
46
46
  # but only if current block_height is nil.
47
- def update_block_height!(limit=100,dry_run=false)
47
+ def update_block_height!(limit=100,dont_save=false)
48
48
 
49
49
  # This calculates the approximate number of blocks to check.
50
50
  # So, for example, if transaction is less than 10 minutes old,
@@ -65,7 +65,7 @@ module TxCatcher
65
65
  LOGGER.report "--- checking block #{TxCatcher.current_block_height - i} for tx #{self.txid}"
66
66
  if block["tx"] && block["tx"].include?(self.txid)
67
67
  LOGGER.report "tx #{self.txid} block height updated to #{block["height"]}"
68
- self.update(block_height: block["height"]) if !dry_run
68
+ self.update(block_height: block["height"]) if !dont_save
69
69
  return block["height"].to_i
70
70
  end
71
71
  end
@@ -11,6 +11,7 @@ module TxCatcher
11
11
  rescue BitcoinRPC::JSONRPCError => e
12
12
  return [400, {}, { error: e.data }.to_json]
13
13
  rescue Exception => e
14
+ p e.backtrace
14
15
  return [500, {}, { error: e.to_s }.to_json]
15
16
  end
16
17
  end
@@ -66,25 +67,41 @@ module TxCatcher
66
67
  model = Address.where(address: addr).eager(deposits: :transactions).first
67
68
  return [200, {}, "{}"] unless model
68
69
 
69
- txs_to_update = []
70
+ confirmed_txs_to_update = []
71
+ unconfirmed_txs_to_update = []
72
+ newly_confirmed_txs_to_update = []
73
+
70
74
  transactions = model.deposits.map { |d| d.transaction }
71
75
  utxos = transactions.map do |t|
72
76
  outs = t.tx_hash["vout"].select { |out| out["scriptPubKey"]["addresses"] == [addr] }
73
- txs_to_update << t if outs.length > 0
74
77
  outs.map! do |out|
75
78
  out["confirmations"] = t.confirmations || 0
76
79
  out["txid"] = t.txid
80
+ confirmed_txs_to_update << t if out["confirmations"] > 0
81
+ unconfirmed_txs_to_update << t if out["confirmations"] == 0
77
82
  out
78
83
  end
79
84
  outs
80
85
  end.flatten
81
86
 
87
+ unconfirmed_txs_to_update = unconfirmed_txs_to_update.map do |t|
88
+ tx_block_height = t.update_block_height!(100,:dont_save)
89
+ if tx_block_height && tx_block_height > 0
90
+ newly_confirmed_txs_to_update << t
91
+ nil
92
+ else
93
+ t
94
+ end
95
+ end.compact
96
+
82
97
  # Update all txs after we map them. We don't use regular Transaction#update
83
98
  # in the #map loop above, because this will quickly get out of hand and result
84
99
  # in a gateway timeout, if there are a lot of transactions to be updated. Instead,
85
100
  # we collect all txs in an array and then update them in bulk here.
86
- txs_to_update.map! { |t| [t.id, true, t.update_block_height!] }
87
- TxCatcher.db_connection[:transactions].import([:id, :protected, :block_height], txs_to_update)
101
+ no_block_height_change_txs_ids = (confirmed_txs_to_update + unconfirmed_txs_to_update).map(&:id)
102
+ block_height_change_txs_ids = newly_confirmed_txs_to_update.map(&:id)
103
+ TxCatcher.db_connection[:transactions].where(id: no_block_height_change_txs_ids).update(protected: true)
104
+ TxCatcher.db_connection[:transactions].where(id: block_height_change_txs_ids).update(protected: true, block_height: TxCatcher.current_block_height)
88
105
 
89
106
  [200, {}, utxos.to_json]
90
107
  end
data/txcatcher.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: txcatcher 0.1.99 ruby lib
5
+ # stub: txcatcher 0.1.100 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "txcatcher".freeze
9
- s.version = "0.1.99"
9
+ s.version = "0.1.100"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: txcatcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.99
4
+ version: 0.1.100
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Snitko