Beispiel #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)
	}
}
Beispiel #2
0
// Returns a wallet by ID if GET.  Creates or updates a wallet if POST.
func walletHandler(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		if r.Method == "GET" {
			SendOr404(w, gateway.GetWallet(wallet.WalletID(r.FormValue("id"))))
		} else if r.Method == "POST" {
			walletHandlerPOST(gateway, w, r)
		} else {
			Error405(w)
		}
	}
}
Beispiel #3
0
func walletHandler(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		SendOr404(w, gateway.GetWallet())
	}
}