istox 0.1.79.pre.test1 → 0.1.79.pre.test2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b9fe0e553280bf1aeb096f7a61a8e5fae7f6fa220e0bb6eb64cce5e0be685e2
4
- data.tar.gz: adcc41c73750b9b3b09919a9b8fd20e7671eccd0dda34e730bd5cf59b00bb4bb
3
+ metadata.gz: e176f1517a34a5168750aecc2e64b86d497fcfafdfc03c4b301705009091f344
4
+ data.tar.gz: d61f64d0fa7d1792eb8f703a1abf93ff046ac770d7ef8260fadd6bbd5e110bcb
5
5
  SHA512:
6
- metadata.gz: 07e4b1fb124bb17eb60c7c38e3e0c7faeec9afc1e9802da2fae721ad8cbf5fe8afea128c691b907f97799bdb8aa1805ad9c16e0d7321512972e9b7a505da1876
7
- data.tar.gz: 79870c307e990da68a18f17633b49300b9348443baf5fed0ac5a32cc7c7a23c46eb0e0a85036bdcce4a6ae54a36c1d847de88b252b189944158cb6bbf3ea7f40
6
+ metadata.gz: 1ef16f8f9c63ed330f34f695aed8cf271bebbff916d702e503fe6f269479bb31e664c960fd4523959924c2de4c689ba38cc29b6b53b81be0eaf54c013650b197
7
+ data.tar.gz: 9c51fd8f23dedfb380fdfe12f2a3d529cfdbc03cdace09e5e5f33e2ddd715eec52512d84dfc69a3fcf5b51a4b358d7d9da500e028d3cc1c782709fc977b1162e
data/.rubocop.yml ADDED
@@ -0,0 +1,105 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5
5
+ Exclude:
6
+ - .gems/**/*
7
+ - bin/**/*
8
+ - config/**/*
9
+ - db/**/*
10
+ - log/**/*
11
+ - public/**/*
12
+ - tmp/**/*
13
+ - vendor/**/*
14
+ - spec/rails_helper.rb
15
+ - spec/spec_helper.rb
16
+ - config.ru
17
+ - Guardfile
18
+ - Rakefile
19
+
20
+ Documentation:
21
+ Enabled: false
22
+
23
+ Layout/SpaceBeforeFirstArg:
24
+ Exclude:
25
+ - app/views/api/**/**/*
26
+
27
+ Lint/AmbiguousBlockAssociation:
28
+ Exclude:
29
+ - spec/**/*
30
+
31
+ Metrics/AbcSize:
32
+ # The ABC size is a calculated magnitude, so this number can be an Integer or
33
+ # a Float.
34
+ Max: 100
35
+
36
+ Metrics/BlockLength:
37
+ CountComments: false # count full line comments?
38
+ Max: 25
39
+ Exclude:
40
+ - config/**/*
41
+ - spec/**/*
42
+ - app/admin/**/*
43
+
44
+ Metrics/BlockNesting:
45
+ Max: 4
46
+
47
+ Metrics/ClassLength:
48
+ CountComments: false # count full line comments?
49
+ Max: 200
50
+
51
+ # Avoid complex methods.
52
+ Metrics/CyclomaticComplexity:
53
+ Max: 20
54
+
55
+ Metrics/MethodLength:
56
+ CountComments: false # count full line comments?
57
+ Max: 100
58
+
59
+ Metrics/ModuleLength:
60
+ CountComments: false # count full line comments?
61
+ Max: 200
62
+
63
+ Metrics/LineLength:
64
+ Max: 120
65
+ # To make it possible to copy or click on URIs in the code, we allow lines
66
+ # containing a URI to be longer than Max.
67
+ AllowURI: true
68
+ URISchemes:
69
+ - http
70
+ - https
71
+
72
+ Metrics/ParameterLists:
73
+ Max: 5
74
+ CountKeywordArgs: true
75
+
76
+ Metrics/PerceivedComplexity:
77
+ Max: 12
78
+
79
+ Style/FrozenStringLiteralComment:
80
+ Enabled: false
81
+
82
+ Style/ModuleFunction:
83
+ Enabled: false
84
+
85
+ RequireNotFound:
86
+ Enabled: false
87
+
88
+ RSpec/MultipleExpectations:
89
+ Max: 99
90
+
91
+ RSpec/ExampleLength:
92
+ Max: 100
93
+
94
+ Lint/BigDecimalNew:
95
+ Enabled: false
96
+
97
+
98
+ RSpec/MessageSpies:
99
+ Enabled: false
100
+
101
+ RSpec/AnyInstance:
102
+ Enabled: false
103
+
104
+ RSpec/VerifiedDoubles:
105
+ Enabled: false
data/.solargraph.yml ADDED
@@ -0,0 +1,14 @@
1
+ ---
2
+ include:
3
+ - "**/*.rb"
4
+ exclude:
5
+ - spec/**/*
6
+ - test/**/*
7
+ - vendor/**/*
8
+ - ".bundle/**/*"
9
+ require: []
10
+ domains: []
11
+ reporters:
12
+ - rubocop
13
+ require_paths: []
14
+ max_files: 5000
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.79)
4
+ istox (0.1.79.pre.test1)
5
5
  binding_of_caller
6
6
  bunny (>= 2.12.0)
7
7
  graphlient
@@ -88,21 +88,21 @@ GEM
88
88
  ffi (1.11.1)
89
89
  globalid (0.4.2)
90
90
  activesupport (>= 4.2.0)
91
- google-protobuf (3.8.0-universal-darwin)
91
+ google-protobuf (3.9.1)
92
92
  googleapis-common-protos-types (1.0.4)
93
93
  google-protobuf (~> 3.0)
94
- graphlient (0.3.5)
94
+ graphlient (0.3.6)
95
95
  faraday
96
96
  faraday_middleware
97
97
  graphql-client
98
- graphql (1.9.7)
99
- graphql-client (0.14.0)
100
- activesupport (>= 3.0, < 6.0)
101
- graphql (~> 1.6)
102
- grpc (1.22.0-universal-darwin)
98
+ graphql (1.9.11)
99
+ graphql-client (0.15.0)
100
+ activesupport (>= 3.0)
101
+ graphql (~> 1.8)
102
+ grpc (1.23.0)
103
103
  google-protobuf (~> 3.8)
104
104
  googleapis-common-protos-types (~> 1.0)
105
- grpc-tools (1.22.0)
105
+ grpc-tools (1.23.0)
106
106
  gruf (2.7.0)
107
107
  activesupport (> 4)
108
108
  concurrent-ruby (> 1)
@@ -227,4 +227,4 @@ DEPENDENCIES
227
227
  sqlite3 (~> 1.3.6)
228
228
 
229
229
  BUNDLED WITH
230
- 1.17.1
230
+ 1.17.3
@@ -14,26 +14,26 @@ module Istox
14
14
  return
15
15
  end
16
16
 
17
- return if !(%w[failed confirmed].include?(transaction.status))
17
+ return unless %w[failed confirmed].include?(transaction.status)
18
+
18
19
  receipt.update!(status: transaction.status)
19
-
20
+
20
21
  resource = begin
21
- class_eval("::#{receipt.resource_name}").find(receipt.resource_id)
22
- rescue => e
23
- puts "Class not found, skipping..."
24
- return
22
+ class_eval("::#{receipt.resource_name}", __FILE__, __LINE__).find(receipt.resource_id)
23
+ rescue StandardError
24
+ puts 'Class not found, skipping...'
25
+ return
25
26
  end
26
27
 
27
28
  return if resource_handled?(receipt)
28
29
 
29
30
  if transaction.status == 'confirmed'
30
31
  resource.handle_confirm(receipt.resource_action)
31
-
32
+
32
33
  mark_resource_handled(receipt)
33
34
  publish_to_frontend(resource, true, receipt, receipt.sid)
34
- end
35
35
 
36
- if transaction.status == 'failed'
36
+ elsif transaction.status == 'failed'
37
37
  resource.handle_fail(receipt.resource_action)
38
38
 
39
39
  mark_resource_handled(receipt)
@@ -61,22 +61,23 @@ module Istox
61
61
  purpose: receipt.activity
62
62
  }
63
63
  )
