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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xboston committed Aug 15, 2019
2 parents bf8ffa6 + effd4f9 commit 717df60
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
6 changes: 6 additions & 0 deletions examples/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require __DIR__.'/../vendor/autoload.php';

use Dump\Dump;
use Metahash\HistoryFilters;
use Metahash\MetaHash;

$metaHash = new MetaHash();
Expand Down Expand Up @@ -30,6 +31,11 @@
$fetchHistory1010 = $metaHash->fetchHistory('0x00312d149c348120faffe00ca275d012e2a64524979df899d3', 10, 10);
Dump::d('fetchHistory 10 10', $fetchHistory1010);

$filter = new HistoryFilters();
$filter->setIsForging(true);
$fetchHistoryFilter = $metaHash->fetchHistoryFilter('0x00fa2a5279f8f0fd2f0f9d3280ad70403f01f9d62f52373833', $filter, 2);
Dump::d('fetchHistoryFilter', $fetchHistoryFilter);

$getTx = $metaHash->getTx('dd86635a7d7a8d8d44fc604f5fbb51eeb920dd28611b0f634e40b60af02a8c68');
Dump::d('getTx', $getTx);

Expand Down
85 changes: 85 additions & 0 deletions src/HistoryFilters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php declare(strict_types=1);
/**
* Copyright (c) 2019.
*/

namespace Metahash;

use JsonSerializable;

/**
* Class HistoryFilters
* @package Metahash
*/
class HistoryFilters implements JsonSerializable
{
public $isInput = false;// - Display only isInput transactions
public $isOutput = false;// - Display only isOutput transactions
public $isSuccess = false;// - Display only success transactions
public $isForging = false;// - Display only forging transactions
public $isTest = false;//- Display only test transactions
public $isDelegate = false;//- Display only delegation transactions

/**
* @return array|mixed
*/
public function jsonSerialize(): array
{
$filters = \get_object_vars($this);
$result = [];
foreach ($filters as $filter => $value) {
if ($value) {
$result[$filter] = true;
}
}
return $result;
}

/**
* @param bool $isInput
*/
public function setIsInput(bool $isInput): void
{
$this->isInput = $isInput;
}

/**
* @param bool $isOutput
*/
public function setIsOutput(bool $isOutput): void
{
$this->isOutput = $isOutput;
}

/**
* @param bool $isSuccess
*/
public function setIsSuccess(bool $isSuccess): void
{
$this->isSuccess = $isSuccess;
}

/**
* @param bool $isForging
*/
public function setIsForging(bool $isForging): void
{
$this->isForging = $isForging;
}

/**
* @param bool $isTest
*/
public function setIsTest(bool $isTest): void
{
$this->isTest = $isTest;
}

/**
* @param bool $isDelegate
*/
public function setIsDelegate(bool $isDelegate): void
{
$this->isDelegate = $isDelegate;
}
}
31 changes: 30 additions & 1 deletion src/MetaHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function checkAddress(string $address, bool $fast = false): bool
* @return bool|mixed|string
* @throws GuzzleException
*/
public function fetchHistory(string $address, int $countTx = self::HISTORY_LIMIT, int $beginTx = 0)
public function fetchHistory(string $address, int $countTx = self::HISTORY_LIMIT, int $beginTx = 0): array
{
if ($countTx > self::HISTORY_LIMIT) {
throw new RuntimeException('Too many transaction. Maximum is '.self::HISTORY_LIMIT);
Expand All @@ -207,6 +207,35 @@ public function fetchHistory(string $address, int $countTx = self::HISTORY_LIMIT
);
}

/**
* Get address transaction history
*
* @see https://github.com/xboston/metahash-api#fetch-history-filter
*
* @param string $address
* @param HistoryFilters $filter
* @param int $countTx
* @param int $beginTx
* @return array
* @throws GuzzleException
*/
public function fetchHistoryFilter(string $address, HistoryFilters $filter, int $countTx = self::HISTORY_LIMIT, int $beginTx = 0): array
{
if ($countTx > self::HISTORY_LIMIT) {
throw new RuntimeException('Too many transaction. Maximum is '.self::HISTORY_LIMIT);
}

return $this->queryTorrent(
'fetch-history-filter',
[
'address' => $address,
'countTxs' => $countTx,
'beginTx' => $beginTx,
'filters' => $filter,
]
);
}

/**
* Send request to torrent node
*
Expand Down

0 comments on commit 717df60

Please sign in to comment.