Skip to content

Commit

Permalink
fix nil pointer, see 1198
Browse files Browse the repository at this point in the history
  • Loading branch information
jordipainan committed Nov 23, 2023
1 parent 22552f1 commit 9b5a2d6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,29 @@ func (a *API) accountHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext) er
// @Router /accounts [post]
func (a *API) accountSetHandler(msg *apirest.APIdata, ctx *httprouter.HTTPContext) error {
req := &AccountSet{}
if msg == nil {
return ErrCantParseDataAsJSON
}
if msg.Data == nil {
return ErrCantParseDataAsJSON
}
if err := json.Unmarshal(msg.Data, req); err != nil {
return err
}

// check if the transaction is of the correct type and extract metadata URI
metadataURI, err := func() (string, error) {
stx := &models.SignedTx{}
if req.TxPayload == nil {
return "", ErrUnmarshalingServerProto
}
if err := proto.Unmarshal(req.TxPayload, stx); err != nil {
return "", err
}
tx := &models.Tx{}
if stx.GetTx() == nil {
return "", ErrUnmarshalingServerProto
}
if err := proto.Unmarshal(stx.GetTx(), tx); err != nil {
return "", err
}
Expand Down Expand Up @@ -231,6 +243,9 @@ func (a *API) accountSetHandler(msg *apirest.APIdata, ctx *httprouter.HTTPContex
if err != nil {
return err
}
if res == nil {
return ErrVochainSendTxFailed
}

// prepare the reply
resp := &AccountSet{
Expand Down

0 comments on commit 9b5a2d6

Please sign in to comment.