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

dao-params.json Deserialize->Validate->Serialize Workflow #297

Open
dOrgJelli opened this issue Mar 27, 2020 · 0 comments
Open

dao-params.json Deserialize->Validate->Serialize Workflow #297

dOrgJelli opened this issue Mar 27, 2020 · 0 comments

Comments

@dOrgJelli
Copy link
Contributor

Currently the dao-params.json schema is loosely defined. In order for developers to understand the full schema, they could look at the example dao-params.json in the repo, but this lacks completeness. To gain a full understanding they would have to look through how the dao-params are being used in the migrate-dao.js script.

I've tried to remedy this a bit by creating the sanitize.js script that defines a jsonschema for dao-params, but this is still a bit incomplete and hard to work with IMO. Reasons:

  • I've encountered issues using jsonschema's node package, where it does not traverse the document's AST and apply the schema correctly.
  • jsonschema doesn't provide a solution for serializing / deserializing.
  • jsonschema schemas defined in javascript do not give you typescript types to utilize else where.

In the DAOcreator I've solved the above by creating a serialize of forms that implement the dao-params schema. This form library uses an extended version formstate. These forms can be used to deserialize -> validate -> serialze. I propose that we adopt this form library.

Here's the DAO Form class which implements the schema.

Here's an example usage:

const daoParams = `{
  ...json string
}`

const dao = new DAOForm()
// deserialize
dao.fromJson(daoParams)
// modify
dao.$.orgName.value = 'something'
dao.$.founders.$.value = []
// validate
const res = await dao.validate()
console.log(res.hasError) // true
console.log(res.error) // founders must contain at least 1 item
// serialize
const json = dao.toJson()

Custom validators can be written to verify single properties, or cross verify multiple properties together. This is used in the DAOcreator to ensure these conditions for the genesis protocol are met: https://github.com/daostack/infra/blob/a09e9a524fbacc9fb39d5d1de8986dcf45c4889c/contracts/votingMachines/GenesisProtocolLogic.sol#L259-L264

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

No branches or pull requests

1 participant