Skip to content

Commit

Permalink
add setState() function
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcabot committed Nov 2, 2023
1 parent f17e9b6 commit 7905eb6
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 13 deletions.
1 change: 1 addition & 0 deletions contracts/libraries/Errors.sol
Expand Up @@ -14,6 +14,7 @@ error IdentityOwnerNotTokenOwner(uint256 tokenId, uint256 ownerIdentityId);
error InvalidPaymentMethod(address paymentMethod);
error InvalidSignature();
error InvalidSignatureDate(uint256 signatureDate);
error InvalidState(string state);
error InvalidToken(address token);
error InvalidTokenURI(string tokenURI);
error LinkAlreadyExists(
Expand Down
22 changes: 21 additions & 1 deletion contracts/tokens/MasaStatefulSBT.sol
Expand Up @@ -25,7 +25,7 @@ abstract contract MasaStatefulSBT is MasaSBT
// states for each address (preMintStates)
mapping (address => mapping (string => bool)) public addressStates;
// states for each token (postMintStates)
mapping (uint256 => mapping (string => bool)) public tokenIdStates;
mapping (uint256 => mapping (string => bool)) public tokenStates;

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

Expand Down Expand Up @@ -61,6 +61,26 @@ abstract contract MasaStatefulSBT is MasaSBT

/* ========== MUTATIVE FUNCTIONS ======================================== */

/// @notice Sets a state for an account
/// @dev
/// @param account Account to set the state for
/// @param state State to set
/// @param value Value of the state
function setState(address account, string memory state, bool value) external {
if (!_validPreMintStates[state]) revert InvalidState(state);
addressStates[account][state] = value;
}

/// @notice Sets a state for a token
/// @dev
/// @param tokenId Token to set the state for
/// @param state State to set
/// @param value Value of the state
function setState(uint256 tokenId, string memory state, bool value) external {
if (!_validPostMintStates[state]) revert InvalidState(state);
tokenStates[tokenId][state] = value;
}

/* ========== VIEWS ===================================================== */

/* ========== PRIVATE FUNCTIONS ========================================= */
Expand Down
76 changes: 64 additions & 12 deletions docs/tokens/MasaStatefulSBT.md
Expand Up @@ -927,6 +927,42 @@ Sets the stable coin to pay the fee in (USDC)
|---|---|---|
| _stableCoin | address | New stable coin to pay the fee in |

### setState

```solidity
function setState(address account, string state, bool value) external nonpayable
```

Sets a state for an account

*@param account Account to set the state for*

#### Parameters

| Name | Type | Description |
|---|---|---|
| account | address | undefined |
| state | string | State to set |
| value | bool | Value of the state |

### setState

```solidity
function setState(uint256 tokenId, string state, bool value) external nonpayable
```

Sets a state for a token

*@param tokenId Token to set the state for*

#### Parameters

| Name | Type | Description |
|---|---|---|
| tokenId | uint256 | undefined |
| state | string | State to set |
| value | bool | Value of the state |

### setSwapRouter

```solidity
Expand Down Expand Up @@ -1071,51 +1107,51 @@ function tokenByIndex(uint256 index) external view returns (uint256)
|---|---|---|
| _0 | uint256 | undefined |

### tokenIdStates
### tokenOfOwnerByIndex

```solidity
function tokenIdStates(uint256, string) external view returns (bool)
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256)
```




*See {ISBTEnumerable-tokenOfOwnerByIndex}.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined |
| _1 | string | undefined |
| owner | address | undefined |
| index | uint256 | undefined |

#### Returns

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

### tokenOfOwnerByIndex
### tokenStates

```solidity
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256)
function tokenStates(uint256, string) external view returns (bool)
```



*See {ISBTEnumerable-tokenOfOwnerByIndex}.*


#### Parameters

| Name | Type | Description |
|---|---|---|
| owner | address | undefined |
| index | uint256 | undefined |
| _0 | uint256 | undefined |
| _1 | string | undefined |

#### Returns

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

### tokenURI

Expand Down Expand Up @@ -1296,6 +1332,22 @@ error InvalidPaymentMethod(address paymentMethod)
|---|---|---|
| paymentMethod | address | undefined |

### InvalidState

```solidity
error InvalidState(string state)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| state | string | undefined |

### InvalidToken

```solidity
Expand Down

0 comments on commit 7905eb6

Please sign in to comment.