istox 0.1.42.14 → 0.1.43
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -36
- data/lib/istox.rb +2 -0
- data/lib/istox/consumers/blockchain_status_handler.rb +12 -1
- data/lib/istox/helpers/blockchain_receipt_service.rb +28 -17
- data/lib/istox/migrations/create_blockchain_receipts.rb +1 -0
- data/lib/istox/models/concerns/blockchain_receipt_query.rb +57 -17
- data/lib/istox/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88f804800fe5806da1be32b8f6b8510d4935937f81d0f37a7cdf2e70fdbb77e3
|
4
|
+
data.tar.gz: 13b4692c747648fb8ff21426b4c322fc50cdaf8b417039d6ddaaf8a5fadedcd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d63ab6ab5288527e9aef9ecfff3fd02848fd9eaa254f235e1189eb4a80b42309189f97e4ab23c613126c4c2b8397160eaa268366b7a8f9c564fc059ca5fa661
|
7
|
+
data.tar.gz: 82b14b0b6fd2f4fb1998e8e40785b62c660083b81b8a58edb85e45fc8cc043eb7b0f1419dfba6af7566c8593c52e53736e7f889f73f7809289793c4d31c5b41c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,39 +1,7 @@
|
|
1
|
-
|
1
|
+
to publish new version
|
2
2
|
|
3
|
-
|
3
|
+
1. Change version number in version.rb
|
4
4
|
|
5
|
-
|
5
|
+
2. gem build istox
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'istox'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install istox
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/istox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
-
|
37
|
-
## Code of Conduct
|
38
|
-
|
39
|
-
Everyone interacting in the Istox project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/istox/blob/master/CODE_OF_CONDUCT.md).
|
7
|
+
3. gem publish istox-<VERSION>.gem
|
data/lib/istox.rb
CHANGED
@@ -10,6 +10,7 @@ module Istox
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
require "istox/interfaces/chainhub/transaction"
|
13
14
|
require "istox/helpers/publisher"
|
14
15
|
require "istox/helpers/bunny_boot"
|
15
16
|
require "istox/helpers/order_book"
|
@@ -19,5 +20,6 @@ module Istox
|
|
19
20
|
require "istox/models/blockchain_receipt"
|
20
21
|
require "istox/models/concerns/blockchain_receipt_query"
|
21
22
|
require "istox/consumers/blockchain_status_handler"
|
23
|
+
require "istox/consumers/blockchain_hash_handler"
|
22
24
|
require "istox/migrations/create_blockchain_receipts"
|
23
25
|
end
|
@@ -4,9 +4,19 @@ module Istox
|
|
4
4
|
def txn_status_changed(transactions)
|
5
5
|
transactions.each do |transaction|
|
6
6
|
|
7
|
-
|
7
|
+
receipt = ::Istox::BlockchainReceipt.where(txhash: transaction[:hash], txid: transaction[:id]).first
|
8
|
+
|
9
|
+
if receipt.nil?
|
10
|
+
receipt = ::Istox::BlockchainReceipt.where(txhash: nil, txid: transaction[:id]).first
|
11
|
+
end
|
12
|
+
|
13
|
+
if receipt.nil?
|
8
14
|
puts 'Transaction not found, skipping...'
|
9
15
|
next
|
16
|
+
else
|
17
|
+
if receipt.txhash.blank?
|
18
|
+
receipt.update!(txhash: transaction[:hash])
|
19
|
+
end
|
10
20
|
end
|
11
21
|
|
12
22
|
find_resource(transaction) do |receipt, resource_name, resource_id, resource_action, sid|
|
@@ -23,6 +33,7 @@ module Istox
|
|
23
33
|
|
24
34
|
if confirmed?(transaction)
|
25
35
|
next if resource.outcome == 'pending'
|
36
|
+
|
26
37
|
if resource.outcome == 'confirmed'
|
27
38
|
resource.handle_confirm(resource_action)
|
28
39
|
publish_to_frontend(resource, true, receipt, sid, receipt_list) do
|
@@ -1,26 +1,37 @@
|
|
1
1
|
module Istox
|
2
2
|
class BlockchainReceiptService
|
3
|
-
|
3
|
+
|
4
|
+
def self.init(blockchain_receipt_klass)
|
5
|
+
@@blockchain_receipt_klass = blockchain_receipt_klass
|
6
|
+
end
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
raise RuntimeError, "#{blockchain_receipt_klass.name} does not inherit istox blockchain receipt"
|
8
|
+
def self.get_blockchain_receipt_klass
|
9
|
+
@@blockchain_receipt_klass
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
def create!(tx_message, model, sid, action)
|
13
|
+
raise "Have you forgetten to init blockchain receipt service?" if ::Istox::BlockchainReceiptService.get_blockchain_receipt_klass == nil
|
14
|
+
|
15
|
+
blockchain_receipt_klass = ::Istox::BlockchainReceiptService.get_blockchain_receipt_klass
|
16
|
+
klass = class_eval("::#{blockchain_receipt_klass.name}")
|
17
|
+
unless klass <= ::Istox::BlockchainReceipt
|
18
|
+
raise RuntimeError, "#{blockchain_receipt_klass.name} does not inherit istox blockchain receipt"
|
19
|
+
end
|
13
20
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
# delete the previous existing blockchain receipts
|
22
|
+
klass.where(resource_name: model.class.name,
|
23
|
+
resource_id: model.id).destroy_all
|
24
|
+
|
25
|
+
(0...tx_message.txnCount).each do |i|
|
26
|
+
blockchain_receipt = klass.new(
|
27
|
+
sid: sid,
|
28
|
+
txid: tx_message.uuid,
|
29
|
+
resource_name: model.class.name,
|
30
|
+
resource_id: model.id,
|
31
|
+
resource_action: action
|
32
|
+
)
|
33
|
+
blockchain_receipt.save!
|
34
|
+
end
|
23
35
|
end
|
24
36
|
end
|
25
|
-
end
|
26
37
|
end
|
@@ -1,6 +1,33 @@
|
|
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
|
4
31
|
|
5
32
|
#overrideable, when blockchain transaction has confirmed
|
6
33
|
def handle_confirm(resource_action)
|
@@ -23,23 +50,41 @@ module Istox
|
|
23
50
|
|
24
51
|
return "confirmed" if @blockchain_receipts.empty?
|
25
52
|
|
26
|
-
|
27
|
-
blockchain_receipt.
|
28
|
-
end
|
53
|
+
txhashes = @blockchain_receipts.map do |blockchain_receipt|
|
54
|
+
blockchain_receipt.txhash
|
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
|
+
@transaction_store ||= get_block_transactions(txhashes)
|
62
|
+
@blocks = []
|
29
63
|
|
30
|
-
@
|
64
|
+
@blockchain_receipts.map do |blockchain_receipt|
|
65
|
+
transaction = @transaction_store.find { |t| t.txhash == blockchain_receipt.txhash}
|
66
|
+
|
67
|
+
|
68
|
+
if transaction
|
69
|
+
@blocks.push(transaction)
|
70
|
+
else
|
71
|
+
@blocks.push(OpenStruct.new({ txhash: blockchain_receipt.txhash, status: 'pending' }))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
31
76
|
|
32
77
|
return "failed" if blocks_failed?
|
33
78
|
return "pending" if blocks_pending?
|
34
79
|
return "confirmed" if blocks_confirmed?
|
35
80
|
end
|
36
81
|
|
37
|
-
private
|
38
|
-
|
39
82
|
def get_blockchain_receipts
|
40
83
|
::Istox::BlockchainReceipt.where(resource_id: self.id, resource_name: self.class.name).all
|
41
84
|
end
|
42
85
|
|
86
|
+
private
|
87
|
+
|
43
88
|
def blocks_failed?
|
44
89
|
@blocks.any? { |obj| obj.state == 'failed' }
|
45
90
|
end
|
@@ -52,17 +97,12 @@ module Istox
|
|
52
97
|
!@blocks.any? { |obj| obj.state == 'pending' } && !@blocks.any? { |obj| obj.state == 'failed' }
|
53
98
|
end
|
54
99
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
}
|
62
|
-
}
|
63
|
-
GRAPHQL
|
64
|
-
|
65
|
-
Istox::GraphqlClient.query("chainhub", query, { ids: txids }).data.block_transactions
|
100
|
+
def set_transactions_store(store)
|
101
|
+
@transactions_store = store
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_block_transactions(txhashes)
|
105
|
+
Istox::Interfaces::Chainhub::Transaction.get_block_transactions(txhashes)
|
66
106
|
end
|
67
107
|
|
68
108
|
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.43
|
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-
|
11
|
+
date: 2019-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|