mirror of
https://github.com/alexgo-io/stacks.js.git
synced 2026-04-28 17:25:51 +08:00
fix: BREAKING CHANGE: make coreApiUrl readonly for stacks network and initialize in constructor
This commit is contained in:
committed by
Reed Rosenbluth
parent
f572477ca0
commit
4fd0732666
@@ -337,7 +337,6 @@ async function makeKeychain(network: CLINetworkAdapter, args: string[]): Promise
|
||||
if (args[0]) {
|
||||
mnemonic = await getBackupPhrase(args[0]);
|
||||
} else {
|
||||
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||
mnemonic = await bip39.generateMnemonic(
|
||||
STX_WALLET_COMPATIBLE_SEED_STRENGTH,
|
||||
crypto.randomBytes
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import { TransactionVersion, ChainID, fetchPrivate } from '@stacks/common';
|
||||
|
||||
export const HIRO_MAINNET_DEFAULT = 'https://stacks-node-api.mainnet.stacks.co';
|
||||
export const HIRO_TESTNET_DEFAULT = 'https://stacks-node-api.testnet.stacks.co';
|
||||
export const HIRO_MOCKNET_DEFAULT = 'http://localhost:3999';
|
||||
|
||||
export interface NetworkUrl {
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface StacksNetwork {
|
||||
version: TransactionVersion;
|
||||
chainId: ChainID;
|
||||
coreApiUrl: string;
|
||||
readonly coreApiUrl: string;
|
||||
bnsLookupUrl: string;
|
||||
broadcastEndpoint: string;
|
||||
transferFeeEstimateEndpoint: string;
|
||||
@@ -39,7 +47,7 @@ export interface StacksNetwork {
|
||||
export class StacksMainnet implements StacksNetwork {
|
||||
version = TransactionVersion.Mainnet;
|
||||
chainId = ChainID.Mainnet;
|
||||
coreApiUrl = 'https://stacks-node-api.mainnet.stacks.co';
|
||||
readonly coreApiUrl;
|
||||
bnsLookupUrl = 'https://stacks-node-api.mainnet.stacks.co';
|
||||
broadcastEndpoint = '/v2/transactions';
|
||||
transferFeeEstimateEndpoint = '/v2/fees/transfer';
|
||||
@@ -47,6 +55,10 @@ export class StacksMainnet implements StacksNetwork {
|
||||
contractAbiEndpoint = '/v2/contracts/interface';
|
||||
readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
|
||||
|
||||
constructor(networkUrl: NetworkUrl = { url: HIRO_MAINNET_DEFAULT }) {
|
||||
this.coreApiUrl = networkUrl.url;
|
||||
}
|
||||
|
||||
isMainnet = () => this.version === TransactionVersion.Mainnet;
|
||||
getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
|
||||
getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
|
||||
@@ -99,13 +111,19 @@ export class StacksMainnet implements StacksNetwork {
|
||||
export class StacksTestnet extends StacksMainnet implements StacksNetwork {
|
||||
version = TransactionVersion.Testnet;
|
||||
chainId = ChainID.Testnet;
|
||||
coreApiUrl = 'https://stacks-node-api.testnet.stacks.co';
|
||||
|
||||
constructor(networkUrl: NetworkUrl = { url: HIRO_TESTNET_DEFAULT }) {
|
||||
super(networkUrl);
|
||||
}
|
||||
}
|
||||
|
||||
export class StacksMocknet extends StacksMainnet implements StacksNetwork {
|
||||
version = TransactionVersion.Testnet;
|
||||
chainId = ChainID.Testnet;
|
||||
coreApiUrl = 'http://localhost:3999';
|
||||
|
||||
constructor(networkUrl: NetworkUrl = { url: HIRO_MOCKNET_DEFAULT }) {
|
||||
super(networkUrl);
|
||||
}
|
||||
}
|
||||
|
||||
export class StacksRegtest extends StacksMainnet implements StacksNetwork {
|
||||
|
||||
@@ -1,4 +1,23 @@
|
||||
test('test', () => {
|
||||
expect(true).toBeTruthy()
|
||||
})
|
||||
import {
|
||||
HIRO_MAINNET_DEFAULT,
|
||||
HIRO_MOCKNET_DEFAULT,
|
||||
HIRO_TESTNET_DEFAULT,
|
||||
StacksMainnet,
|
||||
StacksMocknet,
|
||||
StacksTestnet,
|
||||
} from '@stacks/network';
|
||||
|
||||
test('network test-- coreApiUrl', () => {
|
||||
const mainnet = new StacksMainnet();
|
||||
expect(mainnet.coreApiUrl).toBe(HIRO_MAINNET_DEFAULT);
|
||||
|
||||
const testnet = new StacksTestnet();
|
||||
expect(testnet.coreApiUrl).toBe(HIRO_TESTNET_DEFAULT);
|
||||
|
||||
const mocknet = new StacksMocknet();
|
||||
expect(mocknet.coreApiUrl).toBe(HIRO_MOCKNET_DEFAULT);
|
||||
|
||||
const customURL = 'customeURL';
|
||||
const customNET = new StacksMainnet({ url: customURL });
|
||||
expect(customNET.coreApiUrl).toBe(customURL);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user