Skip to content

Commit

Permalink
feat: migrate names related endpoints to v3 (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmichek authored Oct 24, 2024
1 parent 506155e commit cf3c959
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ NUXT_PUBLIC_SENTRY_DSN=
NUXT_PUBLIC_APP_DOMAIN=localhost:8080
NUXT_PUBLIC_MIDDLEWARE_URL=https://mainnet.aeternity.io/mdw
NUXT_PUBLIC_NODE_URL=https://mainnet.aeternity.io
NUXT_PUBLIC_WEBSOCKET_URL=wss://mainnet.aeternity.io/mdw/v2/websocket
NUXT_PUBLIC_WEBSOCKET_URL=wss://mainnet.aeternity.io/mdw/v3/websocket
NUXT_PUBLIC_NETWORK_NAME=MAINNET
NUXT_PUBLIC_ALTERNATIVE_NETWORK_NAME=TESTNET
NUXT_PUBLIC_NETWORK_ID=ae_mainnet
Expand Down
2 changes: 1 addition & 1 deletion src/components/NameDetailsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
</th>
<td>
<app-link
:to="`/keyblocks/${name.acutionEndsHeight || name.expirationHeight}`">
:to="`/keyblocks/${name.auctionEndsHeight || name.expirationHeight}`">
{{ name.auctionEndsHeight || name.expirationHeight }}
</app-link>
</td>
Expand Down
3 changes: 2 additions & 1 deletion src/stores/accountDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ export const useAccountStore = defineStore('account', () => {

async function fetchAccountNames({ accountId, queryParameters, limit } = {}) {
rawAccountNames.value = null
const defaultParameters = `/v2/names?owned_by=${accountId}&by=name&direction=forward&state=active&limit=${limit ?? 10}`
const defaultParameters = `/v3/names?owned_by=${accountId}&by=name&direction=forward&state=active&limit=${limit ?? 10}`
const { data } = await axios.get(`${MIDDLEWARE_URL}${queryParameters || defaultParameters}`)
rawAccountNames.value = data
console.log('rawAccountNames.value', rawAccountNames.value)
}

async function fetchAccountTokens({ accountId, queryParameters, limit } = {}) {
Expand Down
8 changes: 5 additions & 3 deletions src/stores/nameDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@ export const useNameDetailsStore = defineStore('nameDetails', () => {

async function fetchName(name) {
rawName.value = null
const { data } = await axios.get(`${MIDDLEWARE_URL}/v2/names/${name}`)
const { data } = await axios.get(`${MIDDLEWARE_URL}/v3/names/${name}`)
rawName.value = data
}

// todo history issue
// todo close time count function
async function fetchNameActions({ nameHash = null, queryParameters = null }) {
rawNameActions.value = null
const defaultParameters = `/v2/names/${nameHash}/history`
const defaultParameters = `/v3/names/${nameHash}/history`
const { data } = await axios.get(`${MIDDLEWARE_URL}${queryParameters || defaultParameters}`)
rawNameActions.value = data
}

async function isNameAvailable(name) {
try {
await axios.get(`${MIDDLEWARE_URL}/v2/names/${name}`)
await axios.get(`${MIDDLEWARE_URL}/v3/names/${name}`)
return true
} catch (error) {
if (error.response.status === 404) {
Expand Down
10 changes: 5 additions & 5 deletions src/stores/nftDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export const useNftDetailsStore = defineStore('nftDetails', () => {

await Promise.all([
fetchNft(),
Promise.allSettled([
fetchNftTransfers(),
fetchNftInventory(),
fetchNftOwners(),
]),
// Promise.allSettled([
// fetchNftTransfers(),
// fetchNftInventory(),
// fetchNftOwners(),
// ]),
])

return true
Expand Down
4 changes: 2 additions & 2 deletions src/stores/tokenDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ export const useTokenDetailsStore = defineStore('tokenDetails', () => {

async function fetchTokenHolders({ queryParameters, limit } = {}) {
rawTokenHolders.value = null
const defaultParameters = `/v2/aex9/${tokenId.value}/balances?by=amount&limit=${limit ?? 10}`
const defaultParameters = `/v3/aex9/${tokenId.value}/balances?by=amount&limit=${limit ?? 10}`
const { data } = await axios.get(`${MIDDLEWARE_URL}${queryParameters || defaultParameters}`)
rawTokenHolders.value = data
}

async function fetchTokenHoldersCount() {
tokenHoldersCount.value = null
const { data } = await axios.get(`${MIDDLEWARE_URL}/v2/aex9/${tokenId.value}`)
const { data } = await axios.get(`${MIDDLEWARE_URL}/v3/aex9/${tokenId.value}`)
tokenHoldersCount.value = data.holders
}

Expand Down
59 changes: 29 additions & 30 deletions src/utils/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ export function adaptAccountNames(names) {
const formattedData = names.data.map(name => {
return {
name: name.name,
expirationHeight: name.info.expireHeight,
expiration: DateTime.fromMillis(name.info.approximateExpireTime),
pointers: Object.values(name.info.pointers),
expirationHeight: name.expireHeight,
expiration: DateTime.fromMillis(name.approximateExpireTime),
pointers: name.pointers.map(pointer => pointer.id),
}
})
return {
Expand Down Expand Up @@ -265,62 +265,62 @@ export function adaptExpiredNames(names) {
}

export function adaptCustomPointers(allPointers) {
const customPointers = { ...allPointers }

SPECIAL_POINTERS_PRESET_KEYS.forEach(specialPointerKey => {
const customPointers = allPointers.filter(pointer =>
// separate special and custom pointers
delete customPointers[specialPointerKey]
})
!SPECIAL_POINTERS_PRESET_KEYS.includes(pointer.key),
)

const hasRawPointers = allPointers
? Object.values(allPointers)
.some(v => isAddressValid(v, Encoding.Bytearray))
? allPointers.some(pointer => isAddressValid(pointer.id, Encoding.Bytearray))
: null

return Object.entries(customPointers).map(pointer => {
return customPointers.map(pointer => {
return {
key: formatDecodeBase64(pointer[0]),
pointer: hasRawPointers ? decode(pointer[1]).toString() : pointer[1],
key: pointer.key,
pointer: hasRawPointers ? decode(pointer.id).toString() : pointer.id,
isRawPointer: hasRawPointers,
}
})
}

export function adaptName(name, blockHeight, blockTime) {
const lastBid = name?.auction?.lastBid || name?.info?.lastBid
const customPointers = adaptCustomPointers(name.info?.pointers)
const endHeight = name.auction?.auctionEnd || name?.info?.auctionEnd
const ends = name.auction?.approximateAuctionEndTime || name.info?.approximateAuctionEndTime
const lastBid = name?.auction?.lastBid
const state = formatNameState(name, blockHeight)
const endHeight = name.auction?.auctionEnd
const ends = name.auction?.approximateExpireTime || name.approximateExpireTime
const blockCreatedTime = DateTime.fromMillis(blockTime)
const activated = state === 'active'
? blockCreatedTime.minus({
minutes: blockHeight - name.info.activeFrom * MINUTES_PER_BLOCK,
minutes: blockHeight - name.activeFrom * MINUTES_PER_BLOCK,
})
: null
const customPointers = adaptCustomPointers(name.pointers)

const specialPointers = {
account: name.pointers ? name.pointers.find(name => name.key === 'account_pubkey')?.id : null,
channel: name.pointers ? name.pointers.find(name => name.key === 'channel')?.id : null,
contract: name.pointers ? name.pointers.find(name => name.key === 'contract_pubkey')?.id : null,
oracle: name.pointers ? name.pointers.find(name => name.key === 'oracle_pubkey')?.id : null,
}

return {
state,
name: name.name,
active: name.active,
owner: name.info?.ownership?.current,
owner: name?.ownership?.current,
bidder: lastBid?.tx?.accountId,
bid: lastBid?.tx.nameFee ? formatAettosToAe(lastBid.tx.nameFee) : null,
activatedHeight: state === 'active' ? name.info.activeFrom : null,
activatedHeight: state === 'active' ? name.activeFrom : null,
activated,
expirationHeight: name.info.expireHeight,
expiration: name.info.approximateExpireTime
? DateTime.fromMillis(name.info.approximateExpireTime)
expirationHeight: name.expireHeight,
expiration: name.approximateExpireTime
? DateTime.fromMillis(name.approximateExpireTime)
: null,
auctionEndsHeight: endHeight,
auctionEnds: ends
? DateTime.fromMillis(ends)
: null,
specialPointers: {
account: name.info?.pointers?.account_pubkey,
channel: name.info?.pointers?.channel,
contract: name.info?.pointers?.contract_pubkey,
oracle: name.info?.pointers?.oracle_pubkey,
},
specialPointers,
customPointers,
}
}
Expand Down Expand Up @@ -763,5 +763,4 @@ export function adaptReadEntrypoints(aci) {

export function adaptWriteEntrypoints(aci) {
return Object.groupBy(aci.contract.functions, formatIsStatefulEntrypoint).true

}
6 changes: 3 additions & 3 deletions src/utils/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ export function formatDecodeByteArray(bytesArray) {
}

export function formatNameState(name, blockHeight) {
const isInAuction = name.status === 'auction'
const isActive = name.active
const isExpired = name.status === 'name' && !name.active
const isInAuction = !!name.auction
const isExpired = !name.active && name.auction === null
const isRevoked = isExpired && name.active === false &&
name.info.expireHeight + REVOKED_PERIOD > blockHeight
name.expireHeight + REVOKED_PERIOD > blockHeight

if (isInAuction) {
return 'auction'
Expand Down

0 comments on commit cf3c959

Please sign in to comment.