Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 94
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CreateInstructionV3
0.00% covered (danger)
0.00%
0 / 94
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 serialize
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getInstruction
0.00% covered (danger)
0.00%
0 / 89
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3use Attestto\SolanaPhpSdk\Buffer;
4use Attestto\SolanaPhpSdk\PublicKey;
5use Attestto\SolanaPhpSdk\TransactionInstruction;
6use Attestto\SolanaPhpSdk\Borsh\Borsh;
7
8class CreateInstructionV3 {
9    public $tag;
10    public $name;
11    public $space;
12    public $referrerIdxOpt;
13
14    public const SCHEMA = [
15        'struct' => [
16            'tag' => 'u8',
17            'name' => 'string',
18            'space' => 'u32',
19            'referrerIdxOpt' => ['option' => 'u16'],
20        ],
21    ];
22
23    public function __construct(array $obj) {
24        $this->tag = 13;
25        $this->name = $obj['name'];
26        $this->space = $obj['space'];
27        $this->referrerIdxOpt = $obj['referrerIdxOpt'];
28    }
29
30    public function serialize(): Buffer {
31        return Borsh::serialize(self::SCHEMA, $this);
32    }
33
34    public function getInstruction(
35        PublicKey $programId,
36        PublicKey $namingServiceProgram,
37        PublicKey $rootDomain,
38        PublicKey $name,
39        PublicKey $reverseLookup,
40        PublicKey $systemProgram,
41        PublicKey $centralState,
42        PublicKey $buyer,
43        PublicKey $buyerTokenSource,
44        PublicKey $pythMappingAcc,
45        PublicKey $pythProductAcc,
46        PublicKey $pythPriceAcc,
47        PublicKey $vault,
48        PublicKey $splTokenProgram,
49        PublicKey $rentSysvar,
50        PublicKey $state,
51        ?PublicKey $referrerAccountOpt = null
52    ): TransactionInstruction {
53        $data = $this->serialize();
54        $keys = [
55            [
56                'pubkey' => $namingServiceProgram,
57                'isSigner' => false,
58                'isWritable' => false,
59            ],
60            [
61                'pubkey' => $rootDomain,
62                'isSigner' => false,
63                'isWritable' => false,
64            ],
65            [
66                'pubkey' => $name,
67                'isSigner' => false,
68                'isWritable' => true,
69            ],
70            [
71                'pubkey' => $reverseLookup,
72                'isSigner' => false,
73                'isWritable' => true,
74            ],
75            [
76                'pubkey' => $systemProgram,
77                'isSigner' => false,
78                'isWritable' => false,
79            ],
80            [
81                'pubkey' => $centralState,
82                'isSigner' => false,
83                'isWritable' => false,
84            ],
85            [
86                'pubkey' => $buyer,
87                'isSigner' => true,
88                'isWritable' => true,
89            ],
90            [
91                'pubkey' => $buyerTokenSource,
92                'isSigner' => false,
93                'isWritable' => true,
94            ],
95            [
96                'pubkey' => $pythMappingAcc,
97                'isSigner' => false,
98                'isWritable' => false,
99            ],
100            [
101                'pubkey' => $pythProductAcc,
102                'isSigner' => false,
103                'isWritable' => false,
104            ],
105            [
106                'pubkey' => $pythPriceAcc,
107                'isSigner' => false,
108                'isWritable' => false,
109            ],
110            [
111                'pubkey' => $vault,
112                'isSigner' => false,
113                'isWritable' => true,
114            ],
115            [
116                'pubkey' => $splTokenProgram,
117                'isSigner' => false,
118                'isWritable' => false,
119            ],
120            [
121                'pubkey' => $rentSysvar,
122                'isSigner' => false,
123                'isWritable' => false,
124            ],
125            [
126                'pubkey' => $state,
127                'isSigner' => false,
128                'isWritable' => false,
129            ],
130        ];
131
132        if (!is_null($referrerAccountOpt)) {
133            $keys[] = [
134                'pubkey' => $referrerAccountOpt,
135                'isSigner' => false,
136                'isWritable' => true,
137            ];
138        }
139
140        return new TransactionInstruction([
141            'keys' => $keys,
142            'programId' => $programId,
143            'data' => $data,
144        ]);
145    }
146}
147
148?>