// EVENT: VOTE
// START: 2024-01-01T00:00:00.000Z
// END: 2024-02-01T00:00:00.000Z
// COMUNITY: Example Community
// TYPE: Anonimous vote
// QUESTION: ¿Should we modify the constitution to allow ...?
// OPTION_1: Yes
// OPTION_2: No
var seleccion =
// INPUT
{
voto: "Null",
};
// INPUT END
var checkVoter = get({
scope: contract.hash,
name: "voters/" + block.by,
});
if (checkVoter) {
throw Error("Rejected, already voted.");
} else {
if (block.timestamp < 1687628800000) {
if (
seleccion.voto === "Yes" ||
seleccion.voto === "No" ||
seleccion.voto === "Null"
) {
var votes = get({
scope: contract.hash,
name: "votes/" + seleccion.voto,
}) || 0;
put({
scope: contract.hash,
name: "votes/" + seleccion.voto,
value: votes + 1,
});
put({
scope: contract.hash,
name: "voters/" + block.by,
value: seleccion.voto,
});
result({
message:
"Vote (" +
seleccion.voto +
") by user " +
block.by +
", correctly registered.",
});
} else {
throw Error("Invalid vote:" + seleccion.voto);
}
} else {
throw Error("Votation ended.");
}
}
// IMPORT d1d259e37...037401fdb
{
voto: "Yes"
}
// IMPORT d1d259e37...037401fdb
{
voto: "No"
}