Custom Wallet Data
/* Code in OpenWallet */
// load the wallet
var w = LoadWallet(address);
// if the wallet has a Data field inside (it means that it is an existing wallet)
if(w.Data !== '') {
// the data, in json format is parsed
var data = JSON.parse(w.Data);
// we extract here the balance
if ('Balance' in data) { this.Balance = data.Balance; }
// we extract here the allowances
if ('Allowances' in data) { this.Allowances = data.Allowances;}
}
// if the wallet didn't contain any instance of this contract, nothing will be done and the initial
// values of the contract will be used.
/* Code in CloseWallet */
// we create an object with all the info that we wish to store
var dataObject = {
Balance : this.Balance, // the wallet balance
Allowances : this.Allowances // the allowances
};
// Convert the data object to a JSON string
var dataString = JSON.stringify(dataObject);
// Use the SaveWallet function to save the updated wallet
SaveWallet(this.Address, dataString); Last updated