From eea44a92ece20f6c56919a6a4ed354fa80a869fb Mon Sep 17 00:00:00 2001 From: Joe El hajj <joe.elhajj.etu@univ-lille.fr> Date: Tue, 19 Mar 2024 15:29:56 +0100 Subject: [PATCH] Update AssociationRegistry.jsligo --- contracts/AssociationRegistry.jsligo | 81 +++++++--------------------- 1 file changed, 19 insertions(+), 62 deletions(-) diff --git a/contracts/AssociationRegistry.jsligo b/contracts/AssociationRegistry.jsligo index 6c05400..799471e 100644 --- a/contracts/AssociationRegistry.jsligo +++ b/contracts/AssociationRegistry.jsligo @@ -1,87 +1,44 @@ -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 = 10 as tez; -const registrationFeeInitial= 10 as tez; - -//Register a new DAO @entry -function registerAssociation(newAssociation: association, storage: storage): return_ { - const existingAssociation = Big_map.mem(newAssociation.name, storage); - if (existingAssociation) { +function registerAssociation(newAssociation, storage) { + const existingAssociationOpt = Big_map.find_opt(newAssociation.name, storage); + if (Option.is_some(existingAssociationOpt)) { failwith("Association already registered"); } - const updatedStorage: storage = Big_map.add(newAssociation.name, { + + const updatedStorage = 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; + const noOperations = ([] : list<operation>); + return [noOperations, updatedStorage]; } - - -//Change Admin @entry -function changeAdmin(associationName :string, newAdmin : address, stor: storage) { +function changeAdmin(associationName, newAdmin, stor) { const associationOpt = Big_map.find_opt(associationName, stor); if (Option.is_none(associationOpt)) { - failwith("Unknown association cannot change admin");} - const association = Option.unopt_with_error(associationOpt,"Failed to get association"); - //todo + failwith("Unknown association cannot change admin"); + } + + const association = Option.unopt_with_error(associationOpt, "Failed to get association"); const senderAddress = Tezos.get_sender(); - if (!Option.is_some(association.admin) || senderAddress != Option.unopt(association.admin)) { + if (!Option.is_some(association.admin) || senderAddress != Option.unopt(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), 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); - - return [list([]), updatedStorage]; -}; -*/ + const updatedStorage = Big_map.update(associationName, Some(updatedAssociation), stor); + return [[], updatedStorage]; +} -//List associations @view -function getAssociationDetails(associationName: string, storage: storage): option<association> { +function getAssociationDetails(associationName, storage) { return Big_map.find_opt(associationName, storage); } -- GitLab