Skip to content

Commit

Permalink
remove identityId parameter from createLink() and removeLink()
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcabot committed Oct 9, 2022
1 parent 4b534fa commit 4a04890
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 50 deletions.
28 changes: 19 additions & 9 deletions contracts/SoulLinker.sol
Expand Up @@ -17,12 +17,12 @@ contract SoulLinker is AccessControl, EIP712, ISoulLinker {

ISoulboundIdentity public soulboundIdentity;

// Identity.tokenId => NFT/SBT address => tokenId
mapping(uint256 => mapping(address => SoulLink)) private soulLinks;

// NFT/SBT address => tokenId = Identity.tokenId
mapping(address => mapping(uint256 => LinkToSoul)) private linksToSoul;

// Identity.tokenId => NFT/SBT address => tokenId
mapping(uint256 => mapping(address => SoulLink)) private soulLinks;

/* ========== INITIALIZE ================================================ */

/// @notice Creates a new soul linker
Expand All @@ -48,30 +48,31 @@ contract SoulLinker is AccessControl, EIP712, ISoulLinker {
/* ========== MUTATIVE FUNCTIONS ======================================== */

function createLink(
uint256 identityId,
address token,
uint256 tokenId,
uint256 expirationDate
) external override {
uint256 identityId = _getIdentityId(token, tokenId);

require(
_isIdentityApprovedOrOwner(_msgSender(), identityId),
"CALLER_NOT_IDENTITY_OWNER"
);

require(!soulLinks[identityId][token].exists, "LINK_EXISTS");
require(!linksToSoul[token][tokenId].exists, "LINK_EXISTS");
soulLinks[identityId][token] = SoulLink(true, tokenId, expirationDate);
linksToSoul[token][tokenId] = LinkToSoul(true, identityId);
}

function breakLink(
uint256 identityId,
address token,
uint256 tokenId
) external override {
function removeLink(address token, uint256 tokenId) external override {
uint256 identityId = _getIdentityId(token, tokenId);

require(
_isIdentityApprovedOrOwner(_msgSender(), identityId),
"CALLER_NOT_IDENTITY_OWNER"
);

require(soulLinks[identityId][token].exists, "LINK_NOT_EXISTS");
require(linksToSoul[token][tokenId].exists, "LINK_NOT_EXISTS");
soulLinks[identityId][token].exists = false;
Expand Down Expand Up @@ -117,6 +118,15 @@ contract SoulLinker is AccessControl, EIP712, ISoulLinker {

/* ========== PRIVATE FUNCTIONS ========================================= */

function _getIdentityId(address token, uint256 tokenId)
internal
view
returns (uint256)
{
address owner = IERC721(token).ownerOf(tokenId);
return soulboundIdentity.tokenOfOwner(owner);
}

function _isIdentityApprovedOrOwner(address caller, uint256 identityId)
internal
view
Expand Down
7 changes: 1 addition & 6 deletions contracts/interfaces/ISoulLinker.sol
Expand Up @@ -22,15 +22,10 @@ interface ISoulLinker {
returns (bool);

function createLink(
uint256 identityId,
address token,
uint256 tokenId,
uint256 expirationDate
) external;

function breakLink(
uint256 identityId,
address token,
uint256 tokenId
) external;
function removeLink(address token, uint256 tokenId) external;
}
38 changes: 18 additions & 20 deletions docs/SoulLinker.md
Expand Up @@ -27,28 +27,10 @@ function DEFAULT_ADMIN_ROLE() external view returns (bytes32)
|---|---|---|
| _0 | bytes32 | undefined |

### breakLink

```solidity
function breakLink(uint256 identityId, address token, uint256 tokenId) external nonpayable
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| identityId | uint256 | undefined |
| token | address | undefined |
| tokenId | uint256 | undefined |

### createLink

```solidity
function createLink(uint256 identityId, address token, uint256 tokenId, uint256 expirationDate) external nonpayable
function createLink(address token, uint256 tokenId, uint256 expirationDate) external nonpayable
```


Expand All @@ -59,7 +41,6 @@ function createLink(uint256 identityId, address token, uint256 tokenId, uint256

| Name | Type | Description |
|---|---|---|
| identityId | uint256 | undefined |
| token | address | undefined |
| tokenId | uint256 | undefined |
| expirationDate | uint256 | undefined |
Expand Down Expand Up @@ -175,6 +156,23 @@ function hasRole(bytes32 role, address account) external view returns (bool)
|---|---|---|
| _0 | bool | undefined |

### removeLink

```solidity
function removeLink(address token, uint256 tokenId) external nonpayable
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| token | address | undefined |
| tokenId | uint256 | undefined |

### renounceRole

```solidity
Expand Down
28 changes: 13 additions & 15 deletions docs/interfaces/ISoulLinker.md
Expand Up @@ -10,10 +10,10 @@

## Methods

### breakLink
### createLink

```solidity
function breakLink(uint256 identityId, address token, uint256 tokenId) external nonpayable
function createLink(address token, uint256 tokenId, uint256 expirationDate) external nonpayable
```


Expand All @@ -24,14 +24,14 @@ function breakLink(uint256 identityId, address token, uint256 tokenId) external

| Name | Type | Description |
|---|---|---|
| identityId | uint256 | undefined |
| token | address | undefined |
| tokenId | uint256 | undefined |
| expirationDate | uint256 | undefined |

### createLink
### hasLinks

```solidity
function createLink(uint256 identityId, address token, uint256 tokenId, uint256 expirationDate) external nonpayable
function hasLinks(address token, uint256 tokenId) external view returns (bool)
```


Expand All @@ -42,15 +42,19 @@ function createLink(uint256 identityId, address token, uint256 tokenId, uint256

| Name | Type | Description |
|---|---|---|
| identityId | uint256 | undefined |
| token | address | undefined |
| tokenId | uint256 | undefined |
| expirationDate | uint256 | undefined |

### hasLinks
#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | bool | undefined |

### removeLink

```solidity
function hasLinks(address token, uint256 tokenId) external view returns (bool)
function removeLink(address token, uint256 tokenId) external nonpayable
```


Expand All @@ -64,12 +68,6 @@ function hasLinks(address token, uint256 tokenId) external view returns (bool)
| token | address | undefined |
| tokenId | uint256 | undefined |

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | bool | undefined |




0 comments on commit 4a04890

Please sign in to comment.