diff --git a/contracts/AssociationRegistry.jsligo b/contracts/AssociationRegistry.jsligo index 3bb4d02c1961d7f9f47ca04f294c9bd2bcc684bf..44c4c9e2d0189b367bc74a347193a194244db630 100644 --- a/contracts/AssociationRegistry.jsligo +++ b/contracts/AssociationRegistry.jsligo @@ -1,4 +1,4 @@ - type coordinate = { +type coordinate = { x: int; y: int; z: int; @@ -15,10 +15,7 @@ type association = { admin: option<address>; }; -type storage = { - associations: big_map<string, association>, - associationNames: list<string> -}; +type storage = big_map<string, association>; type return_ = [list<operation>, storage]; @@ -28,29 +25,34 @@ const registrationFeeInitial= 10 as tez; // Register a new DAO @entry const registerAssociation = (association: association, storage: storage): return_ => { + // Check if walletAmount is present and greater than or equal to registrationFeeInitial if (Tezos.get_amount () < registrationFeeInitial) { failwith("Insufficient funds to register association"); } - const existingAssociation = Big_map.mem(association.name, storage.associations); + + // Check if association already exists + const existingAssociation = Big_map.mem(association.name, storage); if (existingAssociation) { failwith("Association already registered"); } - const updatedAssociations: big_map<string, association> = Big_map.add(association.name, association, storage.associations); - const updatedAssociationNames: list<string> = List.cons(association.name, storage.associationNames); -const updatedStorage: storage = { - associations: updatedAssociations, - associationNames: updatedAssociationNames + // Deduct registration fee from wallet amount and create new association + const newAssociation: association = { + ...association, }; + // Add new association to storage + const updatedStorage: storage = Big_map.add(association.name, newAssociation, storage); + return [list([]), updatedStorage]; } //Change Admin + @entry const changeAdmin = (associationName: string, stor: storage): return_ => { - const associationOpt = Big_map.find_opt(associationName, stor.associations); + const associationOpt = Big_map.find_opt(associationName, stor); if (Option.is_none(associationOpt)) { failwith("Unknown association cannot change admin"); } @@ -66,12 +68,7 @@ const changeAdmin = (associationName: string, stor: storage): return_ => { admin: Some(senderAddress) }; - const updatedAssociations = Big_map.update(associationName, Some(updatedAssociation), stor.associations); - - const updatedStorage: storage = { - associations: updatedAssociations, - associationNames: stor.associationNames // This remains unchanged - }; + const updatedStorage = Big_map.update(associationName, Some(updatedAssociation), stor); return [list([]), updatedStorage]; } @@ -79,27 +76,22 @@ const changeAdmin = (associationName: string, stor: storage): return_ => { //details d'une associations @view const listDetailsAssociations = (associationName:string, stor: storage): association => { - return match(Big_map.find_opt(associationName, stor.associations)){ + return match(Big_map.find_opt(associationName, stor)){ when(Some(value)): value; when(None): failwith("No value.") }; } -//todo Function to list details of all associations -@view -const listAllAssociations = (_:string, stor: storage): list<association> => { - let associationsList: list<association> = list([]); - - // Iterate over each association name in the storage's list - for (const associationName of stor.associationNames) { - // Attempt to find the association details in the big_map using the name - const associationOpt = Big_map.find_opt(associationName, stor.associations); - - // If the association is found (not None), add it to the associationsList - if (Option.is_some(associationOpt)) { - const association = Option.unopt(associationOpt); - associationsList = List.cons(association, associationsList); - } - } - return associationsList; -} +// Function to list details of all associations +// @view +// const listAllAssociations = (stor: storage): list<association> => { +// const associations: list<association> = list([]); +// const keys = Big_map.of_list(stor); +// for (const name of keys) { +// const association = Big_map.find_opt(name, stor); +// if (Option.is_some(association)) { +// associations.push(Option.unopt(association)); +// } +// } +// return associations; +// } \ No newline at end of file diff --git a/deploy/.env b/deploy/.env index 6afb24d51dbda033e0ad4421a001181cb0c283aa..8db42feca984fc5fc38b12084665e2998cb49849 100644 --- a/deploy/.env +++ b/deploy/.env @@ -1,7 +1,8 @@ # Required: Your private key -PK=...... +PK= # Required: see see https://tezostaquito.io/docs/rpc_nodes/ RPC_URL=https://ghostnet.tezos.marigold.dev/ #Contract address: -- KT1PCg4GbtF5LQQhHmY4t1qNYVspnitKGHgm \ No newline at end of file +# KT1PCg4GbtF5LQQhHmY4t1qNYVspnitKGHgm +# new adresse : KT1NMZvpAEQmezU8kHKzgi9PjysoH4VTcB3P \ No newline at end of file