Skip to content

Commit 06ecd81

Browse files
committed
feat: tokens endpoint
1 parent 18b848d commit 06ecd81

3 files changed

Lines changed: 153 additions & 0 deletions

File tree

‎src/API/Tokens.php‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ArkEcosystem\Client\API;
6+
7+
class Tokens extends AbstractAPI
8+
{
9+
/**
10+
* Get all tokens.
11+
*
12+
* @param array $parameters
13+
*
14+
* @return array
15+
*/
16+
public function all(array $parameters = []): ?array
17+
{
18+
return $this->requestGet('tokens', $parameters);
19+
}
20+
21+
/**
22+
* Get all tokens using whitelist filtering.
23+
*
24+
* This method sends a POST request with whitelist parameters.
25+
*
26+
* @param array $parameters
27+
*
28+
* @return array
29+
*/
30+
public function allWithWhitelist(array $parameters = []): ?array
31+
{
32+
return $this->requestPost('tokens', $parameters);
33+
}
34+
35+
/**
36+
* Get a token by contract address.
37+
*
38+
* @param string $address
39+
*
40+
* @return array
41+
*/
42+
public function get(string $address): ?array
43+
{
44+
return $this->requestGet("tokens/{$address}");
45+
}
46+
47+
/**
48+
* Get token holders for a given token.
49+
*
50+
* @param string $address
51+
* @param array $query
52+
*
53+
* @return array
54+
*/
55+
public function holders(string $address, array $query = []): ?array
56+
{
57+
return $this->requestGet("tokens/{$address}/holders", $query);
58+
}
59+
60+
/**
61+
* Get token transfers for a given token.
62+
*
63+
* @param string $address
64+
* @param array $query
65+
*
66+
* @return array
67+
*/
68+
public function transfersByToken(string $address, array $query = []): ?array
69+
{
70+
return $this->requestGet("tokens/{$address}/transfers", $query);
71+
}
72+
73+
/**
74+
* Get all token transfers.
75+
*
76+
* @param array $query
77+
*
78+
* @return array
79+
*/
80+
public function transfers(array $query = []): ?array
81+
{
82+
return $this->requestGet('tokens/transfers', $query);
83+
}
84+
85+
/**
86+
* Get the token whitelist.
87+
*
88+
* @param array $query
89+
*
90+
* @return array
91+
*/
92+
public function whitelist(array $query = []): ?array
93+
{
94+
return $this->requestGet('tokens/whitelist', $query);
95+
}
96+
}

‎src/ArkClient.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use ArkEcosystem\Client\API\Peers;
1515
use ArkEcosystem\Client\API\Receipts;
1616
use ArkEcosystem\Client\API\Rounds;
17+
use ArkEcosystem\Client\API\Tokens;
1718
use ArkEcosystem\Client\API\Transactions;
1819
use ArkEcosystem\Client\API\Validators;
1920
use ArkEcosystem\Client\API\Votes;
@@ -79,6 +80,11 @@ public function rounds(): Rounds
7980
return new Rounds($this->connection);
8081
}
8182

83+
public function tokens(): Tokens
84+
{
85+
return new Tokens($this->connection);
86+
}
87+
8288
public function transactions(): Transactions
8389
{
8490
return new Transactions($this->connection);

‎tests/API/TokensTest.php‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ArkEcosystem\Tests\Client\API;
6+
7+
use ArkEcosystem\Client\ArkClient;
8+
9+
it('calls correct url for all', function () {
10+
$this->assertResponse('GET', 'tokens', function (ArkClient $client) {
11+
return $client->tokens()->all();
12+
});
13+
});
14+
15+
it('calls correct url for all with whitelist', function () {
16+
$this->assertResponse('POST', 'tokens', function (ArkClient $client) {
17+
return $client->tokens()->all([
18+
'whitelist' => ['0x1234567890abcdef1234567890abcdef12345678'],
19+
]);
20+
});
21+
});
22+
23+
it('calls correct url for get', function () {
24+
$this->assertResponse('GET', 'tokens/dummy', function (ArkClient $client) {
25+
return $client->tokens()->get('dummy');
26+
});
27+
});
28+
29+
it('calls correct url for holders', function () {
30+
$this->assertResponse('GET', 'tokens/dummy/holders', function (ArkClient $client) {
31+
return $client->tokens()->holders('dummy');
32+
});
33+
});
34+
35+
it('calls correct url for transfers by token', function () {
36+
$this->assertResponse('GET', 'tokens/dummy/transfers', function (ArkClient $client) {
37+
return $client->tokens()->transfersByToken('dummy');
38+
});
39+
});
40+
41+
it('calls correct url for all transfers', function () {
42+
$this->assertResponse('GET', 'tokens/transfers', function (ArkClient $client) {
43+
return $client->tokens()->transfers();
44+
});
45+
});
46+
47+
it('calls correct url for whitelist', function () {
48+
$this->assertResponse('GET', 'tokens/whitelist', function (ArkClient $client) {
49+
return $client->tokens()->whitelist();
50+
});
51+
});

0 commit comments

Comments
 (0)