kit-squared 0.2.5 → 0.2.7
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 +53 -45
- package/package.json +1 -1
package/dist/library/program.js
CHANGED
|
@@ -77,6 +77,7 @@ export async function transact(ixs = [], names = []) {
|
|
|
77
77
|
onConfirm.trigger(names);
|
|
78
78
|
}
|
|
79
79
|
catch (e) {
|
|
80
|
+
console.error(e);
|
|
80
81
|
if (_txWasCancelled(e)) {
|
|
81
82
|
// TODO: properly catch this and other errors
|
|
82
83
|
onCancel.trigger(names);
|
|
@@ -116,14 +117,16 @@ export async function createProgram(programClient, idl, signer = null, noEvents
|
|
|
116
117
|
const _eventTranslation = {};
|
|
117
118
|
// Events
|
|
118
119
|
const _events = {};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
name
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
if (idl.events) {
|
|
121
|
+
for (let event of idl.events) {
|
|
122
|
+
const nameCamel = pascalToCamel(event.name);
|
|
123
|
+
_events[event.name] = {
|
|
124
|
+
name: nameCamel,
|
|
125
|
+
discriminator: event.discriminator,
|
|
126
|
+
codec: programClient[`get${event.name}Codec`](),
|
|
127
|
+
};
|
|
128
|
+
_eventTranslation[nameCamel] = Event();
|
|
129
|
+
}
|
|
127
130
|
}
|
|
128
131
|
// Set up an abort controller.
|
|
129
132
|
const abortController = new AbortController();
|
|
@@ -351,9 +354,10 @@ export async function createProgram(programClient, idl, signer = null, noEvents
|
|
|
351
354
|
// use [property] of that.
|
|
352
355
|
// Will need to infer type from the account
|
|
353
356
|
const accountData = await readAccount(seed.account, ixProps[parentName]);
|
|
357
|
+
const propertyCamel = snakeToCamel(property);
|
|
354
358
|
if (!accountData)
|
|
355
359
|
throw new Error(`Unable to read account relating to ${seed.account}: ${ixProps[parentName]}`);
|
|
356
|
-
const value = accountData[
|
|
360
|
+
const value = accountData[propertyCamel];
|
|
357
361
|
const propertyType = getAccountPropertyType(seed.account, property);
|
|
358
362
|
if (!propertyType)
|
|
359
363
|
throw new Error(`Unable to read property type relating to ${seed.account}: ${property}`);
|
|
@@ -400,44 +404,48 @@ export async function createProgram(programClient, idl, signer = null, noEvents
|
|
|
400
404
|
}
|
|
401
405
|
}
|
|
402
406
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
407
|
+
if (idl.instructions) {
|
|
408
|
+
for (let instruction of idl.instructions) {
|
|
409
|
+
const name = instruction.name;
|
|
410
|
+
const nameCamel = snakeToCamel(name);
|
|
411
|
+
const NamePascal = snakeToPascal(name);
|
|
412
|
+
const argTypes = instruction.args;
|
|
413
|
+
ixs[nameCamel] = async function () {
|
|
414
|
+
if (arguments.length !== argTypes.length) {
|
|
415
|
+
throw new Error(`Incorrect arguments provided for ${name}. Received ${arguments.length}, expected ${argTypes.length}.`);
|
|
416
|
+
}
|
|
417
|
+
let ixProps = {};
|
|
418
|
+
for (let account in addedAccounts) {
|
|
419
|
+
ixProps[account] = addedAccounts[account];
|
|
420
|
+
}
|
|
421
|
+
for (let i = 0; i < arguments.length; i++) {
|
|
422
|
+
ixProps[snakeToCamel(argTypes[i].name)] = arguments[i];
|
|
423
|
+
}
|
|
424
|
+
await addIxAccounts(instruction, ixProps);
|
|
425
|
+
return programClient[`get${NamePascal}Instruction`](ixProps);
|
|
426
|
+
};
|
|
427
|
+
tx[nameCamel] = async function () {
|
|
428
|
+
let ix = await ixs[nameCamel](...arguments);
|
|
429
|
+
await transactSingle(ix, nameCamel);
|
|
430
|
+
};
|
|
431
|
+
}
|
|
426
432
|
}
|
|
427
433
|
let account = {};
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
434
|
+
if (idl.accounts) {
|
|
435
|
+
for (let a of idl.accounts) {
|
|
436
|
+
const nameCamel = pascalToCamel(a.name);
|
|
437
|
+
account[nameCamel] = async function (addressOrSeeds) {
|
|
438
|
+
if (Array.isArray(addressOrSeeds)) {
|
|
439
|
+
// it's array, assume it's seeds
|
|
440
|
+
const address = await pda(addressOrSeeds);
|
|
441
|
+
return await readAccount(nameCamel, address);
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
// assume address
|
|
445
|
+
return await readAccount(nameCamel, addressOrSeeds);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
}
|
|
441
449
|
}
|
|
442
450
|
const returns = {
|
|
443
451
|
on,
|