-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathblockfrost.ts
792 lines (693 loc) · 23.5 KB
/
blockfrost.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
import type {
AssetId as AssetIdType,
CostModels,
Credential,
ProtocolParameters,
Redeemer,
ScriptHash,
TokenMap,
Transaction,
} from "@blaze-cardano/core";
import {
Address,
AddressType,
AssetId,
Datum,
DatumHash,
ExUnits,
fromHex,
hardCodedProtocolParams,
Hash28ByteBase16,
HexBlob,
NetworkId,
PlutusData,
PlutusV1Script,
PlutusV2Script,
Redeemers,
Script,
TransactionId,
TransactionInput,
TransactionOutput,
TransactionUnspentOutput,
Value,
} from "@blaze-cardano/core";
import { PlutusLanguageVersion } from "@blaze-cardano/core";
import { purposeToTag, Provider } from "./provider";
export class Blockfrost extends Provider {
url: string;
private projectId: string;
constructor({
network,
projectId,
}: {
network:
| "cardano-preview"
| "cardano-preprod"
| "cardano-mainnet"
| "cardano-sanchonet";
projectId: string;
}) {
super(network == "cardano-mainnet" ? NetworkId.Mainnet : NetworkId.Testnet);
this.url = `https://${network}.blockfrost.io/api/v0/`;
this.projectId = projectId;
}
headers() {
return { project_id: this.projectId };
}
/**
* This method fetches the protocol parameters from the Blockfrost API.
* It constructs the query URL, sends a GET request with the appropriate headers, and processes the response.
* The response is parsed into a ProtocolParameters object, which is then returned.
* If the response is not in the expected format, an error is thrown.
* @returns A Promise that resolves to a ProtocolParameters object.
*/
async getParameters(): Promise<ProtocolParameters> {
const query = "epochs/latest/parameters";
const json = await fetch(`${this.url}${query}`, {
headers: this.headers(),
}).then((resp) => resp.json());
if (!json) {
throw new Error("getParameters: Could not parse response json");
}
const response =
json as BlockfrostResponse<BlockfrostProtocolParametersResponse>;
if ("message" in response) {
throw new Error(`getParameters: Blockfrost threw "${response.message}"`);
}
// Build cost models
const costModels: CostModels = new Map();
for (const [key, value] of Object.entries(response.cost_models_raw)) {
costModels.set(
fromBlockfrostLanguageVersion(key as BlockfrostLanguageVersions),
value,
);
}
return {
coinsPerUtxoByte: response.coins_per_utxo_size,
maxTxSize: response.max_tx_size,
minFeeCoefficient: response.min_fee_a,
minFeeConstant: response.min_fee_b,
maxBlockBodySize: response.max_block_size,
maxBlockHeaderSize: response.max_block_header_size,
stakeKeyDeposit: response.key_deposit,
poolDeposit: response.pool_deposit,
poolRetirementEpochBound: response.e_max,
desiredNumberOfPools: response.n_opt,
poolInfluence: response.a0,
monetaryExpansion: response.rho,
treasuryExpansion: response.tau,
minPoolCost: response.min_pool_cost,
protocolVersion: {
major: response.protocol_major_ver,
minor: response.protocol_minor_ver,
},
maxValueSize: response.max_val_size,
collateralPercentage: response.collateral_percent,
maxCollateralInputs: response.max_collateral_inputs,
costModels: costModels,
prices: {
memory: parseFloat(response.price_mem),
steps: parseFloat(response.price_step),
},
maxExecutionUnitsPerTransaction: {
memory: response.max_tx_ex_mem,
steps: response.max_tx_ex_steps,
},
maxExecutionUnitsPerBlock: {
memory: response.max_block_ex_mem,
steps: response.max_block_ex_steps,
},
minFeeReferenceScripts: response.min_fee_ref_script_cost_per_byte
? {
...hardCodedProtocolParams.minFeeReferenceScripts!,
base: response.min_fee_ref_script_cost_per_byte,
}
: undefined,
};
}
/**
* This method fetches the UTxOs under a given address.
* The response is parsed into a TransactionUnspentOutput[] type, which is
* then returned.
* If the response is not in the expected format, an error is thrown.
* @param address - The Address or Payment Credential
* @returns A Promise that resolves to TransactionUnspentOutput[].
*/
async getUnspentOutputs(
address: Address | Credential,
): Promise<TransactionUnspentOutput[]> {
// 100 per page is max allowed by Blockfrost
const maxPageCount = 100;
let page = 1;
const bech32 =
address instanceof Address
? address.toBech32()
: new Address({
type: AddressType.EnterpriseKey,
paymentPart: address.toCore(),
}).toBech32();
const buildTxUnspentOutput = this.buildTransactionUnspentOutput(
Address.fromBech32(bech32),
);
const results: Set<TransactionUnspentOutput> = new Set();
for (;;) {
const pagination = `count=${maxPageCount}&page=${page}`;
const query = `/addresses/${bech32}/utxos?${pagination}`;
const json = await fetch(`${this.url}${query}`, {
headers: this.headers(),
}).then((resp) => resp.json());
if (!json) {
throw new Error("getUnspentOutputs: Could not parse response json");
}
const response = json as BlockfrostResponse<BlockfrostUTxO[]>;
if ("message" in response) {
throw new Error(
`getUnspentOutputs: Blockfrost threw "${response.message}"`,
);
}
for (const blockfrostUTxO of response) {
results.add(await buildTxUnspentOutput(blockfrostUTxO));
}
if (response.length < maxPageCount) {
break;
} else {
page = page + 1;
}
}
return Array.from(results);
}
/**
* This method fetches the UTxOs under a given address that hold
* a particular asset.
* The response is parsed into a TransactionUnspentOutput[] type, which is
* then returned.
* If the response is not in the expected format, an error is thrown.
* @param address - Address or Payment Credential.
* @param unit - The AssetId
* @returns A Promise that resolves to TransactionUnspentOutput[].
*/
async getUnspentOutputsWithAsset(
address: Address | Credential,
unit: AssetIdType,
): Promise<TransactionUnspentOutput[]> {
// 100 per page is max allowed by Blockfrost
const maxPageCount = 100;
let page = 1;
const bech32 =
address instanceof Address
? address.toBech32()
: new Address({
type: AddressType.EnterpriseKey,
paymentPart: address.toCore(),
}).toBech32();
const buildTxUnspentOutput = this.buildTransactionUnspentOutput(
Address.fromBech32(bech32),
);
const asset = AssetId.getPolicyId(unit) + AssetId.getAssetName(unit);
const results: Set<TransactionUnspentOutput> = new Set();
for (;;) {
const pagination = `count=${maxPageCount}&page=${page}`;
const query = `/addresses/${bech32}/utxos/${asset}?${pagination}`;
const json = await fetch(`${this.url}${query}`, {
headers: this.headers(),
}).then((resp) => resp.json());
if (!json) {
throw new Error(
"getUnspentOutputsWithAsset: Could not parse response json",
);
}
const response = json as BlockfrostResponse<BlockfrostUTxO[]>;
if ("message" in response) {
throw new Error(
`getUnspentOutputsWithAsset: Blockfrost threw "${response.message}"`,
);
}
for (const blockfrostUTxO of response) {
results.add(await buildTxUnspentOutput(blockfrostUTxO));
}
if (response.length < maxPageCount) {
break;
} else {
page = page + 1;
}
}
return Array.from(results);
}
/**
* This method fetches the UTxO that holds a particular NFT given as
* argument.
* The response is parsed into a TransactionUnspentOutput type, which is
* then returned.
* If the response is not in the expected format, an error is thrown.
* @param nft - The AssetId for the NFT
* @returns A Promise that resolves to TransactionUnspentOutput.
*/
async getUnspentOutputByNFT(nft: AssetId): Promise<TransactionUnspentOutput> {
const asset = AssetId.getPolicyId(nft) + AssetId.getAssetName(nft);
// Fetch addresses holding the asset. Since it's an NFT, a single
// address is expected to be returned
const query = `/assets/${asset}/addresses`;
const json = await fetch(`${this.url}${query}`, {
headers: this.headers(),
}).then((resp) => resp.json());
if (!json) {
throw new Error("getUnspentOutputByNFT: Could not parse response json");
}
const response = json as BlockfrostResponse<BlockfrostAssetAddress[]>;
if ("message" in response) {
throw new Error(
`getUnspentOutputByNFT: Blockfrost threw "${response.message}"`,
);
}
// Ensures a single asset address is returned
if (response.length === 0) {
throw new Error(
"getUnspentOutputByNFT: No addresses found holding the asset.",
);
}
if (response.length > 1) {
throw new Error(
"getUnspentOutputByNFT: Asset must be held by only one address. Multiple found.",
);
}
const utxo = response[0] as BlockfrostAssetAddress;
const address = Address.fromBech32(utxo.address);
// A second call to Blockfrost is needed in order to fetch utxo information
const utxos = await this.getUnspentOutputsWithAsset(address, nft);
// Ensures a single UTxO holds the asset
if (utxos.length !== 1) {
throw new Error(
"getUnspentOutputByNFT: Asset must be present in only one UTxO. Multiple found.",
);
}
return utxos[0]!;
}
/**
* This method resolves transaction outputs from a list of transaction
* inputs given as argument.
* The response is parsed into a TransactionUnspentOutput[] type, which is
* then returned.
* If the response is not in the expected format, an error is thrown.
* @param txIns - A list of TransactionInput
* @returns A Promise that resolves to TransactionUnspentOutput[].
*/
async resolveUnspentOutputs(
txIns: TransactionInput[],
): Promise<TransactionUnspentOutput[]> {
const results: Set<TransactionUnspentOutput> = new Set();
for (const txIn of txIns) {
const query = `/txs/${txIn.transactionId()}/utxos`;
const json = await fetch(`${this.url}${query}`, {
headers: this.headers(),
}).then((resp) => resp.json());
if (!json) {
throw new Error("resolveUnspentOutputs: Could not parse response json");
}
const response =
json as BlockfrostResponse<BlockfrostUnspentOutputResolution>;
if ("message" in response) {
throw new Error(
`resolveUnspentOutputs: Blockfrost threw "${response.message}"`,
);
}
const txIndex = BigInt(txIn.index());
for (const blockfrostUTxO of response.outputs) {
if (BigInt(blockfrostUTxO.output_index) !== txIndex) {
// Ignore outputs whose index don't match
// the index we are looking for
continue;
}
// Blockfrost API does not return tx hash, so it must be manually set
blockfrostUTxO.tx_hash = txIn.transactionId();
const buildTxUnspentOutput = this.buildTransactionUnspentOutput(
Address.fromBech32(blockfrostUTxO.address),
);
results.add(await buildTxUnspentOutput(blockfrostUTxO));
}
}
return Array.from(results);
}
/**
* This method returns the datum for the datum hash given as argument.
* The response is parsed into a PlutusData type, which is then returned.
* If the response is not in the expected format, an error is thrown.
* @param datumHash - The hash of a datum
* @returns A Promise that resolves to PlutusData
*/
async resolveDatum(datumHash: DatumHash): Promise<PlutusData> {
const query = `/scripts/datum/${datumHash}/cbor`;
const json = await fetch(`${this.url}${query}`, {
headers: this.headers(),
}).then((resp) => resp.json());
if (!json) {
throw new Error("resolveDatum: Could not parse response json");
}
const response = json as BlockfrostResponse<BlockfrostDatumHashResolution>;
if ("message" in response) {
throw new Error(`resolveDatum: Blockfrost threw "${response.message}"`);
}
return PlutusData.fromCbor(HexBlob(response.cbor));
}
/**
* This method awaits confirmation of the transaction given as argument.
* The response is parsed into a boolean, which is then returned.
* If tx is not confirmed at first and no value for timeout is provided,
* then false is returned.
* If tx is not confirmed at first and a value for timeout (in ms) is given,
* then subsequent checks will be performed at a 20 second interval until
* timeout is reached.
* @param txId - The hash of a transaction
* @param timeout - An optional timeout for waiting for confirmation. This
* value should be greater than average block time of 20000 ms
* @returns A Promise that resolves to a boolean
*/
async awaitTransactionConfirmation(
txId: TransactionId,
timeout?: number,
): Promise<boolean> {
const averageBlockTime = 20_000;
if (timeout && timeout < averageBlockTime) {
console.log("Warning: timeout given is less than average block time.");
}
const query = `/txs/${txId}/metadata/cbor`;
const startTime = Date.now();
const delay = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
const checkConfirmation = async () => {
const response = await fetch(`${this.url}${query}`, {
headers: this.headers(),
});
return response.ok;
};
if (await checkConfirmation()) {
return true;
}
if (timeout) {
while (Date.now() - startTime < timeout) {
await delay(averageBlockTime);
if (await checkConfirmation()) {
return true;
}
}
}
return false;
}
/**
* This method submits a transaction to the chain.
* @param tx - The Transaction
* @returns A Promise that resolves to a TransactionId type
*/
async postTransactionToChain(tx: Transaction): Promise<TransactionId> {
const query = "/tx/submit";
const response = await fetch(`${this.url}${query}`, {
method: "POST",
headers: {
"Content-Type": "application/cbor",
...this.headers(),
},
body: fromHex(tx.toCbor()),
});
if (!response.ok) {
const error = await response.text();
throw new Error(
`postTransactionToChain: failed to submit transaction to Blockfrost endpoint.\nError ${error}`,
);
}
const txId = (await response.json()) as string;
return TransactionId(txId);
}
/**
* This method evaluates how much execution units a transaction requires.
* Optionally, additional outputs can be provided. These are added to the
* evaluation without checking for their presence on-chain. This is useful
* when performing transaction chaining, where some outputs used as inputs
* to a transaction will have not yet been submitted to the network.
* @param tx - The Transaction
* @param additionalUtxos - Optional utxos to be added to the evaluation.
* @returns A Promise that resolves to a Redeemers type
*/
async evaluateTransaction(
tx: Transaction,
additionalUtxos?: TransactionUnspentOutput[],
): Promise<Redeemers> {
const currentRedeemers = tx.witnessSet().redeemers()?.values();
if (!currentRedeemers || currentRedeemers.length === 0) {
throw new Error(
`evaluateTransaction: No Redeemers found in transaction"`,
);
}
const additionalUtxoSet = new Set();
for (const utxo of additionalUtxos || []) {
const txIn = {
txId: utxo.input().transactionId(),
index: utxo.input().index(),
};
const output = utxo.output();
const value = output.amount();
const txOut = {
address: output.address(),
value: {
coins: value.coin(),
assets: value.multiasset(),
},
datum_hash: output.datum()?.asDataHash(),
datum: output.datum()?.asInlineData()?.toCbor(),
script: output.scriptRef()?.toCbor(),
};
additionalUtxoSet.add([txIn, txOut]);
}
const payload = {
cbor: tx.toCbor(),
additionalUtxoset: Array.from(additionalUtxoSet),
};
const query = "/utils/txs/evaluate/utxos";
const response = await fetch(`${this.url}${query}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
...this.headers(),
},
body: JSON.stringify(payload, (_, value) =>
typeof value === "bigint" ? value.toString() : value,
),
});
if (!response.ok) {
const error = await response.text();
throw new Error(
`evaluateTransaction: failed to evaluate transaction with additional UTxO set in Blockfrost endpoint.\nError ${error}`,
);
}
const json =
(await response.json()) as BlockfrostResponse<BlockfrostRedeemer>;
if ("message" in json) {
throw new Error(
`evaluateTransaction: Blockfrost threw "${json.message}"`,
);
}
const evaledRedeemers: Set<Redeemer> = new Set();
if (!("EvaluationResult" in json.result)) {
throw new Error(
`evaluateTransaction: Blockfrost endpoint returned evaluation failure.`,
);
}
const result = json.result.EvaluationResult;
for (const redeemerPointer in result) {
const [pTag, pIndex] = redeemerPointer.split(":");
const purpose = purposeToTag[pTag!];
const index = BigInt(pIndex!);
const data = result[redeemerPointer]!;
const exUnits = ExUnits.fromCore({
memory: data.memory,
steps: data.steps,
});
const redeemer = currentRedeemers!.find(
(x: Redeemer) => x.tag() == purpose && x.index() == index,
);
if (!redeemer) {
throw new Error(
"evaluateTransaction: Blockfrost endpoint had extraneous redeemer data",
);
}
// Manually set exUnits for redeemer
redeemer.setExUnits(exUnits);
// Add redeemer to result set
evaledRedeemers.add(redeemer);
}
// Build return value from evaluated result set
return Redeemers.fromCore(
Array.from(evaledRedeemers).map((x) => x.toCore()),
);
}
private async getScriptRef(scriptHash: ScriptHash): Promise<Script> {
const typeQuery = `/scripts/${scriptHash}`;
const typeJson = await fetch(`${this.url}${typeQuery}`, {
headers: this.headers(),
}).then((resp) => resp.json());
if (!typeJson) {
throw new Error("getScriptRef: Could not parse response json");
}
const typeResponse = typeJson as BlockfrostResponse<{
type: "timelock" | "plutusV1" | "plutusV2";
}>;
if ("message" in typeResponse) {
throw new Error(
`getScriptRef: Blockfrost threw "${typeResponse.message}"`,
);
}
const type = typeResponse.type;
if (type == "timelock") {
throw new Error("getScriptRef: Native scripts are not yet supported.");
}
const cborQuery = `/scripts/${scriptHash}/cbor`;
const cborJson = await fetch(`${this.url}${cborQuery}`, {
headers: this.headers(),
}).then((resp) => resp.json());
if (!cborJson) {
throw new Error("getScriptRef: Could not parse response json");
}
const cborResponse = cborJson as BlockfrostResponse<{
cbor: string;
}>;
if ("message" in cborResponse) {
throw new Error(
`getScriptRef: Blockfrost threw "${cborResponse.message}"`,
);
}
const cbor = HexBlob(cborResponse.cbor);
switch (type) {
case "plutusV1":
return Script.newPlutusV1Script(new PlutusV1Script(cbor));
case "plutusV2":
return Script.newPlutusV2Script(new PlutusV2Script(cbor));
}
}
// Partially applies address in order to avoid sending it
// as argument repeatedly when building TransactionUnspentOutput
private buildTransactionUnspentOutput(
address: Address,
): (blockfrostUTxO: BlockfrostUTxO) => Promise<TransactionUnspentOutput> {
return async (blockfrostUTxO) => {
const txIn = new TransactionInput(
TransactionId(blockfrostUTxO.tx_hash),
BigInt(blockfrostUTxO.output_index),
);
// No tx output CBOR available from Blockfrost,
// so TransactionOutput must be manually constructed.
const tokenMap: TokenMap = new Map<AssetId, bigint>();
let lovelace = 0n;
for (const { unit, quantity } of blockfrostUTxO.amount) {
if (unit === "lovelace") {
lovelace = BigInt(quantity);
} else {
tokenMap.set(unit as AssetId, BigInt(quantity));
}
}
const txOut = new TransactionOutput(
address,
new Value(lovelace, tokenMap),
);
const datum = blockfrostUTxO.inline_datum
? Datum.newInlineData(
PlutusData.fromCbor(HexBlob(blockfrostUTxO.inline_datum)),
)
: blockfrostUTxO.data_hash
? Datum.newDataHash(DatumHash(blockfrostUTxO.data_hash))
: undefined;
if (datum) txOut.setDatum(datum);
if (blockfrostUTxO.reference_script_hash)
txOut.setScriptRef(
await this.getScriptRef(
Hash28ByteBase16(blockfrostUTxO.reference_script_hash),
),
);
return new TransactionUnspentOutput(txIn, txOut);
};
}
}
type BlockfrostLanguageVersions = "PlutusV1" | "PlutusV2" | "PlutusV3";
export const fromBlockfrostLanguageVersion = (
x: BlockfrostLanguageVersions,
): PlutusLanguageVersion => {
if (x == "PlutusV1") {
return PlutusLanguageVersion.V1;
} else if (x == "PlutusV2") {
return PlutusLanguageVersion.V2;
} else if (x == "PlutusV3") {
return PlutusLanguageVersion.V3;
}
throw new Error("fromBlockfrostLanguageVersion: Unreachable!");
};
export interface BlockfrostProtocolParametersResponse {
epoch: number;
min_fee_a: number;
min_fee_b: number;
max_block_size: number;
max_tx_size: number;
max_block_header_size: number;
key_deposit: number;
pool_deposit: number;
e_max: number;
n_opt: number;
a0: string;
rho: string;
tau: string;
decentralisation_param: number;
extra_entropy: null;
protocol_major_ver: number;
protocol_minor_ver: number;
min_utxo: string;
min_pool_cost: number;
nonce: string;
cost_models: Record<BlockfrostLanguageVersions, { [key: string]: number }>;
cost_models_raw: Record<BlockfrostLanguageVersions, number[]>;
price_mem: string;
price_step: string;
max_tx_ex_mem: number;
max_tx_ex_steps: number;
max_block_ex_mem: number;
max_block_ex_steps: number;
max_val_size: number;
collateral_percent: number;
max_collateral_inputs: number;
coins_per_utxo_size: number;
min_fee_ref_script_cost_per_byte?: number;
}
type BlockfrostResponse<SomeResponse> = SomeResponse | { message: string };
interface BlockfrostUTxO {
address: string;
tx_hash: string;
output_index: number;
amount: {
unit: string;
quantity: string;
}[];
block: string;
data_hash?: string;
inline_datum?: string;
reference_script_hash?: string;
}
interface BlockfrostAssetAddress {
address: string;
quantity: string;
}
interface BlockfrostUnspentOutputResolution {
outputs: BlockfrostUTxO[];
}
interface BlockfrostDatumHashResolution {
cbor: string;
}
interface BlockfrostRedeemer {
result:
| {
EvaluationResult: {
[key: string]: {
memory: number;
steps: number;
};
};
}
| {
CannotCreateEvaluationContext: any;
};
}