Function to distribute token of another contract

AlxMrxAlxMrx Member Posts: 1
I have a deployed contract I use to distribute tokens on demand. The main functions in the contract are:


function getEthBalance(address _addr) constant public returns(uint) { return _addr.balance; } function distributeTokens(address[] addresses, uint256 _value, uint256 _ethbal) onlyOwner canDistr public { for (uint i = 0; i < addresses.length; i++) { if (getEthBalance(addresses[i]) < _ethbal) { continue; } balances[owner] -= _value; balances[addresses[i]] += _value; Transfer(owner, addresses[i], _value); } }


As you can see the function checks for a minimum balance in Ether before sending the tokens. Now I would like to also check for the token itself, with a new function in another contract (since it is already deployed). So I tried with this contract but it doesn't work:


contract ForeignToken { function balanceOf(address _owner) public constant returns (uint256); function transfer(address _to, uint256 _value) public returns (bool); } contract ERC20Basic { uint256 public totalSupply; function balanceOf(address who) public constant returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public constant returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint256 value); } contract tokenDistribution is ERC20 { address owner = msg.sender; ERC20 token; uint256 public totalSupply = 1000; function name() public constant returns (string) { return "TokenDistribution"; } function symbol() public constant returns (string) { return "TKD"; } function decimals() public constant returns (uint8) { return 8; } mapping (address => uint256) balances; mapping (address => mapping (address => uint256)) allowed; modifier onlyOwner { require(msg.sender == owner); _; } function setToken() public { token = ERC20(0x...); } function getTokenBalance(address holder) constant public returns (uint balance){ return token.balanceOf(holder); } function getEthBalance(address _addr) constant public returns(uint) { return _addr.balance; } function distributeTokens(address _tokenContract, address[] addresses, uint256 _value, uint256 _ethbal, uint256 _tokenbal) onlyOwner public { require(msg.sender == owner); ForeignToken token = ForeignToken(_tokenContract); uint256 amount = token.balanceOf(address(this)); for (uint i = 0; i < addresses.length; i++) { if (getEthBalance(addresses[i]) < _ethbal) { continue; } if (getTokenBalance(addresses[i]) < _tokenbal) { continue; } amount -= _value; balances[addresses[i]] += _value; Transfer(owner, addresses[i], _value); } } function withdrawForeignTokens(address _tokenContract) onlyOwner public returns (bool) { require(msg.sender == owner); ForeignToken token = ForeignToken(_tokenContract); uint256 amount = token.balanceOf(address(this)); return token.transfer(owner, amount); } }


The idea is to send some of the already deployed tokens to the new contract, and the distribute them with a new function. I had to give the new contract a name and supply since I couldn't deploy it without them. The problem is that the distributeTokens function doesn't distribute the "Foreign" token but its token itself. Any help? Thank you
Sign In or Register to comment.