istox 0.2.11.pre.2 → 0.2.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +20 -16
- data/lib/istox.rb +2 -0
- data/lib/istox/helpers/blockchain_service.rb +8 -0
- data/lib/istox/helpers/formatter.rb +3 -1
- data/lib/istox/helpers/race_condition_helper.rb +26 -0
- data/lib/istox/models/auto_enum.rb +38 -0
- data/lib/istox/version.rb +1 -1
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca1e8a56cf58ec65db8e7c74bce91228a9c58f6fac41fba4dd8569263fe293ae
|
4
|
+
data.tar.gz: e222955b4c24d1422f43cccc266251d77bf79322df1d3b6e24c7e8e598ced3cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 293000d6656fc803c265a7dd025824a782895bb86d50c4b9e64f1c3a53b64695c68b5b72498aeff9750a800522368811371bf5d6657b2a7b39fb531141d33ca5
|
7
|
+
data.tar.gz: a12c26ffb85108b2b664245f57e5cf86dbd6a3dbc952dcf5c06d3d01fff1bcdeaffd5a68792c172bfd4722166dac74d26fdaaa2887afe6c154c63b2860fa22d7
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
istox (0.2.
|
4
|
+
istox (0.2.13)
|
5
5
|
amazing_print
|
6
6
|
awesome_print
|
7
7
|
aws-sdk-sns (~> 1)
|
@@ -67,21 +67,21 @@ GEM
|
|
67
67
|
amq-protocol (2.3.2)
|
68
68
|
arel (9.0.0)
|
69
69
|
awesome_print (1.9.2)
|
70
|
-
aws-eventstream (1.1.
|
71
|
-
aws-partitions (1.
|
72
|
-
aws-sdk-core (3.
|
70
|
+
aws-eventstream (1.1.1)
|
71
|
+
aws-partitions (1.470.0)
|
72
|
+
aws-sdk-core (3.114.3)
|
73
73
|
aws-eventstream (~> 1, >= 1.0.2)
|
74
74
|
aws-partitions (~> 1, >= 1.239.0)
|
75
75
|
aws-sigv4 (~> 1.1)
|
76
76
|
jmespath (~> 1.0)
|
77
|
-
aws-sdk-sns (1.
|
78
|
-
aws-sdk-core (~> 3, >= 3.
|
77
|
+
aws-sdk-sns (1.42.0)
|
78
|
+
aws-sdk-core (~> 3, >= 3.112.0)
|
79
79
|
aws-sigv4 (~> 1.1)
|
80
80
|
aws-sdk-xray (1.4.0)
|
81
81
|
aws-sdk-core (~> 3)
|
82
82
|
aws-sigv4 (~> 1.0)
|
83
|
-
aws-sigv4 (1.
|
84
|
-
aws-eventstream (~> 1
|
83
|
+
aws-sigv4 (1.2.3)
|
84
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
85
85
|
aws-xray-sdk (0.11.4)
|
86
86
|
aws-sdk-xray (~> 1.4.0)
|
87
87
|
multi_json (~> 1)
|
@@ -91,7 +91,7 @@ GEM
|
|
91
91
|
bullet (5.7.6)
|
92
92
|
activesupport (>= 3.0.0)
|
93
93
|
uniform_notifier (~> 1.11.0)
|
94
|
-
bunny (2.
|
94
|
+
bunny (2.19.0)
|
95
95
|
amq-protocol (~> 2.3, >= 2.3.1)
|
96
96
|
sorted_set (~> 1, >= 1.0.2)
|
97
97
|
byebug (11.1.3)
|
@@ -112,32 +112,36 @@ GEM
|
|
112
112
|
i18n (~> 0.5)
|
113
113
|
fakeredis (0.7.0)
|
114
114
|
redis (>= 3.2, < 5.0)
|
115
|
-
faraday (1.
|
115
|
+
faraday (1.5.1)
|
116
116
|
faraday-em_http (~> 1.0)
|
117
117
|
faraday-em_synchrony (~> 1.0)
|
118
118
|
faraday-excon (~> 1.1)
|
119
|
+
faraday-httpclient (~> 1.0.1)
|
119
120
|
faraday-net_http (~> 1.0)
|
120
121
|
faraday-net_http_persistent (~> 1.1)
|
122
|
+
faraday-patron (~> 1.0)
|
121
123
|
multipart-post (>= 1.2, < 3)
|
122
124
|
ruby2_keywords (>= 0.0.4)
|
123
125
|
faraday-em_http (1.0.0)
|
124
126
|
faraday-em_synchrony (1.0.0)
|
125
127
|
faraday-excon (1.1.0)
|
128
|
+
faraday-httpclient (1.0.1)
|
126
129
|
faraday-net_http (1.0.1)
|
127
|
-
faraday-net_http_persistent (1.
|
130
|
+
faraday-net_http_persistent (1.2.0)
|
131
|
+
faraday-patron (1.0.0)
|
128
132
|
faraday_middleware (1.0.0)
|
129
133
|
faraday (~> 1.0)
|
130
134
|
ffi (1.15.3)
|
131
135
|
globalid (0.4.2)
|
132
136
|
activesupport (>= 4.2.0)
|
133
137
|
google-protobuf (3.17.3)
|
134
|
-
googleapis-common-protos-types (1.0
|
138
|
+
googleapis-common-protos-types (1.1.0)
|
135
139
|
google-protobuf (~> 3.14)
|
136
140
|
graphlient (0.5.0)
|
137
141
|
faraday (>= 1.0)
|
138
142
|
faraday_middleware
|
139
143
|
graphql-client
|
140
|
-
graphql (1.12.
|
144
|
+
graphql (1.12.14)
|
141
145
|
graphql-client (0.16.0)
|
142
146
|
activesupport (>= 3.0)
|
143
147
|
graphql (~> 1.8)
|
@@ -174,7 +178,7 @@ GEM
|
|
174
178
|
nokogiri (1.11.7)
|
175
179
|
mini_portile2 (~> 2.5.0)
|
176
180
|
racc (~> 1.4)
|
177
|
-
oj (3.
|
181
|
+
oj (3.12.2)
|
178
182
|
ougai (2.0.0)
|
179
183
|
oj (~> 3.10)
|
180
184
|
paranoia (2.4.3)
|
@@ -220,7 +224,7 @@ GEM
|
|
220
224
|
rb-inotify (0.10.1)
|
221
225
|
ffi (~> 1.0)
|
222
226
|
rbtree (0.4.4)
|
223
|
-
redis (4.1
|
227
|
+
redis (4.3.1)
|
224
228
|
redis-actionpack (5.2.0)
|
225
229
|
actionpack (>= 5, < 7)
|
226
230
|
redis-rack (>= 2.1.0, < 3)
|
@@ -260,7 +264,7 @@ GEM
|
|
260
264
|
rspec-mocks (~> 3.8.0)
|
261
265
|
rspec-support (~> 3.8.0)
|
262
266
|
rspec-support (3.8.0)
|
263
|
-
ruby2_keywords (0.0.
|
267
|
+
ruby2_keywords (0.0.5)
|
264
268
|
set (1.0.1)
|
265
269
|
slop (4.9.1)
|
266
270
|
sorted_set (1.0.3)
|
data/lib/istox.rb
CHANGED
@@ -27,6 +27,7 @@ module Istox
|
|
27
27
|
require 'istox/helpers/graphql_client'
|
28
28
|
require 'istox/helpers/gruf_listener_hook'
|
29
29
|
require 'istox/helpers/messaging'
|
30
|
+
require 'istox/helpers/race_condition_helper'
|
30
31
|
require 'istox/helpers/blockchain_service'
|
31
32
|
require 'istox/helpers/f_math'
|
32
33
|
require 'istox/helpers/my_open_struct'
|
@@ -47,6 +48,7 @@ module Istox
|
|
47
48
|
|
48
49
|
require 'istox/models/blockchain_receipt'
|
49
50
|
require 'istox/models/concerns/blockchain_receipt_query'
|
51
|
+
require 'istox/models/auto_enum'
|
50
52
|
require 'istox/consumers/blockchain_status_handler'
|
51
53
|
require 'istox/quant/bond'
|
52
54
|
end
|
@@ -30,6 +30,7 @@ module Istox
|
|
30
30
|
request_reason: request_reason,
|
31
31
|
resource_action: action
|
32
32
|
)
|
33
|
+
key = nil
|
33
34
|
|
34
35
|
chainhub_processing = true
|
35
36
|
|
@@ -39,6 +40,10 @@ module Istox
|
|
39
40
|
# execute before proc, and get the model that blockchain receipt should bind to
|
40
41
|
model = before.call(uuid)
|
41
42
|
|
43
|
+
key = model.class.name + '-' + model.id.to_s
|
44
|
+
## for request there we need a lock to prevent there is not duplicate request exist for single model
|
45
|
+
::Istox::RaceConditionHelper.acquire!(key) if is_request
|
46
|
+
|
42
47
|
# delete the previous existing blockchain receipts
|
43
48
|
klass.where(resource_name: model.class.name, resource_id: model.id).destroy_all
|
44
49
|
|
@@ -57,11 +62,14 @@ module Istox
|
|
57
62
|
chainhub_processing = false
|
58
63
|
end
|
59
64
|
end
|
65
|
+
|
66
|
+
::Istox::RaceConditionHelper.release(key) if is_request
|
60
67
|
end
|
61
68
|
|
62
69
|
chainhub_processing
|
63
70
|
rescue StandardError => e
|
64
71
|
receipt&.destroy
|
72
|
+
::Istox::RaceConditionHelper.release(key) if is_request && key.present?
|
65
73
|
raise e
|
66
74
|
end
|
67
75
|
|
@@ -13,7 +13,9 @@ module Istox
|
|
13
13
|
|
14
14
|
result = format("%.#{precision}f", input)
|
15
15
|
|
16
|
-
result.to_s.
|
16
|
+
parts = result.to_s.split('.')
|
17
|
+
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, '\\1,')
|
18
|
+
parts.join('.')
|
17
19
|
end
|
18
20
|
|
19
21
|
# format a money, eg. 20000.134 > SGD 20,000.14, position can be :front or :behind, abs_num: whether to absolute the number
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Istox
|
2
|
+
class RaceConditionHelper
|
3
|
+
class << self
|
4
|
+
def acquire!(key, expired_seconds: 20)
|
5
|
+
result = acquire(key, expired_seconds: expired_seconds)
|
6
|
+
|
7
|
+
raise 'Duplicate request detected, please refresh the page and try again.' if result == false
|
8
|
+
end
|
9
|
+
|
10
|
+
def acquire(key, expired_seconds: 20)
|
11
|
+
result = request_redis.set('race-condition||' + key.to_s, 'EMPTY', nx: true, ex: expired_seconds.to_i.seconds)
|
12
|
+
|
13
|
+
# if result false means the key already exist
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
def release(key)
|
18
|
+
request_redis.del('race-condition||' + key.to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
def request_redis
|
22
|
+
@request_redis ||= ::Istox::RedisManager.request_redis
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Istox
|
2
|
+
module AutoEnum
|
3
|
+
def method_missing(name, *args, &block)
|
4
|
+
if name[-1] == '?' || name[-1] == '!'
|
5
|
+
method_name = name[0...-1]
|
6
|
+
if method_name.parameterize.underscore != method_name
|
7
|
+
send(:"#{method_name}#{name[-1]}")
|
8
|
+
else
|
9
|
+
index = _all_enums_in_underscore.find_index { |e| e == method_name }
|
10
|
+
if index >= 0
|
11
|
+
send(:"#{_all_enums[index]}#{name[-1]}")
|
12
|
+
else
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def respond_to_missing?(name, include_private)
|
22
|
+
if name[-1] == '?' || name[-1] == '!'
|
23
|
+
method_name = name[0...-1]
|
24
|
+
_all_enums_in_underscore.include?(method_name)
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def _all_enums_in_underscore
|
31
|
+
defined_enums.values.map(&:keys).flatten.map { |i| i.parameterize.underscore }
|
32
|
+
end
|
33
|
+
|
34
|
+
def _all_enums
|
35
|
+
defined_enums.values.map(&:keys).flatten
|
36
|
+
end
|
37
|
+
end
|
38
|
+
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.2.
|
4
|
+
version: 0.2.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siong Leng
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|
@@ -495,6 +495,7 @@ files:
|
|
495
495
|
- lib/istox/helpers/order_book_price_time.rb
|
496
496
|
- lib/istox/helpers/order_book_prorate.rb
|
497
497
|
- lib/istox/helpers/publisher.rb
|
498
|
+
- lib/istox/helpers/race_condition_helper.rb
|
498
499
|
- lib/istox/helpers/rate_limit.rb
|
499
500
|
- lib/istox/helpers/redis_boot.rb
|
500
501
|
- lib/istox/helpers/redis_manager.rb
|
@@ -510,6 +511,7 @@ files:
|
|
510
511
|
- lib/istox/helpers/xray/rabbitmq_publisher_interceptor.rb
|
511
512
|
- lib/istox/helpers/xray/xray_initializer.rb
|
512
513
|
- lib/istox/interfaces/chainhub/transaction.rb
|
514
|
+
- lib/istox/models/auto_enum.rb
|
513
515
|
- lib/istox/models/blockchain_receipt.rb
|
514
516
|
- lib/istox/models/concerns/blockchain_receipt_query.rb
|
515
517
|
- lib/istox/quant/bond.rb
|
@@ -517,7 +519,7 @@ files:
|
|
517
519
|
homepage: http://www.abc.com
|
518
520
|
licenses: []
|
519
521
|
metadata: {}
|
520
|
-
post_install_message:
|
522
|
+
post_install_message:
|
521
523
|
rdoc_options: []
|
522
524
|
require_paths:
|
523
525
|
- lib
|
@@ -528,12 +530,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
528
530
|
version: '0'
|
529
531
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
530
532
|
requirements:
|
531
|
-
- - "
|
533
|
+
- - ">="
|
532
534
|
- !ruby/object:Gem::Version
|
533
|
-
version:
|
535
|
+
version: '0'
|
534
536
|
requirements: []
|
535
|
-
rubygems_version: 3.0.
|
536
|
-
signing_key:
|
537
|
+
rubygems_version: 3.0.6
|
538
|
+
signing_key:
|
537
539
|
specification_version: 4
|
538
540
|
summary: istox backend shared gem
|
539
541
|
test_files: []
|