Skip to content

Commit

Permalink
signer from context
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiko committed Apr 27, 2022
1 parent 518ba1a commit a3c6847
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 2 additions & 4 deletions client/core_public.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ func (c *core) Invoke(
return nil, "", fmt.Errorf("invalid tx waiter type. got %v, available: '%v', '%v'", txWaiterType, api.TxWaiterSelfType, api.TxWaiterAllType)
}

if signer == nil {
signer = c.CurrentIdentity()
}

if endorserMSPs := tx.EndorserMSPsFromContext(ctx); len(endorserMSPs) > 0 {
doOpts = append(doOpts, api.WithEndorsingMpsIDs(endorserMSPs))
}

signer = tx.ChooseSigner(ctx, signer, c.CurrentIdentity())

ccAPI, err := c.Channel(channel).Chaincode(ctx, ccName)
if err != nil {
return nil, "", err
Expand Down
12 changes: 12 additions & 0 deletions client/tx/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ func SignerFromContext(ctx context.Context) msp.SigningIdentity {
return nil
}

func ChooseSigner(ctx context.Context, signer, defaultSigner msp.SigningIdentity) msp.SigningIdentity {
if signer != nil {
return signer
}

if ctxSigner := SignerFromContext(ctx); ctxSigner != nil {
return ctxSigner
}

return defaultSigner
}

func ContextWithTxWaiter(ctx context.Context, txWaiterType string) context.Context {
return context.WithValue(ctx, CtxTxWaiterKey, txWaiterType)
}
Expand Down
5 changes: 1 addition & 4 deletions peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ func (p *peer) Query(
}
}

if signer == nil && p.identity != nil {
signer = p.identity
zapFields = append(zapFields, zap.String(`use default identity`, p.identity.GetMSPIdentifier()))
}
signer = tx.ChooseSigner(ctx, signer, p.identity)

p.logger.Debug(`peer query`, zapFields...)

Expand Down

0 comments on commit a3c6847

Please sign in to comment.