From e3e2fcf326073904616561de0688ee3e4b65de54 Mon Sep 17 00:00:00 2001 From: Andrey Bogatyr285 Bogatyrev Date: Tue, 26 Oct 2021 12:22:34 +0300 Subject: [PATCH] tx waiter integration --- gateway/service/chaincode.go | 2 ++ gateway/service/context.go | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gateway/service/chaincode.go b/gateway/service/chaincode.go index 22c396cd..ffa7aeb5 100644 --- a/gateway/service/chaincode.go +++ b/gateway/service/chaincode.go @@ -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( @@ -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) diff --git a/gateway/service/context.go b/gateway/service/context.go index ed39bf82..e7dc5323 100644 --- a/gateway/service/context.go +++ b/gateway/service/context.go @@ -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 { @@ -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 +}