Contract con_nameservice_v3


Contract Code


  
1 # THIS IS LST003 STANDARD
2 # You will be able to use these custom receiver names on the Lamden Wallet App and maybe Vault.
3 # A mint costs 1 Tau
4
5
6 import currency as tau
7 collection_name = Variable() # The name of the collection for display
8 collection_owner = Variable() # Only the owner can mint new NFTs for this collection
9 collection_nfts = Hash(default_value=0) # All NFTs of the collection
10 collection_balances = Hash(default_value=0) # All user balances of the NFTs
11 collection_balances_approvals = Hash(default_value=0) # Approval amounts of certain NFTs
12
13 @construct
14 def seed(name: str, owner: str):
15 collection_name.set(name) # Sets the name
16 collection_owner.set(owner) # Sets the owner
17
18 # function to mint a new NFT
19 @export
20 def mint_nft(name: str):
21 name = name.lower()
22 assert name.isalnum() == True, "Only alphanumeric characters allowed"
23 assert name != "", "Name cannot be empty"
24 assert collection_nfts[name] == 0, "Name already exists"
25 assert len(name) >= 3, "The minimum length is 3 characters"
26
27 tau.transfer_from(amount=1, to=collection_owner.get(), main_account=ctx.caller)
28 collection_nfts[name] = {"description": "A domain in the Lamden Name Service", "ipfs_image_url": "", "metadata": {}, "amount": 1} # Adds NFT to collection with all details
29 collection_balances[ctx.caller, name] = 1 # Mints the NFT
30
31 # standard transfer function
32 @export
33 def transfer(name: str, amount:int, to: str):
34 assert amount > 0, "You cannot transfer negative amounts"
35 assert name != "", "Please specify the name of the NFT you want to transfer"
36 assert collection_balances[ctx.caller, name] >= amount, "You don't have enough NFTs to send"
37
38 collection_balances[ctx.caller, name] -= amount # Removes amount from sender
39 collection_balances[to, name] += amount # Adds amount to receiver
40
41 # allows other account to spend on your behalf
42 @export
43 def approve(amount: int, name: str, to: str):
44 assert amount > 0, "Cannot approve negative amounts"
45
46 collection_balances_approvals[ctx.caller, to, name] += amount # Approves certain amount for spending by another account
47
48 # transfers on your behalf
49 @export
50 def transfer_from(name:str, amount:int, to: str, main_account: str):
51 assert amount > 0, 'Cannot send negative balances!'
52
53 assert collection_balances_approvals[main_account, to, name] >= amount, "Not enough NFTs approved to send! You have {} and are trying to spend {}"\
54 .format(collection_balances_approvals[main_account, to, name], amount)
55 assert collection_balances[main_account, name] >= amount, "Not enough NFTs to send!"
56
57 collection_balances_approvals[main_account, to, name] -= amount # Removes Approval Amount
58 collection_balances[main_account, name] -= amount # Removes amount from sender
59 collection_balances[to, name] += amount # Adds amount to receiver

Byte Code

