-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CU-86dt24n2g - Allow user to add/change icon link if they can verify … #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…themselves on the smart contract
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
from boa3.builtin.interop import runtime, storage | ||
from boa3.builtin.interop.blockchain import Transaction | ||
from boa3.builtin.interop.contract import Contract | ||
from boa3.builtin.interop.contract.contractmanifest import ContractAbi | ||
from boa3.builtin.interop.contract.contractmanifest import ContractManifest | ||
from boa3.builtin.interop.iterator import Iterator | ||
from boa3.builtin.nativecontract.contractmanagement import ContractManagement | ||
|
@@ -248,44 +249,46 @@ def get_contract_owner(script_hash: UInt160) -> Optional[UInt160]: | |
|
||
@public(name='setOwnership') | ||
def set_ownership(script_hash: UInt160, contract_owner: UInt160) -> bool: | ||
# if it's not icon dapp admin, needs to check if it's the contract deployer | ||
if runtime.check_witness(get_owner()): | ||
contract_deployer = contract_owner | ||
else: | ||
current_contract_owner: UInt160 = get_contract_owner(script_hash) | ||
# using two if's instead of one with a 'and' operation because it had runtime errors | ||
if isinstance(current_contract_owner, UInt160): | ||
# the contract owner can change the contract ownership | ||
# if it's not signed by the contract owner, checks if it's signed by the given address | ||
if not runtime.check_witness(current_contract_owner): | ||
if not runtime.check_witness(contract_owner): | ||
raise Exception('No authorization') | ||
|
||
contract_deployer = contract_owner | ||
else: | ||
if not runtime.check_witness(contract_owner): | ||
raise Exception('No authorization') | ||
|
||
contract_deployer = get_deployer(script_hash, contract_owner) | ||
|
||
if isinstance(contract_deployer, UInt160): | ||
if can_change_meta_data(script_hash, contract_owner): | ||
contract_owner_key = get_contract_owner_key(script_hash) | ||
storage.put(contract_owner_key, contract_deployer) | ||
storage.put(contract_owner_key, contract_owner) | ||
return True | ||
return False | ||
|
||
|
||
def get_deployer(script_hash: UInt160, sender: UInt160) -> Optional[UInt160]: | ||
contract: Contract = ContractManagement.get_contract(script_hash) | ||
@public(name='canChangeMetaData', safe=True) | ||
def can_change_meta_data(contract_script_hash: UInt160, contract_owner: UInt160) -> bool: | ||
contract: Contract = ContractManagement.get_contract(contract_script_hash) | ||
if not isinstance(contract, Contract): | ||
return None | ||
return False | ||
|
||
icon_dapp_owner = get_owner() | ||
melanke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if runtime.check_witness(icon_dapp_owner): | ||
return True | ||
|
||
computed_script_hash: bytes = _compute_contract_hash(sender, contract) | ||
if computed_script_hash != script_hash: | ||
return None | ||
contract_abi: ContractAbi = contract.manifest.abi | ||
has_verify = False | ||
for method in contract_abi.methods: | ||
melanke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if method.name == 'verify': | ||
has_verify = True | ||
break | ||
if has_verify: | ||
if runtime.check_witness(contract_script_hash): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider handling the case where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible for the check_witness to return |
||
return True | ||
else: | ||
return False | ||
|
||
current_contract_owner: UInt160 = get_contract_owner(contract_script_hash) | ||
if isinstance(current_contract_owner, UInt160): | ||
if runtime.check_witness(current_contract_owner): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider handling the case where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, is it possible for the check_witness to return |
||
return True | ||
|
||
return sender | ||
# check if the contract was deployed by the given address | ||
computed_script_hash: bytes = _compute_contract_hash(contract_owner, contract) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider handling the case where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible for the _compute_contract_hash to return None? |
||
if computed_script_hash == contract_script_hash: | ||
return True | ||
|
||
return False | ||
|
||
def _compute_contract_hash(sender: UInt160, contract: Contract) -> bytes: | ||
# there's a bug with calling contract.nef[:4] directly | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider renaming the function
can_change_meta_data
tocan_change_metadata
to follow the camelCase naming convention.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metadata is a single word. We should change on the annotation as well to
canChangeMetadata