-
Notifications
You must be signed in to change notification settings - Fork 56
/
BasicMessageReceiver.sol
56 lines (49 loc) · 1.62 KB
/
BasicMessageReceiver.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {Withdraw} from "./utils/Withdraw.sol";
/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
* THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
* DO NOT USE THIS CODE IN PRODUCTION.
*/
contract BasicMessageReceiver is CCIPReceiver, Withdraw {
bytes32 latestMessageId;
uint64 latestSourceChainSelector;
address latestSender;
string latestMessage;
event MessageReceived(
bytes32 latestMessageId,
uint64 latestSourceChainSelector,
address latestSender,
string latestMessage
);
constructor(address router) CCIPReceiver(router) {}
function _ccipReceive(
Client.Any2EVMMessage memory message
) internal override {
latestMessageId = message.messageId;
latestSourceChainSelector = message.sourceChainSelector;
latestSender = abi.decode(message.sender, (address));
latestMessage = abi.decode(message.data, (string));
emit MessageReceived(
latestMessageId,
latestSourceChainSelector,
latestSender,
latestMessage
);
}
function getLatestMessageDetails()
public
view
returns (bytes32, uint64, address, string memory)
{
return (
latestMessageId,
latestSourceChainSelector,
latestSender,
latestMessage
);
}
}