e3000000000000000000000000060000004000000073c4000000640064016c005a0165026402640364048d025a0365026402640564048d025a04650564006402640664078d035a06650564006402640864078d035a07650564006402640964078d035a0865096509640a9c02640b640c84045a0a650b640283016509640d9c01640e640f840483015a0c650b640283016509650d650964109c0364116412840483015a0e650b64028301650d6509650964139c0364146415840483015a0f650b640283016509650d6509650964169c0464176418840483015a10640153002919e9000000004eda12636f6e5f6e616d65736572766963655f7633da0f636f6c6c656374696f6e5f6e616d652902da08636f6e7472616374da046e616d65da10636f6c6c656374696f6e5f6f776e6572da0f636f6c6c656374696f6e5f6e6674732903da0d64656661756c745f76616c756572040000007205000000da13636f6c6c656374696f6e5f62616c616e636573da1d636f6c6c656374696f6e5f62616c616e6365735f617070726f76616c7329027205000000da056f776e6572630200000000000000020000000200000043000000731800000074006a017c008301010074026a017c01830101006400530029014e2903da115f5f636f6c6c656374696f6e5f6e616d65da03736574da125f5f636f6c6c656374696f6e5f6f776e657229027205000000720b000000a900720f000000da00da045f5f5f5f0e000000730400000000010a01721100000029017205000000630100000000000000010000000500000043000000738e0000007c006a0083007d007c006a01830064016b02731c74026402830182017c0064036b03732c740264048301820174037c00190064056b027340740264068301820174047c00830164076b057354740264088301820174056a06640974076a08830074096a0a640a8d030100640b640369006409640c9c0474037c003c006409740b74096a0a7c0066023c0064005300290d4e547a244f6e6c7920616c7068616e756d65726963206368617261637465727320616c6c6f77656472100000007a144e616d652063616e6e6f7420626520656d70747972010000007a134e616d6520616c726561647920657869737473e9030000007a22546865206d696e696d756d206c656e67746820697320332063686172616374657273e9010000002903da06616d6f756e74da02746fda0c6d61696e5f6163636f756e747a234120646f6d61696e20696e20746865204c616d64656e204e616d6520536572766963652904da0b6465736372697074696f6eda0e697066735f696d6167655f75726cda086d657461646174617214000000290cda056c6f776572da076973616c6e756dda0e417373657274696f6e4572726f72da115f5f636f6c6c656374696f6e5f6e667473da036c656eda03746175da0d7472616e736665725f66726f6d720e000000da03676574da03637478da0663616c6c6572da155f5f636f6c6c656374696f6e5f62616c616e63657329017205000000720f000000720f0000007210000000da086d696e745f6e66741300000073140000000002080114011001140114010c010a0204010e017225000000290372050000007214000000721500000063030000000000000003000000040000004300000073680000007c0164016b04731074006402830182017c0064036b0373207400640483018201740174026a037c00660219007c016b05733a7400640583018201740174026a037c006602050019007c01380003003c0074017c027c006602050019007c01370003003c006400530029064e72010000007a24596f752063616e6e6f74207472616e73666572206e6567617469766520616d6f756e747372100000007a37506c65617365207370656369667920746865206e616d65206f6620746865204e465420796f752077616e7420746f207472616e736665727a22596f7520646f6e2774206861766520656e6f756768204e46547320746f2073656e642904721c0000007224000000722200000072230000002903720500000072140000007215000000720f000000720f0000007210000000da087472616e7366657222000000730c0000000002100110010c010e01160172260000002903721400000072050000007215000000630300000000000000030000000400000043000000732c0000007c0064016b0473107400640283018201740174026a037c027c016603050019007c00370003003c006400530029034e72010000007a1f43616e6e6f7420617070726f7665206e6567617469766520616d6f756e74732904721c000000da1f5f5f636f6c6c656374696f6e5f62616c616e6365735f617070726f76616c73722200000072230000002903721400000072050000007215000000720f000000720f0000007210000000da07617070726f76652c00000073040000000002100172280000002904720500000072140000007215000000721600000063040000000000000004000000060000004300000073960000007c0164016b047310740064028301820174017c037c027c00660319007c016b05733c740064036a0274017c037c027c00660319007c0183028301820174037c037c00660219007c016b057354740064048301820174017c037c027c006603050019007c01380003003c0074037c037c006602050019007c01380003003c0074037c027c006602050019007c01370003003c006400530029054e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a484e6f7420656e6f756768204e46547320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a184e6f7420656e6f756768204e46547320746f2073656e64212904721c0000007227000000da06666f726d6174722400000029047205000000721400000072150000007216000000720f000000720f00000072100000007220000000320000007312000000000210010c010c0114010a010e011601140172200000002911da0863757272656e6379721f000000da085661726961626c65720c000000720e000000da0448617368721d00000072240000007227000000da037374727211000000da085f5f6578706f72747225000000da03696e74722600000072280000007220000000720f000000720f000000720f0000007210000000da083c6d6f64756c653e01000000732600000008010401080104010801060108010601080104010a0310050601100e06011409060114050601