kit-squared 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/library/program.js +52 -45
- package/package.json +1 -1
package/dist/library/program.js
CHANGED
|
@@ -116,14 +116,16 @@ export async function createProgram(programClient, idl, signer = null, noEvents
|
|
|
116
116
|
const _eventTranslation = {};
|
|
117
117
|
// Events
|
|
118
118
|
const _events = {};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
name
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
if (idl.events) {
|
|
120
|
+
for (let event of idl.events) {
|
|
121
|
+
const nameCamel = pascalToCamel(event.name);
|
|
122
|
+
_events[event.name] = {
|
|
123
|
+
name: nameCamel,
|
|
124
|
+
discriminator: event.discriminator,
|
|
125
|
+
codec: programClient[`get${event.name}Codec`](),
|
|
126
|
+
};
|
|
127
|
+
_eventTranslation[nameCamel] = Event();
|
|
128
|
+
}
|
|
127
129
|
}
|
|
128
130
|
// Set up an abort controller.
|
|
129
131
|
const abortController = new AbortController();
|
|
@@ -351,9 +353,10 @@ export async function createProgram(programClient, idl, signer = null, noEvents
|
|
|
351
353
|
// use [property] of that.
|
|
352
354
|
// Will need to infer type from the account
|
|
353
355
|
const accountData = await readAccount(seed.account, ixProps[parentName]);
|
|
356
|
+
const propertyCamel = snakeToCamel(property);
|
|
354
357
|
if (!accountData)
|
|
355
358
|
throw new Error(`Unable to read account relating to ${seed.account}: ${ixProps[parentName]}`);
|
|
356
|
-
const value = accountData[
|
|
359
|
+
const value = accountData[propertyCamel];
|
|
357
360
|
const propertyType = getAccountPropertyType(seed.account, property);
|
|
358
361
|
if (!propertyType)
|
|
359
362
|
throw new Error(`Unable to read property type relating to ${seed.account}: ${property}`);
|
|
@@ -400,44 +403,48 @@ export async function createProgram(programClient, idl, signer = null, noEvents
|
|
|
400
403
|
}
|
|
401
404
|
}
|
|
402
405
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
406
|
+
if (idl.instructions) {
|
|
407
|
+
for (let instruction of idl.instructions) {
|
|
408
|
+
const name = instruction.name;
|
|
409
|
+
const nameCamel = snakeToCamel(name);
|
|
410
|
+
const NamePascal = snakeToPascal(name);
|
|
411
|
+
const argTypes = instruction.args;
|
|
412
|
+
ixs[nameCamel] = async function () {
|
|
413
|
+
if (arguments.length !== argTypes.length) {
|
|
414
|
+
throw new Error(`Incorrect arguments provided for ${name}. Received ${arguments.length}, expected ${argTypes.length}.`);
|
|
415
|
+
}
|
|
416
|
+
let ixProps = {};
|
|
417
|
+
for (let account in addedAccounts) {
|
|
418
|
+
ixProps[account] = addedAccounts[account];
|
|
419
|
+
}
|
|
420
|
+
for (let i = 0; i < arguments.length; i++) {
|
|
421
|
+
ixProps[snakeToCamel(argTypes[i].name)] = arguments[i];
|
|
422
|
+
}
|
|
423
|
+
await addIxAccounts(instruction, ixProps);
|
|
424
|
+
return programClient[`get${NamePascal}Instruction`](ixProps);
|
|
425
|
+
};
|
|
426
|
+
tx[nameCamel] = async function () {
|
|
427
|
+
let ix = await ixs[nameCamel](...arguments);
|
|
428
|
+
await transactSingle(ix, nameCamel);
|
|
429
|
+
};
|
|
430
|
+
}
|
|
426
431
|
}
|
|
427
432
|
let account = {};
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
433
|
+
if (idl.accounts) {
|
|
434
|
+
for (let a of idl.accounts) {
|
|
435
|
+
const nameCamel = pascalToCamel(a.name);
|
|
436
|
+
account[nameCamel] = async function (addressOrSeeds) {
|
|
437
|
+
if (Array.isArray(addressOrSeeds)) {
|
|
438
|
+
// it's array, assume it's seeds
|
|
439
|
+
const address = await pda(addressOrSeeds);
|
|
440
|
+
return await readAccount(nameCamel, address);
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
// assume address
|
|
444
|
+
return await readAccount(nameCamel, addressOrSeeds);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
}
|
|
441
448
|
}
|
|
442
449
|
const returns = {
|
|
443
450
|
on,
|