Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Account | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| fromBuffer | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAccount | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Attestto\SolanaPhpSdk\State; |
| 4 | |
| 5 | use Attestto\SolanaPhpSdk\Borsh\Borsh; |
| 6 | use Attestto\SolanaPhpSdk\Borsh\BorshObject; |
| 7 | use Attestto\SolanaPhpSdk\Connection; |
| 8 | use Attestto\SolanaPhpSdk\Exceptions\AccountNotFoundException; |
| 9 | use Attestto\SolanaPhpSdk\PublicKey; |
| 10 | use Attestto\SolanaPhpSdk\Util\Commitment; |
| 11 | |
| 12 | /** |
| 13 | * @property mixed|null $mint |
| 14 | */ |
| 15 | class Account |
| 16 | { |
| 17 | |
| 18 | use BorshObject; |
| 19 | protected const TOKEN_PROGRAM_ID = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; |
| 20 | private static PublicKey $address; |
| 21 | private static mixed $tlvData; |
| 22 | |
| 23 | |
| 24 | |
| 25 | public const SCHEMA = [ |
| 26 | self::class => [ |
| 27 | 'kind' => 'struct', |
| 28 | 'fields' => [ |
| 29 | ['mint', 'pubKey'], |
| 30 | ['owner', 'pubKey'], |
| 31 | ['amount', 'u64'], |
| 32 | ['delegateOption', 'u32'], |
| 33 | ['delegate', 'pubKey'], |
| 34 | ['state', 'u8'], |
| 35 | ['isNativeOption', 'u8'], |
| 36 | ['isNative', 'u8'], |
| 37 | ['delegatedAmount', 'u64'], |
| 38 | ['closeAuthorityOption', 'u32'], |
| 39 | ['closeAuthority', 'pubKey'] |
| 40 | ], |
| 41 | ], |
| 42 | ]; |
| 43 | |
| 44 | public static function fromBuffer(array $buffer): self |
| 45 | { |
| 46 | return Borsh::deserialize(self::SCHEMA, self::class, $buffer); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @throws AccountNotFoundException |
| 51 | */ |
| 52 | public static function getAccount( |
| 53 | Connection $connection, |
| 54 | PublicKey $accountPublicKeyOnbject, |
| 55 | Commitment $commitment = null, |
| 56 | $programId = new PublicKey(self::TOKEN_PROGRAM_ID) |
| 57 | ): Account |
| 58 | { |
| 59 | try { |
| 60 | $info = $connection->getAccountInfo($accountPublicKeyOnbject, $commitment); |
| 61 | self::$address = $accountPublicKeyOnbject; |
| 62 | self::$tlvData = $info['data']; |
| 63 | $base64Data = $info['data']['0']; |
| 64 | $base64String = base64_decode($base64Data); |
| 65 | $uint8Array = array_values(unpack('C*', $base64String)); |
| 66 | return self::fromBuffer($uint8Array); |
| 67 | } catch (AccountNotFoundException $e) { |
| 68 | throw new AccountNotFoundException(); |
| 69 | } |
| 70 | } |
| 71 | } |