istox 0.1.79.pre.test2 → 0.1.79.pre.test3

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: e176f1517a34a5168750aecc2e64b86d497fcfafdfc03c4b301705009091f344
4
- data.tar.gz: d61f64d0fa7d1792eb8f703a1abf93ff046ac770d7ef8260fadd6bbd5e110bcb
3
+ metadata.gz: e7d19bbdc591b22e6aab3fcd13aab425b5aff45a10ed05f9e6f8cfd032ec24a2
4
+ data.tar.gz: 22a4d2eca2f0b65b43ab98cf4edb5ff1865e6e0fd4724e33f9f5630bff2014ec
5
5
  SHA512:
6
- metadata.gz: 1ef16f8f9c63ed330f34f695aed8cf271bebbff916d702e503fe6f269479bb31e664c960fd4523959924c2de4c689ba38cc29b6b53b81be0eaf54c013650b197
7
- data.tar.gz: 9c51fd8f23dedfb380fdfe12f2a3d529cfdbc03cdace09e5e5f33e2ddd715eec52512d84dfc69a3fcf5b51a4b358d7d9da500e028d3cc1c782709fc977b1162e
6
+ metadata.gz: 40df563acabb16b4aceed611fe28ca8dd841d2ab5ccd8cd3bb55ebec1e3e1e56f65503f5b78094fe40d98c241049a58f6e4549e62947e5c05dd05fea7f7f2166
7
+ data.tar.gz: dc34763eaac873b0698cb59a6d336ae5686aba76b8480b216716346d53cde5eeff09b6a7b0c17597f76d4bd7052963479e1593dd8bdc5442932d31c88cfd8286
data/.rubocop.yml CHANGED
@@ -61,7 +61,7 @@ Metrics/ModuleLength:
61
61
  Max: 200
62
62
 
63
63
  Metrics/LineLength:
64
- Max: 120
64
+ Max: 130
65
65
  # To make it possible to copy or click on URIs in the code, we allow lines
66
66
  # containing a URI to be longer than Max.
67
67
  AllowURI: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.79.pre.test1)
4
+ istox (0.1.79.pre.test3)
5
5
  binding_of_caller
6
6
  bunny (>= 2.12.0)
7
7
  graphlient
@@ -88,7 +88,7 @@ GEM
88
88
  ffi (1.11.1)
89
89
  globalid (0.4.2)
90
90
  activesupport (>= 4.2.0)
91
- google-protobuf (3.9.1)
91
+ google-protobuf (3.9.1-universal-darwin)
92
92
  googleapis-common-protos-types (1.0.4)
93
93
  google-protobuf (~> 3.0)
94
94
  graphlient (0.3.6)
@@ -99,7 +99,7 @@ GEM
99
99
  graphql-client (0.15.0)
100
100
  activesupport (>= 3.0)
101
101
  graphql (~> 1.8)
102
- grpc (1.23.0)
102
+ grpc (1.23.0-universal-darwin)
103
103
  google-protobuf (~> 3.8)
104
104
  googleapis-common-protos-types (~> 1.0)
105
105
  grpc-tools (1.23.0)
data/lib/istox.rb CHANGED
@@ -1,32 +1,34 @@
1
1
  require 'active_record'
2
2
  require 'paranoia'
3
- require "gruf"
4
- require "listen"
5
- require "istox/version"
3
+ require 'gruf'
4
+ require 'listen'
5
+ require 'istox/version'
6
6
 
7
7
  module Istox
8
8
  # Your code goes here...
9
9
  class Test
10
10
  def self.method1
11
- "abc"
11
+ 'abc'
12
12
  end
13
13
  end
14
14
 
15
- require "istox/interfaces/chainhub/transaction"
16
- require "istox/helpers/publisher"
17
- require "istox/helpers/bunny_boot"
18
- require "istox/helpers/vault"
19
- require "istox/helpers/order_book"
20
- require "istox/helpers/grpc_client"
21
- require "istox/helpers/graphql_client"
22
- require "istox/helpers/gruf_listener_hook"
23
- require "istox/helpers/message_service"
24
- require "istox/helpers/blockchain_service"
25
- require "istox/helpers/f_math"
26
- require "istox/models/blockchain_receipt"
27
- require "istox/models/concerns/blockchain_receipt_query"
28
- require "istox/consumers/blockchain_status_handler"
29
- require "istox/migrations/create_blockchain_receipts"
30
- require "istox/logging/hash_logging"
31
- require "istox/logging/log_formatter"
15
+ require 'istox/interfaces/chainhub/transaction'
16
+ require 'istox/helpers/publisher'
17
+ require 'istox/helpers/bunny_boot'
18
+ require 'istox/helpers/vault'
19
+ require 'istox/helpers/order_book'
20
+ require 'istox/helpers/grpc_client'
21
+ require 'istox/helpers/graphql_client'
22
+ require 'istox/helpers/gruf_listener_hook'
23
+ require 'istox/helpers/message_service'
24
+ require 'istox/helpers/blockchain_service'
25
+ require 'istox/helpers/f_math'
26
+ require 'istox/helpers/my_open_struct'
27
+ require 'istox/helpers/common_helper'
28
+ require 'istox/models/blockchain_receipt'
29
+ require 'istox/models/concerns/blockchain_receipt_query'
30
+ require 'istox/consumers/blockchain_status_handler'
31
+ require 'istox/migrations/create_blockchain_receipts'
32
+ require 'istox/logging/hash_logging'
33
+ require 'istox/logging/log_formatter'
32
34
  end
@@ -0,0 +1,69 @@
1
+ module Istox
2
+ module CommonHelper
3
+ def self.to_open_struct(model)
4
+ return nil if model.blank?
5
+
6
+ if model.is_a?(Array)
7
+ model.map do |item|
8
+ hash = deep_to_h(item).deep_transform_keys { |key| key.to_s.underscore.to_sym }
9
+ process_hash(nil, hash)
10
+ to_recursive_ostruct(hash)
11
+ end
12
+ else
13
+ hash = deep_to_h(model).deep_transform_keys { |key| key.to_s.underscore.to_sym }
14
+ process_hash(nil, hash)
15
+ to_recursive_ostruct(hash)
16
+ end
17
+ end
18
+
19
+ def self.process_hash(_parent, my_hash)
20
+ my_hash.each do |key, value|
21
+ if value.is_a?(Hash)
22
+ process_hash(key, value)
23
+ elsif value.is_a?(Array)
24
+ my_hash[key] = value.map do |item|
25
+ process_hash(nil, item.to_h)
26
+ end
27
+ else
28
+ my_hash[key] = value
29
+ end
30
+ end
31
+ end
32
+
33
+ # def self.add_methods(ostruct)
34
+ # hashmap = ostruct.to_h
35
+
36
+ # hashmap&.each do |k, _v|
37
+ # # add_method k.to_s do
38
+ # ostruct.send(k.to_s)
39
+ # # end
40
+ # end
41
+ # end
42
+
43
+ def self.to_recursive_ostruct(hash)
44
+ ::Istox::MyOpenStruct.new(hash.each_with_object({}) do |(key, val), memo|
45
+ memo[key] = if val.is_a?(Hash)
46
+ to_open_struct(val)
47
+ elsif val.is_a?(Array)
48
+ val.map do |item|
49
+ to_open_struct(item)
50
+ end
51
+ else
52
+ val
53
+ end
54
+ end)
55
+ end
56
+
57
+ def add_method(name, &block)
58
+ (class << self; self; end).class_eval do
59
+ define_method name, &block
60
+ end
61
+ end
62
+
63
+ def self.deep_to_h(obj)
64
+ obj.to_h.transform_values do |v|
65
+ v.is_a?(OpenStruct) ? deep_to_h(v) : v
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,35 +1,35 @@
1
- require "graphlient"
1
+ require 'graphlient'
2
2
 
3
3
  module Istox
