Pirichain Smart Scenarios Documentation
  • ➰Pirichain Smart Scenario (PSce)
  • 🧿Which Industries can use easily PSces?
  • ♥️Full Support Interoperability!
  • ➰General Structure of Smart Scenarios
  • ➰PSce Working Principles And Limitations
  • ➰PSce Constants
  • ➰PSce Accumulator Object
  • ➰Simple Usage PSce
  • ➰Generating a new transaction though PSce
  • ➰What will i have if i execute a PCse
  • 💲Operation Costs
  • 🔐Double Protect! your client assets are in safe with addition authenticator code
  • 🛑Avoid these methods and situations in PSce
  • ➿PSce Functions
    • 🏁sendPIRI
    • 🏁sendToken
    • 🏁pushData
    • 🏁getBalance
    • 🏁getBalanceList
    • 🏁getPureTransaction
    • 🏁getTransaction
    • 🏁listPoolTransactions
    • 🏁findData
    • 🏁findDataWithAddress
    • 🏁findDataWithValue
      • 🏁findDataUpperThanValue
      • 🏁findDataLowerThanValue
    • 🏁getRandom
    • 🌏getData
    • 🌎postData
    • 🔓generateAuthenticator
    • 🔓verifyAuthenticator
    • 🔓getMyAuthenticatorToken
    • ❓Validators
    • 🔔Examples
      • 🍁Get PSce owner wallet balance
      • 🍁sendToken Example
      • 🍁EVM based similar approach- Token Management With PSDATA
      • 🍁Connect to EXTERNAL ENVIRONMENTS!
      • 🍁Time Based Inheritor Example
      • 🍁Token Example with Ticket Operation
      • 🍁A sample about token vesting
      • 🍁Asset Management Of Share Holders using with PSce
      • 🍁Double Protect your assets using with Pirichain Authenticator Factor
      • 🍁What an easy to build up your metaverse planet in Pirichain!
      • 🍁A new approach dependency factor using with PSce
      • 🍁Advanced Operation - Withdraw All Your Asset From PCse
      • 🍁Task Diversification and Transaction Proof (TDTP)
      • 🍁A Sample of using Origin Flag Integration on Binance Smart Chain Network.
      • 🍁Deposit/Withdraw from Foreign Chain (BSC) and Add Order , Buy and Sell Token, Just a 277 Code Lines!
      • 🍁Pirichain Decentralized Exchange (DEX) Sample Full Codes
Powered by GitBook
On this page
  1. PSce Functions
  2. Examples

Asset Management Of Share Holders using with PSce

This scenario presents that 2 different share holders have been created at first stage. Then these people can sell their share holder percentage to other people.

//####PIRICHAIN Smart Scenario v.1.0########
// PiriChain Smart Scenario Code Blocks Area 

 // All Functions must be return promise non-blocking async block or await prefix delimitier..  

const myProductName='Ferrari';
const myProductWorth=1000000;
const contractExplanation='This Product can be sold with shareholders how much they have. And All of Shareholders must accept before operations!';

async function initializeDeliverShareHolders()
{

    if (PSDATA["shareHolders"]==undefined)
    {
            PSDATA['totalPerson']=2;
            PSDATA["shareHolders"]=new Array();
            PSDATA["shareHolders"].push({name:'Alex',holderpercent:50,address:'PRTMRKWZ56v4D8mV1oj813bqTgdfUm9J4woVTDMpGxF'});
            PSDATA["shareHolders"].push({name:'Barbara',holderpercent:50,address:'PRTMPp6wo6zGAcStmhmBGQErnomzhFCoaTfLuXKTvo2'});
            await Map.saveMap(JSON.stringify(PSDATA));       
    }
    return PSDATA["shareHolders"];
}
async function getHoldersWithAuthorized()
{
        initializeDeliverShareHolders();
        
        if (PSDATA["shareHolders"].find(r=>r.address==EXECUTER_ADDRESS)!=undefined)
            return PSDATA;
        else
            return {error:1,message:'You dont have right to execute this scenario. You are not shareholder in this scenario!'};
}

async function sellYourShareHolder(acceptText,buyerName,buyerAddress,buyerHolderPercent)
{
    initializeDeliverShareHolders();

    if (acceptText!=='I accept to sell my holder')
            return {error:1,message:'You need to write for accepting your holder!'};

    if (buyerAddress===EXECUTER_ADDRESS)
        return {error:1,message:'You cannot transfer to your self!'};

    if (parseFloat(buyerHolderPercent)<=0 || isNaN(parseFloat(buyerHolderPercent)))
        return {error:1,message:'Percent is not true format!'};

    const myHolder=PSDATA["shareHolders"].find(r=>r.address===EXECUTER_ADDRESS);
    if (myHolder==undefined)
        return {error:1,message:'Your holder has not been found!'};

    if (myHolder.holderpercent<buyerHolderPercent)
        return {error:1,message:'Your Percent is not enough that you wanted to sell! Please decrease the holder to sell'};
    
    myHolder.holderpercent-=buyerHolderPercent;

    const isExistsHolder=PSDATA["shareHolders"].find(r=>r.address===buyerAddress);
    if (isExistsHolder==undefined)
    {
        PSDATA['totalPerson']+=1;
        PSDATA["shareHolders"].push({name:buyerName,holderpercent:buyerHolderPercent,address:buyerAddress});
    }
    else
    {
        isExistsHolder.holderpercent+=buyerHolderPercent;
    }
    
    return await Map.saveMap(JSON.stringify(PSDATA));       
}
async function getTotalPersonCount()
{
    initializeDeliverShareHolders();
    return PSDATA["totalPerson"];
}

async function listHolderTransactions(skip,limit)
{
    if (parseInt(skip)<0 || parseInt(limit)<=0)
    return {error:1,message:'Skip or Limit Param(s) are not true format!'};
    return await Transaction.listTransactions(EXECUTER_SCENARIOADDRESS,skip,limit);
}

async function getMyShareHolderPercentage()
{
    initializeDeliverShareHolders();
    const myHolder= PSDATA["shareHolders"].find(f=>f.address==EXECUTER_ADDRESS);
    if (myHolder===undefined)
        return 0;
    else
       return myHolder.holderpercent;
}

// Auto generated Withdraw Function.
// Please DO NOT Edit and Remove WithdrawAllAssetToOwnerWallet function!
/// Withdraw all amount of defined asset_ID to scenario owner address
async function WithdrawAllAssetToOwnerWallet(asset_ID)
{
    if (OWNER_ADDRESS!==EXECUTER_ADDRESS)
    return {error:1,data:'Only scenario owner can execute this method!'};
    if (asset_ID)
    {
        if (!isNaN(parseInt(asset_ID)))
        {
            const myBalanceObject=await Transaction.getBalance(EXECUTER_SCENARIOADDRESS,-1);
            let myBalance=parseFloat(myBalanceObject.balance);
            if (asset_ID===-1)
            {
                if (myBalance<1)
                    return {error:1,data:'Your Piri Coin is not enough to transfer!'};
                myBalance-=1; // Fee
                    return await Transaction.sendPIRI(OWNER_ADDRESS,myBalance);
            }
            else
            {
                if (myBalance<1)
                    return {error:1,data:'Your Piri Coin is not enough to transfer!'};             
                const myTokenBalanceObject=await Transaction.getBalance(EXECUTER_SCENARIOADDRESS,asset_ID);
                let myTokenBalance=parseFloat(myTokenBalanceObject.balance);
                if (myTokenBalance>0)
                    return await Transaction.sendToken(OWNER_ADDRESS,myTokenBalance,asset_ID);
                else
                return {error:1,data:'You dont have enough token balance!'};
            }

        }
    }
}
PreviousA sample about token vestingNextDouble Protect your assets using with Pirichain Authenticator Factor

Last updated 9 months ago

➿
🔔
🍁