Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| NtfRecordAccount | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| deserialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| retrieve | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| findKey | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Attestto\SolanaPhpSdk\Accounts; |
| 4 | |
| 5 | use Attestto\SolanaPhpSdk\Accounts\Did\VerificationMethodStruct; |
| 6 | use Attestto\SolanaPhpSdk\Accounts\Did\ServiceStruct; |
| 7 | use Attestto\SolanaPhpSdk\Borsh\Borsh; |
| 8 | use Attestto\SolanaPhpSdk\Borsh\BorshDeserializable; |
| 9 | use Attestto\SolanaPhpSdk\Connection; |
| 10 | use Attestto\SolanaPhpSdk\PublicKey; |
| 11 | use Attestto\SolanaPhpSdk\Exceptions\SNSError; |
| 12 | use Attestto\SolanaPhpSdk\Util\Buffer; |
| 13 | |
| 14 | |
| 15 | class NtfRecordAccount |
| 16 | { |
| 17 | |
| 18 | use BorshDeserializable; |
| 19 | |
| 20 | |
| 21 | public const SCHEMA = [ |
| 22 | self::class => [ |
| 23 | 'kind' => 'struct', |
| 24 | 'fields' => [ |
| 25 | ['tag', ['u8']], |
| 26 | ['nonce', ['u8']], |
| 27 | ['nameAccount', ['u8']], // len 32 |
| 28 | ['owner', ['u8']], // len 32 |
| 29 | ['nftMint', ['u8']], // len 32 |
| 30 | ], |
| 31 | ], |
| 32 | ]; |
| 33 | |
| 34 | public static function deserialize(array $buffer): self |
| 35 | { |
| 36 | return Borsh::deserialize(self::SCHEMA, self::class, $buffer); |
| 37 | } |
| 38 | |
| 39 | public static function retrieve(Connection $connection, PublicKey $key): self |
| 40 | { |
| 41 | $accountInfo = $connection->getAccountInfo($key); |
| 42 | if (!$accountInfo || !$accountInfo['data']) { |
| 43 | throw new \Exception("NFT record not found"); |
| 44 | } |
| 45 | $base64String = base64_decode($accountInfo['data']); |
| 46 | $uint8Array = array_values(unpack('C*', $base64String)); |
| 47 | return self::deserialize($uint8Array); |
| 48 | } |
| 49 | |
| 50 | public static function findKey(PublicKey $nameAccount, PublicKey $programId) |
| 51 | { |
| 52 | return PublicKey::findProgramAddress( |
| 53 | [Buffer::from("nft_record"), $nameAccount->toBuffer()], |
| 54 | $programId |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | } |
| 59 |