Skip to content

Commit

Permalink
expose transaction batch commit to http api
Browse files Browse the repository at this point in the history
Co-authored-by: Geoffrey Ragot <[email protected]>
Co-authored-by: Clément Salaün <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2022
1 parent 4946721 commit 7a3d914
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/api/controllers/transaction_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,34 @@ func (ctl *TransactionController) PostTransactionMetadata(c *gin.Context) {
nil,
)
}

// PostTransactionsBatch godoc
// @Summary Create Transactions Batch
// @Description Create a new ledger transactions batch
// @Tags transactions
// @Schemes
// @Description Commit a batch of new transactions to the ledger
// @Param ledger path string true "ledger"
// @Param transactions body core.Transactions true "transactions"
// @Accept json
// @Produce json
// @Success 200 {object} controllers.BaseResponse
// @Failure 400
// @Router /{ledger}/transactions/batch [post]
func (ctl *TransactionController) PostTransactionsBatch(c *gin.Context) {
l, _ := c.Get("ledger")

var transactions core.Transactions
if err := c.ShouldBindJSON(&transactions); err != nil {
ctl.responseError(c, http.StatusBadRequest, err)
return
}

ret, err := l.(*ledger.Ledger).Commit(c.Request.Context(), transactions.Transactions)
if err != nil {
ctl.responseError(c, http.StatusBadRequest, err)
return
}

ctl.response(c, http.StatusOK, ret)
}
1 change: 1 addition & 0 deletions pkg/api/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (r *Routes) Engine(cc cors.Config) *gin.Engine {
// TransactionController
ledger.GET("/transactions", r.transactionController.GetTransactions)
ledger.POST("/transactions", r.transactionController.PostTransaction)
ledger.POST("/transactions/batch", r.transactionController.PostTransactionsBatch)
ledger.GET("/transactions/:txid", r.transactionController.GetTransaction)
ledger.POST("/transactions/:txid/revert", r.transactionController.RevertTransaction)
ledger.POST("/transactions/:txid/metadata", r.transactionController.PostTransactionMetadata)
Expand Down
5 changes: 5 additions & 0 deletions pkg/core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"fmt"
)

// Transactions struct
type Transactions struct {
Transactions []Transaction `json:"transactions" binding:"required,dive"`
}

type Transaction struct {
ID int64 `json:"txid"`
Postings Postings `json:"postings"`
Expand Down

0 comments on commit 7a3d914

Please sign in to comment.