Documentation
¶
Index ¶
- Constants
- func ConvertDocProofToClientFormat(proof *DocumentProof) (*documentpb.DocumentProof, error)
- func ConvertProofToClientFormat(proof *proofspb.Proof) *documentpb.Proof
- func ConvertProofsToClientFormat(proofs []*proofspb.Proof) []*documentpb.Proof
- func GRPCHandler(registry *ServiceRegistry) documentpb.DocumentServiceServer
- func IsCurrencyValid(cur string) bool
- func NewError(key, msg string) error
- type Bootstrapper
- type Config
- type DocumentProof
- type Error
- type Model
- type Repository
- type Service
- type ServiceRegistry
- type Validator
- type ValidatorFunc
- type ValidatorGroup
Constants ¶
const ( // BootstrappedRegistry is the key to ServiceRegistry in Bootstrap context BootstrappedRegistry = "BootstrappedRegistry" // BootstrappedDocumentRepository is the key to the database repository of documents BootstrappedDocumentRepository = "BootstrappedDocumentRepository" )
const ( // ErrDocumentConfigTenantID must be used for errors related to tenantID operations ErrDocumentConfigTenantID = errors.Error("error with tenantID operations") // ErrDocumentBootstrap must be used for errors related to documents package bootstrapping ErrDocumentBootstrap = errors.Error("error when bootstrapping document package") // ErrDocumentIdentifier must be used for errors caused by document identifier problems ErrDocumentIdentifier = errors.Error("document identifier error") // ErrDocumentInvalidType must be used when a provided document type is not valid to be processed by the service ErrDocumentInvalidType = errors.Error("document is of invalid type") // ErrDocumentNil must be used when the provided document through a function is nil ErrDocumentNil = errors.Error("no(nil) document provided") // ErrDocumentInvalid must only be used when the reason for invalidity is impossible to determine or the invalidity is caused by validation errors ErrDocumentInvalid = errors.Error("document is invalid") // ErrDocumentNotFound must be used to indicate that the document for provided id is not found in the system ErrDocumentNotFound = errors.Error("document not found in the system database") // ErrDocumentVersionNotFound must be used to indicate that the specified version of the document for provided id is not found in the system ErrDocumentVersionNotFound = errors.Error("specified version of the document not found in the system database") // ErrDocumentPersistence must be used when creating or updating a document in the system database failed ErrDocumentPersistence = errors.Error("error encountered when storing document in the system database") // ErrDocumentPackingCoreDocument must be used when packing of core document for the given document failed ErrDocumentPackingCoreDocument = errors.Error("core document packing failed") // ErrDocumentUnPackingCoreDocument must be used when unpacking of core document for the given document failed ErrDocumentUnPackingCoreDocument = errors.Error("core document unpacking failed") // ErrDocumentPrepareCoreDocument must be used when preparing a new core document fails for the given document ErrDocumentPrepareCoreDocument = errors.Error("core document preparation failed") // ErrDocumentSigning must be used when document signing related functionality fails ErrDocumentSigning = errors.Error("document signing failed") // ErrDocumentAnchoring must be used when document anchoring fails ErrDocumentAnchoring = errors.Error("document anchoring failed") // ErrDocumentCollaborator must be used when there is an error in processing collaborators ErrDocumentCollaborator = errors.Error("document collaborator issue") // ErrDocumentProof must be used when document proof creation fails ErrDocumentProof = errors.Error("document proof error") // ErrDocumentRepositoryModelNotRegistered must be used when the model hasn't been registered in the database repository ErrDocumentRepositoryModelNotRegistered = errors.Error("document model hasn't been registered in the database repository") // ErrDocumentRepositorySerialisation must be used when document repository encounters a marshalling error ErrDocumentRepositorySerialisation = errors.Error("document repository encountered a marshalling error") // ErrDocumentRepositoryModelNotFound must be used when document repository can not locate the given model ErrDocumentRepositoryModelNotFound = errors.Error("document repository could not locate the given model") // ErrDocumentRepositoryModelSave must be used when document repository can not save the given model ErrDocumentRepositoryModelSave = errors.Error("document repository could not save the given model") // ErrDocumentRepositoryModelAllReadyExists must be used when document repository finds an already existing model when saving ErrDocumentRepositoryModelAllReadyExists = errors.Error("document repository found an already existing model when saving") // ErrDocumentRepositoryModelDoesntExist must be used when document repository does not find an existing model for an update ErrDocumentRepositoryModelDoesntExist = errors.Error("document repository did not find an existing model for an update") )
Variables ¶
This section is empty.
Functions ¶
func ConvertDocProofToClientFormat ¶
func ConvertDocProofToClientFormat(proof *DocumentProof) (*documentpb.DocumentProof, error)
ConvertDocProofToClientFormat converts a DocumentProof to client api format
func ConvertProofToClientFormat ¶
func ConvertProofToClientFormat(proof *proofspb.Proof) *documentpb.Proof
ConvertProofToClientFormat converts a proof in precise proof format in to a client protobuf proof
func ConvertProofsToClientFormat ¶
func ConvertProofsToClientFormat(proofs []*proofspb.Proof) []*documentpb.Proof
ConvertProofsToClientFormat converts a proof protobuf from precise proofs into a client protobuf proof format
func GRPCHandler ¶
func GRPCHandler(registry *ServiceRegistry) documentpb.DocumentServiceServer
GRPCHandler returns an implementation of documentpb.DocumentServiceServer
func IsCurrencyValid ¶
IsCurrencyValid checks if the currency is of length 3
Types ¶
type Bootstrapper ¶
type Bootstrapper struct{}
Bootstrapper implements bootstrap.Bootstrapper.
func (Bootstrapper) Bootstrap ¶
func (Bootstrapper) Bootstrap(ctx map[string]interface{}) error
Bootstrap sets the required storage and registers
type Config ¶
type Config interface { // GetIdentityID retrieves the centID(TenentID) configured GetIdentityID() ([]byte, error) }
Config specified configs required by documents package
type DocumentProof ¶
type DocumentProof struct { DocumentID []byte VersionID []byte State string FieldProofs []*proofspb.Proof }
DocumentProof is a value to represent a document and its field proofs
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error wraps an error with specific key Deprecated: in favour of Error type in `github.com/centrifuge/go-centrifuge/errors`
type Model ¶
type Model interface { // Get the ID of the document represented by this model ID() ([]byte, error) // PackCoreDocument packs the implementing document into a core document // should create the identifiers for the core document if not present PackCoreDocument() (*coredocumentpb.CoreDocument, error) // UnpackCoreDocument must return the document.Model // assumes that core document has valid identifiers set UnpackCoreDocument(cd *coredocumentpb.CoreDocument) error //Returns the underlying type of the Model Type() reflect.Type // JSON return the json representation of the model JSON() ([]byte, error) // FromJSON initialize the model with a json FromJSON(json []byte) error }
Model is an interface to abstract away model specificness like invoice or purchaseOrder The interface can cast into the type specified by the model if required
func AnchorDocument ¶
func AnchorDocument(ctx *header.ContextHeader, model Model, proc anchorProcessor, updater updaterFunc) (Model, error)
AnchorDocument add signature, requests signatures, anchors document, and sends the anchored document to collaborators
type Repository ¶
type Repository interface { // Exists checks if the id, owned by tenantID, exists in DB Exists(tenantID, id []byte) bool // Get returns the Model associated with ID, owned by tenantID Get(tenantID, id []byte) (Model, error) // Create creates the model if not present in the DB. // should error out if the document exists. Create(tenantID, id []byte, model Model) error // Update strictly updates the model. // Will error out when the model doesn't exist in the DB. Update(tenantID, id []byte, model Model) error // Register registers the model so that the DB can return the document without knowing the type Register(model Model) }
Repository defines the required methods for a document repository. Can be implemented by any type that stores the documents. Ex: levelDB, sql etc...
func NewLevelDBRepository ¶
func NewLevelDBRepository(db *leveldb.DB) Repository
NewLevelDBRepository returns levelDb implementation of Repository
type Service ¶
type Service interface { // GetCurrentVersion reads a document from the database GetCurrentVersion(documentID []byte) (Model, error) // Exists checks if a document exists Exists(documentID []byte) bool // GetVersion reads a document from the database GetVersion(documentID []byte, version []byte) (Model, error) // DeriveFromCoreDocument derives a model given the core document DeriveFromCoreDocument(cd *coredocumentpb.CoreDocument) (Model, error) // CreateProofs creates proofs for the latest version document given the fields CreateProofs(documentID []byte, fields []string) (*DocumentProof, error) // CreateProofsForVersion creates proofs for a particular version of the document given the fields CreateProofsForVersion(documentID, version []byte, fields []string) (*DocumentProof, error) // RequestDocumentSignature Validates and Signs document received over the p2p layer RequestDocumentSignature(contextHeader *header.ContextHeader, model Model) (*coredocumentpb.Signature, error) // ReceiveAnchoredDocument receives a new anchored document over the p2p layer, validates and updates the document in DB ReceiveAnchoredDocument(model Model, headers *p2ppb.CentrifugeHeader) error }
Service provides an interface for functions common to all document types
type ServiceRegistry ¶
type ServiceRegistry struct {
// contains filtered or unexported fields
}
ServiceRegistry matches for a provided coreDocument the corresponding service
func NewServiceRegistry ¶
func NewServiceRegistry() *ServiceRegistry
NewServiceRegistry returns a new instance of service registry
func (*ServiceRegistry) FindService ¶
func (s *ServiceRegistry) FindService(documentID []byte) (Service, error)
FindService will search the service based on the documentID
func (*ServiceRegistry) LocateService ¶
func (s *ServiceRegistry) LocateService(serviceID string) (Service, error)
LocateService will return the registered service for the embedded document type
type Validator ¶
type Validator interface { // Validate validates the updates to the model in newState. Validate(oldState Model, newState Model) error }
Validator is an interface every Validator (atomic or group) should implement
type ValidatorFunc ¶
ValidatorFunc implements Validator and can be used as a adaptor for functions with specific function signature
func (ValidatorFunc) Validate ¶
func (vf ValidatorFunc) Validate(old, new Model) error
Validate passes the arguments to the underlying validator function and returns the results
type ValidatorGroup ¶
type ValidatorGroup []Validator
ValidatorGroup implements Validator for validating a set of validators.