62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package rest
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
store "custodial/pkg/store"
|
|
|
|
gin "github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type AccountListRequest struct {
|
|
Offset int `json:"offset"`
|
|
Limit int `json:"limit"`
|
|
}
|
|
|
|
// @BasePath /api/v1
|
|
//
|
|
// AccountListV1 godoc
|
|
//
|
|
// @Summary List all accounts
|
|
// @Schemes
|
|
// @Description List accounts paginating by (limit, offset)
|
|
// @Tags Account
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security ApiKeyAuth
|
|
// @Param message body AccountListRequest true "Paging Info"
|
|
// @Success 200 {object} []CreateAccountResponse
|
|
// @Failure 400 {object} ErrorResponse
|
|
//
|
|
// @Router /account/list [post]
|
|
func AccountListV1(c *gin.Context) {
|
|
|
|
var req AccountListRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
eth, err := store.ListAccounts(store.Ethereum, req.Offset, req.Limit)
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
fmt.Println("eth", eth)
|
|
|
|
merge := []CreateAccountResponse{}
|
|
for _, account := range eth {
|
|
|
|
merge = append(merge, CreateAccountResponse{
|
|
AccountID: account.GetAccountID(),
|
|
Label: account.GetLabel(),
|
|
Index: account.GetHDIndex(),
|
|
TronAddress: GetPrivKeys(account.GetHDIndex()).TRONAddress,
|
|
EthAddress: account.GetAddress(),
|
|
})
|
|
}
|
|
|
|
c.JSON(http.StatusOK, merge)
|
|
}
|