Skip to content

Commit

Permalink
Merge branch 'develop' into release/babylon-2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
krzlabrdx committed Jan 24, 2024
2 parents 2635a73 + bf56a45 commit 133e7f1
Show file tree
Hide file tree
Showing 104 changed files with 5,450 additions and 709 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ Release Date: _unreleased_
- Dropped `balance_changes` fallback mechanism.
- Reworked internal mechanism used to fetch network configuration. Is no longer stored in the underlying database and it is shared across all services.

## 1.2.5
## 1.3.0
Release Date: _unreleased_

- add support for new transaction types (flash transactions) that are gonna occur on protocol update.
- Added support for new transaction types (flash transactions) that are gonna occur on protocol updates.
- Moved vm_type to `package_code_history` table from package in `entity` table.
- `vm_type`, `code_hash_hex` and `code_hex` are returned as collection (it's allowed after protocol update to have multiple codes per package). Previous properties will return empty strings to keep contract compatibility.
- Created new `package_blueprint_aggregate_history` table which will hold pointers to all package blueprints.
- Created new `package_code_aggregate_history` table which will hold pointers to all package codes.

## 1.2.4
Release Date: 4.01.2024

- Extended validator's data returned from `/state/validators/list`: added `effective_fee_factor` field which returns `current` fee_factor and optionally `pending` change.
- Enable retries on transient database connectivity issues in gateway api.
- Enable retries on core api calls in gateway api.
Expand Down
24 changes: 0 additions & 24 deletions sdk/typescript/lib/helpers/exhaust-pagination.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
import { LedgerState } from '../generated'

/**
* Exhausts a paginated API resource and returns all the results.
*/
export const exhaustPagination = async <T>(
queryFunction: (
cursor?: string
) => Promise<{ items: T[]; next_cursor?: string | null }>,
start?: string
): Promise<T[]> => {
let next_cursor: string | null | undefined = start
const aggregatedEntities: T[] = []

do {
const queryFunctionResponse: {
next_cursor?: string | null
items: T[]
} = await queryFunction(next_cursor)
aggregatedEntities.push(...queryFunctionResponse.items)
next_cursor = queryFunctionResponse.next_cursor
} while (next_cursor)

return aggregatedEntities
}

/**
* Exhausts a paginated API resource and returns all the results.
*/
Expand Down
8 changes: 7 additions & 1 deletion sdk/typescript/lib/helpers/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export const RadixNetworkConfig: Record<string, NetworkConfig> = {
gatewayUrl: 'https://rcnet.radixdlt.com',
dashboardUrl: 'https://rcnet-dashboard.radixdlt.com',
},
Mardunet: {
networkName: 'Mardunet',
networkId: RadixNetwork.Mardunet,
gatewayUrl: 'https://mardunet-gateway.radixdlt.com',
dashboardUrl: 'https://mardunet-dashboard.rdx-works-main.extratools.works',
},
Zabanet: {
networkName: 'Zabanet',
networkId: RadixNetwork.Zabanet,
Expand All @@ -66,7 +72,7 @@ export const RadixNetworkConfig: Record<string, NetworkConfig> = {
networkName: 'Gilganet',
networkId: RadixNetwork.Gilganet,
gatewayUrl: 'https://gilganet-gateway.radixdlt.com',
dashboardUrl: '',
dashboardUrl: 'https://gilganet-dashboard.rdx-works-main.extratools.works',
},
Enkinet: {
networkName: 'Enkinet',
Expand Down
208 changes: 169 additions & 39 deletions sdk/typescript/lib/subapis/state.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { chunk } from '../helpers/chunk'
import {
exhaustPagination,
exhaustPaginationWithLedgerState,
} from '../helpers/exhaust-pagination'
import { exhaustPaginationWithLedgerState } from '../helpers/exhaust-pagination'
import {
EntityMetadataItem,
FungibleResourcesCollection,
Expand All @@ -17,6 +14,7 @@ import {
StateEntityDetailsResponseItem,
StateEntityFungiblesPageResponse,
StateEntityMetadataPageResponse,
StateEntityNonFungiblesPageResponse,
StateNonFungibleDetailsResponseItem,
StateNonFungibleIdsResponse,
StateNonFungibleLocationResponseItem,
Expand Down Expand Up @@ -69,7 +67,7 @@ export class State {
* Returns an array or single item depending on input value. If array is passed, it will be split into chunks of 20 addresses
* which will be requested separately and returned only if all requests are successful.
*
* Calling this function will exhaust list of all fungible resources for each entity.
* Calling this function will exhaust list of all resources for each entity.
* If any of the requests fail, the whole operation will fail.
*
* When requesting details for `internal_vault` entity, `non_fungible_resources` and `fungible_resources` will be defaulted to objects with empty arrays
Expand Down Expand Up @@ -136,16 +134,25 @@ export class State {
return isArray
? Promise.all(
(items as StateEntityDetailsVaultResponseItem[]).map((item) =>
this.queryAllFungibles(
this.queryAllResources(
item,
{
explicitMetadata: options?.explicitMetadata ?? [],
nonFungibleIncludeNfids:
options?.nonFungibleIncludeNfids ?? true,
},
ledgerState || {
state_version: ledger_state.state_version,
}
)
)
)
: this.queryAllFungibles(
: this.queryAllResources(
items[0] as StateEntityDetailsVaultResponseItem,
{
explicitMetadata: options?.explicitMetadata ?? [],
nonFungibleIncludeNfids: options?.nonFungibleIncludeNfids ?? true,
},
ledgerState || {
state_version: ledger_state.state_version,
}
Expand Down Expand Up @@ -208,10 +215,10 @@ export class State {
address: string,
startCursor?: string
): Promise<EntityMetadataItem[]> {
return exhaustPagination(
return exhaustPaginationWithLedgerState(
this.getEntityMetadata.bind(this, address),
startCursor
)
).then((res) => res.aggregatedEntities)
}

/**
Expand All @@ -232,11 +239,18 @@ export class State {
* Get list of all validators. This will iterate over returned cursors and aggregate all responses.
*/
async getAllValidators(start?: string): Promise<ValidatorCollectionItem[]> {
return exhaustPagination(this.getValidators.bind(this), start)
return exhaustPaginationWithLedgerState((cursor?: string) => {
const v = this.getValidatorsWithLedgerState(cursor)
return v.then((res) => ({
items: res.validators.items,
ledger_state: res.ledger_state,
next_cursor: res.validators.next_cursor,
}))
}, start).then((res) => res.aggregatedEntities)
}

/**
* Get paged list of validators
* Get paged list of validators with ledger state
* @param cursor
*/
async getValidatorsWithLedgerState(cursor?: string) {
Expand All @@ -256,6 +270,7 @@ export class State {
this.getValidatorsWithLedgerState(cursor).then((res) => ({
items: res.validators.items,
ledger_state: res.ledger_state,
next_cursor: res.validators.next_cursor,
})),
start
)
Expand Down Expand Up @@ -358,8 +373,11 @@ export class State {

private async getEntityFungiblesPageVaultAggregated(
entity: string,
nextCursor?: string | undefined,
ledgerState?: LedgerStateSelector
options?: {
nextCursor?: string | undefined
ledgerState?: LedgerStateSelector
explicitMetadata?: string[]
}
): Promise<
ReplaceProperty<
StateEntityFungiblesPageResponse,
Expand All @@ -370,9 +388,12 @@ export class State {
return this.innerClient.entityFungiblesPage({
stateEntityFungiblesPageRequest: {
address: entity,
cursor: nextCursor,
cursor: options?.nextCursor,
aggregation_level: 'Vault',
at_ledger_state: ledgerState,
at_ledger_state: options?.ledgerState,
opt_ins: {
explicit_metadata: options?.explicitMetadata,
},
},
}) as Promise<
ReplaceProperty<
Expand All @@ -383,8 +404,69 @@ export class State {
>
}

private async getEntityNonFungiblesPageVaultAggregated(
entity: string,
options?: {
cursor: string | undefined
ledgerState?: LedgerStateSelector
explicitMetadata?: string[]
nonFungibleIncludeNfids?: boolean
}
): Promise<
ReplaceProperty<
StateEntityNonFungiblesPageResponse,
'items',
NonFungibleResourcesCollectionItemVaultAggregated[]
>
> {
return this.innerClient.entityNonFungiblesPage({
stateEntityNonFungiblesPageRequest: {
address: entity,
cursor: options?.cursor,
aggregation_level: 'Vault',
at_ledger_state: options?.ledgerState,
opt_ins: {
explicit_metadata: options?.explicitMetadata,
non_fungible_include_nfids: options?.nonFungibleIncludeNfids,
},
},
}) as Promise<
ReplaceProperty<
StateEntityNonFungiblesPageResponse,
'items',
NonFungibleResourcesCollectionItemVaultAggregated[]
>
>
}

private ensureResourcesProperties(
response: StateEntityDetailsResponse
): ReplaceProperty<
StateEntityDetailsResponse,
'items',
StateEntityDetailsVaultResponseItem[]
> {
return {
...response,
items: response.items.map((item) => ({
...item,
fungible_resources: item.fungible_resources || {
total_count: 0,
items: [],
},
non_fungible_resources: item.non_fungible_resources || {
total_count: 0,
items: [],
},
})) as StateEntityDetailsVaultResponseItem[],
}
}

private async queryAllFungibles(
stateEntityDetails: StateEntityDetailsVaultResponseItem,
options?: {
explicitMetadata?: string[]
},
ledgerState?: LedgerStateSelector
): Promise<StateEntityDetailsVaultResponseItem> {
const nextCursor = stateEntityDetails?.fungible_resources?.next_cursor
Expand All @@ -393,11 +475,11 @@ export class State {

const allFungibles = await exhaustPaginationWithLedgerState(
(cursor) =>
this.getEntityFungiblesPageVaultAggregated(
stateEntityDetails.address,
cursor,
ledgerState
),
this.getEntityFungiblesPageVaultAggregated(stateEntityDetails.address, {
nextCursor: cursor,
ledgerState,
explicitMetadata: options?.explicitMetadata,
}),
nextCursor
)

Expand All @@ -412,26 +494,74 @@ export class State {
})
}

private ensureResourcesProperties(
response: StateEntityDetailsResponse
): ReplaceProperty<
StateEntityDetailsResponse,
'items',
StateEntityDetailsVaultResponseItem[]
> {
return {
...response,
items: response.items.map((item) => ({
...item,
fungible_resources: item.fungible_resources || {
total_count: 0,
items: [],
private async queryAllNonFungibles(
stateEntityDetails: StateEntityDetailsVaultResponseItem,
options?: {
explicitMetadata?: string[]
nonFungibleIncludeNfids?: boolean
},
ledgerState?: LedgerStateSelector
): Promise<StateEntityDetailsVaultResponseItem> {
const nextCursor = stateEntityDetails.non_fungible_resources.next_cursor

if (!nextCursor) return Promise.resolve(stateEntityDetails)

const allNonFungibles = await exhaustPaginationWithLedgerState(
(cursor) =>
this.getEntityNonFungiblesPageVaultAggregated(
stateEntityDetails.address,
{
cursor,
ledgerState,
explicitMetadata: options?.explicitMetadata,
nonFungibleIncludeNfids: options?.nonFungibleIncludeNfids,
}
),
nextCursor
)

return Promise.resolve({
...stateEntityDetails,
non_fungible_resources: {
items: [
...stateEntityDetails.non_fungible_resources.items,
...allNonFungibles.aggregatedEntities,
],
},
})
}

private async queryAllResources(
stateEntityDetails: StateEntityDetailsVaultResponseItem,
options?: {
explicitMetadata?: string[]
nonFungibleIncludeNfids?: boolean
},
ledgerState?: LedgerStateSelector
): Promise<StateEntityDetailsVaultResponseItem> {
const itemsWithAllFungibles = this.queryAllFungibles(
stateEntityDetails,
options,
ledgerState
)
const itemsWithAllNonFungibles = this.queryAllNonFungibles(
stateEntityDetails,
options,
ledgerState
)

return Promise.all([itemsWithAllFungibles, itemsWithAllNonFungibles]).then(
(results) => ({
...stateEntityDetails,
fungible_resources: {
...stateEntityDetails.fungible_resources,
items: [...results[0].fungible_resources.items],
},
non_fungible_resources: item.non_fungible_resources || {
total_count: 0,
items: [],
non_fungible_resources: {
...stateEntityDetails.non_fungible_resources,
items: [...results[1].non_fungible_resources.items],
},
})) as StateEntityDetailsVaultResponseItem[],
}
})
)
}
}
Loading

0 comments on commit 133e7f1

Please sign in to comment.