Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
tx waiter integration
Browse files Browse the repository at this point in the history
  • Loading branch information
bogatyr285 committed Oct 26, 2021
1 parent 6b21651 commit e3e2fcf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gateway/service/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Peer interface {
args [][]byte,
identity msp.SigningIdentity,
transient map[string][]byte,
txWaiterType string,
) (res *peer.Response, chaincodeTx string, err error)

Query(
Expand Down Expand Up @@ -74,6 +75,7 @@ func (cs *ChaincodeService) Invoke(ctx context.Context, in *ChaincodeInput) (*pe
in.Args,
signer,
in.Transient,
TxWaiterFromContext(ctx),
)
if err != nil {
return nil, fmt.Errorf("invoke chaincode: %w", err)
Expand Down
16 changes: 15 additions & 1 deletion gateway/service/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (c contextKey) String() string {

const (
CtxSignerKey = contextKey(`SigningIdentity`)
CtxDoOptionKey = contextKey(`SdkDoOption`)
CtxTxWaiterKey = contextKey(`TxWaiter`)
)

func ContextWithDefaultSigner(ctx context.Context, defaultSigner msp.SigningIdentity) context.Context {
Expand All @@ -36,3 +36,17 @@ func SignerFromContext(ctx context.Context) (msp.SigningIdentity, error) {
return signer, nil
}
}

func ContextWithTxWaiter(ctx context.Context, txWaiterType string) context.Context {
return context.WithValue(ctx, CtxTxWaiterKey, txWaiterType)
}

// TxWaiterFromContext - fetch 'txWaiterType' param which identify transaction waiting policy
// what params you'll have depends on your implementation
// for example, in hlf-sdk:
// available: 'self'(wait for one peer of endorser org), 'all'(wait for each organizations from endorsement policy)
// default is 'self'(even if you pass empty string)
func TxWaiterFromContext(ctx context.Context) string {
txWaiter, _ := ctx.Value(CtxTxWaiterKey).(string)
return txWaiter
}

0 comments on commit e3e2fcf

Please sign in to comment.