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
GitLab 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
Show 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 '
...
@@ -16,28 +16,26 @@ import { handleAdminChoice, handleAdherentChoice, handleConnectedChoice } from '
const
tezos
=
new
TezosToolkit
(
'
https://ghostnet.ecadinfra.com
'
);
const
tezos
=
new
TezosToolkit
(
'
https://ghostnet.ecadinfra.com
'
);
const
program
=
new
Command
();
const
program
=
new
Command
();
program
program
.
name
(
'
my-asso
'
)
.
option
(
'
-f, --file <filePath>
'
,
'
Chemin du fichier JSON du portefeuille
'
)
.
description
(
'
My Asso CLI
'
)
.
parse
(
process
.
argv
);
.
version
(
'
1.0.0
'
);
if
(
!
program
.
args
)
{
console
.
error
(
'
Erreur: Veuillez spécifier le chemin du fichier JSON du portefeuille avec l
\'
option -f
'
);
process
.
exit
(
1
);
}
program
.
command
(
'
main
'
)
.
argument
(
'
<filePath>
'
,
'
Chemin du fichier JSON du portefeuille
'
)
.
action
(
async
(
file
)
=>
{
// LOAD WALLET FROM JSON
// LOAD WALLET FROM JSON
const
walletData
=
JSON
.
parse
(
fs
.
readFileSync
(
program
.
args
[
0
]
,
'
utf8
'
));
const
walletData
=
JSON
.
parse
(
fs
.
readFileSync
(
file
,
'
utf8
'
));
// REGISTER THE PROVIDER
// REGISTER THE PROVIDER
const
signer
=
new
InMemorySigner
(
walletData
.
privateKey
);
const
signer
=
new
InMemorySigner
(
walletData
.
privateKey
);
tezos
.
setProvider
({
signer
});
tezos
.
setProvider
({
signer
});
program
// DISPLAY HEADER
.
action
(
async
()
=>
{
await
getAsciiArtText
()
await
getAsciiArtText
()
console
.
log
(
`\n`
);
console
.
log
(
`\n`
);
console
.
log
(
chalk
.
bgBlue
(
`Vous êtes connecté en tant que
${
getRole
(
tezos
)}
\n`
))
console
.
log
(
chalk
.
bgBlue
(
`Vous êtes connecté en tant que
${
getRole
(
tezos
)}
\n`
))
// START MAIN APPLICATION
while
(
true
)
{
while
(
true
)
{
let
choice
:
string
let
choice
:
string
switch
(
getRole
(
tezos
))
{
switch
(
getRole
(
tezos
))
{
...
@@ -57,4 +55,4 @@ program
...
@@ -57,4 +55,4 @@ 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
...
@@ -15,7 +15,12 @@ import { createAssociation, joinAssociation } from '../services/association.serv
import
{
createProposal
}
from
'
../services/proposal.service.js
'
;
import
{
createProposal
}
from
'
../services/proposal.service.js
'
;
import
{
createFA21Contract
}
from
'
../services/contract.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
name
=
await
askQuestion
(
chalk
.
yellow
(
'
Nom:
'
));
const
description
=
await
askQuestion
(
chalk
.
yellow
(
'
Description:
'
));
const
description
=
await
askQuestion
(
chalk
.
yellow
(
'
Description:
'
));
const
association
:
Association
=
{
const
association
:
Association
=
{
...
@@ -33,7 +38,12 @@ async function handleCreateAsssociation(tezos: TezosToolkit) {
...
@@ -33,7 +38,12 @@ async function handleCreateAsssociation(tezos: TezosToolkit) {
}
}
}
}
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:
'
));
const
nbTokenFungible
:
string
=
await
askQuestion
(
chalk
.
yellow
(
'
Nombre de token fongible:
'
));
try
{
try
{
...
@@ -45,7 +55,12 @@ async function handleCreateToken(tezos: TezosToolkit) {
...
@@ -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
{
try
{
const
balance
=
await
getBalance
(
tezos
);
const
balance
=
await
getBalance
(
tezos
);
console
.
log
(
`\nSolde du portefeuille:
${
balance
}
ꜩ\n`
);
console
.
log
(
`\nSolde du portefeuille:
${
balance
}
ꜩ\n`
);
...
@@ -54,7 +69,12 @@ async function handleGetBalance(tezos: TezosToolkit) {
...
@@ -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
title
=
await
askQuestion
(
chalk
.
yellow
(
'
Titre:
'
));
const
description
=
await
askQuestion
(
chalk
.
yellow
(
'
Description:
'
));
const
description
=
await
askQuestion
(
chalk
.
yellow
(
'
Description:
'
));
const
proposal
:
Proposal
=
{
const
proposal
:
Proposal
=
{
...
@@ -72,7 +92,12 @@ async function handleCreateProposal(tezos: TezosToolkit) {
...
@@ -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:
"
));
const
name
=
await
askQuestion
(
chalk
.
yellow
(
"
Nom de l'association:
"
));
try
{
try
{
...
@@ -86,7 +111,13 @@ async function handleJoinAssociation(tezos: TezosToolkit) {
...
@@ -86,7 +111,13 @@ async function handleJoinAssociation(tezos: TezosToolkit) {
console
.
log
(
chalk
.
green
(
"
\n
Vous avez rejoint l'association !!
\n
"
));
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
)
{
switch
(
choice
)
{
case
"
0
"
:
case
"
0
"
:
break
;
break
;
...
@@ -100,12 +131,18 @@ async function handleAdminChoice(choice: string, tezos: TezosToolkit) {
...
@@ -100,12 +131,18 @@ async function handleAdminChoice(choice: string, tezos: TezosToolkit) {
await
handleGetBalance
(
tezos
);
await
handleGetBalance
(
tezos
);
break
;
break
;
default
:
default
:
console
.
log
(
'
Choix invalide
'
);
console
.
log
(
chalk
.
bgRedBright
(
'
\n
Choix invalide
\n
'
)
);
break
;
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
)
{
switch
(
choice
)
{
case
"
0
"
:
case
"
0
"
:
break
;
break
;
...
@@ -116,12 +153,18 @@ async function handleAdherentChoice(choice: string, tezos: TezosToolkit) {
...
@@ -116,12 +153,18 @@ async function handleAdherentChoice(choice: string, tezos: TezosToolkit) {
await
handleGetBalance
(
tezos
);
await
handleGetBalance
(
tezos
);
break
;
break
;
default
:
default
:
console
.
log
(
'
Choix invalide
'
);
console
.
log
(
chalk
.
bgRedBright
(
'
\n
Choix invalide
\n
'
)
);
break
;
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
)
{
switch
(
choice
)
{
case
"
0
"
:
case
"
0
"
:
break
;
break
;
...
@@ -132,7 +175,7 @@ async function handleConnectedChoice(choice: string, tezos: TezosToolkit) {
...
@@ -132,7 +175,7 @@ async function handleConnectedChoice(choice: string, tezos: TezosToolkit) {
await
handleGetBalance
(
tezos
);
await
handleGetBalance
(
tezos
);
break
;
break
;
default
:
default
:
console
.
log
(
'
Choix invalide
'
);
console
.
log
(
chalk
.
bgRedBright
(
'
\n
Choix invalide
\n
'
)
);
break
;
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