Skip to content

Commit

Permalink
Initial pass inscriptions for Laravel
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsmithies committed Jan 7, 2024
1 parent 05062ba commit 008179d
Show file tree
Hide file tree
Showing 9 changed files with 935 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/Contracts/InscriptionMethodInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Trustenterprises\LaravelHashgraph\Contracts;

use Trustenterprises\LaravelHashgraph\Models\Inscriptions\BurnInscription;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\DeployInscription;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\MintInscription;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\InscriptionResponse;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\TransferInscription;

interface InscriptionMethodInterface
{
/**
* @param MintInscription $request
* @return InscriptionResponse
*/
public function deployInscription(DeployInscription $request): InscriptionResponse;

/**
* @param MintInscription $request
* @return InscriptionResponse
*/
public function mintInscription(MintInscription $request): InscriptionResponse;

/**
* @param BurnInscription $request
* @return InscriptionResponse
*/
public function burnInscription(BurnInscription $request): InscriptionResponse;

/**
* @param TransferInscription $request
* @return InscriptionResponse
*/
public function transferInscription(TransferInscription $request): InscriptionResponse;
}
48 changes: 47 additions & 1 deletion src/Http/Client/HashgraphClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Trustenterprises\LaravelHashgraph\Contracts\HashgraphConsensus;
use Trustenterprises\LaravelHashgraph\Contracts\InscriptionMethodInterface;
use Trustenterprises\LaravelHashgraph\Models\AccountCreateResponse;
use Trustenterprises\LaravelHashgraph\Models\AccountHoldingsResponse;
use Trustenterprises\LaravelHashgraph\Models\AccountTokenBalanceResponse;
use Trustenterprises\LaravelHashgraph\Models\BequestToken;
use Trustenterprises\LaravelHashgraph\Models\BequestTokenResponse;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\BurnInscription;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\DeployInscription;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\MintInscription;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\InscriptionResponse;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\TransferInscription;
use Trustenterprises\LaravelHashgraph\Models\NFT\BatchTransferNft;
use Trustenterprises\LaravelHashgraph\Models\NFT\BatchTransferNftResponse;
use Trustenterprises\LaravelHashgraph\Models\NFT\ClaimNft;
Expand All @@ -35,7 +41,7 @@
* Class ServerlessHashgraphClient
* @package Trustenterprises\LaravelHashgraph\Http\Client
*/
class HashgraphClient implements HashgraphConsensus
class HashgraphClient implements HashgraphConsensus, InscriptionMethodInterface
{
/**
* @var Client
Expand Down Expand Up @@ -339,4 +345,44 @@ public function claimNft(ClaimNft $claimNft): ClaimNftResponse {

return new ClaimNftResponse($data);
}

/**
* HCS20 Inscription Methods
*/

public function deployInscription(DeployInscription $request): InscriptionResponse
{
$response = $this->guzzle->post('api/inscription/deploy', $request->forRequest());

$data = json_decode($response->getBody()->getContents());

return new InscriptionResponse($data);
}

public function mintInscription(MintInscription $request): InscriptionResponse
{
$response = $this->guzzle->post("api/inscription/{$request->getTicker()}/mint", $request->forRequest());

$data = json_decode($response->getBody()->getContents());

return new InscriptionResponse($data);
}

public function burnInscription(BurnInscription $request): InscriptionResponse
{
$response = $this->guzzle->post("api/inscription/{$request->getTicker()}/burn", $request->forRequest());

$data = json_decode($response->getBody()->getContents());

return new InscriptionResponse($data);
}

public function transferInscription(TransferInscription $request): InscriptionResponse
{
$response = $this->guzzle->post("api/inscription/{$request->getTicker()}/transfer", $request->forRequest());

$data = json_decode($response->getBody()->getContents());

return new InscriptionResponse($data);
}
}
48 changes: 47 additions & 1 deletion src/LaravelHashgraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Trustenterprises\LaravelHashgraph;

use GuzzleHttp\Exception\GuzzleException;
use Trustenterprises\LaravelHashgraph\Contracts\InscriptionMethodInterface;
use Trustenterprises\LaravelHashgraph\Contracts\HashgraphConsensus;
use Trustenterprises\LaravelHashgraph\Events\TopicWasCreated;
use Trustenterprises\LaravelHashgraph\Exception\HashgraphException;
Expand All @@ -12,6 +13,11 @@
use Trustenterprises\LaravelHashgraph\Models\AccountTokenBalanceResponse;
use Trustenterprises\LaravelHashgraph\Models\BequestToken;
use Trustenterprises\LaravelHashgraph\Models\BequestTokenResponse;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\BurnInscription;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\DeployInscription;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\MintInscription;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\InscriptionResponse;
use Trustenterprises\LaravelHashgraph\Models\Inscriptions\TransferInscription;
use Trustenterprises\LaravelHashgraph\Models\NFT\BatchTransferNft;
use Trustenterprises\LaravelHashgraph\Models\NFT\BatchTransferNftResponse;
use Trustenterprises\LaravelHashgraph\Models\NFT\ClaimNft;
Expand Down Expand Up @@ -151,6 +157,46 @@ public static function claimNonFungibleToken(ClaimNft $claimNft) : ClaimNftRespo
return static::withAuthenticatedClient()->getClient()->claimNft($claimNft);
}

/**
* Deploy a new inscription
*
* @throws GuzzleException
*/
public static function deployInscription(DeployInscription $deployInscription) : InscriptionResponse
{
return static::withAuthenticatedClient()->getClient()->deployInscription($deployInscription);
}

/**
* Mint a new inscription
*
* @throws GuzzleException
*/
public static function mintInscription(MintInscription $mintInscription) : InscriptionResponse
{
return static::withAuthenticatedClient()->getClient()->mintInscription($mintInscription);
}

/**
* Burn a inscription
*
* @throws GuzzleException
*/
public static function burnInscription(BurnInscription $burnInscription) : InscriptionResponse
{
return static::withAuthenticatedClient()->getClient()->burnInscription($burnInscription);
}

/**
* Transfer a inscription
*
* @throws GuzzleException
*/
public static function transferInscription(TransferInscription $transferInscription) : InscriptionResponse
{
return static::withAuthenticatedClient()->getClient()->transferInscription($transferInscription);
}

/**
* Set the topic key for the transactions.
*
Expand Down Expand Up @@ -292,7 +338,7 @@ public function setTopic(string $topic_name): self
/**
* @return HashgraphClient
*/
public function getClient(): HashgraphConsensus
public function getClient(): InscriptionMethodInterface
{
return $this->client;
}
Expand Down
130 changes: 130 additions & 0 deletions src/Models/Inscriptions/BurnInscription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace Trustenterprises\LaravelHashgraph\Models\Inscriptions;

use GuzzleHttp\RequestOptions;

class BurnInscription
{
private String $from;

private int $amount;

private String $ticker;

private ?String $memo = null;

private ?String $topic_id = null;

/**
* FungibleToken constructor.
* @param string $ticker
* @param string $from
* @param int $amount
*/
public function __construct(string $ticker, string $from, int $amount)
{
$this->ticker = $ticker;
$this->from = $from;
$this->amount = $amount;
}

public function forRequest(): array
{
$payload = [
'from' => $this->getFrom(),
'amount' => $this->getAmount(),
];

if ($this->getMemo()) {
$payload['memo'] = $this->getMemo();
}

if ($this->getPrivateTopicId()) {
$payload['topic_id'] = $this->getPrivateTopicId();
}

return [ RequestOptions::JSON => $payload ];
}

/**
* @return String|string
*/
public function getTicker()
{
return $this->ticker;
}

/**
* @param String|string $ticker
*/
public function setTicker($ticker)
{
$this->ticker = $ticker;
}

/**
* @return String
*/
public function getMemo()
{
return $this->memo;
}

/**
* @param String $memo
*/
public function setMemo($memo)
{
$this->memo = $memo;
}

/**
* @return String
*/
public function getPrivateTopicId()
{
return $this->topic_id;
}

/**
* @param String $topic_id
*/
public function setPrivateTopic($topic_id)
{
$this->topic_id = $topic_id;
}

/**
* @return string|string
*/
public function getFrom()
{
return $this->from;
}

/**
* @param string|string $from
*/
public function setFrom($from)
{
$this->from = $from;
}

/**
* @return int|int
*/
public function getAmount()
{
return $this->amount;
}

/**
* @param int|int $amount
*/
public function setAmount($amount)
{
$this->amount = $amount;
}
}

Loading

0 comments on commit 008179d

Please sign in to comment.