🍁Advanced Operation - Withdraw All Your Asset From PCse

PSce creates automatically below function for each PSce for providing to withdraw all asset type from Smart Scenario Balance.

Is it necessary to use? Its not necessary to use at each PSce. But if you remove this function before creation of PSce. No one can withdraw assets from PSce if you didn't code different withdrawal approach .

async function WithdrawAllAssetToOwnerWallet(asset_ID)
{
    if (OWNER_ADDRESS!==EXECUTER_ADDRESS)
    // Only PSce owner execute this function. otherwise return an error.
    return {error:1,data:'Only scenario owner can execute this method!'};
    
    if (asset_ID) // check asset_ID has value
    {
        if (!isNaN(parseInt(asset_ID))) // check asset_ID is numeric.
        {
            const myBalanceObject=await Transaction.getBalance(EXECUTER_SCENARIOADDRESS,-1); 
            // get Balance from PSce.
            let myBalance=parseFloat(myBalanceObject.balance);
            if (asset_ID===-1) // if its PIRI
            {
                if (myBalance<0.1) // check the balance minimum 0.1 PIRI for fee
                    return {error:1,data:'Your Piri Coin is not enough to transfer!'};
                myBalance-=0.1; // seperate for fee
                    return await Transaction.sendPIRI(OWNER_ADDRESS,myBalance); 
                    // Send asset to PSce owner wallet
            }
            else // if its a token 
            {
                if (myBalance<0.1) 
                // check the balance minimum 0.1 PIRI for fee
                    return {error:1,data:'Your Piri Coin is not enough to transfer!'};             
                const myTokenBalanceObject=await Transaction.getBalance(EXECUTER_SCENARIOADDRESS,asset_ID);
                // check PSce balance 
                let myTokenBalance=parseFloat(myTokenBalanceObject.balance);
                if (myTokenBalance>0) // check the token balance 
                    return await Transaction.sendToken(OWNER_ADDRESS,myTokenBalance,asset_ID);
                else
                return {error:1,data:'You dont have enough token balance!'};
            }

        }
    }
}

Last updated