Skip to content

Commit

Permalink
chore: In gnoNativeService.Call, if useGnokeyMobile then use the Gnok…
Browse files Browse the repository at this point in the history
…ey Mobile service to sign the tx. See the PR.

Signed-off-by: Jeff Thompson <[email protected]>
  • Loading branch information
jefft0 committed Aug 8, 2024
1 parent ca96e9c commit c2c7283
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions service/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,53 @@ func (s *gnoNativeService) Call(ctx context.Context, req *connect.Request[api_ge

cfg, msgs := convertCallRequest(req.Msg)

if s.useGnokeyMobile {
c, err := s.getClient()
if err != nil {
return getGrpcError(err)
}
tx, err := c.MakeCallTx(*cfg, msgs...)
if err != nil {
return err
}
txJSON, err := amino.MarshalJSON(tx)
if err != nil {
return err
}

// Use Gnokey Mobile to sign.
// Note that req.Msg.CallerAddress must be set to the desired signer. The app can get the
// address using ListKeyInfo.
signedTxJSON, err := s.gnokeyMobileClient.SignTx(
context.Background(),
connect.NewRequest(&api_gen.SignTxRequest{
TxJson: string(txJSON),
}),
)
if err != nil {
return err
}
signedTx := &std.Tx{}
if err := amino.UnmarshalJSON([]byte(signedTxJSON.Msg.SignedTxJson), signedTx); err != nil {
return err
}

// Now broadcast
bres, err := c.BroadcastTxCommit(signedTx)
if err != nil {
return getGrpcError(err)
}

if err := stream.Send(&api_gen.CallResponse{
Result: bres.DeliverTx.Data,
}); err != nil {
s.logger.Error("Call stream.Send returned error", zap.Error(err))
return err
}

return nil
}

s.lock.RLock()
if s.activeAccount == nil {
s.lock.RUnlock()
Expand Down

0 comments on commit c2c7283

Please sign in to comment.