poetapp / frost-api

Po.et's API Layer
https://api.poetnetwork.net
MIT License
24 stars 5 forks source link

feat: registries #1007

Closed lautarodragan closed 4 years ago

lautarodragan commented 4 years ago

This PR adds registries endpoints to Frost.

Users can use these registries by submitting the address of a registry known to them with the authenticated POST /registries endpoint, which creates an id for the registry, and later submit entries to the registry by calling POST /registries/:id { "cid": "ipfs-directory-hash" }.

A list of all registries owned by a user can be retrieved by calling GET /registries?ownerId=:userId. A single registry can be retrieved with its id. When requesting a single registry, its last 10 entries are also returned.

{
    "id": "8da12e34-e0c7-4bf3-82be-391a3faa4469",
    "ownerId": "1a747111-48cf-48c2-949e-e20c3f48ebba",
    "address": "0xcF4644e881fed66eBCf3f54a2956B1e397f5356B",
    "cidCount": 1,
    "cids": [
        "cid-here"
    ]
}

To enable interaction with Ethereum registries, an Ethereum account is created for each user upon sign up. For users that had signed up before this change, the creation of an Ethereum account can be manually requested by PATCH /users/:id { "ethereumRegistryPrivateKey": true }, where ethereumRegistryPrivateKey can be set to any truthy value. Calling this endpoint will not overwrite a present ethereumRegistryPrivateKey, only set it if unset.

The address of this account is exposed in GET /accounts/:issuer as ethereumRegistryAddress if the requester owns the requested account, but hidden from the general public.

This account is used to sign the transactions that add to the Ethereum registry, and the user will need to ensure this address has enough funds to pay for the transaction fees.

The implementation uses eth-lib's Account.create directly rather than web3's because

POST /registries/:id { "cid: "value" } does its best to create, sign and send the smart-contract-modifying transaction, catch any errors that happen and return as fast as possible.

For example, if the associated Ethereum account has insufficient balance to pay for fees, this error will be reported back to the user of the API immediately.

Not to block I/O, this call does not wait for any block confirmations whatsoever. This means that other possible errors, such as the transaction being reverted by the EVM or never being mined at all, will not be reported.

poet-ci commented 4 years ago

:tada: This PR is included in version 1.37.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: