Skip to content

Commit

Permalink
chore: clean up and add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kopy-kat committed May 21, 2024
1 parent 830f6f9 commit d1f5829
Show file tree
Hide file tree
Showing 8 changed files with 911 additions and 16 deletions.
18 changes: 18 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "solhint:recommended",
"rules": {
"avoid-low-level-calls": "off",
"code-complexity": ["error", 9],
"compiler-version": ["error", ">=0.8.0"],
"contract-name-camelcase": "off",
"const-name-snakecase": "off",
"func-name-mixedcase": "off",
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 123],
"named-parameters-mapping": "warn",
"no-empty-blocks": "off",
"not-rely-on-time": "off",
"one-contract-per-file": "off",
"var-name-mixedcase": "off"
}
}
2 changes: 2 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
test/
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,62 @@ The library comes with linked lists in different flavors:

## Using the library

todo
In a contract, you can use the `SentinelList` library to store a linked list of addresses:

```solidity
contract Example {
using SentinelListLib for SentinelListLib.SentinelList;
// Declare a variable to store the data
// Note: this can also be in a mapping or other data structure
SentinelListLib.SentinelList list;
function set(address newAddress) external {
// Store the data
list.push(newAddress);
}
function get(uint256 size) external view returns (address[] memory addressArray) {
// Retrieve the data
(addressArray,) = list.getEntriesPaginated(SENTINEL, size);
}
}
```

### Available functions

#### `SentinelListLib`

- `init(SentinelList storage self)`: Initialize the list (required before using the list and will revert if the list is already initialized)
- `alreadyInitialized(SentinelList storage self)`: Check if the list is already initialized
- `getNext(SentinelList storage self, address entry)`: Get the next entry in the list
- `push(SentinelList storage self, address newEntry)`: Add a new entry to the list
- `pop(SentinelList storage self, address prevEntry, address popEntry)`: Remove an entry from the list
- `popAll(SentinelList storage self)`: Remove all entries from the list
- `contains(SentinelList storage self, address entry)`: Check if an entry is in the list
- `getEntriesPaginated(SentinelList storage self, address start, uint256 size)`: Get a paginated list of entries from `start` with a maximum of `size` entries

#### `SentinelList4337Lib`

- `init(SentinelList storage self, address account)`: Initialize the list (required before using the list and will revert if the list is already initialized)
- `alreadyInitialized(SentinelList storage self, address account)`: Check if the list is already initialized
- `getNext(SentinelList storage self, address account, address entry)`: Get the next entry in the list
- `push(SentinelList storage self, address account, address newEntry)`: Add a new entry to the list
- `pop(SentinelList storage self, address account, address prevEntry, address popEntry)`: Remove an entry from the list
- `popAll(SentinelList storage self, address account)`: Remove all entries from the list
- `contains(SentinelList storage self, address account, address entry)`: Check if an entry is in the list
- `getEntriesPaginated(SentinelList storage self, address account, address start, uint256 size)`: Get a paginated list of entries from `start` with a maximum of `size` entries

#### `LinkedBytes32Lib`

- `init(LinkedBytes32 storage self)`: Initialize the list (required before using the list and will revert if the list is already initialized)
- `alreadyInitialized(LinkedBytes32 storage self)`: Check if the list is already initialized
- `getNext(LinkedBytes32 storage self, bytes32 entry)`: Get the next entry in the list
- `push(LinkedBytes32 storage self, bytes32 newEntry)`: Add a new entry to the list
- `pop(LinkedBytes32 storage self, bytes32 prevEntry, bytes32 popEntry)`: Remove an entry from the list
- `popAll(LinkedBytes32 storage self)`: Remove all entries from the list
- `contains(LinkedBytes32 storage self, bytes32 entry)`: Check if an entry is in the list
- `getEntriesPaginated(LinkedBytes32 storage self, bytes32 start, uint256 size)`: Get a paginated list of entries from `start` with a maximum of `size` entries

## Using this repo

Expand Down
Loading

0 comments on commit d1f5829

Please sign in to comment.