import {
ActionPostResponse,
ACTIONS_CORS_HEADERS,
createPostResponse,
ActionGetResponse,
ActionPostRequest,
} from "@solana/actions";
import { clusterApiUrl } from "@solana/web3.js";
import { createTree } from "@metaplex-foundation/mpl-bubblegum";
import { toWeb3JsTransaction } from "@metaplex-foundation/umi-web3js-adapters";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import {
createNoopSigner,
createSignerFromKeypair,
generateSigner,
publicKey,
PublicKey,
signerIdentity,
signerPayer,
} from "@metaplex-foundation/umi";
export const GET = async (req: Request) => {
const payload: ActionGetResponse = {
title: "Actions Example - Create a merkle tree",
icon: new URL("/solana_devs.jpg", new URL(req.url).origin).toString(),
description:
"Create a single state compression tree on solana for use with compressed NFTs",
label: "Send Memo",
links: {
actions: [
{
label: "Create Tree",
href: "/api/actions/create-tree?depth={depth}&buffer={buffer}&canopy={canopy}",
parameters: [
{
name: "depth",
required: true,
label: "Max depth for the tree",
},
{
name: "buffer",
required: true,
label: "Max buffer size for the tree",
},
{
name: "canopy",
required: true,
label: "Canopy depth for the tree",
},
],
},
],
},
};
return Response.json(payload, {
headers: ACTIONS_CORS_HEADERS,
});
};
export const OPTIONS = GET;
export const POST = async (req: Request) => {
try {
const body: ActionPostRequest = await req.json();
let account: PublicKey;
try {
account = publicKey(body.account);
} catch (err) {
return new Response('Invalid "account" provided', {
status: 400,
headers: ACTIONS_CORS_HEADERS,
});
}
const url = new URL(req.url);
const treeConfig = {
maxBufferSize: 0,
canopyDepth: 0,
maxDepth: 0,
};
try {
let depth = url.searchParams.get("depth");
let canopy = url.searchParams.get("canopy");
let buffer = url.searchParams.get("buffer");
if (!!depth) treeConfig.maxDepth = parseInt(depth);
if (!!canopy) treeConfig.canopyDepth = parseInt(canopy);