From c653a66a6927b5236798de309a43a200fb8a85bd Mon Sep 17 00:00:00 2001 From: Matt Smithies Date: Thu, 17 Nov 2022 12:07:32 +0000 Subject: [PATCH 1/6] Update HashgraphClient.php --- src/Http/Client/HashgraphClient.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Http/Client/HashgraphClient.php b/src/Http/Client/HashgraphClient.php index ee50836..8c62fa8 100644 --- a/src/Http/Client/HashgraphClient.php +++ b/src/Http/Client/HashgraphClient.php @@ -11,6 +11,8 @@ use Trustenterprises\LaravelHashgraph\Models\AccountTokenBalanceResponse; use Trustenterprises\LaravelHashgraph\Models\BequestToken; use Trustenterprises\LaravelHashgraph\Models\BequestTokenResponse; +use Trustenterprises\LaravelHashgraph\Models\NFT\BatchTransferNft; +use Trustenterprises\LaravelHashgraph\Models\NFT\BatchTransferNftResponse; use Trustenterprises\LaravelHashgraph\Models\NFT\ClaimNft; use Trustenterprises\LaravelHashgraph\Models\NFT\ClaimNftResponse; use Trustenterprises\LaravelHashgraph\Models\NFT\MintToken; @@ -310,6 +312,21 @@ public function transferNft(TransferNft $transferNft): TransferNftResponse { return new TransferNftResponse($data); } + /** + * Transfer a batch of NFTs from a treasury to a user. + * + * @param BatchTransferNft $transferNft + * @return BatchTransferNftResponse + * @throws GuzzleException + */ + public function batchTransferNft(BatchTransferNft $transferNft): BatchTransferNftResponse { + $response = $this->guzzle->post('api/nft/batch', $transferNft->forRequest()); + + $data = json_decode($response->getBody()->getContents()); + + return new BatchTransferNftResponse($data); + } + /** * @param ClaimNft $claimNft * @return ClaimNftResponse From ca85f8e850f3dc04b2799e974369ee8aa25fe524 Mon Sep 17 00:00:00 2001 From: Matt Smithies Date: Thu, 17 Nov 2022 12:07:37 +0000 Subject: [PATCH 2/6] Update LaravelHashgraph.php --- src/LaravelHashgraph.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/LaravelHashgraph.php b/src/LaravelHashgraph.php index 22497f2..eed8226 100644 --- a/src/LaravelHashgraph.php +++ b/src/LaravelHashgraph.php @@ -12,6 +12,8 @@ use Trustenterprises\LaravelHashgraph\Models\AccountTokenBalanceResponse; use Trustenterprises\LaravelHashgraph\Models\BequestToken; use Trustenterprises\LaravelHashgraph\Models\BequestTokenResponse; +use Trustenterprises\LaravelHashgraph\Models\NFT\BatchTransferNft; +use Trustenterprises\LaravelHashgraph\Models\NFT\BatchTransferNftResponse; use Trustenterprises\LaravelHashgraph\Models\NFT\ClaimNft; use Trustenterprises\LaravelHashgraph\Models\NFT\ClaimNftResponse; use Trustenterprises\LaravelHashgraph\Models\NFT\MintToken; @@ -129,6 +131,16 @@ public static function transferNonFungibleToken(TransferNft $transferNft) : Tran return static::withAuthenticatedClient()->getClient()->transferNft($transferNft); } + /** + * Batch transfer an NFT to a user + * + * @throws GuzzleException + */ + public static function batchTransferNonFungibleToken(BatchTransferNft $batchTransferNft) : BatchTransferNftResponse + { + return static::withAuthenticatedClient()->getClient()->batchTransferNft($batchTransferNft); + } + /** * A user can claim an NFT if they hold the correct pass * From 140f7ba7800dcb0478c8d5c401f73b61da233fe2 Mon Sep 17 00:00:00 2001 From: Matt Smithies Date: Thu, 17 Nov 2022 12:07:41 +0000 Subject: [PATCH 3/6] Create BatchTransferNft.php --- src/Models/NFT/BatchTransferNft.php | 63 +++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/Models/NFT/BatchTransferNft.php diff --git a/src/Models/NFT/BatchTransferNft.php b/src/Models/NFT/BatchTransferNft.php new file mode 100644 index 0000000..00b92c4 --- /dev/null +++ b/src/Models/NFT/BatchTransferNft.php @@ -0,0 +1,63 @@ +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; + } +} From 5dc2b81ccab2a58a77c9e696027fa4883be53de2 Mon Sep 17 00:00:00 2001 From: Matt Smithies Date: Thu, 17 Nov 2022 12:07:44 +0000 Subject: [PATCH 4/6] Create BatchTransferNftResponse.php --- src/Models/NFT/BatchTransferNftResponse.php | 83 +++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/Models/NFT/BatchTransferNftResponse.php diff --git a/src/Models/NFT/BatchTransferNftResponse.php b/src/Models/NFT/BatchTransferNftResponse.php new file mode 100644 index 0000000..026dde9 --- /dev/null +++ b/src/Models/NFT/BatchTransferNftResponse.php @@ -0,0 +1,83 @@ +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; + } +} From 3b3596f19e061f2968ebe3e9f1a557aaca9f0b84 Mon Sep 17 00:00:00 2001 From: Matt Smithies Date: Thu, 17 Nov 2022 12:07:46 +0000 Subject: [PATCH 5/6] Create HashgraphBatchNftTest.php --- tests/HashgraphBatchNftTest.php | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/HashgraphBatchNftTest.php diff --git a/tests/HashgraphBatchNftTest.php b/tests/HashgraphBatchNftTest.php new file mode 100644 index 0000000..f4bc713 --- /dev/null +++ b/tests/HashgraphBatchNftTest.php @@ -0,0 +1,58 @@ +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]); + } + + +} From c1f918841657ed20a4482b884fd579d219d454fa Mon Sep 17 00:00:00 2001 From: Matt Smithies Date: Thu, 17 Nov 2022 12:22:28 +0000 Subject: [PATCH 6/6] Chore psalm --- src/Models/NFT/NonFungibleToken.php | 8 ++++---- src/Utilities/Hmac.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Models/NFT/NonFungibleToken.php b/src/Models/NFT/NonFungibleToken.php index a0c8b05..be91dce 100644 --- a/src/Models/NFT/NonFungibleToken.php +++ b/src/Models/NFT/NonFungibleToken.php @@ -96,17 +96,17 @@ public function setName(string $name): void } /** - * @return String + * @return Int */ - public function getSupply(): string + public function getSupply(): Int { return $this->supply; } /** - * @param String $supply + * @param Int $supply */ - public function setSupply(string $supply): void + public function setSupply(int $supply): void { $this->supply = $supply; } diff --git a/src/Utilities/Hmac.php b/src/Utilities/Hmac.php index ee04454..07ed87e 100644 --- a/src/Utilities/Hmac.php +++ b/src/Utilities/Hmac.php @@ -8,7 +8,7 @@ class Hmac * Generate a HMAC from request content to validate that a payload matches with a x-signature * * @link https://github.com/symfony/http-foundation/blob/master/Request.php#L1535 Documentation of Foo. - * @var string|resource|false|null + * @param $content * @return string */ public static function generate($content): string