@secondlayer/cli 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +39 -20
- package/dist/cli.js.map +3 -3
- package/dist/index.js +40 -21
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -15811,12 +15811,44 @@ var init_clarity = () => {};
|
|
|
15811
15811
|
|
|
15812
15812
|
// src/generators/contract.ts
|
|
15813
15813
|
import { format } from "prettier";
|
|
15814
|
+
function generateNetworkUtils() {
|
|
15815
|
+
return `/**
|
|
15816
|
+
* API URLs for different networks
|
|
15817
|
+
*/
|
|
15818
|
+
const API_URLS: Record<'mainnet' | 'testnet' | 'devnet', string> = {
|
|
15819
|
+
mainnet: 'https://api.hiro.so',
|
|
15820
|
+
testnet: 'https://api.testnet.hiro.so',
|
|
15821
|
+
devnet: 'http://localhost:3999'
|
|
15822
|
+
};
|
|
15823
|
+
|
|
15824
|
+
/**
|
|
15825
|
+
* Infer network from Stacks address prefix
|
|
15826
|
+
* SP/SM = mainnet, ST/SN = testnet
|
|
15827
|
+
*/
|
|
15828
|
+
function inferNetworkFromAddress(address: string): 'mainnet' | 'testnet' | undefined {
|
|
15829
|
+
if (address.startsWith('SP') || address.startsWith('SM')) return 'mainnet';
|
|
15830
|
+
if (address.startsWith('ST') || address.startsWith('SN')) return 'testnet';
|
|
15831
|
+
return undefined;
|
|
15832
|
+
}
|
|
15833
|
+
|
|
15834
|
+
/**
|
|
15835
|
+
* Get API URL, inferring network from contract address if not specified
|
|
15836
|
+
*/
|
|
15837
|
+
function getApiUrl(
|
|
15838
|
+
contractAddress: string,
|
|
15839
|
+
explicitNetwork?: 'mainnet' | 'testnet' | 'devnet'
|
|
15840
|
+
): string {
|
|
15841
|
+
const network = explicitNetwork ?? inferNetworkFromAddress(contractAddress) ?? 'mainnet';
|
|
15842
|
+
return API_URLS[network];
|
|
15843
|
+
}`;
|
|
15844
|
+
}
|
|
15814
15845
|
async function generateContractInterface(contracts) {
|
|
15815
15846
|
const imports = `import { Cl, validateStacksAddress } from '@stacks/transactions'`;
|
|
15816
15847
|
const header = `/**
|
|
15817
15848
|
* Generated by @secondlayer/cli
|
|
15818
15849
|
* DO NOT EDIT MANUALLY
|
|
15819
15850
|
*/`;
|
|
15851
|
+
const networkUtils = generateNetworkUtils();
|
|
15820
15852
|
const contractsCode = contracts.map((contract) => generateContract(contract)).join(`
|
|
15821
15853
|
|
|
15822
15854
|
`);
|
|
@@ -15824,6 +15856,8 @@ async function generateContractInterface(contracts) {
|
|
|
15824
15856
|
|
|
15825
15857
|
${header}
|
|
15826
15858
|
|
|
15859
|
+
${networkUtils}
|
|
15860
|
+
|
|
15827
15861
|
${contractsCode}`;
|
|
15828
15862
|
const formatted = await format(code, {
|
|
15829
15863
|
parser: "typescript",
|
|
@@ -16074,12 +16108,7 @@ function generateMapsObject(maps, address, contractName) {
|
|
|
16074
16108
|
return `${methodName}: {
|
|
16075
16109
|
async get(key: ${keyType}, options?: { network?: 'mainnet' | 'testnet' | 'devnet' }): Promise<${valueType} | null> {
|
|
16076
16110
|
const { cvToJSON, serializeCV } = await import('@stacks/transactions');
|
|
16077
|
-
const
|
|
16078
|
-
mainnet: 'https://api.hiro.so',
|
|
16079
|
-
testnet: 'https://api.testnet.hiro.so',
|
|
16080
|
-
devnet: 'http://localhost:3999'
|
|
16081
|
-
};
|
|
16082
|
-
const baseUrl = apiUrls[options?.network || 'mainnet'];
|
|
16111
|
+
const baseUrl = getApiUrl('${address}', options?.network);
|
|
16083
16112
|
const mapKey = ${keyConversion};
|
|
16084
16113
|
const keyHex = serializeCV(mapKey).toString('hex');
|
|
16085
16114
|
|
|
@@ -16131,12 +16160,7 @@ function generateVarsObject(variables, address, contractName) {
|
|
|
16131
16160
|
return `${methodName}: {
|
|
16132
16161
|
async get(options?: { network?: 'mainnet' | 'testnet' | 'devnet' }): Promise<${valueType}> {
|
|
16133
16162
|
const { cvToJSON, deserializeCV } = await import('@stacks/transactions');
|
|
16134
|
-
const
|
|
16135
|
-
mainnet: 'https://api.hiro.so',
|
|
16136
|
-
testnet: 'https://api.testnet.hiro.so',
|
|
16137
|
-
devnet: 'http://localhost:3999'
|
|
16138
|
-
};
|
|
16139
|
-
const baseUrl = apiUrls[options?.network || 'mainnet'];
|
|
16163
|
+
const baseUrl = getApiUrl('${address}', options?.network);
|
|
16140
16164
|
|
|
16141
16165
|
const response = await fetch(
|
|
16142
16166
|
\`\${baseUrl}/v2/data_var/${address}/${contractName}/${variable.name}?proof=0\`
|
|
@@ -16174,12 +16198,7 @@ function generateConstantsObject(variables, address, contractName) {
|
|
|
16174
16198
|
return `${methodName}: {
|
|
16175
16199
|
async get(options?: { network?: 'mainnet' | 'testnet' | 'devnet' }): Promise<${valueType}> {
|
|
16176
16200
|
const { cvToJSON, deserializeCV } = await import('@stacks/transactions');
|
|
16177
|
-
const
|
|
16178
|
-
mainnet: 'https://api.hiro.so',
|
|
16179
|
-
testnet: 'https://api.testnet.hiro.so',
|
|
16180
|
-
devnet: 'http://localhost:3999'
|
|
16181
|
-
};
|
|
16182
|
-
const baseUrl = apiUrls[options?.network || 'mainnet'];
|
|
16201
|
+
const baseUrl = getApiUrl('${address}', options?.network);
|
|
16183
16202
|
|
|
16184
16203
|
const response = await fetch(
|
|
16185
16204
|
\`\${baseUrl}/v2/constant_val/${address}/${contractName}/${constant.name}?proof=0\`
|
|
@@ -16543,7 +16562,7 @@ var {
|
|
|
16543
16562
|
// package.json
|
|
16544
16563
|
var package_default = {
|
|
16545
16564
|
name: "@secondlayer/cli",
|
|
16546
|
-
version: "0.3.
|
|
16565
|
+
version: "0.3.1",
|
|
16547
16566
|
description: "CLI for generating type-safe contract interfaces for the Stacks blockchain",
|
|
16548
16567
|
type: "module",
|
|
16549
16568
|
bin: {
|
|
@@ -16619,5 +16638,5 @@ program.command("init").description("Initialize a new stacks.config.ts file").ac
|
|
|
16619
16638
|
});
|
|
16620
16639
|
program.parse();
|
|
16621
16640
|
|
|
16622
|
-
//# debugId=
|
|
16641
|
+
//# debugId=00D09707C564934264756E2164756E21
|
|
16623
16642
|
//# sourceMappingURL=cli.js.map
|