stellar_base-rails 0.2.0 → 0.2.1

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: 86c1a220ccc8dec7052bd575a4fbdc8b477ef714a8e99c0ba0f1d08ccd8e92ff
4
- data.tar.gz: eb4b64fe63c1d8602ff823496d24da6793acbdb2e540665c0d4097e0e0267947
3
+ metadata.gz: ecd5d5fc63b0d3fc23adafd92a5e330c1ae47949bc410898565a9efdb4f6726f
4
+ data.tar.gz: 3d7f60859d18ab5376070d7ec7fbc1281ddc4ff8708927221f146978fe2c96e4
5
5
  SHA512:
6
- metadata.gz: be387cda44d420b25fc46f98f0e786cb1a74f38ae15020d658f86979575cd78ba3be480a785813f625cc930d176a72b21c29a1aa33cc3ab44c2f32f1e422ea48
7
- data.tar.gz: 84ea52aea9cb4e759e1236f18909af28972e9d163c5c6dc03f0790308ce75e7b0cb8369690a5e12d7e2b96a27f06254fe38c24aafd46d287a7a1327f9fb56d4d
6
+ metadata.gz: 9fc6a3115718edb85a4a9e43ff75141d96720514e49c2f41a9dae261b29d2f1a1ddc8979d8ef80cf0c871185fefb469c9ac38f23a279997f7b3105890a8b3ad8
7
+ data.tar.gz: 9d8ed4542c4f85231f68ada991cecbe6e5895d3f2f2590dadf4bba0102822b061d50906f8124531199e405712c5334b63e45e52b433628fb60c97aa7f5041763
@@ -14,6 +14,11 @@ module StellarBase
14
14
  property :data
15
15
  property :transaction_id
16
16
 
17
+ validates :id, presence: true
18
+ validates :transaction_id, presence: true
19
+ validates :from, presence: true
20
+ validates :amount, presence: true
21
+
17
22
  validate :check_callback_authenticity
18
23
 
19
24
  def check_callback_authenticity
@@ -10,6 +10,7 @@ module StellarBase
10
10
  if op.success?
11
11
  head :ok
12
12
  else
13
+ log_unsuccessful_callback(op)
13
14
  head :unprocessable_entity
14
15
  end
15
16
  end
@@ -18,6 +19,13 @@ module StellarBase
18
19
 
19
20
  private
20
21
 
22
+ def log_unsuccessful_callback(op)
23
+ Rails.logger.warn("Unsuccessful bridge callback #{callback_params.to_s}")
24
+
25
+ error_messages = op["contract.default"].errors.full_messages
26
+ Rails.logger.warn("Details: #{error_messages}")
27
+ end
28
+
21
29
  def callback_params
22
30
  params.permit(
23
31
  :id,
@@ -8,6 +8,7 @@ module StellarBase
8
8
  InitializeHorizonClient,
9
9
  GetOperation,
10
10
  GetTransaction,
11
+ Compare,
11
12
  )
12
13
  end
13
14
 
@@ -0,0 +1,45 @@
1
+ module StellarBase
2
+ module BridgeCallbacks
3
+ class Compare
4
+ extend LightService::Action
5
+ expects :operation_response, :transaction_response, :params
6
+
7
+ executed do |c|
8
+ operation = c.operation_response
9
+ transaction = c.transaction_response
10
+
11
+ # TODO: implement route check if Compliance server is available
12
+ hash = {
13
+ id: operation["id"],
14
+ from: operation["source_account"],
15
+ amount: operation["amount"],
16
+ route: transaction["memo"],
17
+ asset_code: transaction["asset_code"],
18
+ asset_issuer: transaction["asset_issuer"],
19
+ memo: transaction["memo"],
20
+ memo_type: transaction["memo_type"],
21
+ transaction_id: transaction["id"],
22
+ }
23
+
24
+ result = compare(hash, c.params)
25
+
26
+ if result.any?
27
+ message = [result.join(", "), "value isn't the same"].join(" ")
28
+ elsif transaction["id"] != operation["transaction_hash"]
29
+ message = "Operation#transaction_id and transaction_id not the same"
30
+ end
31
+
32
+ c.fail_and_return! message if message.present?
33
+ end
34
+
35
+ def self.compare(hash, params)
36
+ # TODO: implement data comparison
37
+ params.except!(:data)
38
+
39
+ params.keys.map do |param_key|
40
+ param_key if params[param_key] != hash[param_key].to_s
41
+ end.compact
42
+ end
43
+ end
44
+ end
45
+ end
@@ -6,6 +6,8 @@ module StellarBase
6
6
  promises :operation_response
7
7
 
8
8
  executed do |c|
9
+ c.fail_and_return! unless c.operation_id.present?
10
+
9
11
  id = c.operation_id
10
12
  response = c.client.get_operation(id)
11
13
 
@@ -6,6 +6,8 @@ module StellarBase
6
6
  promises :transaction_response
7
7
 
8
8
  executed do |c|
9
+ c.fail_and_return! unless c.transaction_id.present?
10
+
9
11
  id = c.transaction_id
10
12
  response = c.client.get_transaction(id)
11
13
 
@@ -1,3 +1,3 @@
1
1
  module StellarBase
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar_base-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Subido
@@ -203,6 +203,7 @@ files:
203
203
  - app/models/stellar_base/application_record.rb
204
204
  - app/models/stellar_base/bridge_callback.rb
205
205
  - app/services/stellar_base/bridge_callbacks/check.rb
206
+ - app/services/stellar_base/bridge_callbacks/compare.rb
206
207
  - app/services/stellar_base/bridge_callbacks/get_operation.rb
207
208
  - app/services/stellar_base/bridge_callbacks/get_transaction.rb
208
209
  - app/services/stellar_base/bridge_callbacks/initialize_horizon_client.rb