Message passing interface between L1 and L2, sending and receiving data on the L1 side.
By abstracting the complexities of direct contract interactions, the L1CrossDomainMessenger provides users with a more user-friendly and reliable means of communication between different layers. This reduces the risk of errors and enhances the overall security of the transaction process. Users are strongly encouraged to utilize this interface instead of engaging with lower-level contracts directly, as it simplifies the process and leverages built-in security and efficiency optimizations inherent to the TON and ParaTon architectures.
import "@stdlib/deploy";
import "@stdlib/ownable";
contract L1CrossDomainMessenger with Deployable, Ownable {
// Contracts and configuration
superchainConfig: Address;
portal: Address;
version: String = "1.0.0";
owner: Address; // Add owner field
// Initial setup
init(superchainConfig: Address, portal: Address) {
self.superchainConfig = superchainConfig;
self.portal = portal;
self.owner = sender(); // Set the owner field
}
// Getter for portal contract address
get fun getPortal(): Address {
return self.portal;
}
// Sending a message through the portal
fun _sendMessage(_to: Address, _gasLimit: Int, _value: Int, _data: Cell) {
send(SendParameters{
to: self.portal,
value: _value,
body: beginCell()
.storeUint(_gasLimit, 64)
.storeCoins(_value)
.storeRef(_data)
.endCell()
});
}
// Check if the sender is the other messenger
fun _isOtherMessenger(): Bool {
return sender() == self.portal; // Check if it is the other messenger
}
// Check if the target address is unsafe
fun _isUnsafeTarget(_target: Address): Bool {
return _target == myAddress() || _target == self.portal;
}
// Check if the contract is paused
get fun paused(): Bool {
// There is currently no actual paused method, so return false
return false; // Substitute for actual logic
}
}