The Admin
contract class in our token contract is responsible for defining administrative privileges. It includes a single entry point: setAdministrator
. This entry point allows the current administrator to assign a new administrator.
Python
class Admin(sp.Contract):
def __init__(self, administrator):
self.init(administrator=administrator)
@sp.entrypointdef setAdministrator(self, params):
sp.verify(sp.sender == self.data.administrator)
self.data.administrator = params
The setAdministrator
function verifies that only the current administrator can execute this function. If the verification fails, the operation is rejected. If it passes, the function proceeds to assign the new administrator.
The Pause
contract class provides a mechanism to pause and unpause the contract operations. It includes an entry point setPause
that can change the paused status of the contract.
Python
class Pause(sp.Contract):
def __init__(self):
self.init(paused=False)
@sp.entrypointdef setPause(self, params):
sp.verify(sp.sender == self.data.administrator)
self.data.paused = params
The function setPause
first checks that the operation is performed by the administrator. If the check passes, it updates the paused status of the contract.
The Mint
contract class enables increasing the token supply. It comes with a mint
entry point that increases the total supply and updates the balance of a particular address.
Python
class Mint(sp.Contract):
@sp.entrypointdef mint(self, params):
sp.verify(sp.sender == self.data.administrator)
self.data.total_supply += params.value
self.data.balances[params.address].balance += params.value
The mint
function first verifies that the sender is the administrator. Then, it increases the total supply and the balance of the address specified.
The Burn
contract class is for decreasing the token supply. It has a burn
entry point which reduces the total supply and the balance of a specific address.
Python
class Burn(sp.Contract):
@sp.entrypointdef burn(self, params):
sp.verify(sp.sender == self.data.administrator)
self.data.total_supply -= params.value
self.data.balances[params.address].balance -= params.value
The burn
function operates similarly to the mint
function but decreases the total supply and the balance of the specified address instead.
With the following code, the Admin burns Bob token
Python
sc.h2("Admin burns Bob token")
c1.burn(address=bob.address, value=1).run(sender=admin)
The ChangeMetadata
contract class is for updating the metadata of the contract. It includes a function update_metadata
which updates a key-value pair in the metadata.
Python
class ChangeMetadata(sp.Contract):
@sp.entrypointdef update_metadata(self, key, value):
sp.verify(sp.sender == self.data.administrator)
self.data.metadata[key] = value
The update_metadata
function, similar to the previous functions, verifies that the sender is the administrator. Then, it updates the specified key-value pair in the metadata.
In the next lesson, we will delve into the final contract that includes all these functionalities, Fa1_2TestFull
. We will learn about how this contract inherits from all the classes we discussed today and how they all contribute to the token’s functionality. Stay tuned!
The Admin
contract class in our token contract is responsible for defining administrative privileges. It includes a single entry point: setAdministrator
. This entry point allows the current administrator to assign a new administrator.
Python
class Admin(sp.Contract):
def __init__(self, administrator):
self.init(administrator=administrator)
@sp.entrypointdef setAdministrator(self, params):
sp.verify(sp.sender == self.data.administrator)
self.data.administrator = params
The setAdministrator
function verifies that only the current administrator can execute this function. If the verification fails, the operation is rejected. If it passes, the function proceeds to assign the new administrator.
The Pause
contract class provides a mechanism to pause and unpause the contract operations. It includes an entry point setPause
that can change the paused status of the contract.
Python
class Pause(sp.Contract):
def __init__(self):
self.init(paused=False)
@sp.entrypointdef setPause(self, params):
sp.verify(sp.sender == self.data.administrator)
self.data.paused = params
The function setPause
first checks that the operation is performed by the administrator. If the check passes, it updates the paused status of the contract.
The Mint
contract class enables increasing the token supply. It comes with a mint
entry point that increases the total supply and updates the balance of a particular address.
Python
class Mint(sp.Contract):
@sp.entrypointdef mint(self, params):
sp.verify(sp.sender == self.data.administrator)
self.data.total_supply += params.value
self.data.balances[params.address].balance += params.value
The mint
function first verifies that the sender is the administrator. Then, it increases the total supply and the balance of the address specified.
The Burn
contract class is for decreasing the token supply. It has a burn
entry point which reduces the total supply and the balance of a specific address.
Python
class Burn(sp.Contract):
@sp.entrypointdef burn(self, params):
sp.verify(sp.sender == self.data.administrator)
self.data.total_supply -= params.value
self.data.balances[params.address].balance -= params.value
The burn
function operates similarly to the mint
function but decreases the total supply and the balance of the specified address instead.
With the following code, the Admin burns Bob token
Python
sc.h2("Admin burns Bob token")
c1.burn(address=bob.address, value=1).run(sender=admin)
The ChangeMetadata
contract class is for updating the metadata of the contract. It includes a function update_metadata
which updates a key-value pair in the metadata.
Python
class ChangeMetadata(sp.Contract):
@sp.entrypointdef update_metadata(self, key, value):
sp.verify(sp.sender == self.data.administrator)
self.data.metadata[key] = value
The update_metadata
function, similar to the previous functions, verifies that the sender is the administrator. Then, it updates the specified key-value pair in the metadata.
In the next lesson, we will delve into the final contract that includes all these functionalities, Fa1_2TestFull
. We will learn about how this contract inherits from all the classes we discussed today and how they all contribute to the token’s functionality. Stay tuned!