@@ -14,6 +14,7 @@ import (
14
14
"github.com/gnolang/gno/tm2/pkg/crypto/bip39"
15
15
crypto_keys "github.com/gnolang/gno/tm2/pkg/crypto/keys"
16
16
"github.com/gnolang/gno/tm2/pkg/crypto/keys/keyerror"
17
+ "github.com/gnolang/gno/tm2/pkg/sdk/bank"
17
18
"github.com/gnolang/gno/tm2/pkg/std"
18
19
"go.uber.org/zap"
19
20
@@ -419,14 +420,17 @@ func (s *gnoNativeService) Call(ctx context.Context, req *connect.Request[api_ge
419
420
s .logger .Debug ("Call" , zap .String ("package" , msg .PackagePath ), zap .String ("function" , msg .Fnc ), zap .Any ("args" , msg .Args ))
420
421
}
421
422
422
- cfg , msgs := convertCallRequest (req .Msg )
423
+ cfg , msgs , err := s .convertCallRequest (req .Msg )
424
+ if err != nil {
425
+ return err
426
+ }
423
427
424
428
if s .useGnokeyMobile {
425
429
c , err := s .getClient ()
426
430
if err != nil {
427
431
return getGrpcError (err )
428
432
}
429
- tx , err := c . MakeCallTx (* cfg , msgs ... )
433
+ tx , err := gnoclient . NewCallTx (* cfg , msgs ... )
430
434
if err != nil {
431
435
return err
432
436
}
@@ -490,30 +494,45 @@ func (s *gnoNativeService) Call(ctx context.Context, req *connect.Request[api_ge
490
494
return nil
491
495
}
492
496
493
- func convertCallRequest (req * api_gen.CallRequest ) (* gnoclient.BaseTxCfg , []gnoclient .MsgCall ) {
497
+ func ( s * gnoNativeService ) convertCallRequest (req * api_gen.CallRequest ) (* gnoclient.BaseTxCfg , []vm .MsgCall , error ) {
494
498
var callerAddress crypto.Address
495
499
if req .CallerAddress != nil {
496
500
callerAddress = crypto .AddressFromBytes (req .CallerAddress )
501
+ } else {
502
+ // Get the caller address from the active account
503
+ s .lock .RLock ()
504
+ account := s .activeAccount
505
+ s .lock .RUnlock ()
506
+ if account == nil {
507
+ return nil , nil , api_gen .ErrCode_ErrNoActiveAccount
508
+ }
509
+
510
+ callerAddress = account .keyInfo .GetAddress ()
497
511
}
498
512
cfg := & gnoclient.BaseTxCfg {
499
- GasFee : req .GasFee ,
500
- GasWanted : req .GasWanted ,
501
- Memo : req .Memo ,
502
- CallerAddress : callerAddress ,
513
+ GasFee : req .GasFee ,
514
+ GasWanted : req .GasWanted ,
515
+ Memo : req .Memo ,
503
516
}
504
517
505
- msgs := make ([]gnoclient .MsgCall , 0 )
518
+ msgs := make ([]vm .MsgCall , 0 )
506
519
507
520
for _ , msg := range req .Msgs {
508
- msgs = append (msgs , gnoclient.MsgCall {
509
- PkgPath : msg .PackagePath ,
510
- FuncName : msg .Fnc ,
511
- Args : msg .Args ,
512
- Send : msg .Send ,
521
+ send , err := std .ParseCoins (msg .Send )
522
+ if err != nil {
523
+ return nil , nil , getGrpcError (err )
524
+ }
525
+
526
+ msgs = append (msgs , vm.MsgCall {
527
+ Caller : callerAddress ,
528
+ PkgPath : msg .PackagePath ,
529
+ Func : msg .Fnc ,
530
+ Args : msg .Args ,
531
+ Send : send ,
513
532
})
514
533
}
515
534
516
- return cfg , msgs
535
+ return cfg , msgs , nil
517
536
}
518
537
519
538
func (s * gnoNativeService ) Send (ctx context.Context , req * connect.Request [api_gen.SendRequest ], stream * connect.ServerStream [api_gen.SendResponse ]) error {
@@ -528,9 +547,12 @@ func (s *gnoNativeService) Send(ctx context.Context, req *connect.Request[api_ge
528
547
}
529
548
s .lock .RUnlock ()
530
549
531
- cfg , msgs := convertSendRequest (req .Msg )
550
+ cfg , msgs , err := s .convertSendRequest (req .Msg )
551
+ if err != nil {
552
+ return err
553
+ }
532
554
533
- _ , err : = s .client .Send (* cfg , msgs ... )
555
+ _ , err = s .client .Send (* cfg , msgs ... )
534
556
if err != nil {
535
557
return getGrpcError (err )
536
558
}
@@ -543,28 +565,43 @@ func (s *gnoNativeService) Send(ctx context.Context, req *connect.Request[api_ge
543
565
return nil
544
566
}
545
567
546
- func convertSendRequest (req * api_gen.SendRequest ) (* gnoclient.BaseTxCfg , []gnoclient .MsgSend ) {
568
+ func ( s * gnoNativeService ) convertSendRequest (req * api_gen.SendRequest ) (* gnoclient.BaseTxCfg , []bank .MsgSend , error ) {
547
569
var callerAddress crypto.Address
548
570
if req .CallerAddress != nil {
549
571
callerAddress = crypto .AddressFromBytes (req .CallerAddress )
572
+ } else {
573
+ // Get the caller address from the active account
574
+ s .lock .RLock ()
575
+ account := s .activeAccount
576
+ s .lock .RUnlock ()
577
+ if account == nil {
578
+ return nil , nil , api_gen .ErrCode_ErrNoActiveAccount
579
+ }
580
+
581
+ callerAddress = account .keyInfo .GetAddress ()
550
582
}
551
583
cfg := & gnoclient.BaseTxCfg {
552
- GasFee : req .GasFee ,
553
- GasWanted : req .GasWanted ,
554
- Memo : req .Memo ,
555
- CallerAddress : callerAddress ,
584
+ GasFee : req .GasFee ,
585
+ GasWanted : req .GasWanted ,
586
+ Memo : req .Memo ,
556
587
}
557
588
558
- msgs := make ([]gnoclient .MsgSend , 0 )
589
+ msgs := make ([]bank .MsgSend , 0 )
559
590
560
591
for _ , msg := range req .Msgs {
561
- msgs = append (msgs , gnoclient.MsgSend {
562
- ToAddress : crypto .AddressFromBytes (msg .ToAddress ),
563
- Send : msg .Send ,
592
+ send , err := std .ParseCoins (msg .Send )
593
+ if err != nil {
594
+ return nil , nil , getGrpcError (err )
595
+ }
596
+
597
+ msgs = append (msgs , bank.MsgSend {
598
+ FromAddress : callerAddress ,
599
+ ToAddress : crypto .AddressFromBytes (msg .ToAddress ),
600
+ Amount : send ,
564
601
})
565
602
}
566
603
567
- return cfg , msgs
604
+ return cfg , msgs , nil
568
605
}
569
606
570
607
func (s * gnoNativeService ) Run (ctx context.Context , req * connect.Request [api_gen.RunRequest ], stream * connect.ServerStream [api_gen.RunResponse ]) error {
@@ -575,7 +612,10 @@ func (s *gnoNativeService) Run(ctx context.Context, req *connect.Request[api_gen
575
612
}
576
613
s .lock .RUnlock ()
577
614
578
- cfg , msgs := convertRunRequest (req .Msg )
615
+ cfg , msgs , err := s .convertRunRequest (req .Msg )
616
+ if err != nil {
617
+ return err
618
+ }
579
619
580
620
bres , err := s .client .Run (* cfg , msgs ... )
581
621
if err != nil {
@@ -592,21 +632,35 @@ func (s *gnoNativeService) Run(ctx context.Context, req *connect.Request[api_gen
592
632
return nil
593
633
}
594
634
595
- func convertRunRequest (req * api_gen.RunRequest ) (* gnoclient.BaseTxCfg , []gnoclient .MsgRun ) {
635
+ func ( s * gnoNativeService ) convertRunRequest (req * api_gen.RunRequest ) (* gnoclient.BaseTxCfg , []vm .MsgRun , error ) {
596
636
var callerAddress crypto.Address
597
637
if req .CallerAddress != nil {
598
638
callerAddress = crypto .AddressFromBytes (req .CallerAddress )
639
+ } else {
640
+ // Get the caller address from the active account
641
+ s .lock .RLock ()
642
+ account := s .activeAccount
643
+ s .lock .RUnlock ()
644
+ if account == nil {
645
+ return nil , nil , api_gen .ErrCode_ErrNoActiveAccount
646
+ }
647
+
648
+ callerAddress = account .keyInfo .GetAddress ()
599
649
}
600
650
cfg := & gnoclient.BaseTxCfg {
601
- GasFee : req .GasFee ,
602
- GasWanted : req .GasWanted ,
603
- Memo : req .Memo ,
604
- CallerAddress : callerAddress ,
651
+ GasFee : req .GasFee ,
652
+ GasWanted : req .GasWanted ,
653
+ Memo : req .Memo ,
605
654
}
606
655
607
- msgs := make ([]gnoclient .MsgRun , 0 )
656
+ msgs := make ([]vm .MsgRun , 0 )
608
657
609
658
for _ , msg := range req .Msgs {
659
+ send , err := std .ParseCoins (msg .Send )
660
+ if err != nil {
661
+ return nil , nil , getGrpcError (err )
662
+ }
663
+
610
664
memPkg := & std.MemPackage {
611
665
Files : []* std.MemFile {
612
666
{
@@ -615,22 +669,26 @@ func convertRunRequest(req *api_gen.RunRequest) (*gnoclient.BaseTxCfg, []gnoclie
615
669
},
616
670
},
617
671
}
618
- msgs = append (msgs , gnoclient.MsgRun {
672
+ msgs = append (msgs , vm.MsgRun {
673
+ Caller : callerAddress ,
619
674
Package : memPkg ,
620
- Send : msg . Send ,
675
+ Send : send ,
621
676
})
622
677
}
623
678
624
- return cfg , msgs
679
+ return cfg , msgs , nil
625
680
}
626
681
627
682
func (s * gnoNativeService ) MakeCallTx (ctx context.Context , req * connect.Request [api_gen.CallRequest ]) (* connect.Response [api_gen.MakeTxResponse ], error ) {
628
683
for _ , msg := range req .Msg .Msgs {
629
684
s .logger .Debug ("MakeCallTx" , zap .String ("package" , msg .PackagePath ), zap .String ("function" , msg .Fnc ), zap .Any ("args" , msg .Args ))
630
685
}
631
686
632
- cfg , msgs := convertCallRequest (req .Msg )
633
- tx , err := s .client .MakeCallTx (* cfg , msgs ... )
687
+ cfg , msgs , err := s .convertCallRequest (req .Msg )
688
+ if err != nil {
689
+ return nil , err
690
+ }
691
+ tx , err := gnoclient .NewCallTx (* cfg , msgs ... )
634
692
if err != nil {
635
693
return nil , getGrpcError (err )
636
694
}
@@ -643,8 +701,11 @@ func (s *gnoNativeService) MakeCallTx(ctx context.Context, req *connect.Request[
643
701
}
644
702
645
703
func (s * gnoNativeService ) MakeSendTx (ctx context.Context , req * connect.Request [api_gen.SendRequest ]) (* connect.Response [api_gen.MakeTxResponse ], error ) {
646
- cfg , msgs := convertSendRequest (req .Msg )
647
- tx , err := s .client .MakeSendTx (* cfg , msgs ... )
704
+ cfg , msgs , err := s .convertSendRequest (req .Msg )
705
+ if err != nil {
706
+ return nil , err
707
+ }
708
+ tx , err := gnoclient .NewSendTx (* cfg , msgs ... )
648
709
if err != nil {
649
710
return nil , getGrpcError (err )
650
711
}
@@ -657,8 +718,11 @@ func (s *gnoNativeService) MakeSendTx(ctx context.Context, req *connect.Request[
657
718
}
658
719
659
720
func (s * gnoNativeService ) MakeRunTx (ctx context.Context , req * connect.Request [api_gen.RunRequest ]) (* connect.Response [api_gen.MakeTxResponse ], error ) {
660
- cfg , msgs := convertRunRequest (req .Msg )
661
- tx , err := s .client .MakeRunTx (* cfg , msgs ... )
721
+ cfg , msgs , err := s .convertRunRequest (req .Msg )
722
+ if err != nil {
723
+ return nil , err
724
+ }
725
+ tx , err := gnoclient .NewRunTx (* cfg , msgs ... )
662
726
if err != nil {
663
727
return nil , getGrpcError (err )
664
728
}
0 commit comments