class DepositeContent{
constructor(text){
if(text){
let o = JSON.parse(text);
this.balance = new BigNumber(o.balance);
this.expiryHeight = new BigNumber(o.expiryHeight);
} else {
this.balance = new BigNumber(0);
this.expiryHeight = new BigNumber(0);
}
};
toString(){
return JSON.stringify(this)
};
};
class BankVaultContract{
constructor(){
LocalContractStorage.defineMapProperty(this, 'bankVault', {
parse(text) {
return new DepositeContent(text);
},
stringify(o) {
return o.toString();
}
})
}
init(){
//TODO
}
save(height) {
let from = Blockchain.transaction.from;
let value = Blockchain.transaction.value;
let bk_height = new BigNumber(Blockchain.block.height);
let orig_deposit = this.bankVault.get(from);
if (orig_deposit) {
value = value.plus(orig_deposit.balance);
}
let deposit = new DepositeContent();
deposit.balance = value;
deposit.expiryHeight = bk_height.plus(height);
this.bankVault.put(from, deposit);
}
}
export {BankVaultContract}
部署的合约是tutorial中改写ES6的