@@ -47,6 +47,7 @@ const (
4747 InvokeInterchainMethod = "invokeInterchain"
4848 InvokeInterchainsMethod = "invokeInterchains"
4949 InvokeReceiptMethod = "invokeReceipt"
50+ InvokeReceiptsMethod = "invokeReceipts"
5051 InvokeIndexUpdateMethod = "invokeIndexUpdate"
5152 InvokeGetDirectTransactionMetaMethod = "getDirectTransactionMeta"
5253 InvokerGetAppchainInfoMethod = "getAppchainInfo"
@@ -339,8 +340,39 @@ func (c *Client) GetIBTPCh() chan *pb.IBTP {
339340 return c .eventC
340341}
341342
342- func (c * Client ) SubmitReceiptBatch (to []string , index []uint64 , serviceID []string , ibtpType []pb.IBTP_Type , result []* pb.Result , proof []* pb.BxhProof ) (* pb.SubmitIBTPResponse , error ) {
343- panic ("implement me" )
343+ func (c * Client ) SubmitReceiptBatch (to []string , index []uint64 , serviceID []string , ibtpTypes []pb.IBTP_Type , batchResult []* pb.Result , proofs []* pb.BxhProof ) (* pb.SubmitIBTPResponse , error ) {
344+ ret := & pb.SubmitIBTPResponse {Status : true }
345+ batchResults := make ([][][][]byte , 0 )
346+ batchMultiStatus := make ([][]bool , 0 )
347+ for _ , result := range batchResult {
348+ var results [][][]byte
349+ for _ , s := range result .Data {
350+ results = append (results , s .Data )
351+ }
352+ batchMultiStatus = append (batchMultiStatus , result .MultiStatus )
353+ batchResults = append (batchResults , results )
354+ }
355+ ibtpTyps := make ([]uint64 , 0 )
356+ for _ , ibtpType := range ibtpTypes {
357+ ibtpTyps = append (ibtpTyps , uint64 (ibtpType ))
358+ }
359+
360+ batchTxStatus := make ([]uint64 , 0 )
361+ multiSigns := make ([][][]byte , 0 )
362+ for _ , proof := range proofs {
363+ batchTxStatus = append (batchTxStatus , uint64 (proof .TxStatus ))
364+ multiSigns = append (multiSigns , proof .MultiSign )
365+ }
366+
367+ _ , resp , err := c .InvokeReceipts (serviceID , to , index , ibtpTyps , batchResults , batchMultiStatus , batchTxStatus , multiSigns )
368+ if err != nil {
369+ ret .Status = false
370+ ret .Message = fmt .Sprintf ("invoke receipt for ibtp to call: %s" , err )
371+ return ret , nil
372+ }
373+ ret .Status = resp .OK
374+ ret .Message = resp .Message
375+ return ret , nil
344376}
345377
346378func (c * Client ) SubmitIBTPBatch (from []string , index []uint64 , serviceID []string , ibtpType []pb.IBTP_Type , content []* pb.Content , proof []* pb.BxhProof , isEncrypted []bool ) (* pb.SubmitIBTPResponse , error ) {
@@ -354,13 +386,13 @@ func (c *Client) SubmitIBTPBatch(from []string, index []uint64, serviceID []stri
354386 )
355387 for idx , ct := range content {
356388 callFunc = append (callFunc , ct .Func )
357- args = append (args , ct .Args [ 1 :] )
389+ args = append (args , ct .Args )
358390 typ = append (typ , uint64 (ibtpType [idx ]))
359391 txStatus = append (txStatus , uint64 (proof [idx ].TxStatus ))
360392 sign = append (sign , proof [idx ].MultiSign )
361393 }
362394
363- _ , resp , err := c .InvokeInterchains (from , index , serviceID , typ , callFunc , args , txStatus , sign , isEncrypted )
395+ _ , resp , err := c .InvokeInterchains (from , serviceID , index , typ , callFunc , args , txStatus , sign , isEncrypted )
364396 if err != nil {
365397 ret .Status = false
366398 ret .Message = fmt .Sprintf ("invoke interchains failed: %s" , err .Error ())
@@ -445,7 +477,7 @@ func (c *Client) GetDirectTransactionMeta(IBTPid string) (uint64, uint64, uint64
445477
446478}
447479
448- func (c * Client ) InvokeInterchains (srcFullID []string , index []uint64 , destAddr []string , reqType []uint64 , callFunc []string , callArgs [][][]byte , txStatus []uint64 , multiSign [][][]byte , encrypt []bool ) (* channel.Response , * Response , error ) {
480+ func (c * Client ) InvokeInterchains (srcFullID []string , destAddr []string , index []uint64 , reqType []uint64 , callFunc []string , callArgs [][][]byte , txStatus []uint64 , multiSign [][][]byte , encrypt []bool ) (* channel.Response , * Response , error ) {
449481 srcFullIDBytes , err := json .Marshal (srcFullID )
450482 if err != nil {
451483 return nil , nil , err
@@ -483,7 +515,8 @@ func (c *Client) InvokeInterchains(srcFullID []string, index []uint64, destAddr
483515 return nil , nil , err
484516 }
485517
486- args := util .ToChaincodeArgs (string (srcFullIDBytes ), string (indexBytes ), string (destAddrBytes ), string (reqTypeBytes ), string (callFuncBytes ),
518+ // 0: srcFullID, 1: targetCID, 2: index, 3: typ, 4: callFunc, 5: callArgs, 6: txStatus, 7: signature, 8: isEncrypted
519+ args := util .ToChaincodeArgs (string (srcFullIDBytes ), string (destAddrBytes ), string (indexBytes ), string (reqTypeBytes ), string (callFuncBytes ),
487520 string (callArgsBytes ), string (txStatusBytes ), string (multiSignBytes ), string (encryptBytes ))
488521
489522 request := channel.Request {
@@ -632,6 +665,83 @@ func (c *Client) InvokeReceipt(srcAddr string, dstFullID string, index uint64, r
632665 return & res , response , nil
633666}
634667
668+ // InvokeReceipts call invokeReceipt multiple times
669+ func (c * Client ) InvokeReceipts (srcAddrs []string , destFullIDs []string , indexs []uint64 , reqTypes []uint64 ,
670+ batchResults [][][][]byte , batchMultiStatus [][]bool , batchTxStatus []uint64 , multiSigns [][][]byte ) (* channel.Response , * Response , error ) {
671+ srcAddrsBytes , err := json .Marshal (srcAddrs )
672+ if err != nil {
673+ return nil , nil , err
674+ }
675+ destFullIDsBytes , err := json .Marshal (destFullIDs )
676+ if err != nil {
677+ return nil , nil , err
678+ }
679+
680+ indexsBytes , err := json .Marshal (indexs )
681+ if err != nil {
682+ return nil , nil , err
683+ }
684+ reqTypesBytes , err := json .Marshal (reqTypes )
685+ if err != nil {
686+ return nil , nil , err
687+ }
688+
689+ batchResultsBytes , err := json .Marshal (batchResults )
690+ if err != nil {
691+ return nil , nil , err
692+ }
693+ batchMultiStatusBytes , err := json .Marshal (batchMultiStatus )
694+ if err != nil {
695+ return nil , nil , err
696+ }
697+ batchTxStatusBytes , err := json .Marshal (batchTxStatus )
698+ if err != nil {
699+ return nil , nil , err
700+ }
701+ multiSignsBytes , err := json .Marshal (multiSigns )
702+ if err != nil {
703+ return nil , nil , err
704+ }
705+ // args:srcFullIDs, dstFullIDs, indexs, typs, results, multiStatuss, multiTxStatus, multiSignatures
706+ args := util .ToChaincodeArgs (string (srcAddrsBytes ), string (destFullIDsBytes ), string (indexsBytes ), string (reqTypesBytes ), string (batchResultsBytes ), string (batchMultiStatusBytes ), string (batchTxStatusBytes ), string (multiSignsBytes ))
707+
708+ request := channel.Request {
709+ ChaincodeID : c .meta .CCID ,
710+ Fcn : InvokeReceiptsMethod ,
711+ Args : args ,
712+ }
713+
714+ // retry executing
715+ var res channel.Response
716+ if err := retry .Retry (func (attempt uint ) error {
717+ res , err = c .consumer .ChannelClient .Execute (request )
718+ if err != nil {
719+ if strings .Contains (err .Error (), "Chaincode status Code: (500)" ) {
720+ res .ChaincodeStatus = shim .ERROR
721+ logger .Error ("execute request failed" , "err" , err .Error ())
722+ return nil
723+ }
724+ return fmt .Errorf ("execute request: %w" , err )
725+ }
726+
727+ return nil
728+ }, strategy .Wait (2 * time .Second )); err != nil {
729+ logger .Error ("Can't send rollback ibtp back to bitxhub" , "error" , err .Error ())
730+ }
731+
732+ if err != nil {
733+ return nil , nil , err
734+ }
735+
736+ logger .Info ("response" , "cc status" , strconv .Itoa (int (res .ChaincodeStatus )), "payload" , string (res .Payload ))
737+ response := & Response {}
738+ if err := json .Unmarshal (res .Payload , response ); err != nil {
739+ return nil , nil , err
740+ }
741+
742+ return & res , response , nil
743+ }
744+
635745func (c * Client ) GetOutMessage (servicePair string , idx uint64 ) (* pb.IBTP , error ) {
636746 args := util .ToChaincodeArgs (servicePair , strconv .FormatUint (idx , 10 ))
637747 request := channel.Request {
0 commit comments