Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add API for recent multisig txns #922

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions server/handler/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,78 @@ func (h *Handler) GetTransactions(c echo.Context) error {
})
}

func (h *Handler) GetAllMultisigTxns(c echo.Context) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an existing API for this /multisig/:address/txs. The only modification needed is to make the transaction status filter optional.

Copy link
Contributor Author

@charymalloju charymalloju Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have multi-sig account address transactions, we need account of all multisig txns.

address := c.Param("address")
page, limit, _, err := utils.ParsePaginationParams(c)
if err != nil {
return c.JSON(http.StatusBadRequest, model.ErrorResponse{
Status: "error",
Message: err.Error(),
Log: err.Error(),
})
}

status := utils.GetStatus(c.QueryParam("status"))
var rows *sql.Rows

if status == model.Pending {
rows, err = h.DB.Query(`SELECT id,multisig_address,fee,status,created_at,messages,hash,
err_msg,last_updated,memo,signatures FROM transactions WHERE multisig_address in (select multisig_address from pubkeys where address=$1) AND status=$2 order by created_at desc LIMIT $3 OFFSET $4`,
address, status, limit, (page-1)*limit)
} else {
rows, err = h.DB.Query(`SELECT id,multisig_address,fee,status,created_at,messages,hash,
err_msg,last_updated,memo,signatures FROM transactions WHERE multisig_address in (select multisig_address from pubkeys where address=$1) order by created_at desc LIMIT $2 OFFSET $3`,
address, limit, (page-1)*limit)
}

if err != nil {
if rows != nil && sql.ErrNoRows == rows.Err() {
return c.JSON(http.StatusBadRequest, model.ErrorResponse{
Status: "error",
Message: fmt.Sprintf("no transactions with address %s", address),
Log: rows.Err().Error(),
})
}

return c.JSON(http.StatusInternalServerError, model.ErrorResponse{
Status: "error",
Message: "failed to query transaction",
Log: err.Error(),
})
}

transactions := make([]schema.Transaction, 0)
for rows.Next() {
var transaction schema.Transaction
if err := rows.Scan(
&transaction.ID,
&transaction.MultisigAddress,
&transaction.Fee,
&transaction.Status,
&transaction.CreatedAt,
&transaction.Messages,
&transaction.Hash,
&transaction.ErrMsg,
&transaction.LastUpdated,
&transaction.Memo,
&transaction.Signatures,
); err != nil {
return c.JSON(http.StatusInternalServerError, model.ErrorResponse{
Status: "error",
Message: "failed to decode transaction",
Log: err.Error(),
})
}
transactions = append(transactions, transaction)
}
rows.Close()

return c.JSON(http.StatusOK, model.SuccessResponse{
Data: transactions,
Status: "success",
})
}

func (h *Handler) GetTransaction(c echo.Context) error {
id := c.Param("id")
address := c.Param("address")
Expand Down
2 changes: 1 addition & 1 deletion server/schema/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type Transaction struct {
ID int `pg:"id,pk" json:"id"`
MultisigAddress string `pg:"multisig_address,use_zero" json:"multisig_address"`
Fee json.RawMessage `pg:"fee" json:"fee"`
Fee json.RawMessage `pg:"fee" json:"fee" sql:"-"`
Status string `pg:"status,use_zero" json:"status"`
Messages json.RawMessage `pg:"messages" json:"messages"`
Hash *string `pg:"hash" json:"hash"`
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func main() {
e.DELETE("/multisig/:address/tx/:id", h.DeleteTransaction)
e.POST("/multisig/:address/sign-tx/:id", h.SignTransaction)
e.GET("/multisig/:address/txs", h.GetTransactions)
e.GET("/accounts/:address/all-txns", h.GetAllMultisigTxns)

e.GET("/tokens-info", h.GetTokensInfo)
e.GET("/tokens-info/:denom", h.GetTokenInfo)
Expand Down