@@ -10,37 +10,52 @@ import (
1010 "time"
1111
1212 "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
13- fabric2 "github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
14- "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/endorser"
13+ "github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
1514 "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
16- token2 "github.com/hyperledger-labs/fabric-token-sdk/token"
15+ "github.com/hyperledger-labs/fabric-token-sdk/token"
1716 "github.com/hyperledger-labs/fabric-token-sdk/token/services/network/driver"
1817)
1918
19+ // RequestApprovalView is the initiator of the request approval protocol
2020type RequestApprovalView struct {
21- TMSID token2 .TMSID
21+ TMSID token .TMSID
2222 TxID driver.TxID
2323 RequestRaw []byte
2424 // Nonce, if not nil it will be appended to the messages to sign.
2525 // This is to be used only for testing.
2626 Nonce []byte
2727 // Endorsers are the identities of the FSC node that play the role of endorser
2828 Endorsers []view.Identity
29+
30+ // EndorserService is the endorser service
31+ EndorserService EndorserService
32+ }
33+
34+ // NewRequestApprovalView returns a new instance of RequestApprovalView
35+ func NewRequestApprovalView (
36+ TMSID token.TMSID ,
37+ txID driver.TxID ,
38+ requestRaw []byte ,
39+ nonce []byte ,
40+ endorsers []view.Identity ,
41+ endorserService EndorserService ,
42+ ) * RequestApprovalView {
43+ return & RequestApprovalView {TMSID : TMSID , TxID : txID , RequestRaw : requestRaw , Nonce : nonce , Endorsers : endorsers , EndorserService : endorserService }
2944}
3045
31- func (r * RequestApprovalView ) Call (context view.Context ) (interface {} , error ) {
32- logger .DebugfContext (context .Context (), "request approval..." )
46+ func (r * RequestApprovalView ) Call (ctx view.Context ) (any , error ) {
47+ logger .DebugfContext (ctx .Context (), "request approval..." )
3348
34- _ , tx , err := endorser .NewTransaction (
35- context ,
36- fabric2 .WithCreator (r .TxID .Creator ),
37- fabric2 .WithNonce (r .TxID .Nonce ),
49+ tx , err := r . EndorserService .NewTransaction (
50+ ctx ,
51+ fabric .WithCreator (r .TxID .Creator ),
52+ fabric .WithNonce (r .TxID .Nonce ),
3853 )
3954 if err != nil {
4055 return nil , errors .WithMessagef (err , "failed to create endorser transaction" )
4156 }
4257
43- tms , err := token2 .GetManagementService (context , token2 .WithTMSID (r .TMSID ))
58+ tms , err := token .GetManagementService (ctx , token .WithTMSID (r .TMSID ))
4459 if err != nil {
4560 return nil , errors .WithMessagef (err , "no token management service for [%s]" , r .TMSID )
4661 }
@@ -57,22 +72,19 @@ func (r *RequestApprovalView) Call(context view.Context) (interface{}, error) {
5772 return nil , errors .WithMessagef (err , "failed to set token request transient" )
5873 }
5974
60- logger .DebugfContext (context .Context (), "request endorsement on tx [%s] to [%v]..." , tx .ID (), r .Endorsers )
61- _ , err = context .RunView (endorser .NewParallelCollectEndorsementsOnProposalView (
62- tx ,
63- r .Endorsers ... ,
64- ).WithTimeout (2 * time .Minute ))
75+ logger .DebugfContext (ctx .Context (), "request endorsement on tx [%s] to [%v]..." , tx .ID (), r .Endorsers )
76+ err = r .EndorserService .CollectEndorsements (ctx , tx , 2 * time .Minute , r .Endorsers ... )
6577 if err != nil {
6678 return nil , errors .WithMessagef (err , "failed to collect endorsements" )
6779 }
68- logger .DebugfContext (context .Context (), "request endorsement done" )
80+ logger .DebugfContext (ctx .Context (), "request endorsement done" )
6981
7082 // Return envelope
7183 env , err := tx .Envelope ()
7284 if err != nil {
7385 return nil , errors .WithMessagef (err , "failed to retrieve envelope for endorsement" )
7486 }
75- logger .DebugfContext (context .Context (), "envelope ready" )
87+ logger .DebugfContext (ctx .Context (), "envelope ready" )
7688
7789 return env , nil
7890}
0 commit comments