Select Git revision
AssociationRegistry.jsligo
-
Joe El hajj authoredJoe El hajj authored
AssociationRegistry.jsligo 1.94 KiB
type coordinate = {
x: int;
y: int;
z: int;
}
type associationStatus =
| ["Active"]
| ["Inactive"]
| ["Pending"];
type association = {
name: string;
coordinate: coordinate;
status: associationStatus;
admin: option<address>;
registrationFee: tez;
};
type storage = big_map<string, association>;
type return_ = [list<operation>, storage];
const registrationFeeInitial: tez = 10 as tez;
//Register a new DAO
@entry
function registerAssociation(newAssociation: association, storage: storage): return_ {
const existingAssociation = Big_map.find_opt(newAssociation.name, storage);
if (Option.is_some(existingAssociation)) {
failwith("Association already registered");
}
const updatedStorage: storage = Big_map.add(newAssociation.name, {
...newAssociation,
registrationFee: registrationFeeInitial
}, storage);
// Within the registerAssociation function
const noOperations : list<operation> = list([]);
const result: return_ = [noOperations, updatedStorage];
return result;
}
//Change Admin
@entry
function changeAdmin(associationName, newAdmin, storage) {
const associationOpt = Big_map.find_opt(associationName, storage);
if (Option.is_none(associationOpt)) {
failwith("Unknown association cannot change admin");
}
const association = Option.unopt(associationOpt, () => failwith("Failed to get association"));
//todo
if (Some(Tezos.get_sender()) != association.admin) {
failwith("Only the current admin can change the admin");
}
const updatedAssociation = {
...association,
admin: Some(newAdmin)
};
const updatedStorage = Big_map.update(associationName, Some(updatedAssociation), storage);
const noOperations: list<operation> = [];
const result: return_ = [noOperations, updatedStorage];
return result;
}
//List associations
@view
function getAssociationDetails(associationName: string, storage: storage): option<association> {
return Big_map.find_opt(associationName, storage);
}