istox 0.1.42.14 → 0.1.43

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: dcf8eb41f347c697c127cf7358205c1225930c393fc6f905aa4d97eb70a43d68
4
- data.tar.gz: bed057deb70c062102838f9dddb0a30093e7cd2dff894acd596ba0adfabffbef
3
+ metadata.gz: 88f804800fe5806da1be32b8f6b8510d4935937f81d0f37a7cdf2e70fdbb77e3
4
+ data.tar.gz: 13b4692c747648fb8ff21426b4c322fc50cdaf8b417039d6ddaaf8a5fadedcd3
5
5
  SHA512:
6
- metadata.gz: 33ff5011ea803997929839cf0c6bf82979808a720b2a81c7852c075f82034d7edf81aaacb05f1f218c49abd06123b0e8e6bb7f5e7975b784966fa1ba740ac43c
7
- data.tar.gz: 43982766b83677208e27da959763c0aed40040c617d27ce683225266b1ab8ae40cca4c9ed6afa43ff9341546f2768891321d51bbfc03e79ab84f2f847e3145b5
6
+ metadata.gz: 5d63ab6ab5288527e9aef9ecfff3fd02848fd9eaa254f235e1189eb4a80b42309189f97e4ab23c613126c4c2b8397160eaa268366b7a8f9c564fc059ca5fa661
7
+ data.tar.gz: 82b14b0b6fd2f4fb1998e8e40785b62c660083b81b8a58edb85e45fc8cc043eb7b0f1419dfba6af7566c8593c52e53736e7f889f73f7809289793c4d31c5b41c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.42.13)
4
+ istox (0.1.42.14)
5
5
  bunny (>= 2.12.0)
6
6
  graphlient
7
7
  gruf
data/README.md CHANGED
@@ -1,39 +1,7 @@
1
- # Istox
1
+ to publish new version
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/istox`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ 1. Change version number in version.rb
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ 2. gem build istox
6
6
 
7
- ## Installation
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
- if ::Istox::BlockchainReceipt.find_by_txid(transaction[:id]).nil?
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
- def create!(blockchain_receipt_klass, txids, model, sid, action)
3
+
4
+ def self.init(blockchain_receipt_klass)
5
+ @@blockchain_receipt_klass = blockchain_receipt_klass
6
+ end
4
7
 
5
- klass = class_eval("::#{blockchain_receipt_klass.name}")
6
- unless klass <= ::Istox::BlockchainReceipt
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
- # delete the previous existing blockchain receipts
11
- klass.where(resource_name: model.class.name,
12
- resource_id: model.id).destroy_all
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
- [txids].flatten.each do |txid|
15
- blockchain_receipt = klass.new(
16
- sid: sid,
17
- txid: txid,
18
- resource_name: model.class.name,
19
- resource_id: model.id,
20
- resource_action: action
21
- )
22
- blockchain_receipt.save!
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
@@ -10,6 +10,7 @@ module Istox
10
10
  def change
11
11
  create_table @table_name do |t|
12
12
  t.string :txid
13
+ t.string :txhash
13
14
  t.integer :resource_id
14
15
  t.string :resource_action
15
16
  t.string :resource_name
@@ -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
- txids = @blockchain_receipts.map do |blockchain_receipt|
27
- blockchain_receipt.txid
28
- end.compact
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
- @blocks = get_block_transactions(txids)
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 get_block_transactions(txids)
56
- query = <<-'GRAPHQL'
57
- query($ids: [String!]!) {
58
- blockTransactions(hashes: $ids) {
59
- txid
60
- state
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
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = "0.1.42.14"
2
+ VERSION = "0.1.43"
3
3
  end
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.42.14
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-03-22 00:00:00.000000000 Z
11
+ date: 2019-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny