🍁Token Example with Ticket Operation

//####PIRICHAIN Smart Scenario v.1.0########
// TICKET Token Sample Scenario

// System first fetches data from external environment , 
//checks the received data where is real or fake user infos
//and then
// controls to send one TICKET Token to users and cut 10 PIRI coin for each TICKET.

 async function TryToBuyTicket(name,surname)
{
    // Checking Amount Price
    if (parseInt(AMOUNT)<10 )
        return {error:1,message:'You must send 10 PIRI Coin for buy ticket!'};

    const userPiriBalance=await Transaction.getBalance(EXECUTER_ADDRESS,-1);

    if (parseFloat(userPiriBalance.balance)<10)
       return {error:1,message:'You dont have enough Piri Coin to buy ticket!'};

    let result=await Tools.getData('https://dummyjson.com/users');
    if (!result) return {error:1,message:'Result Object not fetched!'};
    if (!result.data) return {error:1,message:'Result Data not fetched!'};
    if (!result.data.users) return {error:1,message:'Users not fetched!'};
    try
    {
        var user=result.data.users.find((user)=> 
                        user.firstName==name 
                        && user.lastName==surname);
        if (user)
        {
            const isUserBoughtBeforeTicket=await Transaction.getBalance(EXECUTER_ADDRESS,10006);
            if (parseInt(isUserBoughtBeforeTicket.balance)==0)
            {
                // Send to Ticket Revelant Address
                const transactionResult=await Transaction.sendToken(EXECUTER_ADDRESS,1,10006);
                if (transactionResult.tx)
                {
                    // Inform to ticket organizator using with their service 
                    //for completed new ticket operation
                    await Tools.postData('https://ticketorganizatorservice.xyz/newTicket/',{tx:transactionResult.tx,address:EXECUTER_ADDRESS});
                    return {error:0,message:'Congratulations! Ticket has been transferred to your wallet Operation Number:'+transactionResult.tx};
                }
                else
                return {error:1,message:'There was an error while processing!'};
            }
            else
                return {error:1,message:'You have already a ticket! '+
                                         'You cannot buy twice this address!'};
        }
        else
            return {error:1,message:'User not found for this ticket organization!'};
    }
    catch(e)
    {
        return {error:1,message:e.message};
    }
}

async function getAllUsers()
{
        let result=await Tools.getData('https://dummyjson.com/users');
        return result;

}

Last updated