Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion codama.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
instructionAccountDisplayNode,
instructionRemainingAccountsNode,
resolverValueNode,
rootNodeVisitor,
} from 'codama';
import { writeFileSync } from 'node:fs';

const executeRemainingAccounts = instructionRemainingAccountsNode(
resolverValueNode('resolveExecutionMessageAccounts', {
Expand Down Expand Up @@ -39,6 +41,17 @@ const addRemainingAccounts = remainingAccounts => node => {
return { ...node, remainingAccounts: [remainingAccounts] };
};

// Writes one IDL per program, e.g. for uploading to the Program Metadata program.
export const writeProgramIdlsVisitor = paths =>
rootNodeVisitor(root => {
const programs = [root.program, ...root.additionalPrograms];
for (const [name, path] of Object.entries(paths)) {
const program = programs.find(p => p.name === name);
if (!program) throw new Error(`Program "${name}" not found in IDL`);
writeFileSync(path, JSON.stringify({ ...root, program, additionalPrograms: [] }, null, 2));
}
});

export default {
idl: 'target/codama-idl/signer-interface.json',
additionalIdls: [
Expand All @@ -63,7 +76,19 @@ export default {
},
],
scripts: {
idl: { from: '@codama/renderers-core#writeIdlVisitor', args: ['idl.json'] },
idl: [
{ from: '@codama/renderers-core#writeIdlVisitor', args: ['idl.json'] },
{
from: './codama.mjs#writeProgramIdlsVisitor',
args: [
{
ed25519Signer: 'signer/idl.json',
messageExecutor: 'executor/idl.json',
nonce: 'nonce/idl.json',
},
],
},
],
js: {
from: '@codama/renderers-js',
args: [
Expand Down
174 changes: 174 additions & 0 deletions executor/idl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{
"kind": "rootNode",
"standard": "codama",
"version": "1.9.2",
"program": {
"kind": "programNode",
"name": "messageExecutor",
"publicKey": "ExecxgyHYsAXB4c5dZodV1zJZ9hqfsDCYkRDRATrpkFR",
"version": "0.1.0",
"instructions": [
{
"kind": "instructionNode",
"name": "execute",
"optionalAccountStrategy": "programId",
"accounts": [
{
"kind": "instructionAccountNode",
"name": "nonceAuthority",
"isWritable": false,
"isSigner": true,
"isOptional": false,
"docs": [
"Authority signer for the nonce account"
],
"display": {
"kind": "instructionAccountDisplayNode",
"label": "Nonce authority"
}
},
{
"kind": "instructionAccountNode",
"name": "nonceAccount",
"isWritable": true,
"isSigner": false,
"isOptional": false,
"docs": [
"Nonce account consumed for replay protection"
],
"display": {
"kind": "instructionAccountDisplayNode",
"label": "Nonce account to advance"
}
},
{
"kind": "instructionAccountNode",
"name": "nonceProgram",
"isWritable": false,
"isSigner": false,
"isOptional": false,
"docs": [
"SPL Nonce program"
],
"defaultValue": {
"kind": "publicKeyValueNode",
"publicKey": "Noncediea1fH12usShuQAz28UhgAeuE5Maf32LsMUQB"
},
"display": {
"kind": "instructionAccountDisplayNode",
"skip": "always"
}
}
],
"arguments": [
{
"kind": "instructionArgumentNode",
"name": "discriminator",
"defaultValueStrategy": "omitted",
"type": {
"kind": "numberTypeNode",
"format": "u8",
"endian": "le"
},
"defaultValue": {
"kind": "numberValueNode",
"number": 0
},
"display": {
"kind": "structFieldDisplayNode",
"skip": "always"
}
},
{
"kind": "instructionArgumentNode",
"name": "message",
"type": {
"kind": "bytesTypeNode"
},
"display": {
"kind": "structFieldDisplayNode",
"label": "Execution message"
}
}
],
"discriminators": [
{
"kind": "fieldDiscriminatorNode",
"name": "discriminator",
"offset": 0
}
],
"display": {
"kind": "instructionDisplayNode",
"intent": "Execute all instructions in an execution message"
},
"remainingAccounts": [
{
"kind": "instructionRemainingAccountsNode",
"isOptional": false,
"isSigner": "either",
"docs": [
"One account for each key in the execution message's static account-key list, in the same order."
],
"value": {
"kind": "resolverValueNode",
"name": "resolveExecutionMessageAccounts",
"docs": [
"Preserves each execution message account's signer and writable role."
],
"dependsOn": [
{
"kind": "argumentValueNode",
"name": "message"
}
]
},
"display": {
"kind": "instructionAccountDisplayNode",
"label": "Execution message accounts"
}
}
]
}
],
"errors": [
{
"kind": "errorNode",
"name": "invalidNonceAccount",
"code": 0,
"message": "The nonce account data could not be decoded as nonce state"
},
{
"kind": "errorNode",
"name": "invalidMessage",
"code": 1,
"message": "The v1 message fails sanitization or contains duplicate keys"
},
{
"kind": "errorNode",
"name": "messageAccountsMismatch",
"code": 2,
"message": "The passed accounts do not match the execution message's account keys"
},
{
"kind": "errorNode",
"name": "nonceMismatch",
"code": 3,
"message": "The message's recent blockhash does not match the stored nonce"
},
{
"kind": "errorNode",
"name": "unsupportedMessageVersion",
"code": 4,
"message": "The execution message is not a v1 message"
},
{
"kind": "errorNode",
"name": "unsupportedTransactionConfig",
"code": 5,
"message": "The execution message sets transaction config fields"
}
]
},
"additionalPrograms": []
}
Loading
Loading