Skip to content

proposal: refactor the View creation to be a Builder pattern #6

@dhuseby

Description

@dhuseby

After looking again at the interface for getting the different views on a Multikey, I think it makes sense to refactor that to be a Builder pattern. The general idea is to do the following:

  1. initialize a builder passing a reference to the multikey: ViewBuilder::new(&multikey)
  2. optionally add in the codec and view creation callback: .with_local_codec(codec, |mk, view_id| -> Box<dyn View> => { .. })
  3. call the build function to get the view: .build()

The main motivation for this comes from the proposal going into the multikey spec to support custom protocol keys: cryptidtech/provenance-specifications#4

By re-arranging the view building to a builder pattern we enable custom protocol implemenations to pass in callbacks that the builder will call to construct the view. This is how we can support user-defined custom protocol keys in the cleanest possible way. For the "standard" key types, the builder just calls the correct functions in the View interface implementation to construct the standard view.

This will be a breaking change since it will change the Multikey interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions