@stacks/network 2.0.1 → 3.2.0
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/CHANGELOG.md +11 -0
- package/README.md +18 -16
- package/dist/esm/index.d.ts +12 -33
- package/dist/esm/index.js +30 -18
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +12 -33
- package/dist/index.js +33 -21
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +41 -56
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.2.0](https://github.com/blockstack/blockstack.js/compare/v3.1.1...v3.2.0) (2022-02-02)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* reduce reliance on network package ([422fda3](https://github.com/blockstack/blockstack.js/commit/422fda3cd43e16ae24ea9d97297b423a90823672))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [2.0.1](https://github.com/blockstack/blockstack.js/compare/v2.0.1-beta.2...v2.0.1) (2021-08-09)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @stacks/network
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ npm install @stacks/network
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
Creating a Stacks mainnet, testnet
|
|
13
|
+
Creating a Stacks mainnet, testnet or mocknet network
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
16
|
import { StacksMainnet, StacksTestnet, StacksMocknet } from '@stacks/network';
|
|
@@ -19,15 +19,13 @@ const network = new StacksMainnet();
|
|
|
19
19
|
|
|
20
20
|
const testnet = new StacksTestnet();
|
|
21
21
|
|
|
22
|
-
const regtest = new StacksRegtest();
|
|
23
|
-
|
|
24
22
|
const mocknet = new StacksMocknet();
|
|
25
23
|
```
|
|
26
24
|
|
|
27
25
|
Setting a custom node URL
|
|
28
26
|
|
|
29
27
|
```typescript
|
|
30
|
-
network
|
|
28
|
+
const network = new StacksMainnet({ url: 'https://www.mystacksnode.com/' });
|
|
31
29
|
```
|
|
32
30
|
|
|
33
31
|
Check if network is mainnet
|
|
@@ -54,22 +52,26 @@ const transaction = await makeSTXTokenTransfer(txOptions);
|
|
|
54
52
|
Get various API URLs
|
|
55
53
|
|
|
56
54
|
```typescript
|
|
57
|
-
|
|
55
|
+
const txBroadcastUrl = network.getBroadcastApiUrl();
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
const feeEstimateUrl = network.getTransferFeeEstimateApiUrl();
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
const address = 'SP2BS6HD7TN34V8Z5BNF8Q2AW3K8K2DPV4264CF26';
|
|
60
|
+
const accountInfoUrl = network.getAccountApiUrl(address);
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
const contractName = 'hello_world';
|
|
63
|
+
const abiUrl = network.getAbiApiUrl(address, contractName);
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const functionName = 'hello';
|
|
66
|
+
const readOnlyFunctionCallUrl = network.getReadOnlyFunctionCallApiUrl(
|
|
67
|
+
address,
|
|
68
|
+
contractName,
|
|
69
|
+
functionName
|
|
70
|
+
);
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
const nodeInfoUrl = network.getInfoUrl();
|
|
71
73
|
|
|
72
|
-
|
|
74
|
+
const blockTimeUrl = network.getBlockTimeInfoUrl();
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
```
|
|
76
|
+
const poxInfoUrl = network.getPoxInfoUrl();
|
|
77
|
+
```
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,51 +1,30 @@
|
|
|
1
1
|
import { TransactionVersion, ChainID } from '@stacks/common';
|
|
2
2
|
export declare const HIRO_MAINNET_DEFAULT = "https://stacks-node-api.mainnet.stacks.co";
|
|
3
|
-
export declare const HIRO_REGTEST_DEFAULT = "https://stacks-node-api.regtest.stacks.co";
|
|
4
3
|
export declare const HIRO_TESTNET_DEFAULT = "https://stacks-node-api.testnet.stacks.co";
|
|
5
4
|
export declare const HIRO_MOCKNET_DEFAULT = "http://localhost:3999";
|
|
6
5
|
export interface NetworkConfig {
|
|
7
6
|
url: string;
|
|
8
7
|
}
|
|
9
|
-
export
|
|
8
|
+
export declare const StacksNetworks: readonly ["mainnet", "testnet"];
|
|
9
|
+
export declare type StacksNetworkName = typeof StacksNetworks[number];
|
|
10
|
+
export declare class StacksNetwork {
|
|
10
11
|
version: TransactionVersion;
|
|
11
12
|
chainId: ChainID;
|
|
12
13
|
bnsLookupUrl: string;
|
|
13
14
|
broadcastEndpoint: string;
|
|
14
15
|
transferFeeEstimateEndpoint: string;
|
|
16
|
+
transactionFeeEstimateEndpoint: string;
|
|
15
17
|
accountEndpoint: string;
|
|
16
18
|
contractAbiEndpoint: string;
|
|
17
19
|
readOnlyFunctionCallEndpoint: string;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
getAbiApiUrl: (address: string, contract: string) => string;
|
|
23
|
-
getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
|
|
24
|
-
getInfoUrl: () => string;
|
|
25
|
-
getBlockTimeInfoUrl: () => string;
|
|
26
|
-
getPoxInfoUrl: () => string;
|
|
27
|
-
getRewardsUrl: (address: string, options?: any) => string;
|
|
28
|
-
getRewardHoldersUrl: (address: string, options?: any) => string;
|
|
29
|
-
getRewardsTotalUrl: (address: string) => string;
|
|
30
|
-
getStackerInfoUrl: (contractAddress: string, contractName: string) => string;
|
|
31
|
-
getNameInfo: (fullyQualifiedName: string) => any;
|
|
32
|
-
}
|
|
33
|
-
export declare class StacksMainnet implements StacksNetwork {
|
|
34
|
-
version: TransactionVersion;
|
|
35
|
-
chainId: ChainID;
|
|
36
|
-
bnsLookupUrl: string;
|
|
37
|
-
broadcastEndpoint: string;
|
|
38
|
-
transferFeeEstimateEndpoint: string;
|
|
39
|
-
accountEndpoint: string;
|
|
40
|
-
contractAbiEndpoint: string;
|
|
41
|
-
readOnlyFunctionCallEndpoint: string;
|
|
42
|
-
private _coreApiUrl;
|
|
43
|
-
get coreApiUrl(): string;
|
|
44
|
-
set coreApiUrl(_url: string);
|
|
45
|
-
constructor(networkUrl?: NetworkConfig);
|
|
20
|
+
readonly coreApiUrl: string;
|
|
21
|
+
constructor(networkConfig: NetworkConfig);
|
|
22
|
+
static fromName: (networkName: StacksNetworkName) => StacksNetwork;
|
|
23
|
+
static fromNameOrNetwork: (network: StacksNetworkName | StacksNetwork) => StacksNetwork;
|
|
46
24
|
isMainnet: () => boolean;
|
|
47
25
|
getBroadcastApiUrl: () => string;
|
|
48
26
|
getTransferFeeEstimateApiUrl: () => string;
|
|
27
|
+
getTransactionFeeEstimateApiUrl: () => string;
|
|
49
28
|
getAccountApiUrl: (address: string) => string;
|
|
50
29
|
getAbiApiUrl: (address: string, contract: string) => string;
|
|
51
30
|
getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
|
|
@@ -58,17 +37,17 @@ export declare class StacksMainnet implements StacksNetwork {
|
|
|
58
37
|
getStackerInfoUrl: (contractAddress: string, contractName: string) => string;
|
|
59
38
|
getNameInfo(fullyQualifiedName: string): Promise<any>;
|
|
60
39
|
}
|
|
61
|
-
export declare class
|
|
40
|
+
export declare class StacksMainnet extends StacksNetwork {
|
|
62
41
|
version: TransactionVersion;
|
|
63
42
|
chainId: ChainID;
|
|
64
43
|
constructor(networkUrl?: NetworkConfig);
|
|
65
44
|
}
|
|
66
|
-
export declare class
|
|
45
|
+
export declare class StacksTestnet extends StacksNetwork {
|
|
67
46
|
version: TransactionVersion;
|
|
68
47
|
chainId: ChainID;
|
|
69
48
|
constructor(networkUrl?: NetworkConfig);
|
|
70
49
|
}
|
|
71
|
-
export declare class
|
|
50
|
+
export declare class StacksMocknet extends StacksNetwork {
|
|
72
51
|
version: TransactionVersion;
|
|
73
52
|
chainId: ChainID;
|
|
74
53
|
constructor(networkUrl?: NetworkConfig);
|
package/dist/esm/index.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { TransactionVersion, ChainID, fetchPrivate } from '@stacks/common';
|
|
2
2
|
export const HIRO_MAINNET_DEFAULT = 'https://stacks-node-api.mainnet.stacks.co';
|
|
3
|
-
export const HIRO_REGTEST_DEFAULT = 'https://stacks-node-api.regtest.stacks.co';
|
|
4
3
|
export const HIRO_TESTNET_DEFAULT = 'https://stacks-node-api.testnet.stacks.co';
|
|
5
4
|
export const HIRO_MOCKNET_DEFAULT = 'http://localhost:3999';
|
|
6
|
-
export
|
|
7
|
-
|
|
5
|
+
export const StacksNetworks = ['mainnet', 'testnet'];
|
|
6
|
+
export class StacksNetwork {
|
|
7
|
+
constructor(networkConfig) {
|
|
8
8
|
this.version = TransactionVersion.Mainnet;
|
|
9
9
|
this.chainId = ChainID.Mainnet;
|
|
10
10
|
this.bnsLookupUrl = 'https://stacks-node-api.mainnet.stacks.co';
|
|
11
11
|
this.broadcastEndpoint = '/v2/transactions';
|
|
12
12
|
this.transferFeeEstimateEndpoint = '/v2/fees/transfer';
|
|
13
|
+
this.transactionFeeEstimateEndpoint = '/v2/fees/transaction';
|
|
13
14
|
this.accountEndpoint = '/v2/accounts';
|
|
14
15
|
this.contractAbiEndpoint = '/v2/contracts/interface';
|
|
15
16
|
this.readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
|
|
16
17
|
this.isMainnet = () => this.version === TransactionVersion.Mainnet;
|
|
17
18
|
this.getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
|
|
18
19
|
this.getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
|
|
20
|
+
this.getTransactionFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`;
|
|
19
21
|
this.getAccountApiUrl = (address) => `${this.coreApiUrl}${this.accountEndpoint}/${address}?proof=0`;
|
|
20
22
|
this.getAbiApiUrl = (address, contract) => `${this.coreApiUrl}${this.contractAbiEndpoint}/${address}/${contract}`;
|
|
21
23
|
this.getReadOnlyFunctionCallApiUrl = (contractAddress, contractName, functionName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${contractAddress}/${contractName}/${encodeURIComponent(functionName)}`;
|
|
@@ -39,13 +41,7 @@ export class StacksMainnet {
|
|
|
39
41
|
};
|
|
40
42
|
this.getStackerInfoUrl = (contractAddress, contractName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}
|
|
41
43
|
${contractAddress}/${contractName}/get-stacker-info`;
|
|
42
|
-
this.
|
|
43
|
-
}
|
|
44
|
-
get coreApiUrl() {
|
|
45
|
-
return this._coreApiUrl;
|
|
46
|
-
}
|
|
47
|
-
set coreApiUrl(_url) {
|
|
48
|
-
throw new Error('Cannot modify property `coreApiUrl` after object initialization');
|
|
44
|
+
this.coreApiUrl = networkConfig.url;
|
|
49
45
|
}
|
|
50
46
|
getNameInfo(fullyQualifiedName) {
|
|
51
47
|
const nameLookupURL = `${this.bnsLookupUrl}/v1/names/${fullyQualifiedName}`;
|
|
@@ -71,22 +67,38 @@ export class StacksMainnet {
|
|
|
71
67
|
});
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
StacksNetwork.fromName = (networkName) => {
|
|
71
|
+
switch (networkName) {
|
|
72
|
+
case 'mainnet':
|
|
73
|
+
return new StacksMainnet();
|
|
74
|
+
case 'testnet':
|
|
75
|
+
return new StacksTestnet();
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Invalid network name provided. Must be one of the following: ${StacksNetworks.join(', ')}`);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
StacksNetwork.fromNameOrNetwork = (network) => {
|
|
81
|
+
if (typeof network !== 'string' && 'version' in network) {
|
|
82
|
+
return network;
|
|
83
|
+
}
|
|
84
|
+
return StacksNetwork.fromName(network);
|
|
85
|
+
};
|
|
86
|
+
export class StacksMainnet extends StacksNetwork {
|
|
87
|
+
constructor(networkUrl = { url: HIRO_MAINNET_DEFAULT }) {
|
|
76
88
|
super(networkUrl);
|
|
77
|
-
this.version = TransactionVersion.
|
|
78
|
-
this.chainId = ChainID.
|
|
89
|
+
this.version = TransactionVersion.Mainnet;
|
|
90
|
+
this.chainId = ChainID.Mainnet;
|
|
79
91
|
}
|
|
80
92
|
}
|
|
81
|
-
export class
|
|
82
|
-
constructor(networkUrl = { url:
|
|
93
|
+
export class StacksTestnet extends StacksNetwork {
|
|
94
|
+
constructor(networkUrl = { url: HIRO_TESTNET_DEFAULT }) {
|
|
83
95
|
super(networkUrl);
|
|
84
96
|
this.version = TransactionVersion.Testnet;
|
|
85
97
|
this.chainId = ChainID.Testnet;
|
|
86
98
|
}
|
|
87
99
|
}
|
|
88
|
-
export class
|
|
89
|
-
constructor(networkUrl = { url:
|
|
100
|
+
export class StacksMocknet extends StacksNetwork {
|
|
101
|
+
constructor(networkUrl = { url: HIRO_MOCKNET_DEFAULT }) {
|
|
90
102
|
super(networkUrl);
|
|
91
103
|
this.version = TransactionVersion.Testnet;
|
|
92
104
|
this.chainId = ChainID.Testnet;
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3E,MAAM,CAAC,MAAM,oBAAoB,GAAG,2CAA2C,CAAC;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG,2CAA2C,CAAC;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG,
|
|
1
|
+
{"version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AK,CACb,gEAAgE,cAAc,CAAC,IAAI,CACjF,IAAI,CACL,EAAE,CACJ,CAAC;KACL;AACH,CAAC,CAAC;AAEK,+BAAiB,GAAG,CAAC,OAA0C,EAAE,EAAE;IACxE,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,SAAS,IAAI,OAAO,EAAE;QACvD,OAAO,OAAO,CAAC;KAChB;IAED,OAAO,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC,CAAC;AAqEJ,MAAM,OAAO,aAAc,SAAQ,aAAa;IAI9C,YAAY,aAA4B,EAAE,GAAG,EAAE,oBAAoB,EAAE;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAJpB,YAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAI1B,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,aAAa;IAI9C,YAAY,aAA4B,EAAE,GAAG,EAAE,oBAAoB,EAAE;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAJpB,YAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAI1B,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,aAAa;IAI9C,YAAY,aAA4B,EAAE,GAAG,EAAE,oBAAoB,EAAE;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAJpB,YAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAI1B,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,51 +1,30 @@
|
|
|
1
1
|
import { TransactionVersion, ChainID } from '@stacks/common';
|
|
2
2
|
export declare const HIRO_MAINNET_DEFAULT = "https://stacks-node-api.mainnet.stacks.co";
|
|
3
|
-
export declare const HIRO_REGTEST_DEFAULT = "https://stacks-node-api.regtest.stacks.co";
|
|
4
3
|
export declare const HIRO_TESTNET_DEFAULT = "https://stacks-node-api.testnet.stacks.co";
|
|
5
4
|
export declare const HIRO_MOCKNET_DEFAULT = "http://localhost:3999";
|
|
6
5
|
export interface NetworkConfig {
|
|
7
6
|
url: string;
|
|
8
7
|
}
|
|
9
|
-
export
|
|
8
|
+
export declare const StacksNetworks: readonly ["mainnet", "testnet"];
|
|
9
|
+
export declare type StacksNetworkName = typeof StacksNetworks[number];
|
|
10
|
+
export declare class StacksNetwork {
|
|
10
11
|
version: TransactionVersion;
|
|
11
12
|
chainId: ChainID;
|
|
12
13
|
bnsLookupUrl: string;
|
|
13
14
|
broadcastEndpoint: string;
|
|
14
15
|
transferFeeEstimateEndpoint: string;
|
|
16
|
+
transactionFeeEstimateEndpoint: string;
|
|
15
17
|
accountEndpoint: string;
|
|
16
18
|
contractAbiEndpoint: string;
|
|
17
19
|
readOnlyFunctionCallEndpoint: string;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
getAbiApiUrl: (address: string, contract: string) => string;
|
|
23
|
-
getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
|
|
24
|
-
getInfoUrl: () => string;
|
|
25
|
-
getBlockTimeInfoUrl: () => string;
|
|
26
|
-
getPoxInfoUrl: () => string;
|
|
27
|
-
getRewardsUrl: (address: string, options?: any) => string;
|
|
28
|
-
getRewardHoldersUrl: (address: string, options?: any) => string;
|
|
29
|
-
getRewardsTotalUrl: (address: string) => string;
|
|
30
|
-
getStackerInfoUrl: (contractAddress: string, contractName: string) => string;
|
|
31
|
-
getNameInfo: (fullyQualifiedName: string) => any;
|
|
32
|
-
}
|
|
33
|
-
export declare class StacksMainnet implements StacksNetwork {
|
|
34
|
-
version: TransactionVersion;
|
|
35
|
-
chainId: ChainID;
|
|
36
|
-
bnsLookupUrl: string;
|
|
37
|
-
broadcastEndpoint: string;
|
|
38
|
-
transferFeeEstimateEndpoint: string;
|
|
39
|
-
accountEndpoint: string;
|
|
40
|
-
contractAbiEndpoint: string;
|
|
41
|
-
readOnlyFunctionCallEndpoint: string;
|
|
42
|
-
private _coreApiUrl;
|
|
43
|
-
get coreApiUrl(): string;
|
|
44
|
-
set coreApiUrl(_url: string);
|
|
45
|
-
constructor(networkUrl?: NetworkConfig);
|
|
20
|
+
readonly coreApiUrl: string;
|
|
21
|
+
constructor(networkConfig: NetworkConfig);
|
|
22
|
+
static fromName: (networkName: StacksNetworkName) => StacksNetwork;
|
|
23
|
+
static fromNameOrNetwork: (network: StacksNetworkName | StacksNetwork) => StacksNetwork;
|
|
46
24
|
isMainnet: () => boolean;
|
|
47
25
|
getBroadcastApiUrl: () => string;
|
|
48
26
|
getTransferFeeEstimateApiUrl: () => string;
|
|
27
|
+
getTransactionFeeEstimateApiUrl: () => string;
|
|
49
28
|
getAccountApiUrl: (address: string) => string;
|
|
50
29
|
getAbiApiUrl: (address: string, contract: string) => string;
|
|
51
30
|
getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
|
|
@@ -58,17 +37,17 @@ export declare class StacksMainnet implements StacksNetwork {
|
|
|
58
37
|
getStackerInfoUrl: (contractAddress: string, contractName: string) => string;
|
|
59
38
|
getNameInfo(fullyQualifiedName: string): Promise<any>;
|
|
60
39
|
}
|
|
61
|
-
export declare class
|
|
40
|
+
export declare class StacksMainnet extends StacksNetwork {
|
|
62
41
|
version: TransactionVersion;
|
|
63
42
|
chainId: ChainID;
|
|
64
43
|
constructor(networkUrl?: NetworkConfig);
|
|
65
44
|
}
|
|
66
|
-
export declare class
|
|
45
|
+
export declare class StacksTestnet extends StacksNetwork {
|
|
67
46
|
version: TransactionVersion;
|
|
68
47
|
chainId: ChainID;
|
|
69
48
|
constructor(networkUrl?: NetworkConfig);
|
|
70
49
|
}
|
|
71
|
-
export declare class
|
|
50
|
+
export declare class StacksMocknet extends StacksNetwork {
|
|
72
51
|
version: TransactionVersion;
|
|
73
52
|
chainId: ChainID;
|
|
74
53
|
constructor(networkUrl?: NetworkConfig);
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.StacksMocknet = exports.StacksTestnet = exports.StacksMainnet = exports.StacksNetwork = exports.StacksNetworks = exports.HIRO_MOCKNET_DEFAULT = exports.HIRO_TESTNET_DEFAULT = exports.HIRO_MAINNET_DEFAULT = void 0;
|
|
4
4
|
const common_1 = require("@stacks/common");
|
|
5
5
|
exports.HIRO_MAINNET_DEFAULT = 'https://stacks-node-api.mainnet.stacks.co';
|
|
6
|
-
exports.HIRO_REGTEST_DEFAULT = 'https://stacks-node-api.regtest.stacks.co';
|
|
7
6
|
exports.HIRO_TESTNET_DEFAULT = 'https://stacks-node-api.testnet.stacks.co';
|
|
8
7
|
exports.HIRO_MOCKNET_DEFAULT = 'http://localhost:3999';
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
exports.StacksNetworks = ['mainnet', 'testnet'];
|
|
9
|
+
class StacksNetwork {
|
|
10
|
+
constructor(networkConfig) {
|
|
11
11
|
this.version = common_1.TransactionVersion.Mainnet;
|
|
12
12
|
this.chainId = common_1.ChainID.Mainnet;
|
|
13
13
|
this.bnsLookupUrl = 'https://stacks-node-api.mainnet.stacks.co';
|
|
14
14
|
this.broadcastEndpoint = '/v2/transactions';
|
|
15
15
|
this.transferFeeEstimateEndpoint = '/v2/fees/transfer';
|
|
16
|
+
this.transactionFeeEstimateEndpoint = '/v2/fees/transaction';
|
|
16
17
|
this.accountEndpoint = '/v2/accounts';
|
|
17
18
|
this.contractAbiEndpoint = '/v2/contracts/interface';
|
|
18
19
|
this.readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
|
|
19
20
|
this.isMainnet = () => this.version === common_1.TransactionVersion.Mainnet;
|
|
20
21
|
this.getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
|
|
21
22
|
this.getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
|
|
23
|
+
this.getTransactionFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`;
|
|
22
24
|
this.getAccountApiUrl = (address) => `${this.coreApiUrl}${this.accountEndpoint}/${address}?proof=0`;
|
|
23
25
|
this.getAbiApiUrl = (address, contract) => `${this.coreApiUrl}${this.contractAbiEndpoint}/${address}/${contract}`;
|
|
24
26
|
this.getReadOnlyFunctionCallApiUrl = (contractAddress, contractName, functionName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${contractAddress}/${contractName}/${encodeURIComponent(functionName)}`;
|
|
@@ -42,13 +44,7 @@ class StacksMainnet {
|
|
|
42
44
|
};
|
|
43
45
|
this.getStackerInfoUrl = (contractAddress, contractName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}
|
|
44
46
|
${contractAddress}/${contractName}/get-stacker-info`;
|
|
45
|
-
this.
|
|
46
|
-
}
|
|
47
|
-
get coreApiUrl() {
|
|
48
|
-
return this._coreApiUrl;
|
|
49
|
-
}
|
|
50
|
-
set coreApiUrl(_url) {
|
|
51
|
-
throw new Error('Cannot modify property `coreApiUrl` after object initialization');
|
|
47
|
+
this.coreApiUrl = networkConfig.url;
|
|
52
48
|
}
|
|
53
49
|
getNameInfo(fullyQualifiedName) {
|
|
54
50
|
const nameLookupURL = `${this.bnsLookupUrl}/v1/names/${fullyQualifiedName}`;
|
|
@@ -74,8 +70,32 @@ class StacksMainnet {
|
|
|
74
70
|
});
|
|
75
71
|
}
|
|
76
72
|
}
|
|
73
|
+
exports.StacksNetwork = StacksNetwork;
|
|
74
|
+
StacksNetwork.fromName = (networkName) => {
|
|
75
|
+
switch (networkName) {
|
|
76
|
+
case 'mainnet':
|
|
77
|
+
return new StacksMainnet();
|
|
78
|
+
case 'testnet':
|
|
79
|
+
return new StacksTestnet();
|
|
80
|
+
default:
|
|
81
|
+
throw new Error(`Invalid network name provided. Must be one of the following: ${exports.StacksNetworks.join(', ')}`);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
StacksNetwork.fromNameOrNetwork = (network) => {
|
|
85
|
+
if (typeof network !== 'string' && 'version' in network) {
|
|
86
|
+
return network;
|
|
87
|
+
}
|
|
88
|
+
return StacksNetwork.fromName(network);
|
|
89
|
+
};
|
|
90
|
+
class StacksMainnet extends StacksNetwork {
|
|
91
|
+
constructor(networkUrl = { url: exports.HIRO_MAINNET_DEFAULT }) {
|
|
92
|
+
super(networkUrl);
|
|
93
|
+
this.version = common_1.TransactionVersion.Mainnet;
|
|
94
|
+
this.chainId = common_1.ChainID.Mainnet;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
77
97
|
exports.StacksMainnet = StacksMainnet;
|
|
78
|
-
class StacksTestnet extends
|
|
98
|
+
class StacksTestnet extends StacksNetwork {
|
|
79
99
|
constructor(networkUrl = { url: exports.HIRO_TESTNET_DEFAULT }) {
|
|
80
100
|
super(networkUrl);
|
|
81
101
|
this.version = common_1.TransactionVersion.Testnet;
|
|
@@ -83,7 +103,7 @@ class StacksTestnet extends StacksMainnet {
|
|
|
83
103
|
}
|
|
84
104
|
}
|
|
85
105
|
exports.StacksTestnet = StacksTestnet;
|
|
86
|
-
class StacksMocknet extends
|
|
106
|
+
class StacksMocknet extends StacksNetwork {
|
|
87
107
|
constructor(networkUrl = { url: exports.HIRO_MOCKNET_DEFAULT }) {
|
|
88
108
|
super(networkUrl);
|
|
89
109
|
this.version = common_1.TransactionVersion.Testnet;
|
|
@@ -91,12 +111,4 @@ class StacksMocknet extends StacksMainnet {
|
|
|
91
111
|
}
|
|
92
112
|
}
|
|
93
113
|
exports.StacksMocknet = StacksMocknet;
|
|
94
|
-
class StacksRegtest extends StacksMainnet {
|
|
95
|
-
constructor(networkUrl = { url: exports.HIRO_REGTEST_DEFAULT }) {
|
|
96
|
-
super(networkUrl);
|
|
97
|
-
this.version = common_1.TransactionVersion.Testnet;
|
|
98
|
-
this.chainId = common_1.ChainID.Testnet;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.StacksRegtest = StacksRegtest;
|
|
102
114
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAA2E;AAE9D,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAA2E;AAE9D,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,uBAAuB,CAAC;AAM/C,QAAA,cAAc,GAAG,CAAC,SAAS,EAAE,SAAS,CAAU,CAAC;AAG9D,MAAa,aAAa;IAaxB,YAAY,aAA4B;QAZxC,YAAO,GAAG,2BAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,gBAAO,CAAC,OAAO,CAAC;QAC1B,iBAAY,GAAG,2CAA2C,CAAC;QAC3D,sBAAiB,GAAG,kBAAkB,CAAC;QACvC,gCAA2B,GAAG,mBAAmB,CAAC;QAClD,mCAA8B,GAAG,sBAAsB,CAAC;QACxD,oBAAe,GAAG,cAAc,CAAC;QACjC,wBAAmB,GAAG,yBAAyB,CAAC;QAChD,iCAA4B,GAAG,yBAAyB,CAAC;QA+BzD,cAAS,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,2BAAkB,CAAC,OAAO,CAAC;QAC9D,uBAAkB,GAAG,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzE,iCAA4B,G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2BAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,gBAAO,CAAC,OAAO,CAAC;IAI1B,CAAC;CACF;AAPD,sCAOC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacks/network",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Library for Stacks network operations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"stacks",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"url": "https://github.com/blockstack/blockstack.js/issues"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@stacks/common": "^
|
|
41
|
+
"@stacks/common": "^3.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/jest": "^26.0.22",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"typings": "dist/index.d.ts",
|
|
59
59
|
"umd:main": "dist/index.umd.js",
|
|
60
60
|
"unpkg": "dist/index.umd.js",
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "cfabdf8a48269e35e72f5e558fc722a55da02a5e"
|
|
62
62
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TransactionVersion, ChainID, fetchPrivate } from '@stacks/common';
|
|
2
2
|
|
|
3
3
|
export const HIRO_MAINNET_DEFAULT = 'https://stacks-node-api.mainnet.stacks.co';
|
|
4
|
-
export const HIRO_REGTEST_DEFAULT = 'https://stacks-node-api.regtest.stacks.co';
|
|
5
4
|
export const HIRO_TESTNET_DEFAULT = 'https://stacks-node-api.testnet.stacks.co';
|
|
6
5
|
export const HIRO_MOCKNET_DEFAULT = 'http://localhost:3999';
|
|
7
6
|
|
|
@@ -9,68 +8,54 @@ export interface NetworkConfig {
|
|
|
9
8
|
url: string;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
chainId: ChainID;
|
|
15
|
-
bnsLookupUrl: string;
|
|
16
|
-
broadcastEndpoint: string;
|
|
17
|
-
transferFeeEstimateEndpoint: string;
|
|
18
|
-
accountEndpoint: string;
|
|
19
|
-
contractAbiEndpoint: string;
|
|
20
|
-
readOnlyFunctionCallEndpoint: string;
|
|
21
|
-
isMainnet(): boolean;
|
|
22
|
-
getBroadcastApiUrl: () => string;
|
|
23
|
-
getTransferFeeEstimateApiUrl: () => string;
|
|
24
|
-
getAccountApiUrl: (address: string) => string;
|
|
25
|
-
getAbiApiUrl: (address: string, contract: string) => string;
|
|
26
|
-
getReadOnlyFunctionCallApiUrl: (
|
|
27
|
-
contractAddress: string,
|
|
28
|
-
contractName: string,
|
|
29
|
-
functionName: string
|
|
30
|
-
) => string;
|
|
31
|
-
getInfoUrl: () => string;
|
|
32
|
-
getBlockTimeInfoUrl: () => string;
|
|
33
|
-
getPoxInfoUrl: () => string;
|
|
34
|
-
getRewardsUrl: (address: string, options?: any) => string;
|
|
35
|
-
getRewardHoldersUrl: (address: string, options?: any) => string;
|
|
36
|
-
getRewardsTotalUrl: (address: string) => string;
|
|
37
|
-
getStackerInfoUrl: (contractAddress: string, contractName: string) => string;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Get WHOIS-like information for a name, including the address that owns it,
|
|
41
|
-
* the block at which it expires, and the zone file anchored to it (if available).
|
|
42
|
-
*
|
|
43
|
-
* This is intended for use in third-party wallets or in DApps that register names.
|
|
44
|
-
* @param fullyQualifiedName the name to query. Can be on-chain of off-chain.
|
|
45
|
-
* @return a promise that resolves to the WHOIS-like information
|
|
46
|
-
*/
|
|
47
|
-
getNameInfo: (fullyQualifiedName: string) => any;
|
|
48
|
-
}
|
|
11
|
+
export const StacksNetworks = ['mainnet', 'testnet'] as const;
|
|
12
|
+
export type StacksNetworkName = typeof StacksNetworks[number];
|
|
49
13
|
|
|
50
|
-
export class
|
|
14
|
+
export class StacksNetwork {
|
|
51
15
|
version = TransactionVersion.Mainnet;
|
|
52
16
|
chainId = ChainID.Mainnet;
|
|
53
17
|
bnsLookupUrl = 'https://stacks-node-api.mainnet.stacks.co';
|
|
54
18
|
broadcastEndpoint = '/v2/transactions';
|
|
55
19
|
transferFeeEstimateEndpoint = '/v2/fees/transfer';
|
|
20
|
+
transactionFeeEstimateEndpoint = '/v2/fees/transaction';
|
|
56
21
|
accountEndpoint = '/v2/accounts';
|
|
57
22
|
contractAbiEndpoint = '/v2/contracts/interface';
|
|
58
23
|
readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
|
|
59
|
-
private _coreApiUrl: string;
|
|
60
24
|
|
|
61
|
-
|
|
62
|
-
return this._coreApiUrl;
|
|
63
|
-
}
|
|
64
|
-
set coreApiUrl(_url: string) {
|
|
65
|
-
throw new Error('Cannot modify property `coreApiUrl` after object initialization');
|
|
66
|
-
}
|
|
25
|
+
readonly coreApiUrl: string;
|
|
67
26
|
|
|
68
|
-
constructor(
|
|
69
|
-
this.
|
|
27
|
+
constructor(networkConfig: NetworkConfig) {
|
|
28
|
+
this.coreApiUrl = networkConfig.url;
|
|
70
29
|
}
|
|
30
|
+
|
|
31
|
+
static fromName = (networkName: StacksNetworkName): StacksNetwork => {
|
|
32
|
+
switch (networkName) {
|
|
33
|
+
case 'mainnet':
|
|
34
|
+
return new StacksMainnet();
|
|
35
|
+
case 'testnet':
|
|
36
|
+
return new StacksTestnet();
|
|
37
|
+
default:
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Invalid network name provided. Must be one of the following: ${StacksNetworks.join(
|
|
40
|
+
', '
|
|
41
|
+
)}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
static fromNameOrNetwork = (network: StacksNetworkName | StacksNetwork) => {
|
|
47
|
+
if (typeof network !== 'string' && 'version' in network) {
|
|
48
|
+
return network;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return StacksNetwork.fromName(network);
|
|
52
|
+
};
|
|
53
|
+
|
|
71
54
|
isMainnet = () => this.version === TransactionVersion.Mainnet;
|
|
72
55
|
getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
|
|
73
56
|
getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
|
|
57
|
+
getTransactionFeeEstimateApiUrl = () =>
|
|
58
|
+
`${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`;
|
|
74
59
|
getAccountApiUrl = (address: string) =>
|
|
75
60
|
`${this.coreApiUrl}${this.accountEndpoint}/${address}?proof=0`;
|
|
76
61
|
getAbiApiUrl = (address: string, contract: string) =>
|
|
@@ -133,29 +118,29 @@ export class StacksMainnet implements StacksNetwork {
|
|
|
133
118
|
}
|
|
134
119
|
}
|
|
135
120
|
|
|
136
|
-
export class
|
|
137
|
-
version = TransactionVersion.
|
|
138
|
-
chainId = ChainID.
|
|
121
|
+
export class StacksMainnet extends StacksNetwork {
|
|
122
|
+
version = TransactionVersion.Mainnet;
|
|
123
|
+
chainId = ChainID.Mainnet;
|
|
139
124
|
|
|
140
|
-
constructor(networkUrl: NetworkConfig = { url:
|
|
125
|
+
constructor(networkUrl: NetworkConfig = { url: HIRO_MAINNET_DEFAULT }) {
|
|
141
126
|
super(networkUrl);
|
|
142
127
|
}
|
|
143
128
|
}
|
|
144
129
|
|
|
145
|
-
export class
|
|
130
|
+
export class StacksTestnet extends StacksNetwork {
|
|
146
131
|
version = TransactionVersion.Testnet;
|
|
147
132
|
chainId = ChainID.Testnet;
|
|
148
133
|
|
|
149
|
-
constructor(networkUrl: NetworkConfig = { url:
|
|
134
|
+
constructor(networkUrl: NetworkConfig = { url: HIRO_TESTNET_DEFAULT }) {
|
|
150
135
|
super(networkUrl);
|
|
151
136
|
}
|
|
152
137
|
}
|
|
153
138
|
|
|
154
|
-
export class
|
|
139
|
+
export class StacksMocknet extends StacksNetwork {
|
|
155
140
|
version = TransactionVersion.Testnet;
|
|
156
141
|
chainId = ChainID.Testnet;
|
|
157
142
|
|
|
158
|
-
constructor(networkUrl: NetworkConfig = { url:
|
|
143
|
+
constructor(networkUrl: NetworkConfig = { url: HIRO_MOCKNET_DEFAULT }) {
|
|
159
144
|
super(networkUrl);
|
|
160
145
|
}
|
|
161
146
|
}
|