Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: message id #43

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/evm/contracts/Yaho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IAdapter } from "./interfaces/IAdapter.sol";

contract Yaho is IYaho, MessageIdCalculator, MessageHashCalculator {
mapping(uint256 => bytes32) private _pendingMessageHashes;
uint256 public currentNonce;

/// @inheritdoc IYaho
function dispatchMessage(
Expand Down Expand Up @@ -146,7 +147,7 @@ contract Yaho is IYaho, MessageIdCalculator, MessageHashCalculator {
) internal returns (uint256, bytes32) {
address sender = msg.sender;
Message memory message = Message(
keccak256(abi.encode(blockhash(block.number - 1), gasleft())),
currentNonce,
targetChainId,
threshold,
sender,
Expand All @@ -158,6 +159,9 @@ contract Yaho is IYaho, MessageIdCalculator, MessageHashCalculator {
bytes32 messageHash = calculateMessageHash(message);
uint256 messageId = calculateMessageId(block.chainid, address(this), messageHash);
_pendingMessageHashes[messageId] = messageHash;
unchecked {
++currentNonce;
}
emit MessageDispatched(messageId, message);
return (messageId, messageHash);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/contracts/interfaces/IMessage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IReporter } from "./IReporter.sol";
import { IAdapter } from "./IAdapter.sol";

struct Message {
bytes32 salt;
uint256 nonce;
uint256 targetChainId;
uint256 threshold;
address sender;
Expand Down
10 changes: 5 additions & 5 deletions packages/evm/test/utils/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Configs = {
id: string
receiver: `0x${string}`
targetChainId: number
salt: string
nonce: number
reporters: `0x${string}`[]
adapters: `0x${string}`[]
}
Expand All @@ -19,17 +19,17 @@ class Message {
public id: string
public receiver: `0x${string}`
public targetChainId: number
public salt: string
public nonce: number
public reporters: `0x${string}`[]
public adapters: `0x${string}`[]

constructor({ data, sender, threshold, id, receiver, targetChainId, salt, reporters, adapters }: Configs) {
constructor({ data, sender, threshold, id, receiver, targetChainId, nonce, reporters, adapters }: Configs) {
this.id = id
this.sender = sender
this.targetChainId = targetChainId
this.receiver = receiver
this.data = data
this.salt = salt
this.nonce = nonce
this.reporters = reporters
this.adapters = adapters
this.threshold = threshold
Expand All @@ -42,7 +42,7 @@ class Message {

serialize() {
return [
this.salt,
this.nonce,
this.targetChainId,
this.threshold,
this.sender,
Expand Down
Loading