Skip to content

Instantly share code, notes, and snippets.

@KasraAb
Created November 2, 2020 16:35
Show Gist options
  • Save KasraAb/4633d8c5d43f65ab29e830c821991f7c to your computer and use it in GitHub Desktop.
Save KasraAb/4633d8c5d43f65ab29e830c821991f7c to your computer and use it in GitHub Desktop.
BuyBond
//update sender's account
const new_sender_nash = new BigNum(sender.asset.nash).sub(bond.asset.price).toString() ;
const updated_sender = {...sender, asset: {...sender.asset, nash: new_sender_nash} };
store.account.set(updated_sender.address, updated_sender);
//update bond's account
const updated_bond = {...bond, asset: {...bond.asset, ownerId:sender.address, status: 'sold'}};
store.account.set(updated_bond.address, updated_bond);
//update Manager's account
const new_supply = new BigNum(Manager.asset.nashSupply).sub(bond.asset.price).toString();
var new_bondsList = (!Manager.asset.bondsList) ? [] : Manager.asset.bondsList;
new_bondsList.push(bond.address);
const updated_Manager = {...Manager,asset : {...Manager.asset, bondsList : new_bondsList , nashSupply: new_supply}};
store.account.set(updated_Manager.address, updated_Manager);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment