-
Notifications
You must be signed in to change notification settings - Fork 12
feat: tokens endpoint #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
06ecd81
feat: tokens endpoint
alexbarnsley 57e9bc6
fix failing test
alexbarnsley 98cc28b
Update src/API/Tokens.php
alexbarnsley 02ce9a4
combine all methods
alexbarnsley a2bc09e
wallet endpoints
alexbarnsley 6f6f31a
wallet endpoints
alexbarnsley 8907742
style: resolve style guide violations
alexbarnsley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ArkEcosystem\Client\API; | ||
|
|
||
| class Tokens extends AbstractAPI | ||
| { | ||
| /** | ||
| * Get all tokens. | ||
| * | ||
| * @param array $query | ||
| * | ||
| * @return array | ||
| */ | ||
| public function all(array $query = []): ?array | ||
| { | ||
| if (isset($query['whitelist'])) { | ||
| return $this->requestPost('tokens', $query); | ||
| } | ||
|
|
||
| return $this->requestGet('tokens', $query); | ||
| } | ||
|
|
||
| /** | ||
| * 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <?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()->all([ | ||
| 'whitelist' => ['0x1234567890abcdef1234567890abcdef12345678'], | ||
| ]); | ||
| }, | ||
| expectedRequestBody: [ | ||
| 'whitelist' => ['0x1234567890abcdef1234567890abcdef12345678'], | ||
| ] | ||
| ); | ||
| }); | ||
|
|
||
| it('sends all whitelist values in the request body', function () { | ||
| $this->assertResponse( | ||
| 'POST', | ||
| 'tokens', | ||
| function (ArkClient $client) { | ||
| return $client->tokens()->all([ | ||
| 'whitelist' => [ | ||
| '0x1234567890abcdef1234567890abcdef12345678', | ||
| '0xabcdef1234567890abcdef1234567890abcdef12', | ||
| ], | ||
| ]); | ||
| }, | ||
| expectedRequestBody: [ | ||
| 'whitelist' => [ | ||
| '0x1234567890abcdef1234567890abcdef12345678', | ||
| '0xabcdef1234567890abcdef1234567890abcdef12', | ||
| ], | ||
| ] | ||
| ); | ||
| }); | ||
|
|
||
| it('calls correct url for whitelist with query', function () { | ||
| $this->assertResponse('GET', 'tokens/whitelist?page=2&limit=10', function (ArkClient $client) { | ||
| return $client->tokens()->whitelist([ | ||
| 'page' => 2, | ||
| 'limit' => 10, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| 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(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.