Skip to content

Commit c3d0cce

Browse files
misc improvements assert return messages, fix standard naming inconsiste…
1 parent e2435d3 commit c3d0cce

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NEP11TemplatePy
2-
Fully featured NEP11 python contract to allow to easily deploy your own NFT minting contract, and make it seamless to integrate it on GhostMarket.
2+
Fully featured NEP-11 python contract to allow to easily deploy your own NFT minting contract, and make it seamless to integrate it on GhostMarket.
33

44

55
## Contract overview
@@ -37,7 +37,7 @@ This contract features two methods to handle properties:
3737

3838
`properties` and `propertiesJson`
3939

40-
`properties` returns a MAP of all the NFT metadata, and is what follows NEP11 standard (even though currently the standard is inconsistent as the signature shows it should be a MAP, while the explanation tied to it shows it should be a serialized NVM object).
40+
`properties` returns a MAP of all the NFT metadata, and is what follows NEP-11 standard (even though currently the standard is inconsistent as the signature shows it should be a MAP, while the explanation tied to it shows it should be a serialized NVM object).
4141

4242
`propertiesJson` returns a serialized JSON string of all the NFT metadata, and is what makes more sense for us to handle metadata.
4343

contracts/NEP11/NEP11-Template.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def balanceOf(owner: UInt160) -> int:
172172
:return: the total amount of tokens owned by the specified address.
173173
:raise AssertionError: raised if `owner` length is not 20.
174174
"""
175-
expect(validateAddress(owner), "Not a valid address")
175+
expect(validateAddress(owner), "balanceOf - not a valid address")
176176
debug(['balanceOf: ', get(mk_balance_key(owner), get_read_only_context()).to_int()])
177177
return get(mk_balance_key(owner), get_read_only_context()).to_int()
178178

@@ -188,7 +188,7 @@ def tokensOf(owner: UInt160) -> Iterator:
188188
:return: an iterator that contains all of the token ids owned by the specified address.
189189
:raise AssertionError: raised if `owner` length is not 20.
190190
"""
191-
expect(validateAddress(owner), "Not a valid address")
191+
expect(validateAddress(owner), "tokensOf - not a valid address")
192192
flags = FindOptions.REMOVE_PREFIX | FindOptions.KEYS_ONLY
193193
context = get_read_only_context()
194194
return find(mk_account_key(owner), context, flags)
@@ -218,8 +218,8 @@ def transfer(to: UInt160, tokenId: ByteString, data: Any) -> bool:
218218
:return: whether the transfer was successful
219219
:raise AssertionError: raised if `to` length is not 20 or if `tokenId` is not a valid NFT or if the contract is paused.
220220
"""
221-
expect(validateAddress(to), "Not a valid address")
222-
expect(not isPaused(), "Contract is currently paused")
221+
expect(validateAddress(to), "transfer - not a valid address")
222+
expect(not isPaused(), "transfer - contract paused")
223223
token_owner = get_owner_of(tokenId)
224224

225225
if not check_witness(token_owner):
@@ -238,7 +238,7 @@ def transfer(to: UInt160, tokenId: ByteString, data: Any) -> bool:
238238

239239
def post_transfer(token_owner: Union[UInt160, None], to: Union[UInt160, None], tokenId: ByteString, data: Any):
240240
"""
241-
Checks if the one receiving NEP11 tokens is a smart contract and if it's one the onPayment method will be called - internal
241+
Checks if the one receiving NEP-11 tokens is a smart contract and if it's one the onPayment method will be called - internal
242242
243243
:param token_owner: the address of the sender
244244
:type token_owner: UInt160
@@ -296,7 +296,7 @@ def properties(tokenId: ByteString) -> Dict[Any, Any]:
296296
:raise AssertionError: raised if `tokenId` is not a valid NFT, or if no metadata available.
297297
"""
298298
metaBytes = cast(str, get_meta(tokenId))
299-
expect(len(metaBytes) != 0, 'No metadata available for token')
299+
expect(len(metaBytes) != 0, 'properties - no metadata available for token')
300300
metaObject = cast(Dict[str, str], json_deserialize(metaBytes))
301301

302302
return metaObject
@@ -314,7 +314,7 @@ def propertiesJson(tokenId: ByteString) -> ByteString:
314314
:raise AssertionError: raised if `tokenId` is not a valid NFT, or if no metadata available.
315315
"""
316316
meta = get_meta(tokenId)
317-
expect(len(meta) != 0, 'No metadata available for token')
317+
expect(len(meta) != 0, 'propertiesJson - no metadata available for token')
318318
debug(['properties: ', meta])
319319
return meta
320320

