Last active
January 11, 2021 05:22
-
-
Save t8/db0dce32c0dc45e490158242c1d73cab to your computer and use it in GitHub Desktop.
A SmartWeave contract for deploying dynamic permaweb apps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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