4
4
  class GraphqlClient
5
- class << self
6
- def add_host(host_type, url)
7
- unless defined?(@@hosts)
8
- @@hosts = {}
9
- end
10
- init_host(host_type, url)
11
- end
12
-
13
- def query(host_type, query, variables = {})
14
- client = @@hosts[host_type]
15
-
16
- raise "Please make sure you have initialised graphql cient for host #{host_type}" if !client
17
-
18
- Rails.logger.info "Querying Graphql host: #{host_type}, query: #{query}, variables: #{variables.inspect}"
19
- result = client.query(query, variables)
20
- Rails.logger.info "Graphql result: #{result.inspect}"
21
-
22
- return result
23
- end
24
-
25
- private
26
-
27
- def init_host(host_type, url)
28
- client = Graphlient::Client.new(url, http: Graphlient::Adapters::HTTP::HTTPAdapter)
29
-
30
- @@hosts[host_type] = client
31
- end
5
+ class << self
6
+ def add_host(host_type, url)
7
+ @@hosts = {} unless defined?(@@hosts)
8
+ init_host(host_type, url)
9
+ end
10
+
11
+ def query(host_type, query, variables = {})
12
+ client = @@hosts[host_type]
13
+
14
+ raise "Please make sure you have initialised graphql cient for host #{host_type}" unless client
15
+
16
+ Rails.logger.info "Querying Graphql host: #{host_type}, query: #{query}, variables: #{variables.inspect}"
17
+ result = client.query(query, variables)
18
+
19
+ return_values = ::Istox::CommonHelper.to_open_struct(result)
20
+
21
+ Rails.logger.info "Graphql result: #{return_values.inspect}"
22
+
23
+ return_values
24
+ end
25
+
26
+ private
27
+
28
+ def init_host(host_type, url)
29
+ client = Graphlient::Client.new(url, http: Graphlient::Adapters::HTTP::HTTPAdapter)
32
30
 
31
+ @@hosts[host_type] = client
33
32
  end
33
+ end
34
34
  end
35
- end
35
+ end
@@ -1,66 +1,63 @@
1
1
  module Istox
2
- class GrpcClient
3
- class << self
4
- def add_host(host_type, url)
5
- unless defined?(@@hosts)
6
- @@hosts = {}
7
- end
2
+ class GrpcClient
3
+ class << self
4
+ def add_host(host_type, url)
5
+ @@hosts = {} unless defined?(@@hosts)
8
6
 
9
- @@hosts[host_type] = url
10
- end
7
+ @@hosts[host_type] = url
8
+ end
11
9
 
12
- def call(host_type, service, method, **keyword_args)
13
- execute(host_type, service, method, **keyword_args)
14
- # rescue => e
15
- # reinitiate service and try again, second chance
16
- # reinitiate_service(host_type, service)
17
- # execute(host_type, service, method, **keyword_args)
18
- end
19
-
20
- private
10
+ def call(host_type, service, method, **keyword_args)
11
+ execute(host_type, service, method, **keyword_args)
12
+ # rescue => e
13
+ # reinitiate service and try again, second chance
14
+ # reinitiate_service(host_type, service)
15
+ # execute(host_type, service, method, **keyword_args)
16
+ end
21
17
 
22
- def execute(host_type, service, method, **keyword_args)
23
- Rails.logger.info "Calling method in grpc method: #{method.inspect}, params: #{keyword_args.inspect}"
24
- t1 = Time.now
25
-
26
- result = get_host(host_type, service).call(method, keyword_args)
27
- Rails.logger.info "Time taken for grpc execution: #{Time.now - t1} seconds"
28
- Rails.logger.info "Result: #{result.message.inspect}"
29
- result
30
- end
18
+ private
31
19
 
32
- def get_host(host_type, service)
33
- unless defined?(@@services)
34
- @@services = {}
35
- end
20
+ def execute(host_type, service, method, **keyword_args)
21
+ Rails.logger.info "Calling method in grpc method: #{method.inspect}, params: #{keyword_args.inspect}"
22
+ t1 = Time.now
36
23
 
37
- grpc_client = @@services[get_key(host_type, service)]
24
+ result = get_host(host_type, service).call(method, keyword_args)
25
+ Rails.logger.info "Time taken for grpc execution: #{Time.now - t1} seconds"
38
26
 
39
- if grpc_client
40
- return grpc_client
41
- else
42
- reinitiate_service(host_type, service)
43
- return @@services[get_key(host_type, service)]
44
- end
45
- end
27
+ return_values = ::Istox::CommonHelper.to_open_struct(result.message)
28
+ Rails.logger.info "Result: #{return_values}"
46
29
 
47
- def reinitiate_service(host_type, service)
48
- unless defined?(@@services)
49
- @@services = {}
50
- end
30
+ return_values
31
+ end
51
32
 
52
- host_url = @@hosts[host_type]
53
- raise StandardError, 'Unable to find host, have you forgotten to add host to grpc client?' if !host_url
54
-
55
- Rails.logger.info 'Reinitiating to grpc host at ' + host_url
56
- t1 = Time.now
57
- @@services[get_key(host_type, service)] = ::Gruf::Client.new(service: service, options: { hostname: host_url })
58
- Rails.logger.info "Time taken for reinitiating grpc host: #{Time.now - t1} seconds"
59
- end
33
+ def get_host(host_type, service)
34
+ @@services = {} unless defined?(@@services)
60
35
 
61
- def get_key(host_type, service)
62
- host_type.to_s + service.to_s
63
- end
36
+ grpc_client = @@services[get_key(host_type, service)]
37
+
38
+ if grpc_client
39
+ return grpc_client
40
+ else
41
+ reinitiate_service(host_type, service)
42
+ return @@services[get_key(host_type, service)]
64
43
  end
44
+ end
45
+
46
+ def reinitiate_service(host_type, service)
47
+ @@services = {} unless defined?(@@services)
48
+
49
+ host_url = @@hosts[host_type]
50
+ raise StandardError, 'Unable to find host, have you forgotten to add host to grpc client?' unless host_url
51
+
52
+ Rails.logger.info 'Reinitiating to grpc host at ' + host_url
53
+ t1 = Time.now
54
+ @@services[get_key(host_type, service)] = ::Gruf::Client.new(service: service, options: { hostname: host_url })
55
+ Rails.logger.info "Time taken for reinitiating grpc host: #{Time.now - t1} seconds"
56
+ end
57
+
58
+ def get_key(host_type, service)
59
+ host_type.to_s + service.to_s
60
+ end
65
61
  end
66
- end
62
+ end
63
+ end
@@ -0,0 +1,7 @@
1
+ module Istox
2
+ class MyOpenStruct < OpenStruct
3
+ def to_json(*_args)
4
+ to_h.to_json
5
+ end
6
+ end
7
+ end
data/lib/istox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.79-test2'.freeze
2
+ VERSION = '0.1.79-test3'.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.test2
4
+ version: 0.1.79.pre.test3
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-09-01 00:00:00.000000000 Z
11
+ date: 2019-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -292,11 +292,13 @@ files:
292
292
  - lib/istox/consumers/blockchain_status_handler.rb
293
293
  - lib/istox/helpers/blockchain_service.rb
294
294
  - lib/istox/helpers/bunny_boot.rb
295
+ - lib/istox/helpers/common_helper.rb
295
296
  - lib/istox/helpers/f_math.rb
296
297
  - lib/istox/helpers/graphql_client.rb
297
298
  - lib/istox/helpers/grpc_client.rb
298
299
  - lib/istox/helpers/gruf_listener_hook.rb
299
300
  - lib/istox/helpers/message_service.rb
301
+ - lib/istox/helpers/my_open_struct.rb
300
302
  - lib/istox/helpers/order_book.rb
301
303
  - lib/istox/helpers/publisher.rb
302
304
  - lib/istox/helpers/vault.rb