Skip to content

Commit

Permalink
feat: add external owned/minted/byId functions (#46)
Browse files Browse the repository at this point in the history
* feat: add external owned/minted/byId functions

* refactor: remove all function
  • Loading branch information
ethzoomer authored Feb 13, 2024
1 parent 56dcfaf commit 0d3f069
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
31 changes: 22 additions & 9 deletions contracts/GovNftSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,12 @@ def __init__(_nft: address):

@external
@view
def all(_account: address) -> DynArray[GovNft, MAX_RESULTS]:
def owned(_account: address) -> DynArray[GovNft, MAX_RESULTS]:
"""
@notice Returns all owned and minted GovNFTs for the given account
@notice Returns all owned GovNFTs for the given account
@return Array of GovNft structs
"""
govnfts: DynArray[GovNft, MAX_RESULTS] = self._owned(_account)
minted: DynArray[GovNft, MAX_RESULTS] = self._minted(_account)

for govnft in minted:
govnfts.append(govnft)

return govnfts
return self._owned(_account)

@internal
@view
Expand All @@ -104,6 +98,15 @@ def _owned(_account: address) -> DynArray[GovNft, MAX_RESULTS]:

return govnfts

@external
@view
def minted(_account: address) -> DynArray[GovNft, MAX_RESULTS]:
"""
@notice Returns all minted GovNFTs for the given account
@return Array of GovNft structs
"""
return self._minted(_account)

@internal
@view
def _minted(_account: address) -> DynArray[GovNft, MAX_RESULTS]:
Expand All @@ -126,6 +129,16 @@ def _minted(_account: address) -> DynArray[GovNft, MAX_RESULTS]:

return govnfts

@external
@view
def byId(_govnft_id: uint256) -> GovNft:
"""
@notice Returns GovNFT data based on ID
@param _govnft_id The GovNFT ID to look up
@return GovNft struct
"""
return self._byId(_govnft_id)

@internal
@view
def _byId(_govnft_id: uint256) -> GovNft:
Expand Down
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ The returned data/struct of type `GovNft` values represent:

The available methods are:

* `all(_account: address) -> GovNft[]` - returns a list of all `GovNft` structs owned or minted by the given account.
* `owned(_account: address) -> GovNft[]` - returns a list of all `GovNft` structs owned by the given account.
* `minted(_account: address) -> GovNft[]` - returns a list of all `GovNft` structs minted by the given account.
* `byId(_govnft_id: uint256) -> GovNft` - returns the `GovNft` based on the given ID.

## Development

Expand Down

0 comments on commit 0d3f069

Please sign in to comment.