diff --git a/index.ts b/index.ts index 4873489262ee9e0e14045e02642ace2653788e26..3f793549e9185b2534e4eca2ecabbe4d113ccd0b 100644 --- a/index.ts +++ b/index.ts @@ -6,6 +6,33 @@ import { TezosToolkit } from '@taquito/taquito'; import { InMemorySigner } from '@taquito/signer'; import figlet from 'figlet'; +// START SERVICE +function createToken(address: string, tezos) { + tezos.wallet.at(address) + .then((contract) => contract.methodsObject.discoverPlanet({ + density: 0, + planet_type: "terrestrial", + coordinate: [0,0,0], + name: "test" + }).send()) + .then((op) => { + console.log(`Hash: ${op.opHash}`); + return op.confirmation(); + }) + .then((result) => { + console.log(result); + if (result.completed) { + console.log(`Transaction correctly processed! + Block: ${result.block.header.level} + Chain ID: ${result.block.chain_id}`); + } else { + console.log('An error has occurred'); + } + }) + .catch((err) => console.log(err)); +} +// END SERVICE + const tezos = new TezosToolkit('https://ghostnet.tezos.marigold.dev'); const program = new Command(); @@ -24,7 +51,6 @@ async function askQuestion(question: string): Promise<string> { }); } - program .option('-f, --file <filePath>', 'Chemin du fichier JSON du portefeuille') .parse(process.argv); @@ -73,38 +99,78 @@ program console.log(`\n`); + // Définir un moyen de connaître le rôle + let ROLE; + ROLE = "ADMIN"; + console.log(chalk.bgBlue(`Vous êtes connecté en tant que ${ROLE}\n`)) + while (true) { // IF ADMIN - const choice = await askQuestion(`${chalk.yellow('Que souhaitez-vous faire ?')} \n\n1: Créer une association\n2: Créer un token\n3: Voir mon portefeuille\n0: Quitter\n`); + if(ROLE === "ADMIN") { + const choice = await askQuestion(`${chalk.yellow('Que souhaitez-vous faire ?')} \n\n1: Créer une association\n2: Créer un token\n3: Voir mon portefeuille\n0: Quitter\n`); - if (choice === '0') { - break; + if (choice === '0') { + break; + } + + if (choice === '1') { + const name = await askQuestion(chalk.yellow('Nom: ')); + const description = await askQuestion(chalk.yellow('Description: ')); + const association = { + name: name, + description: description + }; + + console.log(chalk.green("\nVotre association a été crée !!\n")); + // Faire l'appel a create association + } else if (choice === '2') { + const nbTokenFungible = await askQuestion(chalk.yellow('Nombre de token fongible: ')); + // Faire le call pour créer un token + console.log(chalk.green("\nVotre token a été créé !!\n")); + } else if (choice === '3') { + await getBalance(walletData.privateKey); + } else { + console.log('Choix invalide'); + } } - if (choice === '1') { - const name = await askQuestion(chalk.yellow('Nom: ')); - const description = await askQuestion(chalk.yellow('Description: ')); - const association = { - name: name, - description: description - }; - - console.log(chalk.green("\nVotre association a été crée !!\n")); - // Faire l'appel a create association - } else if (choice === '2') { - const nbTokenFungible = await askQuestion(chalk.yellow('Nombre de token fongible: ')); - // Faire le call pour créer un token - console.log(chalk.green("\nVotre token a été créé !!\n")); - } else if (choice === '3') { - await getBalance(walletData.privateKey); - } else { - console.log('Choix invalide'); + // IF ADHERENT + if(ROLE === "ADHERENT") { + const choice = await askQuestion(`${chalk.yellow('Que souhaitez-vous faire ?')} \n\n1: Faire une proposition\n2: Voir mon portefeuille\n0: Quitter\n`); + + if (choice === '0') { + break; + } + + if (choice === '1') { + console.log(chalk.green("\nVous avez soumis une proposition !!\n")); + // Faire l'appel a post proposal association + } else if (choice === '2') { + await getBalance(walletData.privateKey); + } else { + console.log('Choix invalide'); + } } - // IF ADHERENT + // IF CONNECTED + if(ROLE === "CONNECTED") { + const choice = await askQuestion(`${chalk.yellow('Que souhaitez-vous faire ?')} \n\n1: Rejoindre une association\n2: Voir mon portefeuille\n0: Quitter\n`); - // IF CONNECTE + if (choice === '0') { + break; + } + if (choice === '1') { + const name = await askQuestion(chalk.yellow("Nom de l'association: ")); + + console.log(chalk.green("\nVous avez rejoint l'association !!\n")); + // Faire l'appel a join association + } else if (choice === '2') { + await getBalance(walletData.privateKey); + } else { + console.log('Choix invalide'); + } + } } }); diff --git a/package-lock.json b/package-lock.json index 40f1ef3213761628dd1e76df9bde4420c9a263eb..67aabcd1c7c704fce66052b613211838072f4350 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,9 @@ "chalk": "^5.3.0", "commander": "^12.0.0", "figlet": "^1.7.0", - "ts-node": "^10.9.2" + "ts-node": "^10.9.2", + "tsc": "^2.0.4", + "typescript": "^5.4.2" }, "devDependencies": { "@types/commander": "^2.12.2", @@ -872,6 +874,14 @@ } } }, + "node_modules/tsc": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/tsc/-/tsc-2.0.4.tgz", + "integrity": "sha512-fzoSieZI5KKJVBYGvwbVZs/J5za84f2lSTLPYf6AGiIf43tZ3GNrI1QzTLcjtyDDP4aLxd46RTZq1nQxe7+k5Q==", + "bin": { + "tsc": "bin/tsc" + } + }, "node_modules/tslib": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", @@ -897,10 +907,9 @@ ] }, "node_modules/typescript": { - "version": "5.3.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", - "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", - "peer": true, + "version": "5.4.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.2.tgz", + "integrity": "sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index ea38c72560cb6bce0f805a35a0e8ffe5108f9a00..47053d0bb36ca6d53f22e2b2f99c11865d3e2ac6 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,9 @@ "chalk": "^5.3.0", "commander": "^12.0.0", "figlet": "^1.7.0", - "ts-node": "^10.9.2" + "ts-node": "^10.9.2", + "tsc": "^2.0.4", + "typescript": "^5.4.2" }, "devDependencies": { "@types/commander": "^2.12.2", diff --git a/src/services/createToken.ts b/src/services/createToken.ts new file mode 100644 index 0000000000000000000000000000000000000000..69b8a54fef9dd8207c2c9ebde310f5a16fe380fc --- /dev/null +++ b/src/services/createToken.ts @@ -0,0 +1,21 @@ +function createToken(address: string, tezos) { + tezos.wallet.at(address) + .then((contract) => contract.methodsObject.areYouThere(true).send()) + .then((op) => { + console.log(`Hash: ${op.opHash}`); + return op.confirmation(); + }) + .then((result) => { + console.log(result); + if (result.completed) { + console.log(`Transaction correctly processed! + Block: ${result.block.header.level} + Chain ID: ${result.block.chain_id}`); + } else { + console.log('An error has occurred'); + } + }) + .catch((err) => console.log(err)); +} + +export { createToken } \ No newline at end of file