示例#1
0
文件: wallet.go 项目: skycoin/skycoin
// Update wallet label
func walletUpdateHandler(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// Update wallet
		id := r.FormValue("id")
		if id == "" {
			wh.Error400(w, "wallet id is empty")
			return
		}

		label := r.FormValue("label")
		if label == "" {
			wh.Error400(w, "label is empty")
			return
		}

		wlt := Wg.GetWallet(id)
		if wlt == nil {
			wh.Error404(w, fmt.Sprintf("wallet of id: %v does not exist", id))
			return
		}

		wlt.SetLabel(label)
		if err := Wg.SaveWallet(wlt.GetID()); err != nil {
			m := "Failed to save wallet: %v"
			logger.Critical(m, "Failed to update label of wallet %v", id)
			wh.Error500(w, "Update wallet failed")
			return
		}

		wh.SendOr404(w, "success")
	}
}
示例#2
0
文件: wallet.go 项目: skycoin/skycoin
func walletNewAddresses(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		if r.Method != "POST" {
			wh.Error405(w, "")
			return
		}

		wltID := r.FormValue("id")
		if wltID == "" {
			wh.Error400(w, "wallet id not set")
			return
		}

		addrs, err := Wg.NewAddresses(wltID, 1)
		if err != nil {
			wh.Error400(w, err.Error())
			return
		}

		if err := Wg.SaveWallet(wltID); err != nil {
			wh.Error500(w, "")
			return
		}

		var rlt = struct {
			Address string `json:"address"`
		}{
			addrs[0].String(),
		}
		wh.SendOr404(w, rlt)
		return
	}
}
示例#3
0
文件: wallet.go 项目: skycoin/skycoin
// Loads/unloads wallets from the wallet directory
func walletsReloadHandler(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		err := Wg.ReloadWallets()
		if err != nil {
			wh.Error500(w, err.(error).Error())
		}
	}
}
示例#4
0
//Handler for /nodemanager/start - add new Node
//mode: GET
//url: /nodemanager/start
func nodeStartHandler(nm *nodemanager.NodeManager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		logger.Info("Starting Node")
		count := len(nm.NodesList)
		i := nm.AddNode()
		if i != count {
			wh.Error500(w)
		}

	}
}
示例#5
0
文件: wallet.go 项目: skycoin/skycoin
// Saves all loaded wallets
func walletsSaveHandler(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		errs := Wg.SaveWallets() // (map[string]error)
		if len(errs) != 0 {
			err := ""
			for id, e := range errs {
				err += id + ": " + e.Error()
			}
			wh.Error500(w, err)
		}
	}
}
示例#6
0
文件: wallet.go 项目: skycoin/skycoin
func newWalletSeed(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		entropy, err := bip39.NewEntropy(128)
		if err != nil {
			wh.Error500(w)
			return
		}

		mnemonic, err := bip39.NewMnemonic(entropy)
		if err != nil {
			wh.Error500(w)
			return
		}

		var rlt = struct {
			Seed string `json:"seed"`
		}{
			mnemonic,
		}

		wh.SendOr404(w, rlt)
	}
}
示例#7
0
// getLastTxs get the last confirmed txs.
func getLastTxs(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		if r.Method != "GET" {
			wh.Error405(w, "")
			return
		}
		txs, err := gateway.V.GetLastTxs()
		if err != nil {
			wh.Error500(w, err.Error())
			return
		}

		resTxs := make([]visor.TransactionResult, len(txs))
		for i, tx := range txs {
			resTxs[i] = visor.TransactionResult{
				Transaction: visor.NewReadableTransaction(tx),
				Status:      tx.Status,
			}
		}

		wh.SendOr404(w, &resTxs)
	}
}