|
@@ -133,44 +133,49 @@ class Trace extends Command
|
|
|
|
|
|
protected function transcation($md5)
|
|
|
{
|
|
|
- $api = (new ChainFactory())->api(base_path());
|
|
|
- $walapi = (new WalletFactory())->api(base_path());
|
|
|
- $eos = (new EosRpc($api, $walapi));
|
|
|
- $accountA = "alice";
|
|
|
- $accountB = "bob";
|
|
|
- $coinCode = "SYS";
|
|
|
- $coin = "1.0000";
|
|
|
+ try{
|
|
|
+ $api = (new ChainFactory())->api(base_path());
|
|
|
+ $walapi = (new WalletFactory())->api(base_path());
|
|
|
+ $eos = (new EosRpc($api, $walapi));
|
|
|
+ $accountA = "chxqsuyuanaa";
|
|
|
+ $accountB = "chxqsuyuanbb";
|
|
|
+ $coinCode = "EOS";
|
|
|
+ $coin = "0.1";
|
|
|
|
|
|
- $walletPassword = "PW5KFL5mQSWauhwnYTMFU3v9ALhkTCuCkfvVJgzJTpRKZysygTJZe";
|
|
|
- $walletName = "default";
|
|
|
- $eos->setWalletInfo($walletName, $walletPassword);
|
|
|
- $aliceBalance = $api->getCurrencyBalance('eosio.token', $accountA, $coinCode);
|
|
|
- $bobBalance = $api->getCurrencyBalance('eosio.token', $accountB, $coinCode);
|
|
|
- $balaceA = 0;
|
|
|
- $balaceB = 0;
|
|
|
- if (isset($aliceBalance[$accountA])) {
|
|
|
- $balaceA = $aliceBalance[$accountA][0];
|
|
|
- }
|
|
|
- if (isset($bobBalance[$accountB])) {
|
|
|
- $balaceB = $bobBalance[$accountB][0];
|
|
|
- }
|
|
|
- if ($balaceA == 0 && $balaceB == 0) {
|
|
|
- $this->line("两个账号都没钱了,快充钱");
|
|
|
- return;
|
|
|
- }
|
|
|
- if ($balaceA >= $coin * 2) {
|
|
|
- $trans = $eos->transfer($accountA, $accountB, $coin . " " . $coinCode, $md5, 'eosio.token', false);
|
|
|
- }elseif ($balaceB >= $coin * 2) {
|
|
|
- $trans = $eos->transfer($accountB, $accountA, $coin . " " . $coinCode, $md5, 'eosio.token', false);
|
|
|
- }else{
|
|
|
- $this->line('账号余额不足');
|
|
|
- return;
|
|
|
+ $walletPassword = "PW5KiK4oBMgjvxjhYxJzeRWNYtLot7GbH9wLM8pDmTH17yzUb4GTP";
|
|
|
+ $walletName = "caihongxingqiu";
|
|
|
+ $eos->setWalletInfo($walletName, $walletPassword);
|
|
|
+ $aliceBalance = $api->getCurrencyBalance('eosio.token', $accountA, $coinCode);
|
|
|
+ $bobBalance = $api->getCurrencyBalance('eosio.token', $accountB, $coinCode);
|
|
|
+ $balaceA = 0;
|
|
|
+ $balaceB = 0;
|
|
|
+ if (isset($aliceBalance[$accountA])) {
|
|
|
+ $balaceA = $aliceBalance[$accountA][0];
|
|
|
+ }
|
|
|
+ if (isset($bobBalance[$accountB])) {
|
|
|
+ $balaceB = $bobBalance[$accountB][0];
|
|
|
+ }
|
|
|
+ if ($balaceA == 0 && $balaceB == 0) {
|
|
|
+ $this->line("两个账号都没钱了,快充钱");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if ($balaceA >= $coin * 2) {
|
|
|
+ $trans = $eos->transfer($accountA, $accountB, $coin . " " . $coinCode, $md5, 'eosio.token', false);
|
|
|
+ }elseif ($balaceB >= $coin * 2) {
|
|
|
+ $trans = $eos->transfer($accountB, $accountA, $coin . " " . $coinCode, $md5, 'eosio.token', false);
|
|
|
+ }else{
|
|
|
+ $this->line('账号余额不足');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Log::debug('transinfo:'.\GuzzleHttp\json_encode($trans));
|
|
|
+ return [
|
|
|
+ 'transaction_id' => $trans['trans']['transaction_id'] ?? '',
|
|
|
+ 'block_num' => $trans['trans']['processed']['block_num'] ?? 0,
|
|
|
+ 'block_time' => $trans['trans']['processed']['block_time'] ?? ''
|
|
|
+ ];
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ $this->line('上链失败:'.$exception->getMessage());
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
- return [
|
|
|
- 'transaction_id' => $trans['trans']['transaction_id'] ?? '',
|
|
|
- 'block_num' => $trans['trans']['processed']['block_num'] ?? 0,
|
|
|
- 'block_time' => $trans['trans']['processed']['block_time'] ?? ''
|
|
|
- ];
|
|
|
}
|
|
|
}
|