64
- rescue => e
65
- Rails.logger.error "Unable to publish to frontend for receipt #{receipt.inspect}, but will silently ignore the error"
64
+ rescue StandardError => e
65
+ Rails.logger.error "Unable to publish to frontend for receipt #{receipt.inspect},
66
+ but will silently ignore the error"
66
67
  Rails.logger.error e
67
68
  end
68
69
 
69
70
  def mark_resource_handled(receipt)
70
71
  receipt.update(resource_handled: true)
71
- rescue => e
72
- Rails.logger.error "Unable to update resource_handled for receipt #{receipt.inspect}, but will silently ignore the error"
72
+ rescue StandardError => e
73
+ Rails.logger.error "Unable to update resource_handled for receipt #{receipt.inspect},
74
+ but will silently ignore the error"
73
75
  Rails.logger.error e
74
76
  end
75
77
 
76
78
  def resource_handled?(receipt)
77
- return receipt.resource_handled == true
79
+ receipt.resource_handled == true
78
80
  end
79
-
80
81
  end
81
82
  end
82
83
  end
@@ -1,66 +1,65 @@
1
1
  module Istox
2
- class BlockchainService
3
-
4
- def self.init(blockchain_receipt_klass)
5
- @@blockchain_receipt_klass = blockchain_receipt_klass
6
- end
2
+ class BlockchainService
3
+ def self.init(blockchain_receipt_klass)
4
+ @@blockchain_receipt_klass = blockchain_receipt_klass
5
+ end
7
6
 
8
- def self.get_blockchain_receipt_klass
9
- @@blockchain_receipt_klass
10
- end
7
+ def self.get_blockchain_receipt_klass
8
+ @@blockchain_receipt_klass
9
+ end
11
10
 
12
- def self.request(sid:, action:, before:, execute:)
13
- self.start(sid: sid, action: action, before: before, execute: execute, is_request: true)
14
- end
11
+ def self.request(sid:, action:, before:, execute:)
12
+ start(sid: sid, action: action, before: before, execute: execute, is_request: true)
13
+ end
15
14
 
16
- def self.run(sid:, action:, before:, execute:)
17
- self.start(sid: sid, action: action, before: before, execute: execute)
18
- end
15
+ def self.run(sid:, action:, before:, execute:)
16
+ start(sid: sid, action: action, before: before, execute: execute)
17
+ end
19
18
 
20
- private
21
- # before is the proc that will be executed before, must return the main model blockchain receipt will bind to
22
- def self.start(sid:, action:, before:, execute:, is_request: false)
23
- # create blockchain receipt first
24
- klass = self.blockchain_receipt_class
25
- uuid = :: SecureRandom.uuid
26
- @receipt = klass.create!({
27
- txid: uuid,
28
- sid: sid,
29
- is_request: is_request,
30
- resource_action: action
31
- })
19
+ private
32
20
 
33
- ::ActiveRecord::Base.transaction do
34
- # execute before proc, and get the model that blockchain receipt should bind to
35
- model = before.call(uuid)
21
+ # before is the proc that will be executed before, must return the main model blockchain receipt will bind to
22
+ def self.start(sid:, action:, before:, execute:, is_request: false)
23
+ # create blockchain receipt first
24
+ klass = blockchain_receipt_class
25
+ uuid = :: SecureRandom.uuid
26
+ @receipt = klass.create!(
27
+ txid: uuid,
28
+ sid: sid,
29
+ is_request: is_request,
30
+ resource_action: action
31
+ )
36
32
 
37
- puts model
33
+ ::ActiveRecord::Base.transaction do
34
+ # execute before proc, and get the model that blockchain receipt should bind to
35
+ model = before.call(uuid)
38
36
 
39
- # delete the previous existing blockchain receipts
40
- klass.where(resource_name: model.class.name, resource_id: model.id).destroy_all
37
+ puts model
41
38
 
42
- # then update receipt
43
- @receipt.update!(resource_id: model.id, resource_name: model.class.name)
39
+ # delete the previous existing blockchain receipts
40
+ klass.where(resource_name: model.class.name, resource_id: model.id).destroy_all
44
41
 
45
- # execute the actual call to chainhub
46
- result = execute.call(uuid)
47
- end
48
- rescue => e
49
- @receipt.destroy if @receipt
50
- raise e
51
- end
42
+ # then update receipt
43
+ @receipt.update!(resource_id: model.id, resource_name: model.class.name)
52
44
 
