I'm trying out a publisher-subscriber smart contracts in ganache.
Both the publisher and subscriber work independently, but when I try to invoke the subscriber from publisher through the contract address, I get below error:
"Error: VM Exception while processing transaction: revert".
Been searching on the net, but didn't find any solution.
Here is my code:
Producer.sol
//Mocking subscriber contract
contract Receiver {
function notify(uint count) returns(uint);
function getCurrentCounter() constant returns(uint);
}
//Publisher
contract Producer {
uint private count;
uint private subscriberCount;
mapping(uint => Subscriber) subscribers;
event CountIncreased(uint num);
struct Subscriber {
string subscriberName;
address subscriberAddress;
}
function Producer() {
count = 0;
subscriberCount = 0;
}
function increaseCount() returns(uint,address) {
count++;
Receiver receiver = Receiver(subscribers[0].subscriberAddress);
receiver.notify(count);
CountIncreased(count);
return (count,subscribers[0].subscriberAddress);
}
function addSubscriber(string name, address subAddress) {
subscriberCount++;
subscribers[subscriberCount].subscriberName = name ;
subscribers[subscriberCount].subscriberAddress = subAddress ;
}
function removeSubscriber(string subscriberName) {
for (uint i=0; i<subscriberCount; i++) {
Subscriber sub = subscribers[i];
if(keccak256(sub.subscriberName) == keccak256(subscriberName)) {
delete subscribers[i];
subscriberCount--;
}
}
}
}
Subscriber.sol
pragma solidity ^0.4.0;
contract Bookkeeping {
uint counter;
function Bookkeeping() {
counter = 0;
}
function notify(uint count) returns(uint) {
counter = count+5;
return counter;
}
function getCurrentCounter() constant returns(uint) {
return counter;
}
}
call
instead ofsendTransaction
when callingaddSubscriber
beforeincreaseCount
?