Skip to content

Commit

Permalink
chore: remove regtest from network list
Browse files Browse the repository at this point in the history
  • Loading branch information
Imamah-Zafar authored and diwakergupta committed Nov 12, 2021
1 parent 5df8b6d commit d9500ab
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 54 deletions.
22 changes: 2 additions & 20 deletions packages/cli/src/argparse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,6 @@ const CONFIG_DEFAULTS: CLI_CONFIG_TYPE = {
logConfig: LOG_CONFIG_DEFAULTS,
};

const CONFIG_REGTEST_DEFAULTS: CLI_CONFIG_TYPE = {
blockstackAPIUrl: 'http://localhost:16268',
blockstackNodeUrl: 'http://localhost:16264',
broadcastServiceUrl: 'http://localhost:16269',
utxoServiceUrl: 'http://localhost:18332',
logConfig: LOG_CONFIG_DEFAULTS,
bitcoindPassword: 'blockstacksystem',
bitcoindUsername: 'blockstack',
};

const CONFIG_LOCALNET_DEFAULTS = {
blockstackAPIUrl: `http://localhost:20443`,
blockstackNodeUrl: `http://localhost:20443`,
Expand All @@ -117,7 +107,6 @@ const CONFIG_TESTNET_DEFAULTS = {
};

export const DEFAULT_CONFIG_PATH = '~/.blockstack-cli.conf';
export const DEFAULT_CONFIG_REGTEST_PATH = path.join(os.homedir(), '.blockstack-cli-regtest.conf');
export const DEFAULT_CONFIG_TESTNET_PATH = path.join(os.homedir(), '.blockstack-cli-testnet.conf');

export const DEFAULT_MAX_ID_SEARCH_INDEX = 256;
Expand Down Expand Up @@ -3387,24 +3376,17 @@ export function checkArgs(argList: string[]): CheckArgsSuccessType | CheckArgsFa
* If no config file exists, then return the default config.
*
* @configPath (string) the path to the config file.
* @networkType (sring) 'mainnet', 'regtest', 'localnet', or 'testnet'
* @networkType (sring) 'mainnet', 'localnet', or 'testnet'
*/
export function loadConfig(configFile: string, networkType: string): CLI_CONFIG_TYPE {
if (
networkType !== 'mainnet' &&
networkType !== 'testnet' &&
networkType != 'regtest' &&
networkType != 'localnet'
) {
if (networkType !== 'mainnet' && networkType !== 'testnet' && networkType != 'localnet') {
throw new Error('Unregognized network');
}

let configRet: CLI_CONFIG_TYPE;

if (networkType === 'mainnet') {
configRet = Object.assign({}, CONFIG_DEFAULTS);
} else if (networkType === 'regtest') {
configRet = Object.assign({}, CONFIG_REGTEST_DEFAULTS);
} else if (networkType === 'localnet') {
configRet = Object.assign({}, CONFIG_LOCALNET_DEFAULTS);
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ async function getIdentityInfo(
_appGaiaHub: string,
_profileGaiaHub: string
): Promise<NamedIdentityType[]> {
network.setCoerceMainnetAddress(true); // for lookups in regtest
network.setCoerceMainnetAddress(false);
let identities: NamedIdentityType[];

try {
Expand Down
13 changes: 2 additions & 11 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ import {
makeAllCommandsList,
USAGE,
DEFAULT_CONFIG_PATH,
DEFAULT_CONFIG_REGTEST_PATH,
DEFAULT_CONFIG_TESTNET_PATH,
ID_ADDRESS_PATTERN,
STACKS_ADDRESS_PATTERN,
Expand Down Expand Up @@ -356,7 +355,7 @@ function balance(network: CLINetworkAdapter, args: string[]): Promise<string> {
let address = args[0];

if (BLOCKSTACK_TEST) {
// force testnet address if we're in regtest or testnet mode
// force testnet address if we're in testnet mode
address = network.coerceAddress(address);
}

Expand Down Expand Up @@ -1826,8 +1825,6 @@ export function CLIMain() {

const configPath = CLIOptAsString(opts, 'c')
? CLIOptAsString(opts, 'c')
: integration_test
? DEFAULT_CONFIG_REGTEST_PATH
: testnet
? DEFAULT_CONFIG_TESTNET_PATH
: DEFAULT_CONFIG_PATH;
Expand All @@ -1837,13 +1834,7 @@ export function CLIMain() {
const priceToPay = CLIOptAsString(opts, 'P') ? CLIOptAsString(opts, 'P') : '0';
const priceUnits = CLIOptAsString(opts, 'D');

const networkType = testnet
? 'testnet'
: localnet
? 'localnet'
: integration_test
? 'regtest'
: 'mainnet';
const networkType = testnet ? 'testnet' : localnet ? 'localnet' : 'mainnet';

const configData = loadConfig(configPath!, networkType);

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export async function getStacksWalletKeyInfo(
// btcAddress = const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey });
const { address } = bitcoin.payments.p2pkh({
pubkey: ecPair.publicKey,
network: bitcoin.networks.regtest,
network: bitcoin.networks.testnet,
});
btcAddress = address!;
} else {
Expand Down
10 changes: 2 additions & 8 deletions packages/cli/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { CLI_CONFIG_TYPE } from './argparse';

import { BlockstackNetwork } from 'blockstack/lib/network';

const SATOSHIS_PER_BTC = 1e8;

export interface CLI_NETWORK_OPTS {
consensusHash: string | null;
feeRate: number | null;
Expand Down Expand Up @@ -122,10 +120,6 @@ export class CLINetworkAdapter {
// override with CLI option
return Promise.resolve(this.feeRate);
}
if (this.isTestnet()) {
// in regtest mode
return Promise.resolve(Math.floor(0.00001 * SATOSHIS_PER_BTC));
}
return this.legacyNetwork.getFeeRate();
}

Expand Down Expand Up @@ -330,8 +324,8 @@ export class CLINetworkAdapter {
/*
* Instantiate a network using settings from the config file.
*/
export function getNetwork(configData: CLI_CONFIG_TYPE, regTest: boolean): BlockstackNetwork {
if (regTest) {
export function getNetwork(configData: CLI_CONFIG_TYPE, testNet: boolean): BlockstackNetwork {
if (testNet) {
const network = new blockstack.network.LocalRegtest(
configData.blockstackAPIUrl,
configData.broadcastServiceUrl,
Expand Down
4 changes: 1 addition & 3 deletions packages/network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ npm install @stacks/network

## Usage

Creating a Stacks mainnet, testnet, regtest or mocknet network
Creating a Stacks mainnet, testnet or mocknet network

```typescript
import { StacksMainnet, StacksTestnet, StacksMocknet } from '@stacks/network';
Expand All @@ -19,8 +19,6 @@ const network = new StacksMainnet();

const testnet = new StacksTestnet();

const regtest = new StacksRegtest();

const mocknet = new StacksMocknet();
```

Expand Down
10 changes: 0 additions & 10 deletions packages/network/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TransactionVersion, ChainID, fetchPrivate } from '@stacks/common';

export const HIRO_MAINNET_DEFAULT = 'https://stacks-node-api.mainnet.stacks.co';
export const HIRO_REGTEST_DEFAULT = 'https://stacks-node-api.regtest.stacks.co';
export const HIRO_TESTNET_DEFAULT = 'https://stacks-node-api.testnet.stacks.co';
export const HIRO_MOCKNET_DEFAULT = 'http://localhost:3999';

Expand Down Expand Up @@ -146,12 +145,3 @@ export class StacksMocknet extends StacksMainnet implements StacksNetwork {
super(networkUrl);
}
}

export class StacksRegtest extends StacksMainnet implements StacksNetwork {
version = TransactionVersion.Testnet;
chainId = ChainID.Testnet;

constructor(networkUrl: NetworkConfig = { url: HIRO_REGTEST_DEFAULT }) {
super(networkUrl);
}
}

1 comment on commit d9500ab

@vercel
Copy link

@vercel vercel bot commented on d9500ab Nov 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.