I want to have a contract that releases an erc-20 token as soon as someone pays ether to contract. Let's call this contract Bid Contract. The abstract code goes like:
function askForTokens() public payable returns(bool){
uint coins = msg.value / rate;
token.transfer(msg.sender, coins);
BidSuccessful(msg.sender, rate, msg.value, coins);
return true;
}
function() payable{
askForTokens();
}
So, now when someone sends ethers to contract from his wallet, the fallback functions gets executed and which in turn calls the askForToken
function that will send corresponding tokens to msg.sender
.
I have tested the functionality and this seems to be working fine.
What I am concerned about is is there any security threat in this implementation?
I can find everywhere suggestion of not writing the logic in fallback
function, is the only reason is gas or this makes the contract more vulnerable?