Transfer Function
Transfer: function (to, amount) {
// tests the transfer amount
if(amount<=0)
{
print("Inproper amount\n");
return false;
}
// Createa a new wallet instance
var From = Object.create(CRC_Wallet);
// Opens the Sender's wallet
From.OpenWallet(msg.From);
// If there are enough tokens and the amount is positive
if (From.Balance >= amount) {
// Create a new wallet instance
var To = Object.create(CRC_Wallet);
// Opens the recipient's wallet
if(To.OpenWallet(to)){
// Transfers the tokens
From.Balance -= amount;
To.Balance += amount;
//Prints out the message
println('Transfered : ' + amount + ', To : "' + To.Address );
// Saves the wallets
From.CloseWallet();
To.CloseWallet();
return true;
} else {
// Invalid Recipient Address
print("Invalid Recipient\n");
return false;
}
}
print("Transfer failed\n");
return false;
},Last updated