I am trying to create a simple contract which adds the amount (passed as a parameter) to contract owner and reduces the equivalent amount from an account (account address passed as a parameter).
In the contract, I have created a second function 'getBalance' to inquire account balances.
After executing the transferamount
function when I inquire the account balances of contract owner and the passed account, they remain same with no increase or decrease of ethers. But when I verified the balances in the account balance mapping 'balanceOf' that I created in the code, I can see changes in amounts via the events that I set to watch balances before and after the transaction.
Pardon me for my noob status in solidity coding and kindly suggest what is an optimal way to implement requirement wherein we have to add or subtract a definite amount from user accounts and contract accounts. Also, please highlight errors in my code that can fix the issue.
Below is the logic of the code that I created.
pragma solidity ^0.4.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
/*
* @title Testing Oraclize
* Test contract to understand the basics of leveraging the Oraclize service.
*/
contract Betting is usingOraclize {
address public owner = msg.sender;
uint accountbalance;
/*Events*/
event Log(string);
event error(string error_);
event beforebetbalanceplayer(uint256);
event beforebetbalanceowner(uint256);
event afterbetbalanceplayer(uint256);
event afterbetbalanceowner(uint256);
event betamount(uint256);
/*Modifier*/
modifier onlyOwner {
require(msg.sender == owner);
_;
}
/*Constructor*/
/*Array*/
mapping (address => uint256) private balanceOf;
/*Put Bet*/
function transferamount (address _player, uint256 _amount) public payable {
balanceOf[_player] = _player.balance;
balanceOf[owner] = owner.balance;
beforebetbalanceplayer(balanceOf[_player]);
beforebetbalanceowner(balanceOf[owner]);
Log("Reducing amount from player's account");
balanceOf[_player] -= _amount;
afterbetbalanceplayer(balanceOf[_player]);
Log("Adding amount to owner's account");
balanceOf[owner] += _amount;
afterbetbalanceowner(balanceOf[owner]);
afterbetbalanceplayer(_player.balance);
afterbetbalanceowner(owner.balance);
}
/*Get Balance*/
function getBalance (address _account) constant returns(uint256){
return _account.balance;
}
/*Payable Fallback function*/
function() payable{
}
}