Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QSI_Groupe4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lydia Tarmelit
QSI_Groupe4
Commits
9d8c1580
Commit
9d8c1580
authored
1 year ago
by
Nawfel Senoussi
Browse files
Options
Downloads
Patches
Plain Diff
clean commander + add jsdoc
parent
890cb2f0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
index.ts
+17
-19
17 additions, 19 deletions
index.ts
src/handlers/handlers.ts
+55
-12
55 additions, 12 deletions
src/handlers/handlers.ts
with
72 additions
and
31 deletions
index.ts
+
17
−
19
View file @
9d8c1580
...
...
@@ -16,28 +16,26 @@ import { handleAdminChoice, handleAdherentChoice, handleConnectedChoice } from '
const
tezos
=
new
TezosToolkit
(
'
https://ghostnet.ecadinfra.com
'
);
const
program
=
new
Command
();
program
.
option
(
'
-f, --file <filePath>
'
,
'
Chemin du fichier JSON du portefeuille
'
)
.
parse
(
process
.
argv
);
if
(
!
program
.
args
)
{
console
.
error
(
'
Erreur: Veuillez spécifier le chemin du fichier JSON du portefeuille avec l
\'
option -f
'
);
process
.
exit
(
1
);
}
// LOAD WALLET FROM JSON
const
walletData
=
JSON
.
parse
(
fs
.
readFileSync
(
program
.
args
[
0
],
'
utf8
'
));
// REGISTER THE PROVIDER
const
signer
=
new
InMemorySigner
(
walletData
.
privateKey
);
tezos
.
setProvider
({
signer
});
program
.
name
(
'
my-asso
'
)
.
description
(
'
My Asso CLI
'
)
.
version
(
'
1.0.0
'
);
program
.
command
(
'
main
'
)
.
argument
(
'
<filePath>
'
,
'
Chemin du fichier JSON du portefeuille
'
)
.
action
(
async
(
file
)
=>
{
// LOAD WALLET FROM JSON
const
walletData
=
JSON
.
parse
(
fs
.
readFileSync
(
file
,
'
utf8
'
));
// REGISTER THE PROVIDER
const
signer
=
new
InMemorySigner
(
walletData
.
privateKey
);
tezos
.
setProvider
({
signer
});
program
.
action
(
async
()
=>
{
// DISPLAY HEADER
await
getAsciiArtText
()
console
.
log
(
`\n`
);
console
.
log
(
chalk
.
bgBlue
(
`Vous êtes connecté en tant que
${
getRole
(
tezos
)}
\n`
))
// START MAIN APPLICATION
while
(
true
)
{
let
choice
:
string
switch
(
getRole
(
tezos
))
{
...
...
@@ -56,5 +54,5 @@ program
}
}
});
program
.
parse
(
process
.
argv
);
program
.
parse
(
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/handlers/handlers.ts
+
55
−
12
View file @
9d8c1580
...
...
@@ -15,7 +15,12 @@ import { createAssociation, joinAssociation } from '../services/association.serv
import
{
createProposal
}
from
'
../services/proposal.service.js
'
;
import
{
createFA21Contract
}
from
'
../services/contract.service.js
'
;
async
function
handleCreateAsssociation
(
tezos
:
TezosToolkit
)
{
/**
* Handles the process of creating an association.
* @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations.
* @returns {Promise<void>} A promise resolved once the association creation process is complete.
*/
async
function
handleCreateAsssociation
(
tezos
:
TezosToolkit
):
Promise
<
void
>
{
const
name
=
await
askQuestion
(
chalk
.
yellow
(
'
Nom:
'
));
const
description
=
await
askQuestion
(
chalk
.
yellow
(
'
Description:
'
));
const
association
:
Association
=
{
...
...
@@ -32,8 +37,13 @@ async function handleCreateAsssociation(tezos: TezosToolkit) {
console
.
log
(
"
Erreur lors de la création de l'association
"
);
}
}
async
function
handleCreateToken
(
tezos
:
TezosToolkit
)
{
/**
* Handles the process of creating a fungible token.
* @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations.
* @returns {Promise<void>} A promise resolved once the token creation process is complete.
*/
async
function
handleCreateToken
(
tezos
:
TezosToolkit
):
Promise
<
void
>
{
const
nbTokenFungible
:
string
=
await
askQuestion
(
chalk
.
yellow
(
'
Nombre de token fongible:
'
));
try
{
...
...
@@ -45,7 +55,12 @@ async function handleCreateToken(tezos: TezosToolkit) {
}
}
async
function
handleGetBalance
(
tezos
:
TezosToolkit
)
{
/**
* Handles the process of retrieving the balance of the wallet.
* @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations.
* @returns {Promise<void>} A promise resolved once the balance retrieval process is complete.
*/
async
function
handleGetBalance
(
tezos
:
TezosToolkit
):
Promise
<
void
>
{
try
{
const
balance
=
await
getBalance
(
tezos
);
console
.
log
(
`\nSolde du portefeuille:
${
balance
}
ꜩ\n`
);
...
...
@@ -54,7 +69,12 @@ async function handleGetBalance(tezos: TezosToolkit) {
}
}
async
function
handleCreateProposal
(
tezos
:
TezosToolkit
)
{
/**
* Handles the process of creating a proposal.
* @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations.
* @returns {Promise<void>} A promise resolved once the proposal creation process is complete.
*/
async
function
handleCreateProposal
(
tezos
:
TezosToolkit
):
Promise
<
void
>
{
const
title
=
await
askQuestion
(
chalk
.
yellow
(
'
Titre:
'
));
const
description
=
await
askQuestion
(
chalk
.
yellow
(
'
Description:
'
));
const
proposal
:
Proposal
=
{
...
...
@@ -72,7 +92,12 @@ async function handleCreateProposal(tezos: TezosToolkit) {
}
}
async
function
handleJoinAssociation
(
tezos
:
TezosToolkit
)
{
/**
* Handles the process of joining an association.
* @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations.
* @returns {Promise<void>} A promise resolved once the joining process is complete.
*/
async
function
handleJoinAssociation
(
tezos
:
TezosToolkit
):
Promise
<
void
>
{
const
name
=
await
askQuestion
(
chalk
.
yellow
(
"
Nom de l'association:
"
));
try
{
...
...
@@ -86,7 +111,13 @@ async function handleJoinAssociation(tezos: TezosToolkit) {
console
.
log
(
chalk
.
green
(
"
\n
Vous avez rejoint l'association !!
\n
"
));
}
async
function
handleAdminChoice
(
choice
:
string
,
tezos
:
TezosToolkit
)
{
/**
* Handles administrator actions based on the specified choice.
* @param {string} choice - The administrator's choice.
* @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations.
* @returns {Promise<void>} A promise resolved once the processing is complete.
*/
async
function
handleAdminChoice
(
choice
:
string
,
tezos
:
TezosToolkit
):
Promise
<
void
>
{
switch
(
choice
)
{
case
"
0
"
:
break
;
...
...
@@ -100,12 +131,18 @@ async function handleAdminChoice(choice: string, tezos: TezosToolkit) {
await
handleGetBalance
(
tezos
);
break
;
default
:
console
.
log
(
'
Choix invalide
'
);
console
.
log
(
chalk
.
bgRedBright
(
'
\n
Choix invalide
\n
'
)
);
break
;
}
}
async
function
handleAdherentChoice
(
choice
:
string
,
tezos
:
TezosToolkit
)
{
/**
* Handles adherent actions based on the specified choice.
* @param {string} choice - The adherent's choice.
* @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations.
* @returns {Promise<void>} A promise resolved once the processing is complete.
*/
async
function
handleAdherentChoice
(
choice
:
string
,
tezos
:
TezosToolkit
):
Promise
<
void
>
{
switch
(
choice
)
{
case
"
0
"
:
break
;
...
...
@@ -116,12 +153,18 @@ async function handleAdherentChoice(choice: string, tezos: TezosToolkit) {
await
handleGetBalance
(
tezos
);
break
;
default
:
console
.
log
(
'
Choix invalide
'
);
console
.
log
(
chalk
.
bgRedBright
(
'
\n
Choix invalide
\n
'
)
);
break
;
}
}
async
function
handleConnectedChoice
(
choice
:
string
,
tezos
:
TezosToolkit
)
{
/**
* Handles connected actions based on the specified choice.
* @param {string} choice - The connected's choice.
* @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations.
* @returns {Promise<void>} A promise resolved once the processing is complete.
*/
async
function
handleConnectedChoice
(
choice
:
string
,
tezos
:
TezosToolkit
):
Promise
<
void
>
{
switch
(
choice
)
{
case
"
0
"
:
break
;
...
...
@@ -132,7 +175,7 @@ async function handleConnectedChoice(choice: string, tezos: TezosToolkit) {
await
handleGetBalance
(
tezos
);
break
;
default
:
console
.
log
(
'
Choix invalide
'
);
console
.
log
(
chalk
.
bgRedBright
(
'
\n
Choix invalide
\n
'
)
);
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment