Drop Function
Drop: function (to, amount) {
// If the sender address is the contract owner and it is a positive amount
if (msg.From == this._owner && amount > 0) {
// Creates a new wallet instance
var Owner = Object.create(CRC_Wallet);
// Loads the owner's wallet
Owner.OpenWallet(this._owner);
// check if the owner has enough tokens for the drop
if(Owner.Balance < amount)
{
// Low balance
print("Low Balance\n");
return false;
}
// Create a new wallet instance
var To = Object.create(CRC_Wallet);
// Opens the recipient's wallet
if(To.OpenWallet(to)){
// If the wallet is available transfers the tokens to the recipient's Wallet
To.Balance += Number(amount);
// Removes the tokens out of the owner's wallet
Owner.Balance-= Number(amount);
// Removes the same amount of tokens out of the contract's balance
this._Balance -= Number(amount);
// Print the message in JSON format
println('Dropped : ' + amount + ', To : ' + To.Address);
// close the wallets
Owner.CloseWallet();
To.CloseWallet();
return true;
} else {
// Invalid Recipient Address
print("Invalid Recipient\n");
return false;
}
}
// unauthorized Drop
print("Invalid Drop\n");
return false;
}Observations (OBS):
Last updated