Skip to content

Instantly share code, notes, and snippets.

@t8
Last active January 11, 2021 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t8/db0dce32c0dc45e490158242c1d73cab to your computer and use it in GitHub Desktop.
Save t8/db0dce32c0dc45e490158242c1d73cab to your computer and use it in GitHub Desktop.
A SmartWeave contract for deploying dynamic permaweb apps.
export function handle(state, action) {
const authors = state.authors;
const deployments = state.deployments;
const input = action.input;
const caller = action.caller;
if (input.function === "deploy") {
const deployment = input.deployment;
if (!authors.includes(caller)) {
throw new ContractError(`${caller} is not an author and cannot deploy`);
}
if (!deployment) {
throw new ContractError("Missing deployment hash");
}
deployments.push(deployment);
return { state };
}
if (input.function === "nominate") {
const nominee = input.nominee;
if (!nominee) {
throw new ContractError("Missing a nominee");
}
if (authors.includes(nominee)) {
throw new ContractError(`${nominee} is already an author`);
}
if (!authors.includes(caller)) {
throw new ContractError(`${caller} is not an author and cannot nominate`);
}
authors.push(nominee);
return { state };
}
if (input.function === "getAuthors") {
return {
result: {
authors
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment