@@ -14,7 +14,7 @@ import (
1414	orion2 "github.com/hyperledger-labs/fabric-smart-client/platform/orion" 
1515	view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view" 
1616	"github.com/hyperledger-labs/fabric-smart-client/platform/view/view" 
17- 	session2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/utils/json/session " 
17+ 	session2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/utils/json/jsession " 
1818	"github.com/pkg/errors" 
1919	"go.uber.org/zap/zapcore" 
2020)
@@ -24,7 +24,6 @@ type LookupKeyRequest struct {
2424	Namespace     string 
2525	StartingTxID  string 
2626	Key           string 
27- 	Timeout       time.Duration 
2827}
2928
3029func  (l  * LookupKeyRequest ) String () string  {
@@ -39,14 +38,13 @@ type LookupKeyRequestView struct {
3938	* LookupKeyRequest 
4039}
4140
42- func  NewLookupKeyRequestView (network  string , namespace  string , startingTxID  string , key  string ,  timeout  time. Duration ) * LookupKeyRequestView  {
41+ func  NewLookupKeyRequestView (network  string , namespace  string , startingTxID  string , key  string ) * LookupKeyRequestView  {
4342	return  & LookupKeyRequestView {
4443		LookupKeyRequest : & LookupKeyRequest {
4544			Network :      network ,
4645			Namespace :    namespace ,
4746			StartingTxID : startingTxID ,
4847			Key :          key ,
49- 			Timeout :      timeout ,
5048		},
5149	}
5250}
@@ -78,7 +76,7 @@ func (v *LookupKeyRequestView) Call(context view.Context) (interface{}, error) {
7876		return  nil , errors .Wrapf (err , "failed to send request [%s] to custodian [%s]" , v .LookupKeyRequest , custodian )
7977	}
8078	response  :=  & LookupKeyResponse {}
81- 	if  err  :=  session .ReceiveWithTimeout (response ,  v . Timeout ); err  !=  nil  {
79+ 	if  err  :=  session .Receive (response ); err  !=  nil  {
8280		return  nil , errors .Wrapf (err , "failed to receive response from custodian [%s] on request [%s]" , custodian , v .LookupKeyRequest )
8381	}
8482	return  response .Raw , nil 
@@ -88,7 +86,7 @@ type LookupKeyRequestRespondView struct{}
8886
8987func  (v  * LookupKeyRequestRespondView ) Call (context  view.Context ) (interface {}, error ) {
9088	// receive request 
91- 	session  :=  session2 .JSON (context )
89+ 	session  :=  session2 .FromContext (context )
9290	request  :=  & LookupKeyRequest {}
9391	if  err  :=  session .Receive (request ); err  !=  nil  {
9492		return  nil , errors .Wrapf (err , "failed to receive request" )
@@ -126,18 +124,13 @@ func LookupKey(context view.Context, request *LookupKeyRequest) ([]byte, error)
126124	}
127125
128126	pollingTime  :=  int64 (500 )
129- 	iterations  :=  int (request .Timeout .Milliseconds () /  pollingTime )
130- 	if  iterations  ==  0  {
131- 		iterations  =  1 
132- 	}
133- 	for  i  :=  0 ; i  <  iterations ; i ++  {
127+ 	for  {
134128		timeout  :=  time .NewTimer (time .Duration (pollingTime ) *  time .Millisecond )
135129
136- 		stop  :=  false 
137130		select  {
138131		case  <- context .Context ().Done ():
139132			timeout .Stop ()
140- 			return  nil , errors .Errorf ("view  context done" )
133+ 			return  nil , errors .Errorf ("context done" )
141134		case  <- timeout .C :
142135			timeout .Stop ()
143136			v , err  :=  qe .Get (request .Key )
@@ -147,18 +140,14 @@ func LookupKey(context view.Context, request *LookupKeyRequest) ([]byte, error)
147140			logger .Debugf ("get key [%s] from [%s:%s], result [%d]" , request .Key , request .Network , request .Namespace , len (v ))
148141			if  len (v ) !=  0  {
149142				if  logger .IsEnabledFor (zapcore .DebugLevel ) {
150- 					logger .Debugf ("scanning for key [%s] with timeout [%s ] found, [%s]" ,
143+ 					logger .Debugf ("scanning for key [%s] with timeout [%d ] found, [%s]" ,
151144						request .Key ,
152- 						timeout ,
145+ 						pollingTime ,
153146						base64 .StdEncoding .EncodeToString (v ),
154147					)
155148				}
156149				return  v , nil 
157150			}
158151		}
159- 		if  stop  {
160- 			break 
161- 		}
162152	}
163- 	return  nil , errors .Errorf ("cannot find get key [%s] from [%s:%s]" , request .Key , request .Network , request .Namespace )
164153}
0 commit comments