Created
November 2, 2020 16:35
-
-
Save KasraAb/4633d8c5d43f65ab29e830c821991f7c to your computer and use it in GitHub Desktop.
BuyBond
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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