@odatano/core 2.0.0-rc.48 → 2.0.0-rc.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoIndexerService/index.d.ts +32 -0
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/package.json +1 -1
- package/srv/blockchain/backends/cardano-backend.d.ts +6 -0
- package/srv/blockchain/backends/cardano-backend.js +5 -0
- package/srv/blockchain/backends/koios-backend.d.ts +4 -2
- package/srv/blockchain/backends/koios-backend.js +25 -0
- package/srv/blockchain/cardano-client.d.ts +3 -1
- package/srv/blockchain/cardano-client.js +9 -0
- package/srv/blockchain/cardano-indexer.d.ts +3 -0
- package/srv/blockchain/cardano-indexer.js +7 -1
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +21 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +63 -0
- package/srv/cardano-indexer-service.cds +20 -0
- package/srv/cardano-indexer-service.js +25 -0
|
@@ -12,6 +12,7 @@ export default class {
|
|
|
12
12
|
static readonly backfillTransactions: typeof backfillTransactions;
|
|
13
13
|
static readonly backfillPaymentCredentials: typeof backfillPaymentCredentials;
|
|
14
14
|
static readonly backfillAssetDecimals: typeof backfillAssetDecimals;
|
|
15
|
+
static readonly backfillAssetRegistry: typeof backfillAssetRegistry;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
// entity 'SyncState'
|
|
@@ -93,6 +94,7 @@ export declare function _CrawlerStatusAspect<TBase extends new (...args: any[])
|
|
|
93
94
|
transactionBackfill?: TransactionBackfillStatus | null
|
|
94
95
|
credentialBackfill?: CredentialBackfillStatus | null
|
|
95
96
|
decimalsBackfill?: DecimalsBackfillStatus | null
|
|
97
|
+
registryBackfill?: RegistryBackfillStatus | null
|
|
96
98
|
epochSnapshots?: EpochSnapshotStatus | null
|
|
97
99
|
} & InstanceType<TBase>
|
|
98
100
|
readonly kind: 'type';
|
|
@@ -207,6 +209,26 @@ export declare function _DecimalsBackfillStatusAspect<TBase extends new (...args
|
|
|
207
209
|
export class DecimalsBackfillStatus extends _DecimalsBackfillStatusAspect(__.Entity) {
|
|
208
210
|
}
|
|
209
211
|
|
|
212
|
+
// entity 'RegistryBackfillStatus'
|
|
213
|
+
export declare function _RegistryBackfillStatusAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
|
|
214
|
+
new (...args: any[]): {
|
|
215
|
+
status?: string | null
|
|
216
|
+
units?: number | null
|
|
217
|
+
processed?: number | null
|
|
218
|
+
filled?: number | null
|
|
219
|
+
failed?: number | null
|
|
220
|
+
startedAt?: __.CdsTimestamp | null
|
|
221
|
+
finishedAt?: __.CdsTimestamp | null
|
|
222
|
+
error?: string | null
|
|
223
|
+
} & InstanceType<TBase>
|
|
224
|
+
readonly kind: 'type';
|
|
225
|
+
readonly keys: __.KeysOf<RegistryBackfillStatus>;
|
|
226
|
+
readonly elements: __.ElementsOf<RegistryBackfillStatus>;
|
|
227
|
+
readonly actions: globalThis.Record<never, never>;
|
|
228
|
+
};
|
|
229
|
+
export class RegistryBackfillStatus extends _RegistryBackfillStatusAspect(__.Entity) {
|
|
230
|
+
}
|
|
231
|
+
|
|
210
232
|
// entity 'BackfillResult'
|
|
211
233
|
export declare function _BackfillResultAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
|
|
212
234
|
new (...args: any[]): {
|
|
@@ -394,4 +416,14 @@ export declare const backfillAssetDecimals: {
|
|
|
394
416
|
// metadata (do not use)
|
|
395
417
|
__parameters: globalThis.Record<never, never>, __returns: globalThis.Promise<BackfillResult | null> | BackfillResult | null, __self: never
|
|
396
418
|
kind: 'action'
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export declare const backfillAssetRegistry: {
|
|
422
|
+
// positional
|
|
423
|
+
(): globalThis.Promise<BackfillResult | null> | BackfillResult | null
|
|
424
|
+
// named
|
|
425
|
+
({}: globalThis.Record<never, never>): globalThis.Promise<BackfillResult | null> | BackfillResult | null
|
|
426
|
+
// metadata (do not use)
|
|
427
|
+
__parameters: globalThis.Record<never, never>, __returns: globalThis.Promise<BackfillResult | null> | BackfillResult | null, __self: never
|
|
428
|
+
kind: 'action'
|
|
397
429
|
}
|
|
@@ -28,6 +28,9 @@ module.exports.__Array_CredentialBackfillStatus_ = createEntityProxy(['CardanoIn
|
|
|
28
28
|
// DecimalsBackfillStatus
|
|
29
29
|
module.exports.DecimalsBackfillStatus = createEntityProxy(['CardanoIndexerService', 'DecimalsBackfillStatus'], { target: { is_singular: true } })
|
|
30
30
|
module.exports.__Array_DecimalsBackfillStatus_ = createEntityProxy(['CardanoIndexerService', 'DecimalsBackfillStatus'], { target: { is_singular: false }})
|
|
31
|
+
// RegistryBackfillStatus
|
|
32
|
+
module.exports.RegistryBackfillStatus = createEntityProxy(['CardanoIndexerService', 'RegistryBackfillStatus'], { target: { is_singular: true } })
|
|
33
|
+
module.exports.__Array_RegistryBackfillStatus_ = createEntityProxy(['CardanoIndexerService', 'RegistryBackfillStatus'], { target: { is_singular: false }})
|
|
31
34
|
// BackfillResult
|
|
32
35
|
module.exports.BackfillResult = createEntityProxy(['CardanoIndexerService', 'BackfillResult'], { target: { is_singular: true } })
|
|
33
36
|
module.exports.__Array_BackfillResult_ = createEntityProxy(['CardanoIndexerService', 'BackfillResult'], { target: { is_singular: false }})
|
|
@@ -56,4 +59,5 @@ module.exports.backfillCertificates = 'backfillCertificates'
|
|
|
56
59
|
module.exports.backfillTransactions = 'backfillTransactions'
|
|
57
60
|
module.exports.backfillPaymentCredentials = 'backfillPaymentCredentials'
|
|
58
61
|
module.exports.backfillAssetDecimals = 'backfillAssetDecimals'
|
|
62
|
+
module.exports.backfillAssetRegistry = 'backfillAssetRegistry'
|
|
59
63
|
// enums
|
package/package.json
CHANGED
|
@@ -133,6 +133,12 @@ export interface EpochStateBackend extends CardanoBackend {
|
|
|
133
133
|
}
|
|
134
134
|
/** Type guard: can this backend read epoch state at a block? */
|
|
135
135
|
export declare function isEpochStateBackend(backend: CardanoBackend): backend is EpochStateBackend;
|
|
136
|
+
export interface TokenRegistryBackend extends CardanoBackend {
|
|
137
|
+
/** Units (policyId + assetNameHex) that have a registry entry. */
|
|
138
|
+
getTokenRegistryUnits(): Promise<string[]>;
|
|
139
|
+
}
|
|
140
|
+
/** Type guard: can this backend list the token registry? */
|
|
141
|
+
export declare function isTokenRegistryBackend(backend: CardanoBackend): backend is TokenRegistryBackend;
|
|
136
142
|
/** Type guard: can this backend enumerate pools and DReps? */
|
|
137
143
|
export declare function isEnumeratingBackend(backend: CardanoBackend): backend is EnumeratingBackend;
|
|
138
144
|
//# sourceMappingURL=cardano-backend.d.ts.map
|
|
@@ -5,6 +5,7 @@ exports.isChainSyncBackend = isChainSyncBackend;
|
|
|
5
5
|
exports.isLedgerStateBackend = isLedgerStateBackend;
|
|
6
6
|
exports.isPaginatingBackend = isPaginatingBackend;
|
|
7
7
|
exports.isEpochStateBackend = isEpochStateBackend;
|
|
8
|
+
exports.isTokenRegistryBackend = isTokenRegistryBackend;
|
|
8
9
|
exports.isEnumeratingBackend = isEnumeratingBackend;
|
|
9
10
|
/** Type guard: does this backend support transaction evaluation? */
|
|
10
11
|
function isEvaluatingBackend(backend) {
|
|
@@ -28,6 +29,10 @@ function isPaginatingBackend(backend) {
|
|
|
28
29
|
function isEpochStateBackend(backend) {
|
|
29
30
|
return typeof backend.epochStateAt === 'function';
|
|
30
31
|
}
|
|
32
|
+
/** Type guard: can this backend list the token registry? */
|
|
33
|
+
function isTokenRegistryBackend(backend) {
|
|
34
|
+
return typeof backend.getTokenRegistryUnits === 'function';
|
|
35
|
+
}
|
|
31
36
|
/** Type guard: can this backend enumerate pools and DReps? */
|
|
32
37
|
function isEnumeratingBackend(backend) {
|
|
33
38
|
const b = backend;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CardanoBackend, PaginatingBackend, EnumeratingBackend } from './cardano-backend';
|
|
1
|
+
import { CardanoBackend, PaginatingBackend, EnumeratingBackend, TokenRegistryBackend } from './cardano-backend';
|
|
2
2
|
import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters, TxCertificate } from '../../utils/types';
|
|
3
3
|
import { Network } from '../cardano-client';
|
|
4
4
|
/** Shape of a Koios tx-in/tx-out row from /tx_info */
|
|
@@ -60,7 +60,7 @@ interface KoiosTxInfo {
|
|
|
60
60
|
}> | null;
|
|
61
61
|
}
|
|
62
62
|
/** CardanoBackend implementation on the Koios REST API (Axios). */
|
|
63
|
-
export declare class KoiosBackend implements CardanoBackend, PaginatingBackend, EnumeratingBackend {
|
|
63
|
+
export declare class KoiosBackend implements CardanoBackend, PaginatingBackend, EnumeratingBackend, TokenRegistryBackend {
|
|
64
64
|
readonly name = "koios";
|
|
65
65
|
private api;
|
|
66
66
|
private network;
|
|
@@ -120,6 +120,8 @@ export declare class KoiosBackend implements CardanoBackend, PaginatingBackend,
|
|
|
120
120
|
private static readonly LIST_MAX_PAGES;
|
|
121
121
|
/** Pages through a PostgREST list endpoint for one id column. Stops on the first short page. */
|
|
122
122
|
private listAllIds;
|
|
123
|
+
/** Units with a CIP-26 registry entry, from `asset_token_registry` (the whole registry, paged). */
|
|
124
|
+
getTokenRegistryUnits(): Promise<string[]>;
|
|
123
125
|
/** All pool ids, including retired ones, so a snapshot does not drop retiring pools. */
|
|
124
126
|
getPoolIds(): Promise<string[]>;
|
|
125
127
|
/** Resolve pool ids in batches. Ids Koios does not return are omitted, never filled with empty rows. */
|
|
@@ -871,6 +871,31 @@ class KoiosBackend {
|
|
|
871
871
|
logger.warn(`${label}: stopped after ${KoiosBackend.LIST_MAX_PAGES} pages, the list may be truncated`);
|
|
872
872
|
return ids;
|
|
873
873
|
}
|
|
874
|
+
/** Units with a CIP-26 registry entry, from `asset_token_registry` (the whole registry, paged). */
|
|
875
|
+
async getTokenRegistryUnits() {
|
|
876
|
+
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
877
|
+
const units = [];
|
|
878
|
+
for (let page = 0; page < KoiosBackend.LIST_MAX_PAGES; page++) {
|
|
879
|
+
const offset = page * KoiosBackend.LIST_PAGE_SIZE;
|
|
880
|
+
const { data } = await this.getWithRetryOn42804(`/asset_token_registry?select=policy_id,asset_name&limit=${KoiosBackend.LIST_PAGE_SIZE}&offset=${offset}`, {}, 'getTokenRegistryUnits');
|
|
881
|
+
if (!Array.isArray(data) || data.length === 0)
|
|
882
|
+
return units;
|
|
883
|
+
for (const row of data) {
|
|
884
|
+
const r = row;
|
|
885
|
+
if (typeof r.policy_id !== 'string' || !/^[0-9a-f]{56}$/i.test(r.policy_id))
|
|
886
|
+
continue;
|
|
887
|
+
const name = typeof r.asset_name === 'string' ? r.asset_name : '';
|
|
888
|
+
if (!/^([0-9a-f]{2}){0,32}$/i.test(name))
|
|
889
|
+
continue;
|
|
890
|
+
units.push((r.policy_id + name).toLowerCase());
|
|
891
|
+
}
|
|
892
|
+
if (data.length < KoiosBackend.LIST_PAGE_SIZE)
|
|
893
|
+
return units;
|
|
894
|
+
}
|
|
895
|
+
logger.warn(`getTokenRegistryUnits: stopped after ${KoiosBackend.LIST_MAX_PAGES} pages, the list may be truncated`);
|
|
896
|
+
return units;
|
|
897
|
+
}, this.name);
|
|
898
|
+
}
|
|
874
899
|
/** All pool ids, including retired ones, so a snapshot does not drop retiring pools. */
|
|
875
900
|
async getPoolIds() {
|
|
876
901
|
return (0, backend_request_handler_1.handleBackendRequest)(() => this.listAllIds('/pool_list', 'pool_id_bech32', 'getPoolIds'), this.name);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainSyncBackend, PaginatingBackend, EnumeratingBackend, LedgerStateBackend, EpochStateBackend } from './backends/cardano-backend';
|
|
1
|
+
import { ChainSyncBackend, PaginatingBackend, EnumeratingBackend, LedgerStateBackend, EpochStateBackend, TokenRegistryBackend } from './backends/cardano-backend';
|
|
2
2
|
import { PendingSpends } from './pending-spends';
|
|
3
3
|
import { type CircuitBreakerConfig } from './circuit-breaker';
|
|
4
4
|
import { Transaction, Address, UTxO, NetworkInformation, BlockData, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters, ScriptEvaluationResult } from '../utils/types';
|
|
@@ -107,6 +107,8 @@ export declare class CardanoClient {
|
|
|
107
107
|
getEpochStateBackend(): EpochStateBackend | null;
|
|
108
108
|
/** Without one, epoch snapshots stay off instead of making thousands of single requests. */
|
|
109
109
|
getEnumeratingBackend(): EnumeratingBackend | null;
|
|
110
|
+
/** Backend that lists the CIP-26 token registry (Koios). Null when none is configured. */
|
|
111
|
+
getTokenRegistryBackend(): TokenRegistryBackend | null;
|
|
110
112
|
/** Prefers Koios, because it batches 100 txs per call and Blockfrost needs about 3 calls per tx. */
|
|
111
113
|
getPaginatingBackend(): PaginatingBackend | null;
|
|
112
114
|
/** Protocol parameters with a 5-minute in-memory cache and coalesced refresh. */
|
|
@@ -487,6 +487,15 @@ class CardanoClient {
|
|
|
487
487
|
}
|
|
488
488
|
return null;
|
|
489
489
|
}
|
|
490
|
+
/** Backend that lists the CIP-26 token registry (Koios). Null when none is configured. */
|
|
491
|
+
getTokenRegistryBackend() {
|
|
492
|
+
const candidates = [...this.historicalBackends, this.liveBackend];
|
|
493
|
+
for (const b of candidates) {
|
|
494
|
+
if (b && !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isTokenRegistryBackend)(b))
|
|
495
|
+
return b;
|
|
496
|
+
}
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
490
499
|
/** Prefers Koios, because it batches 100 txs per call and Blockfrost needs about 3 calls per tx. */
|
|
491
500
|
getPaginatingBackend() {
|
|
492
501
|
const usable = this.historicalBackends.filter((b) => !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isPaginatingBackend)(b));
|
|
@@ -173,6 +173,9 @@ export declare class CardanoIndexer {
|
|
|
173
173
|
resolvePool(tx: CapTransaction, poolId: string): Promise<PoolData>;
|
|
174
174
|
/** Index an asset by unit (policyId + assetNameHex). */
|
|
175
175
|
indexAsset(tx: CapTransaction, unit: string): Promise<Asset>;
|
|
176
|
+
/** Like indexAsset, but always from the backend: the crawled chain has no CIP-26 registry fields. */
|
|
177
|
+
indexAssetFromBackend(tx: CapTransaction, unit: string): Promise<Asset>;
|
|
178
|
+
private writeAsset;
|
|
176
179
|
/** Always fresh. Rows are keyed by unit and tx, so older cached entries persist. */
|
|
177
180
|
indexAssetHistory(tx: CapTransaction, unit: string, limit?: number): Promise<AssetHistory[]>;
|
|
178
181
|
/** Build a transaction and persist the build result with inputs/outputs/address association. */
|
|
@@ -1488,7 +1488,13 @@ class CardanoIndexer {
|
|
|
1488
1488
|
}
|
|
1489
1489
|
/** Index an asset by unit (policyId + assetNameHex). */
|
|
1490
1490
|
async indexAsset(tx, unit) {
|
|
1491
|
-
|
|
1491
|
+
return this.writeAsset(tx, unit, await this.resolveAssetInfo(tx, unit));
|
|
1492
|
+
}
|
|
1493
|
+
/** Like indexAsset, but always from the backend: the crawled chain has no CIP-26 registry fields. */
|
|
1494
|
+
async indexAssetFromBackend(tx, unit) {
|
|
1495
|
+
return this.writeAsset(tx, unit, await this.client.getAssetInfo(unit));
|
|
1496
|
+
}
|
|
1497
|
+
async writeAsset(tx, unit, assetInfo) {
|
|
1492
1498
|
const assetEntity = (0, mappers_1.mapAsset)(assetInfo, this.client.max_age_ms);
|
|
1493
1499
|
assetEntity.decimals = (await (0, asset_decimals_1.cip68Decimals)(tx, unit, assetInfo.initialMintTxHash)) ?? assetInfo.registryDecimals;
|
|
1494
1500
|
await tx.run(UPSERT.into(CardanoODataService_1.Assets).entries(assetEntity));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CardanoClient } from '../cardano-client';
|
|
2
|
+
import type { CardanoIndexer } from '../cardano-indexer';
|
|
3
|
+
export interface RegistryBackfillProgress {
|
|
4
|
+
/** Units with a CIP-26 registry entry. */
|
|
5
|
+
units: number;
|
|
6
|
+
/** Units handled so far, filled or failed. */
|
|
7
|
+
processed: number;
|
|
8
|
+
/** Units whose Assets rows received the registry values. */
|
|
9
|
+
filled: number;
|
|
10
|
+
/** Units the backend did not resolve. */
|
|
11
|
+
failed: number;
|
|
12
|
+
}
|
|
13
|
+
export interface RegistryBackfillOptions {
|
|
14
|
+
client: CardanoClient;
|
|
15
|
+
indexer: CardanoIndexer;
|
|
16
|
+
/** Backend calls per second; one unit is one call. */
|
|
17
|
+
unitsPerSecond?: number;
|
|
18
|
+
onProgress?: (p: RegistryBackfillProgress) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare function backfillAssetRegistry(opts: RegistryBackfillOptions): Promise<RegistryBackfillProgress>;
|
|
21
|
+
//# sourceMappingURL=asset-registry-backfill.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.backfillAssetRegistry = backfillAssetRegistry;
|
|
7
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
8
|
+
const cardano_1 = require("#cds-models/odatano/cardano");
|
|
9
|
+
const errors_1 = require("../../utils/errors");
|
|
10
|
+
const { UPDATE } = cds_1.default.ql;
|
|
11
|
+
const logger = cds_1.default.log('RegistryBackfill');
|
|
12
|
+
/** The run stops when this many units in a row fail: the backend is down, not the units. */
|
|
13
|
+
const MAX_CONSECUTIVE_FAILURES = 25;
|
|
14
|
+
// Fill the CIP-26 registry fields of every Assets slice for the units the registry lists. The
|
|
15
|
+
// registry is off-chain, so each unit is read from the backend; a repeat run refreshes the values.
|
|
16
|
+
async function backfillAssetRegistry(opts) {
|
|
17
|
+
const backend = opts.client.getTokenRegistryBackend();
|
|
18
|
+
if (!backend)
|
|
19
|
+
throw new errors_1.ProviderUnavailableError('No backend lists the token registry (needs Koios)');
|
|
20
|
+
const units = await backend.getTokenRegistryUnits();
|
|
21
|
+
const intervalMs = 1000 / Math.max(1, opts.unitsPerSecond ?? 4);
|
|
22
|
+
const progress = { units: units.length, processed: 0, filled: 0, failed: 0 };
|
|
23
|
+
let consecutiveFailures = 0;
|
|
24
|
+
for (const unit of units) {
|
|
25
|
+
const started = Date.now();
|
|
26
|
+
try {
|
|
27
|
+
await cds_1.default.tx(async (tx) => {
|
|
28
|
+
const row = await opts.indexer.indexAssetFromBackend(tx, unit);
|
|
29
|
+
// Every slice of the unit carries the registry values, the bare catalogue row included.
|
|
30
|
+
await tx.run(UPDATE.entity(cardano_1.Assets).set({
|
|
31
|
+
registryName: row.registryName ?? null,
|
|
32
|
+
registryTicker: row.registryTicker ?? null,
|
|
33
|
+
registryDecimals: row.registryDecimals ?? null,
|
|
34
|
+
registryDescription: row.registryDescription ?? null,
|
|
35
|
+
registryUrl: row.registryUrl ?? null,
|
|
36
|
+
registryLogo: row.registryLogo ?? null,
|
|
37
|
+
}).where({ unit }));
|
|
38
|
+
if (row.decimals != null) {
|
|
39
|
+
await tx.run(UPDATE.entity(cardano_1.Assets).set({ decimals: row.decimals }).where({ unit, decimals: null }));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
progress.filled++;
|
|
43
|
+
consecutiveFailures = 0;
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
progress.failed++;
|
|
47
|
+
consecutiveFailures++;
|
|
48
|
+
logger.debug(`registry fill for ${unit} failed:`, err);
|
|
49
|
+
if (!(err instanceof errors_1.NotFoundError) && consecutiveFailures >= MAX_CONSECUTIVE_FAILURES) {
|
|
50
|
+
const last = err instanceof Error ? err.message : String(err);
|
|
51
|
+
throw new errors_1.ProviderUnavailableError(`${consecutiveFailures} units in a row failed, last: ${last}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
progress.processed++;
|
|
55
|
+
opts.onProgress?.({ ...progress });
|
|
56
|
+
const wait = intervalMs - (Date.now() - started);
|
|
57
|
+
if (wait > 0)
|
|
58
|
+
await new Promise((r) => setTimeout(r, wait));
|
|
59
|
+
}
|
|
60
|
+
logger.info(`asset registry filled: ${progress.filled} of ${progress.units} registered units, ${progress.failed} failed`);
|
|
61
|
+
return progress;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=asset-registry-backfill.js.map
|
|
@@ -44,6 +44,8 @@ service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
|
44
44
|
credentialBackfill : CredentialBackfillStatus;
|
|
45
45
|
// one-off CIP-68 decimals fill of the asset catalogue (this process)
|
|
46
46
|
decimalsBackfill : DecimalsBackfillStatus;
|
|
47
|
+
// one-off CIP-26 registry fill of the asset catalogue (this process)
|
|
48
|
+
registryBackfill : RegistryBackfillStatus;
|
|
47
49
|
// per-epoch pool/DRep/pot snapshots (crawler.epochSnapshots)
|
|
48
50
|
epochSnapshots : EpochSnapshotStatus;
|
|
49
51
|
}
|
|
@@ -117,6 +119,19 @@ service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
|
117
119
|
error : String;
|
|
118
120
|
}
|
|
119
121
|
|
|
122
|
+
@title : 'Registry Backfill Status'
|
|
123
|
+
@description: 'Progress of the CIP-26 registry fill started with backfillAssetRegistry; process-local, none after a restart'
|
|
124
|
+
type RegistryBackfillStatus {
|
|
125
|
+
status : String; // none | running | done | failed
|
|
126
|
+
units : Integer64; // units with a registry entry
|
|
127
|
+
processed : Integer64; // units handled so far
|
|
128
|
+
filled : Integer64; // units whose rows received the registry values
|
|
129
|
+
failed : Integer64; // units the backend did not resolve
|
|
130
|
+
startedAt : Timestamp;
|
|
131
|
+
finishedAt : Timestamp;
|
|
132
|
+
error : String;
|
|
133
|
+
}
|
|
134
|
+
|
|
120
135
|
@title : 'Backfill Result'
|
|
121
136
|
type BackfillResult {
|
|
122
137
|
accepted : Boolean;
|
|
@@ -223,4 +238,9 @@ service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
|
223
238
|
@description: 'Fill Assets.decimals from the CIP-68 reference datum for every catalogue unit with label 333 or 444: the reference NFT is followed from its mint through the crawled transactions to the output that holds it now, and the decimals of that datum are written to every slice of the unit. No backend call; the crawler may keep running; a repeat refreshes the values. Runs in the background; progress via getStatus().decimalsBackfill.'
|
|
224
239
|
@requires : 'Admin'
|
|
225
240
|
action backfillAssetDecimals() returns BackfillResult;
|
|
241
|
+
|
|
242
|
+
@title : 'Backfill Asset Registry'
|
|
243
|
+
@description: 'Fill the CIP-26 registry fields (registryName, registryTicker, registryDecimals, registryDescription, registryUrl, registryLogo) on every slice of every Assets unit the token registry lists, and decimals where it is still empty. The registry is off-chain, so each unit is read from the backend (needs Koios), rate limited; the crawler may keep running; a repeat refreshes the values. Runs in the background; progress via getStatus().registryBackfill.'
|
|
244
|
+
@requires : 'Admin'
|
|
245
|
+
action backfillAssetRegistry() returns BackfillResult;
|
|
226
246
|
}
|
|
@@ -15,6 +15,7 @@ const certificate_backfill_1 = require("./blockchain/crawler/certificate-backfil
|
|
|
15
15
|
const transaction_backfill_1 = require("./blockchain/crawler/transaction-backfill");
|
|
16
16
|
const credential_backfill_1 = require("./blockchain/crawler/credential-backfill");
|
|
17
17
|
const asset_decimals_backfill_1 = require("./blockchain/crawler/asset-decimals-backfill");
|
|
18
|
+
const asset_registry_backfill_1 = require("./blockchain/crawler/asset-registry-backfill");
|
|
18
19
|
const validators_1 = require("./utils/validators");
|
|
19
20
|
const server_1 = require("./server");
|
|
20
21
|
const liveness_1 = require("./utils/liveness");
|
|
@@ -40,6 +41,9 @@ let credentialBackfill = {
|
|
|
40
41
|
let decimalsBackfill = {
|
|
41
42
|
status: 'none', scanned: 0, candidates: 0, filled: 0, startedAt: null, finishedAt: null, error: null,
|
|
42
43
|
};
|
|
44
|
+
let registryBackfill = {
|
|
45
|
+
status: 'none', units: 0, processed: 0, filled: 0, failed: 0, startedAt: null, finishedAt: null, error: null,
|
|
46
|
+
};
|
|
43
47
|
/** Slot range of a backfill: defaults to crawl start .. cursor, never past the cursor. */
|
|
44
48
|
async function backfillRange(db, data) {
|
|
45
49
|
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
@@ -151,6 +155,7 @@ module.exports = (srv) => {
|
|
|
151
155
|
},
|
|
152
156
|
credentialBackfill: { ...credentialBackfill },
|
|
153
157
|
decimalsBackfill: { ...decimalsBackfill },
|
|
158
|
+
registryBackfill: { ...registryBackfill },
|
|
154
159
|
epochSnapshots: {
|
|
155
160
|
enabled: epochSnapshotsConfigured(),
|
|
156
161
|
source: epochSnapshotSource(),
|
|
@@ -287,6 +292,26 @@ module.exports = (srv) => {
|
|
|
287
292
|
});
|
|
288
293
|
return { accepted: true, message: 'Asset-decimals backfill started; poll getStatus().decimalsBackfill.' };
|
|
289
294
|
});
|
|
295
|
+
// backfillAssetRegistry: writes the CIP-26 registry fields of every registered unit. The registry
|
|
296
|
+
// is off-chain, so this needs a backend that lists it. Progress is in getStatus().registryBackfill.
|
|
297
|
+
srv.on('backfillAssetRegistry', async (req) => {
|
|
298
|
+
if (registryBackfill.status === 'running')
|
|
299
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillAssetRegistry', 'An asset-registry backfill is already running');
|
|
300
|
+
if (!(0, server_1.getCardanoClient)().getTokenRegistryBackend())
|
|
301
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillAssetRegistry', 'No backend lists the token registry (needs Koios)');
|
|
302
|
+
registryBackfill = { status: 'running', units: 0, processed: 0, filled: 0, failed: 0, startedAt: new Date().toISOString(), finishedAt: null, error: null };
|
|
303
|
+
void (0, asset_registry_backfill_1.backfillAssetRegistry)({
|
|
304
|
+
client: (0, server_1.getCardanoClient)(), indexer: (0, server_1.getCardanoIndexer)(),
|
|
305
|
+
onProgress: (p) => { Object.assign(registryBackfill, p); },
|
|
306
|
+
})
|
|
307
|
+
.then((r) => { Object.assign(registryBackfill, r, { status: 'done', finishedAt: new Date().toISOString() }); })
|
|
308
|
+
.catch((err) => {
|
|
309
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
310
|
+
Object.assign(registryBackfill, { status: 'failed', finishedAt: new Date().toISOString(), error: message.slice(0, 500) });
|
|
311
|
+
logger.error(`Asset-registry backfill failed: ${message}`);
|
|
312
|
+
});
|
|
313
|
+
return { accepted: true, message: 'Asset-registry backfill started; poll getStatus().registryBackfill.' };
|
|
314
|
+
});
|
|
290
315
|
// importUtxoSet: one-off snapshot import that anchors crawler.utxoSet.
|
|
291
316
|
// Runs detached. Progress is in getStatus().utxoSet.
|
|
292
317
|
srv.on('importUtxoSet', async (req) => {
|