1

I write this contracts. RegProvider creates Registrator and Counter, and Client connect to it. But when I do any action from Client, there are not any Events in RegProvider.

Where is my error? Any ideas...

pragma solidity ^0.4.8; 

contract RegProvider { 
address[] public registrators_contracts; 
address[] public counters_contracts; 

// EVENTS 
event EventReg(address useraddr); 
event EventTick(address useraddr, uint chislo); 
event EventRemove(address useraddr); 

function getRegistratorsContractCount() 
public 
returns(uint contractCount) 
{ 
return registrators_contracts.length; 
} 

function getCountersContractCount() 
public
returns(uint contractCount) 
{ 
return counters_contracts.length; 
} 

function NotifyRegister(address client) 
public 
{ 
EventReg(client); 
} 

function NotifyGetTick(address client, uint chislo) 
public 
{ 
EventTick(client, chislo); 
} 

function NotifyRemove(address client) 
public 
{ 
EventRemove(client); 
} 

function newRegistratorCounterPair() 
public 
{ 
Registrator reg = new Registrator(); 
registrators_contracts.push(reg); 
Counter cnt = new Counter(); 
counters_contracts.push(cnt); 
reg.set_counter_addr(cnt); 
reg.set_provider_addr(this); 
cnt.set_registrator_addr(reg); 
cnt.set_provider_addr(this); 
} 
} 

contract Registrator { 
address counter_addr; 
address provider_addr; 

function set_counter_addr(address myaddr) 
public 
{ 
counter_addr = myaddr; 
} 

function set_provider_addr(address myaddr) 
public 
{ 
provider_addr = myaddr; 
} 

function Register(address useraddr) 
public 
{ 
var rez = provider_addr.call(bytes4(sha3("NotifyRegister(address client)")), useraddr); 
uint random_number = uint(block.blockhash(block.number-1))%10 + 1; 
var rez2 = counter_addr.call(bytes4(sha3("SetInitNumber(address user_addr, uint init_number)")), useraddr, random_number); 
} 

function Remove(address useraddr) 
public 
{ 
var rez = provider_addr.call(bytes4(sha3("NotifyRemove(address client)")), useraddr); 
uint random_number = uint(block.blockhash(block.number-1))%10 + 1; 
var rez2 = counter_addr.call(bytes4(sha3("RemoveUser(address user_addr)")), useraddr); 
} 

} 

contract Counter { 
mapping (address => uint) usersInfo; 
mapping (address => bool) isAdmin; 
address registrator_addr; 
address provider_addr; 

function set_registrator_addr(address myaddr) 
public 
{ 
registrator_addr = myaddr; 
isAdmin[registrator_addr] = true; 
} 

function set_provider_addr(address myaddr) 
public 
{ 
provider_addr = myaddr; 
} 

function SetInitNumber(address user_addr, uint init_number) 
public 
{ 
//if (!isAdmin[msg.sender]) throw; 
usersInfo[user_addr] = init_number; 
} 

function TickNumber(address user_addr) 
public
returns (uint curval) 
{ 
uint currentvalue = usersInfo[user_addr]; 
var rez = provider_addr.call(bytes4(sha3("NotifyGetTick(address client, uint chislo)")), user_addr, currentvalue); 
usersInfo[user_addr] = usersInfo[user_addr]+1; 
return currentvalue; 
} 

function RemoveUser(address user_addr) 
public 
{ 
//if (!isAdmin[msg.sender]) throw; 
delete usersInfo[user_addr]; 
} 
}

And second...

pragma solidity ^0.4.8; 

contract Client { 
address public registrator_contract; 
address public counter_contract; 

function Client(address reg_addr, address cnt_addr) 
{ 
registrator_contract = reg_addr; 
counter_contract = cnt_addr; 
} 

function Register() 
public 
{ 
var rez = registrator_contract.call(bytes4(sha3("Register(address useraddr)")), msg.sender); 
} 

function GetTick() 
public 
{ 
var rez = counter_contract.call(bytes4(sha3("TickNumber(address user_addr)")), msg.sender); 
} 

function Remove() 
public 
{ 
var rez = registrator_contract.call(bytes4(sha3("Remove(address user_addr)")), msg.sender); 
} 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.