Sunday, April 21, 2019

Creating a cryptocurrency cashier system

Introduction

To create a cryptocurrency cashier system, we need to have



1) Create address

    Create multiple public and private keys.

2) Recharge coin

    Scan every blockchain block. 

    If the block consists of user transaction data, capture the transaction record.  

3) Collect Task

    Collect all the deposit from multiple users and consolidate them into a single account.

4) Withdraw coin

    Allow user to withdraw coin from the system back to the wallet.


Database Design


  1. CoinConfig
  2. AdminAddress
  3. AddressPool
  4. UserAddress
  5. CoinRecharge
  6. CoinWithdraw













Technical explanation

1) Create address

  • 500 addresses and private keys are created and store in the address_pool table.
  • When user surfs the coin deposit page, system will pick a record from address_pool table and insert into user_address table
  • User needs to deposit coin to the address. 
2) Recharge coin

  • Select the last scanned block no from coin_config table.
  • Get last block no from the blockchain.
  • Scanned block no should always be less than last block no from blockchain.
  • System will scan every block from last scanned block no to the last block of the blockchain
  • If found any transaction records, system will save the records into the coin_recharge table.
  • Insert a record to collect task table. [This is not apply to bitcoin]
3) Collect task [This apply to non-bitcoin blockchain only]

  • Check whether there is any record inserted into collect task table
  • Consolidate all the deposit and send to the admin address account.
 4) Withdraw

  • After user clicks withdraw button providing with an amount, a record is inserted to coin_withdraw table.
  • System will pick 50 coin_withdraw table records and perform transfer function.
  • After transfer function is performed, System will mark succeed for the coin_withdraw record.

Application





























Blockchain
- Study 
- GetBalance
- Genereate address
- Get token



Tether is built on top of omnilayer, ethereum or trc20

Ethereum is a newer blockchain, include smart contract capability.
Has is own token, with famous ERC20 token.
Introduce the concept of coin and token
which rely to account model not UXTO model
Ethereum addresses are composed of the prefix "0x"
  • Its block time is 14 to 15 seconds, compared with 10 minutes for bitcoin

Proof of Stake, which was proof of work
Transaction fees are generally considerably lower for Ethereum than for Bitcoin

18 decimal point
bitcoin decimal point

Bitcoin
Litecoin
Ethereum
Tether

Tether will use modern ERC20 coin









Assign the user a new public key



- Collect Task
- Withdraw coin

Create Address


Recharge Coin








Here we use Bitcoin, Ethereum and Tether as the example.

















People deposit using cryptocurrency wallet.

Company use 

bitcoin
ethereum

It is encourage to use RPC

not programming language

For example bitcoin, litecoin, dash, bitcoin SV, bitcoin Cash, Qtum are similar
and you can use same RPC to call

Because programming language maybe changed it is more safe to use

Deposit process

- Sync blockchain
- Full sync is the best

- Scan block by block

Check whether the block has deposit account

Create account

- Need to create

Bitcoin 

getnewaddress

Deposit

- Generate New address
- Coin recharge
- Collect Task
- Coin withdraw
- Check transaction fee
Microservice architechture



Kurbanetees

Docker

Create 5 services for 

CreateNewAddress.pl
CoinRecharge.pl
CollectTask.pl
CoinWithdraw.pl
GetTransactionFee.pl


There are 2 types of design

Create 1 service
- There are 5 schedulers

Create 5 services
- No scheduler






















 LtcClient.pl

ClientInfo.pl
GenerateAddress.pl
Recharge.pl
Withdraw.pl




LtcClient

- getInfo
- getBalance
- getBlock

- generateNewAddress

- transfer
- transferMany 

ClientInfo

- loadIp
- loadrpc
- try communicate with node

Deposit

  // Get block from node
  // Get block from db
  // loop all the transaction
  // Check whether receipient address = userAddress address
  // If yes, record down and save in db
  // Amount time txid is important

Withdraw
  
  // Get amount, sender and recipient from db 
  // If one send, if more sendtomany
  



In this tutorial, I will illustrate how the deposit / withdraw of the following coins work

  1. Bitcoin
  2. Litecoin
  3. Ethereum
  4. Tether
A Crytpo casher system should have the following functionalitie

- Create address

1) 500 addresses are created and store in address_pool table.
2) When user surfs coin deposit page, system will pick a record from address_pool table.
3) User needs to deposit coin to the address. 

- Recharge

1) Select last scanned block no from coin_config table.

2) Get last block no from blockchain.
3) Scanned block no should always be less than last block no from blockchain.
4) System will scan every block from last scanned block no to blockchain's last block
5) If found any transaction records, save the records in the coin_recharge table.
6) Insert a record to collect task table. [This apply to non-bitcoin blockchain only]

- Collect task [This apply to non-bitcoin blockchain only]


1) Check whether there is any record inserted into collect task table
2) Consolidate all the deposit and send to the admin address account.

- Withdraw


1) After user clicks withdraw button providing with an amount, a record is inserted to coin_withdraw table.
2) System will pick 50 coin_withdraw table records and perform transfer function.


3) After transfer function is performed, System will mark succeed for the coin_withdraw record.