Ejemplo n.º 1
0
// walletTransactionsAddrHandler handles API calls to
// /wallet/transactions/:addr.
func (api *API) walletTransactionsAddrHandler(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
	// Parse the address being input.
	jsonAddr := "\"" + ps.ByName("addr") + "\""
	var addr types.UnlockHash
	err := addr.UnmarshalJSON([]byte(jsonAddr))
	if err != nil {
		WriteError(w, Error{"error after call to /wallet/transactions: " + err.Error()}, http.StatusBadRequest)
		return
	}

	confirmedATs := api.wallet.AddressTransactions(addr)
	unconfirmedATs := api.wallet.AddressUnconfirmedTransactions(addr)
	WriteJSON(w, WalletTransactionsGETaddr{
		ConfirmedTransactions:   confirmedATs,
		UnconfirmedTransactions: unconfirmedATs,
	})
}
Ejemplo n.º 2
0
// walletTransactionsHandler handles API calls to /wallet/transactions.
func (srv *Server) walletTransactionsHandler(w http.ResponseWriter, req *http.Request) {
	if req.URL.Path == "/wallet/transactions" && (req.Method == "" || req.Method == "GET") {
		srv.walletTransactionsHandlerGET(w, req)
		return
	}

	// Only a GET call is allowed at this point.
	if req.Method != "GET" && req.Method != "" {
		writeError(w, "unrecognized method call to /wallet/transactions", http.StatusBadRequest)
		return
	}

	// The only call remaining is /wallet/transactions/$(addr) - parse the
	// address.
	jsonAddr := "\"" + strings.TrimPrefix(req.URL.Path, "/wallet/transactions/") + "\""
	var addr types.UnlockHash
	err := addr.UnmarshalJSON([]byte(jsonAddr))
	if err != nil {
		writeError(w, "error after call to /wallet/transactions: "+err.Error(), http.StatusBadRequest)
		return
	}
	srv.walletTransactionsHandlerGETaddr(w, req, addr)
}