Skip to content

Instantly share code, notes, and snippets.

@KasraAb
Created November 2, 2020 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KasraAb/0378ab697531e6ae58cc554c2290244d to your computer and use it in GitHub Desktop.
Save KasraAb/0378ab697531e6ae58cc554c2290244d to your computer and use it in GitHub Desktop.
SellShare
//update sender's account
const new_sender_balance = new BigNum(sender.balance).add(lisk_amount).toString();
const new_sender_share = (!sender.asset.share)? this.asset.amount:
new BigNum(sender.asset.share).sub(this.asset.amount).toString();
const updated_sender = { ...sender, balance: new_sender_balance,
asset: { ...sender.asset, share: new_sender_share} };
store.account.set(updated_sender.address, updated_sender);
//update Manager's account
const new_recipient_balance = new BigNum(recipient.balance).sub(lisk_amount).toString();
var new_holders = recipient.asset.holders;
new_holders[sender.address] = new_sender_share;
if(new_sender_share === '0'){
delete new_holders[sender.address];
}
const new_share_supply = new BigNum(recipient.asset.shareSupply).sub(this.asset.amount).toString();
const updated_recipient = {...recipient, balance : new_recipient_balance,
asset:{...recipient.asset, holders: new_holders, shareSupply: new_share_supply}};
store.account.set(updated_recipient.address, updated_recipient);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment