Skip to content

Commit 596d57b

Browse files
committed
undo msg hasher
1 parent 60f7b9a commit 596d57b

File tree

5 files changed

+127
-163
lines changed

5 files changed

+127
-163
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.4;
3+
4+
import {Client} from "../../libraries/Client.sol";
5+
6+
contract MessageHasher {
7+
function encodeEVMExtraArgsV1(
8+
Client.EVMExtraArgsV1 memory extraArgs
9+
) public pure returns (bytes memory) {
10+
return Client._argsToBytes(extraArgs);
11+
}
12+
13+
function encodeEVMExtraArgsV2(
14+
Client.GenericExtraArgsV2 memory extraArgs
15+
) public pure returns (bytes memory) {
16+
return Client._argsToBytes(extraArgs);
17+
}
18+
19+
function encodeGenericExtraArgsV2(
20+
Client.GenericExtraArgsV2 memory extraArgs
21+
) public pure returns (bytes memory) {
22+
return Client._argsToBytes(extraArgs);
23+
}
24+
25+
function encodeGenericExtraArgsV3(
26+
Client.EVMExtraArgsV3 memory extraArgs
27+
) public pure returns (bytes memory) {
28+
return Client._argsToBytes(extraArgs);
29+
}
30+
31+
function decodeEVMExtraArgsV1(
32+
uint256 gasLimit
33+
) public pure returns (Client.EVMExtraArgsV1 memory) {
34+
return Client.EVMExtraArgsV1(gasLimit);
35+
}
36+
37+
function decodeGenericExtraArgsV2(
38+
uint256 gasLimit,
39+
bool allowOutOfOrderExecution
40+
) public pure returns (Client.GenericExtraArgsV2 memory) {
41+
return Client.GenericExtraArgsV2({gasLimit: gasLimit, allowOutOfOrderExecution: allowOutOfOrderExecution});
42+
}
43+
44+
function decodeEVMExtraArgsV2(
45+
uint256 gasLimit,
46+
bool allowOutOfOrderExecution
47+
) public pure returns (Client.GenericExtraArgsV2 memory) {
48+
return Client.GenericExtraArgsV2({gasLimit: gasLimit, allowOutOfOrderExecution: allowOutOfOrderExecution});
49+
}
50+
51+
function encodeSVMExtraArgsV1(
52+
Client.SVMExtraArgsV1 memory extraArgs
53+
) public pure returns (bytes memory) {
54+
return Client._svmArgsToBytes(extraArgs);
55+
}
56+
57+
function encodeSUIExtraArgsV1(
58+
Client.SuiExtraArgsV1 memory extraArgs
59+
) public pure returns (bytes memory) {
60+
return Client._suiArgsToBytes(extraArgs);
61+
}
62+
63+
/// @notice used offchain to decode an encoded SVMExtraArgsV1 struct.
64+
/// @dev The unrolled version fails due to differences in encoding when the accounts[] array
65+
/// is empty or not.
66+
function decodeSVMExtraArgsStruct(
67+
Client.SVMExtraArgsV1 memory extraArgs
68+
)
69+
public
70+
pure
71+
returns (
72+
uint32 computeUnits,
73+
uint64 accountIsWritableBitmap,
74+
bool allowOutOfOrderExecution,
75+
bytes32 tokenReceiver,
76+
bytes32[] memory accounts
77+
)
78+
{
79+
return (
80+
extraArgs.computeUnits,
81+
extraArgs.accountIsWritableBitmap,
82+
extraArgs.allowOutOfOrderExecution,
83+
extraArgs.tokenReceiver,
84+
extraArgs.accounts
85+
);
86+
}
87+
88+
/// @notice Used offchain to decode an encoded SuiExtraArgsV1 struct.
89+
function decodeSuiExtraArgsStruct(
90+
Client.SuiExtraArgsV1 memory extraArgs
91+
)
92+
public
93+
pure
94+
returns (uint256 gasLimit, bool allowOutOfOrderExecution, bytes32 tokenReceiver, bytes32[] memory receiverObjectIds)
95+
{
96+
return
97+
(extraArgs.gasLimit, extraArgs.allowOutOfOrderExecution, extraArgs.tokenReceiver, extraArgs.receiverObjectIds);
98+
}
99+
}

0 commit comments

Comments
 (0)