1
- import * as dntShim from "../../_dnt.shims.js" ;
2
1
import { C } from "../core/mod.js" ;
3
2
import { applyDoubleCborEncoding , fromHex , toHex } from "../utils/mod.js" ;
4
3
import packageJson from "../../package.js" ;
@@ -10,7 +9,7 @@ export class Blockfrost {
10
9
this . projectId = projectId || "" ;
11
10
}
12
11
async getProtocolParameters ( ) {
13
- const result = await dntShim . fetch ( `${ this . url } /epochs/latest/parameters` , {
12
+ const result = await fetch ( `${ this . url } /epochs/latest/parameters` , {
14
13
headers : { project_id : this . projectId , lucid } ,
15
14
} ) . then ( ( res ) => res . json ( ) ) ;
16
15
return {
@@ -42,7 +41,7 @@ export class Blockfrost {
42
41
let result = [ ] ;
43
42
let page = 1 ;
44
43
while ( true ) {
45
- const pageResult = await dntShim . fetch ( `${ this . url } /addresses/${ queryPredicate } /utxos?page=${ page } ` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
44
+ const pageResult = await fetch ( `${ this . url } /addresses/${ queryPredicate } /utxos?page=${ page } ` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
46
45
if ( pageResult . error ) {
47
46
if ( pageResult . status_code === 404 ) {
48
47
return [ ] ;
@@ -70,7 +69,7 @@ export class Blockfrost {
70
69
let result = [ ] ;
71
70
let page = 1 ;
72
71
while ( true ) {
73
- const pageResult = await dntShim . fetch ( `${ this . url } /addresses/${ queryPredicate } /utxos/${ unit } ?page=${ page } ` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
72
+ const pageResult = await fetch ( `${ this . url } /addresses/${ queryPredicate } /utxos/${ unit } ?page=${ page } ` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
74
73
if ( pageResult . error ) {
75
74
if ( pageResult . status_code === 404 ) {
76
75
return [ ] ;
@@ -87,7 +86,7 @@ export class Blockfrost {
87
86
return this . blockfrostUtxosToUtxos ( result ) ;
88
87
}
89
88
async getUtxoByUnit ( unit ) {
90
- const addresses = await dntShim . fetch ( `${ this . url } /assets/${ unit } /addresses?count=2` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
89
+ const addresses = await fetch ( `${ this . url } /assets/${ unit } /addresses?count=2` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
91
90
if ( ! addresses || addresses . error ) {
92
91
throw new Error ( "Unit not found." ) ;
93
92
}
@@ -105,7 +104,7 @@ export class Blockfrost {
105
104
// TODO: Make sure old already spent UTxOs are not retrievable.
106
105
const queryHashes = [ ...new Set ( outRefs . map ( ( outRef ) => outRef . txHash ) ) ] ;
107
106
const utxos = await Promise . all ( queryHashes . map ( async ( txHash ) => {
108
- const result = await dntShim . fetch ( `${ this . url } /txs/${ txHash } /utxos` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
107
+ const result = await fetch ( `${ this . url } /txs/${ txHash } /utxos` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
109
108
if ( ! result || result . error ) {
110
109
return [ ] ;
111
110
}
@@ -120,7 +119,7 @@ export class Blockfrost {
120
119
return utxos . reduce ( ( acc , utxos ) => acc . concat ( utxos ) , [ ] ) . filter ( ( utxo ) => outRefs . some ( ( outRef ) => utxo . txHash === outRef . txHash && utxo . outputIndex === outRef . outputIndex ) ) ;
121
120
}
122
121
async getDelegation ( rewardAddress ) {
123
- const result = await dntShim . fetch ( `${ this . url } /accounts/${ rewardAddress } ` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
122
+ const result = await fetch ( `${ this . url } /accounts/${ rewardAddress } ` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
124
123
if ( ! result || result . error ) {
125
124
return { poolId : null , rewards : 0n } ;
126
125
}
@@ -130,7 +129,7 @@ export class Blockfrost {
130
129
} ;
131
130
}
132
131
async getDatum ( datumHash ) {
133
- const datum = await dntShim . fetch ( `${ this . url } /scripts/datum/${ datumHash } /cbor` , {
132
+ const datum = await fetch ( `${ this . url } /scripts/datum/${ datumHash } /cbor` , {
134
133
headers : { project_id : this . projectId , lucid } ,
135
134
} )
136
135
. then ( ( res ) => res . json ( ) )
@@ -143,7 +142,7 @@ export class Blockfrost {
143
142
awaitTx ( txHash , checkInterval = 3000 ) {
144
143
return new Promise ( ( res ) => {
145
144
const confirmation = setInterval ( async ( ) => {
146
- const isConfirmed = await dntShim . fetch ( `${ this . url } /txs/${ txHash } ` , {
145
+ const isConfirmed = await fetch ( `${ this . url } /txs/${ txHash } ` , {
147
146
headers : { project_id : this . projectId , lucid } ,
148
147
} ) . then ( ( res ) => res . json ( ) ) ;
149
148
if ( isConfirmed && ! isConfirmed . error ) {
@@ -155,7 +154,7 @@ export class Blockfrost {
155
154
} ) ;
156
155
}
157
156
async submitTx ( tx ) {
158
- const result = await dntShim . fetch ( `${ this . url } /tx/submit` , {
157
+ const result = await fetch ( `${ this . url } /tx/submit` , {
159
158
method : "POST" ,
160
159
headers : {
161
160
"Content-Type" : "application/cbor" ,
@@ -182,14 +181,14 @@ export class Blockfrost {
182
181
datum : r . inline_datum || undefined ,
183
182
scriptRef : r . reference_script_hash
184
183
? ( await ( async ( ) => {
185
- const { type, } = await dntShim . fetch ( `${ this . url } /scripts/${ r . reference_script_hash } ` , {
184
+ const { type, } = await fetch ( `${ this . url } /scripts/${ r . reference_script_hash } ` , {
186
185
headers : { project_id : this . projectId , lucid } ,
187
186
} ) . then ( ( res ) => res . json ( ) ) ;
188
187
// TODO: support native scripts
189
188
if ( type === "Native" || type === "native" ) {
190
189
throw new Error ( "Native script ref not implemented!" ) ;
191
190
}
192
- const { cbor : script } = await dntShim . fetch ( `${ this . url } /scripts/${ r . reference_script_hash } /cbor` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
191
+ const { cbor : script } = await fetch ( `${ this . url } /scripts/${ r . reference_script_hash } /cbor` , { headers : { project_id : this . projectId , lucid } } ) . then ( ( res ) => res . json ( ) ) ;
193
192
return {
194
193
type : type === "plutusV1" ? "PlutusV1" : "PlutusV2" ,
195
194
script : applyDoubleCborEncoding ( script ) ,
0 commit comments