Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions api/rest/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,36 +265,43 @@ func (w *WebBridgeRunner) postmnemonic(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": strErrMsg})
return
}
cmd := `dynamic-cli importmnemonic "` + req.Mnemonic + `"`
if len(req.Language) > 0 {
cmd += ` "` + req.Language + `"`
} else {
cmd += ` "english"`
}
if len(req.Passphrase) > 0 {
cmd += ` "` + req.Passphrase + `"`
}
strCommand, _ := dynamic.NewRequest(cmd)
response, _ := <-w.dynamicd.ExecCmdRequest(strCommand)
if strings.Contains(response, "Error:") {
result := models.RPCError{}
err := json.Unmarshal([]byte(response), &result)
wordCount := len(strings.Split(req.Mnemonic, " "))
if wordCount == 12 || wordCount == 13 || wordCount == 24 || wordCount == 25 {
cmd := `dynamic-cli importmnemonic "` + req.Mnemonic + `"`
if len(req.Language) > 0 {
cmd += ` "` + req.Language + `"`
} else {
cmd += ` "english"`
}
if len(req.Passphrase) > 0 {
cmd += ` "` + req.Passphrase + `"`
}
strCommand, _ := dynamic.NewRequest(cmd)
response, _ := <-w.dynamicd.ExecCmdRequest(strCommand)
if strings.Contains(response, "Error:") {
result := models.RPCError{}
err := json.Unmarshal([]byte(response), &result)
if err != nil {
strErrMsg := fmt.Sprintf("Response JSON unmarshal error %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": strErrMsg})
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": result.Error})
return
}
var result interface{}
err = json.Unmarshal([]byte(response), &result)
if err != nil {
strErrMsg := fmt.Sprintf("Response JSON unmarshal error %v", err)
strErrMsg := fmt.Sprintf("Results JSON unmarshal error %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": strErrMsg})
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": result.Error})
return
}
var result interface{}
err = json.Unmarshal([]byte(response), &result)
if err != nil {
strErrMsg := fmt.Sprintf("Results JSON unmarshal error %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": strErrMsg})
c.JSON(http.StatusOK, gin.H{"result": result})
} else {
strErrMsg := fmt.Sprintf("Incorrect number of words (%v) in mnemonic", wordCount)
c.JSON(http.StatusBadRequest, gin.H{"error": strErrMsg})
return
}
c.JSON(http.StatusOK, gin.H{"result": result})
}

//
Expand Down
Loading