generated from mrz1836/go-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new utxo endpoints, including the original transaction
- Loading branch information
Showing
8 changed files
with
714 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package utxos | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/BuxOrg/bux" | ||
"github.com/BuxOrg/bux-server/actions" | ||
"github.com/julienschmidt/httprouter" | ||
apirouter "github.com/mrz1836/go-api-router" | ||
) | ||
|
||
// count will count all the utxos fulfilling the given conditions | ||
func (a *Action) count(w http.ResponseWriter, req *http.Request, _ httprouter.Params) { | ||
|
||
reqXPubID, _ := bux.GetXpubIDFromRequest(req) | ||
|
||
// Parse the params | ||
params := apirouter.GetParams(req) | ||
_, metadata, conditions, err := actions.GetQueryParameters(params) | ||
if err != nil { | ||
apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) | ||
return | ||
} | ||
|
||
var dbConditions = map[string]interface{}{} | ||
if conditions != nil { | ||
dbConditions = *conditions | ||
} | ||
// force the xpub_id of the current user on query | ||
dbConditions["xpub_id"] = reqXPubID | ||
|
||
// Get a utxo using a xPub | ||
var count int64 | ||
if count, err = a.Services.Bux.GetUtxosCount( | ||
req.Context(), | ||
metadata, | ||
&dbConditions, | ||
); err != nil { | ||
apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) | ||
return | ||
} | ||
|
||
// Return response | ||
apirouter.ReturnResponse(w, req, http.StatusOK, count) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.