11import blockstack from 'blockstack' ;
22import * as bitcoin from 'bitcoinjs-lib' ;
33import BN from 'bn.js' ;
4- import fetch from 'node-fetch' ;
54
65import { CLI_CONFIG_TYPE } from './argparse' ;
76
87import { BlockstackNetwork } from 'blockstack/lib/network' ;
8+ import { createFetchFn , FetchFn } from '@stacks/network' ;
99
1010export interface CLI_NETWORK_OPTS {
1111 consensusHash : string | null ;
@@ -187,15 +187,16 @@ export class CLINetworkAdapter {
187187 getNamespaceBurnAddress (
188188 namespace : string ,
189189 useCLI : boolean = true ,
190- receiveFeesPeriod : number = - 1
190+ receiveFeesPeriod : number = - 1 ,
191+ fetchFn : FetchFn = createFetchFn ( )
191192 ) : Promise < string > {
192193 // override with CLI option
193194 if ( this . namespaceBurnAddress && useCLI ) {
194195 return new Promise ( ( resolve : any ) => resolve ( this . namespaceBurnAddress ) ) ;
195196 }
196197
197198 return Promise . all ( [
198- fetch ( `${ this . legacyNetwork . blockstackAPIUrl } /v1/namespaces/${ namespace } ` ) ,
199+ fetchFn ( `${ this . legacyNetwork . blockstackAPIUrl } /v1/namespaces/${ namespace } ` ) ,
199200 this . legacyNetwork . getBlockHeight ( ) ,
200201 ] )
201202 . then ( ( [ resp , blockHeight ] : [ any , number ] ) => {
@@ -245,10 +246,10 @@ export class CLINetworkAdapter {
245246 } ) ;
246247 }
247248
248- getBlockchainNameRecord ( name : string ) : Promise < any > {
249+ getBlockchainNameRecord ( name : string , fetchFn : FetchFn = createFetchFn ( ) ) : Promise < any > {
249250 // TODO: send to blockstack.js
250251 const url = `${ this . legacyNetwork . blockstackAPIUrl } /v1/blockchains/bitcoin/names/${ name } ` ;
251- return fetch ( url )
252+ return fetchFn ( url )
252253 . then ( resp => {
253254 if ( resp . status !== 200 ) {
254255 throw new Error ( `Bad response status: ${ resp . status } ` ) ;
@@ -268,10 +269,14 @@ export class CLINetworkAdapter {
268269 } ) ;
269270 }
270271
271- getNameHistory ( name : string , page : number ) : Promise < Record < string , any [ ] > > {
272+ getNameHistory (
273+ name : string ,
274+ page : number ,
275+ fetchFn : FetchFn = createFetchFn ( )
276+ ) : Promise < Record < string , any [ ] > > {
272277 // TODO: send to blockstack.js
273278 const url = `${ this . legacyNetwork . blockstackAPIUrl } /v1/names/${ name } /history?page=${ page } ` ;
274- return fetch ( url )
279+ return fetchFn ( url )
275280 . then ( resp => {
276281 if ( resp . status !== 200 ) {
277282 throw new Error ( `Bad response status: ${ resp . status } ` ) ;
0 commit comments