Skip to content
Snippets Groups Projects
Commit c61ea560 authored by tarmelit's avatar tarmelit
Browse files

association registry

parent 7128629b
No related branches found
No related tags found
No related merge requests found
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/javascript-node/.devcontainer/base.Dockerfile
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster
ARG VARIANT=18-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}
# Install ligo-client
RUN wget -O ligo https://gitlab.com/ligolang/ligo/-/jobs/6056572676/artifacts/raw/ligo
RUN chmod +x ./ligo
RUN mv ./ligo /usr/local/bin
\ No newline at end of file
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
{
"name": "JsLIgo",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 16, 14, 12.
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon.
"args": {
"VARIANT": "18-bullseye"
}
},
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "npm install",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
"customizations": {
"vscode": {
"extensions": [
"esbenp.prettier-vscode",
"ligolang-publish.ligo-vscode",
"ligolang-publish.ligo-debugger-vscode"
],
"settings": {
"editor.formatOnSave": true
}
}
}
}
node_modules
build/*.tz
build/*.json
\ No newline at end of file
e0b84887-ecb9-46ef-27fb-8c590a79852a
\ No newline at end of file
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: tez = 10 as tez;
@entry
function registerAssociation(newAssociation: association, storage: storage): return_ {
const existingAssociation = Big_map.find_opt(newAssociation.name, storage);
if (Option.is_some(existingAssociation)) {
failwith("Association already registered");
}
const updatedStorage: storage = Big_map.add(newAssociation.name, {
...newAssociation,
registrationFee: registrationFeeInitial
}, storage);
const noOperations: list<operation> = [];
const result: return_ = [noOperations, updatedStorage];
return result;
}
@entry
function changeAdmin(associationName: string, newAdmin: address, storage: storage): return_ {
const associationOpt = Big_map.find_opt(associationName, storage);
if (Option.is_none(associationOpt)) {
failwith("Unknown association cannot change admin");
}
let association = Option.get(associationOpt);
if (Option.is_none(association.admin) || Tezos.sender != Option.get(association.admin)) {
failwith("Only the current admin can change the admin");
}
const updatedAssociation = {
...association,
admin: Some(newAdmin)
};
const updatedStorage: storage = Big_map.update(associationName, Some(updatedAssociation), storage);
const noOperations: list<operation> = [];
const result: return_ = [noOperations, updatedStorage];
return result;
}
@view
function getAssociationDetails(associationName: string, storage: storage): option<association> {
return Big_map.find_opt(associationName, storage);
}
# Required: Your private key
PK=
# Required: see see https://tezostaquito.io/docs/rpc_nodes/
RPC_URL=https://ghostnet.tezos.marigold.dev/
\ No newline at end of file
import { InMemorySigner } from "@taquito/signer";
import { MichelsonMap, TezosToolkit } from "@taquito/taquito";
import c from 'ansi-colors';
import { Spinner } from "cli-spinner";
import dotenv from "dotenv";
import code from "../build/AssociationRegistry.json";
import path from "node:path";
// Read environment variables from .env file
dotenv.config({ path:path.resolve(__dirname,'.env')});
const missingEnvVarLog = (name: string) =>
console.log(
c.redBright(`Missing `) +
c.red.bold.underline(name) +
c.redBright(` env var. Please add it in `) +
c.red.bold.underline(`deploy/.env`)
);
const makeSpinnerOperation = async <T>(
operation: Promise<T>,
{
loadingMessage,
endMessage,
}: {
loadingMessage: string;
endMessage: string;
}
): Promise<T> => {
const spinner = new Spinner(loadingMessage);
spinner.start();
const result = await operation;
spinner.stop();
console.log("");
console.log(endMessage);
return result;
};
const pk = process.env.PK;
const rpcUrl = process.env.RPC_URL;
if (![pk, rpcUrl].find((v) => !!v)) {
console.log(
c.redBright(`Couldn't find env variables. Have you filed `) +
c.red.bold.underline(`deploy/.env` )
);
process.exit(-1);
}
if (!pk) {
missingEnvVarLog("PK");
process.exit(-1);
}
if (!rpcUrl) {
missingEnvVarLog("RPC_URL");
process.exit(-1);
}
// Initialize RPC connection
const Tezos = new TezosToolkit(process.env.RPC_URL || "");
// Deploy to configured node with configured secret key
const deploy = async () => {
try {
const signer = await InMemorySigner.fromSecretKey(process.env.PK|| "");
Tezos.setProvider({ signer });
// create a JavaScript object to be used as initial storage
// https://tezostaquito.io/docs/originate/#a-initializing-storage-using-a-plain-old-javascript-object
const storage = new MichelsonMap();
const origination = await makeSpinnerOperation(
Tezos.contract.originate({ code, storage }),
{
loadingMessage: c.yellowBright(`Deploying contract`),
endMessage: c.green(`Contract deployed!`),
}
);
await makeSpinnerOperation(origination.contract(), {
loadingMessage:
c.yellowBright(`Waiting for contract to be confirmed at: `) +
c.yellow.bold(origination.contractAddress || ""),
endMessage: c.green(`Contract confirmed!`),
});
console.log(
c.green(`\nContract address: \n- `) +
c.green.underline(`${origination.contractAddress}`)
);
} catch (e) {
console.log("");
console.log(c.redBright(`Error during deployment:`));
console.log(e);
process.exit(1);
}
};
deploy();
\ No newline at end of file
This diff is collapsed.
{
"name": "univers",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"compile": "ligo compile contract contracts/AssociationRegistry.jsligo --output-file build/AssociationRegistry.tz && ligo compile contract contracts/AssociationRegistry.jsligo --output-file build/AssociationRegistry.json --michelson-format json",
"deploy": "ts-node deploy/deploy.ts ",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "MPL-2.0",
"devDependencies": {
"@taquito/signer": "*",
"@taquito/taquito": "*",
"@taquito/utils": "*",
"cli-spinner": "*",
"dotenv": "*",
"ts-node": "*",
"typescript": "*",
"ansi-colors": "^4.1.3"
}
}
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 16",
"compilerOptions": {
"lib": ["ESNext"],
"module": "CommonJS",
"target": "ESNext",
"resolveJsonModule": true,
"noImplicitAny": false,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "Node"
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment