forked from 0xPolygon/fx-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFxChild.sol
33 lines (27 loc) · 1.21 KB
/
FxChild.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// IStateReceiver represents interface to receive state
interface IStateReceiver {
function onStateReceive(uint256 stateId, bytes calldata data) external;
}
// IFxMessageProcessor represents interface to process message
interface IFxMessageProcessor {
function processMessageFromRoot(uint256 stateId, address rootMessageSender, bytes calldata data) external;
}
/**
* @title FxChild child contract for state receiver
*/
contract FxChild is IStateReceiver {
address public fxRoot;
event NewFxMessage(address rootMessageSender, address receiver, bytes data);
function setFxRoot(address _fxRoot) external {
require(fxRoot == address(0x0));
fxRoot = _fxRoot;
}
function onStateReceive(uint256 stateId, bytes calldata _data) external override {
require(msg.sender == address(0x0000000000000000000000000000000000001001), "Invalid sender");
(address rootMessageSender, address receiver, bytes memory data) = abi.decode(_data, (address, address, bytes));
emit NewFxMessage(rootMessageSender, receiver, data);
IFxMessageProcessor(receiver).processMessageFromRoot(stateId, rootMessageSender, data);
}
}