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

4 endpoints

parent 31e735b1
Branches
No related tags found
No related merge requests found
# QSI_Groupe1
l'adresse du contrat: KT1QTwmF2eptKss2FWbT1rHP5wCERL16kihQ
## Getting started
......
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_ => {
//Addresse of MyAsso
const ownerAddress = ("tz1dV9UkbS6uMuKjQy5Vs7FSptKz8LR28oFq" as address)
const receiver : contract<unit> =
match (Tezos.get_contract_opt(Option.unopt(association.admin)) as option<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 ;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment