1- import blockstack from 'blockstack ' ;
1+ import { createFetchFn , FetchFn } from '@stacks/network ' ;
22import * as bitcoin from 'bitcoinjs-lib' ;
3- import fetch from 'node-fetch' ;
4-
5- import { CLI_CONFIG_TYPE } from './argparse' ;
6-
3+ import blockstack from 'blockstack' ;
74import { BlockstackNetwork } from 'blockstack/lib/network' ;
5+ import { CLI_CONFIG_TYPE } from './argparse' ;
86
97export interface CLI_NETWORK_OPTS {
108 consensusHash : string | null ;
@@ -186,15 +184,16 @@ export class CLINetworkAdapter {
186184 getNamespaceBurnAddress (
187185 namespace : string ,
188186 useCLI : boolean = true ,
189- receiveFeesPeriod : number = - 1
187+ receiveFeesPeriod : number = - 1 ,
188+ fetchFn : FetchFn = createFetchFn ( )
190189 ) : Promise < string > {
191190 // override with CLI option
192191 if ( this . namespaceBurnAddress && useCLI ) {
193192 return new Promise ( ( resolve : any ) => resolve ( this . namespaceBurnAddress ) ) ;
194193 }
195194
196195 return Promise . all ( [
197- fetch ( `${ this . legacyNetwork . blockstackAPIUrl } /v1/namespaces/${ namespace } ` ) ,
196+ fetchFn ( `${ this . legacyNetwork . blockstackAPIUrl } /v1/namespaces/${ namespace } ` ) ,
198197 this . legacyNetwork . getBlockHeight ( ) ,
199198 ] )
200199 . then ( ( [ resp , blockHeight ] : [ any , number ] ) => {
@@ -244,10 +243,10 @@ export class CLINetworkAdapter {
244243 } ) ;
245244 }
246245
247- getBlockchainNameRecord ( name : string ) : Promise < any > {
246+ getBlockchainNameRecord ( name : string , fetchFn : FetchFn = createFetchFn ( ) ) : Promise < any > {
248247 // TODO: send to blockstack.js
249248 const url = `${ this . legacyNetwork . blockstackAPIUrl } /v1/blockchains/bitcoin/names/${ name } ` ;
250- return fetch ( url )
249+ return fetchFn ( url )
251250 . then ( resp => {
252251 if ( resp . status !== 200 ) {
253252 throw new Error ( `Bad response status: ${ resp . status } ` ) ;
@@ -267,10 +266,14 @@ export class CLINetworkAdapter {
267266 } ) ;
268267 }
269268
270- getNameHistory ( name : string , page : number ) : Promise < Record < string , any [ ] > > {
269+ getNameHistory (
270+ name : string ,
271+ page : number ,
272+ fetchFn : FetchFn = createFetchFn ( )
273+ ) : Promise < Record < string , any [ ] > > {
271274 // TODO: send to blockstack.js
272275 const url = `${ this . legacyNetwork . blockstackAPIUrl } /v1/names/${ name } /history?page=${ page } ` ;
273- return fetch ( url )
276+ return fetchFn ( url )
274277 . then ( resp => {
275278 if ( resp . status !== 200 ) {
276279 throw new Error ( `Bad response status: ${ resp . status } ` ) ;
0 commit comments