🍁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 .
asyncfunctionWithdrawAllAssetToOwnerWallet(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. {constmyBalanceObject=awaitTransaction.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 feereturn {error:1,data:'Your Piri Coin is not enough to transfer!'}; myBalance-=0.1; // seperate for feereturnawaitTransaction.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 feereturn {error:1,data:'Your Piri Coin is not enough to transfer!'}; constmyTokenBalanceObject=awaitTransaction.getBalance(EXECUTER_SCENARIOADDRESS,asset_ID);// check PSce balance let myTokenBalance=parseFloat(myTokenBalanceObject.balance);if (myTokenBalance>0) // check the token balance returnawaitTransaction.sendToken(OWNER_ADDRESS,myTokenBalance,asset_ID);elsereturn {error:1,data:'You dont have enough token balance!'}; } } }}