2023-07-18 08:47:04 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
|
|
|
|
|
|
|
pragma solidity ^0.8.2;
|
|
|
|
|
|
|
|
contract TestStateSender {
|
|
|
|
|
|
|
|
uint256 public counter;
|
|
|
|
mapping(address => address) public registrations;
|
|
|
|
|
|
|
|
event NewRegistration(
|
|
|
|
address indexed user,
|
|
|
|
address indexed sender,
|
|
|
|
address indexed receiver
|
|
|
|
);
|
|
|
|
event RegistrationUpdated(
|
|
|
|
address indexed user,
|
|
|
|
address indexed sender,
|
|
|
|
address indexed receiver
|
|
|
|
);
|
|
|
|
event StateSynced(
|
|
|
|
uint256 indexed id,
|
|
|
|
address indexed contractAddress,
|
|
|
|
bytes data
|
|
|
|
);
|
|
|
|
|
|
|
|
modifier onlyRegistered(address receiver) {
|
2023-07-28 13:03:32 +00:00
|
|
|
//require(registrations[receiver] == msg.sender, "Invalid sender");
|
2023-07-18 08:47:04 +00:00
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
|
|
|
function syncState(address receiver, bytes calldata data)
|
|
|
|
external
|
|
|
|
onlyRegistered(receiver)
|
|
|
|
{
|
|
|
|
counter = counter = counter + 1;
|
|
|
|
emit StateSynced(counter, receiver, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// register new contract for state sync
|
|
|
|
function register(address sender, address receiver) public {
|
|
|
|
registrations[receiver] = sender;
|
|
|
|
if (registrations[receiver] == address(0)) {
|
|
|
|
emit NewRegistration(msg.sender, sender, receiver);
|
|
|
|
} else {
|
|
|
|
emit RegistrationUpdated(msg.sender, sender, receiver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|