@@ -374,7 +374,7 @@ def burn(tokenId: ByteString) -> bool:
374374
:return: whether the burn was successful.
375375
:raise AssertionError: raised if the contract is paused.
376376
"""
377-
expect(not isPaused(), "Contract is currently paused")
377+
expect(not isPaused(), "burn - contract paused")
378378
return internal_burn(tokenId)
379379

380380
@public
@@ -393,13 +393,13 @@ def mint(account: UInt160, meta: ByteString, lockedContent: ByteString, royaltie
393393
:return: tokenId of the token minted
394394
:raise AssertionError: raised if the contract is paused or if check witness fails.
395395
"""
396-
expect(validateAddress(account), "Not a valid address") # not really necessary because check_witness would catch an invalid address
397-
expect(not isPaused(), "Contract is currently paused")
396+
expect(validateAddress(account), "mint - not a valid address") # not really necessary because check_witness would catch an invalid address
397+
expect(not isPaused(), "mint - contract paused")
398398

399399
# TODO_TEMPLATE: add own logic if necessary, or uncomment below to restrict minting to contract authorized addresses
400400
# verified: bool = verify()
401401
# expect(verified, '`account` is not allowed for mint')
402-
expect(check_witness(account), "Invalid witness")
402+
expect(check_witness(account), "mint - invalid witness")
403403

404404
return internal_mint(account, meta, lockedContent, royalties)
405405

@@ -442,7 +442,7 @@ def getLockedContent(tokenId: ByteString) -> ByteString:
442442
"""
443443
owner = get_owner_of(tokenId)
444444

445-
expect(check_witness(owner), "Prohibited access to locked content!")
445+
expect(check_witness(owner), "getLockedContent - prohibited access to locked content!")
446446
set_locked_view_counter(tokenId)
447447

448448
debug(['getLockedContent: ', get_locked_content(tokenId)])
@@ -489,9 +489,9 @@ def setAuthorizedAddress(address: UInt160, authorized: bool):
489489
:raise AssertionError: raised if witness is not verified.
490490
"""
491491
verified: bool = verify()
492-
expect(verified, '`account` is not allowed for setAuthorizedAddress')
493-
expect(validateAddress(address), "Not a valid address")
494-
expect(isinstance(authorized, bool), "authorized has to be of type bool")
492+
expect(verified, 'setAuthorizedAddress - `account` is not allowed for setAuthorizedAddress')
493+
expect(validateAddress(address), "setAuthorizedAddress - not a valid address")
494+
expect(isinstance(authorized, bool), "setAuthorizedAddress - authorized has to be of type bool")
495495
serialized = get(AUTH_ADDRESSES, get_read_only_context())
496496
auth = cast(list[UInt160], deserialize(serialized))
497497

@@ -523,8 +523,8 @@ def updatePause(status: bool) -> bool:
523523
:raise AssertionError: raised if witness is not verified.
524524
"""
525525
verified: bool = verify()
526-
expect(verified, '`account` is not allowed for updatePause')
527-
expect(isinstance(status, bool), "status has to be of type bool")
526+
expect(verified, 'updatePause - `account` is not allowed for updatePause')
527+
expect(isinstance(status, bool), "updatePause - status has to be of type bool")
528528
put(PAUSED, status)
529529
debug(['updatePause: ', get(PAUSED, get_read_only_context()).to_bool()])
530530
return get(PAUSED, get_read_only_context()).to_bool()
@@ -577,7 +577,7 @@ def update(script: bytes, manifest: bytes):
577577
:raise AssertionError: raised if witness is not verified
578578
"""
579579
verified: bool = verify()
580-
expect(verified, '`account` is not allowed for update')
580+
expect(verified, 'update - `account` is not allowed for update')
581581
update_contract(script, manifest)
582582
debug(['update called and done'])
583583

@@ -589,7 +589,7 @@ def destroy():
589589
:raise AssertionError: raised if witness is not verified
590590
"""
591591
verified: bool = verify()
592-
expect(verified, '`account` is not allowed for destroy')
592+
expect(verified, 'destroy - `account` is not allowed for destroy')
593593
destroy_contract()
594594
debug(['destroy called and done'])
595595

@@ -633,7 +633,7 @@ def internal_mint(account: UInt160, meta: ByteString, lockedContent: ByteString,
633633
:return: tokenId of the token minted
634634
:raise AssertionError: raised if meta is empty, or if contract is paused.
635635
"""
636-
expect(len(meta) != 0, '`meta` can not be empty')
636+
expect(len(meta) != 0, 'internal_mint - `meta` can not be empty')
637637

638638
tokenId = get(TOKEN_COUNT, get_read_only_context()).to_int() + 1
639639
put(TOKEN_COUNT, tokenId)
@@ -651,7 +651,7 @@ def internal_mint(account: UInt160, meta: ByteString, lockedContent: ByteString,
651651
debug(['locked: ', lockedContent])
652652

653653
if len(royalties) != 0:
654-
expect(validateRoyalties(royalties), "Not a valid royalties format")
654+
expect(validateRoyalties(royalties), "internal_mint - not a valid royalties format")
655655
add_royalties(tokenIdBytes, cast(str, royalties))
656656
debug(['royalties: ', royalties])
657657

0 commit comments

Comments
 (0)