mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
API Update tokens endpoint
This commit is contained in:
@@ -404,8 +404,8 @@ func (hdb *HistoryDB) UpdateTokenValue(tokenSymbol string, value float64) error
|
||||
}
|
||||
|
||||
// GetToken returns a token from the DB given a TokenID
|
||||
func (hdb *HistoryDB) GetToken(tokenID common.TokenID) (*TokenRead, error) {
|
||||
token := &TokenRead{}
|
||||
func (hdb *HistoryDB) GetToken(tokenID common.TokenID) (*TokenWithUSD, error) {
|
||||
token := &TokenWithUSD{}
|
||||
err := meddler.QueryRow(
|
||||
hdb.db, token, `SELECT * FROM token WHERE token_id = $1;`, tokenID,
|
||||
)
|
||||
@@ -413,17 +413,17 @@ func (hdb *HistoryDB) GetToken(tokenID common.TokenID) (*TokenRead, error) {
|
||||
}
|
||||
|
||||
// GetAllTokens returns all tokens from the DB
|
||||
func (hdb *HistoryDB) GetAllTokens() ([]TokenRead, error) {
|
||||
var tokens []*TokenRead
|
||||
func (hdb *HistoryDB) GetAllTokens() ([]TokenWithUSD, error) {
|
||||
var tokens []*TokenWithUSD
|
||||
err := meddler.QueryAll(
|
||||
hdb.db, &tokens,
|
||||
"SELECT * FROM token ORDER BY token_id;",
|
||||
)
|
||||
return db.SlicePtrsToSlice(tokens).([]TokenRead), err
|
||||
return db.SlicePtrsToSlice(tokens).([]TokenWithUSD), err
|
||||
}
|
||||
|
||||
// GetTokens returns a list of tokens from the DB
|
||||
func (hdb *HistoryDB) GetTokens(ids []common.TokenID, symbols []string, name string, fromItem, limit *uint, order string) ([]TokenRead, *db.Pagination, error) {
|
||||
func (hdb *HistoryDB) GetTokens(ids []common.TokenID, symbols []string, name string, fromItem, limit *uint, order string) ([]TokenWithUSD, *db.Pagination, error) {
|
||||
var query string
|
||||
var args []interface{}
|
||||
queryStr := `SELECT * , COUNT(*) OVER() AS total_items, MIN(token.item_id) OVER() AS first_item, MAX(token.item_id) OVER() AS last_item FROM token `
|
||||
@@ -480,14 +480,14 @@ func (hdb *HistoryDB) GetTokens(ids []common.TokenID, symbols []string, name str
|
||||
return nil, nil, err
|
||||
}
|
||||
query = hdb.db.Rebind(query)
|
||||
tokens := []*TokenRead{}
|
||||
tokens := []*TokenWithUSD{}
|
||||
if err := meddler.QueryAll(hdb.db, &tokens, query, argsQ...); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if len(tokens) == 0 {
|
||||
return nil, nil, sql.ErrNoRows
|
||||
}
|
||||
return db.SlicePtrsToSlice(tokens).([]TokenRead), &db.Pagination{
|
||||
return db.SlicePtrsToSlice(tokens).([]TokenWithUSD), &db.Pagination{
|
||||
TotalItems: tokens[0].TotalItems,
|
||||
FirstItem: tokens[0].FirstItem,
|
||||
LastItem: tokens[0].LastItem,
|
||||
|
||||
@@ -80,20 +80,20 @@ type txWrite struct {
|
||||
Nonce *common.Nonce `meddler:"nonce"`
|
||||
}
|
||||
|
||||
// TokenRead add USD info to common.Token
|
||||
type TokenRead struct {
|
||||
ItemID int `meddler:"item_id"`
|
||||
TokenID common.TokenID `meddler:"token_id"`
|
||||
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum block number in which this token was registered
|
||||
EthAddr ethCommon.Address `meddler:"eth_addr"`
|
||||
Name string `meddler:"name"`
|
||||
Symbol string `meddler:"symbol"`
|
||||
Decimals uint64 `meddler:"decimals"`
|
||||
USD *float64 `meddler:"usd"`
|
||||
USDUpdate *time.Time `meddler:"usd_update,utctime"`
|
||||
TotalItems int `meddler:"total_items"`
|
||||
FirstItem int `meddler:"first_item"`
|
||||
LastItem int `meddler:"last_item"`
|
||||
// TokenWithUSD add USD info to common.Token
|
||||
type TokenWithUSD struct {
|
||||
ItemID int `json:"itemId" meddler:"item_id"`
|
||||
TokenID common.TokenID `json:"id" meddler:"token_id"`
|
||||
EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"` // Ethereum block number in which this token was registered
|
||||
EthAddr ethCommon.Address `json:"ethereumAddress" meddler:"eth_addr"`
|
||||
Name string `json:"name" meddler:"name"`
|
||||
Symbol string `json:"symbol" meddler:"symbol"`
|
||||
Decimals uint64 `json:"decimals" meddler:"decimals"`
|
||||
USD *float64 `json:"USD" meddler:"usd"`
|
||||
USDUpdate *time.Time `json:"fiatUpdate" meddler:"usd_update,utctime"`
|
||||
TotalItems int `json:"-" meddler:"total_items"`
|
||||
FirstItem int `json:"-" meddler:"first_item"`
|
||||
LastItem int `json:"-" meddler:"last_item"`
|
||||
}
|
||||
|
||||
// HistoryExit is a representation of a exit with additional information
|
||||
|
||||
Reference in New Issue
Block a user