@odatano/core 1.8.0 → 1.9.0
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/CardanoODataService/index.d.ts +66 -42
- package/@cds-models/CardanoODataService/index.d.ts.map +1 -1
- package/@cds-models/CardanoODataService/index.js.map +1 -1
- package/@cds-models/CardanoODataService/index.ts +11 -7
- package/@cds-models/odatano/cardano/index.d.ts +70 -46
- package/@cds-models/odatano/cardano/index.d.ts.map +1 -1
- package/@cds-models/odatano/cardano/index.js +2 -2
- package/@cds-models/odatano/cardano/index.js.map +1 -1
- package/@cds-models/odatano/cardano/index.ts +13 -13
- package/db/schema.cds +18 -18
- package/db/types.cds +3 -3
- package/package.json +17 -2
- package/src/index.d.ts +29 -0
- package/src/index.js +1 -0
- package/src/plugin.d.ts +2 -0
- package/src/plugin.js +6 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +155 -0
- package/srv/blockchain/backends/blockfrost-backend.js +19 -8
- package/srv/blockchain/backends/cardano-backend.d.ts +182 -0
- package/srv/blockchain/backends/koios-backend.d.ts +171 -0
- package/srv/blockchain/backends/koios-backend.js +69 -27
- package/srv/blockchain/backends/ogmios-backend.d.ts +188 -0
- package/srv/blockchain/backends/ogmios-backend.js +175 -108
- package/srv/blockchain/cardano-client.d.ts +279 -0
- package/srv/blockchain/cardano-client.js +134 -33
- package/srv/blockchain/cardano-indexer.d.ts +330 -0
- package/srv/blockchain/cardano-indexer.js +51 -8
- package/srv/blockchain/cardano-tx-builder.d.ts +113 -0
- package/srv/blockchain/cardano-tx-builder.js +61 -54
- package/srv/blockchain/circuit-breaker.d.ts +37 -0
- package/srv/blockchain/circuit-breaker.js +11 -2
- package/srv/blockchain/request-coalescer.d.ts +23 -0
- package/srv/blockchain/signing/external-signer.d.ts +146 -0
- package/srv/blockchain/signing/external-signer.js +23 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +74 -0
- package/srv/blockchain/signing/hsm-signer.js +20 -5
- package/srv/blockchain/signing/signature-verifier.d.ts +56 -0
- package/srv/blockchain/signing/signature-verifier.js +11 -2
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +236 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +626 -187
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +47 -0
- package/srv/cardano-service.cds +23 -3
- package/srv/cardano-service.d.ts +2 -0
- package/srv/cardano-service.js +25 -5
- package/srv/cardano-sign-service.d.ts +2 -0
- package/srv/cardano-sign-service.js +219 -131
- package/srv/cardano-tx-service.d.ts +12 -0
- package/srv/cardano-tx-service.js +152 -110
- package/srv/cbor/index.d.ts +2 -0
- package/srv/cbor/parse.d.ts +64 -0
- package/srv/server.d.ts +90 -0
- package/srv/server.js +27 -9
- package/srv/utils/backend-request-handler.d.ts +20 -0
- package/srv/utils/const.d.ts +183 -0
- package/srv/utils/const.js +13 -6
- package/srv/utils/error-codes.d.ts +79 -0
- package/srv/utils/errors.d.ts +259 -0
- package/srv/utils/errors.js +22 -7
- package/srv/utils/mappers.d.ts +260 -0
- package/srv/utils/mappers.js +34 -10
- package/srv/utils/plutus-placeholders.d.ts +35 -0
- package/srv/utils/plutus-placeholders.js +5 -15
- package/srv/utils/signing-helper.d.ts +23 -0
- package/srv/utils/signing-helper.js +5 -2
- package/srv/utils/tx-build-helper.d.ts +76 -0
- package/srv/utils/tx-build-helper.js +10 -37
- package/srv/utils/types.d.ts +653 -0
- package/srv/utils/validators.d.ts +145 -0
- package/srv/utils/validators.js +28 -1
- package/@cds-models/CardanoWatcherAdminService/index.js +0 -109
- package/@cds-models/CardanoWatcherAdminService/index.js.map +0 -1
- package/@cds-models/CardanoWatcherAdminService/index.ts +0 -263
- package/@cds-models/cds/outbox/index.js.map +0 -1
- package/@cds-models/cds/xt/MTXServices/index.js +0 -8
- package/@cds-models/cds/xt/MTXServices/index.js.map +0 -1
- package/@cds-models/cds/xt/MTXServices/index.ts +0 -4
- package/@cds-models/odatano/reeve/index.js +0 -77
- package/@cds-models/odatano/reeve/index.js.map +0 -1
- package/@cds-models/odatano/reeve/index.ts +0 -57
- package/@cds-models/odatano/transactions/index.js +0 -55
- package/@cds-models/odatano/transactions/index.js.map +0 -1
- package/@cds-models/odatano/transactions/index.ts +0 -18
- package/@cds-models/odatano/watch/index.js +0 -114
- package/@cds-models/odatano/watch/index.js.map +0 -1
- package/@cds-models/odatano/watch/index.ts +0 -110
- package/config/preview/cardano-node/alonzo-genesis.json +0 -196
- package/config/preview/cardano-node/byron-genesis.json +0 -117
- package/config/preview/cardano-node/config.json +0 -117
- package/config/preview/cardano-node/conway-genesis.json +0 -297
- package/config/preview/cardano-node/peer-snapshot.json +0 -890
- package/config/preview/cardano-node/shelley-genesis.json +0 -68
- package/config/preview/cardano-node/topology.json +0 -24
- package/output/sora/iter0_base.json +0 -32
- package/output/sora/iter0_base.mp4 +0 -0
- package/output/sora/logo_ref_1280x720.png +0 -0
- package/output/sora/odatano_full_logo_sky_ref_1280x720.png +0 -0
- package/output/sora/odatano_full_logo_transparent.png +0 -0
- package/output/sora/odatano_full_logo_transparent_dark.png +0 -0
- package/output/sora/odatano_full_logo_v4_8s.json +0 -32
- package/output/sora/odatano_full_logo_v4_8s.mp4 +0 -0
- package/output/sora/odatano_full_logo_v5_create.json +0 -15
- package/output/sora/odatano_full_logo_v5_fixes.json +0 -15
- package/output/sora/odatano_full_logo_v5_fixes.mp4 +0 -0
- package/output/sora/odatano_logo_v1.json +0 -32
- package/output/sora/odatano_logo_v1.mp4 +0 -0
- package/output/sora/odatano_o_only_clean.png +0 -0
- package/output/sora/odatano_o_sky_ref_1280x720.png +0 -0
- package/output/sora/odatano_o_sky_v2_8s.json +0 -32
- package/output/sora/odatano_o_sky_v2_8s.mp4 +0 -0
- package/output/sora/odatano_o_sky_v3_create.json +0 -15
- package/output/sora/odatano_o_sky_v3_splash_text.json +0 -15
- package/output/sora/odatano_o_sky_v3_splash_text.mp4 +0 -0
- package/output/sora/odatano_v6_composite_exact_logo.mp4 +0 -0
- package/output/sora/odatano_v6_composite_exact_logo_clean.mp4 +0 -0
- package/output/sora/odatano_v6_composite_exact_logo_final.mp4 +0 -0
- package/output/sora/odatano_v6_endframe.jpg +0 -0
- package/output/sora/odatano_v6_endframe_clean.jpg +0 -0
- package/output/sora/odatano_v6_endframe_final.jpg +0 -0
- package/output/sora/odatano_v7_1_earlylogo_fadeoldtext.mp4 +0 -0
- package/output/sora/odatano_v7_1_end.jpg +0 -0
- package/output/sora/odatano_v7_1_transition.jpg +0 -0
- package/output/sora/odatano_v7_2_original2d_keep_sky.mp4 +0 -0
- package/output/sora/odatano_v7_endframe_nobg.jpg +0 -0
- package/output/sora/odatano_v7_endframe_nobg_cleanend.jpg +0 -0
- package/output/sora/odatano_v7_spin_splash_logo_nobg.mp4 +0 -0
- package/output/sora/odatano_v7_spin_splash_logo_nobg_cleanend.mp4 +0 -0
- package/prod.mtaext +0 -17
- package/prod.mtaext.example +0 -27
- package/review.md +0 -42
- package/src/index.d.ts.map +0 -1
- package/src/index.js.map +0 -1
- package/src/plugin.d.ts.map +0 -1
- package/src/plugin.js.map +0 -1
- package/srv/blockchain/backends/blockfrost-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/blockfrost-backend.js.map +0 -1
- package/srv/blockchain/backends/cardano-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/cardano-backend.js.map +0 -1
- package/srv/blockchain/backends/koios-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/koios-backend.js.map +0 -1
- package/srv/blockchain/backends/ogmios-backend.d.ts.map +0 -1
- package/srv/blockchain/backends/ogmios-backend.js.map +0 -1
- package/srv/blockchain/cardano-client.d.ts.map +0 -1
- package/srv/blockchain/cardano-client.js.map +0 -1
- package/srv/blockchain/cardano-indexer.d.ts.map +0 -1
- package/srv/blockchain/cardano-indexer.js.map +0 -1
- package/srv/blockchain/cardano-tx-builder.d.ts.map +0 -1
- package/srv/blockchain/cardano-tx-builder.js.map +0 -1
- package/srv/blockchain/circuit-breaker.d.ts.map +0 -1
- package/srv/blockchain/circuit-breaker.js.map +0 -1
- package/srv/blockchain/request-coalescer.d.ts.map +0 -1
- package/srv/blockchain/request-coalescer.js.map +0 -1
- package/srv/blockchain/signing/external-signer.d.ts.map +0 -1
- package/srv/blockchain/signing/external-signer.js.map +0 -1
- package/srv/blockchain/signing/hsm-signer.d.ts.map +0 -1
- package/srv/blockchain/signing/hsm-signer.js.map +0 -1
- package/srv/blockchain/signing/signature-verifier.d.ts.map +0 -1
- package/srv/blockchain/signing/signature-verifier.js.map +0 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts.map +0 -1
- package/srv/blockchain/transaction-building/buildooor-tx.js.map +0 -1
- package/srv/blockchain/transaction-building/cardano-tx.d.ts.map +0 -1
- package/srv/blockchain/transaction-building/cardano-tx.js.map +0 -1
- package/srv/cardano-service.d.ts.map +0 -1
- package/srv/cardano-service.js.map +0 -1
- package/srv/cardano-sign-service.d.ts.map +0 -1
- package/srv/cardano-sign-service.js.map +0 -1
- package/srv/cardano-tx-service.d.ts.map +0 -1
- package/srv/cardano-tx-service.js.map +0 -1
- package/srv/cbor/index.d.ts.map +0 -1
- package/srv/cbor/index.js.map +0 -1
- package/srv/cbor/parse.d.ts.map +0 -1
- package/srv/cbor/parse.js.map +0 -1
- package/srv/server.d.ts.map +0 -1
- package/srv/server.js.map +0 -1
- package/srv/utils/backend-request-handler.d.ts.map +0 -1
- package/srv/utils/backend-request-handler.js.map +0 -1
- package/srv/utils/const.d.ts.map +0 -1
- package/srv/utils/const.js.map +0 -1
- package/srv/utils/error-codes.d.ts.map +0 -1
- package/srv/utils/error-codes.js.map +0 -1
- package/srv/utils/errors.d.ts.map +0 -1
- package/srv/utils/errors.js.map +0 -1
- package/srv/utils/mappers.d.ts.map +0 -1
- package/srv/utils/mappers.js.map +0 -1
- package/srv/utils/plutus-placeholders.d.ts.map +0 -1
- package/srv/utils/plutus-placeholders.js.map +0 -1
- package/srv/utils/signing-helper.d.ts.map +0 -1
- package/srv/utils/signing-helper.js.map +0 -1
- package/srv/utils/tx-build-helper.d.ts.map +0 -1
- package/srv/utils/tx-build-helper.js.map +0 -1
- package/srv/utils/types.d.ts.map +0 -1
- package/srv/utils/types.js.map +0 -1
- package/srv/utils/validators.d.ts.map +0 -1
- package/srv/utils/validators.js.map +0 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { CardanoBackend } from './cardano-backend';
|
|
2
|
+
import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters } from '../../utils/types';
|
|
3
|
+
import { Network } from '../cardano-client';
|
|
4
|
+
/**
|
|
5
|
+
* KoiosBackend Implementation for CardanoBackend Interface
|
|
6
|
+
* Implements the CardanoBackend interface using Koios API with Axios
|
|
7
|
+
*/
|
|
8
|
+
export declare class KoiosBackend implements CardanoBackend {
|
|
9
|
+
readonly name = "koios";
|
|
10
|
+
private api;
|
|
11
|
+
private network;
|
|
12
|
+
/**
|
|
13
|
+
* Constructor
|
|
14
|
+
*/
|
|
15
|
+
constructor(network: Network, timeoutMs: number, apiKey?: string);
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the backend
|
|
18
|
+
*/
|
|
19
|
+
init(): Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Retry a Koios API call up to 3 times with exponential backoff if the
|
|
22
|
+
* result is an empty array. Koios sometimes returns [] transiently for
|
|
23
|
+
* valid queries — a single retry is not always sufficient for historical
|
|
24
|
+
* epoch lookups, so we retry with increasing delays (500 → 1000 → 2000 ms).
|
|
25
|
+
*/
|
|
26
|
+
private fetchWithRetryOnEmpty;
|
|
27
|
+
/**
|
|
28
|
+
* Get Transaction Data for specified transaction hash
|
|
29
|
+
* @param hash transaction hash (hex)
|
|
30
|
+
* @returns {Promise<Transaction>} transaction data
|
|
31
|
+
*/
|
|
32
|
+
getTransaction(hash: string): Promise<Transaction>;
|
|
33
|
+
/**
|
|
34
|
+
* Get Block Data for specified block hash
|
|
35
|
+
* @param blockHash block hash (hex)
|
|
36
|
+
* @returns {Promise<BlockData>} block data
|
|
37
|
+
*/
|
|
38
|
+
getBlock(blockHash: string): Promise<BlockData>;
|
|
39
|
+
/**
|
|
40
|
+
* Get Epoch Data for specified epoch number
|
|
41
|
+
* @param epochNumber epoch number
|
|
42
|
+
* @returns {Promise<EpochData>} epoch data
|
|
43
|
+
*/
|
|
44
|
+
getEpoch(epochNumber: number): Promise<EpochData>;
|
|
45
|
+
/**
|
|
46
|
+
* Get Address Data (without transactions - use getAddressTransactions() separately)
|
|
47
|
+
* @param address bech32 address
|
|
48
|
+
* @returns {Promise<Address>} address data
|
|
49
|
+
*/
|
|
50
|
+
getAddress(address: string): Promise<Address>;
|
|
51
|
+
/**
|
|
52
|
+
* Get Address Transactions
|
|
53
|
+
* @param address bech32 address
|
|
54
|
+
* @returns {Promise<Transaction[]>} list of transactions for this address
|
|
55
|
+
*/
|
|
56
|
+
getAddressTransactions(address: string, limit: number): Promise<Transaction[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Get Address UTxOs for specified address
|
|
59
|
+
* @param address bech32 address
|
|
60
|
+
* @returns {Promise<UTxO[]>} list of UTxOs
|
|
61
|
+
*/
|
|
62
|
+
getAddressUtxos(address: string): Promise<UTxO[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Get UTxOs by payment credential. Returns UTxOs across all bech32 addresses
|
|
65
|
+
* sharing the given 28-byte payment credential (key hash or script hash).
|
|
66
|
+
* Native Koios endpoint — single round-trip with inline-datum hydration.
|
|
67
|
+
* @param credHash 28-byte payment credential as 56-char lowercase hex
|
|
68
|
+
* @returns {Promise<UTxO[]>} list of UTxOs across all bech32 forms
|
|
69
|
+
*/
|
|
70
|
+
getCredentialUtxos(credHash: string): Promise<UTxO[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Get Network Information
|
|
73
|
+
* @returns {Promise<Network>} network information
|
|
74
|
+
*/
|
|
75
|
+
getNetworkInformation(): Promise<NetworkInformation>;
|
|
76
|
+
/**
|
|
77
|
+
* Get Transaction Metadata for specified transaction hash
|
|
78
|
+
* @param tx_hash transaction hash (hex)
|
|
79
|
+
* @returns {Promise<MetadataLabelTx[]>} transaction metadata list
|
|
80
|
+
*/
|
|
81
|
+
getTransactionMetadata(tx_hash: string): Promise<MetadataLabelTx[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Get Pool Data for specified pool id
|
|
84
|
+
* @param poolId pool id
|
|
85
|
+
* @returns {Promise<PoolData>} pool data
|
|
86
|
+
*/
|
|
87
|
+
getPool(poolId: string): Promise<PoolData>;
|
|
88
|
+
/**
|
|
89
|
+
* Get Asset Info (supply, mint history, CIP-25 + CIP-26 metadata).
|
|
90
|
+
* Koios's `asset_info` returns total_supply, mint/burn counts split,
|
|
91
|
+
* minting tx + creation_time, and both on-chain and registry metadata.
|
|
92
|
+
* @param unit policyId + assetNameHex (concatenated hex)
|
|
93
|
+
* @returns {Promise<AssetInfo>} canonical asset info
|
|
94
|
+
*/
|
|
95
|
+
getAssetInfo(unit: string): Promise<AssetInfo>;
|
|
96
|
+
/**
|
|
97
|
+
* Get latest mint/burn events for an asset.
|
|
98
|
+
* Koios's `asset_history` returns minting_txs[{ tx_hash, block_time, quantity }]
|
|
99
|
+
* with `quantity` SIGNED (negative = burn). Action is derived from sign;
|
|
100
|
+
* the canonical `quantity` field stores absolute value.
|
|
101
|
+
* @param unit policyId + assetNameHex (concatenated hex)
|
|
102
|
+
* @param limit max number of events (default 100). Note: Koios returns ALL events;
|
|
103
|
+
* limit is applied client-side after sort-by-block_time desc.
|
|
104
|
+
* @returns {Promise<AssetHistoryEntry[]>} list of mint/burn events (most recent first)
|
|
105
|
+
*/
|
|
106
|
+
getAssetHistory(unit: string, limit?: number): Promise<AssetHistoryEntry[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Get Drep Data for specified drep id
|
|
109
|
+
* @param drepId drep id
|
|
110
|
+
* @returns {Promise<DrepData>} drep data
|
|
111
|
+
*/
|
|
112
|
+
getDrep(drepId: string): Promise<DrepData>;
|
|
113
|
+
/**
|
|
114
|
+
* Get Account Data for specified stake address
|
|
115
|
+
* @param accountId account id
|
|
116
|
+
* @returns {Promise<AccountData>} account data
|
|
117
|
+
*/
|
|
118
|
+
getAccount(accountId: string): Promise<AccountData>;
|
|
119
|
+
/**
|
|
120
|
+
* Submit Transaction
|
|
121
|
+
* @param signedTxCbor signed transaction in CBOR hex format
|
|
122
|
+
* @returns {Promise<string>} transaction hash
|
|
123
|
+
*/
|
|
124
|
+
submitTransaction(signedTxCbor: string): Promise<string>;
|
|
125
|
+
/**
|
|
126
|
+
* Get Protocol Parameters
|
|
127
|
+
* @returns {Promise<any>} protocol parameters
|
|
128
|
+
*/
|
|
129
|
+
getProtocolParameters(): Promise<LedgerProtocolParameters>;
|
|
130
|
+
/**
|
|
131
|
+
* Get Latest Block Data
|
|
132
|
+
* @returns {Promise<BlockData>} latest block data
|
|
133
|
+
*/
|
|
134
|
+
getLatestBlock(): Promise<BlockData>;
|
|
135
|
+
/**
|
|
136
|
+
* Get Latest Epoch Data
|
|
137
|
+
* @returns {Promise<EpochData>} latest epoch data
|
|
138
|
+
*/
|
|
139
|
+
getLatestEpoch(): Promise<EpochData>;
|
|
140
|
+
/**
|
|
141
|
+
* Get the latest chain tip slot.
|
|
142
|
+
* @returns {Promise<number>} current chain slot
|
|
143
|
+
*/
|
|
144
|
+
getCurrentSlot(): Promise<number>;
|
|
145
|
+
/**
|
|
146
|
+
* Check whether a UTxO is still unspent via Koios `POST /utxo_info`.
|
|
147
|
+
* @param txHash 64-char lowercase hex
|
|
148
|
+
* @param outputIndex non-negative integer
|
|
149
|
+
* @returns {Promise<boolean>} true iff the UTxO exists and is unspent
|
|
150
|
+
*/
|
|
151
|
+
isUtxoUnspent(txHash: string, outputIndex: number): Promise<boolean>;
|
|
152
|
+
/**
|
|
153
|
+
* Get transaction hashes for an address (lightweight — no full tx details).
|
|
154
|
+
* @param address bech32 address
|
|
155
|
+
* @param limit maximum number of hashes
|
|
156
|
+
* @returns {Promise<string[]>} most recent tx hashes
|
|
157
|
+
*/
|
|
158
|
+
getAddressTransactionHashes(address: string, limit: number): Promise<string[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Batch fetch multiple transactions by hash using Koios POST /tx_info.
|
|
161
|
+
* Sends all hashes in one request (chunked at 100 per Koios limit).
|
|
162
|
+
* @param txHashes array of transaction hashes
|
|
163
|
+
* @returns {Promise<Map<string, Transaction>>} map of hash -> Transaction
|
|
164
|
+
*/
|
|
165
|
+
getTransactionsBatch(txHashes: string[]): Promise<Map<string, Transaction>>;
|
|
166
|
+
/**
|
|
167
|
+
* Map a Koios /tx_info response object to the normalized Transaction type.
|
|
168
|
+
*/
|
|
169
|
+
private _mapKoiosTx;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=koios-backend.d.ts.map
|
|
@@ -17,6 +17,38 @@ const KOIOS_URLS = {
|
|
|
17
17
|
preview: 'https://preview.koios.rest/api/v1',
|
|
18
18
|
preprod: 'https://preprod.koios.rest/api/v1',
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Koios `reference_script` (with `_extended: true`) is an OBJECT
|
|
22
|
+
* `{ hash, size, type, bytes, value }` — the previous `as string` cast handed
|
|
23
|
+
* that object downstream and broke the v1.6.1 input-side refScript feature.
|
|
24
|
+
* Returns the full script CBOR bytes when present (what the local Plutus eval
|
|
25
|
+
* needs), falling back to the hash (resolved on-chain only).
|
|
26
|
+
*/
|
|
27
|
+
function koiosRefScriptBytes(ref) {
|
|
28
|
+
if (!ref)
|
|
29
|
+
return null;
|
|
30
|
+
if (typeof ref === 'string')
|
|
31
|
+
return ref;
|
|
32
|
+
const obj = ref;
|
|
33
|
+
return obj.bytes || obj.hash || null;
|
|
34
|
+
}
|
|
35
|
+
/** Like koiosRefScriptBytes, but strictly the script HASH (for *Hash fields). */
|
|
36
|
+
function koiosRefScriptHash(ref) {
|
|
37
|
+
if (!ref)
|
|
38
|
+
return null;
|
|
39
|
+
if (typeof ref === 'string')
|
|
40
|
+
return ref;
|
|
41
|
+
const obj = ref;
|
|
42
|
+
return obj.hash || null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Sort Koios /address_txs rows newest-first. Koios gives no ordering guarantee —
|
|
46
|
+
* a bare `slice(0, limit)` returned ARBITRARY rather than recent transactions
|
|
47
|
+
* (Blockfrost requests `order: 'desc'` for the same data).
|
|
48
|
+
*/
|
|
49
|
+
function sortAddressTxsDesc(rows) {
|
|
50
|
+
return [...rows].sort((a, b) => Number(b.block_height ?? b.block_time ?? 0) - Number(a.block_height ?? a.block_time ?? 0));
|
|
51
|
+
}
|
|
20
52
|
/**
|
|
21
53
|
* KoiosBackend Implementation for CardanoBackend Interface
|
|
22
54
|
* Implements the CardanoBackend interface using Koios API with Axios
|
|
@@ -60,13 +92,13 @@ class KoiosBackend {
|
|
|
60
92
|
* valid queries — a single retry is not always sufficient for historical
|
|
61
93
|
* epoch lookups, so we retry with increasing delays (500 → 1000 → 2000 ms).
|
|
62
94
|
*/
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
// eslint-disable-
|
|
69
|
-
) {
|
|
95
|
+
// Type-agnostic retry helper: it only checks that `.data` is a non-empty
|
|
96
|
+
// array, so the element type is intentionally `any` to avoid forcing every
|
|
97
|
+
// Koios endpoint call site (block_info, epoch_info, account_info, …) to
|
|
98
|
+
// declare a row shape just for the empty-array retry path. Row narrowing
|
|
99
|
+
// happens at the use sites.
|
|
100
|
+
async fetchWithRetryOnEmpty(fn, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
101
|
+
label) {
|
|
70
102
|
const maxRetries = 3;
|
|
71
103
|
const baseDelayMs = 500;
|
|
72
104
|
const result = await fn();
|
|
@@ -174,14 +206,12 @@ class KoiosBackend {
|
|
|
174
206
|
}
|
|
175
207
|
const addressData = data[0];
|
|
176
208
|
const addressUtxos = await this.getAddressUtxos(address);
|
|
209
|
+
// Sum balances from the already-mapped UTxOs instead of re-iterating
|
|
210
|
+
// address_info's utxo_set (whose asset_list can be null → crashed here).
|
|
177
211
|
const totals = new Map();
|
|
178
|
-
for (const u of
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// add native assets
|
|
182
|
-
for (const a of u.asset_list) {
|
|
183
|
-
const unit = `${a.policy_id}${a.asset_name}`;
|
|
184
|
-
totals.set(unit, (totals.get(unit) ?? 0n) + BigInt(a.quantity));
|
|
212
|
+
for (const u of addressUtxos) {
|
|
213
|
+
for (const a of u.amount) {
|
|
214
|
+
totals.set(a.unit, (totals.get(a.unit) ?? 0n) + BigInt(a.quantity));
|
|
185
215
|
}
|
|
186
216
|
}
|
|
187
217
|
const amount = Array.from(totals.entries()).map(([unit, quantity]) => ({
|
|
@@ -206,11 +236,15 @@ class KoiosBackend {
|
|
|
206
236
|
async getAddressTransactions(address, limit) {
|
|
207
237
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
208
238
|
const { data: addressTxs } = await this.api.post('/address_txs', { _addresses: [address] });
|
|
209
|
-
//
|
|
210
|
-
const limitedTxs = addressTxs.slice(0, limit);
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
239
|
+
// newest first, THEN limit (saves API calls); batch instead of unbounded Promise.all
|
|
240
|
+
const limitedTxs = sortAddressTxsDesc(addressTxs).slice(0, limit);
|
|
241
|
+
const batch = await this.getTransactionsBatch(limitedTxs.map(tx => tx.tx_hash));
|
|
242
|
+
const transactions = [];
|
|
243
|
+
for (const tx of limitedTxs) {
|
|
244
|
+
const resolved = batch.get(tx.tx_hash);
|
|
245
|
+
if (resolved)
|
|
246
|
+
transactions.push(resolved);
|
|
247
|
+
}
|
|
214
248
|
return transactions;
|
|
215
249
|
}, this.name);
|
|
216
250
|
}
|
|
@@ -242,7 +276,7 @@ class KoiosBackend {
|
|
|
242
276
|
amount: amount,
|
|
243
277
|
blockHash: utxo.block_hash,
|
|
244
278
|
datumHash: utxo.datum_hash || null,
|
|
245
|
-
scriptRef: utxo.reference_script
|
|
279
|
+
scriptRef: koiosRefScriptBytes(utxo.reference_script),
|
|
246
280
|
inlineDatum: (0, tx_build_helper_1.inlineDatumToHex)(utxo.inline_datum),
|
|
247
281
|
};
|
|
248
282
|
});
|
|
@@ -280,7 +314,7 @@ class KoiosBackend {
|
|
|
280
314
|
amount: amount,
|
|
281
315
|
blockHash: utxo.block_hash,
|
|
282
316
|
datumHash: utxo.datum_hash || null,
|
|
283
|
-
scriptRef: utxo.reference_script
|
|
317
|
+
scriptRef: koiosRefScriptBytes(utxo.reference_script),
|
|
284
318
|
inlineDatum: (0, tx_build_helper_1.inlineDatumToHex)(utxo.inline_datum),
|
|
285
319
|
};
|
|
286
320
|
});
|
|
@@ -382,7 +416,10 @@ class KoiosBackend {
|
|
|
382
416
|
poolId: poolData.pool_id_bech32 || poolData.pool_id_hex || poolId,
|
|
383
417
|
vrfKeyHash: poolData.vrf_key_hash,
|
|
384
418
|
blocksMinted: poolData.block_count,
|
|
385
|
-
|
|
419
|
+
// Koios pool_info has no blocks-in-current-epoch figure — epoch_no
|
|
420
|
+
// (the epoch NUMBER) was mapped here before, which is a different
|
|
421
|
+
// semantic than Blockfrost's blocks_epoch. 0 = not available.
|
|
422
|
+
blocksEpoch: 0,
|
|
386
423
|
liveStake: poolData.live_stake || '0',
|
|
387
424
|
liveSize: poolData.live_size || 0,
|
|
388
425
|
liveDelegators: poolData.live_delegators || 0,
|
|
@@ -733,7 +770,9 @@ class KoiosBackend {
|
|
|
733
770
|
async getAddressTransactionHashes(address, limit) {
|
|
734
771
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
735
772
|
const { data } = await this.api.post('/address_txs', { _addresses: [address] });
|
|
736
|
-
return data
|
|
773
|
+
return sortAddressTxsDesc(data)
|
|
774
|
+
.slice(0, limit)
|
|
775
|
+
.map(tx => tx.tx_hash);
|
|
737
776
|
}, this.name);
|
|
738
777
|
}
|
|
739
778
|
/**
|
|
@@ -793,8 +832,11 @@ class KoiosBackend {
|
|
|
793
832
|
blockHeight: Number(tx.block_height),
|
|
794
833
|
blockTime: tx.tx_timestamp ?? tx.block_time ?? 0,
|
|
795
834
|
slot: tx.absolute_slot ?? tx.slot_no ?? 0,
|
|
796
|
-
|
|
797
|
-
|
|
835
|
+
// Koios /tx_info fields are `tx_block_index` and `fee` (verified against
|
|
836
|
+
// the live OpenAPI spec) — `tx_index`/`tx_fee` never existed, so the fee
|
|
837
|
+
// was always reported as '0'
|
|
838
|
+
index: tx.tx_block_index ?? 0,
|
|
839
|
+
fee: tx.fee || '0',
|
|
798
840
|
deposit: tx.deposit || '0',
|
|
799
841
|
size: tx.tx_size,
|
|
800
842
|
inputs: tx.inputs.map((input) => {
|
|
@@ -816,7 +858,7 @@ class KoiosBackend {
|
|
|
816
858
|
amount: amount,
|
|
817
859
|
dataHash: input.datum_hash || null,
|
|
818
860
|
inlineDatum: (0, tx_build_helper_1.inlineDatumToHex)(input.inline_datum),
|
|
819
|
-
referenceScriptHash: input.reference_script
|
|
861
|
+
referenceScriptHash: koiosRefScriptHash(input.reference_script),
|
|
820
862
|
};
|
|
821
863
|
}),
|
|
822
864
|
outputs: tx.outputs.map((output) => {
|
|
@@ -839,7 +881,7 @@ class KoiosBackend {
|
|
|
839
881
|
dataHash: output.datum_hash || null,
|
|
840
882
|
inlineDatum: (0, tx_build_helper_1.inlineDatumToHex)(output.inline_datum),
|
|
841
883
|
isCollateral: false,
|
|
842
|
-
referenceScriptHash: output.reference_script
|
|
884
|
+
referenceScriptHash: koiosRefScriptHash(output.reference_script),
|
|
843
885
|
};
|
|
844
886
|
}),
|
|
845
887
|
metadata: labels
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, AccountData, DrepData, AssetInfo, LedgerProtocolParameters, ScriptEvaluationResult } from '../../utils/types';
|
|
2
|
+
import { EvaluatingBackend } from './cardano-backend';
|
|
3
|
+
import { Network } from '../cardano-client';
|
|
4
|
+
/** Resolve Ogmios ledger tip which may be 'origin' (genesis block) or a point */
|
|
5
|
+
export declare function resolveOgmiosTip(tip: 'origin' | {
|
|
6
|
+
slot: number;
|
|
7
|
+
id: string;
|
|
8
|
+
}): {
|
|
9
|
+
slot: number;
|
|
10
|
+
hash: string;
|
|
11
|
+
};
|
|
12
|
+
/** Resolve Ogmios block height which may be 'origin' (genesis block) or a number */
|
|
13
|
+
export declare function resolveOgmiosHeight(height: 'origin' | number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Ogmios Backend Implementation for Cardano Backend Interface
|
|
16
|
+
* Implements the CardanoBackend interface using Ogmios WebSocket client for local node interaction
|
|
17
|
+
*/
|
|
18
|
+
export declare class OgmiosBackend implements EvaluatingBackend {
|
|
19
|
+
readonly name = "ogmios";
|
|
20
|
+
/**
|
|
21
|
+
* Capability declaration — the orchestrator skips Ogmios for these without
|
|
22
|
+
* counting circuit failures. Historic queries are out of protocol scope;
|
|
23
|
+
* getAddress/getNetworkInformation previously FABRICATED placeholder data
|
|
24
|
+
* (type:'base'/isScript:false/stakeAddress:null resp. maxSupply as
|
|
25
|
+
* total/circulating) which preferLive routing then preferred over correct
|
|
26
|
+
* Blockfrost/Koios data.
|
|
27
|
+
*/
|
|
28
|
+
readonly unsupportedMethods: ReadonlySet<string>;
|
|
29
|
+
private stateQueryClient;
|
|
30
|
+
private txSubmissionClient;
|
|
31
|
+
private context;
|
|
32
|
+
private isShutdown;
|
|
33
|
+
private reconnectPromise;
|
|
34
|
+
private network;
|
|
35
|
+
private timeoutMs;
|
|
36
|
+
private ogmiosUrl;
|
|
37
|
+
/**
|
|
38
|
+
* Constructor
|
|
39
|
+
*/
|
|
40
|
+
constructor(network: Network, timeoutMs: number, ogmiosUrl: string);
|
|
41
|
+
/** Validate Ogmios URL scheme and reject dangerous protocols */
|
|
42
|
+
private static validateOgmiosUrl;
|
|
43
|
+
/**
|
|
44
|
+
* Initialize the Ogmios backend connection
|
|
45
|
+
*/
|
|
46
|
+
init(): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Reconnect when the WebSocket has died since the last successful init.
|
|
49
|
+
* No-op when never initialized (test-injected clients) — startup-init
|
|
50
|
+
* recovery is the orchestrator's job (lazy init retry in CardanoClient).
|
|
51
|
+
* Concurrent callers share one reconnect attempt.
|
|
52
|
+
*/
|
|
53
|
+
private ensureConnected;
|
|
54
|
+
/**
|
|
55
|
+
* Get specific Block Data (not supported)
|
|
56
|
+
* @param _hash block hash (hex)
|
|
57
|
+
* @returns {Promise<BlockData>} block data
|
|
58
|
+
*/
|
|
59
|
+
getBlock(_hash: string): Promise<BlockData>;
|
|
60
|
+
/**
|
|
61
|
+
* Get specific Epoch Data (not supported)
|
|
62
|
+
* @param _epochNumber epoch number
|
|
63
|
+
* @returns {Promise<EpochData>} epoch data
|
|
64
|
+
*/
|
|
65
|
+
getEpoch(epochNumber: number): Promise<EpochData>;
|
|
66
|
+
/**
|
|
67
|
+
* Get specific Transaction Data (not supported)
|
|
68
|
+
* @param _hash transaction hash (hex)
|
|
69
|
+
* @returns {Promise<Transaction>} transaction data
|
|
70
|
+
*/
|
|
71
|
+
getTransaction(_hash: string): Promise<Transaction>;
|
|
72
|
+
/**
|
|
73
|
+
* Get specific Transaction Metadata (not supported)
|
|
74
|
+
* @param _tx_hash transaction hash (hex)
|
|
75
|
+
* @returns {Promise<MetadataLabelTx[]>} transaction metadata list
|
|
76
|
+
*/
|
|
77
|
+
getTransactionMetadata(_tx_hash: string): Promise<MetadataLabelTx[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Get specific Drep Data (not supported for Ogmios)
|
|
80
|
+
* @param _drepId drep id
|
|
81
|
+
* @returns {Promise<DrepData>} drep data
|
|
82
|
+
*/
|
|
83
|
+
getDrep(_drepId: string): Promise<DrepData>;
|
|
84
|
+
/**
|
|
85
|
+
* Get Asset Info (not supported for Ogmios — no aggregate-supply query in the protocol)
|
|
86
|
+
* @param _unit asset unit (policyId + assetNameHex)
|
|
87
|
+
* @returns {Promise<AssetInfo>} asset info
|
|
88
|
+
*/
|
|
89
|
+
getAssetInfo(_unit: string): Promise<AssetInfo>;
|
|
90
|
+
/**
|
|
91
|
+
* Get specific Network Information (not supported — Ogmios state queries
|
|
92
|
+
* expose no supply/stake aggregates; the previous implementation fabricated
|
|
93
|
+
* maxSupply as total/circulating, which preferLive routing then preferred
|
|
94
|
+
* over correct Blockfrost/Koios data)
|
|
95
|
+
*/
|
|
96
|
+
getNetworkInformation(): Promise<NetworkInformation>;
|
|
97
|
+
/**
|
|
98
|
+
* Get current specific Address Data (not supported — address type, script
|
|
99
|
+
* flag and stake address are not derivable from Ogmios state queries; the
|
|
100
|
+
* previous implementation fabricated type:'base'/isScript:false/
|
|
101
|
+
* stakeAddress:null. UTxOs remain available via getAddressUtxos.)
|
|
102
|
+
*/
|
|
103
|
+
getAddress(_address: string): Promise<Address>;
|
|
104
|
+
/** get current specific Address UTxOs
|
|
105
|
+
* @param address bech32 address
|
|
106
|
+
* @returns {Promise<UTxO[]>} address UTxOs
|
|
107
|
+
*/
|
|
108
|
+
getAddressUtxos(address: string): Promise<UTxO[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Get Address Transactions (not supported by Ogmios - use historical backend)
|
|
111
|
+
* Ogmios is a live state query backend and does not provide historical transaction data
|
|
112
|
+
* @param _address bech32 address
|
|
113
|
+
* @returns {Promise<Transaction[]>} always throws - use historical backend instead
|
|
114
|
+
*/
|
|
115
|
+
getAddressTransactions(_address: string): Promise<Transaction[]>;
|
|
116
|
+
/**
|
|
117
|
+
* Get current specific Pool Data
|
|
118
|
+
* @param poolId pool id
|
|
119
|
+
* @returns {Promise<PoolData>} pool data
|
|
120
|
+
*/
|
|
121
|
+
getPool(poolId: string): Promise<PoolData>;
|
|
122
|
+
/**
|
|
123
|
+
* Get Account Data for specified stake address
|
|
124
|
+
* @param stakeAddress stake address
|
|
125
|
+
* @returns {Promise<AccountData>} account data
|
|
126
|
+
*/
|
|
127
|
+
getAccount(stakeAddress: string): Promise<AccountData>;
|
|
128
|
+
/**
|
|
129
|
+
* Submit Transaction to the network
|
|
130
|
+
* @param signedTxCbor signed transaction in CBOR hex format
|
|
131
|
+
* @returns {Promise<string>} transaction hash
|
|
132
|
+
*/
|
|
133
|
+
submitTransaction(signedTxCbor: string): Promise<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Evaluate transaction script execution units
|
|
136
|
+
* @param unsignedTxCbor unsigned transaction in CBOR hex format
|
|
137
|
+
* @returns {Promise<ScriptEvaluationResult[]>} evaluation results
|
|
138
|
+
*/
|
|
139
|
+
evaluateTransaction(unsignedTxCbor: string): Promise<ScriptEvaluationResult[]>;
|
|
140
|
+
/**
|
|
141
|
+
* Get current Protocol Parameters
|
|
142
|
+
* @returns {Promise<LedgerProtocolParameters>} protocol parameters
|
|
143
|
+
*/
|
|
144
|
+
getProtocolParameters(): Promise<LedgerProtocolParameters>;
|
|
145
|
+
/**
|
|
146
|
+
* Get Latest Epoch Data
|
|
147
|
+
* @returns {Promise<EpochData>} latest epoch data
|
|
148
|
+
*/
|
|
149
|
+
getLatestEpoch(): Promise<EpochData>;
|
|
150
|
+
/**
|
|
151
|
+
* Get current Latest Block Data
|
|
152
|
+
* @returns {Promise<BlockData>} latest block data
|
|
153
|
+
*/
|
|
154
|
+
getLatestBlock(): Promise<BlockData>;
|
|
155
|
+
/**
|
|
156
|
+
* Get the latest chain tip slot.
|
|
157
|
+
* @returns {Promise<number>} current chain slot
|
|
158
|
+
*/
|
|
159
|
+
getCurrentSlot(): Promise<number>;
|
|
160
|
+
/**
|
|
161
|
+
* Check whether a UTxO is still unspent via Ogmios `queryLedgerState/utxo`
|
|
162
|
+
* with an outputReferences filter. Empty result means spent or nonexistent.
|
|
163
|
+
* @param txHash 64-char lowercase hex
|
|
164
|
+
* @param outputIndex non-negative integer
|
|
165
|
+
* @returns {Promise<boolean>} true iff the UTxO exists and is unspent
|
|
166
|
+
*/
|
|
167
|
+
isUtxoUnspent(txHash: string, outputIndex: number): Promise<boolean>;
|
|
168
|
+
/**
|
|
169
|
+
* Shutdown the Ogmios Backend
|
|
170
|
+
* Closes all connections and marks as shutdown
|
|
171
|
+
*/
|
|
172
|
+
shutdown(): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Check if backend is connected
|
|
175
|
+
*/
|
|
176
|
+
isConnected(): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Ensure the client is not shutdown before operations
|
|
179
|
+
*/
|
|
180
|
+
private ensureNotShutdown;
|
|
181
|
+
/**
|
|
182
|
+
* Convert Ogmios value format to odatano amount array
|
|
183
|
+
* Ogmios: { ada: { lovelace: 1000000 }, policyId: { assetName: quantity } }
|
|
184
|
+
* Standard: [{ unit: 'lovelace', quantity: '1000000' }, { unit: 'policyId.assetName', quantity: 'N' }]
|
|
185
|
+
*/
|
|
186
|
+
private convertOgmiosValue;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=ogmios-backend.d.ts.map
|