From b5931bc66d2c1eed608bad2f9055e6e9f6c66673 Mon Sep 17 00:00:00 2001 From: Bob Stasyszyn Date: Thu, 22 Jun 2023 11:55:20 -0400 Subject: [PATCH] feat: Added Type and Properties to Operation Added two fields: - Type: The type of operation (create, update, recover, etc.) - Properties: An arbitrary set of properties of the operation Signed-off-by: Bob Stasyszyn --- pkg/api/operation/models.go | 11 +++++++++++ pkg/batch/cutter/cutter.go | 2 ++ pkg/dochandler/handler.go | 2 ++ 3 files changed, 15 insertions(+) diff --git a/pkg/api/operation/models.go b/pkg/api/operation/models.go index 2dbe9f4a..bbd4ec31 100644 --- a/pkg/api/operation/models.go +++ b/pkg/api/operation/models.go @@ -6,6 +6,12 @@ SPDX-License-Identifier: Apache-2.0 package operation +// Property contains a key-value pair. +type Property struct { + Key string + Value interface{} +} + // Operation holds minimum information required for parsing/validating client request. type Operation struct { @@ -23,6 +29,9 @@ type Operation struct { // AnchorOrigin defines anchor origin. AnchorOrigin interface{} + + // Properties contains an arbitrary set of implementation-specific name-value pairs. + Properties []Property } // Reference holds minimum information about did operation (suffix and type). @@ -90,10 +99,12 @@ const ( // QueuedOperation stores minimum required operation info for operations queue. type QueuedOperation struct { + Type Type OperationRequest []byte UniqueSuffix string Namespace string AnchorOrigin interface{} + Properties []Property } // QueuedOperationAtTime contains queued operation info with protocol genesis time. diff --git a/pkg/batch/cutter/cutter.go b/pkg/batch/cutter/cutter.go index ca34ca5b..6714431d 100644 --- a/pkg/batch/cutter/cutter.go +++ b/pkg/batch/cutter/cutter.go @@ -144,9 +144,11 @@ func getOperationsAtProtocolVersion(opsAtTime []*operation.QueuedOperationAtTime ops = append(ops, &operation.QueuedOperation{ + Type: op.Type, OperationRequest: op.OperationRequest, UniqueSuffix: op.UniqueSuffix, Namespace: op.Namespace, + Properties: op.Properties, }, ) } diff --git a/pkg/dochandler/handler.go b/pkg/dochandler/handler.go index c8bef56a..e2da451d 100644 --- a/pkg/dochandler/handler.go +++ b/pkg/dochandler/handler.go @@ -540,10 +540,12 @@ func (r *DocumentHandler) resolveRequestWithInitialState(uniqueSuffix, longFormD func (r *DocumentHandler) addToBatch(op *operation.Operation, versionTime uint64) error { return r.writer.Add( &operation.QueuedOperation{ + Type: op.Type, Namespace: r.namespace, UniqueSuffix: op.UniqueSuffix, OperationRequest: op.OperationRequest, AnchorOrigin: op.AnchorOrigin, + Properties: op.Properties, }, versionTime) }