@odatano/core 2.0.0-rc.30 → 2.0.0-rc.32
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 +11 -0
- package/@cds-models/CardanoODataService/index.js +1 -0
- package/@cds-models/index.d.ts +53 -0
- package/@cds-models/index.js +9 -0
- package/db/types.cds +83 -0
- package/package.json +1 -1
- package/src/index.d.ts +7 -1
- package/src/index.js +17 -1
- package/srv/blockchain/cardano-indexer.d.ts +10 -1
- package/srv/blockchain/cardano-indexer.js +49 -2
- package/srv/blockchain/signing/signature-verifier.d.ts +6 -1
- package/srv/blockchain/signing/signature-verifier.js +62 -24
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +7 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +38 -9
- package/srv/blockchain/transaction-building/caller-datums.d.ts +12 -0
- package/srv/blockchain/transaction-building/caller-datums.js +89 -0
- package/srv/cardano-service.cds +8 -1
- package/srv/cardano-service.js +8 -0
- package/srv/cbor/index.d.ts +1 -1
- package/srv/cbor/parse.d.ts +25 -0
- package/srv/cbor/parse.js +48 -1
- package/srv/server.js +3 -0
- package/srv/utils/epoch-slots.d.ts +8 -1
- package/srv/utils/epoch-slots.js +20 -2
- package/srv/utils/types.d.ts +18 -0
|
@@ -41,6 +41,7 @@ export default class {
|
|
|
41
41
|
static readonly GetAssetHistory: typeof GetAssetHistory;
|
|
42
42
|
static readonly GetAccountByStakeAddress: typeof GetAccountByStakeAddress;
|
|
43
43
|
static readonly GetTransactionByHash: typeof GetTransactionByHash;
|
|
44
|
+
static readonly GetTransactionConfirmations: typeof GetTransactionConfirmations;
|
|
44
45
|
static readonly GetMetadataByTxHash: typeof GetMetadataByTxHash;
|
|
45
46
|
static readonly GetAddressByBech32: typeof GetAddressByBech32;
|
|
46
47
|
static readonly GetUTxOsByAddress: typeof GetUTxOsByAddress;
|
|
@@ -983,6 +984,16 @@ export declare const GetTransactionByHash: {
|
|
|
983
984
|
kind: 'action'
|
|
984
985
|
}
|
|
985
986
|
|
|
987
|
+
export declare const GetTransactionConfirmations: {
|
|
988
|
+
// positional
|
|
989
|
+
(txHash: _.Blake2b256 | null): globalThis.Promise<_.TransactionConfirmations | null> | _.TransactionConfirmations | null
|
|
990
|
+
// named
|
|
991
|
+
({txHash}: {txHash?: _.Blake2b256 | null}): globalThis.Promise<_.TransactionConfirmations | null> | _.TransactionConfirmations | null
|
|
992
|
+
// metadata (do not use)
|
|
993
|
+
__parameters: {txHash?: _.Blake2b256 | null}, __returns: globalThis.Promise<_.TransactionConfirmations | null> | _.TransactionConfirmations | null, __self: never
|
|
994
|
+
kind: 'action'
|
|
995
|
+
}
|
|
996
|
+
|
|
986
997
|
export declare const GetMetadataByTxHash: {
|
|
987
998
|
// positional
|
|
988
999
|
(txHash: _.Blake2b256 | null): globalThis.Promise<Array<TransactionMetadata>> | Array<TransactionMetadata>
|
|
@@ -108,6 +108,7 @@ module.exports.GetAssetInfo = 'GetAssetInfo'
|
|
|
108
108
|
module.exports.GetAssetHistory = 'GetAssetHistory'
|
|
109
109
|
module.exports.GetAccountByStakeAddress = 'GetAccountByStakeAddress'
|
|
110
110
|
module.exports.GetTransactionByHash = 'GetTransactionByHash'
|
|
111
|
+
module.exports.GetTransactionConfirmations = 'GetTransactionConfirmations'
|
|
111
112
|
module.exports.GetMetadataByTxHash = 'GetMetadataByTxHash'
|
|
112
113
|
module.exports.GetAddressByBech32 = 'GetAddressByBech32'
|
|
113
114
|
module.exports.GetUTxOsByAddress = 'GetUTxOsByAddress'
|
package/@cds-models/index.d.ts
CHANGED
|
@@ -228,6 +228,22 @@ export declare function _UTxODataSliceAspect<TBase extends new (...args: any[])
|
|
|
228
228
|
export class UTxODataSlice extends _UTxODataSliceAspect(__.Entity) {
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
+
// entity 'TransactionConfirmations'
|
|
232
|
+
export declare function _TransactionConfirmationsAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
|
|
233
|
+
new (...args: any[]): {
|
|
234
|
+
txHash?: Blake2b256 | null
|
|
235
|
+
blockHeight?: number | null
|
|
236
|
+
tipHeight?: number | null
|
|
237
|
+
confirmations?: number | null
|
|
238
|
+
} & InstanceType<TBase>
|
|
239
|
+
readonly kind: 'type';
|
|
240
|
+
readonly keys: __.KeysOf<TransactionConfirmations>;
|
|
241
|
+
readonly elements: __.ElementsOf<TransactionConfirmations>;
|
|
242
|
+
readonly actions: globalThis.Record<never, never>;
|
|
243
|
+
};
|
|
244
|
+
export class TransactionConfirmations extends _TransactionConfirmationsAspect(__.Entity) {
|
|
245
|
+
}
|
|
246
|
+
|
|
231
247
|
// entity 'ParsedInput'
|
|
232
248
|
export declare function _ParsedInputAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
|
|
233
249
|
new (...args: any[]): {
|
|
@@ -265,6 +281,7 @@ export declare function _ParsedOutputAspect<TBase extends new (...args: any[]) =
|
|
|
265
281
|
datumHash?: Blake2b256 | null
|
|
266
282
|
inlineDatumHex?: string | null
|
|
267
283
|
referenceScriptHex?: string | null
|
|
284
|
+
cborSize?: number | null
|
|
268
285
|
} & InstanceType<TBase>
|
|
269
286
|
readonly kind: 'type';
|
|
270
287
|
readonly keys: __.KeysOf<ParsedOutput>;
|
|
@@ -274,6 +291,34 @@ export declare function _ParsedOutputAspect<TBase extends new (...args: any[]) =
|
|
|
274
291
|
export class ParsedOutput extends _ParsedOutputAspect(__.Entity) {
|
|
275
292
|
}
|
|
276
293
|
|
|
294
|
+
// entity 'ParsedWithdrawal'
|
|
295
|
+
export declare function _ParsedWithdrawalAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
|
|
296
|
+
new (...args: any[]): {
|
|
297
|
+
rewardAddress?: Bech32 | null
|
|
298
|
+
lovelace?: Lovelace | null
|
|
299
|
+
} & InstanceType<TBase>
|
|
300
|
+
readonly kind: 'type';
|
|
301
|
+
readonly keys: __.KeysOf<ParsedWithdrawal>;
|
|
302
|
+
readonly elements: __.ElementsOf<ParsedWithdrawal>;
|
|
303
|
+
readonly actions: globalThis.Record<never, never>;
|
|
304
|
+
};
|
|
305
|
+
export class ParsedWithdrawal extends _ParsedWithdrawalAspect(__.Entity) {
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// entity 'ParsedCertificate'
|
|
309
|
+
export declare function _ParsedCertificateAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
|
|
310
|
+
new (...args: any[]): {
|
|
311
|
+
index?: number | null
|
|
312
|
+
type?: string | null
|
|
313
|
+
} & InstanceType<TBase>
|
|
314
|
+
readonly kind: 'type';
|
|
315
|
+
readonly keys: __.KeysOf<ParsedCertificate>;
|
|
316
|
+
readonly elements: __.ElementsOf<ParsedCertificate>;
|
|
317
|
+
readonly actions: globalThis.Record<never, never>;
|
|
318
|
+
};
|
|
319
|
+
export class ParsedCertificate extends _ParsedCertificateAspect(__.Entity) {
|
|
320
|
+
}
|
|
321
|
+
|
|
277
322
|
// entity 'ParsedWitnesses'
|
|
278
323
|
export declare function _ParsedWitnessesAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
|
|
279
324
|
new (...args: any[]): {
|
|
@@ -296,6 +341,7 @@ export declare function _ParsedTransactionAspect<TBase extends new (...args: any
|
|
|
296
341
|
new (...args: any[]): {
|
|
297
342
|
txHash?: Blake2b256 | null
|
|
298
343
|
network?: string | null
|
|
344
|
+
networkId?: number | null
|
|
299
345
|
inputs?: Array<ParsedInput>
|
|
300
346
|
outputs?: Array<ParsedOutput>
|
|
301
347
|
validityStart?: string | null
|
|
@@ -304,6 +350,13 @@ export declare function _ParsedTransactionAspect<TBase extends new (...args: any
|
|
|
304
350
|
mint?: Array<ParsedAsset>
|
|
305
351
|
metadataLabels?: Array<string>
|
|
306
352
|
collateral?: Array<ParsedInput>
|
|
353
|
+
referenceInputs?: Array<ParsedInput>
|
|
354
|
+
withdrawals?: Array<ParsedWithdrawal>
|
|
355
|
+
certificates?: Array<ParsedCertificate>
|
|
356
|
+
votingProcedures?: number | null
|
|
357
|
+
proposalProcedures?: number | null
|
|
358
|
+
treasuryDonation?: Lovelace | null
|
|
359
|
+
currentTreasuryValue?: Lovelace | null
|
|
307
360
|
requiredSigners?: Array<Blake2b224>
|
|
308
361
|
scriptDataHash?: Blake2b256 | null
|
|
309
362
|
witnesses?: ParsedWitnesses | null
|
package/@cds-models/index.js
CHANGED
|
@@ -12,6 +12,9 @@ module.exports.__Array_MetadataSlice_ = createEntityProxy(['', 'MetadataSlice'],
|
|
|
12
12
|
// UTxODataSlice
|
|
13
13
|
module.exports.UTxODataSlice = createEntityProxy(['', 'UTxODataSlice'], { target: { is_singular: true } })
|
|
14
14
|
module.exports.__Array_UTxODataSlice_ = createEntityProxy(['', 'UTxODataSlice'], { target: { is_singular: false }})
|
|
15
|
+
// TransactionConfirmations
|
|
16
|
+
module.exports.TransactionConfirmations = createEntityProxy(['', 'TransactionConfirmations'], { target: { is_singular: true } })
|
|
17
|
+
module.exports.__Array_TransactionConfirmations_ = createEntityProxy(['', 'TransactionConfirmations'], { target: { is_singular: false }})
|
|
15
18
|
// ParsedInput
|
|
16
19
|
module.exports.ParsedInput = createEntityProxy(['', 'ParsedInput'], { target: { is_singular: true } })
|
|
17
20
|
module.exports.__Array_ParsedInput_ = createEntityProxy(['', 'ParsedInput'], { target: { is_singular: false }})
|
|
@@ -21,6 +24,12 @@ module.exports.__Array_ParsedAsset_ = createEntityProxy(['', 'ParsedAsset'], { t
|
|
|
21
24
|
// ParsedOutput
|
|
22
25
|
module.exports.ParsedOutput = createEntityProxy(['', 'ParsedOutput'], { target: { is_singular: true } })
|
|
23
26
|
module.exports.__Array_ParsedOutput_ = createEntityProxy(['', 'ParsedOutput'], { target: { is_singular: false }})
|
|
27
|
+
// ParsedWithdrawal
|
|
28
|
+
module.exports.ParsedWithdrawal = createEntityProxy(['', 'ParsedWithdrawal'], { target: { is_singular: true } })
|
|
29
|
+
module.exports.__Array_ParsedWithdrawal_ = createEntityProxy(['', 'ParsedWithdrawal'], { target: { is_singular: false }})
|
|
30
|
+
// ParsedCertificate
|
|
31
|
+
module.exports.ParsedCertificate = createEntityProxy(['', 'ParsedCertificate'], { target: { is_singular: true } })
|
|
32
|
+
module.exports.__Array_ParsedCertificate_ = createEntityProxy(['', 'ParsedCertificate'], { target: { is_singular: false }})
|
|
24
33
|
// ParsedWitnesses
|
|
25
34
|
module.exports.ParsedWitnesses = createEntityProxy(['', 'ParsedWitnesses'], { target: { is_singular: true } })
|
|
26
35
|
module.exports.__Array_ParsedWitnesses_ = createEntityProxy(['', 'ParsedWitnesses'], { target: { is_singular: false }})
|
package/db/types.cds
CHANGED
|
@@ -186,6 +186,29 @@ type WorkerSignerType : String(10) enum {
|
|
|
186
186
|
software = 'software'; // operator-configured Ed25519 key (dev/test)
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
// -----------------------------------------------------
|
|
190
|
+
// Transaction confirmations (GetTransactionConfirmations action result)
|
|
191
|
+
// -----------------------------------------------------
|
|
192
|
+
@title : 'Transaction Confirmations'
|
|
193
|
+
@description: 'Depth of a transaction in the chain. Depth 1 means it sits in the tip block.'
|
|
194
|
+
type TransactionConfirmations {
|
|
195
|
+
@title : 'Transaction Hash'
|
|
196
|
+
@description: 'The transaction asked for'
|
|
197
|
+
txHash : Blake2b256;
|
|
198
|
+
|
|
199
|
+
@title : 'Block Height'
|
|
200
|
+
@description: 'Height of the block holding the transaction; null while it is not on chain'
|
|
201
|
+
blockHeight : Integer64;
|
|
202
|
+
|
|
203
|
+
@title : 'Tip Height'
|
|
204
|
+
@description: 'Height of the chain tip used for the count; null while the transaction is not on chain'
|
|
205
|
+
tipHeight : Integer64;
|
|
206
|
+
|
|
207
|
+
@title : 'Confirmations'
|
|
208
|
+
@description: 'Tip height minus block height plus one; 0 while the transaction is not on chain'
|
|
209
|
+
confirmations : Integer;
|
|
210
|
+
}
|
|
211
|
+
|
|
189
212
|
// -----------------------------------------------------
|
|
190
213
|
// Parsed Transaction (ParseTransactionCbor action result)
|
|
191
214
|
// -----------------------------------------------------
|
|
@@ -239,6 +262,34 @@ type ParsedOutput {
|
|
|
239
262
|
@title : 'Reference Script CBOR'
|
|
240
263
|
@description: 'Hex-encoded CIP-33 reference script CBOR when present; null otherwise'
|
|
241
264
|
referenceScriptHex : LargeString;
|
|
265
|
+
|
|
266
|
+
@title : 'Output CBOR Size'
|
|
267
|
+
@description: 'Byte length of the output as it stands in the transaction (input for the min-UTxO check)'
|
|
268
|
+
cborSize : Integer;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
@title : 'Parsed Withdrawal'
|
|
272
|
+
@description: 'A reward withdrawal of a parsed transaction'
|
|
273
|
+
type ParsedWithdrawal {
|
|
274
|
+
@title : 'Reward Address'
|
|
275
|
+
@description: 'Bech32 reward address the lovelace is withdrawn from'
|
|
276
|
+
rewardAddress : Bech32;
|
|
277
|
+
|
|
278
|
+
@title : 'Withdrawn Lovelace'
|
|
279
|
+
@description: 'Withdrawn amount in lovelace (decimal string)'
|
|
280
|
+
lovelace : Lovelace;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
@title : 'Parsed Certificate'
|
|
284
|
+
@description: 'A certificate of a parsed transaction'
|
|
285
|
+
type ParsedCertificate {
|
|
286
|
+
@title : 'Certificate Index'
|
|
287
|
+
@description: 'Position in the body certificate list'
|
|
288
|
+
index : Integer;
|
|
289
|
+
|
|
290
|
+
@title : 'Certificate Type'
|
|
291
|
+
@description: 'Ledger certificate name, e.g. StakeDelegation or RegistrationDrep'
|
|
292
|
+
type : String(40);
|
|
242
293
|
}
|
|
243
294
|
|
|
244
295
|
@title : 'Parsed Witness Counts'
|
|
@@ -276,6 +327,10 @@ type ParsedTransaction {
|
|
|
276
327
|
@description: '"mainnet" or "testnet" from the tx body network ID byte; null if absent. preview vs preprod cannot be distinguished from CBOR alone.'
|
|
277
328
|
network : String(10);
|
|
278
329
|
|
|
330
|
+
@title : 'Network ID'
|
|
331
|
+
@description: 'Body field 15: 1 = mainnet, 0 = testnet; null if absent'
|
|
332
|
+
networkId : Integer;
|
|
333
|
+
|
|
279
334
|
@title : 'Inputs'
|
|
280
335
|
@description: 'UTxOs consumed by the transaction'
|
|
281
336
|
inputs : many ParsedInput;
|
|
@@ -308,6 +363,34 @@ type ParsedTransaction {
|
|
|
308
363
|
@description: 'Collateral UTxOs for phase-2 validation (empty when no Plutus scripts run)'
|
|
309
364
|
collateral : many ParsedInput;
|
|
310
365
|
|
|
366
|
+
@title : 'Reference Inputs'
|
|
367
|
+
@description: 'UTxOs the transaction reads without spending them'
|
|
368
|
+
referenceInputs : many ParsedInput;
|
|
369
|
+
|
|
370
|
+
@title : 'Withdrawals'
|
|
371
|
+
@description: 'Reward withdrawals; empty array if none'
|
|
372
|
+
withdrawals : many ParsedWithdrawal;
|
|
373
|
+
|
|
374
|
+
@title : 'Certificates'
|
|
375
|
+
@description: 'Certificates in body order; empty array if none'
|
|
376
|
+
certificates : many ParsedCertificate;
|
|
377
|
+
|
|
378
|
+
@title : 'Vote Count'
|
|
379
|
+
@description: 'Number of votes over all voters; 0 if the body has no voting procedures'
|
|
380
|
+
votingProcedures : Integer;
|
|
381
|
+
|
|
382
|
+
@title : 'Proposal Count'
|
|
383
|
+
@description: 'Number of governance proposals'
|
|
384
|
+
proposalProcedures : Integer;
|
|
385
|
+
|
|
386
|
+
@title : 'Treasury Donation'
|
|
387
|
+
@description: 'Lovelace donated to the treasury; null if absent'
|
|
388
|
+
treasuryDonation : Lovelace;
|
|
389
|
+
|
|
390
|
+
@title : 'Current Treasury Value'
|
|
391
|
+
@description: 'Treasury value the transaction asserts; null if absent'
|
|
392
|
+
currentTreasuryValue : Lovelace;
|
|
393
|
+
|
|
311
394
|
@title : 'Required Signers'
|
|
312
395
|
@description: '28-byte Ed25519 key hashes listed in the tx body required_signers field'
|
|
313
396
|
requiredSigners : many Blake2b224;
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TransactionConfirmations } from '../srv/utils/types';
|
|
1
2
|
export { CardanoClient } from '../srv/blockchain/cardano-client';
|
|
2
3
|
export type { CardanoClientConfig, Network, BackendName, TransactionBuilderName } from '../srv/blockchain/cardano-client';
|
|
3
4
|
export { CardanoIndexer } from '../srv/blockchain/cardano-indexer';
|
|
@@ -12,7 +13,10 @@ export { loadAgentGrantsConfig } from '../srv/utils/agent-grants-config';
|
|
|
12
13
|
export type { AgentGrantsConfig } from '../srv/utils/agent-grants-config';
|
|
13
14
|
export type { HsmConfig, HsmSignResult } from '../srv/utils/types';
|
|
14
15
|
export { parseTransaction } from '../srv/cbor';
|
|
15
|
-
export type { ParsedTransaction, ParsedInput, ParsedOutput, ParsedAsset, ParsedWitnesses, } from '../srv/cbor';
|
|
16
|
+
export type { ParsedTransaction, ParsedInput, ParsedOutput, ParsedAsset, ParsedWitnesses, ParsedWithdrawal, ParsedCertificate, } from '../srv/cbor';
|
|
17
|
+
export { verifyTxWitnesses } from '../srv/blockchain/signing/signature-verifier';
|
|
18
|
+
export { posixToSlot, slotToPosixMs } from '../srv/utils/epoch-slots';
|
|
19
|
+
export type { TxWitnessVerification, TransactionConfirmations } from '../srv/utils/types';
|
|
16
20
|
export { applyScriptParameters, plutusScriptHash } from '../srv/utils/tx-build-helper';
|
|
17
21
|
/**
|
|
18
22
|
* Initialize the plugin: config from cds.env.requires["odatano-core"] or env vars,
|
|
@@ -21,6 +25,8 @@ export { applyScriptParameters, plutusScriptHash } from '../srv/utils/tx-build-h
|
|
|
21
25
|
export declare function initialize(): Promise<void>;
|
|
22
26
|
/** Shut down the plugin and close all backend connections. */
|
|
23
27
|
export declare function shutdown(): Promise<void>;
|
|
28
|
+
/** Confirmations of a transaction; needs initialize(). See CardanoIndexer.resolveTransactionConfirmations. */
|
|
29
|
+
export declare function getTransactionConfirmations(txHash: string): Promise<TransactionConfirmations>;
|
|
24
30
|
/** Current plugin status. */
|
|
25
31
|
export declare function getStatus(): {
|
|
26
32
|
initialized: boolean;
|
package/src/index.js
CHANGED
|
@@ -36,11 +36,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.plutusScriptHash = exports.applyScriptParameters = exports.parseTransaction = exports.loadAgentGrantsConfig = exports.registerTransportLane = exports.AGENT_ALWAYS_ALLOWED_EVENTS = exports.AGENT_ALLOWLISTABLE_ACTIONS = exports.AGENT_ROLE = exports.AGENT_TOKEN_PREFIX = exports.AGENT_TOKEN_HEADER = exports.hashAgentToken = exports.resolveUsageWindow = exports.getGrantUsage = exports.revokeAgentGrantById = exports.rotateAgentGrantToken = exports.updateAgentGrant = exports.issueAgentGrant = exports.getHsmSigner = exports.shutdownAppContext = exports.startWalletWorkerIfConfigured = exports.loadWalletWorkerConfigFromEnv = exports.startCrawlerIfConfigured = exports.loadCrawlerConfigFromEnv = exports.loadHsmConfigFromEnv = exports.loadConfigFromEnv = exports.getCardanoTxBuilder = exports.getCardanoClient = exports.getCardanoIndexer = exports.getAppContext = exports.CardanoTransactionBuilder = exports.CardanoIndexer = exports.CardanoClient = void 0;
|
|
39
|
+
exports.plutusScriptHash = exports.applyScriptParameters = exports.slotToPosixMs = exports.posixToSlot = exports.verifyTxWitnesses = exports.parseTransaction = exports.loadAgentGrantsConfig = exports.registerTransportLane = exports.AGENT_ALWAYS_ALLOWED_EVENTS = exports.AGENT_ALLOWLISTABLE_ACTIONS = exports.AGENT_ROLE = exports.AGENT_TOKEN_PREFIX = exports.AGENT_TOKEN_HEADER = exports.hashAgentToken = exports.resolveUsageWindow = exports.getGrantUsage = exports.revokeAgentGrantById = exports.rotateAgentGrantToken = exports.updateAgentGrant = exports.issueAgentGrant = exports.getHsmSigner = exports.shutdownAppContext = exports.startWalletWorkerIfConfigured = exports.loadWalletWorkerConfigFromEnv = exports.startCrawlerIfConfigured = exports.loadCrawlerConfigFromEnv = exports.loadHsmConfigFromEnv = exports.loadConfigFromEnv = exports.getCardanoTxBuilder = exports.getCardanoClient = exports.getCardanoIndexer = exports.getAppContext = exports.CardanoTransactionBuilder = exports.CardanoIndexer = exports.CardanoClient = void 0;
|
|
40
40
|
exports.initialize = initialize;
|
|
41
41
|
exports.shutdown = shutdown;
|
|
42
|
+
exports.getTransactionConfirmations = getTransactionConfirmations;
|
|
42
43
|
exports.getStatus = getStatus;
|
|
43
44
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
45
|
+
const validators_1 = require("../srv/utils/validators");
|
|
46
|
+
const errors_1 = require("../srv/utils/errors");
|
|
47
|
+
const error_codes_1 = require("../srv/utils/error-codes");
|
|
44
48
|
const logger = cds_1.default.log('ODATANO');
|
|
45
49
|
// Re-export key types and classes for programmatic consumers
|
|
46
50
|
var cardano_client_1 = require("../srv/blockchain/cardano-client");
|
|
@@ -86,6 +90,11 @@ Object.defineProperty(exports, "loadAgentGrantsConfig", { enumerable: true, get:
|
|
|
86
90
|
// Re-export pure CBOR utilities (no CAP round-trip needed)
|
|
87
91
|
var cbor_1 = require("../srv/cbor");
|
|
88
92
|
Object.defineProperty(exports, "parseTransaction", { enumerable: true, get: function () { return cbor_1.parseTransaction; } });
|
|
93
|
+
var signature_verifier_1 = require("../srv/blockchain/signing/signature-verifier");
|
|
94
|
+
Object.defineProperty(exports, "verifyTxWitnesses", { enumerable: true, get: function () { return signature_verifier_1.verifyTxWitnesses; } });
|
|
95
|
+
var epoch_slots_1 = require("../srv/utils/epoch-slots");
|
|
96
|
+
Object.defineProperty(exports, "posixToSlot", { enumerable: true, get: function () { return epoch_slots_1.posixToSlot; } });
|
|
97
|
+
Object.defineProperty(exports, "slotToPosixMs", { enumerable: true, get: function () { return epoch_slots_1.slotToPosixMs; } });
|
|
89
98
|
// Pure script helpers (no initialize() needed)
|
|
90
99
|
var tx_build_helper_1 = require("../srv/utils/tx-build-helper");
|
|
91
100
|
Object.defineProperty(exports, "applyScriptParameters", { enumerable: true, get: function () { return tx_build_helper_1.applyScriptParameters; } });
|
|
@@ -122,6 +131,13 @@ async function shutdown() {
|
|
|
122
131
|
await shutdownAppContext();
|
|
123
132
|
logger.info('ODATANO core shutdown');
|
|
124
133
|
}
|
|
134
|
+
/** Confirmations of a transaction; needs initialize(). See CardanoIndexer.resolveTransactionConfirmations. */
|
|
135
|
+
async function getTransactionConfirmations(txHash) {
|
|
136
|
+
if (!(0, validators_1.isTxHash)(txHash))
|
|
137
|
+
throw new errors_1.TransactionValidationError(`Invalid transaction hash: ${txHash}`, undefined, error_codes_1.ERROR_CODES.INVALID_INPUT);
|
|
138
|
+
const { getCardanoIndexer } = await Promise.resolve().then(() => __importStar(require('../srv/server')));
|
|
139
|
+
return cds_1.default.tx((tx) => getCardanoIndexer().resolveTransactionConfirmations(tx, txHash));
|
|
140
|
+
}
|
|
125
141
|
/** Current plugin status. */
|
|
126
142
|
function getStatus() {
|
|
127
143
|
try {
|
|
@@ -3,7 +3,7 @@ import type { CardanoClient } from './cardano-client';
|
|
|
3
3
|
import type { CardanoTransactionBuilder } from './cardano-tx-builder';
|
|
4
4
|
import { Transaction as CardanoTransaction, AddressUTxOs, TransactionMetadata, NetworkInformation, Block, Epoch, AssetHistory, Account, Drep, Pool, Asset, Address, LedgerProtocolParameter, AddressTransactions } from '#cds-models/CardanoODataService';
|
|
5
5
|
import { TransactionBuild, TransactionSubmission } from '#cds-models/CardanoTransactionService';
|
|
6
|
-
import { TxBuildRequest, TxBuildPlutusRequest, AssetInfo, AccountData, PoolData, NetworkInformation as ProviderNetworkInformation, Address as ProviderAddress, Transaction as ProviderTransaction, UTxO as OdatanoUtxo, BlockData, AssetHistoryEntry as AssetHistoryEntryProviderData } from '../utils/types';
|
|
6
|
+
import { TxBuildRequest, TxBuildPlutusRequest, AssetInfo, AccountData, PoolData, NetworkInformation as ProviderNetworkInformation, Address as ProviderAddress, Transaction as ProviderTransaction, UTxO as OdatanoUtxo, BlockData, AssetHistoryEntry as AssetHistoryEntryProviderData, TransactionConfirmations } from '../utils/types';
|
|
7
7
|
import { type LedgerAnchor, type LedgerLookup } from './ledger-state';
|
|
8
8
|
import type { TxCacheTargets } from '../utils/tx-build-helper';
|
|
9
9
|
/**
|
|
@@ -442,7 +442,16 @@ export declare class CardanoIndexer {
|
|
|
442
442
|
findIndexedTransaction(tx: CapTransaction, txHash: string): Promise<{
|
|
443
443
|
slot: number | null;
|
|
444
444
|
blockHeight: number | null;
|
|
445
|
+
blockHash: string | null;
|
|
445
446
|
} | null>;
|
|
447
|
+
/**
|
|
448
|
+
* Blocks on top of a transaction, its own block included; 0 while it is not on chain.
|
|
449
|
+
* A stored row counts only when its block lies in the crawled chain, because the crawler
|
|
450
|
+
* removes those rows on a rollback. Otherwise height and tip come from the backends.
|
|
451
|
+
*/
|
|
452
|
+
resolveTransactionConfirmations(tx: CapTransaction, txHash: string): Promise<TransactionConfirmations>;
|
|
453
|
+
/** Height of a transaction in a crawled block and the crawler's tip; null when the crawl does not hold it. */
|
|
454
|
+
private crawledTransactionDepth;
|
|
446
455
|
/**
|
|
447
456
|
* Ensure a set of transactions is indexed: DB check, batch fetch of the missing ones, UPSERT.
|
|
448
457
|
* @returns provider transactions for the hashes that had to be fetched
|
|
@@ -117,7 +117,7 @@ class CardanoIndexer {
|
|
|
117
117
|
const cursor = await (0, sync_state_1.readCursor)(tx);
|
|
118
118
|
if (!cursor || cursor.syncStatus !== 'synced' || cursor.startSlot == null || !(0, sync_state_1.isCrawlerLeaseActive)(cursor))
|
|
119
119
|
return null;
|
|
120
|
-
return { fromSlot: cursor.startSlot, lastSlot: cursor.lastSlot, ledger: cursor.utxoSet.status === 'active' };
|
|
120
|
+
return { fromSlot: cursor.startSlot, lastSlot: cursor.lastSlot, tipHeight: cursor.tipHeight, ledger: cursor.utxoSet.status === 'active' };
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
123
|
* Block counts of a pool from crawled blocks (`slotLeader` = pool id): the current epoch when the
|
|
@@ -544,6 +544,8 @@ class CardanoIndexer {
|
|
|
544
544
|
* cannot answer. Runs on `cds.db`, i.e. inside the caller's request transaction when there is one.
|
|
545
545
|
*/
|
|
546
546
|
async localAddressUtxos(address) {
|
|
547
|
+
if (!cds_1.default.db)
|
|
548
|
+
return null;
|
|
547
549
|
return (await this.localAddress(cds_1.default.db, address))?.utxos ?? null;
|
|
548
550
|
}
|
|
549
551
|
/**
|
|
@@ -1789,9 +1791,54 @@ class CardanoIndexer {
|
|
|
1789
1791
|
static ADDR_CONCURRENCY = 5;
|
|
1790
1792
|
/** Block position of a transaction already in the local index (crawled or cached), or null. */
|
|
1791
1793
|
async findIndexedTransaction(tx, txHash) {
|
|
1792
|
-
const row = await tx.run(SELECT.one.from(CardanoODataService_1.Transactions).columns('slot', 'blockHeight').where({ hash: txHash }));
|
|
1794
|
+
const row = await tx.run(SELECT.one.from(CardanoODataService_1.Transactions).columns('slot', 'blockHeight', 'blockHash').where({ hash: txHash }));
|
|
1793
1795
|
return row ?? null;
|
|
1794
1796
|
}
|
|
1797
|
+
/**
|
|
1798
|
+
* Blocks on top of a transaction, its own block included; 0 while it is not on chain.
|
|
1799
|
+
* A stored row counts only when its block lies in the crawled chain, because the crawler
|
|
1800
|
+
* removes those rows on a rollback. Otherwise height and tip come from the backends.
|
|
1801
|
+
*/
|
|
1802
|
+
async resolveTransactionConfirmations(tx, txHash) {
|
|
1803
|
+
const crawled = await this.crawledTransactionDepth(tx, txHash);
|
|
1804
|
+
if (crawled)
|
|
1805
|
+
return { txHash, ...crawled, confirmations: crawled.tipHeight - crawled.blockHeight + 1 };
|
|
1806
|
+
let blockHeight;
|
|
1807
|
+
try {
|
|
1808
|
+
const indexed = await this.indexTransaction(tx, txHash);
|
|
1809
|
+
blockHeight = indexed.blockHeight == null ? null : Number(indexed.blockHeight);
|
|
1810
|
+
}
|
|
1811
|
+
catch (err) {
|
|
1812
|
+
if (!(0, errors_1.isNotFoundOnAllBackends)(err))
|
|
1813
|
+
throw err;
|
|
1814
|
+
blockHeight = null;
|
|
1815
|
+
}
|
|
1816
|
+
if (blockHeight == null)
|
|
1817
|
+
return { txHash, blockHeight: null, tipHeight: null, confirmations: 0 };
|
|
1818
|
+
const tip = await this.client.getLatestBlock();
|
|
1819
|
+
if (tip.height == null)
|
|
1820
|
+
throw new errors_1.ProviderUnavailableError('Chain tip height unknown');
|
|
1821
|
+
// a tip from a backend that lags the one that found the tx counts the tx block only
|
|
1822
|
+
const tipHeight = Math.max(tip.height, blockHeight);
|
|
1823
|
+
return { txHash, blockHeight, tipHeight, confirmations: tipHeight - blockHeight + 1 };
|
|
1824
|
+
}
|
|
1825
|
+
/** Height of a transaction in a crawled block and the crawler's tip; null when the crawl does not hold it. */
|
|
1826
|
+
async crawledTransactionDepth(tx, txHash) {
|
|
1827
|
+
const coverage = await this.localCoverage(tx);
|
|
1828
|
+
if (coverage?.tipHeight == null)
|
|
1829
|
+
return null;
|
|
1830
|
+
const stored = await this.findIndexedTransaction(tx, txHash);
|
|
1831
|
+
if (stored?.blockHeight == null || stored.slot == null || !stored.blockHash)
|
|
1832
|
+
return null;
|
|
1833
|
+
const slot = Number(stored.slot);
|
|
1834
|
+
if (slot < coverage.fromSlot || slot > coverage.lastSlot)
|
|
1835
|
+
return null;
|
|
1836
|
+
const block = await tx.run(SELECT.one.from(CardanoODataService_1.Blocks).columns('hash').where({ hash: stored.blockHash }));
|
|
1837
|
+
if (!block)
|
|
1838
|
+
return null;
|
|
1839
|
+
const blockHeight = Number(stored.blockHeight);
|
|
1840
|
+
return { blockHeight, tipHeight: Math.max(coverage.tipHeight, blockHeight) };
|
|
1841
|
+
}
|
|
1795
1842
|
/**
|
|
1796
1843
|
* Ensure a set of transactions is indexed: DB check, batch fetch of the missing ones, UPSERT.
|
|
1797
1844
|
* @returns provider transactions for the hashes that had to be fetched
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { SignatureVerificationResult, VerificationOptions } from '../../utils/types';
|
|
1
|
+
import { SignatureVerificationResult, TxWitnessVerification, VerificationOptions } from '../../utils/types';
|
|
2
|
+
/**
|
|
3
|
+
* Check every vkey witness of a signed tx against its body hash. Pure, needs no initialize().
|
|
4
|
+
* A tx without vkey witnesses is valid here; which keys had to sign is the caller's check.
|
|
5
|
+
*/
|
|
6
|
+
export declare function verifyTxWitnesses(signedTxCbor: string): TxWitnessVerification;
|
|
2
7
|
/**
|
|
3
8
|
* Verifies externally signed transactions without private keys: CBOR parse, body-hash
|
|
4
9
|
* integrity against the build, required signers present, Ed25519 check per witness.
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SignatureVerifier = void 0;
|
|
7
|
+
exports.verifyTxWitnesses = verifyTxWitnesses;
|
|
7
8
|
exports.getSignatureVerifier = getSignatureVerifier;
|
|
8
9
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
9
10
|
const cbor_1 = require("@harmoniclabs/cbor");
|
|
@@ -24,44 +25,83 @@ function computeBodyHash(txBytes) {
|
|
|
24
25
|
return (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_256)(tx.array[0].subCborRef.toBuffer()));
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* Read vkey witnesses (raw public key + signature bytes) from a transaction's witness set
|
|
29
|
+
* (CBOR array index 1, map key 0). Conway wraps the witness array in CBOR tag 258 (set),
|
|
30
|
+
* which is unwrapped here. `malformed` counts entries that are not a [vkey, signature] byte pair.
|
|
30
31
|
*/
|
|
31
|
-
function
|
|
32
|
+
function readVkeyWitnesses(txBytes) {
|
|
32
33
|
const tx = cbor_1.Cbor.parse(txBytes);
|
|
33
34
|
if (!(tx instanceof cbor_1.CborArray) || !(tx.array[1] instanceof cbor_1.CborMap))
|
|
34
|
-
return [];
|
|
35
|
+
return { witnesses: [], malformed: 0 };
|
|
35
36
|
const entry = tx.array[1].map.find(e => e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0);
|
|
36
37
|
if (!entry)
|
|
37
|
-
return [];
|
|
38
|
+
return { witnesses: [], malformed: 0 };
|
|
38
39
|
let arr = entry.v;
|
|
39
40
|
if (arr instanceof cbor_1.CborTag)
|
|
40
41
|
arr = arr.data;
|
|
41
42
|
if (!(arr instanceof cbor_1.CborArray))
|
|
42
|
-
return [];
|
|
43
|
-
// Skip entries that are not a [vkey, signature] pair of byte strings instead of
|
|
44
|
-
// surfacing an opaque TypeError.
|
|
43
|
+
return { witnesses: [], malformed: 0 };
|
|
45
44
|
const witnesses = [];
|
|
46
|
-
let
|
|
47
|
-
|
|
45
|
+
let malformed = 0;
|
|
46
|
+
arr.array.forEach((pair, index) => {
|
|
48
47
|
if (!(pair instanceof cbor_1.CborArray) || pair.array.length !== 2) {
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
malformed++;
|
|
49
|
+
return;
|
|
51
50
|
}
|
|
52
51
|
const [vk, sg] = pair.array;
|
|
53
52
|
if (!(vk instanceof cbor_1.CborBytes) || !(sg instanceof cbor_1.CborBytes)) {
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
malformed++;
|
|
54
|
+
return;
|
|
56
55
|
}
|
|
57
|
-
witnesses.push({ pubKey: vk.bytes, signature: sg.bytes });
|
|
58
|
-
}
|
|
59
|
-
|
|
56
|
+
witnesses.push({ index, pubKey: vk.bytes, signature: sg.bytes });
|
|
57
|
+
});
|
|
58
|
+
return { witnesses, malformed };
|
|
59
|
+
}
|
|
60
|
+
/** Well-formed vkey witnesses; [] when the tx has none. Malformed entries are skipped with a warning. */
|
|
61
|
+
function extractVkeyWitnesses(txBytes) {
|
|
62
|
+
const { witnesses, malformed } = readVkeyWitnesses(txBytes);
|
|
63
|
+
if (malformed > 0) {
|
|
60
64
|
// not fatal, but a malformed witness in a signed tx is suspicious — surface it
|
|
61
|
-
logger.warn(`Skipped ${
|
|
65
|
+
logger.warn(`Skipped ${malformed} malformed vkey witness entr${malformed === 1 ? 'y' : 'ies'} while verifying (expected [vkey, signature] byte pairs)`);
|
|
62
66
|
}
|
|
63
67
|
return witnesses;
|
|
64
68
|
}
|
|
69
|
+
/** Ed25519 check of one witness over the body hash; false for a key or signature of the wrong length. */
|
|
70
|
+
function signatureValid(w, bodyHashBytes) {
|
|
71
|
+
try {
|
|
72
|
+
return (0, crypto_1.verifyEd25519Signature_sync)(w.signature, bodyHashBytes, w.pubKey);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check every vkey witness of a signed tx against its body hash. Pure, needs no initialize().
|
|
80
|
+
* A tx without vkey witnesses is valid here; which keys had to sign is the caller's check.
|
|
81
|
+
*/
|
|
82
|
+
function verifyTxWitnesses(signedTxCbor) {
|
|
83
|
+
const errors = [];
|
|
84
|
+
const signerKeyHashes = [];
|
|
85
|
+
let txBodyHash = null;
|
|
86
|
+
try {
|
|
87
|
+
const txBytes = (0, uint8array_utils_1.fromHex)(signedTxCbor);
|
|
88
|
+
txBodyHash = computeBodyHash(txBytes);
|
|
89
|
+
const bodyHashBytes = (0, uint8array_utils_1.fromHex)(txBodyHash);
|
|
90
|
+
const { witnesses, malformed } = readVkeyWitnesses(txBytes);
|
|
91
|
+
if (malformed > 0)
|
|
92
|
+
errors.push(`${malformed} vkey witness entr${malformed === 1 ? 'y is' : 'ies are'} not a [vkey, signature] byte pair`);
|
|
93
|
+
for (const w of witnesses) {
|
|
94
|
+
if (signatureValid(w, bodyHashBytes))
|
|
95
|
+
signerKeyHashes.push((0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_224)(w.pubKey)));
|
|
96
|
+
else
|
|
97
|
+
errors.push(`Invalid signature at witness index ${w.index}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
errors.push(`Failed to read transaction: ${error instanceof Error ? error.message : String(error)}`);
|
|
102
|
+
}
|
|
103
|
+
return { valid: errors.length === 0, txBodyHash, signerKeyHashes, errors };
|
|
104
|
+
}
|
|
65
105
|
/**
|
|
66
106
|
* Verifies externally signed transactions without private keys: CBOR parse, body-hash
|
|
67
107
|
* integrity against the build, required signers present, Ed25519 check per witness.
|
|
@@ -120,11 +160,9 @@ class SignatureVerifier {
|
|
|
120
160
|
// verify each signature cryptographically against the transaction body hash
|
|
121
161
|
if (vkeyWitnesses.length > 0) {
|
|
122
162
|
const bodyHashBytes = (0, uint8array_utils_1.fromHex)(computedHash);
|
|
123
|
-
for (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (!isValidSig) {
|
|
127
|
-
result.errorMessage = `Invalid signature at witness index ${i}. The signature does not match the transaction body.`;
|
|
163
|
+
for (const w of vkeyWitnesses) {
|
|
164
|
+
if (!signatureValid(w, bodyHashBytes)) {
|
|
165
|
+
result.errorMessage = `Invalid signature at witness index ${w.index}. The signature does not match the transaction body.`;
|
|
128
166
|
logger.warn(result.errorMessage);
|
|
129
167
|
return result;
|
|
130
168
|
}
|
|
@@ -90,6 +90,13 @@ export declare class BuildooorTxBuilder implements CardanoTxBuilder {
|
|
|
90
90
|
* which mismatches once the on-chain cost model grows). Recomputed even when units match.
|
|
91
91
|
*/
|
|
92
92
|
private _stampExecUnits;
|
|
93
|
+
/** Language views the scriptDataHash covers, from the chain's cost models. */
|
|
94
|
+
private _languageViews;
|
|
95
|
+
/**
|
|
96
|
+
* Check a witness datum against the datum hash its script UTxO is locked with: the ledger
|
|
97
|
+
* finds the datum by the hash of its bytes. Inline-datum UTxOs need no witness datum.
|
|
98
|
+
*/
|
|
99
|
+
private _checkWitnessDatum;
|
|
93
100
|
/**
|
|
94
101
|
* Language-view selection for scriptDataHash, mirroring Buildooor's initTxBuild
|
|
95
102
|
* (which flags the languages of *executed* scripts). This builder only attaches
|
|
@@ -368,6 +368,9 @@ class BuildooorTxBuilder {
|
|
|
368
368
|
const datum = plutusScriptExecution.datum
|
|
369
369
|
? (0, tx_build_helper_1.jsonToPlutusData)((0, plutus_placeholders_1.resolveIndexPlaceholders)(plutusScriptExecution.datum, resolveCtx))
|
|
370
370
|
: "inline";
|
|
371
|
+
if (datum !== "inline") {
|
|
372
|
+
this._checkWitnessDatum(scriptOdatanoUtxo, (0, plutus_data_1.dataToCbor)(datum), 'datumJson', '; BuildPlutusTransaction takes the datum as datumCbor with the bytes the UTxO was locked with');
|
|
373
|
+
}
|
|
371
374
|
const resolvedPrimaryInlineDatum = req.inlineDatum
|
|
372
375
|
? (0, plutus_placeholders_1.resolveIndexPlaceholders)(req.inlineDatum, resolveCtx)
|
|
373
376
|
: undefined;
|
|
@@ -591,10 +594,20 @@ class BuildooorTxBuilder {
|
|
|
591
594
|
const sortedInputs = this._computeSortedInputs(req.scriptInputs, forced, this._extractFundingRefs(selectedFundingInputs));
|
|
592
595
|
const sortedWithdrawals = this._ledgerWithdrawalOrder(withdrawalEntries);
|
|
593
596
|
const resolveCtx = { sortedInputs, sortedReferenceInputs, sortedWithdrawals };
|
|
594
|
-
const
|
|
597
|
+
const witnessDatums = [];
|
|
598
|
+
const scriptInputs = scriptEntries.map(({ si, utxo, script, refLedgerUtxo }, i) => {
|
|
595
599
|
const redeemer = si.redeemerCbor ? (0, plutus_data_1.dataFromCbor)(si.redeemerCbor) : (0, tx_build_helper_1.jsonToPlutusData)((0, plutus_placeholders_1.resolveIndexPlaceholders)(si.redeemer, resolveCtx));
|
|
596
|
-
|
|
597
|
-
|
|
600
|
+
let datum = "inline";
|
|
601
|
+
if (si.datumCbor) {
|
|
602
|
+
const bytes = Buffer.from(si.datumCbor, 'hex');
|
|
603
|
+
this._checkWitnessDatum(utxo, bytes, `scriptInputs[${i}].datumCbor`, '');
|
|
604
|
+
witnessDatums.push(bytes);
|
|
605
|
+
datum = (0, plutus_data_1.dataFromCbor)(bytes);
|
|
606
|
+
}
|
|
607
|
+
else if (si.datum !== undefined) {
|
|
608
|
+
datum = (0, tx_build_helper_1.jsonToPlutusData)((0, plutus_placeholders_1.resolveIndexPlaceholders)(si.datum, resolveCtx));
|
|
609
|
+
this._checkWitnessDatum(utxo, (0, plutus_data_1.dataToCbor)(datum), `scriptInputs[${i}].datumJson`, '; pass datumCbor with the bytes the UTxO was locked with');
|
|
610
|
+
}
|
|
598
611
|
const ledgerUtxo = this._mapMultiAssetUtxoToLedgerUtxo(utxo);
|
|
599
612
|
return script
|
|
600
613
|
? { utxo: ledgerUtxo, inputScript: { script, datum, redeemer } }
|
|
@@ -634,7 +647,7 @@ class BuildooorTxBuilder {
|
|
|
634
647
|
...(withdrawals.length > 0 && { withdrawals }),
|
|
635
648
|
...(certificates.length > 0 && { certificates })
|
|
636
649
|
};
|
|
637
|
-
const tx = await this._buildScriptTx(buildParams, ctx.evaluateTransaction, callerDatums);
|
|
650
|
+
const tx = await this._buildScriptTx(buildParams, ctx.evaluateTransaction, callerDatums, witnessDatums);
|
|
638
651
|
const details = this._extractTxDetails(tx);
|
|
639
652
|
const maxTxSize = Number(this.txBuilder.protocolParamters.maxTxSize);
|
|
640
653
|
if (details.sizeBytes > maxTxSize) {
|
|
@@ -759,7 +772,7 @@ class BuildooorTxBuilder {
|
|
|
759
772
|
* budgets and ignores caller-supplied units, so build once, evaluate via Ogmios when available,
|
|
760
773
|
* rebuild with a fee floor for the target units, then stamp them and recompute scriptDataHash.
|
|
761
774
|
*/
|
|
762
|
-
async _buildScriptTx(buildParams, evaluator, callerDatums = new Map()) {
|
|
775
|
+
async _buildScriptTx(buildParams, evaluator, callerDatums = new Map(), witnessDatums = []) {
|
|
763
776
|
const pass1Failures = [];
|
|
764
777
|
const tx1 = await this.txBuilder.build(buildParams, makeScriptBuildOpts(pass1Failures));
|
|
765
778
|
if (!tx1) {
|
|
@@ -783,13 +796,14 @@ class BuildooorTxBuilder {
|
|
|
783
796
|
const feeFloor = BigInt(tx1.body.fee.toString())
|
|
784
797
|
+ this._exUnitsPriceDelta(rdmrs1, targets1)
|
|
785
798
|
+ this._exUnitsSizeDelta(rdmrs1, targets1) * this._txFeePerByte()
|
|
786
|
-
+ BigInt((0, caller_datums_1.callerDatumsGrowth)(callerDatums)) * this._txFeePerByte()
|
|
799
|
+
+ BigInt((0, caller_datums_1.callerDatumsGrowth)(callerDatums) + (0, caller_datums_1.witnessDatumsGrowth)(witnessDatums)) * this._txFeePerByte()
|
|
787
800
|
+ 10n * this._txFeePerByte();
|
|
788
801
|
const pass2Failures = [];
|
|
789
802
|
const tx2 = await this.txBuilder.build({ ...buildParams, fee: feeFloor }, makeScriptBuildOpts(pass2Failures));
|
|
790
803
|
const rdmrs2 = tx2.witnesses.redeemers ?? [];
|
|
791
804
|
const targets2 = this._resolveTargetExUnits(rdmrs2, evaluatedUnits, pass2Failures);
|
|
792
|
-
|
|
805
|
+
const tx = (0, caller_datums_1.writeCallerDatums)(this._stampExecUnits(tx2, targets2), callerDatums);
|
|
806
|
+
return (0, caller_datums_1.writeWitnessDatums)(tx, witnessDatums, this._languageViews(tx));
|
|
793
807
|
}
|
|
794
808
|
/**
|
|
795
809
|
* Evaluate via Ogmios; returns cushioned budgets keyed `tag:index`, or undefined when the
|
|
@@ -921,8 +935,7 @@ class BuildooorTxBuilder {
|
|
|
921
935
|
execUnits: new buildooor_1.ExBudget({ mem: targets[i].mem, cpu: targets[i].cpu })
|
|
922
936
|
}));
|
|
923
937
|
const newWitnesses = new cardano_ledger_ts_1.TxWitnessSet({ ...tx.witnesses, vkeyWitnesses: [], redeemers: stamped });
|
|
924
|
-
const
|
|
925
|
-
const newBody = new cardano_ledger_ts_1.TxBody({ ...tx.body, scriptDataHash: (0, buildooor_1.getScriptDataHash)(newWitnesses, languageViews) });
|
|
938
|
+
const newBody = new cardano_ledger_ts_1.TxBody({ ...tx.body, scriptDataHash: (0, buildooor_1.getScriptDataHash)(newWitnesses, this._languageViews(tx)) });
|
|
926
939
|
const finalTx = new cardano_ledger_ts_1.Tx({ ...tx, body: newBody, witnesses: newWitnesses });
|
|
927
940
|
if (!unchanged) {
|
|
928
941
|
logger.info(`Stamped execution units into ${stamped.length} redeemer(s): ` +
|
|
@@ -930,6 +943,22 @@ class BuildooorTxBuilder {
|
|
|
930
943
|
}
|
|
931
944
|
return finalTx;
|
|
932
945
|
}
|
|
946
|
+
/** Language views the scriptDataHash covers, from the chain's cost models. */
|
|
947
|
+
_languageViews(tx) {
|
|
948
|
+
return (0, buildooor_1.costModelsToLanguageViewCbor)(this._languageViewCostModels(), this._usedLanguageViewOpts(tx));
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Check a witness datum against the datum hash its script UTxO is locked with: the ledger
|
|
952
|
+
* finds the datum by the hash of its bytes. Inline-datum UTxOs need no witness datum.
|
|
953
|
+
*/
|
|
954
|
+
_checkWitnessDatum(utxo, datum, field, hint) {
|
|
955
|
+
if (!utxo.datumHash || utxo.inlineDatum)
|
|
956
|
+
return;
|
|
957
|
+
const hash = (0, caller_datums_1.datumHashOf)(datum);
|
|
958
|
+
if (hash !== utxo.datumHash.toLowerCase()) {
|
|
959
|
+
throw new errors_1.TransactionValidationError(`${field} hashes to ${hash}, but ${utxo.txHash}#${utxo.outputIndex} is locked with datum hash ${utxo.datumHash}${hint}`);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
933
962
|
/**
|
|
934
963
|
* Language-view selection for scriptDataHash, mirroring Buildooor's initTxBuild
|
|
935
964
|
* (which flags the languages of *executed* scripts). This builder only attaches
|
|
@@ -14,4 +14,16 @@ export declare function callerDatumsGrowth(datums: CallerDatums): number;
|
|
|
14
14
|
* Only the datum bytes change. Containers in CBOR count items, not bytes, so the rest stays valid.
|
|
15
15
|
*/
|
|
16
16
|
export declare function writeCallerDatums(tx: Tx, datums: CallerDatums): Tx;
|
|
17
|
+
/** Datum hash as the ledger computes it: blake2b-256 of the datum bytes. */
|
|
18
|
+
export declare function datumHashOf(datum: Uint8Array): string;
|
|
19
|
+
/** Bytes the witness set gains from the caller's datums, never below zero. */
|
|
20
|
+
export declare function witnessDatumsGrowth(datums: Uint8Array[]): number;
|
|
21
|
+
/**
|
|
22
|
+
* Replace Buildooor's encoding of the witness datums with the caller's bytes, then recompute
|
|
23
|
+
* scriptDataHash over redeemers, datums and language views as they now stand in the transaction.
|
|
24
|
+
* The ledger finds a witness datum by the hash of its bytes, so a re-encoded datum is missing to it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function writeWitnessDatums(tx: Tx, datums: Uint8Array[], languageViews: Uint8Array): Tx;
|
|
27
|
+
/** scriptDataHash of a transaction over its redeemer and datum bytes as they stand, laid out like Buildooor's getScriptDataHash. */
|
|
28
|
+
export declare function scriptDataHashOf(txBytes: Uint8Array, languageViews: Uint8Array): Uint8Array;
|
|
17
29
|
//# sourceMappingURL=caller-datums.d.ts.map
|
|
@@ -3,9 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.callerDatumGrowth = callerDatumGrowth;
|
|
4
4
|
exports.callerDatumsGrowth = callerDatumsGrowth;
|
|
5
5
|
exports.writeCallerDatums = writeCallerDatums;
|
|
6
|
+
exports.datumHashOf = datumHashOf;
|
|
7
|
+
exports.witnessDatumsGrowth = witnessDatumsGrowth;
|
|
8
|
+
exports.writeWitnessDatums = writeWitnessDatums;
|
|
9
|
+
exports.scriptDataHashOf = scriptDataHashOf;
|
|
6
10
|
const cbor_1 = require("@harmoniclabs/cbor");
|
|
7
11
|
const plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
8
12
|
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
13
|
+
const crypto_1 = require("@harmoniclabs/crypto");
|
|
9
14
|
const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
10
15
|
/** Output map entry `2 => [1, #6.24(datum)]` that holds an inline datum. */
|
|
11
16
|
function inlineDatumEntry(datum) {
|
|
@@ -47,4 +52,88 @@ function writeCallerDatums(tx, datums) {
|
|
|
47
52
|
}
|
|
48
53
|
return cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.toHex)(bytes));
|
|
49
54
|
}
|
|
55
|
+
/** Datum hash as the ledger computes it: blake2b-256 of the datum bytes. */
|
|
56
|
+
function datumHashOf(datum) {
|
|
57
|
+
return (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_256)(datum));
|
|
58
|
+
}
|
|
59
|
+
/** Bytes the witness set gains from the caller's datums, never below zero. */
|
|
60
|
+
function witnessDatumsGrowth(datums) {
|
|
61
|
+
let growth = 0;
|
|
62
|
+
for (const datum of datums)
|
|
63
|
+
growth += datum.length - (0, plutus_data_1.dataToCbor)((0, plutus_data_1.dataFromCbor)(datum)).length;
|
|
64
|
+
return Math.max(0, growth);
|
|
65
|
+
}
|
|
66
|
+
/** End offset of a parsed item; a tag carries no offset of its own, its content does. */
|
|
67
|
+
function endOf(item) {
|
|
68
|
+
let inner = item;
|
|
69
|
+
while (inner instanceof cbor_1.CborTag)
|
|
70
|
+
inner = inner.data;
|
|
71
|
+
return inner.subCborRef.end;
|
|
72
|
+
}
|
|
73
|
+
/** Length of a CBOR item head, from its first byte. */
|
|
74
|
+
function headLength(first) {
|
|
75
|
+
const info = first & 0x1f;
|
|
76
|
+
return info < 24 || info === 31 ? 1 : info === 24 ? 2 : info === 25 ? 3 : info === 26 ? 5 : 9;
|
|
77
|
+
}
|
|
78
|
+
function entryOf(map, key) {
|
|
79
|
+
return map.map.find(e => e.k instanceof cbor_1.CborUInt && Number(e.k.num) === key);
|
|
80
|
+
}
|
|
81
|
+
/** Bytes of a map entry's value as they stand in `bytes`. */
|
|
82
|
+
function valueBytes(bytes, entry) {
|
|
83
|
+
return bytes.subarray(entry.k.subCborRef.end, endOf(entry.v));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Replace Buildooor's encoding of the witness datums with the caller's bytes, then recompute
|
|
87
|
+
* scriptDataHash over redeemers, datums and language views as they now stand in the transaction.
|
|
88
|
+
* The ledger finds a witness datum by the hash of its bytes, so a re-encoded datum is missing to it.
|
|
89
|
+
*/
|
|
90
|
+
function writeWitnessDatums(tx, datums, languageViews) {
|
|
91
|
+
const wanted = new Map();
|
|
92
|
+
for (const datum of datums) {
|
|
93
|
+
const built = (0, uint8array_utils_1.toHex)((0, plutus_data_1.dataToCbor)((0, plutus_data_1.dataFromCbor)(datum)));
|
|
94
|
+
if (built !== (0, uint8array_utils_1.toHex)(datum))
|
|
95
|
+
wanted.set(built, datum);
|
|
96
|
+
}
|
|
97
|
+
if (wanted.size === 0)
|
|
98
|
+
return tx;
|
|
99
|
+
let bytes = Buffer.from(tx.toCbor());
|
|
100
|
+
let root = cbor_1.Cbor.parse(bytes, { keepRef: true });
|
|
101
|
+
const datumsEntry = entryOf(root.array[1], 4);
|
|
102
|
+
let list = datumsEntry?.v;
|
|
103
|
+
while (list instanceof cbor_1.CborTag)
|
|
104
|
+
list = list.data;
|
|
105
|
+
if (!(list instanceof cbor_1.CborArray))
|
|
106
|
+
throw new Error('the built transaction carries no witness datums');
|
|
107
|
+
// Rebuild the datum list item by item: head, items, and the break byte of an indefinite list
|
|
108
|
+
const listStart = list.subCborRef.start;
|
|
109
|
+
const listEnd = list.subCborRef.end;
|
|
110
|
+
let at = listStart + headLength(bytes[listStart]);
|
|
111
|
+
const parts = [bytes.subarray(listStart, at)];
|
|
112
|
+
for (const item of list.array) {
|
|
113
|
+
const end = endOf(item);
|
|
114
|
+
parts.push(wanted.get((0, uint8array_utils_1.toHex)(bytes.subarray(at, end))) ?? bytes.subarray(at, end));
|
|
115
|
+
at = end;
|
|
116
|
+
}
|
|
117
|
+
parts.push(bytes.subarray(at, listEnd));
|
|
118
|
+
bytes = Buffer.concat([bytes.subarray(0, listStart), ...parts, bytes.subarray(listEnd)]);
|
|
119
|
+
root = cbor_1.Cbor.parse(bytes, { keepRef: true });
|
|
120
|
+
const hashEntry = entryOf(root.array[0], 11);
|
|
121
|
+
if (!hashEntry)
|
|
122
|
+
throw new Error('the built transaction carries no scriptDataHash');
|
|
123
|
+
bytes.set(scriptDataHashOf(bytes, languageViews), endOf(hashEntry.v) - 32);
|
|
124
|
+
return cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.toHex)(bytes));
|
|
125
|
+
}
|
|
126
|
+
/** scriptDataHash of a transaction over its redeemer and datum bytes as they stand, laid out like Buildooor's getScriptDataHash. */
|
|
127
|
+
function scriptDataHashOf(txBytes, languageViews) {
|
|
128
|
+
const bytes = Buffer.from(txBytes);
|
|
129
|
+
const witnesses = cbor_1.Cbor.parse(bytes, { keepRef: true }).array[1];
|
|
130
|
+
const redeemers = entryOf(witnesses, 5);
|
|
131
|
+
const datums = entryOf(witnesses, 4);
|
|
132
|
+
if (!redeemers && !datums)
|
|
133
|
+
throw new Error('the transaction carries no redeemers and no datums');
|
|
134
|
+
const datumBytes = datums ? valueBytes(bytes, datums) : Buffer.alloc(0);
|
|
135
|
+
return (0, crypto_1.blake2b_256)(redeemers
|
|
136
|
+
? Buffer.concat([valueBytes(bytes, redeemers), datumBytes, languageViews])
|
|
137
|
+
: Buffer.concat([Buffer.from([0xa0]), datumBytes, Buffer.from([0xa0])]));
|
|
138
|
+
}
|
|
50
139
|
//# sourceMappingURL=caller-datums.js.map
|
package/srv/cardano-service.cds
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
using {odatano.cardano as db} from '../db/schema';
|
|
2
|
-
using { Blake2b256, Bech32, AssetUnit, ParsedTransaction } from '../db/types';
|
|
2
|
+
using { Blake2b256, Bech32, AssetUnit, ParsedTransaction, TransactionConfirmations } from '../db/types';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Cardano OData Service
|
|
@@ -258,6 +258,13 @@ service CardanoODataService @(impl: './cardano-service') {
|
|
|
258
258
|
@description: 'The unique identifier of the transaction'
|
|
259
259
|
hash: Blake2b256) returns Transactions;
|
|
260
260
|
|
|
261
|
+
@title : 'Get Transaction Confirmations'
|
|
262
|
+
@description: 'Number of blocks on top of a transaction, its own block included; 0 while it is not on chain. Uses the crawled chain when the crawler is synced, else the backends.'
|
|
263
|
+
action GetTransactionConfirmations(
|
|
264
|
+
@title: 'Transaction Hash'
|
|
265
|
+
@description: 'The unique identifier of the transaction'
|
|
266
|
+
txHash: Blake2b256) returns TransactionConfirmations;
|
|
267
|
+
|
|
261
268
|
@title : 'Get Transaction Metadata by Tx Hash'
|
|
262
269
|
@description: 'Retrieve transaction metadata using the Transaction Hash'
|
|
263
270
|
action GetMetadataByTxHash(
|
package/srv/cardano-service.js
CHANGED
|
@@ -257,6 +257,14 @@ module.exports = (srv) => {
|
|
|
257
257
|
// ---------------------------------------------------------------------------
|
|
258
258
|
srv.on('READ', Transactions, indexOnMissRead(Transactions, 'hash', validators_1.isTxHash, (db, h) => indexer().indexTransaction(db, h), { errorMessage: 'Invalid transaction hash format' }));
|
|
259
259
|
srv.on('GetTransactionByHash', indexOnMissAction('GetTransactionByHash', Transactions, 'hash', validators_1.isTxHash, (db, h) => indexer().indexTransaction(db, h), { errorMessage: 'Invalid transaction hash format' }));
|
|
260
|
+
srv.on('GetTransactionConfirmations', async (req) => {
|
|
261
|
+
const { txHash } = req.data;
|
|
262
|
+
if (!txHash)
|
|
263
|
+
(0, errors_1.rejectMissing)(req, 'GetTransactionConfirmations', 'txHash');
|
|
264
|
+
if (!(0, validators_1.isTxHash)(txHash))
|
|
265
|
+
(0, errors_1.rejectInvalid)(req, 'GetTransactionConfirmations', 'Invalid transaction hash format', 'txHash');
|
|
266
|
+
return (0, backend_request_handler_1.handleRequest)(req, (db) => indexer().resolveTransactionConfirmations(db, txHash));
|
|
267
|
+
});
|
|
260
268
|
// ---------------------------------------------------------------------------
|
|
261
269
|
// Transaction Metadata
|
|
262
270
|
// ---------------------------------------------------------------------------
|
package/srv/cbor/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { parseTransaction, type ParsedTransaction, type ParsedInput, type ParsedOutput, type ParsedAsset, type ParsedWitnesses, } from './parse';
|
|
1
|
+
export { parseTransaction, type ParsedTransaction, type ParsedInput, type ParsedOutput, type ParsedAsset, type ParsedWitnesses, type ParsedWithdrawal, type ParsedCertificate, } from './parse';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/srv/cbor/parse.d.ts
CHANGED
|
@@ -15,6 +15,19 @@ export interface ParsedOutput {
|
|
|
15
15
|
datumHash: string | null;
|
|
16
16
|
inlineDatumHex: string | null;
|
|
17
17
|
referenceScriptHex: string | null;
|
|
18
|
+
/** Byte length of the output as it stands in the transaction. */
|
|
19
|
+
cborSize: number;
|
|
20
|
+
}
|
|
21
|
+
export interface ParsedWithdrawal {
|
|
22
|
+
/** Bech32 reward address. */
|
|
23
|
+
rewardAddress: string;
|
|
24
|
+
lovelace: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ParsedCertificate {
|
|
27
|
+
/** Position in the body's certificate list. */
|
|
28
|
+
index: number;
|
|
29
|
+
/** Ledger certificate name, e.g. `StakeDelegation` or `RegistrationDrep`. */
|
|
30
|
+
type: string;
|
|
18
31
|
}
|
|
19
32
|
export interface ParsedWitnesses {
|
|
20
33
|
vkeyCount: number;
|
|
@@ -35,6 +48,8 @@ export interface ParsedTransaction {
|
|
|
35
48
|
* consumer needing that split must compare against the service network.
|
|
36
49
|
*/
|
|
37
50
|
network: 'mainnet' | 'testnet' | null;
|
|
51
|
+
/** Body field 15: 1 = mainnet, 0 = testnet, null if absent. */
|
|
52
|
+
networkId: number | null;
|
|
38
53
|
inputs: ParsedInput[];
|
|
39
54
|
outputs: ParsedOutput[];
|
|
40
55
|
/** Validity-interval start slot (decimal string) or `null` if absent. */
|
|
@@ -48,6 +63,16 @@ export interface ParsedTransaction {
|
|
|
48
63
|
/** Metadata labels present (uint64 → decimal string); full payload via GetMetadataByTxHash for submitted txs. */
|
|
49
64
|
metadataLabels: string[];
|
|
50
65
|
collateral: ParsedInput[];
|
|
66
|
+
referenceInputs: ParsedInput[];
|
|
67
|
+
withdrawals: ParsedWithdrawal[];
|
|
68
|
+
certificates: ParsedCertificate[];
|
|
69
|
+
/** Number of votes over all voters; 0 if the body has no voting procedures. */
|
|
70
|
+
votingProcedures: number;
|
|
71
|
+
proposalProcedures: number;
|
|
72
|
+
/** Lovelace (decimal string) or `null` if absent. */
|
|
73
|
+
treasuryDonation: string | null;
|
|
74
|
+
/** Lovelace (decimal string) or `null` if absent. */
|
|
75
|
+
currentTreasuryValue: string | null;
|
|
51
76
|
/** 28-byte Ed25519 key hashes listed in the tx body's required_signers field. */
|
|
52
77
|
requiredSigners: string[];
|
|
53
78
|
scriptDataHash: string | null;
|
package/srv/cbor/parse.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseTransaction = parseTransaction;
|
|
4
4
|
const buildooor_1 = require("@harmoniclabs/buildooor");
|
|
5
|
+
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
5
6
|
const cbor_1 = require("@harmoniclabs/cbor");
|
|
6
7
|
const errors_1 = require("../utils/errors");
|
|
7
8
|
const error_codes_1 = require("../utils/error-codes");
|
|
@@ -14,8 +15,12 @@ const error_codes_1 = require("../utils/error-codes");
|
|
|
14
15
|
*/
|
|
15
16
|
function parseTransaction(cborHex) {
|
|
16
17
|
let tx;
|
|
18
|
+
let raw;
|
|
17
19
|
try {
|
|
18
|
-
|
|
20
|
+
// one decode for both readers; keepRef keeps the original bytes for the body hash and datums
|
|
21
|
+
const parsed = cbor_1.Cbor.parse(Buffer.from(cborHex, 'hex'), { keepRef: true });
|
|
22
|
+
tx = buildooor_1.Tx.fromCborObj(parsed);
|
|
23
|
+
raw = readBodyFields(parsed);
|
|
19
24
|
}
|
|
20
25
|
catch (e) {
|
|
21
26
|
const msg = e instanceof Error ? e.message : String(e);
|
|
@@ -25,6 +30,7 @@ function parseTransaction(cborHex) {
|
|
|
25
30
|
return {
|
|
26
31
|
txHash: body.hash.toString(),
|
|
27
32
|
network: normalizeNetwork(body.network),
|
|
33
|
+
networkId: raw.networkId,
|
|
28
34
|
inputs: body.inputs.map(mapInput),
|
|
29
35
|
outputs: body.outputs.map(mapOutput),
|
|
30
36
|
validityStart: body.validityIntervalStart != null ? body.validityIntervalStart.toString() : null,
|
|
@@ -33,6 +39,16 @@ function parseTransaction(cborHex) {
|
|
|
33
39
|
mint: mapMint(body.mint),
|
|
34
40
|
metadataLabels: extractMetadataLabels(tx.auxiliaryData),
|
|
35
41
|
collateral: (body.collateralInputs ?? []).map(mapInput),
|
|
42
|
+
referenceInputs: (body.refInputs ?? []).map(mapInput),
|
|
43
|
+
withdrawals: (body.withdrawals?.map ?? []).map((w) => ({
|
|
44
|
+
rewardAddress: w.rewardAccount.toString(),
|
|
45
|
+
lovelace: w.amount.toString(),
|
|
46
|
+
})),
|
|
47
|
+
certificates: (body.certs ?? []).map(mapCertificate),
|
|
48
|
+
votingProcedures: raw.votingProcedures,
|
|
49
|
+
proposalProcedures: raw.proposalProcedures,
|
|
50
|
+
treasuryDonation: raw.treasuryDonation,
|
|
51
|
+
currentTreasuryValue: raw.currentTreasuryValue,
|
|
36
52
|
requiredSigners: (body.requiredSigners ?? []).map((s) => s.toString()),
|
|
37
53
|
scriptDataHash: body.scriptDataHash ? body.scriptDataHash.toString() : null,
|
|
38
54
|
witnesses: countWitnesses(tx.witnesses),
|
|
@@ -80,8 +96,39 @@ function mapOutput(out) {
|
|
|
80
96
|
datumHash,
|
|
81
97
|
inlineDatumHex,
|
|
82
98
|
referenceScriptHex,
|
|
99
|
+
cborSize: out.toCborBytes().length,
|
|
83
100
|
};
|
|
84
101
|
}
|
|
102
|
+
function mapCertificate(cert, index) {
|
|
103
|
+
return { index, type: (0, cardano_ledger_ts_1.certTypeToString)(cert.certType) };
|
|
104
|
+
}
|
|
105
|
+
/** Body fields 15 and 19 to 22 as they stand in the bytes. `Tx.fromCbor` drops 19 to 22 and maps any network byte other than 0 to mainnet. */
|
|
106
|
+
function readBodyFields(parsed) {
|
|
107
|
+
const body = parsed instanceof cbor_1.CborArray ? parsed.array[0] : undefined;
|
|
108
|
+
const field = (key) => body instanceof cbor_1.CborMap ? body.map.find(e => e.k instanceof cbor_1.CborUInt && e.k.num === BigInt(key))?.v : undefined;
|
|
109
|
+
const uint = (key) => {
|
|
110
|
+
const v = field(key);
|
|
111
|
+
return v instanceof cbor_1.CborUInt ? v.num : null;
|
|
112
|
+
};
|
|
113
|
+
// voting_procedures = { voter => { gov_action_id => voting_procedure } }
|
|
114
|
+
const voting = field(19);
|
|
115
|
+
const votes = voting instanceof cbor_1.CborMap
|
|
116
|
+
? voting.map.reduce((n, e) => n + (e.v instanceof cbor_1.CborMap ? e.v.map.length : 0), 0)
|
|
117
|
+
: 0;
|
|
118
|
+
const networkId = uint(15);
|
|
119
|
+
return {
|
|
120
|
+
networkId: networkId == null ? null : Number(networkId),
|
|
121
|
+
votingProcedures: votes,
|
|
122
|
+
proposalProcedures: setItems(field(20)).length,
|
|
123
|
+
treasuryDonation: uint(22)?.toString() ?? null,
|
|
124
|
+
currentTreasuryValue: uint(21)?.toString() ?? null,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/** Items of a CBOR set, with or without the Conway set tag 258. */
|
|
128
|
+
function setItems(obj) {
|
|
129
|
+
const inner = obj instanceof cbor_1.CborTag ? obj.data : obj;
|
|
130
|
+
return inner instanceof cbor_1.CborArray ? inner.array : [];
|
|
131
|
+
}
|
|
85
132
|
/** Inline datum bytes as they stand in the transaction; decoding and re-encoding may change them. */
|
|
86
133
|
function inlineDatumBytes(out) {
|
|
87
134
|
if (!out.cborRef)
|
package/srv/server.js
CHANGED
|
@@ -546,6 +546,9 @@ async function startWalletWorkerIfConfigured() {
|
|
|
546
546
|
async function redriveInterruptedSubmissionsIfConfigured() {
|
|
547
547
|
if (process_1.env.SKIP_AUTO_INIT === 'true' || !appContext)
|
|
548
548
|
return;
|
|
549
|
+
// Without a database there are no signing requests to re-drive
|
|
550
|
+
if (!cds_1.default.db)
|
|
551
|
+
return;
|
|
549
552
|
try {
|
|
550
553
|
const { redriveInterruptedSubmissions } = require('./blockchain/signing/submission-finalizer');
|
|
551
554
|
const attempted = await redriveInterruptedSubmissions();
|
|
@@ -5,9 +5,16 @@ export declare function epochOfSlot(network: EpochNetwork, slot: number): number
|
|
|
5
5
|
/** First absolute slot of an epoch, from the network's Shelley anchor. */
|
|
6
6
|
export declare function epochStartSlot(network: EpochNetwork, epoch: number): number;
|
|
7
7
|
/**
|
|
8
|
-
* Absolute POSIX
|
|
8
|
+
* Absolute POSIX milliseconds for a slot via the Shelley-anchored genesis infos (exact for Shelley-era
|
|
9
9
|
* slots). Ogmios' `eraStart.time` is RelativeTime since system start, not a Unix timestamp.
|
|
10
10
|
*/
|
|
11
|
+
export declare function slotToPosixMs(network: EpochNetwork, slot: number): number;
|
|
12
|
+
/** Absolute POSIX seconds for a slot, rounded down. */
|
|
11
13
|
export declare function slotToPosixSeconds(network: EpochNetwork, slot: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Slot that contains a POSIX time in milliseconds.
|
|
16
|
+
* @throws RangeError for a time before the Shelley start, where slots were 20 s long.
|
|
17
|
+
*/
|
|
18
|
+
export declare function posixToSlot(network: EpochNetwork, posixMs: number): number;
|
|
12
19
|
export {};
|
|
13
20
|
//# sourceMappingURL=epoch-slots.d.ts.map
|
package/srv/utils/epoch-slots.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.epochOfSlot = epochOfSlot;
|
|
4
4
|
exports.epochStartSlot = epochStartSlot;
|
|
5
|
+
exports.slotToPosixMs = slotToPosixMs;
|
|
5
6
|
exports.slotToPosixSeconds = slotToPosixSeconds;
|
|
7
|
+
exports.posixToSlot = posixToSlot;
|
|
6
8
|
const const_1 = require("./const");
|
|
7
9
|
/** Epoch a slot belongs to, from the network's Shelley anchor. */
|
|
8
10
|
function epochOfSlot(network, slot) {
|
|
@@ -15,11 +17,27 @@ function epochStartSlot(network, epoch) {
|
|
|
15
17
|
return cfg.shelleyStartSlot + (epoch - cfg.shelleyStartEpoch) * cfg.slotsPerEpoch;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
|
-
* Absolute POSIX
|
|
20
|
+
* Absolute POSIX milliseconds for a slot via the Shelley-anchored genesis infos (exact for Shelley-era
|
|
19
21
|
* slots). Ogmios' `eraStart.time` is RelativeTime since system start, not a Unix timestamp.
|
|
20
22
|
*/
|
|
23
|
+
function slotToPosixMs(network, slot) {
|
|
24
|
+
const genesis = const_1.GENESIS_INFOS_BY_NETWORK[network];
|
|
25
|
+
return genesis.systemStartPosixMs + (slot - genesis.startSlotNo) * genesis.slotLengthMs;
|
|
26
|
+
}
|
|
27
|
+
/** Absolute POSIX seconds for a slot, rounded down. */
|
|
21
28
|
function slotToPosixSeconds(network, slot) {
|
|
29
|
+
return Math.floor(slotToPosixMs(network, slot) / 1000);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Slot that contains a POSIX time in milliseconds.
|
|
33
|
+
* @throws RangeError for a time before the Shelley start, where slots were 20 s long.
|
|
34
|
+
*/
|
|
35
|
+
function posixToSlot(network, posixMs) {
|
|
22
36
|
const genesis = const_1.GENESIS_INFOS_BY_NETWORK[network];
|
|
23
|
-
|
|
37
|
+
const shelleyStartMs = slotToPosixMs(network, const_1.EPOCH_CONFIG_BY_NETWORK[network].shelleyStartSlot);
|
|
38
|
+
if (!Number.isFinite(posixMs) || posixMs < shelleyStartMs) {
|
|
39
|
+
throw new RangeError(`posixToSlot: ${posixMs} is not a time from the ${network} Shelley start on`);
|
|
40
|
+
}
|
|
41
|
+
return genesis.startSlotNo + Math.floor((posixMs - genesis.systemStartPosixMs) / genesis.slotLengthMs);
|
|
24
42
|
}
|
|
25
43
|
//# sourceMappingURL=epoch-slots.js.map
|
package/srv/utils/types.d.ts
CHANGED
|
@@ -670,6 +670,24 @@ export interface SigningWorkflowState {
|
|
|
670
670
|
failed?: string;
|
|
671
671
|
};
|
|
672
672
|
}
|
|
673
|
+
/** Depth of a transaction in the chain. Depth 1 means it sits in the tip block. */
|
|
674
|
+
export interface TransactionConfirmations {
|
|
675
|
+
txHash: string;
|
|
676
|
+
/** null while the tx is not on chain. */
|
|
677
|
+
blockHeight: number | null;
|
|
678
|
+
tipHeight: number | null;
|
|
679
|
+
/** 0 while the tx is not on chain. */
|
|
680
|
+
confirmations: number;
|
|
681
|
+
}
|
|
682
|
+
/** Result of verifyTxWitnesses: every vkey signature checked against the body hash. */
|
|
683
|
+
export interface TxWitnessVerification {
|
|
684
|
+
valid: boolean;
|
|
685
|
+
/** null when the CBOR could not be read. */
|
|
686
|
+
txBodyHash: string | null;
|
|
687
|
+
/** blake2b-224 of each vkey whose signature verifies. */
|
|
688
|
+
signerKeyHashes: string[];
|
|
689
|
+
errors: string[];
|
|
690
|
+
}
|
|
673
691
|
/** Result of signature verification */
|
|
674
692
|
export interface SignatureVerificationResult {
|
|
675
693
|
/** Whether the signature is valid */
|