Skip to content

Commit

Permalink
Shorten definition handler filenames
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
  • Loading branch information
awrichar committed Jun 28, 2022
1 parent 27ae1f3 commit 58ec5b4
Show file tree
Hide file tree
Showing 30 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ $(eval $(call makemock, internal/broadcast, Manager, broadcast
$(eval $(call makemock, internal/privatemessaging, Manager, privatemessagingmocks))
$(eval $(call makemock, internal/shareddownload, Manager, shareddownloadmocks))
$(eval $(call makemock, internal/shareddownload, Callbacks, shareddownloadmocks))
$(eval $(call makemock, internal/definitions, DefinitionHandler, definitionsmocks))
$(eval $(call makemock, internal/definitions, Handler, definitionsmocks))
$(eval $(call makemock, internal/definitions, Sender, definitionsmocks))
$(eval $(call makemock, internal/events, EventManager, eventmocks))
$(eval $(call makemock, internal/namespace, Manager, namespacemocks))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"github.com/hyperledger/firefly/pkg/dataexchange"
)

type DefinitionHandler interface {
type Handler interface {
HandleDefinitionBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (HandlerResult, error)
HandleDefinition(ctx context.Context, state *core.BatchState, msg *core.Message, data *core.Data) error
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func (dma DefinitionMessageAction) String() string {
}
}

type definitionHandlers struct {
type definitionHandler struct {
namespace string
multiparty bool
database database.Plugin
Expand All @@ -89,11 +89,11 @@ type definitionHandlers struct {
contracts contracts.Manager
}

func NewDefinitionHandler(ctx context.Context, ns string, multiparty bool, di database.Plugin, bi blockchain.Plugin, dx dataexchange.Plugin, dm data.Manager, im identity.Manager, am assets.Manager, cm contracts.Manager) (DefinitionHandler, error) {
func NewDefinitionHandler(ctx context.Context, ns string, multiparty bool, di database.Plugin, bi blockchain.Plugin, dx dataexchange.Plugin, dm data.Manager, im identity.Manager, am assets.Manager, cm contracts.Manager) (Handler, error) {
if di == nil || bi == nil || dm == nil || im == nil || am == nil || cm == nil {
return nil, i18n.NewError(ctx, coremsgs.MsgInitializationNilDepError, "DefinitionHandler")
}
return &definitionHandlers{
return &definitionHandler{
namespace: ns,
multiparty: multiparty,
database: di,
Expand All @@ -106,7 +106,7 @@ func NewDefinitionHandler(ctx context.Context, ns string, multiparty bool, di da
}, nil
}

func (dh *definitionHandlers) HandleDefinitionBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (msgAction HandlerResult, err error) {
func (dh *definitionHandler) HandleDefinitionBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (msgAction HandlerResult, err error) {
l := log.L(ctx)
l.Infof("Processing system definition '%s' [%s]", msg.Header.Tag, msg.Header.ID)
switch msg.Header.Tag {
Expand Down Expand Up @@ -135,7 +135,7 @@ func (dh *definitionHandlers) HandleDefinitionBroadcast(ctx context.Context, sta
}
}

func (dh *definitionHandlers) getSystemBroadcastPayload(ctx context.Context, msg *core.Message, data core.DataArray, res core.Definition) (valid bool) {
func (dh *definitionHandler) getSystemBroadcastPayload(ctx context.Context, msg *core.Message, data core.DataArray, res core.Definition) (valid bool) {
l := log.L(ctx)
if len(data) != 1 {
l.Warnf("Unable to process system definition %s - expecting 1 attachment, found %d", msg.Header.ID, len(data))
Expand All @@ -150,7 +150,7 @@ func (dh *definitionHandlers) getSystemBroadcastPayload(ctx context.Context, msg
return true
}

func (dh *definitionHandlers) HandleDefinition(ctx context.Context, state *core.BatchState, msg *core.Message, data *core.Data) error {
func (dh *definitionHandler) HandleDefinition(ctx context.Context, state *core.BatchState, msg *core.Message, data *core.Data) error {
result, err := dh.HandleDefinitionBroadcast(ctx, state, msg, core.DataArray{data}, nil)
if result.Action == ActionReject {
return i18n.WrapError(ctx, err, coremsgs.MsgDefinitionRejected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/hyperledger/firefly/pkg/database"
)

func (dh *definitionHandlers) persistFFI(ctx context.Context, ffi *core.FFI) (err error) {
func (dh *definitionHandler) persistFFI(ctx context.Context, ffi *core.FFI) (err error) {
if err = dh.contracts.ResolveFFI(ctx, ffi); err != nil {
log.L(ctx).Warnf("Unable to process FFI %s - validate failed: %s", ffi.ID, err)
return nil
Expand Down Expand Up @@ -55,7 +55,7 @@ func (dh *definitionHandlers) persistFFI(ctx context.Context, ffi *core.FFI) (er
return nil
}

func (dh *definitionHandlers) persistContractAPI(ctx context.Context, api *core.ContractAPI) (retry bool, err error) {
func (dh *definitionHandler) persistContractAPI(ctx context.Context, api *core.ContractAPI) (retry bool, err error) {
existing, err := dh.database.GetContractAPIByName(ctx, api.Namespace, api.Name)
if err != nil {
return true, err
Expand All @@ -75,7 +75,7 @@ func (dh *definitionHandlers) persistContractAPI(ctx context.Context, api *core.
return false, nil
}

func (dh *definitionHandlers) handleFFIBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (HandlerResult, error) {
func (dh *definitionHandler) handleFFIBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (HandlerResult, error) {
l := log.L(ctx)
var ffi core.FFI
if valid := dh.getSystemBroadcastPayload(ctx, msg, data, &ffi); !valid {
Expand All @@ -98,7 +98,7 @@ func (dh *definitionHandlers) handleFFIBroadcast(ctx context.Context, state *cor
return HandlerResult{Action: ActionConfirm}, nil
}

func (dh *definitionHandlers) handleContractAPIBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (HandlerResult, error) {
func (dh *definitionHandler) handleContractAPIBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (HandlerResult, error) {
l := log.L(ctx)
var api core.ContractAPI
if valid := dh.getSystemBroadcastPayload(ctx, msg, data, &api); !valid {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/hyperledger/firefly/pkg/core"
)

func (dh *definitionHandlers) handleDatatypeBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (HandlerResult, error) {
func (dh *definitionHandler) handleDatatypeBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (HandlerResult, error) {
var dt core.Datatype
valid := dh.getSystemBroadcastPayload(ctx, msg, data, &dt)
if !valid {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import (
"github.com/hyperledger/firefly/pkg/database"
)

func (dh *definitionHandlers) handleIdentityClaimBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, verificationID *fftypes.UUID) (HandlerResult, error) {
func (dh *definitionHandler) handleIdentityClaimBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, verificationID *fftypes.UUID) (HandlerResult, error) {
var claim core.IdentityClaim
if valid := dh.getSystemBroadcastPayload(ctx, msg, data, &claim); !valid {
return HandlerResult{Action: ActionReject}, i18n.NewError(ctx, coremsgs.MsgDefRejectedBadPayload, "identity claim", msg.Header.ID)
}
return dh.handleIdentityClaim(ctx, state, msg, &claim, verificationID)
}

func (dh *definitionHandlers) verifyClaimSignature(ctx context.Context, msg *core.Message, identity *core.Identity, parent *core.Identity) error {
func (dh *definitionHandler) verifyClaimSignature(ctx context.Context, msg *core.Message, identity *core.Identity, parent *core.Identity) error {
author := msg.Header.Author
if author == "" {
return i18n.NewError(ctx, coremsgs.MsgDefRejectedAuthorBlank, "identity claim", msg.Header.ID)
Expand All @@ -60,7 +60,7 @@ func (dh *definitionHandlers) verifyClaimSignature(ctx context.Context, msg *cor
return nil
}

func (dh *definitionHandlers) getClaimVerifier(msg *core.Message, identity *core.Identity) *core.Verifier {
func (dh *definitionHandler) getClaimVerifier(msg *core.Message, identity *core.Identity) *core.Verifier {
verifier := &core.Verifier{
Identity: identity.ID,
Namespace: identity.Namespace,
Expand All @@ -77,7 +77,7 @@ func (dh *definitionHandlers) getClaimVerifier(msg *core.Message, identity *core
return verifier
}

func (dh *definitionHandlers) confirmVerificationForClaim(ctx context.Context, state *core.BatchState, msg *core.Message, identity, parent *core.Identity) (*fftypes.UUID, error) {
func (dh *definitionHandler) confirmVerificationForClaim(ctx context.Context, state *core.BatchState, msg *core.Message, identity, parent *core.Identity) (*fftypes.UUID, error) {
// Query for messages on the topic for this DID, signed by the right identity
idTopic := identity.Topic()
fb := database.MessageQueryFactory.NewFilter(ctx)
Expand Down Expand Up @@ -126,7 +126,7 @@ func (dh *definitionHandlers) confirmVerificationForClaim(ctx context.Context, s
return nil, nil
}

func (dh *definitionHandlers) handleIdentityClaim(ctx context.Context, state *core.BatchState, msg *core.Message, identityClaim *core.IdentityClaim, verificationID *fftypes.UUID) (HandlerResult, error) {
func (dh *definitionHandler) handleIdentityClaim(ctx context.Context, state *core.BatchState, msg *core.Message, identityClaim *core.IdentityClaim, verificationID *fftypes.UUID) (HandlerResult, error) {
l := log.L(ctx)

identity := identityClaim.Identity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/hyperledger/firefly/pkg/database"
)

func (dh *definitionHandlers) handleIdentityUpdateBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray) (HandlerResult, error) {
func (dh *definitionHandler) handleIdentityUpdateBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray) (HandlerResult, error) {
var update core.IdentityUpdate
if valid := dh.getSystemBroadcastPayload(ctx, msg, data, &update); !valid {
return HandlerResult{Action: ActionReject}, i18n.NewError(ctx, coremsgs.MsgDefRejectedBadPayload, "identity update", msg.Header.ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/hyperledger/firefly/pkg/core"
)

func (dh *definitionHandlers) handleIdentityVerificationBroadcast(ctx context.Context, state *core.BatchState, verifyMsg *core.Message, data core.DataArray) (HandlerResult, error) {
func (dh *definitionHandler) handleIdentityVerificationBroadcast(ctx context.Context, state *core.BatchState, verifyMsg *core.Message, data core.DataArray) (HandlerResult, error) {
var verification core.IdentityVerification
valid := dh.getSystemBroadcastPayload(ctx, verifyMsg, data, &verification)
if !valid {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/hyperledger/firefly/pkg/core"
)

func (dh *definitionHandlers) handleNamespaceBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (HandlerResult, error) {
func (dh *definitionHandler) handleNamespaceBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (HandlerResult, error) {
var ns core.Namespace
if valid := dh.getSystemBroadcastPayload(ctx, msg, data, &ns); !valid {
return HandlerResult{Action: ActionReject}, i18n.NewError(ctx, coremsgs.MsgDefRejectedBadPayload, "namespace", msg.Header.ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/hyperledger/firefly/pkg/core"
)

func (dh *definitionHandlers) handleDeprecatedNodeBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray) (HandlerResult, error) {
func (dh *definitionHandler) handleDeprecatedNodeBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray) (HandlerResult, error) {
var nodeOld core.DeprecatedNode
if valid := dh.getSystemBroadcastPayload(ctx, msg, data, &nodeOld); !valid {
return HandlerResult{Action: ActionReject}, i18n.NewError(ctx, coremsgs.MsgDefRejectedBadPayload, "node", msg.Header.ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/hyperledger/firefly/pkg/core"
)

func (dh *definitionHandlers) handleDeprecatedOrganizationBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray) (HandlerResult, error) {
func (dh *definitionHandler) handleDeprecatedOrganizationBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray) (HandlerResult, error) {

var orgOld core.DeprecatedOrganization
valid := dh.getSystemBroadcastPayload(ctx, msg, data, &orgOld)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/stretchr/testify/assert"
)

func newTestDefinitionHandler(t *testing.T) (*definitionHandlers, *testDefinitionBatchState) {
func newTestDefinitionHandler(t *testing.T) (*definitionHandler, *testDefinitionBatchState) {
mdi := &databasemocks.Plugin{}
mbi := &blockchainmocks.Plugin{}
mdx := &dataexchangemocks.Plugin{}
Expand All @@ -43,7 +43,7 @@ func newTestDefinitionHandler(t *testing.T) (*definitionHandlers, *testDefinitio
mcm := &contractmocks.Manager{}
mbi.On("VerifierType").Return(core.VerifierTypeEthAddress).Maybe()
dh, _ := NewDefinitionHandler(context.Background(), "ns1", false, mdi, mbi, mdx, mdm, mim, mam, mcm)
return dh.(*definitionHandlers), newTestDefinitionBatchState(t)
return dh.(*definitionHandler), newTestDefinitionBatchState(t)
}

type testDefinitionBatchState struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/hyperledger/firefly/pkg/database"
)

func (dh *definitionHandlers) handleTokenPoolBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray) (HandlerResult, error) {
func (dh *definitionHandler) handleTokenPoolBroadcast(ctx context.Context, state *core.BatchState, msg *core.Message, data core.DataArray) (HandlerResult, error) {
var announce core.TokenPoolAnnouncement
if valid := dh.getSystemBroadcastPayload(ctx, msg, data, &announce); !valid {
return HandlerResult{Action: ActionReject}, i18n.NewError(ctx, coremsgs.MsgDefRejectedBadPayload, "token pool", msg.Header.ID)
Expand Down
6 changes: 3 additions & 3 deletions internal/definitions/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
type Sender interface {
core.Named

Init(handler DefinitionHandler)
Init(handler Handler)
CreateDefinition(ctx context.Context, def core.Definition, tag string, waitConfirm bool) (msg *core.Message, err error)
CreateDefinitionWithIdentity(ctx context.Context, def core.Definition, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (msg *core.Message, err error)
CreateDatatype(ctx context.Context, datatype *core.Datatype, waitConfirm bool) (msg *core.Message, err error)
Expand All @@ -53,7 +53,7 @@ type definitionSender struct {
identity identity.Manager
data data.Manager
contracts contracts.Manager
handler DefinitionHandler
handler Handler
}

func NewDefinitionSender(ctx context.Context, ns string, multiparty bool, di database.Plugin, bm broadcast.Manager, im identity.Manager, dm data.Manager, cm contracts.Manager) (Sender, error) {
Expand All @@ -76,7 +76,7 @@ func (bm *definitionSender) Name() string {
return "DefinitionSender"
}

func (bm *definitionSender) Init(handler DefinitionHandler) {
func (bm *definitionSender) Init(handler Handler) {
bm.handler = handler
}

Expand Down
4 changes: 2 additions & 2 deletions internal/events/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type aggregator struct {
namespace string
database database.Plugin
messaging privatemessaging.Manager
definitions definitions.DefinitionHandler
definitions definitions.Handler
identity identity.Manager
data data.Manager
eventPoller *eventPoller
Expand All @@ -65,7 +65,7 @@ type batchCacheEntry struct {
manifest *core.BatchManifest
}

func newAggregator(ctx context.Context, ns string, di database.Plugin, bi blockchain.Plugin, pm privatemessaging.Manager, sh definitions.DefinitionHandler, im identity.Manager, dm data.Manager, en *eventNotifier, mm metrics.Manager) *aggregator {
func newAggregator(ctx context.Context, ns string, di database.Plugin, bi blockchain.Plugin, pm privatemessaging.Manager, sh definitions.Handler, im identity.Manager, dm data.Manager, en *eventNotifier, mm metrics.Manager) *aggregator {
batchSize := config.GetInt(coreconfig.EventAggregatorBatchSize)
ag := &aggregator{
ctx: log.WithLogField(ctx, "role", "aggregator"),
Expand Down
10 changes: 5 additions & 5 deletions internal/events/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func newTestAggregatorCommon(metrics bool) (*aggregator, func()) {
mdi := &databasemocks.Plugin{}
mdm := &datamocks.Manager{}
mpm := &privatemessagingmocks.Manager{}
msh := &definitionsmocks.DefinitionHandler{}
msh := &definitionsmocks.Handler{}
mim := &identitymanagermocks.Manager{}
mmi := &metricsmocks.Manager{}
mbi := &blockchainmocks.Plugin{}
Expand Down Expand Up @@ -1516,7 +1516,7 @@ func TestDefinitionBroadcastActionRejectCustomCorrelator(t *testing.T) {
mim.On("FindIdentityForVerifier", ag.ctx, mock.Anything, mock.Anything).Return(org1, nil)

customCorrelator := fftypes.NewUUID()
msh := ag.definitions.(*definitionsmocks.DefinitionHandler)
msh := ag.definitions.(*definitionsmocks.Handler)
msh.On("HandleDefinitionBroadcast", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(definitions.HandlerResult{Action: definitions.ActionReject, CustomCorrelator: customCorrelator}, nil)

Expand Down Expand Up @@ -1733,7 +1733,7 @@ func TestDefinitionBroadcastActionRetry(t *testing.T) {
mim := ag.identity.(*identitymanagermocks.Manager)
mim.On("FindIdentityForVerifier", ag.ctx, mock.Anything, mock.Anything).Return(org1, nil)

msh := ag.definitions.(*definitionsmocks.DefinitionHandler)
msh := ag.definitions.(*definitionsmocks.Handler)
msh.On("HandleDefinitionBroadcast", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(definitions.HandlerResult{Action: definitions.ActionRetry}, fmt.Errorf("pop"))

mdm := ag.data.(*datamocks.Manager)
Expand Down Expand Up @@ -1799,7 +1799,7 @@ func TestDefinitionBroadcastParkUnregisteredSignerIdentityClaim(t *testing.T) {
mim := ag.identity.(*identitymanagermocks.Manager)
mim.On("FindIdentityForVerifier", ag.ctx, mock.Anything, mock.Anything).Return(nil, nil)

msh := ag.definitions.(*definitionsmocks.DefinitionHandler)
msh := ag.definitions.(*definitionsmocks.Handler)
msh.On("HandleDefinitionBroadcast", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(definitions.HandlerResult{Action: definitions.ActionWait}, nil)

newState, valid, err := ag.attemptMessageDispatch(ag.ctx, msg1, nil, nil, &batchState{}, &core.Pin{Signer: "0x12345"})
Expand Down Expand Up @@ -1836,7 +1836,7 @@ func TestDefinitionBroadcastActionWait(t *testing.T) {
mim := ag.identity.(*identitymanagermocks.Manager)
mim.On("FindIdentityForVerifier", ag.ctx, mock.Anything, mock.Anything).Return(org1, nil)

msh := ag.definitions.(*definitionsmocks.DefinitionHandler)
msh := ag.definitions.(*definitionsmocks.Handler)
msh.On("HandleDefinitionBroadcast", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(definitions.HandlerResult{Action: definitions.ActionWait}, nil)

_, _, err := ag.attemptMessageDispatch(ag.ctx, msg1, nil, nil, &batchState{}, &core.Pin{Signer: "0x12345"})
Expand Down
Loading

0 comments on commit 58ec5b4

Please sign in to comment.