Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Commit

Permalink
full history exqmple
Browse files Browse the repository at this point in the history
  • Loading branch information
xboston committed Jul 22, 2019
1 parent aa3302b commit ad8111b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/big-history.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(strict_types=1);

require __DIR__.'/../vendor/autoload.php';

use Metahash\MetaHash;

$metaHash = new MetaHash();

// big history node
$address = '0x0038b12b0fafdc0ec523e3059882daf56fc3b3f6932a527987';

$d = fetchFullHistory($metaHash, $address);
\print_r($d);

function fetchFullHistory(MetaHash $metaHash, string $address)
{
$maxLimit = MetaHash::HISTORY_LIMIT;

$balance = $metaHash->fetchBalance($address);
if ($balance['result']['count_txs'] <= $maxLimit) {
return $metaHash->fetchHistory($address, $maxLimit);
}

$pages = \ceil($balance['result']['count_txs'] / $maxLimit) - 1;

$options = [[]];
for ($index = 0; $index <= $pages; $index++) {
$history = $metaHash->fetchHistory($address, $maxLimit, $index * $maxLimit);
$options[] = $history['result'];
}

$result = $result = [
'id' => 1,
'result' => \array_merge(...$options),
];

return $result;
}

0 comments on commit ad8111b

Please sign in to comment.