Skip to content
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

feat: Support Register/List/Update Smart Contract #65

Open
wants to merge 8 commits into
base: v0.13.0
Choose a base branch
from

Conversation

jianlunz-cb
Copy link

@jianlunz-cb jianlunz-cb commented Dec 17, 2024

What changed? Why?

Support Register/List/Update Smart Contract

Test:

>>> SmartContract.register(contract_name="Test Contract", contract_address="0x0000000071727de22e5e9d8baf0edac6f37da040", network_id="base-sepolia", abi=[
...   {
...     "constant": True,
...     "name": "myField",
...     "outputs": [
...       {
...         "name": "",
...         "type": "uint256"
...       }
...     ],
...     "type": "function"
...   }
... ])

CDP API RESPONSE: Status: 200, Data: b'{"abi":"[{\\"constant\\":true,\\"name\\":\\"myField\\",\\"outputs\\":[{\\"name\\":\\"\\",\\"type\\":\\"uint256\\"}],\\"type\\":\\"function\\"}]","contract_address":"0x0000000071727De22e5E9d8bAF0EDaC6f37Da040","contract_name":"Test Contract","is_external":true,"network_id":"base-sepolia","smart_contract_id":"0104b87a-6617-45f4-924f-06b26e21d77e","type":"custom"}\n'
SmartContract: (smart_contract_id: 0104b87a-6617-45f4-924f-06b26e21d77e, wallet_id: None, network_id: base-sepolia, contract_address: 0x0000000071727De22e5E9d8bAF0EDaC6f37Da040, type: custom, transaction_hash: None, transaction_link: None, status: None)
>>> SmartContract.update(contract_name="Updated Test Contract", contract_address="0x0000000071727de22e5e9d8baf0edac6f37da040", network_id="base-sepolia", abi=[
...   {
...     "constant": False,
...     "name": "newField",
...     "outputs": [
...       {
...         "name": "",
...         "type": "uint256"
...       }
...     ],
...     "type": "function"
...   }
... ])

CDP API RESPONSE: Status: 200, Data: b'{"abi":"[{\\"constant\\":false,\\"name\\":\\"newField\\",\\"outputs\\":[{\\"name\\":\\"\\",\\"type\\":\\"uint256\\"}],\\"type\\":\\"function\\"}]","contract_address":"0x0000000071727De22e5E9d8bAF0EDaC6f37Da040","contract_name":"Updated Test Contract","is_external":true,"network_id":"base-sepolia","smart_contract_id":"0104b87a-6617-45f4-924f-06b26e21d77e","type":"custom"}\n'
SmartContract: (smart_contract_id: 0104b87a-6617-45f4-924f-06b26e21d77e, wallet_id: None, network_id: base-sepolia, contract_address: 0x0000000071727De22e5E9d8bAF0EDaC6f37Da040, type: custom, transaction_hash: None, transaction_link: None, status: None)
>>> l = SmartContract.list()
>>> for sc in l:
...      print(sc)

{"abi":"[{\\"constant\\":false,\\"name\\":\\"newField\\",\\"outputs\\":[{\\"name\\":\\"\\",\\"type\\":\\"uint256\\"}],\\"type\\":\\"function\\"}]","contract_address":"0x0000000071727de22e5e9d8baf0edac6f37da040","contract_name":"Updated Test Contract","is_external":false,"network_id":"base-sepolia","smart_contract_id":"","type":"custom"}
SmartContract: (smart_contract_id: , wallet_id: None, network_id: base-sepolia, contract_address: 0x0000000071727de22e5e9d8baf0edac6f37da040, type: custom, transaction_hash: None, transaction_link: None, status: None)

Qualified Impact

@cb-heimdall
Copy link

cb-heimdall commented Dec 17, 2024

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

@jianlunz-cb jianlunz-cb marked this pull request as ready for review December 17, 2024 07:20
@alex-stone alex-stone changed the base branch from master to v0.13.0 December 17, 2024 19:29
@@ -141,6 +156,16 @@ def deployer_address(self) -> str:
"""
return self._model.deployer_address

@property
def is_external(self) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return a boolean

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch updated


"""
return self._model.contract_name

@property
def deployer_address(self) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now a lot of these other properties will be only set if is_external is false.

This is the NodeJS change we had to make to support this:
coinbase/coinbase-sdk-nodejs@94680a6#diff-2c6bead48767df9b8a842ac4887f9e676b0b38a3b6fc2c4bdb7ff6e2d9ddbb7dR227

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a check of the external fields before returning. If it looks good I'll apply it to the nodejs change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it looks good I'll apply it to the nodejs change

I just linked the change that was made to the NodeJS to handle this!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll also want to handle #sign, #wait, #broadcast, etc... to ensure they throw appropriate errors when called on external contracts

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, updated! Thank you

@alex-stone
Copy link
Contributor

Can you make sure your commits are getting verified?

You may need git config scoped to this repo that includes your specific external GitHub username + signing key configuration

@John-peterson-coinbase
Copy link
Contributor

Please rebase down to only verified commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants