/
StoreHook.sol
181 lines (171 loc) · 7.58 KB
/
StoreHook.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;
import { IStoreHook } from "./IStoreHook.sol";
import { IERC165 } from "./IERC165.sol";
import { EncodedLengths } from "./EncodedLengths.sol";
import { FieldLayout } from "./FieldLayout.sol";
import { ResourceId } from "./ResourceId.sol";
/**
* @title Store Hook Contract
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
* @notice This abstract contract provides hooks for the storage operations.
* @dev Implementers should override the hook functions to provide custom logic.
* If any hooks are activated without overriding these functions, they revert.
*/
abstract contract StoreHook is IStoreHook {
/**
* @notice Check if the interface is supported.
* @dev This function is a part of the ERC-165 standard.
* @param interfaceId The ID of the interface to check.
* @return true if the interface is supported, false otherwise.
*/
function supportsInterface(bytes4 interfaceId) public pure virtual returns (bool) {
return interfaceId == type(IStoreHook).interfaceId || interfaceId == type(IERC165).interfaceId;
}
/**
* @notice Hook that runs before setting a record.
* @dev This function should be overridden to provide custom logic.
* @param tableId The ID of the table where the record is to be set.
* @param keyTuple An array representing the composite key for the record.
* @param staticData The static data of the record.
* @param encodedLengths The encoded lengths of the dynamic data of the record.
* @param dynamicData The dynamic data of the record.
* @param fieldLayout The layout of the field, see FieldLayout.sol.
*/
function onBeforeSetRecord(
ResourceId tableId,
bytes32[] memory keyTuple,
bytes memory staticData,
EncodedLengths encodedLengths,
bytes memory dynamicData,
FieldLayout fieldLayout
) public virtual {
revert StoreHook_NotImplemented();
}
/**
* @notice Hook that runs after setting a record.
* @dev This function should be overridden to provide custom logic.
* @param tableId The ID of the table where the record was set.
* @param keyTuple An array representing the composite key for the record.
* @param staticData The static data of the record.
* @param encodedLengths The encoded lengths of the dynamic data of the record.
* @param dynamicData The dynamic data of the record.
* @param fieldLayout The layout of the field, see FieldLayout.sol.
*/
function onAfterSetRecord(
ResourceId tableId,
bytes32[] memory keyTuple,
bytes memory staticData,
EncodedLengths encodedLengths,
bytes memory dynamicData,
FieldLayout fieldLayout
) public virtual {
revert StoreHook_NotImplemented();
}
/**
* @notice Hook that runs before splicing static (fixed length) data.
* @dev This function should be overridden to provide custom logic.
* Splice operations in static data always overwrite data starting at
* the start position,
* so the total length of the data remains the same and no data is shifted.
* @param tableId The ID of the table where the data is to be spliced.
* @param keyTuple An array representing the composite key for the record.
* @param start The start byte position for splicing.
* @param data The data to be written to the static data of the record at the start byte.
*/
function onBeforeSpliceStaticData(
ResourceId tableId,
bytes32[] memory keyTuple,
uint48 start,
bytes memory data
) public virtual {
revert StoreHook_NotImplemented();
}
/**
* @notice Hook that runs after splicing static (fixed length) data.
* @dev This function should be overridden to provide custom logic.
* Splice operations in static data always overwrite data starting at
* the start position,
* so the total length of the data remains the same and no data is shifted.
* @param tableId The ID of the table where the data is to be spliced.
* @param keyTuple An array representing the composite key for the record.
* @param start The start byte position for splicing.
* @param data The data to be written to the static data of the record at the start byte.
*/
function onAfterSpliceStaticData(
ResourceId tableId,
bytes32[] memory keyTuple,
uint48 start,
bytes memory data
) public virtual {
revert StoreHook_NotImplemented();
}
/**
* @notice Hook that runs before splicing dynamic (variable length) data.
* @dev This function should be overridden to provide custom logic.
* Splice operations in dynamic data always reach the end of the dynamic data
* to avoid shifting data after the inserted or deleted data.
* @param tableId The ID of the table where the data is to be spliced.
* @param keyTuple An array representing the composite key for the record.
* @param dynamicFieldIndex The index of the dynamic field.
* @param startWithinField The start byte position within the field for splicing.
* @param deleteCount The number of bytes to delete in the dynamic data of the record.
* @param encodedLengths The encoded lengths of the dynamic data of the record.
* @param data The data to be inserted into the dynamic data of the record at the start byte.
*/
function onBeforeSpliceDynamicData(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint40 startWithinField,
uint40 deleteCount,
EncodedLengths encodedLengths,
bytes memory data
) public virtual {
revert StoreHook_NotImplemented();
}
/**
* @notice Hook that runs after splicing dynamic (variable length) data.
* @dev This function should be overridden to provide custom logic.
* Splice operations in dynamic data always reach the end of the dynamic data
* to avoid shifting data after the inserted or deleted data.
* @param tableId The ID of the table where the data is to be spliced.
* @param keyTuple An array representing the composite key for the record.
* @param dynamicFieldIndex The index of the dynamic field.
* @param startWithinField The start byte position within the field for splicing.
* @param deleteCount The number of bytes to delete in the dynamic data of the record.
* @param encodedLengths The encoded lengths of the dynamic data of the record.
* @param data The data to be inserted into the dynamic data of the record at the start byte.
*/
function onAfterSpliceDynamicData(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint40 startWithinField,
uint40 deleteCount,
EncodedLengths encodedLengths,
bytes memory data
) public virtual {
revert StoreHook_NotImplemented();
}
/**
* @notice Hook that runs before deleting a record.
* @dev This function should be overridden to provide custom logic.
* @param tableId The ID of the table where the record is to be deleted.
* @param keyTuple An array representing the composite key for the record.
* @param fieldLayout The layout of the field, see FieldLayout.sol.
*/
function onBeforeDeleteRecord(ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fieldLayout) public virtual {
revert StoreHook_NotImplemented();
}
/**
* @notice Hook that runs after deleting a record.
* @dev This function should be overridden to provide custom logic.
* @param tableId The ID of the table where the record is to be deleted.
* @param keyTuple An array representing the composite key for the record.
* @param fieldLayout The layout of the field, see FieldLayout.sol.
*/
function onAfterDeleteRecord(ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fieldLayout) public virtual {
revert StoreHook_NotImplemented();
}
}