Skip to content

fix: Fix a regression from the v7.x.x update where the localnet/mock… #1795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as scureBip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
import { buildPreorderNameTx, buildRegisterNameTx } from '@stacks/bns';
import { bytesToHex, HIRO_MAINNET_URL, HIRO_TESTNET_URL } from '@stacks/common';
import { bytesToHex } from '@stacks/common';
import {
ACCOUNT_PATH,
broadcastTransaction,
Expand Down Expand Up @@ -86,11 +86,17 @@

import { decryptBackupPhrase, encryptBackupPhrase } from './encrypt';

import { CLI_NETWORK_OPTS, CLINetworkAdapter, getNetwork, NameInfoType } from './network';
import {
CLI_NETWORK_OPTS,
CLINetworkAdapter,
getNetwork,
getStacksNetwork,
NameInfoType,
} from './network';

import { gaiaAuth, gaiaConnect, gaiaUploadProfileAll, getGaiaAddressFromProfile } from './data';

import { defaultUrlFromNetwork, STACKS_MAINNET, STACKS_TESTNET } from '@stacks/network';
import { defaultUrlFromNetwork, STACKS_TESTNET } from '@stacks/network';
import {
generateNewAccount,
generateWallet,
Expand Down Expand Up @@ -263,10 +269,7 @@
}
const account = wallet.accounts[index - 1];
const privateKey = getAppPrivateKey({ account, appDomain });
const address = getAddressFromPrivateKey(
privateKey,
_network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET
);
const address = getAddressFromPrivateKey(privateKey, getStacksNetwork(_network));

Check warning on line 272 in packages/cli/src/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli/src/cli.ts#L272

Added line #L272 was not covered by tests

return JSON.stringify({ keyInfo: { privateKey, address } });
}
Expand Down Expand Up @@ -331,7 +334,7 @@
async function migrateSubdomains(_network: CLINetworkAdapter, args: string[]): Promise<string> {
const mnemonic: string = await getBackupPhrase(args[0]); // args[0] is the cli argument for mnemonic
const baseWallet = await generateWallet({ secretKey: mnemonic, password: '' });
const network = _network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET;
const network = getStacksNetwork(_network);
const wallet = await restoreWalletAccounts({
wallet: baseWallet,
gaiaHubUrl: 'https://hub.blockstack.org',
Expand Down Expand Up @@ -511,9 +514,7 @@
address = _network.coerceAddress(address);
}

// temporary hack to use network config from stacks-transactions lib
const url = _network.isMainnet() ? HIRO_MAINNET_URL : HIRO_TESTNET_URL;

const url = _network.nodeAPIUrl;
return fetch(`${url}${ACCOUNT_PATH}/${address}?proof=0`)
.then(response => {
if (response.status === 404) {
Expand Down Expand Up @@ -692,7 +693,7 @@
memo = args[5];
}

const network = _network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET;
const network = getStacksNetwork(_network);

Check warning on line 696 in packages/cli/src/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli/src/cli.ts#L696

Added line #L696 was not covered by tests

const options: SignedTokenTransferOptions = {
recipient: recipientAddress,
Expand Down Expand Up @@ -749,7 +750,7 @@

const source = fs.readFileSync(sourceFile).toString();

const network = _network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET;
const network = getStacksNetwork(_network);

Check warning on line 753 in packages/cli/src/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli/src/cli.ts#L753

Added line #L753 was not covered by tests

const options: SignedContractDeployOptions = {
contractName,
Expand Down Expand Up @@ -807,8 +808,7 @@
const nonce = BigInt(args[4]);
const privateKey = args[5];

// temporary hack to use network config from stacks-transactions lib
const network = _network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET;
const network = getStacksNetwork(_network);

let abi: ClarityAbi;
let abiArgs: ClarityFunctionArg[];
Expand Down Expand Up @@ -892,7 +892,7 @@
const functionName = args[2];
const senderAddress = args[3];

const network = _network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET;
const network = getStacksNetwork(_network);

Check warning on line 895 in packages/cli/src/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli/src/cli.ts#L895

Added line #L895 was not covered by tests

let abi: ClarityAbi;
let abiArgs: ClarityFunctionArg[];
Expand Down Expand Up @@ -1624,7 +1624,7 @@
async function stackingStatus(_network: CLINetworkAdapter, args: string[]): Promise<string> {
const address = args[0];

const network = _network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET;
const network = getStacksNetwork(_network);

Check warning on line 1627 in packages/cli/src/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli/src/cli.ts#L1627

Added line #L1627 was not covered by tests
const stacker = new StackingClient({ address, network });

return stacker
Expand Down Expand Up @@ -1656,7 +1656,7 @@
const poxAddress = args[2];
const stxAddress = args[3];

const network = _network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET;
const network = getStacksNetwork(_network);
const stacker = new StackingClient({ address: stxAddress, network });

const apiConfig = new Configuration({
Expand Down Expand Up @@ -1717,7 +1717,7 @@
// nonce = new BN(args[5]);
// }

const network = _network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET;
const network = getStacksNetwork(_network);

Check warning on line 1720 in packages/cli/src/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli/src/cli.ts#L1720

Added line #L1720 was not covered by tests

const apiConfig = new Configuration({
basePath: network.client.baseUrl,
Expand Down Expand Up @@ -1790,7 +1790,7 @@
const zonefile = args[3];
const publicKey = privateKeyToPublic(privateKey);

const network = _network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET;
const network = getStacksNetwork(_network);

const unsignedTransaction = await buildRegisterNameTx({
fullyQualifiedName,
Expand Down Expand Up @@ -1825,7 +1825,7 @@
const stxToBurn = args[3];
const publicKey = privateKeyToPublic(privateKey);

const network = _network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET;
const network = getStacksNetwork(_network);

const unsignedTransaction = await buildPreorderNameTx({
fullyQualifiedName,
Expand Down Expand Up @@ -2068,7 +2068,7 @@
altTransactionBroadcasterUrl: transactionBroadcasterUrl
? transactionBroadcasterUrl
: configData.broadcastServiceUrl,
nodeAPIUrl: nodeAPIUrl ? nodeAPIUrl : configData.blockstackNodeUrl,
nodeAPIUrl: nodeAPIUrl ? nodeAPIUrl : apiUrl ? apiUrl : configData.blockstackNodeUrl,
};

// wrap command-line options
Expand Down
12 changes: 12 additions & 0 deletions packages/cli/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as bitcoin from 'bitcoinjs-lib';
import blockstack from 'blockstack';
import { BlockstackNetwork } from 'blockstack/lib/network';
import { CLI_CONFIG_TYPE } from './argparse';
import { STACKS_MAINNET, STACKS_TESTNET, StacksNetwork } from '@stacks/network';

export interface CLI_NETWORK_OPTS {
consensusHash: string | null;
Expand Down Expand Up @@ -347,3 +348,14 @@ export function getNetwork(configData: CLI_CONFIG_TYPE, testNet: boolean): Block
return network;
}
}

/** @internal helper to convert a CLINetworkAdapter to a StacksNetwork */
export function getStacksNetwork(network: CLINetworkAdapter): StacksNetwork {
const basic = network.isMainnet() ? STACKS_MAINNET : STACKS_TESTNET;
return {
...basic,
client: {
baseUrl: network.nodeAPIUrl,
},
};
}
Loading
Loading