Commit 54a4caa2 authored by rlgy's avatar rlgy

update

parent 3fa4f915
...@@ -142,4 +142,105 @@ class Chain33Business ...@@ -142,4 +142,105 @@ class Chain33Business
$service = new Chain33Service(); $service = new Chain33Service();
return $service->getTxByAddr($addr, $flag, $count, $direction, $height, $index); return $service->getTxByAddr($addr, $flag, $count, $direction, $height, $index);
} }
/**
* 获取用户首次交易区块信息
*
* @param string $address
* @param int $flag
* @return boolean|array
*/
public static function getAddressFirstTransInfo($address, $flag)
{
$trans = Chain33Business::getTxByAddr($address, $flag, 1, 1, 0, 0);
if ($trans['code'] == 0) {
return $trans['result']['txInfos'][0];
}
return false;
}
/**
* 获取用户最新交易区块信息
*
* @param string $address
* @param int $flag
* @return boolean|array
*/
public static function getAddressLastTransInfo($address, $flag)
{
$trans = Chain33Business::getTxByAddr($address, $flag, 1, 0, -1, 0);
if ($trans['code'] == 0) {
return $trans['result']['txInfos'][0];
}
return false;
}
/**
* 获取高度区间内的所有 txhash
*
* @param string $addr
* @param int $flag
* @param int $direction
* @param int $start_height
* @param int $end_height
* @return boolean|array
*/
public static function getTxByAddrInRange($addr, $flag, $direction, $start_height, $end_height)
{
$result = [];
$trans_info = Chain33Business::getTxByAddr($addr, $flag, 0, 0, -1, 0);
if ($trans_info['code'] == 0) {
$result = $trans_info['result']['txInfos'];
}
// $first_info = Chain33Business::getAddressFirstTransInfo($addr, $flag);
// if ($first_info) {
// $height = $first_info['height'];
// if ($height <= $start_height) {
// //获取开始高度之后的所有信息
// if ($height == $start_height) {
// $result = array_merge($result, $first_info);
// }
// $trans_info = Chain33Business::getTxByAddr($addr, $flag, 0, 1, $start_height, 0);
// var_dump($trans_info);
// if ($trans_info['code'] == 0) {
// $trans_info = $trans_info['result']['txInfos'];
// $result = array_merge(array_column($trans_info, null, 'height'));
// }
// } else {
// $last_info = Chain33Business::getAddressLastTransInfo($addr, $flag);
// if ($last_info) {
// $height = $last_info['height'];
// if ($height == $end_height) {
// $result = array_merge($result, $first_info);
// }
// if ($height <= $end_height) {
// $height = -1;
// } else {
// $height = $end_height;
// }
// $trans_info = Chain33Business::getTxByAddr($addr, $flag, 0, 0, $height, 0);
// if ($trans_info['code'] == 0) {
// $trans_info = $trans_info['result']['txInfos'];
// $result = array_merge(array_column($trans_info, null, 'height'));
// }
// }
// }
// }
foreach ($result as $key => $item) {
if ($item['height'] > $end_height || $item['height'] < $start_height) {
unset($result[$key]);
}
}
return $result;
}
/**
* @param array $hashes
* @return array
*/
public static function getTxByHashs($hashes)
{
$service = new Chain33Service();
return $service->getTxByHashes($hashes);
}
} }
...@@ -161,4 +161,16 @@ class Chain33Service ...@@ -161,4 +161,16 @@ class Chain33Service
]; ];
return $this->send($params, 'Chain33.GetTxByAddr'); return $this->send($params, 'Chain33.GetTxByAddr');
} }
/**
* @param array $hashes
* @return array
*/
public function getTxByHashes(array $hashes)
{
$params = [
'hashes' => $hashes,
];
return $this->send($params, 'Chain33.GetTxByHashes');
}
} }
...@@ -36,24 +36,27 @@ class JugdeAwardJob extends BaseObject implements JobInterface ...@@ -36,24 +36,27 @@ class JugdeAwardJob extends BaseObject implements JobInterface
if ($guess_result) { if ($guess_result) {
$config = Yii::$app->params['h5_activity']['ZWG_GUESS_NEWBEE']; $config = Yii::$app->params['h5_activity']['ZWG_GUESS_NEWBEE'];
//获取区块间的所有交易(正常竞猜) //获取区块间的所有交易(正常竞猜)
$trans_normal = Chain33Business::getTxByAddr($config['from_normal'], 2, 0, 0, $guess_result->end_height, // $trans_normal = Chain33Business::getTxByAddrInRange($config['from_normal'], 2, 0, $guess_result->start_height, $guess_result->end_height);
0); $trans_normal = Chain33Business::getTxByAddrInRange('14o9MHrrLfpsXf7wu4H4YRwvy84fjd7uaj', 2, 0, 710900, 715345);
$trans_normal = Chain33Business::getTxByAddr('1EZxpc1tnKtmQkUHcABXA6Dsn7e7zuhD2p', 2, 0, 0, $trans_new = Chain33Business::getTxByAddrInRange($config['to'], 2, 0, $guess_result->start_height, $guess_result->end_height);
$guess_result->end_height,
0);
if ($trans_normal['code'] != 0) {
return 0;
} else {
$trans_normal = $trans_normal['result']['txInfos'];
var_dump($trans_normal);
die();
}
$trans = array_merge($trans_normal, $trans_new);
$txhashs = array_column($trans, 'hash');
$trans_info = Chain33Business::getTxByHashs($txhashs);
if ($trans_info['code'] == 0) {
$trans_info = $trans_info['result']['txs'];
if (is_array($trans_info)) {
foreach ($trans_info as $k => $v) {
//收集数据
}
}
}
$loop = false;
} else { } else {
$loop = false; $loop = false;
} }
} while ($loop); } while ($loop);
return 0; return 0;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment