stellar_base-rails 0.9.6 → 0.10.0
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 +4 -4
- data/app/concepts/stellar_base/balances/balances_policy.rb +15 -0
- data/app/concepts/stellar_base/balances/contracts/show.rb +28 -0
- data/app/concepts/stellar_base/balances/operations/show.rb +39 -0
- data/app/controllers/stellar_base/balances_controller.rb +39 -0
- data/app/models/stellar_base/balance.rb +17 -0
- data/app/representers/stellar_base/balance_representer.rb +8 -0
- data/config/routes.rb +1 -0
- data/lib/stellar_base/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6677436084a32e990d54bd12bd420fb59962e1fb89cb7dd23c54c26a2f347095
|
4
|
+
data.tar.gz: a7d9291dd36fa0778b4c107484b7e423deb9436ca1a45cb7d7e5a7f8d14a05b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b868d78007d88685e684881286d10712455f273e46f676d29734ee38e7667f9a037daacc17b7759c953714cf712eb795ee452ab65297df591c4710656625d7d
|
7
|
+
data.tar.gz: '06744869debd5c6d71fd38b92e9d2e77bdf8cc65cc8282bd01b6b594591ccd09ceb49e447efc2f5da6eea5ca090fe65ef59e69ce56f37f23853f4e7335407ea5'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module StellarBase
|
2
|
+
module Balances
|
3
|
+
module Contracts
|
4
|
+
class Show < ApplicationContract
|
5
|
+
|
6
|
+
property :asset_code
|
7
|
+
|
8
|
+
validates :asset_code, presence: true
|
9
|
+
validate :check_valid_asset_code
|
10
|
+
|
11
|
+
def check_valid_asset_code
|
12
|
+
asset_codes = StellarBase.configuration.withdrawable_assets
|
13
|
+
&.map do |asset|
|
14
|
+
asset[:asset_code]
|
15
|
+
end
|
16
|
+
|
17
|
+
return if asset_codes.include? asset_code
|
18
|
+
|
19
|
+
errors.add(
|
20
|
+
:asset_code,
|
21
|
+
"invalid asset_code. Valid asset_codes: #{asset_codes.join(', ')}",
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module StellarBase
|
2
|
+
module Balances
|
3
|
+
module Operations
|
4
|
+
class Show < ApplicationOperation
|
5
|
+
|
6
|
+
step self::Policy::Pundit(BalancesPolicy, :show?)
|
7
|
+
failure :set_policy_error!
|
8
|
+
step :setup_model!
|
9
|
+
step Contract::Build(constant: Contracts::Show)
|
10
|
+
step Contract::Validate(key: :balance)
|
11
|
+
step Contract::Persist(method: :sync)
|
12
|
+
step :find_asset_details!
|
13
|
+
success :set_amount!
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def setup_model!(options)
|
18
|
+
options["model"] = Balance.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_policy_error!(options, params:, **)
|
22
|
+
options["result.policy.message"] = "Not authorized to check balances"
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_asset_details!(options, params:, **)
|
26
|
+
details = WithdrawalRequests::FindWithdrawableAsset
|
27
|
+
.(params[:balance][:asset_code])
|
28
|
+
options[:asset_details] = details.presence || {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_amount!(options, asset_details:, params:, **)
|
32
|
+
options["model"].amount = WithdrawalRequests::DetermineMaxAmount
|
33
|
+
.(asset_details[:max_amount_from])
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module StellarBase
|
2
|
+
class BalancesController < ApplicationController
|
3
|
+
|
4
|
+
def show
|
5
|
+
op = Balances::Operations::Show.(balance: balance_params)
|
6
|
+
|
7
|
+
respond_to do |f|
|
8
|
+
f.json do
|
9
|
+
if op.success?
|
10
|
+
representer = BalanceRepresenter.new(op["model"])
|
11
|
+
render json: representer
|
12
|
+
else
|
13
|
+
render(
|
14
|
+
json: errors_from(op),
|
15
|
+
status: :unprocessable_entity,
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def errors_from(op)
|
25
|
+
unless op["result.policy.default"].success?
|
26
|
+
return { errors: op["result.policy.message"] }
|
27
|
+
end
|
28
|
+
|
29
|
+
if op["contract.default"].errors.any?
|
30
|
+
return { errors: op["contract.default"].errors }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def balance_params
|
35
|
+
params.permit(:asset_code).to_hash.with_indifferent_access
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module StellarBase
|
2
|
+
class Balance
|
3
|
+
|
4
|
+
include Virtus.model
|
5
|
+
|
6
|
+
attribute :asset_code, String
|
7
|
+
attribute :amount, BigDecimal
|
8
|
+
|
9
|
+
def self.find(asset_code)
|
10
|
+
asset = FindWithdrawableAsset.(asset_code)
|
11
|
+
|
12
|
+
amount = DetermineMaxAmount.(asset[:max_amount_from])
|
13
|
+
new(asset_code: asset_code, amount: amount)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/config/routes.rb
CHANGED
@@ -2,5 +2,6 @@ StellarBase::Engine.routes.draw do
|
|
2
2
|
resources :bridge_callbacks, only: [:create], defaults: { format: "json" }
|
3
3
|
get "/withdraw" => "withdraw#create", as: :withdraw
|
4
4
|
get "/deposit" => "deposit#create", as: :deposit
|
5
|
+
get "/balance/:asset_code" => "balances#show", as: :balance
|
5
6
|
end
|
6
7
|
|
data/lib/stellar_base/version.rb
CHANGED
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: 0.
|
4
|
+
version: 0.10.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: 2018-11-
|
11
|
+
date: 2018-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: disposable
|
@@ -347,6 +347,9 @@ files:
|
|
347
347
|
- app/assets/stylesheets/stellar_base/application.css
|
348
348
|
- app/concepts/stellar_base/application_contract.rb
|
349
349
|
- app/concepts/stellar_base/application_operation.rb
|
350
|
+
- app/concepts/stellar_base/balances/balances_policy.rb
|
351
|
+
- app/concepts/stellar_base/balances/contracts/show.rb
|
352
|
+
- app/concepts/stellar_base/balances/operations/show.rb
|
350
353
|
- app/concepts/stellar_base/bridge_callbacks/bridge_callback_policy.rb
|
351
354
|
- app/concepts/stellar_base/bridge_callbacks/contracts/create.rb
|
352
355
|
- app/concepts/stellar_base/bridge_callbacks/operations/create.rb
|
@@ -357,6 +360,7 @@ files:
|
|
357
360
|
- app/concepts/stellar_base/withdrawal_requests/operations/create.rb
|
358
361
|
- app/concepts/stellar_base/withdrawal_requests/withdrawal_request_policy.rb
|
359
362
|
- app/controllers/stellar_base/application_controller.rb
|
363
|
+
- app/controllers/stellar_base/balances_controller.rb
|
360
364
|
- app/controllers/stellar_base/bridge_callbacks_controller.rb
|
361
365
|
- app/controllers/stellar_base/deposit_controller.rb
|
362
366
|
- app/controllers/stellar_base/home_controller.rb
|
@@ -368,12 +372,14 @@ files:
|
|
368
372
|
- app/mailers/stellar_base/application_mailer.rb
|
369
373
|
- app/models/stellar_base/account_subscription.rb
|
370
374
|
- app/models/stellar_base/application_record.rb
|
375
|
+
- app/models/stellar_base/balance.rb
|
371
376
|
- app/models/stellar_base/bridge_callback.rb
|
372
377
|
- app/models/stellar_base/deposit.rb
|
373
378
|
- app/models/stellar_base/deposit_request.rb
|
374
379
|
- app/models/stellar_base/stellar_toml.rb
|
375
380
|
- app/models/stellar_base/withdrawal_request.rb
|
376
381
|
- app/representers/stellar_base/application_representer.rb
|
382
|
+
- app/representers/stellar_base/balance_representer.rb
|
377
383
|
- app/representers/stellar_base/deposit_request_representer.rb
|
378
384
|
- app/representers/stellar_base/withdrawal_request_representer.rb
|
379
385
|
- app/services/stellar_base/account_subscriptions/execute_callback.rb
|