Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
1076175
Bump master with 2.7.0. Update API docs
Dec 6, 2020
bbe7d7a
Enhancement: Cleanup application.yml (#2789)
Dec 25, 2020
bc26dab
Add guard to auto test changes
dapi Feb 18, 2021
37fa0ed
Enhancement: Use system timezone if no TIMEZONE env
dapi Mar 5, 2021
774cc75
Fix: uninitialized constant OWHDWallet
dapi Mar 5, 2021
0086603
Fix: update wallet without blockchain api
dapi Mar 10, 2021
f51abb4
Add bitzlato gem and update jwt to 2.3.0.dev
dapi Mar 11, 2021
00371a4
Add bitzlato wallet to initializers
dapi Mar 11, 2021
0721fbd
Add WalletService#create_deposit_intention!
dapi Mar 11, 2021
5ee1c06
Add /api/v2/account/deposits/intention
dapi Mar 11, 2021
54f3662
Add Deposit#data
dapi Mar 11, 2021
700740e
Add poll_intenetion to Bitzlato wallet
dapi Mar 12, 2021
a2adace
Add Peatio::Bitzlato::Wallet#poll_intentions
dapi Mar 15, 2021
dfa4615
Add WalletService#poll_intentions
dapi Mar 15, 2021
2ff81e7
Add deposits polling job
dapi Mar 15, 2021
ea7a862
Add transfer_links presentation for deposit
dapi Mar 16, 2021
a326860
Add enable_intention to deposits API
dapi Mar 17, 2021
75e562b
Add unique index for intention_id
dapi Mar 17, 2021
940ba93
Save remote_username when polling intentions
dapi Mar 17, 2021
4f9a477
Remove add_remote_usernames_to_accounts migration
dapi Mar 18, 2021
9f87aab
Save beneficiary where deposit accepted
dapi Mar 18, 2021
37b6ee5
bump bitzlato plugin version
sixandfo Mar 18, 2021
ba68583
Bump bitzlato gem to 0.1.3
dapi Mar 18, 2021
4a5e4fa
Fix: remove focus from deposits_spec
dapi Mar 18, 2021
826eacc
Use ENV to configure bitzlato client
dapi Mar 18, 2021
51995b8
Bump bitzlato 0.1.4
dapi Mar 18, 2021
92cdccd
Add Bitzlato::Wallet.create_transaction!
dapi Mar 18, 2021
59ea8a3
Fix specs for Peatio::Bitzlato
dapi Mar 18, 2021
44e9ce2
Fix specs
dapi Mar 18, 2021
127e82e
Save links on withdraw by voucher
dapi Mar 18, 2021
708bb2f
Add specific ENV to specs
dapi Mar 18, 2021
f231ec7
Add withdrawal support and specs
dapi Mar 18, 2021
9cee052
Poll withdraws
dapi Mar 18, 2021
8f7dfc1
Minor fix in deposits polling
dapi Mar 22, 2021
4c08060
Rename poll_intentions to poll_deposits
dapi Mar 22, 2021
33ee7ac
Bump bitzlato 0.1.6
dapi Mar 22, 2021
ee355ab
Add payments polling to Bitzlato::Wallet
dapi Mar 22, 2021
cc339ea
Fix minor in WalletService#build_withdrawal!
dapi Mar 22, 2021
00990cf
Add Bitzlato::Wallet#create_payment
dapi Mar 22, 2021
93a850f
Integration fixes
dapi Mar 22, 2021
e705f2d
Save deposit username as beneficiary
dapi Mar 23, 2021
2f82046
Minor improvement beneficary saving from deposits
dapi Mar 23, 2021
ddcb958
Confirm withdraw if payment successful
dapi Mar 24, 2021
1280692
Fix: Use input currency for deposit intention
dapi Mar 29, 2021
93b8579
Fix: poll deposits and withdraws for every currency in the wallet
dapi Mar 29, 2021
4d71a47
Improve: mimemagic to 0.3.10
dapi Mar 29, 2021
6d64d85
Improve: currencies seeding updates existed currency
dapi Mar 29, 2021
b280ee7
fix specs
dapi Mar 31, 2021
8bca10f
Improvement: reseeding wallets updates its data
dapi Apr 1, 2021
d1a9867
Improvement: wallet validation doesn't raise for non blockchain wallets
dapi Apr 1, 2021
0e37503
Temporary fix Bitzlato::Wallet
dapi Apr 1, 2021
302cabf
Improvement: Detailed error on order validation
dapi Apr 13, 2021
72edb3d
Improvement: Direct withdraw confirmation
dapi Apr 13, 2021
0ad3791
Improvement: Save payment ID in bitzlato wallet
dapi Apr 14, 2021
d1bebbf
Improve: Withdraw polling
dapi Apr 14, 2021
5950ba3
Update bitzlato client
dapi Apr 14, 2021
5d711fb
Improvement: Change Deposit#intention_id to string
dapi Apr 16, 2021
d7460bb
fix specs
dapi Apr 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ gem 'faraday_middleware', '~> 0.13.1'
gem 'faye', '~> 1.4'
gem 'eventmachine', '~> 1.2'
gem 'em-synchrony', '~> 1.0'
gem 'jwt', '~> 2.2.0'

# We use 2.3.0.dev for bitzlato client
# Fill free to update to rubygem version when it will be released
gem 'jwt', github: 'jwt/ruby-jwt'

gem 'email_validator', '~> 1.6.0'
gem 'validate_url', '~> 1.0.4'
gem 'god', '~> 0.13.7', require: false
Expand Down Expand Up @@ -72,6 +76,10 @@ group :development do
gem 'annotate', '~> 3.1.0'
gem 'ruby-prof', '~> 0.17.0', require: false
gem 'listen', '>= 3.0.5', '< 3.2'

gem 'rspec'
gem 'guard'
gem 'guard-rspec', github: 'caspark/guard-rspec' # Use from github to remove rspec < 4.0 dependencies
end

group :test do
Expand Down
55 changes: 52 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ GIT
rails (>= 4.1)
vault (~> 0.14)

GIT
remote: https://github.com/caspark/guard-rspec
revision: 407ef8c62f3abad575bb66d53c02ba062a5ee8af
specs:
guard-rspec (4.7.3)
guard (~> 2.1)
guard-compat (~> 1.1)

GIT
remote: https://github.com/finfex/bitzlato
revision: 53b9c814a0be82f7d39c36abc4b9f37770bff405
branch: main
specs:
bitzlato (0.1.8)
faraday (>= 0.17)
json (~> 2.0)
jwt (~> 2.3.0.dev)

GIT
remote: https://github.com/jwt/ruby-jwt
revision: 2cea14fdae439773fafc59640178e5cf7a0af8a4
specs:
jwt (2.3.0.dev)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -166,6 +190,7 @@ GEM
ffi (1.15.0)
figaro (1.1.1)
thor (~> 0.14)
formatador (0.2.5)
globalid (0.4.2)
activesupport (>= 4.2.0)
god (0.13.7)
Expand All @@ -191,6 +216,16 @@ GEM
rack
grape_on_rails_routes (0.3.2)
rails (>= 3.1.1)
guard (2.16.2)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
hashdiff (1.0.1)
hashie (3.6.0)
hiredis (0.6.3)
Expand All @@ -208,7 +243,7 @@ GEM
faraday_middleware (~> 0.13.1)
faye (~> 1.2)
peatio (>= 2.4.2)
jwt (2.2.2)
json (2.5.1)
jwt-multisig (1.0.5)
activesupport (>= 4.0)
jwt (~> 2.2)
Expand All @@ -234,6 +269,7 @@ GEM
loofah (2.9.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
lumberjack (1.2.8)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
Expand All @@ -256,12 +292,16 @@ GEM
mustermann-grape (1.0.1)
mustermann (>= 1.0.0)
mysql2 (0.5.3)
nenv (0.3.0)
net-http-persistent (3.0.1)
connection_pool (~> 2.2)
nio4r (2.5.7)
nokogiri (1.11.2)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.20.1)
parser (3.0.0.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -382,6 +422,10 @@ GEM
reline (0.2.4)
io-console (~> 0.5)
rexml (3.2.4)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.0)
rspec-support (~> 3.9.0)
rspec-expectations (3.9.0)
Expand Down Expand Up @@ -424,6 +468,7 @@ GEM
parser
sentry-raven (2.9.0)
faraday (>= 0.7.6, < 1.0)
shellany (0.0.1)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand Down Expand Up @@ -465,6 +510,7 @@ DEPENDENCIES
annotate (~> 3.1.0)
arel-is-blank (~> 1.0.0)
better-faraday (~> 1.0.5)
bitzlato!
bootsnap (>= 1.1.0)
bullet (~> 5.9)
bump (~> 0.7)
Expand Down Expand Up @@ -493,12 +539,14 @@ DEPENDENCIES
grape-swagger-ui (~> 2.2.8)
grape_logging (~> 1.8.0)
grape_on_rails_routes (~> 0.3.2)
guard
guard-rspec!
hashie (~> 3.6.0)
hiredis (~> 0.6.0)
influxdb (~> 0.7.0)
irb
irix (~> 2.6.0)
jwt (~> 2.2.0)
jwt!
jwt-multisig (~> 1.0.0)
jwt-rack (~> 0.1.0)
kaminari (~> 1.2.1)
Expand All @@ -524,6 +572,7 @@ DEPENDENCIES
ransack (~> 2.3.2)
rbtree (~> 0.4.2)
redis (~> 4.1.2)
rspec
rspec-rails (~> 3.8, >= 3.8.2)
rspec-retry (~> 0.6)
rubocop-rspec (~> 1.32)
Expand All @@ -542,4 +591,4 @@ RUBY VERSION
ruby 2.6.6p146

BUNDLED WITH
2.1.4
2.2.15
1 change: 1 addition & 0 deletions Gemfile.plugin
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ gem 'peatio-bitcoincash', '~> 2.6.1'
gem 'peatio-ripple', '~> 2.6.1'
gem 'peatio-bitgo', '~> 2.6.6'
gem 'peatio-electrum', '~> 2.6.2'
gem 'bitzlato', github: 'finfex/bitzlato', branch: 'main'
75 changes: 75 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
#
notification :tmux, display_message: true if ENV.has_key?('TMUX')

# Note: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)

# Feel free to open issues for suggestions and improvements

# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)

# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)

# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)

watch(rails.controllers) do |m|
[
rspec.spec.call("routing/#{m[1]}_routing"),
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("acceptance/#{m[1]}")
]
end

# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }

# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end

# Rake tasks
dsl.watch_spec_files_for(dsl.rake.rake_files)
end
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,3 @@ Peatio is released under the terms of the [MIT license](http://peatio.mit-licens

[Peatio](http://en.wikipedia.org/wiki/Pixiu) (Chinese: 貔貅) is a Chinese mythical hybrid creature
considered to be a very powerful protector to practitioners of Feng Shui.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.0
2.7.0
33 changes: 33 additions & 0 deletions app/api/v2/account/deposits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,39 @@ class Deposits < Grape::API

before { deposits_must_be_permitted! }


desc 'Create deposit intention',
success: API::V2::Entities::Deposit
params do
requires :currency,
type: String,
values: { value: -> { Currency.visible.codes(bothcase: true) }, message: 'account.currency.doesnt_exist' },
desc: 'Currency code'
requires :amount,
type: BigDecimal,
desc: 'The deposit amount.'
end

post '/deposits/intention' do
currency = Currency.find(params[:currency])

unless currency.deposit_enabled?
error!({ errors: ['management.currency.deposit_disabled'] }, 422)
end

wallet = Wallet.deposit_wallet(currency.id)

unless wallet.present?
error!({ errors: ['account.wallet.not_found'] }, 422)
end

deposit = WalletService
.new(wallet)
.create_deposit_intention!(current_user, currency, params[:amount])

present deposit, with: API::V2::Entities::Deposit
end

desc 'Get your deposits history.',
is_array: true,
success: API::V2::Entities::Deposit
Expand Down
2 changes: 0 additions & 2 deletions app/api/v2/account/withdraws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ class Withdraws < Grape::API
post '/withdraws' do
user_authorize! :create, ::Withdraw

withdraw_api_must_be_enabled!

beneficiary = current_user
.beneficiaries
.available_to_member
Expand Down
13 changes: 12 additions & 1 deletion app/api/v2/entities/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Account < Base

expose(
:deposit_address,
if: ->(account, _options) { account.currency.coin? },
if: ->(account, _options) { account.currency.coin? && !Wallet.deposit_wallet(account.currency_id)&.settings&.fetch('enable_intention', false) },
using: API::V2::Entities::PaymentAddress,
documentation: {
desc: 'User deposit address',
Expand All @@ -44,6 +44,17 @@ class Account < Base
wallet = Wallet.deposit_wallet(account.currency_id)
::PaymentAddress.find_by(wallet: wallet, member: options[:current_user], remote: false)
end

expose(
:enable_intention,
if: ->(account, _options) { Wallet.deposit_wallet(account.currency_id)&.settings&.fetch('enable_intention', false) },
documentation: {
desc: 'Show intention form instead of payment address generation',
type: JSON
}
) do |account, options|
true
end
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions app/api/v2/entities/deposit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ class Deposit < Base
}
)

expose(
:transfer_links,
documentation: {
type: JSON,
desc: 'Links to p2p page to make deposit transfer',
example: -> {
[
{ title: 'telegram', url: 'https://t.me/BTC_STAGE_BOT?start=b_0f8c3db61f223ea9df072fd37e0b6315' },
{ title: 'web', url: 'https://s-www.lgk.one/p2p/?start=b_0f8c3db61f223ea9df072fd37e0b6315' }
]
}
},
if: ->(deposit) { deposit.transfer_links.present? }
)

expose(
:created_at,
Expand Down
17 changes: 17 additions & 0 deletions app/api/v2/entities/withdraw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ class Withdraw < Base
desc: 'The datetime when withdraw was completed'
}
)

expose(
:transfer_links,
if: ->(withdraw) { withdraw.metadata.has_key? 'links' },
documentation: {
type: JSON,
desc: 'Links to confirm withdraw on external resource',
example: -> {
[
{ title: 'telegram', url: 'https://t.me/BTC_STAGE_BOT?start=b_0f8c3db61f223ea9df072fd37e0b6315' },
{ title: 'web', url: 'https://s-www.lgk.one/p2p/?start=b_0f8c3db61f223ea9df072fd37e0b6315' }
]
}
}
) do |withdraw|
withdraw.metadata['links']
end
end
end
end
Expand Down
6 changes: 0 additions & 6 deletions app/api/v2/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ def trading_must_be_permitted!
end
end

def withdraw_api_must_be_enabled!
if ENV.false?('ENABLE_ACCOUNT_WITHDRAWAL_API')
error!({ errors: ['account.withdraw.disabled_api'] }, 422)
end
end

def current_user
# jwt.payload provided by rack-jwt
if request.env.key?('jwt.payload')
Expand Down
Loading