Skip to content

Instantly share code, notes, and snippets.

View KasraAb's full-sized avatar

Kasra Abbaszadeh KasraAb

View GitHub Profile
@KasraAb
KasraAb / NashTransfer.js
Last active November 2, 2020 15:33
NashTransfer
//update recipient's account
const new_recipient_nash = (!recipient.asset.nash)? this.asset.amount
: new BigNum(recipient.asset.nash).add(this.asset.amount).toString();
const updated_recipient = { ...recipient, asset: { ...recipient.asset, nash: new_recipient_nash} };
store.account.set(updated_recipient.address, updated_recipient);
//update sender's account
const new_sender_nash = new BigNum(sender.asset.nash).sub(this.asset.amount).toString();
@KasraAb
KasraAb / BondTransfer.js
Created November 2, 2020 16:31
BondTransfer
//update bond's account
const updated_bond = {...bond, asset: {...bond.asset, ownerId: this.asset.newOwnerId}};
store.account.set(updated_bond.address, updated_bond);
@KasraAb
KasraAb / BuyShare.js
Created November 2, 2020 16:32
BuyShare
//update sender's account
const new_sender_balance = new BigNum(sender.balance).sub(lisk_amount).toString();
const new_sender_share = (!sender.asset.share)? this.asset.amount
: new BigNum(sender.asset.share).add(this.asset.amount).toString();
const updated_sender = { ...sender, balance: new_sender_balance, asset: { ...sender.asset, share: new_sender_share}};
store.account.set(sender.address, updated_sender);
@KasraAb
KasraAb / SellShare.js
Created November 2, 2020 16:34
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);
@KasraAb
KasraAb / BuyBond.js
Created November 2, 2020 16:35
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'}};
@KasraAb
KasraAb / Bon2Nash.js
Created November 2, 2020 16:36
Bon2Nash
//update bond's account
const updated_bond = { ...bond, asset: { ...bond.asset, ownerId: '', status: 'expired'} };
store.account.set(updated_bond.address, updated_bond);
//update owner's account
const new_owner_nash = (!owner.asset.nash)? '100' : new BigNum(owner.asset.nash).add('100').toString();
const updated_owner = { ...owner, asset: { ...owner.asset, nash : new_owner_nash } };
@KasraAb
KasraAb / NewNash.js
Created November 2, 2020 16:37
NewNash
//update recipient's account
const new_recipient_nash = (!recipient.asset.nash)? this.asset.amount
: new BigNum(recipient.asset.nash).add(this.asset.amount).toString();
const updated_recipient = { ...recipient, asset: { ...recipient.asset, nash: new_recipient_nash} };
store.account.set(updated_recipient.address, updated_recipient);
//update Manager's account
const new_supply = (!Manager.asset.nashSupply) ? this.asset.amount
@KasraAb
KasraAb / Initialization.js
Created November 2, 2020 16:39
Initialization
if( this.asset.type === 'manager'){
const Manager = store.account.get(manager.address);
const updated_Manager = {...Manager,
asset: {...Manager.asset, type:'manager', nash: '10000', nashSupply: '10000'}} ;
store.account.set(updated_Manager.address,updated_Manager);
}