From 3e9bde6e96840ae1494a7a0a00bf1f51a0367979 Mon Sep 17 00:00:00 2001
From: JOEELHAJJ <joeelhajj53@gmail.com>
Date: Mon, 1 Apr 2024 01:15:03 +0200
Subject: [PATCH] 4 endpoints

---
 README.md                            |  2 +-
 contracts/AssociationRegistry.jsligo | 77 ++++++++++------------------
 2 files changed, 29 insertions(+), 50 deletions(-)

diff --git a/README.md b/README.md
index f48ea3b..7fced9f 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 # QSI_Groupe1
 
-
+l'adresse du contrat:  KT1QTwmF2eptKss2FWbT1rHP5wCERL16kihQ
 
 ## Getting started
 
diff --git a/contracts/AssociationRegistry.jsligo b/contracts/AssociationRegistry.jsligo
index 27b6ce8..1da8293 100644
--- a/contracts/AssociationRegistry.jsligo
+++ b/contracts/AssociationRegistry.jsligo
@@ -1,46 +1,37 @@
-type coordinate = {
-  x: int;
-  y: int;
-  z: int;
-}
-
-type associationStatus = 
-  | ["Active"]
-  | ["Inactive"]
-  | ["Pending"];
-
 type association = {
   name: string;
   description: string;
   admin: option<address>;
 };
 
-type storage = big_map<string, association>;
+type storage = map<string, association>;
 
 type return_ = [list<operation>, storage];
 
 
-const registrationFeeInitial= 0.01tez;
+const registrationFeeInitial= 10000000mutez;
 
 // Register a new DAO
 @entry
 const registerAssociation = (association: association, storage: storage): return_ => {
-  const receiver : contract<unit> =
-  match (Tezos.get_contract_opt(Option.unopt(association.admin)) as option<contract<unit>>) {
+ //Addresse of MyAsso
+  const ownerAddress = ("tz1dV9UkbS6uMuKjQy5Vs7FSptKz8LR28oFq" as address)
+const receiver : contract<unit> =
+  match (Tezos.get_contract_opt(ownerAddress) as option<contract<unit>>) {
     when(Some(contract)): contract;
     when(None()): (failwith ("Not a contract") as contract<unit>)
   }
   // Check if walletAmount is present and greater than or equal to registrationFeeInitial
-  if (Tezos.get_amount()!= 0tez) {
-    failwith("Insufficient funds to register association");
-  }
+  // if ((Tezos.get_balance())> registrationFeeInitial) {
+  //   failwith("Insufficient funds to register association");
+  // }
   if(Some(Tezos.get_sender())== association.admin)
   {
-   const payoutOperation : operation =Tezos.transaction(unit,0.01tez,receiver);
+   const payoutOperation : operation =Tezos.transaction(unit,10000000mutez,receiver);
    const _operations : list <operation> = list([payoutOperation]);
   // Check if association already exists
   }
-  const existingAssociation = Big_map.mem(association.name, storage);
+  const existingAssociation = Map.mem(association.name, storage);
   if (existingAssociation) {
     failwith("Association already registered");
   }
@@ -52,56 +43,44 @@ const registerAssociation = (association: association, storage: storage): return
   };
 
   // Add new association to storage
-  const updatedStorage: storage = Big_map.add(association.name, newAssociation, storage);
+  const updatedStorage: storage = 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);
-  if (Option.is_none(associationOpt)) {
-    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)) {
+const changeAdmin: (params: {associationName: string, newAdmin: address}, storage: storage) => return_ = (params, storage) => {
+  const {associationName, newAdmin} = params;
+  const existingAssociation = Map.find_opt(associationName, storage);
+  const association = Option.unopt_with_error(existingAssociation, "Unknown assocation");
+  // Check if the sender is the current admin
+  if (Some(Tezos.get_sender()) != association.admin) {
     failwith("Only the current admin can change the admin");
   }
 
-  const updatedAssociation = {
+  // Update the association with the new admin address
+  const updatedAssociation: association = {
     ...association,
-    admin: Some(senderAddress)
+    admin: Some(newAdmin),
   };
 
-  const updatedStorage = Big_map.update(associationName, Some(updatedAssociation), stor);
+  // Update the storage with the modified association
+  const updatedStorage = Map.update(associationName, Some(updatedAssociation), storage);
   
   return [list([]), updatedStorage];
-}
+};
 
 //details d'une associations
 @view
 const listDetailsAssociations = (associationName:string, stor: storage): association => {
- return match(Big_map.find_opt(associationName, stor)){
+ return match(Map.find_opt(associationName, stor)){
     when(Some(value)): value;
     when(None): failwith("No value.")
   };
 }
 
-// Function to list details of all associations
-// @view
-// const listAllAssociations = (stor: storage): list<association> => {
-//   const associations: list<association> = list([]);
-//   const keys = Big_map.of_lnist(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
+@view
+const listAllAssociations = (_unused : unit,stor: storage): storage=> stor ; 
+
-- 
GitLab