@@ -11,6 +11,7 @@ import (
11
11
"io"
12
12
"log"
13
13
"math/big"
14
+ "regexp"
14
15
"strconv"
15
16
"strings"
16
17
"sync"
@@ -511,7 +512,7 @@ func (c *IconLocalnet) ConfigureBaseConnection(ctx context.Context, connection c
511
512
if err != nil {
512
513
return nil , err
513
514
}
514
- params = []byte (`{"nid ":"` + connection .CounterpartyNid + `","connection ":"` + connectionAddress + `"}` )
515
+ params = []byte (`{"_nid ":"` + connection .CounterpartyNid + `","_connection ":"` + connectionAddress + `"}` )
515
516
ctx , err = c .executeContract (context .Background (), c .IBCAddresses [fmt .Sprintf ("xcall-%s" , testcase )], connection .KeyName , "setDefaultConnection" , string (params ))
516
517
if err != nil {
517
518
return nil , err
@@ -537,9 +538,47 @@ func (c *IconLocalnet) SendPacketXCall(ctx context.Context, keyName, _to string,
537
538
}
538
539
539
540
// HasPacketReceipt returns the receipt of the packet sent to the target chain
540
- func (c * IconLocalnet ) IsPacketReceived (ctx context.Context , params map [string ]interface {}) bool {
541
+ func (c * IconLocalnet ) IsPacketReceived (ctx context.Context , params map [string ]interface {}, order ibc.Order ) bool {
542
+ if order == ibc .Ordered {
543
+ sequence := params ["sequence" ].(uint64 ) //2
544
+ ctx , err := c .QueryContract (ctx , c .IBCAddresses ["ibc" ], chains .GetNextSequenceReceive , params )
545
+ if err != nil {
546
+ fmt .Printf ("Error--%v\n " , err )
547
+ return false
548
+ }
549
+ response , err := formatHexNumberFromResponse (ctx .Value ("query-result" ).([]byte ))
550
+
551
+ if err != nil {
552
+ fmt .Printf ("Error--%v\n " , err )
553
+ return false
554
+ }
555
+ fmt .Printf ("response[\" data\" ]----%v" , response )
556
+ return sequence < response
557
+ }
541
558
ctx , _ = c .QueryContract (ctx , c .IBCAddresses ["ibc" ], chains .HasPacketReceipt , params )
542
- return string (ctx .Value ("query-result" ).([]byte )) == "0x1"
559
+
560
+ response , err := formatHexNumberFromResponse (ctx .Value ("query-result" ).([]byte ))
561
+ if err != nil {
562
+ fmt .Printf ("Error--%v\n " , err )
563
+ return false
564
+ }
565
+ return response == 1
566
+ }
567
+
568
+ func formatHexNumberFromResponse (value []byte ) (uint64 , error ) {
569
+ pattern := `0x[0-9a-fA-F]+`
570
+ regex := regexp .MustCompile (pattern )
571
+ result := regex .FindString (string (value ))
572
+ if result == "" {
573
+ return 0 , fmt .Errorf ("number not found" )
574
+
575
+ }
576
+
577
+ response , err := strconv .ParseInt (result , 0 , 64 )
578
+ if err != nil {
579
+ return 0 , err
580
+ }
581
+ return uint64 (response ), nil
543
582
}
544
583
545
584
// FindTargetXCallMessage returns the request id and the data of the message sent to the target chain
0 commit comments