Skip to content
Snippets Groups Projects
Commit e5efa1a1 authored by Joe El hajj's avatar Joe El hajj
Browse files

Update AssociationRegistry.jsligo modify change admin

parent 0065edd1
Branches
No related tags found
No related merge requests found
type coordinate = { type coordinate = {
x: int; x: int;
y: int; y: int;
...@@ -28,8 +27,8 @@ const registrationFeeInitial: tez = 10 as tez; ...@@ -28,8 +27,8 @@ const registrationFeeInitial: tez = 10 as tez;
//Register a new DAO //Register a new DAO
@entry @entry
function registerAssociation(newAssociation: association, storage: storage): return_ { function registerAssociation(newAssociation: association, storage: storage): return_ {
const existingAssociation = Big_map.find_opt(newAssociation.name, storage); const existingAssociation = Big_map.mem(newAssociation.name, storage);
if (Option.is_some(existingAssociation)) { if (existingAssociation) {
failwith("Association already registered"); failwith("Association already registered");
} }
const updatedStorage: storage = Big_map.add(newAssociation.name, { const updatedStorage: storage = Big_map.add(newAssociation.name, {
...@@ -39,38 +38,47 @@ function registerAssociation(newAssociation: association, storage: storage): ret ...@@ -39,38 +38,47 @@ function registerAssociation(newAssociation: association, storage: storage): ret
// Within the registerAssociation function // Within the registerAssociation function
const noOperations : list<operation> = list([]); const noOperations : list<operation> = list([]);
const result: return_ = [noOperations, updatedStorage]; const result: return_ = [noOperations, updatedStorage];
return result; return result;
} }
//Change Admin //Change Admin
@entry @entry
function changeAdmin(associationName, newAdmin, storage) { function changeAdmin(associationName :string, newAdmin : address, stor: storage) {
const associationOpt = Big_map.find_opt(associationName, storage); const associationOpt = Big_map.find_opt(associationName, stor);
if (Option.is_none(associationOpt)) { if (Option.is_none(associationOpt)) {
failwith("Unknown association cannot change admin"); failwith("Unknown association cannot change admin");}
} const association = Option.unopt_with_error(associationOpt,"Failed to get association");
const association = Option.unopt(associationOpt, () => failwith("Failed to get association"));
//todo //todo
if (Some(Tezos.get_sender()) != association.admin) { const senderAddress = Tezos.get_sender();
if (!Option.is_some(association.admin) || senderAddress != Option.unopt(association.admin)) {
failwith("Only the current admin can change the admin"); failwith("Only the current admin can change the admin");
} }
const updatedAssociation = { const updatedAssociation = {
...association, ...association,
admin: Some(newAdmin) admin: Some(newAdmin)
}
const updatedStorage = Big_map.update(associationName, Some(updatedAssociation), stor);
return [list([],updatedStorage)]
}; };
/*
@entry
const destroy = (planetName: string, stor: storage): return_ => {
const existingPlanet = Big_map.find_opt(planetName, stor);
const planet = Option.unopt_with_error(existingPlanet, "Unknown planet cannot be destroyed");
const senderAddress = Tezos.get_sender();
if (!Option.is_some(planet.lord) || !Tezos.address_equals(senderAddress, Option.unopt(planet.lord))) {
failwith("Only the lord of the planet can destroy it");
}
const updatedStorage = Big_map.remove(planetName, stor);
const updatedStorage = Big_map.update(associationName, Some(updatedAssociation), storage); return [list([]), updatedStorage];
};
*/
const noOperations: list<operation> = [];
const result: return_ = [noOperations, updatedStorage];
return result;
}
//List associations //List associations
@view @view
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment