stellar_base-rails 3.1.0 → 4.0.0

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: 74b62f61385eba2ad71a788469192da7d9056875055582a17c38e982688f0bfc
4
- data.tar.gz: 37012d044e08a99b22116cfc54b243a27440721ed4a26eee198c022d10d327c8
3
+ metadata.gz: cff5f415f6a47273028b4ca3624b7438ee2eb31e0ca815869919c0e0636abda9
4
+ data.tar.gz: c489e059fb3c85dc83ac5ade58252f5c342b2a09c67971dfda3eb2c4f7cf8451
5
5
  SHA512:
6
- metadata.gz: 2868b757d5cea6de7ca3a25e9d4f3131f029954f07a2f995b674c858fb6602b00c041a1877176d1c9f106a8d2e543ef2cbd608129e116caa9b9fd01f3f2703ee
7
- data.tar.gz: 54ef4814eb47f06e8d7148b4f6eaf1d68b0ba89d64b38d56b2af169b957e7962a2009cfffaf203c6ad918e6088eb1cd78507b043c4bdf12e5149f60033fbe26e
6
+ metadata.gz: 75a2497469d514931e412bc328d52a8193ce7275d2fddf484c87003a864ffde59c069e54d05e74bb64c21fd23667bd1671a56d9afc5bd9469f6ff4f42e3432be
7
+ data.tar.gz: d194dabc8981366ffd174ca1e3f34f5859f47f7b6ea9f9bf9e575e64c21d14b4a845c4acc15f5b1b29e14b898cd54d3cda7b0912b1103345956cec92ec2e3acf
data/README.md CHANGED
@@ -102,6 +102,8 @@ gem 'stellar_base-rails'
102
102
  And then execute:
103
103
  ```bash
104
104
  $ bundle
105
+ $ rails stellar_base:install:migrations
106
+ $ rails db:migrate
105
107
  ```
106
108
 
107
109
  If you're using `StellarBase.on_deposit_trigger` you'll need to install:
@@ -54,8 +54,7 @@ module StellarBase
54
54
  options["model"].min_amount = 0.0
55
55
 
56
56
  # Make Deposits free unless we want it configured
57
- #
58
- # TODO: this should come from `CallFeeFrom.(details[:fee_from)`
57
+ # TODO: this should come from `CallDepositFeeFrom.(params, details)`
59
58
  options["model"].fee_fixed = details[:fee_fixed] || 0.0
60
59
  options["model"].fee_percent = details[:fee_percent] || 0.0
61
60
  end
@@ -29,9 +29,9 @@ module StellarBase
29
29
  end
30
30
 
31
31
  def set_fee_response!(options, model:, asset_details:, params:, **)
32
- model.fee_response = FeeRequests::CallFeeFrom.(
32
+ model.fee_response = FeeRequests::CallWithdrawFeeFixedQuoteFrom.(
33
33
  fee_request: model,
34
- fee_from: asset_details[:fee_from],
34
+ fee_fixed_quote_from: asset_details[:fee_fixed_quote_from],
35
35
  )
36
36
  end
37
37
 
@@ -7,16 +7,17 @@ module StellarBase
7
7
  property :asset_code
8
8
  property :dest
9
9
  property :dest_extra
10
- property :fee_network
10
+ property :fee_fixed
11
11
 
12
12
  validates(
13
13
  :asset_type,
14
14
  :asset_code,
15
15
  :dest,
16
- :fee_network,
16
+ :fee_fixed,
17
17
  presence: true,
18
18
  )
19
19
  validate :check_valid_asset_code
20
+ validates(:fee_fixed, numericality: {greater_than_or_equal_to: 0})
20
21
 
21
22
  def check_valid_asset_code
22
23
  asset_codes = StellarBase.configuration.withdrawable_assets
@@ -10,10 +10,11 @@ module StellarBase
10
10
  failure :set_policy_error!
11
11
  step Model(WithdrawalRequest, :new)
12
12
  step :setup_params!
13
+ step :find_withdrawal_asset_details!
14
+ step :set_fee_fixed!
13
15
  step Contract::Build(constant: Contracts::Create)
14
16
  step Contract::Validate(key: :withdrawal_request)
15
17
  step Contract::Persist(method: :sync)
16
- step :find_withdrawal_asset_details!
17
18
  success :set_defaults!
18
19
  step Contract::Persist(method: :save)
19
20
 
@@ -29,38 +30,26 @@ module StellarBase
29
30
  })
30
31
  end
31
32
 
32
- def find_withdrawal_asset_details!(options, params:, **)
33
- details = FindWithdrawableAsset
34
- .(params[:withdrawal_request][:asset_code])
35
- params[:withdrawal_asset_details] = details.presence || {}
33
+ def find_withdrawal_asset_details!(ctx, params:, **)
34
+ asset_code = params[:withdrawal_request][:asset_code]
35
+ details = FindWithdrawableAsset.(asset_code)
36
+ ctx["asset_details"] = details.presence || {}
36
37
  end
37
38
 
38
- def set_defaults!(options, params:, **)
39
- withdrawal_asset_details = params[:withdrawal_asset_details]
40
-
41
- fee_network = DetermineFee.network(
42
- withdrawal_asset_details[:network],
43
- params[:withdrawal_request][:fee_network],
44
- )
45
-
46
- options["model"].issuer = withdrawal_asset_details[:issuer]
47
- options["model"].account_id =
48
- StellarBase.configuration.distribution_account
49
- options["model"].memo_type = "text"
50
- options["model"].memo = GenMemoFor.(WithdrawalRequest)
51
- options["model"].eta = DEFAULT_ETA
52
- options["model"].min_amount = 0.0
53
- options["model"].max_amount =
54
- DetermineMaxAmount.(withdrawal_asset_details[:max_amount_from])
55
-
56
- # TODO: This should come from `CallFeeFrom.(details[:fee_from])`
57
- # or dest_extra
58
- options["model"].fee_fixed =
59
- DetermineFee.(withdrawal_asset_details[:fee_fixed])
39
+ def set_fee_fixed!(ctx, params:, asset_details:, **)
40
+ params[:withdrawal_request][:fee_fixed] =
41
+ CallFeeFixedFrom.(params[:withdrawal_request], asset_details)
42
+ end
60
43
 
61
- options["model"].fee_percent =
62
- DetermineFee.(withdrawal_asset_details[:fee_percent])
63
- options["model"].fee_network = fee_network
44
+ def set_defaults!(options, params:, asset_details:, model:, **)
45
+ model.issuer = asset_details[:issuer]
46
+ model.account_id = StellarBase.configuration.distribution_account
47
+ model.memo_type = "text"
48
+ model.memo = GenMemoFor.(WithdrawalRequest)
49
+ model.eta = DEFAULT_ETA
50
+ model.min_amount = 0.0
51
+ model.max_amount = DetermineMaxAmount.(asset_details[:max_amount_from])
52
+ model.fee_percent = DetermineFee.(asset_details[:fee_percent])
64
53
  end
65
54
 
66
55
  end
@@ -25,7 +25,6 @@ module StellarBase
25
25
  :asset_code,
26
26
  :dest,
27
27
  :dest_extra,
28
- :fee_network,
29
28
  :type,
30
29
  ).to_hash.with_indifferent_access
31
30
  end
@@ -8,7 +8,6 @@ module StellarBase
8
8
  property :max_amount
9
9
  property :fee_fixed
10
10
  property :fee_percent
11
- property :fee_network
12
11
  property :extra_info
13
12
 
14
13
  end
@@ -9,8 +9,7 @@ module StellarBase
9
9
 
10
10
  def self.callback_class
11
11
  on_bridge_callback = StellarBase.configuration.on_bridge_callback
12
- return on_bridge_callback if on_bridge_callback.respond_to?(:call)
13
- on_bridge_callback.constantize
12
+ GetCallbackFrom.(on_bridge_callback)
14
13
  rescue NameError
