Skip to content

Commit

Permalink
CustomEntitlement -> CrossChainEntitlement implementation in go (#1083)
Browse files Browse the repository at this point in the history
The `ICrossChainEntitlement` type replaces `ICustomEntitlement` and
takes an abi-encoded byte array of parameters that is decoded by the
contract according to it's own application-specific logic.

This PR migrates the ISENTITLED check type to expect
ICrossChainEntitlement interfaces for ISENTITLED contracts and uses the
v2 check type to encode the parameter byte array for passing directly to
the contract.

A follow-up PR will be released that implements the typescript change
and re-enables e2e tests to complete #1046.
  • Loading branch information
clemire authored Sep 17, 2024
1 parent 39c372d commit 5ae1ad9
Show file tree
Hide file tree
Showing 29 changed files with 1,529 additions and 782 deletions.
34 changes: 34 additions & 0 deletions contracts/test/mocks/MockCrossChainEntitlement.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {ICrossChainEntitlement} from "contracts/src/spaces/entitlements/ICrossChainEntitlement.sol";

contract MockCrossChainEntitlement is ICrossChainEntitlement {
mapping(bytes32 => bool) public isEntitledByUserAndId;

function setIsEntitled(uint256 id, address user, bool entitled) external {
bytes32 hash = keccak256(abi.encode(user, id));
isEntitledByUserAndId[hash] = entitled;
}

function isEntitled(
address[] calldata users,
bytes calldata data
) external view returns (bool) {
uint256 id = abi.decode(data, (uint256));
for (uint256 i = 0; i < users.length; ++i) {
bytes32 hash = keccak256(abi.encode(users[i], id));
if (isEntitledByUserAndId[hash]) {
return true;
}
}

return false;
}

function parameters() external pure returns (Parameter[] memory) {
Parameter[] memory schema = new Parameter[](1);
schema[0] = Parameter("id", "uint256", "Simple parameter type for testing");
return schema;
}
}
4 changes: 0 additions & 4 deletions core/cmd/run_cs.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ out:
go xc.RunClientSimulator(bc, cmdConfig, wallet, xc.ERC20)
case 'b':
go xc.RunClientSimulator(bc, cmdConfig, wallet, xc.ERC721)
case 'c':
go xc.RunClientSimulator(bc, cmdConfig, wallet, xc.ISENTITLED)
case 'd':
go xc.RunClientSimulator(bc, cmdConfig, wallet, xc.TOGGLEISENTITLED)
case 'q':
log.Info("Quit Exit")
break out
Expand Down
324 changes: 324 additions & 0 deletions core/contracts/base/deploy/mock_cross_chain_entitlement.go

Large diffs are not rendered by default.

286 changes: 0 additions & 286 deletions core/contracts/base/deploy/mock_custom_entitlement.go

This file was deleted.

250 changes: 250 additions & 0 deletions core/contracts/base/i_cross_chain_entitlement.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5ae1ad9

Please sign in to comment.