53
- def self.blockchain_receipt_class
54
- raise "Have you forgetten to init blockchain receipt service?" if self.get_blockchain_receipt_klass == nil
45
+ # execute the actual call to chainhub
46
+ execute.call(uuid)
47
+ end
48
+ rescue StandardError => e
49
+ @receipt&.destroy
50
+ raise e
51
+ end
55
52
 
56
- blockchain_receipt_klass = self.get_blockchain_receipt_klass
57
- klass = class_eval("::#{blockchain_receipt_klass.name}")
58
- unless klass <= ::Istox::BlockchainReceipt
59
- raise RuntimeError, "#{blockchain_receipt_klass.name} does not inherit istox blockchain receipt"
60
- end
53
+ def self.blockchain_receipt_class
54
+ raise 'Have you forgetten to init blockchain receipt service?' if get_blockchain_receipt_klass.nil?
61
55
 
62
- return klass
63
- end
56
+ blockchain_receipt_klass = get_blockchain_receipt_klass
57
+ klass = class_eval("::#{blockchain_receipt_klass.name}")
58
+ unless klass <= ::Istox::BlockchainReceipt
59
+ raise "#{blockchain_receipt_klass.name} does not inherit istox blockchain receipt"
60
+ end
64
61
 
62
+ klass
65
63
  end
66
- end
64
+ end
65
+ end
@@ -1,34 +1,31 @@
1
1
  module Istox
2
2
  module BlockchainReceiptQuery
3
3
  extend ActiveSupport::Concern
4
-
5
- #overrideable, when blockchain transaction has confirmed
6
- def handle_confirm(resource_action)
4
+
5
+ # overrideable, when blockchain transaction has confirmed
6
+ def handle_confirm(_resource_action)
7
7
  self
8
8
  end
9
9
 
10
- #overrideable, when blockchain transaction has failed
11
- def handle_fail(resource_action)
10
+ # overrideable, when blockchain transaction has failed
11
+ def handle_fail(_resource_action)
12
12
  self
13
13
  end
14
14
 
15
- #overrideable, extra data that will be published back to frontend
15
+ # overrideable, extra data that will be published back to frontend
16
16
  def handle_extra
17
17
  nil
18
18
  end
19
19
 
20
20
  # outcome of the blockchain transaction, can be "pending" / "confirmed" / "failed"
21
21
  def outcome
22
- blockchain_receipt = ::Istox::BlockchainReceipt.where(resource_id: self.id, resource_name: self.class.name).last
22
+ blockchain_receipt = ::Istox::BlockchainReceipt.where(resource_id: id, resource_name: self.class.name).first
23
23
 
24
- return "confirmed" if blockchain_receipt.empty?
25
-
26
- return blockchain_receipt.status
27
- end
24
+ return 'confirmed' unless blockchain_receipt.present?
28
25
 
29
- def get_blockchain_receipt
30
- ::Istox::BlockchainReceipt.where(resource_id: self.id, resource_name: self.class.name).last
31
- end
26
+ return 'confirmed' if blockchain_receipt.status.blank?
32
27
 
28
+ blockchain_receipt.status
29
+ end
33
30
  end
34
31
  end
data/lib/istox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = "0.1.79-test1"
2
+ VERSION = '0.1.79-test2'.freeze
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.79.pre.test1
4
+ version: 0.1.79.pre.test2
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-08-31 00:00:00.000000000 Z
11
+ date: 2019-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -278,6 +278,8 @@ files:
278
278
  - ".idea/modules.xml"
279
279
  - ".idea/vcs.xml"
280
280
  - ".idea/workspace.xml"
281
+ - ".rubocop.yml"
282
+ - ".solargraph.yml"
281
283
  - CODE_OF_CONDUCT.md
282
284
  - Gemfile
283
285
  - Gemfile.lock
@@ -323,8 +325,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
325
  - !ruby/object:Gem::Version
324
326
  version: 1.3.1
325
327
  requirements: []
326
- rubyforge_project:
327
- rubygems_version: 2.7.7
328
+ rubygems_version: 3.0.6
328
329
  signing_key:
329
330
  specification_version: 4
330
331
  summary: istox backend shared gem