Gladius backend cloud functions

Gladius backend functional setup

Club Sign-up

1. create club owner user cloud function

Purpose

This Firebase function facilitates the sign-up process for the Gladius Club Owner user

frontend

- creates an auth record and email and UID

- frontend calling /users collections and waiting for a user doc to appear

backend

- triggers Auth create record and creates doc ( in /users) with stellar wallet

trigger source code

2. set club owner in the contract cloud function

source code

Purpose

This Firebase function facilitates the sign-up process for the Gladius Club. It integrates with Firebase Firestore for user verification and the Stellar blockchain for role management within a sports club context.

frontend

- calls CF SignupGladiusClub

https://europe-west1-wallet-login-45c1c.cloudfunctions.net/SignupGladiusClub

Request Body Parameters

'{ "ClubOwnerUID": "9UY6EVSrd0XDAHFBdt8sRpGsxLw1",

"ClubName" : "Chess club" }'

backend

- receives ClubOwnerUID, ClubName

- creates club doc in /clubs with unique clubUID

- sets the club_name in club doc based on ClubName

- copies stellar wallet public and private keys from /users doc(ClubOwnerUID) to /clubs/{clubUID}

- sets role = “owner” in club_roles under /users doc(ClubOwnerUID)

- executes Gladius contract Soroban function “set_is_sport_club“ https://testnet.stellarchain.io/operations/4843481864359937

Returns: club_owner_UID has been added to club_doc_UID

{ "message": "Club owner [user email] created a club [club public key]",

"club_public_key": "[Club owner's Stellar public key]"}

3.5 add calendar to the club

· Frontend adds a calendar link to a new club doc

Create Course

4. create course cloud function

source code

Purpose

Handles the creation of a new course within a sports club on the Stellar blockchain, leveraging Firebase Firestore for user authentication and management.

frontend

- calls CF SignupGladiusClubCourse

https://europe-west1-wallet-login-45c1c.cloudfunctions.net/SignupGladiusClubCourse

Request Body Parameters (example)

{ "ClubOwnerUID": "MmNNhkPnhXfluJ0HMpwCFFImpLt2",

"ClubUID" : "4",

"CourseName" : "My awesome course",

"CoursePrice" : 200,

"Courseincentive" : 15,

"CourseIndex" : 8 }'

backend

- Ensures required parameters (ClubOwnerUID, ClubUID, CourseName, CoursePrice, Courseincentive) are provided in the request body.

- executes create_course function with provided parameters

https://testnet.stellarchain.io/operations/4852161993261057

Returns

{"message":"Club owner [user email] created a club [club public key]","club_public_key":"[Club owner's Stellar public key]"

Signup as Parent

5. add student to club cloud function

source code

Purpose: Manages the role assignment and course subscriptions for students and parents within a sports club ecosystem on the Stellar blockchain, facilitated through Firebase Firestore and Stellar smart contracts.

frontend

- creates parent and student Auth record

-> wallets created automatically following logic described in (1)

- calls https://europe-west1-wallet-login-45c1c.cloudfunctions.net/SignupGladiusParent

Request Body Parameters (example)

{ "StudentUID": "exampleStudentUID",

"ParentUID": "exampleParentUID",

"ClubUID" : "exampleClubUID",

"GroupUID" : "exampleGroupUID",

"StudentPassword" : "exampleStudentPassword" }

backend

- Ensures required inputs (ParentUID, StudentUID, ClubUID, GroupUID) are provided and valid.

- Fetches and verifies necessary data from Firestore (for student, parent, and club)

- Executes contract functions with provided parameters

  • Mints EURC to Parent

    • mintToken(addressBook.getContractId(network, 'token_id'), 200, parent.publicKey(), payment_token_admin);

  • Sets and checks roles for both student and parent

  • Registers and manages course subscriptions

    • invokeContract('gladius_subscriptions_id', addressBook, 'get_course', getCourseParams, sport_club);

    • invokeContract('gladius_subscriptions_id', addressBook, 'subscribe_course', subscribeCourseParams, parent);

  • Returns contract function response

    • Example response

{ "message": "Student student@example.com was added to club ExampleClub by parent@example.com",

"parent_public_key":"GAXILOM5P7OQILZVUDGMBQXOUOFY2K5HOU6LHKBRL3TAIL3HABAODZMV",

"student_public_key":"GC3BQVW653PFYBRIXILV2MVVQQ4TCBQZ6FAQ3GO6PDFC3O64FAK3DO6Q",

"club_public_key":"GBHCD53TFM74SFTY4K2CQWGL6L2RR57Y5YPTFMOOJG5CE6EXDLGJVVYJ" }

Check balance

6. getStudentBalanceByID

source code

Endpoint https://europe-west1-wallet-login-45c1c.cloudfunctions.net/getStudentBalanceByID

- Request Body Parameters (example)

{ "StudentUID": "exampleStudentUID" }

- Response example

{message: `GLC Balance of ${userData.email}`, data: balanceGLCStudent }

Gladius Club NFT

7. fetchGladiusNFT

source core

NFT image is hardcoded at the moment

Purpose

Retrieves Non-Fungible Tokens (NFTs) associated with a specific user within a sports club environment on the Stellar blockchain, using Firestore to manage user and club data

- Endpoint https://europe-west1-wallet-login-45c1c.cloudfunctions.net/fetchGladiusNFT

-NFT Data Retrieval: Executes a series of blockchain calls to:

  • Get the number of NFTs owned by the user.

  • Fetch each NFT's token ID and associated metadata URI.

  • Retrieve and parse metadata from each URI to compile NFT details.

- Example request

{ "UID": "exampleUserUID"}

- Execute: fetchGladiusNFT(addressBook, user_stellar_secret, club_stellar_secret);

- Return response

{ message: `GLC NFTs of ${userData.email}`,

data: fetchGladiusNFTresult });

Example response

{

"message": "GLC NFTs of user@example.com",

"data": {

"nfts": [

{ "name": "Gladius Token #1",

"image": "https://example.com/nft1.png",

"description": "This is a Gladius NFT 1" },

{ "name": "Gladius Token #2",

"image": "https://example.com/nft2.png",

"description": "This is another Gladius NFT 2" } ]

}

Gladius coin (GLC) transfer

8. transferGLC

Source code

Purpose

Facilitates the transfer of Gladius Coins (GLC) between a student's account and a sports club's account on the Stellar blockchain, leveraging Firestore for user and club data management.

Endpoint

https://europe-west1-wallet-login-45c1c.cloudfunctions.net/invokeGladiusTransaction

Workflow

User and Club Verification :Checks for necessary parameters (UID and amount), verifying that the amount is a valid number. By default sends GLC to club wallet (this can be changed).

Transaction Execution: Performs several checks before executing the token transfer:

  • Ensures the transaction amount is positive and not zero.

  • Confirms that the sender and receiver are not the same.

  • Verifies that the sender's balance is sufficient to cover the transfer.

  • Executes the transfer on the Stellar blockchain using smart contract interactions.

Example request:

{ "UID": "exampleUserUID", "amount": 100 }

Example response

{ "message": "GLC sent from GAXILOM5P7OQILZVUDGMBQXOUOFY2K5HOU6LHKBRL3TAIL3HABAODZMV to GBHCD53TFM74SFTY4K2CQWGL6L2RR57Y5YPTFMOOJG5CE6EXDLGJVVYJ in the amount of 100" }

Cloud function triggers

  • Firebase_auth_sync - triggers Firebase Authentication. Creates user doc from Firebase Auth. Create wallets ( source )

  • Delete_user_document - triggers Firebase Authentication. Deletes user doc when account is deleted from Firebase Auth

  • Firestore_sync_users - triggers Cloud Firestore doc change. Sync clubs_roles field in /users doc and members docs in /clubs ( source )

Future work

Generate images with OpenAI API - could function draft

Last updated