logo

OpenWare OPEX

rk_logo

#Build Peatio docker image with plugins

To build a docker image with other currencies plugins you need to follow these instructions:

  1. Clone Peatio repository

    git clone https://github.com/rubykube/peatio
    
  2. Modify Gemfile.plugin

    Specify the plugins you want to enable in this peatio build

    # Change directory to peatio
    cd peatio
    # Open Gemfile.plugin file
    vim Gemfile.plugin
    

    Modify content of Gemfile.plugin to the following:

    source 'https://rubygems.org'
    git_source(:github) { |repo_slug| "https://github.com/#{repo_slug}" }
    
    # List your plugins here.
    
    gem 'peatio-litecoin', '~> 0.2.0'
    git 'https://github.com/rubykube/peatio-contrib' do
      gem 'peatio-bitcoincash'
      gem 'peatio-dash'
      gem 'peatio-ripple'
    end
    
  3. Run docker build command

    # Install dependencies
    bundle install
    # Build the docker image
    docker build -t peatio:*base-ver*-plugins .
    

#Peatio troubleshooting

Request peatio from the cluster network

In production environement peatio is configured to force the user to use HTTPS to access the service (Rails option config.force_ssl = true). This is a good security practice, reducing the risk of people to get there password or Cookie stolen by a man in the middle.

Then if you do a request to peatio inside the cluster in HTTP you will get the following response:

$ curl -i peatio-rails:8080
HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Location: https://peatio-rails:8080/
Transfer-Encoding: chunked

Rails redirects you to the same url in https which is not valid since the protocol used is HTTP.

To bypass this problem you need to mimic the fact that you are doing a request from the proxy, adding the folloing header:

curl -H "X-Forwarded-Proto: https" peatio-rails:8080 

Delete a deposit address for a user account

WARNING: the user must NOT reuse the previous address.

member = Member.find_by(uid: "U123456789")
account = member.accounts.find_by(currency: "eth")
account.payment_address.destroy!

Then a new address will be generated one the fly when the user will request it, or you can run the following command to manually trigger the generation:

account.payment_address

Internal transfer between users

Peatio contains internal mechanism to transfer funds from a user to an other. Here is an example how to use this feature, this could be used by the platform administrator to do manual settlements:

def create_transfer(transfer_attrs)
  include API::V2::Management::Helpers

  Transfer.transaction do
    transfer = Transfer.create!(transfer_attrs.slice(:key, :kind, :desc))
    transfer_attrs[:operations].map do |op_pair|
      shared_params = { currency: op_pair[:currency],
                        reference: transfer }

      debit_params = op_pair[:account_src]
                       .merge(debit: op_pair[:amount])
                       .merge(shared_params)
                       .compact


      credit_params = op_pair[:account_dst]
                        .merge(credit: op_pair[:amount])
                        .merge(shared_params)
                        .compact

      create_operation!(debit_params)
      create_operation!(credit_params)
    end
  end
end

transfer_attrs = {
  key:  Time.now.to_i, # This should be unique.
  kind: "member-transfer",
  desc: "Internal money transfers between members on 2019-06-21T16:11:06",
  operations: [
    {
      currency: :btc,
      amount:   10,
      account_src: {
        code: 202,
        uid: "U674918561"
      },
      account_dst: {
        code: 202,
        uid: "U334105020"
      }
    },
    {
      currency: :btc,
      amount:   5,
      account_src: {
        code: 202,
        uid: "U334105020"
      },
      account_dst: {
        code: 202,
        uid: "U674918561"
      }
    }
  ]
}

create_transfer(transfer_attrs)

Create an adjustment

Peatio is capable of creating credit or debit operations to update a user's balance which are called adjustments. Each adjustment creates a pair with an asset and a liabilty/revenue/expense; Adjustement has pending, accepted and rejected states.

adjustment_params = { 
  reason: "member-adjustment",
  description: "Adjust bitcoin for trade bot",
  creator_id: 1,
  amount: 1,
  currency_id: 'btc',
  asset_account_code: 102,
  receiving_account_number: "btc-202-U123456789",
  category: "asset_registration"
 } 

adjustment = Adjustment.create!(adjustment_params)
adjustment.accept!(validator: Member.last)

ActiveRecord::PendingMigrationError

Migrations are pending. To resolve this issue, run in a rails pod:

bundle exec rake db:migrate