istox 0.1.44 → 0.1.45
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 559c9df3e5df4437bfd5d374aedf3967cdaa8beb01157db1facf3d722bfb3f0e
|
4
|
+
data.tar.gz: ae3165eed01d37392f02eb2c4bd0b6c5d55dd4fe17253a39db04a0785519124d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7243f21712865a80d720479b611a124084cba968985dc755e2189110dfc3308d85a2a07a946cf30049bf2947b6862da8a618d903818e0e04d9f44c579602922
|
7
|
+
data.tar.gz: 5e0ca0625bd42bcb4bbafe5fe7a77a7520bbc179deceaf9afc840cbdc978686eaaa8d3237949c1c3458afe8223437094c8af07e6f3e69e5f3f12ee89b32e5677
|
data/Gemfile.lock
CHANGED
@@ -18,50 +18,41 @@ module Istox
|
|
18
18
|
transactions.each do |transaction|
|
19
19
|
receipt = ::Istox::BlockchainReceipt.where(txhash: transaction.id).first
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
if resource.outcome == 'confirmed'
|
37
|
-
resource.handle_confirm(resource_action)
|
38
|
-
publish_to_frontend(resource, true, receipt, sid, receipt_list) do
|
39
|
-
update_receipts(receipt_list)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
21
|
+
next if !(%w[failed confirmed pending].include?(transaction.status))
|
22
|
+
receipt.update!(status: transaction.status)
|
23
|
+
|
24
|
+
resource = begin
|
25
|
+
class_eval("::#{receipt.resource_name}").find(receipt.resource_id)
|
26
|
+
rescue => e
|
27
|
+
puts e.inspect
|
28
|
+
next
|
29
|
+
end
|
30
|
+
|
31
|
+
next if resource_handled?(resource)
|
32
|
+
|
33
|
+
if transaction.status == 'confirmed'
|
34
|
+
next if resource.outcome == 'pending'
|
43
35
|
|
44
|
-
if
|
45
|
-
resource.
|
46
|
-
|
36
|
+
if resource.outcome == 'confirmed'
|
37
|
+
resource.handle_confirm(resource_action)
|
38
|
+
|
39
|
+
mark_resource_handled(resource)
|
40
|
+
publish_to_frontend(resource, true, receipt, sid, receipt_list)
|
47
41
|
end
|
48
42
|
end
|
49
|
-
end
|
50
|
-
end
|
51
43
|
|
52
|
-
|
44
|
+
if transaction.status == 'failed'
|
45
|
+
resource.handle_fail(resource_action)
|
53
46
|
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
mark_resource_handled(resource)
|
48
|
+
publish_to_frontend(resource, false, receipt, sid, receipt_list)
|
49
|
+
end
|
57
50
|
|
58
|
-
|
59
|
-
::Istox::BlockchainReceipt.where(
|
60
|
-
resource_name: resource_name,
|
61
|
-
resource_id: resource.id
|
62
|
-
)
|
51
|
+
end
|
63
52
|
end
|
64
53
|
|
54
|
+
private
|
55
|
+
|
65
56
|
def publish_to_frontend(model, success, receipt, sid, receipt_list)
|
66
57
|
yield if block_given?
|
67
58
|
|
@@ -85,34 +76,29 @@ module Istox
|
|
85
76
|
)
|
86
77
|
end
|
87
78
|
|
88
|
-
def
|
89
|
-
|
90
|
-
end
|
79
|
+
def get_receipts_tx_hashes(receipt_list)
|
80
|
+
tx_hashes = receipt_list.map(&:txhash).compact
|
91
81
|
|
92
|
-
|
93
|
-
transaction.status == 'confirmed'
|
82
|
+
tx_hashes.join(', ')
|
94
83
|
end
|
95
84
|
|
96
|
-
def
|
85
|
+
def mark_resource_handled(resource)
|
86
|
+
receipt_list = get_receipt_list(resource)
|
97
87
|
receipt_list.each do |receipt|
|
98
88
|
receipt.update(resource_handled: true)
|
99
89
|
end
|
100
90
|
end
|
101
91
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
yield(receipt, receipt.resource_name, receipt.resource_id, receipt.resource_action, receipt.sid)
|
106
|
-
end
|
107
|
-
|
108
|
-
def get_receipts_tx_hashes(receipt_list)
|
109
|
-
tx_hashes = receipt_list.map(&:txhash).compact
|
110
|
-
|
111
|
-
tx_hashes.join(', ')
|
92
|
+
def resource_handled?(resource)
|
93
|
+
receipt_list = get_receipt_list(resource)
|
94
|
+
receipt_list.map(&:resource_handled).none? { |item| item.nil? || item == false }
|
112
95
|
end
|
113
96
|
|
114
|
-
def
|
115
|
-
|
97
|
+
def get_receipt_list(resource)
|
98
|
+
::Istox::BlockchainReceipt.where(
|
99
|
+
resource_name: resource.class.name,
|
100
|
+
resource_id: resource.id
|
101
|
+
)
|
116
102
|
end
|
117
103
|
|
118
104
|
end
|
@@ -1,33 +1,6 @@
|
|
1
1
|
module Istox
|
2
2
|
module BlockchainReceiptQuery
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
class_methods do
|
6
|
-
def with_receipts(arr = nil)
|
7
|
-
if !arr
|
8
|
-
arr = self.all
|
9
|
-
end
|
10
|
-
|
11
|
-
hashes = arr.map do |model|
|
12
|
-
blockchain_receipts = model.get_blockchain_receipts
|
13
|
-
|
14
|
-
return blockchain_receipts.map do |blockchain_receipt|
|
15
|
-
blockchain_receipt.txhash
|
16
|
-
end
|
17
|
-
end.flatten
|
18
|
-
|
19
|
-
data = self.block_transactions(hashes)
|
20
|
-
|
21
|
-
arr.map do |model|
|
22
|
-
model.set_transactions_store(data)
|
23
|
-
model
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def block_transactions(txhashes)
|
28
|
-
Istox::Interfaces::Chainhub::Transaction.get_block_transactions(txhashes)
|
29
|
-
end
|
30
|
-
end
|
31
4
|
|
32
5
|
#overrideable, when blockchain transaction has confirmed
|
33
6
|
def handle_confirm(resource_action)
|
@@ -46,63 +19,23 @@ module Istox
|
|
46
19
|
|
47
20
|
# outcome of the blockchain transaction, can be "pending" / "confirmed" / "failed"
|
48
21
|
def outcome
|
49
|
-
|
22
|
+
blockchain_receipts = get_blockchain_receipts
|
50
23
|
|
51
|
-
return "confirmed" if
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
# return pending state if there is any unknown hashes
|
58
|
-
return "pending" if txhashes.any?{ |e| e.blank? }
|
59
|
-
|
60
|
-
# if transactions store already exists, we should retrieve the state from
|
61
|
-
prepare_block_transactions(txhashes)
|
62
|
-
@blocks = []
|
24
|
+
return "confirmed" if blockchain_receipts.empty?
|
25
|
+
|
26
|
+
# return failed state if there is any failed hashes
|
27
|
+
return "failed" if blockchain_receipts.any?{ |r| r.status == 'failed' }
|
63
28
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
if transaction
|
68
|
-
@blocks.push(transaction)
|
69
|
-
else
|
70
|
-
@blocks.push(OpenStruct.new({ txhash: blockchain_receipt.txhash, status: 'pending' }))
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
|
29
|
+
# return pending state if there is any pending hashes
|
30
|
+
return "pending" if blockchain_receipts.any?{ |r| r.status == 'pending' }
|
75
31
|
|
76
|
-
return
|
77
|
-
return "
|
78
|
-
return "confirmed" if blocks_confirmed?
|
32
|
+
# return confirmed otherwise
|
33
|
+
return "confirmed"
|
79
34
|
end
|
80
35
|
|
81
36
|
def get_blockchain_receipts
|
82
37
|
::Istox::BlockchainReceipt.where(resource_id: self.id, resource_name: self.class.name).all
|
83
38
|
end
|
84
|
-
|
85
|
-
def set_transactions_store(store)
|
86
|
-
@transactions_store = store
|
87
|
-
end
|
88
|
-
|
89
|
-
def prepare_block_transactions(txhashes)
|
90
|
-
@transactions_store ||= Istox::Interfaces::Chainhub::Transaction.get_block_transactions(txhashes)
|
91
|
-
end
|
92
|
-
|
93
|
-
private
|
94
|
-
|
95
|
-
def blocks_failed?
|
96
|
-
@blocks.any? { |obj| obj.state == 'failed' }
|
97
|
-
end
|
98
|
-
|
99
|
-
def blocks_pending?
|
100
|
-
@blocks.empty? || @blocks.any? { |obj| obj.state == 'pending' }
|
101
|
-
end
|
102
|
-
|
103
|
-
def blocks_confirmed?
|
104
|
-
!@blocks.any? { |obj| obj.state == 'pending' } && !@blocks.any? { |obj| obj.state == 'failed' }
|
105
|
-
end
|
106
|
-
|
39
|
+
|
107
40
|
end
|
108
41
|
end
|
data/lib/istox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: istox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.45
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siong Leng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|