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

Update AssociationRegistry.jsligo

parent eea44a92
No related branches found
No related tags found
No related merge requests found
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;
//Register a new DAO
@entry
function registerAssociation(newAssociation, storage) {
const existingAssociationOpt = Big_map.find_opt(newAssociation.name, storage);
if (Option.is_some(existingAssociationOpt)) {
function registerAssociation(newAssociation: association, storage: storage): return_ {
const existingAssociation = Big_map.mem(newAssociation.name, storage);
if (existingAssociation) {
failwith("Association already registered");
}
const updatedStorage = Big_map.add(newAssociation.name, {
const updatedStorage: storage = Big_map.add(newAssociation.name, {
...newAssociation,
registrationFee: registrationFeeInitial
}, storage);
const noOperations = ([] : list<operation>);
return [noOperations, updatedStorage];
return [list([],updatedStorage)]
}
//Change Admin
@entry
function changeAdmin(associationName, newAdmin, stor) {
function changeAdmin(associationName :string, newAdmin : address, stor: storage) {
const associationOpt = Big_map.find_opt(associationName, stor);
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");
//todo
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");
}
const updatedAssociation = {
...association,
admin: Some(newAdmin)
};
const updatedStorage = Big_map.update(associationName, Some(updatedAssociation), stor);
return [[], updatedStorage];
}
const updatedStorage = Big_map.update(associationName, Some(updatedAssociation), stor);
return [list([],updatedStorage)]
};
//List associations
/*
@view
function getAssociationDetails(associationName, storage) {
function getAssociationDetails(associationName: string, storage: storage): option<association> {
return Big_map.find_opt(associationName, storage);
}
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment