Skip to content

Commit

Permalink
Merge pull request #289 from vitalibalashka/feat/txs_mapping_admin_panel
Browse files Browse the repository at this point in the history
feat(BUX-116): txs mapping for admin panel
  • Loading branch information
mergify[bot] authored Aug 28, 2023
2 parents 7ae5f7f + db05484 commit cc80004
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
8 changes: 7 additions & 1 deletion actions/admin/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

"github.com/BuxOrg/bux"
buxmodels "github.com/BuxOrg/bux-models"
"github.com/BuxOrg/bux-server/actions"
"github.com/BuxOrg/bux-server/mappings"
"github.com/julienschmidt/httprouter"
Expand Down Expand Up @@ -46,8 +47,13 @@ func (a *Action) transactionsSearch(w http.ResponseWriter, req *http.Request, _
return
}

contracts := make([]*buxmodels.Transaction, 0)
for _, transaction := range transactions {
contracts = append(contracts, mappings.MapToTransactionContractForAdmin(transaction))
}

// Return response
apirouter.ReturnResponse(w, req, http.StatusOK, transactions)
apirouter.ReturnResponse(w, req, http.StatusOK, contracts)
}

// transactionsCount will count all transactions filtered by metadata
Expand Down
31 changes: 31 additions & 0 deletions mappings/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ func MapToTransactionContract(t *bux.Transaction) *buxmodels.Transaction {
TransactionDirection: string(t.Direction),
}

processMetadata(t, t.XPubID, &model)
processOutputValue(t, t.XPubID, &model)

return &model
}

// MapToTransactionContractForAdmin will map the model from bux to the bux-models contract for admin
func MapToTransactionContractForAdmin(t *bux.Transaction) *buxmodels.Transaction {
if t == nil {
return nil
}

model := buxmodels.Transaction{
Model: *common.MapToContract(&t.Model),
ID: t.ID,
Hex: t.Hex,
XpubInIDs: t.XpubInIDs,
XpubOutIDs: t.XpubOutIDs,
BlockHash: t.BlockHash,
BlockHeight: t.BlockHeight,
Fee: t.Fee,
NumberOfInputs: t.NumberOfInputs,
NumberOfOutputs: t.NumberOfOutputs,
DraftID: t.DraftID,
TotalValue: t.TotalValue,
Status: string(t.Status),
Outputs: t.XpubOutputValue,
}

processMetadata(t, t.XPubID, &model)

return &model
Expand All @@ -43,7 +72,9 @@ func processMetadata(t *bux.Transaction, xpubID string, model *buxmodels.Transac
model.Model.Metadata[key] = value
}
}
}

func processOutputValue(t *bux.Transaction, xpubID string, model *buxmodels.Transaction) {
model.OutputValue = int64(0)
if len(t.XpubOutputValue) > 0 && t.XpubOutputValue[xpubID] != 0 {
model.OutputValue = t.XpubOutputValue[xpubID]
Expand Down

0 comments on commit cc80004

Please sign in to comment.