Example #1
0
// walletTransactionHandler handles API calls to /wallet/transaction.
func (srv *Server) walletTransactionHandler(w http.ResponseWriter, req *http.Request) {
	// GET is the only supported method.
	if req.Method != "" && req.Method != "GET" {
		writeError(w, "unrecognized method when calling /wallet/transaction", http.StatusBadRequest)
		return
	}

	// Parse the id from the url.
	var id types.TransactionID
	jsonID := "\"" + strings.TrimPrefix(req.URL.Path, "/wallet/transaction/") + "\""
	err := id.UnmarshalJSON([]byte(jsonID))
	if err != nil {
		writeError(w, "error after call to /wallet/history: "+err.Error(), http.StatusBadRequest)
		return
	}
	srv.walletTransactionHandlerGETid(w, req, id)
}
Example #2
0
// walletTransactionHandler handles API calls to /wallet/transaction/:id.
func (api *API) walletTransactionHandler(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
	// Parse the id from the url.
	var id types.TransactionID
	jsonID := "\"" + ps.ByName("id") + "\""
	err := id.UnmarshalJSON([]byte(jsonID))
	if err != nil {
		WriteError(w, Error{"error after call to /wallet/history: " + err.Error()}, http.StatusBadRequest)
		return
	}

	txn, ok := api.wallet.Transaction(id)
	if !ok {
		WriteError(w, Error{"error when calling /wallet/transaction/$(id): transaction not found"}, http.StatusBadRequest)
		return
	}
	WriteJSON(w, WalletTransactionGETid{
		Transaction: txn,
	})
}