123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <?php
- class Eos extends EosBase {
- const REDIS_SERV = 'dw_chat';
- const PRE_ROOM_REWARD = 'globals:dw_chat:room_reward:';
- const LIVE_LIMIT = 20;
- const NET_EOS = 1;
- const NET_MEETONE = 2;
- const NET_ETH = 3;
- const NET_TRON = 4;
- private static $netToAccount = [
- self::NET_EOS => Account::TYPE_EOS,
- self::NET_MEETONE => Account::TYPE_MEETONE,
- self::NET_ETH => Account::TYPE_ETH,
- self::NET_TRON => Account::TYPE_TRON,
- ];
- public static function getNetAccount($net) {
- return self::$netToAccount[$net];
- }
- public static function getAllNet() {
- return array_keys(self::$netToAccount);
- }
- static $objRedisMap = [];
- function __construct() {
-
- $this->unlockWallet();
- }
- static function pubEvent($event, $data, $cacheKey = self::REDIS_SERV) {
- if (!self::$objRedisMap[$cacheKey]) {
- self::$objRedisMap[$cacheKey] = dwRedis::initNewOne($cacheKey);
- }
- if (is_array($data)) {
- $data = json_encode($data);
- }
- return self::$objRedisMap[$cacheKey]->publish($event, $data);
- }
-
- public static function getBlockInfo($blockId) {
- $cmd = "cleos -u https://api.eosnewyork.io get block '{$blockId}'";
- $json = self::execCmd($cmd);
- return json_decode($json, true);
- }
-
- public static function getBlockId($block_num) {
- $cmd = "cleos -u {$GLOBALS['eosUrl']} get block {$block_num}";
- $json = self::execCmd($cmd);
- $json = str_replace("\n", '', $json);
- $info = json_decode($json, true);
- if ($info && $info['id']) {
- $block_id = $info['id'];
- } else {
- $hex = dechex($block_num);
- $hex = sprintf("%08s", $hex);
- preg_match("/\"({$hex}[0-9a-fA-F]{56})\"/", $json, $matches);
- $block_id = $matches[1];
- }
- return $block_id;
- }
- function _formatDateTime($str) {
- if (strpos($str, 'T') > 0) {
- return date('Y-m-d H:i:s', strtotime($str) + 8 * 3600);
- } else {
- return date('Y-m-d H:i:s', strtotime($str));
- }
- }
- public static function getAccountActions($account_name, $limit = 200) {
- if (ENV == ENV_DEV) {
- $url = $GLOBALS['eosUrl'];
- } else {
-
- $url = 'https://nodes.get-scatter.com';
- }
- $cmd = "cleos -u {$url} get actions {$account_name} -1 -{$limit} -j";
- $json = self::execCmd($cmd);
- return json_decode($json, true);
- }
-
- public static function grabRedpack($redpackId, $trxId, $logId, $player, $quantity, $netId = Eos::NET_EOS) {
- $url = $GLOBALS['eosUrl'];
- $account = $GLOBALS['codeMee'];
- if ($netId == Eos::NET_MEETONE) {
- $url = $GLOBALS['eosxURL'];
- $account = $GLOBALS['codeMeeMO'];
- }
- $cmd = "cleos -u {$url} push action {$account} grabredpack '[ {$redpackId}, \"{$trxId}\", {$logId}, \"{$player}\", \"{$quantity}\" ]' -j -p {$account}";
- $json = self::execCmd($cmd);
- $log = [
- 'player_transaction_id' => $trxId,
- 'transaction_type' => 'grabredpack',
- 'from' => $account,
- 'to' => $player,
- 'cmd' => $cmd,
- 'json' => $json,
- ];
-
- self::logTrans($log);
- return $json;
- }
-
- public static function returnRedpack($redpackId, $trxId, $player, $netId = Eos::NET_EOS) {
- $url = $GLOBALS['eosUrl'];
- $account = $GLOBALS['codeMee'];
- if ($netId == Eos::NET_MEETONE) {
- $url = $GLOBALS['eosxURL'];
- $account = $GLOBALS['codeMeeMO'];
- }
- $cmd = "cleos -u {$url} push action {$account} returnpack '[ {$redpackId} ]' -j -p {$account}";
- $json = self::execCmd($cmd);
- $log = [
- 'player_transaction_id' => $trxId,
- 'transaction_type' => 'returnpack',
- 'from' => $account,
- 'to' => $player,
- 'cmd' => $cmd,
- 'json' => $json,
- ];
-
- self::logTrans($log);
- return $json;
- }
- public static function toDisplayFormat($amount, $unit = 'EOS') {
- return sprintf("%.4f {$unit}", round($amount / 10000, 4));
- }
- public static function toDisplayFormat2($amount, $unit = 'EOS', $keep = 4) {
- return sprintf("%.{$keep}f {$unit}", round($amount / 10000, 4));
- }
- public static function toNumber($amount) {
- $arr = explode(' ', $amount);
- return intval(floatval($arr[0]) * 10000);
- }
- }
|