feat: 项目基础框架+配置+Kernel
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2019/3/15
|
||||
* Time: 17:01
|
||||
*/
|
||||
namespace App\CoinDriver;
|
||||
|
||||
use App\AccountLog;
|
||||
use App\UsersWallet;
|
||||
use App\WalletLog;
|
||||
|
||||
class BTC extends Coin
|
||||
{
|
||||
|
||||
/**
|
||||
* 转账
|
||||
*
|
||||
* @param
|
||||
* $from_address
|
||||
* @param
|
||||
* $to_address
|
||||
* @param
|
||||
* $number
|
||||
* @param
|
||||
* $private_key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function transfer($from_address, $to_address, $number, $private_key)
|
||||
{
|
||||
// TODO: Implement transfer() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取余额
|
||||
*
|
||||
* @param
|
||||
* $address
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function balance($address)
|
||||
{
|
||||
// TODO: Implement balance() method.
|
||||
$api = 'http://43.129.16.120:82/wallet/btc/balance';
|
||||
|
||||
$response = $this->http($api, [
|
||||
'address' => $address
|
||||
]);
|
||||
|
||||
if ($response['errcode'] != 0) {
|
||||
exception('errorinfo');
|
||||
}
|
||||
$lessen = pow(10, $this->currency->decimal_scale);
|
||||
return $response['data']['balance'] / $lessen;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新钱包余额
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateBalance($wallet)
|
||||
{
|
||||
// TODO: Implement updateBalance() method.
|
||||
$this->canUpdateBalance($wallet);
|
||||
$balance = $this->balance($wallet->address);
|
||||
|
||||
if ($balance > $wallet->old_balance) {
|
||||
|
||||
$wallet->old_balance = $balance;
|
||||
$number = $balance - $wallet->old_balance;
|
||||
$wallet->save();
|
||||
|
||||
UsersWallet::changeBalance($wallet->user_id, $wallet->currency_id, $number, AccountLog::UPDATED_BALACNE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2019/3/11
|
||||
* Time: 15:51
|
||||
*/
|
||||
namespace App\CoinDriver;
|
||||
|
||||
use App\Model\Currency;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
abstract class Coin
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Currency
|
||||
*/
|
||||
public $currency;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var
|
||||
*
|
||||
*/
|
||||
public $type;
|
||||
|
||||
public function __construct($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
$currency = Currency::where('type', $this->type)->first();
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账
|
||||
*
|
||||
* @param $from_address 转出地址
|
||||
* @param $to_address 转入地址
|
||||
* @param $number 数量
|
||||
* @param $private_key 转出钱包的私钥
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public abstract function transfer($from_address, $to_address, $number, $private_key);
|
||||
|
||||
/**
|
||||
* 获取余额
|
||||
*
|
||||
* @param
|
||||
* $address
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public abstract function balance($address);
|
||||
|
||||
/**
|
||||
* 更新钱包余额
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public abstract function updateBalance($wallet);
|
||||
|
||||
/**
|
||||
* 获取钱包余额
|
||||
*
|
||||
* @param
|
||||
* $user_id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getAddress($user_id)
|
||||
{}
|
||||
|
||||
/**
|
||||
* 判断能不能更新余额
|
||||
*
|
||||
* @param
|
||||
* $wallet
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function canUpdateBalance($wallet)
|
||||
{
|
||||
if ($wallet->gl_time > time() - 15 * 60) {
|
||||
exception('归拢时间内不能从链上监听余额');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取驱动
|
||||
*
|
||||
* @param
|
||||
* $type
|
||||
*
|
||||
* @return Coin
|
||||
*/
|
||||
public static function newInstance($type)
|
||||
{
|
||||
$type = strtoupper($type);
|
||||
$path = "App\CoinDriver\\{$type}";
|
||||
$instance = new $path($type);
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function http($url, $data = null, $method = 'GET')
|
||||
{
|
||||
$query = strtoupper($method) == 'GET' ? $data : null;
|
||||
$body = strtoupper($method) == 'POST' ? $data : null;
|
||||
|
||||
$client = new Client();
|
||||
$response = $client->request($method, $url, [
|
||||
'query' => $query,
|
||||
'form_params' => $body
|
||||
])
|
||||
->getBody()
|
||||
->getContents();
|
||||
|
||||
return json_decode($response, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2019/3/15
|
||||
* Time: 17:01
|
||||
*/
|
||||
namespace App\CoinDriver;
|
||||
|
||||
use App\AccountLog;
|
||||
use App\UsersWallet;
|
||||
|
||||
class EOS extends Coin
|
||||
{
|
||||
|
||||
/**
|
||||
* 转账
|
||||
*
|
||||
* @param
|
||||
* $from_address
|
||||
* @param
|
||||
* $to_address
|
||||
* @param
|
||||
* $number
|
||||
* @param
|
||||
* $private_key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function transfer($from_address, $to_address, $number, $private_key)
|
||||
{
|
||||
// TODO: Implement transfer() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取余额
|
||||
*
|
||||
* @param
|
||||
* $address
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function balance($address)
|
||||
{
|
||||
// TODO: Implement balance() method.
|
||||
// TODO: Implement balance() method.
|
||||
$api = 'http://43.129.16.120:82/wallet/eos/balance';
|
||||
|
||||
$response = $this->http($api, [
|
||||
'address' => $address
|
||||
]);
|
||||
|
||||
if ($response['errcode'] != 0) {
|
||||
exception('errorinfo');
|
||||
}
|
||||
$lessen = pow(10, $this->currency->decimal_scale);
|
||||
return $response['data']['balance'] / $lessen;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新钱包余额
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateBalance($wallet)
|
||||
{
|
||||
// TODO: Implement updateBalance() method.
|
||||
$this->canUpdateBalance($wallet);
|
||||
$balance = $this->balance($wallet->address);
|
||||
|
||||
if ($balance > $wallet->old_balance) {
|
||||
|
||||
$wallet->old_balance = $balance;
|
||||
$number = $balance - $wallet->old_balance;
|
||||
$wallet->save();
|
||||
|
||||
UsersWallet::changeBalance($wallet->user_id, $wallet->currency_id, $number, AccountLog::UPDATED_BALACNE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2019/2/21
|
||||
* Time: 16:35
|
||||
*/
|
||||
namespace App\CoinDriver;
|
||||
|
||||
use App\Model\AccountLog;
|
||||
use App\Model\UserWallet;
|
||||
|
||||
class ETH extends Coin
|
||||
{
|
||||
|
||||
protected $api = '';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param
|
||||
* $address
|
||||
*
|
||||
* @return float|int|mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function balance($address)
|
||||
{
|
||||
$api = 'http://43.129.16.120:82/wallet/eth/balance';
|
||||
|
||||
$response = $this->http($api, [
|
||||
'address' => $address
|
||||
]);
|
||||
|
||||
if ($response['errcode'] != 0) {
|
||||
exception('errorinfo');
|
||||
}
|
||||
$lessen = pow(10, $this->currency->decimal_scale);
|
||||
return $response['data']['balance'] / $lessen;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新钱包余额
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function updateBalance($wallet)
|
||||
{
|
||||
$this->canUpdateBalance($wallet);
|
||||
$balance = $this->balance($wallet->address);
|
||||
|
||||
if ($balance > $wallet->old_balance) {
|
||||
|
||||
$wallet->old_balance = $balance;
|
||||
$number = $balance - $wallet->old_balance;
|
||||
$wallet->save();
|
||||
|
||||
UserWallet::changeBalance($wallet->user_id, $wallet->currency_id, $number, AccountLog::UPDATED_BALACNE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账
|
||||
*
|
||||
* @param
|
||||
* $from_address
|
||||
* @param
|
||||
* $to_address
|
||||
* @param
|
||||
* $number
|
||||
* @param
|
||||
* $private_key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function transfer($from_address, $to_address, $number, $private_key)
|
||||
{
|
||||
// TODO: Implement transfer() method.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user