15
14
  error_message = [
16
15
  "StellarBase.on_bridge_callback isn't configured or the",
@@ -5,7 +5,10 @@ module StellarBase
5
5
 
6
6
  def self.call(class_name)
7
7
  # TODO: how do we handle errors
8
- return class_name.constantize.send(:call) if class_name.present?
8
+ if class_name.present?
9
+ callback = GetCallbackFrom.(class_name)
10
+ return callback.send(:call)
11
+ end
9
12
  DEFAULT
10
13
  end
11
14
 
@@ -7,11 +7,12 @@ module StellarBase
7
7
  def self.call(class_name, params)
8
8
  # TODO: how do we handle errors
9
9
  if class_name.present?
10
- unless class_name.constantize.method(:call).arity.zero?
11
- return class_name.constantize.send(:call, params)
10
+ callback = GetCallbackFrom.(class_name)
11
+ unless callback.method(:call).arity.zero?
12
+ return callback.send(:call, params)
12
13
  end
13
14
 
14
- return class_name.constantize.send(:call)
15
+ return callback.send(:call)
15
16
  end
16
17
  DEFAULT
17
18
  end
@@ -0,0 +1,42 @@
1
+ module StellarBase
2
+ module FeeRequests
3
+ class CallWithdrawFeeFixedQuoteFrom
4
+
5
+ FEE_FIXED_QUOTE_FROM_ERROR = "`fee_fixed_quote_from` must be a string of an object " \
6
+ "that responds to `.call` or the object itself".freeze
7
+
8
+ def self.call(fee_request:, fee_fixed_quote_from:)
9
+ asset_details = asset_details_from(fee_request)
10
+
11
+ if fee = asset_details[:fee_fixed]
12
+ return fee
13
+ end
14
+
15
+ return 0.0 if fee_fixed_quote_from.nil?
16
+
17
+ callback = callback_from(fee_fixed_quote_from)
18
+ callback.(fee_request)
19
+ end
20
+
21
+ def self.callback_from(fee_fixed_quote_from)
22
+ fee_fixed_quote_from = GetCallbackFrom.(fee_fixed_quote_from)
23
+
24
+ if !fee_fixed_quote_from.respond_to?(:call)
25
+ fail ArgumentError, FEE_FIXED_QUOTE_FROM_ERROR
26
+ end
27
+
28
+ fee_fixed_quote_from
29
+ end
30
+
31
+ private
32
+
33
+ def self.asset_details_from(fee_request)
34
+ FindAssetDetails.(
35
+ operation: "withdraw",
36
+ asset_code: fee_request.asset_code,
37
+ )
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,13 @@
1
+ module StellarBase
2
+ class GetCallbackFrom
3
+
4
+ def self.call(callback)
5
+ if callback.respond_to?(:constantize)
6
+ callback = callback.constantize
7
+ end
8
+
9
+ callback
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module StellarBase
2
+ module WithdrawalRequests
3
+ class CallFeeFixedFrom
4
+
5
+ CALLBACK_CONFIG_NAME = :fee_fixed_from
6
+ INVALID_FEE_MESSAGE =
7
+ "`fee_fixed_from` must return a value >= 0".freeze
8
+
9
+ def self.call(params, asset_details)
10
+ if fee_fixed = asset_details[:fee_fixed]
11
+ return fee_fixed
12
+ end
13
+
14
+ callback = GetCallbackFrom.(asset_details[CALLBACK_CONFIG_NAME])
15
+
16
+ return 0.0 if callback.nil?
17
+
18
+ fee_fixed = callback.(params, asset_details)
19
+
20
+ if fee_fixed.nil?
21
+ fail ArgumentError, INVALID_FEE_MESSAGE
22
+ end
23
+
24
+ fee_fixed
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -15,9 +15,7 @@ module StellarBase
15
15
  end
16
16
 
17
17
  def self.callback_from(on_withdraw)
18
- if on_withdraw.respond_to?(:constantize)
19
- on_withdraw = on_withdraw.constantize
20
- end
18
+ on_withdraw = GetCallbackFrom.(on_withdraw)
21
19
 
22
20
  if !on_withdraw.respond_to?(:call)
23
21
  fail ArgumentError, ON_WITHDRAW_ERROR
@@ -5,8 +5,8 @@ module StellarBase
5
5
  DEFAULT = nil
6
6
 
7
7
  def self.call(class_name)
8
- return class_name.constantize.send(:call) if class_name.present?
9
- DEFAULT
8
+ return DEFAULT if class_name.blank?
9
+ GetCallbackFrom.(class_name).()
10
10
  end
11
11
 
12
12
  end
@@ -8,7 +8,6 @@ module StellarBase
8
8
  property :max_amount
9
9
  property :fee_fixed
10
10
  property :fee_percent
11
- property :fee_network
12
11
  property :extra_info
13
12
 
14
13
  end
@@ -0,0 +1,8 @@
1
+ class RemoveFeeNetwork < ActiveRecord::Migration[5.2]
2
+ def change
3
+ remove_column(:stellar_base_withdrawal_requests, :fee_network, :decimal, {
4
+ default: "0.0",
5
+ null: false,
6
+ })
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module StellarBase
2
- VERSION = "3.1.0".freeze
2
+ VERSION = "4.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar_base-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Subido
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-07 00:00:00.000000000 Z
11
+ date: 2019-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: disposable
@@ -496,13 +496,15 @@ files:
496
496
  - app/services/stellar_base/deposit_requests/send_asset.rb
497
497
  - app/services/stellar_base/deposit_requests/trigger.rb
498
498
  - app/services/stellar_base/deposit_requests/update_deposit.rb
499
- - app/services/stellar_base/fee_requests/call_fee_from.rb
499
+ - app/services/stellar_base/fee_requests/call_withdraw_fee_fixed_quote_from.rb
500
500
  - app/services/stellar_base/find_asset_details.rb
501
501
  - app/services/stellar_base/gen_memo_for.rb
502
502
  - app/services/stellar_base/gen_random_string.rb
503
+ - app/services/stellar_base/get_callback_from.rb
503
504
  - app/services/stellar_base/init_asset_sending_client.rb
504
505
  - app/services/stellar_base/init_stellar_client.rb
505
506
  - app/services/stellar_base/subscribe_account.rb
507
+ - app/services/stellar_base/withdrawal_requests/call_fee_fixed_from.rb
506
508
  - app/services/stellar_base/withdrawal_requests/call_on_withdraw.rb
507
509
  - app/services/stellar_base/withdrawal_requests/determine_fee.rb
508
510
  - app/services/stellar_base/withdrawal_requests/determine_max_amount.rb
@@ -523,6 +525,7 @@ files:
523
525
  - db/migrate/20181003072138_create_stellar_base_account_subscriptions.rb
524
526
  - db/migrate/20181210043919_add_unique_index_to_deposits.rb
525
527
  - db/migrate/20181217090323_create_stellar_transactions_and_operations.rb
528
+ - db/migrate/20190808014913_remove_fee_network.rb
526
529
  - lib/stellar_base-rails.rb
527
530
  - lib/stellar_base.rb
528
531
  - lib/stellar_base/engine.rb
@@ -1,28 +0,0 @@
1
- module StellarBase
2
- module FeeRequests
3
- class CallFeeFrom
4
-
5
- FEE_FROM_ERROR = "`fee_from` must be a string of an object " \
6
- "that responds to `.call` or the object itself".freeze
7
-
8
- def self.call(fee_request:, fee_from:)
9
- return 0 if fee_from.nil?
10
- callback = callback_from(fee_from)
11
- callback.(fee_request)
12
- end
13
-
14
- def self.callback_from(fee_from)
15
- if fee_from.respond_to?(:constantize)
16
- fee_from = fee_from.constantize
17
- end
18
-
19
- if !fee_from.respond_to?(:call)
20
- fail ArgumentError, FEE_FROM_ERROR
21
- end
22
-
23
- fee_from
24
- end
25
-
26
- end
27
- end
28
- end