mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2024-12-22 02:47:32 +01:00
feat: add support for archived tokens
- uses token address for archived tokens others fixes: increase token name limit
This commit is contained in:
parent
a0ba153401
commit
a2422811cb
@ -37,6 +37,7 @@ func InitAdminApi(e *echo.Echo, db *pgxpool.Pool, queries goyesql.Queries, metaC
|
|||||||
g.GET("/address-2-phone/:address", handleAddress2Phone)
|
g.GET("/address-2-phone/:address", handleAddress2Phone)
|
||||||
g.GET("/latest-transactions/:phone", handleLatestTransactions)
|
g.GET("/latest-transactions/:phone", handleLatestTransactions)
|
||||||
g.GET("/latest-transactions-by-token/:phone/:token", handleLatestTransactionsByToken)
|
g.GET("/latest-transactions-by-token/:phone/:token", handleLatestTransactionsByToken)
|
||||||
|
g.GET("/latest-transactions-by-archived-token/:phone/:token", handleLatestTransactionsByArchivedToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newApi(db *pgxpool.Pool, queries goyesql.Queries, metaClient *meta.CicMeta, jwtKey string) *api {
|
func newApi(db *pgxpool.Pool, queries goyesql.Queries, metaClient *meta.CicMeta, jwtKey string) *api {
|
||||||
|
@ -94,3 +94,39 @@ func handleLatestTransactionsByToken(c echo.Context) error {
|
|||||||
|
|
||||||
return c.JSON(http.StatusOK, data)
|
return c.JSON(http.StatusOK, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleLatestTransactionsByArchivedToken(c echo.Context) error {
|
||||||
|
var (
|
||||||
|
api = c.Get("api").(*api)
|
||||||
|
phone = c.Param("phone")
|
||||||
|
token = c.Param("token")
|
||||||
|
pg = pagination.GetPagination(c.QueryParams())
|
||||||
|
|
||||||
|
data []userTransactionRes
|
||||||
|
rows pgx.Rows
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
if pg.FirstPage {
|
||||||
|
rows, err = api.db.Query(context.Background(), api.q["account-latest-transactions-by-archived-token"], phone, token, pg.PerPage)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if pg.Next {
|
||||||
|
rows, err = api.db.Query(context.Background(), api.q["account-latest-transactions-by-archived-token-next"], phone, token, pg.Cursor, pg.PerPage)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rows, err = api.db.Query(context.Background(), api.q["account-latest-transactions-by-archived-token-previous"], phone, token, pg.Cursor, pg.PerPage)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := pgxscan.ScanAll(&data, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, data)
|
||||||
|
}
|
||||||
|
1
migrations/007_tokens_token_name.sql
Normal file
1
migrations/007_tokens_token_name.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE tokens ALTER COLUMN token_name TYPE VARCHAR(32), ALTER COLUMN token_name SET NOT NULL;
|
11
migrations/008_archived_tokens.sql
Normal file
11
migrations/008_archived_tokens.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS archived_tokens (
|
||||||
|
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||||
|
token_address VARCHAR(40) NOT NULL UNIQUE,
|
||||||
|
token_decimals INT NOT NULL,
|
||||||
|
token_name VARCHAR(16) NOT NULL,
|
||||||
|
token_symbol VARCHAR(10) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
---- create above / drop below ----
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS archived_tokens;
|
@ -79,4 +79,36 @@ SELECT * FROM (
|
|||||||
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
|
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
|
||||||
INNER JOIN tokens ON transactions.token_address = tokens.token_address
|
INNER JOIN tokens ON transactions.token_address = tokens.token_address
|
||||||
WHERE users.phone_number = $1 AND tokens.token_symbol = $2 AND transactions.id > $3 ORDER BY transactions.id ASC LIMIT $4
|
WHERE users.phone_number = $1 AND tokens.token_symbol = $2 AND transactions.id > $3 ORDER BY transactions.id ASC LIMIT $4
|
||||||
|
) AS previous_page ORDER BY id DESC;
|
||||||
|
|
||||||
|
-- name: account-latest-transactions-by-archived-token
|
||||||
|
-- Returns the first page of a users latest transactions, filter by token
|
||||||
|
SELECT transactions.id, transactions.date_block, transactions.tx_hash, archived_tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
|
||||||
|
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier,
|
||||||
|
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier
|
||||||
|
FROM transactions
|
||||||
|
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
|
||||||
|
INNER JOIN archived_tokens ON transactions.token_address = archived_tokens.token_address
|
||||||
|
WHERE users.phone_number = $1 AND archived_tokens.token_address = $2 ORDER BY transactions.id DESC LIMIT $3;
|
||||||
|
|
||||||
|
-- name: account-latest-transactions-by-archived-token-next
|
||||||
|
-- Returns the next page based on a cursor, filter by token
|
||||||
|
SELECT transactions.id, transactions.date_block, transactions.tx_hash, archived_tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
|
||||||
|
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier,
|
||||||
|
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier
|
||||||
|
FROM transactions
|
||||||
|
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
|
||||||
|
INNER JOIN archived_tokens ON transactions.token_address = archived_tokens.token_address
|
||||||
|
WHERE users.phone_number = $1 AND archived_tokens.token_address = $2 AND transactions.id < $3 ORDER BY transactions.id DESC LIMIT $4;
|
||||||
|
|
||||||
|
-- name: account-latest-transactions-by-archived-token-previous
|
||||||
|
-- Returns the previous page based on cursor, filter by token
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT transactions.id, transactions.date_block, transactions.tx_hash, archived_tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
|
||||||
|
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier,
|
||||||
|
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier
|
||||||
|
FROM transactions
|
||||||
|
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
|
||||||
|
INNER JOIN archived_tokens ON transactions.token_address = archived_tokens.token_address
|
||||||
|
WHERE users.phone_number = $1 AND archived_tokens.token_address = $2 AND transactions.id > $3 ORDER BY transactions.id ASC LIMIT $4
|
||||||
) AS previous_page ORDER BY id DESC;
|
) AS previous_page ORDER BY id DESC;
|
Loading…
Reference in New Issue
Block a user