Skip to content

Commit

Permalink
feat(whale-api): return decoded address in bid history (#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleleow authored Sep 27, 2022
1 parent 6438695 commit 9e80daa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions apps/whale-api/src/module.api/loan.auction.history.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ it('should listVaultAuctionHistory', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: colAddr,
amount: '5408.55',
tokenId: 2,
block: expect.any(Object)
Expand All @@ -182,6 +183,7 @@ it('should listVaultAuctionHistory', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: bobColAddr,
amount: '5355',
tokenId: 2,
block: expect.any(Object)
Expand All @@ -193,6 +195,7 @@ it('should listVaultAuctionHistory', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: colAddr,
amount: '5300',
tokenId: 2,
block: expect.any(Object)
Expand All @@ -211,6 +214,7 @@ it('should listVaultAuctionHistory', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: bobColAddr,
amount: '5355.123',
tokenId: 4,
block: expect.any(Object)
Expand All @@ -222,6 +226,7 @@ it('should listVaultAuctionHistory', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: colAddr,
amount: '5300.123',
tokenId: 4,
block: expect.any(Object)
Expand All @@ -241,6 +246,7 @@ it('should listVaultAuctionHistory with pagination', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: colAddr,
amount: '5408.55',
tokenId: 2,
block: expect.any(Object)
Expand All @@ -257,6 +263,7 @@ it('should listVaultAuctionHistory with pagination', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: bobColAddr,
amount: '5355',
tokenId: 2,
block: expect.any(Object)
Expand All @@ -273,6 +280,7 @@ it('should listVaultAuctionHistory with pagination', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: colAddr,
amount: '5300',
tokenId: 2,
block: expect.any(Object)
Expand Down
8 changes: 7 additions & 1 deletion apps/whale-api/src/module.api/loan.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { VaultAuctionHistoryMapper, VaultAuctionBatchHistory } from '../module.m
import { ActivePrice } from '@defichain/whale-api-client/dist/api/prices'
import { NetworkName } from '@defichain/jellyfish-network'
import { HexEncoder } from '../module.model/_hex.encoder'
import { fromScriptHex } from '@defichain/jellyfish-address'

@Controller('/loans')
export class LoanController {
Expand Down Expand Up @@ -202,7 +203,12 @@ export class LoanController {
): Promise<ApiPagedResponse<VaultAuctionBatchHistory>> {
const lt = query.next ?? `${HexEncoder.encodeHeight(height)}-${'f'.repeat(64)}`
const gt = `${HexEncoder.encodeHeight(height - this.liqBlockExpiry)}-${'0'.repeat(64)}`
const list = await this.vaultAuctionHistoryMapper.query(`${id}-${batchIndex}`, query.size, lt, gt)
const list = (await this.vaultAuctionHistoryMapper.query(`${id}-${batchIndex}`, query.size, lt, gt)).map(history => {
return {
...history,
address: fromScriptHex(history.from, this.network)?.address as string
}
})

return ApiPagedResponse.of(list, query.size, item => {
return item.sort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface VaultAuctionBatchHistory extends Model {

vaultId: string
index: number
from: string
from: string // -------------------| hex script
amount: string // -------------------| stringified bignumber
tokenId: number // ------------------| tokenId

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ it('should listVaultAuctionHistory', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: colAddr,
amount: '5408.55',
tokenId: 2,
block: expect.any(Object)
Expand All @@ -184,6 +185,7 @@ it('should listVaultAuctionHistory', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: bobColAddr,
amount: '5355',
tokenId: 2,
block: expect.any(Object)
Expand All @@ -195,6 +197,7 @@ it('should listVaultAuctionHistory', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: colAddr,
amount: '5300',
tokenId: 2,
block: expect.any(Object)
Expand All @@ -213,6 +216,7 @@ it('should listVaultAuctionHistory', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: bobColAddr,
amount: '5355.123',
tokenId: 4,
block: expect.any(Object)
Expand All @@ -224,6 +228,7 @@ it('should listVaultAuctionHistory', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: colAddr,
amount: '5300.123',
tokenId: 4,
block: expect.any(Object)
Expand All @@ -245,6 +250,7 @@ it('should listVaultAuctionHistory with pagination', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: colAddr,
amount: '5408.55',
tokenId: 2,
block: expect.any(Object)
Expand All @@ -263,6 +269,7 @@ it('should listVaultAuctionHistory with pagination', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: bobColAddr,
amount: '5355',
tokenId: 2,
block: expect.any(Object)
Expand All @@ -281,6 +288,7 @@ it('should listVaultAuctionHistory with pagination', async () => {
vaultId: vaultId,
index: 0,
from: expect.any(String),
address: colAddr,
amount: '5300',
tokenId: 2,
block: expect.any(Object)
Expand Down
1 change: 1 addition & 0 deletions packages/whale-api-client/src/api/loan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export interface VaultAuctionBatchHistory {
vaultId: string
index: number
from: string
address: string
amount: string
tokenId: number

Expand Down

0 comments on commit 9e80daa

Please sign in to comment.