generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from trustenterprises/feature/laravel-batch-in…
…tegration Laravel batch NFT integration
- Loading branch information
Showing
7 changed files
with
238 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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,63 @@ | ||
<?php | ||
|
||
namespace Trustenterprises\LaravelHashgraph\Models\NFT; | ||
|
||
use GuzzleHttp\RequestOptions; | ||
|
||
class BatchTransferNft | ||
{ | ||
private String $token_id; | ||
|
||
private String $receiver_id; | ||
|
||
private int $amount; | ||
|
||
/** | ||
* SendToken constructor. | ||
* | ||
* @param String $token_id | ||
* @param String $receiver_id | ||
* @param int $amount | ||
*/ | ||
public function __construct(string $token_id, string $receiver_id, int $amount) | ||
{ | ||
$this->token_id = $token_id; | ||
$this->receiver_id = $receiver_id; | ||
$this->amount = $amount; | ||
} | ||
|
||
public function forRequest(): array | ||
{ | ||
return [ | ||
RequestOptions::JSON => [ | ||
'token_id' => $this->getTokenId(), | ||
'receiver_id' => $this->getReceiverId(), | ||
'amount' => $this->getAmount(), | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTokenId(): string | ||
{ | ||
return $this->token_id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getReceiverId(): string | ||
{ | ||
return $this->receiver_id; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getAmount(): int | ||
{ | ||
return $this->amount; | ||
} | ||
} |
This file contains 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,83 @@ | ||
<?php | ||
|
||
namespace Trustenterprises\LaravelHashgraph\Models\NFT; | ||
|
||
class BatchTransferNftResponse | ||
{ | ||
private array $results; | ||
|
||
private int $expected; | ||
|
||
private int $actual_sent; | ||
|
||
private array $errors = []; | ||
|
||
private bool $transfer_success = false; | ||
|
||
/** | ||
* @param object $response | ||
*/ | ||
public function __construct(object $response) | ||
{ | ||
if (property_exists($response->data, 'errors')) { | ||
$this->errors = $response->data->errors; | ||
} else { | ||
$this->transfer_success = true; | ||
$this->results = $response->data->results; | ||
$this->expected = $response->data->expected; | ||
$this->actual_sent = $response->data->actual_sent; | ||
} | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasTransferSucceeded(): bool | ||
{ | ||
return $this->transfer_success; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getErrors(): array | ||
{ | ||
return $this->errors; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getResults(): array | ||
{ | ||
return $this->results; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getExpected(): int | ||
{ | ||
return $this->expected; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getActualSent(): int | ||
{ | ||
return $this->actual_sent; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isTransferSuccess(): bool | ||
{ | ||
return $this->transfer_success; | ||
} | ||
|
||
public function isSuccessful(): bool { | ||
return count($this->errors) == 0; | ||
} | ||
} |
This file contains 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 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 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,58 @@ | ||
<?php | ||
|
||
namespace Trustenterprises\LaravelHashgraph\Tests; | ||
|
||
use Trustenterprises\LaravelHashgraph\LaravelHashgraph; | ||
use Trustenterprises\LaravelHashgraph\Models\NFT\BatchTransferNft; | ||
use Trustenterprises\LaravelHashgraph\Models\NFT\ClaimNft; | ||
use Trustenterprises\LaravelHashgraph\Models\NFT\MintToken; | ||
use Trustenterprises\LaravelHashgraph\Models\NFT\NftMetadata; | ||
use Trustenterprises\LaravelHashgraph\Models\NFT\NonFungibleToken; | ||
use Trustenterprises\LaravelHashgraph\Models\NFT\TransferNft; | ||
|
||
class HashgraphBatchNftTest extends TestCase | ||
{ | ||
/** | ||
* Attempt to send a pre-minted NFT | ||
* | ||
* @test-ignore | ||
*/ | ||
public function attempt_batch_transfer() | ||
{ | ||
|
||
$account = LaravelHashgraph::createAccount(); | ||
|
||
// Mirrornode ain't real time... | ||
$nft_id = '0.0.48905313'; | ||
$batch_amount = 19; | ||
|
||
$batch = new BatchTransferNft($nft_id, $account->getAccountId(), $batch_amount); | ||
|
||
$result = LaravelHashgraph::batchTransferNonFungibleToken($batch); | ||
|
||
$this->assertEquals($batch_amount, $result->getActualSent()); | ||
$this->assertEquals($batch_amount, $result->getExpected()); | ||
} | ||
|
||
/** | ||
* Attempt to send to many NFTs | ||
* | ||
* @test | ||
*/ | ||
public function attempt_failed_too_many_batch_transfer() | ||
{ | ||
$account = LaravelHashgraph::createAccount(); | ||
|
||
// Mirrornode ain't real time... | ||
$nft_id = '0.0.48905313'; | ||
$batch_amount = 1009; | ||
|
||
$batch = new BatchTransferNft($nft_id, $account->getAccountId(), $batch_amount); | ||
|
||
$result = LaravelHashgraph::batchTransferNonFungibleToken($batch); | ||
|
||
$this->assertEquals('The treasury does not hold the amount of NFTs of id ' . $nft_id . ' to do the required batch transfer', $result->getErrors()[0]); | ||
} | ||
|
||
|
||
} |