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

Multiple Dropper v0.2.0 API improvements #299

Merged
merged 12 commits into from
May 9, 2023

Conversation

zomglings
Copy link
Collaborator

@zomglings zomglings commented May 1, 2023

Changes

Queries and responses on /contracts/requests now show contract_address

Now the caller can specify contract_id or contract_address as a query parameter.

At least one of those parameters should be provided.

registered_contract_id in response is now contract_id.

The response also contains a contract_address field.

Resolves #283

Create call_requests using contract ID or contract address

This change allows users to create call requests by posting to /contracts/requests with a JSON body which contains a "contract_id" key or a "contract_address" key.

This change also removes the old /contracts/<contract_id>/requests POST endpoint.

Resolves #298

Moved POST /contracts/register to POST /contracts/

This makes the API more RESTful.

POST /contracts/ documentation shows contract_type as an enum

Previously, this parameter of the request body was being displayed as a string.

Resolves #276

Allow users to edit registered contracts

added a PUT /contracts/<contract_id> endpoint, which allows users to modify the title, description, and image URI for a contract. These changes only apply to the Moonstream Engine API.

Resolves #296

Updated waggle to respect new API changes

  • Queries and responses on /contracts/requests
  • Create call_requests using contract ID or contract address

Unique constraint on registered_contracts modified to include moonstream_user_id

This allows different users to register the same contract under their respective accounts.

Resolves #295

ttl_days is not longer directly inserted into raw SQL

Also fixed a bug on how the list call requests endpoint handled call requests with null expires_at fields - it led to a 500 error before.

Resolves #300

How to test these changes?

Tested manually.

Now the caller can specify `contract_id` or `contract_address` as a
query parameter.

At least one of those parameters should be provided.

`registered_contract_id` in response is now `contract_id`.

The response also contains a `contract_address` field.
@zomglings zomglings requested a review from kompotkot May 1, 2023 22:25
zomglings added 2 commits May 1, 2023 15:26
This allows them to create call requests by contract_id *or* by
contract_address.

I have added `"contract_id"` and `"contract_address"` keys to
`CreateCallRequestsAPIRequest`:

```python
class CreateCallRequestsAPIRequest(BaseModel):
    contract_id: Optional[UUID] = None
    contract_address: Optional[str] = None
    specifications: List[CallSpecification] = Field(default_factory=list)
    ttl_days: Optional[int] = None
```

At least one of those keys must have a non-null value.

Resolves #298
@zomglings zomglings force-pushed the dropper-v0.2.0-api-improvements branch from 7e0b57b to 28e0c35 Compare May 1, 2023 22:49
zomglings added 8 commits May 1, 2023 15:59
Using Pydantic root validator to ensure that at least one of contract_id
or contract_address is provided in the request body (these are optional
fields in the JSON).
This makes the API more RESTful.

- - -

The `POST /contracts/` endpoint also now displays the `contract_type`
enum values in API docs.

Resolves #276

- - -

Also added a PUT `/contracts/<contract_id>` endpoint, which allows users
to modify the title, description, and image URI for a contract. These
changes only apply to the Moonstream Engine API.

Resolves #296
The constraint now includes `moonstream_user_id`. This allows multiple
users to register the same contract.

Resolves #295
when `call_requests` are created from the API. Also fixed a bug where
the `CallRequest` response object did not respect `null` `expired_at`
fields.
@zomglings
Copy link
Collaborator Author

zomglings commented May 2, 2023

@bugout-dev check

  • Run migration on production database

api/engineapi/routes/contracts.py Show resolved Hide resolved
@@ -160,6 +160,7 @@ class RegisteredContract(Base): # type: ignore
__table_args__ = (
UniqueConstraint(
"blockchain",
"moonstream_user_id",
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure if we run migration we will not get error bacause of hitting uniqe constraint?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this feature was just launched into production and there are only two rows in production database under this relation currently.

@zomglings zomglings mentioned this pull request May 8, 2023
4 tasks
Copy link
Contributor

@kompotkot kompotkot left a comment

Choose a reason for hiding this comment

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

lg

@zomglings
Copy link
Collaborator Author

@zomglings zomglings merged commit 772d817 into main May 9, 2023
@zomglings zomglings deleted the dropper-v0.2.0-api-improvements branch May 9, 2023 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment