Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions src/API/Tokens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace ArkEcosystem\Client\API;

class Tokens extends AbstractAPI
{
/**
* Get all tokens.
*
* @param array $parameters
*
* @return array
*/
public function all(array $parameters = []): ?array
{
return $this->requestGet('tokens', $parameters);
Comment thread
alexbarnsley marked this conversation as resolved.
Outdated
}

/**
* Get all tokens using whitelist filtering.
*
* This method sends a POST request with whitelist parameters.
*
* @param array $parameters
*
* @return array
*/
public function allWithWhitelist(array $parameters = []): ?array
{
return $this->requestPost('tokens', $parameters);
}

/**
* Get a token by contract address.
*
* @param string $address
*
* @return array
*/
public function get(string $address): ?array
{
return $this->requestGet("tokens/{$address}");
}

/**
* Get token holders for a given token.
*
* @param string $address
* @param array $query
*
* @return array
*/
public function holders(string $address, array $query = []): ?array
{
return $this->requestGet("tokens/{$address}/holders", $query);
}

/**
* Get token transfers for a given token.
*
* @param string $address
* @param array $query
*
* @return array
*/
public function transfersByToken(string $address, array $query = []): ?array
{
return $this->requestGet("tokens/{$address}/transfers", $query);
}

/**
* Get all token transfers.
*
* @param array $query
*
* @return array
*/
public function transfers(array $query = []): ?array
{
return $this->requestGet('tokens/transfers', $query);
}

/**
* Get the token whitelist.
*
* @param array $query
*
* @return array
*/
public function whitelist(array $query = []): ?array
{
return $this->requestGet('tokens/whitelist', $query);
}
}
6 changes: 6 additions & 0 deletions src/ArkClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use ArkEcosystem\Client\API\Peers;
use ArkEcosystem\Client\API\Receipts;
use ArkEcosystem\Client\API\Rounds;
use ArkEcosystem\Client\API\Tokens;
use ArkEcosystem\Client\API\Transactions;
use ArkEcosystem\Client\API\Validators;
use ArkEcosystem\Client\API\Votes;
Expand Down Expand Up @@ -79,6 +80,11 @@ public function rounds(): Rounds
return new Rounds($this->connection);
}

public function tokens(): Tokens
{
return new Tokens($this->connection);
}

public function transactions(): Transactions
{
return new Transactions($this->connection);
Expand Down
51 changes: 51 additions & 0 deletions tests/API/TokensTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace ArkEcosystem\Tests\Client\API;

use ArkEcosystem\Client\ArkClient;

it('calls correct url for all', function () {
$this->assertResponse('GET', 'tokens', function (ArkClient $client) {
return $client->tokens()->all();
});
});

it('calls correct url for all with whitelist', function () {
$this->assertResponse('POST', 'tokens', function (ArkClient $client) {
return $client->tokens()->allWithWhitelist([
'whitelist' => ['0x1234567890abcdef1234567890abcdef12345678'],
]);
});
Comment thread
alexbarnsley marked this conversation as resolved.
});

it('calls correct url for get', function () {
$this->assertResponse('GET', 'tokens/dummy', function (ArkClient $client) {
return $client->tokens()->get('dummy');
});
});

it('calls correct url for holders', function () {
$this->assertResponse('GET', 'tokens/dummy/holders', function (ArkClient $client) {
return $client->tokens()->holders('dummy');
});
});

it('calls correct url for transfers by token', function () {
$this->assertResponse('GET', 'tokens/dummy/transfers', function (ArkClient $client) {
return $client->tokens()->transfersByToken('dummy');
});
});

it('calls correct url for all transfers', function () {
$this->assertResponse('GET', 'tokens/transfers', function (ArkClient $client) {
return $client->tokens()->transfers();
});
});

it('calls correct url for whitelist', function () {
$this->assertResponse('GET', 'tokens/whitelist', function (ArkClient $client) {
return $client->tokens()->whitelist();
});
});