Esempio n. 1
0
// Create a wallet if no ID provided.  Otherwise update an existing wallet.
// Name the wallet with "name".
func walletHandlerPOST(gateway *daemon.Gateway, w http.ResponseWriter,
	r *http.Request) {
	id := wallet.WalletID(r.FormValue("id"))
	name := r.FormValue("name")
	if id == "" {
		// Create wallet
		iw := gateway.CreateWallet()
		if iw != nil {
			w := iw.(wallet.Wallet)
			w.SetName(name)
			if err := gateway.SaveWallet(w.GetID()); err != nil {
				m := "Failed to save wallet after renaming: %v"
				logger.Critical(m, err)
			}
		}
		SendOr500(w, iw)
	} else {
		// Update wallet
		iw := gateway.GetWallet(id)
		if iw != nil {
			w := iw.(wallet.Wallet)
			w.SetName(name)
			if err := gateway.SaveWallet(w.GetID()); err != nil {
				m := "Failed to save wallet after renaming: %v"
				logger.Critical(m, err)
			}
		}
		SendOr404(w, iw)
	}
}