[wallet] Add wallet_getChachedBalances method
This commit is contained in:
parent
71f66f6806
commit
d1dc5f1e27
|
@ -74,11 +74,11 @@ func LinkPreviewWhitelist() []Site {
|
|||
Address: "youtu.be",
|
||||
ImageSite: false,
|
||||
},
|
||||
Site{
|
||||
Title: "Tenor GIFs",
|
||||
Address: "tenor.com",
|
||||
ImageSite: true,
|
||||
},
|
||||
// Site{
|
||||
// Title: "Tenor GIFs",
|
||||
// Address: "tenor.com",
|
||||
// ImageSite: true,
|
||||
// },
|
||||
Site{
|
||||
Title: "GIPHY GIFs shortener",
|
||||
Address: "gph.is",
|
||||
|
|
|
@ -97,28 +97,28 @@ func TestGetGiphyShortURLPreviewData(t *testing.T) {
|
|||
require.Equal(t, bostonDynamicsEthGifData.Title, previewData.Title)
|
||||
}
|
||||
|
||||
func TestGetTenorPreviewData(t *testing.T) {
|
||||
validTenorLink := "https://tenor.com/view/robot-dance-do-you-love-me-boston-boston-dynamics-dance-gif-19998728"
|
||||
previewData, err := GetTenorPreviewData(validTenorLink)
|
||||
// func TestGetTenorPreviewData(t *testing.T) {
|
||||
// validTenorLink := "https://tenor.com/view/robot-dance-do-you-love-me-boston-boston-dynamics-dance-gif-19998728"
|
||||
// previewData, err := GetTenorPreviewData(validTenorLink)
|
||||
|
||||
gifData := LinkPreviewData{
|
||||
Site: "Tenor",
|
||||
Title: "Annihere",
|
||||
ThumbnailURL: "https://media.tenor.com/images/975f6b95d188c277ebba62d9b5511685/tenor.gif",
|
||||
Height: 400,
|
||||
Width: 600,
|
||||
}
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, gifData.Site, previewData.Site)
|
||||
require.Equal(t, gifData.Title, previewData.Title)
|
||||
require.Equal(t, gifData.ThumbnailURL, previewData.ThumbnailURL)
|
||||
require.Equal(t, gifData.Height, previewData.Height)
|
||||
require.Equal(t, gifData.Width, previewData.Width)
|
||||
// gifData := LinkPreviewData{
|
||||
// Site: "Tenor",
|
||||
// Title: "Annihere",
|
||||
// ThumbnailURL: "https://media.tenor.com/images/975f6b95d188c277ebba62d9b5511685/tenor.gif",
|
||||
// Height: 400,
|
||||
// Width: 600,
|
||||
// }
|
||||
// require.NoError(t, err)
|
||||
// require.Equal(t, gifData.Site, previewData.Site)
|
||||
// require.Equal(t, gifData.Title, previewData.Title)
|
||||
// require.Equal(t, gifData.ThumbnailURL, previewData.ThumbnailURL)
|
||||
// require.Equal(t, gifData.Height, previewData.Height)
|
||||
// require.Equal(t, gifData.Width, previewData.Width)
|
||||
|
||||
invalidTenorLink := "https://giphy.com/gifs/this-gif-does-not-exist-44444"
|
||||
_, err = GetTenorPreviewData(invalidTenorLink)
|
||||
require.Error(t, err)
|
||||
}
|
||||
// invalidTenorLink := "https://giphy.com/gifs/this-gif-does-not-exist-44444"
|
||||
// _, err = GetTenorPreviewData(invalidTenorLink)
|
||||
// require.Error(t, err)
|
||||
// }
|
||||
|
||||
func TestStatusLinkPreviewData(t *testing.T) {
|
||||
|
||||
|
|
|
@ -238,3 +238,34 @@ func (api *API) CheckRecentHistory(ctx context.Context, addresses []common.Addre
|
|||
addresses,
|
||||
new(big.Int).SetUint64(api.s.db.network))
|
||||
}
|
||||
|
||||
type LastKnownBlockView struct {
|
||||
Address common.Address `json:"address"`
|
||||
Number *big.Int `json:"blockNumber"`
|
||||
Balance BigInt `json:"balance"`
|
||||
Nonce *int64 `json:"nonce"`
|
||||
}
|
||||
|
||||
func blocksToViews(blocks map[common.Address]*LastKnownBlock) []LastKnownBlockView {
|
||||
blocksViews := []LastKnownBlockView{}
|
||||
for address, block := range blocks {
|
||||
view := LastKnownBlockView{
|
||||
Address: address,
|
||||
Number: block.Number,
|
||||
Balance: BigInt{block.Balance},
|
||||
Nonce: block.Nonce,
|
||||
}
|
||||
blocksViews = append(blocksViews, view)
|
||||
}
|
||||
|
||||
return blocksViews
|
||||
}
|
||||
|
||||
func (api *API) GetCachedBalances(ctx context.Context, addresses []common.Address) ([]LastKnownBlockView, error) {
|
||||
result, error := api.s.db.getLastKnownBalances(addresses)
|
||||
if error != nil {
|
||||
return nil, error
|
||||
}
|
||||
|
||||
return blocksToViews(result), nil
|
||||
}
|
||||
|
|
|
@ -433,6 +433,22 @@ func (db *Database) GetLastKnownBlockByAddress(address common.Address) (block *L
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (db *Database) getLastKnownBalances(addresses []common.Address) (map[common.Address]*LastKnownBlock, error) {
|
||||
result := map[common.Address]*LastKnownBlock{}
|
||||
for _, address := range addresses {
|
||||
block, error := db.GetLastKnownBlockByAddress(address)
|
||||
if error != nil {
|
||||
return nil, error
|
||||
}
|
||||
|
||||
if block != nil {
|
||||
result[address] = block
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (db *Database) GetLastKnownBlockByAddresses(addresses []common.Address) (map[common.Address]*LastKnownBlock, []common.Address, error) {
|
||||
res := map[common.Address]*LastKnownBlock{}
|
||||
accountsWithoutHistory := []common.Address{}
|
||||
|
@ -785,8 +801,8 @@ func insertBlocksWithTransactions(creator statementCreator, account common.Addre
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateTx, err := creator.Prepare(`UPDATE transfers
|
||||
SET log = ?
|
||||
updateTx, err := creator.Prepare(`UPDATE transfers
|
||||
SET log = ?
|
||||
WHERE network_id = ? AND address = ? AND hash = ?`)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue