@stacks/network 6.14.1-pr.f066584c.0 → 6.14.1-pr.fa0674c3.23
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/constants.d.ts +15 -0
- package/dist/constants.js +25 -0
- package/dist/constants.js.map +1 -0
- package/dist/esm/constants.d.ts +15 -0
- package/dist/esm/constants.js +21 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/network.d.ts +13 -59
- package/dist/esm/network.js +39 -115
- package/dist/esm/network.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/network.d.ts +13 -59
- package/dist/network.js +42 -119
- package/dist/network.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/src/constants.ts +42 -0
- package/src/index.ts +1 -1
- package/src/network.ts +52 -200
- package/dist/esm/fetch.d.ts +0 -31
- package/dist/esm/fetch.js +0 -77
- package/dist/esm/fetch.js.map +0 -1
- package/dist/fetch.d.ts +0 -31
- package/dist/fetch.js +0 -86
- package/dist/fetch.js.map +0 -1
- package/src/fetch.ts +0 -178
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare enum ChainId {
|
|
2
|
+
Mainnet = 1,
|
|
3
|
+
Testnet = 2147483648
|
|
4
|
+
}
|
|
5
|
+
export declare enum PeerNetworkId {
|
|
6
|
+
Mainnet = 385875968,
|
|
7
|
+
Testnet = 4278190080
|
|
8
|
+
}
|
|
9
|
+
export declare const DEFAULT_CHAIN_ID = ChainId.Mainnet;
|
|
10
|
+
export declare enum TransactionVersion {
|
|
11
|
+
Mainnet = 0,
|
|
12
|
+
Testnet = 128
|
|
13
|
+
}
|
|
14
|
+
export declare const DEFAULT_TRANSACTION_VERSION = TransactionVersion.Mainnet;
|
|
15
|
+
export declare function whenTransactionVersion(transactionVersion: TransactionVersion): <T>(map: Record<TransactionVersion, T>) => T;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.whenTransactionVersion = exports.DEFAULT_TRANSACTION_VERSION = exports.TransactionVersion = exports.DEFAULT_CHAIN_ID = exports.PeerNetworkId = exports.ChainId = void 0;
|
|
4
|
+
var ChainId;
|
|
5
|
+
(function (ChainId) {
|
|
6
|
+
ChainId[ChainId["Mainnet"] = 1] = "Mainnet";
|
|
7
|
+
ChainId[ChainId["Testnet"] = 2147483648] = "Testnet";
|
|
8
|
+
})(ChainId || (exports.ChainId = ChainId = {}));
|
|
9
|
+
var PeerNetworkId;
|
|
10
|
+
(function (PeerNetworkId) {
|
|
11
|
+
PeerNetworkId[PeerNetworkId["Mainnet"] = 385875968] = "Mainnet";
|
|
12
|
+
PeerNetworkId[PeerNetworkId["Testnet"] = 4278190080] = "Testnet";
|
|
13
|
+
})(PeerNetworkId || (exports.PeerNetworkId = PeerNetworkId = {}));
|
|
14
|
+
exports.DEFAULT_CHAIN_ID = ChainId.Mainnet;
|
|
15
|
+
var TransactionVersion;
|
|
16
|
+
(function (TransactionVersion) {
|
|
17
|
+
TransactionVersion[TransactionVersion["Mainnet"] = 0] = "Mainnet";
|
|
18
|
+
TransactionVersion[TransactionVersion["Testnet"] = 128] = "Testnet";
|
|
19
|
+
})(TransactionVersion || (exports.TransactionVersion = TransactionVersion = {}));
|
|
20
|
+
exports.DEFAULT_TRANSACTION_VERSION = TransactionVersion.Mainnet;
|
|
21
|
+
function whenTransactionVersion(transactionVersion) {
|
|
22
|
+
return (map) => map[transactionVersion];
|
|
23
|
+
}
|
|
24
|
+
exports.whenTransactionVersion = whenTransactionVersion;
|
|
25
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAIA,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,2CAAoB,CAAA;IACpB,oDAAoB,CAAA;AACtB,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAYD,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,+DAAoB,CAAA;IACpB,gEAAoB,CAAA;AACtB,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAEY,QAAA,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;AAOhD,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,iEAAc,CAAA;IACd,mEAAc,CAAA;AAChB,CAAC,EAHW,kBAAkB,kCAAlB,kBAAkB,QAG7B;AAEY,QAAA,2BAA2B,GAAG,kBAAkB,CAAC,OAAO,CAAC;AAGtE,SAAgB,sBAAsB,CAAC,kBAAsC;IAC3E,OAAO,CAAI,GAAkC,EAAK,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAC/E,CAAC;AAFD,wDAEC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare enum ChainId {
|
|
2
|
+
Mainnet = 1,
|
|
3
|
+
Testnet = 2147483648
|
|
4
|
+
}
|
|
5
|
+
export declare enum PeerNetworkId {
|
|
6
|
+
Mainnet = 385875968,
|
|
7
|
+
Testnet = 4278190080
|
|
8
|
+
}
|
|
9
|
+
export declare const DEFAULT_CHAIN_ID = ChainId.Mainnet;
|
|
10
|
+
export declare enum TransactionVersion {
|
|
11
|
+
Mainnet = 0,
|
|
12
|
+
Testnet = 128
|
|
13
|
+
}
|
|
14
|
+
export declare const DEFAULT_TRANSACTION_VERSION = TransactionVersion.Mainnet;
|
|
15
|
+
export declare function whenTransactionVersion(transactionVersion: TransactionVersion): <T>(map: Record<TransactionVersion, T>) => T;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export var ChainId;
|
|
2
|
+
(function (ChainId) {
|
|
3
|
+
ChainId[ChainId["Mainnet"] = 1] = "Mainnet";
|
|
4
|
+
ChainId[ChainId["Testnet"] = 2147483648] = "Testnet";
|
|
5
|
+
})(ChainId || (ChainId = {}));
|
|
6
|
+
export var PeerNetworkId;
|
|
7
|
+
(function (PeerNetworkId) {
|
|
8
|
+
PeerNetworkId[PeerNetworkId["Mainnet"] = 385875968] = "Mainnet";
|
|
9
|
+
PeerNetworkId[PeerNetworkId["Testnet"] = 4278190080] = "Testnet";
|
|
10
|
+
})(PeerNetworkId || (PeerNetworkId = {}));
|
|
11
|
+
export const DEFAULT_CHAIN_ID = ChainId.Mainnet;
|
|
12
|
+
export var TransactionVersion;
|
|
13
|
+
(function (TransactionVersion) {
|
|
14
|
+
TransactionVersion[TransactionVersion["Mainnet"] = 0] = "Mainnet";
|
|
15
|
+
TransactionVersion[TransactionVersion["Testnet"] = 128] = "Testnet";
|
|
16
|
+
})(TransactionVersion || (TransactionVersion = {}));
|
|
17
|
+
export const DEFAULT_TRANSACTION_VERSION = TransactionVersion.Mainnet;
|
|
18
|
+
export function whenTransactionVersion(transactionVersion) {
|
|
19
|
+
return (map) => map[transactionVersion];
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAIA,MAAM,CAAN,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,2CAAoB,CAAA;IACpB,oDAAoB,CAAA;AACtB,CAAC,EAHW,OAAO,KAAP,OAAO,QAGlB;AAYD,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,+DAAoB,CAAA;IACpB,gEAAoB,CAAA;AACtB,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;AAOhD,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,iEAAc,CAAA;IACd,mEAAc,CAAA;AAChB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AAED,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAAkB,CAAC,OAAO,CAAC;AAGtE,MAAM,UAAU,sBAAsB,CAAC,kBAAsC;IAC3E,OAAO,CAAI,GAAkC,EAAK,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAC/E,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './constants';
|
|
2
2
|
export * from './network';
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
|
package/dist/esm/network.d.ts
CHANGED
|
@@ -1,61 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
export interface StacksNetwork {
|
|
2
|
+
chainId: number;
|
|
3
|
+
transactionVersion: number;
|
|
4
|
+
peerNetworkId: number;
|
|
5
|
+
magicBytes: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const STACKS_MAINNET: StacksNetwork;
|
|
8
|
+
export declare const STACKS_TESTNET: StacksNetwork;
|
|
9
|
+
export declare const STACKS_DEVNET: StacksNetwork;
|
|
10
|
+
export declare const STACKS_MOCKNET: StacksNetwork;
|
|
10
11
|
export declare const StacksNetworks: readonly ["mainnet", "testnet", "devnet", "mocknet"];
|
|
11
12
|
export type StacksNetworkName = (typeof StacksNetworks)[number];
|
|
12
|
-
export declare
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
bnsLookupUrl: string;
|
|
16
|
-
broadcastEndpoint: string;
|
|
17
|
-
transferFeeEstimateEndpoint: string;
|
|
18
|
-
transactionFeeEstimateEndpoint: string;
|
|
19
|
-
accountEndpoint: string;
|
|
20
|
-
contractAbiEndpoint: string;
|
|
21
|
-
readOnlyFunctionCallEndpoint: string;
|
|
22
|
-
readonly coreApiUrl: string;
|
|
23
|
-
fetchFn: FetchFn;
|
|
24
|
-
constructor(networkConfig: NetworkConfig);
|
|
25
|
-
static fromName: (networkName: StacksNetworkName) => StacksNetwork;
|
|
26
|
-
static fromNameOrNetwork: (network: StacksNetworkName | StacksNetwork) => StacksNetwork;
|
|
27
|
-
isMainnet: () => boolean;
|
|
28
|
-
getBroadcastApiUrl: () => string;
|
|
29
|
-
getTransferFeeEstimateApiUrl: () => string;
|
|
30
|
-
getTransactionFeeEstimateApiUrl: () => string;
|
|
31
|
-
getAccountApiUrl: (address: string) => string;
|
|
32
|
-
getAccountExtendedBalancesApiUrl: (address: string) => string;
|
|
33
|
-
getAbiApiUrl: (address: string, contract: string) => string;
|
|
34
|
-
getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
|
|
35
|
-
getInfoUrl: () => string;
|
|
36
|
-
getBlockTimeInfoUrl: () => string;
|
|
37
|
-
getPoxInfoUrl: () => string;
|
|
38
|
-
getRewardsUrl: (address: string, options?: any) => string;
|
|
39
|
-
getRewardsTotalUrl: (address: string) => string;
|
|
40
|
-
getRewardHoldersUrl: (address: string, options?: any) => string;
|
|
41
|
-
getStackerInfoUrl: (contractAddress: string, contractName: string) => string;
|
|
42
|
-
getDataVarUrl: (contractAddress: string, contractName: string, dataVarName: string) => string;
|
|
43
|
-
getMapEntryUrl: (contractAddress: string, contractName: string, mapName: string) => string;
|
|
44
|
-
getNameInfo(fullyQualifiedName: string): Promise<any>;
|
|
45
|
-
}
|
|
46
|
-
export declare class StacksMainnet extends StacksNetwork {
|
|
47
|
-
version: TransactionVersion;
|
|
48
|
-
chainId: ChainID;
|
|
49
|
-
constructor(opts?: Partial<NetworkConfig>);
|
|
50
|
-
}
|
|
51
|
-
export declare class StacksTestnet extends StacksNetwork {
|
|
52
|
-
version: TransactionVersion;
|
|
53
|
-
chainId: ChainID;
|
|
54
|
-
constructor(opts?: Partial<NetworkConfig>);
|
|
55
|
-
}
|
|
56
|
-
export declare class StacksMocknet extends StacksNetwork {
|
|
57
|
-
version: TransactionVersion;
|
|
58
|
-
chainId: ChainID;
|
|
59
|
-
constructor(opts?: Partial<NetworkConfig>);
|
|
60
|
-
}
|
|
61
|
-
export declare const StacksDevnet: typeof StacksMocknet;
|
|
13
|
+
export declare function networkFromName(name: StacksNetworkName): StacksNetwork;
|
|
14
|
+
export declare function networkFrom(network: StacksNetworkName | StacksNetwork): StacksNetwork;
|
|
15
|
+
export declare function deriveDefaultUrl(network: StacksNetwork | StacksNetworkName | undefined): "https://api.mainnet.hiro.so" | "http://localhost:3999" | "https://api.testnet.hiro.so";
|
package/dist/esm/network.js
CHANGED
|
@@ -1,126 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { DEVNET_URL, HIRO_MAINNET_URL, HIRO_TESTNET_URL } from '@stacks/common';
|
|
2
|
+
import { ChainId, PeerNetworkId, TransactionVersion } from './constants';
|
|
3
|
+
export const STACKS_MAINNET = {
|
|
4
|
+
chainId: ChainId.Mainnet,
|
|
5
|
+
transactionVersion: TransactionVersion.Mainnet,
|
|
6
|
+
peerNetworkId: PeerNetworkId.Mainnet,
|
|
7
|
+
magicBytes: 'X2',
|
|
8
|
+
};
|
|
9
|
+
export const STACKS_TESTNET = {
|
|
10
|
+
chainId: ChainId.Testnet,
|
|
11
|
+
transactionVersion: TransactionVersion.Testnet,
|
|
12
|
+
peerNetworkId: PeerNetworkId.Testnet,
|
|
13
|
+
magicBytes: 'T2',
|
|
14
|
+
};
|
|
15
|
+
export const STACKS_DEVNET = {
|
|
16
|
+
...STACKS_TESTNET,
|
|
17
|
+
magicBytes: 'id',
|
|
18
|
+
};
|
|
19
|
+
export const STACKS_MOCKNET = { ...STACKS_DEVNET };
|
|
6
20
|
export const StacksNetworks = ['mainnet', 'testnet', 'devnet', 'mocknet'];
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
this.version = TransactionVersion.Mainnet;
|
|
10
|
-
this.chainId = ChainID.Mainnet;
|
|
11
|
-
this.bnsLookupUrl = 'https://api.mainnet.hiro.so';
|
|
12
|
-
this.broadcastEndpoint = '/v2/transactions';
|
|
13
|
-
this.transferFeeEstimateEndpoint = '/v2/fees/transfer';
|
|
14
|
-
this.transactionFeeEstimateEndpoint = '/v2/fees/transaction';
|
|
15
|
-
this.accountEndpoint = '/v2/accounts';
|
|
16
|
-
this.contractAbiEndpoint = '/v2/contracts/interface';
|
|
17
|
-
this.readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
|
|
18
|
-
this.isMainnet = () => this.version === TransactionVersion.Mainnet;
|
|
19
|
-
this.getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
|
|
20
|
-
this.getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
|
|
21
|
-
this.getTransactionFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`;
|
|
22
|
-
this.getAccountApiUrl = (address) => `${this.coreApiUrl}${this.accountEndpoint}/${address}?proof=0`;
|
|
23
|
-
this.getAccountExtendedBalancesApiUrl = (address) => `${this.coreApiUrl}/extended/v1/address/${address}/balances`;
|
|
24
|
-
this.getAbiApiUrl = (address, contract) => `${this.coreApiUrl}${this.contractAbiEndpoint}/${address}/${contract}`;
|
|
25
|
-
this.getReadOnlyFunctionCallApiUrl = (contractAddress, contractName, functionName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${contractAddress}/${contractName}/${encodeURIComponent(functionName)}`;
|
|
26
|
-
this.getInfoUrl = () => `${this.coreApiUrl}/v2/info`;
|
|
27
|
-
this.getBlockTimeInfoUrl = () => `${this.coreApiUrl}/extended/v1/info/network_block_times`;
|
|
28
|
-
this.getPoxInfoUrl = () => `${this.coreApiUrl}/v2/pox`;
|
|
29
|
-
this.getRewardsUrl = (address, options) => {
|
|
30
|
-
let url = `${this.coreApiUrl}/extended/v1/burnchain/rewards/${address}`;
|
|
31
|
-
if (options) {
|
|
32
|
-
url = `${url}?limit=${options.limit}&offset=${options.offset}`;
|
|
33
|
-
}
|
|
34
|
-
return url;
|
|
35
|
-
};
|
|
36
|
-
this.getRewardsTotalUrl = (address) => `${this.coreApiUrl}/extended/v1/burnchain/rewards/${address}/total`;
|
|
37
|
-
this.getRewardHoldersUrl = (address, options) => {
|
|
38
|
-
let url = `${this.coreApiUrl}/extended/v1/burnchain/reward_slot_holders/${address}`;
|
|
39
|
-
if (options) {
|
|
40
|
-
url = `${url}?limit=${options.limit}&offset=${options.offset}`;
|
|
41
|
-
}
|
|
42
|
-
return url;
|
|
43
|
-
};
|
|
44
|
-
this.getStackerInfoUrl = (contractAddress, contractName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}
|
|
45
|
-
${contractAddress}/${contractName}/get-stacker-info`;
|
|
46
|
-
this.getDataVarUrl = (contractAddress, contractName, dataVarName) => `${this.coreApiUrl}/v2/data_var/${contractAddress}/${contractName}/${dataVarName}?proof=0`;
|
|
47
|
-
this.getMapEntryUrl = (contractAddress, contractName, mapName) => `${this.coreApiUrl}/v2/map_entry/${contractAddress}/${contractName}/${mapName}?proof=0`;
|
|
48
|
-
this.coreApiUrl = networkConfig.url;
|
|
49
|
-
this.fetchFn = networkConfig.fetchFn ?? createFetchFn();
|
|
50
|
-
}
|
|
51
|
-
getNameInfo(fullyQualifiedName) {
|
|
52
|
-
const nameLookupURL = `${this.bnsLookupUrl}/v1/names/${fullyQualifiedName}`;
|
|
53
|
-
return this.fetchFn(nameLookupURL)
|
|
54
|
-
.then(resp => {
|
|
55
|
-
if (resp.status === 404) {
|
|
56
|
-
throw new Error('Name not found');
|
|
57
|
-
}
|
|
58
|
-
else if (resp.status !== 200) {
|
|
59
|
-
throw new Error(`Bad response status: ${resp.status}`);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
return resp.json();
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
.then(nameInfo => {
|
|
66
|
-
if (nameInfo.address) {
|
|
67
|
-
return Object.assign({}, nameInfo, { address: nameInfo.address });
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
return nameInfo;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
StacksNetwork.fromName = (networkName) => {
|
|
76
|
-
switch (networkName) {
|
|
21
|
+
export function networkFromName(name) {
|
|
22
|
+
switch (name) {
|
|
77
23
|
case 'mainnet':
|
|
78
|
-
return
|
|
24
|
+
return STACKS_MAINNET;
|
|
79
25
|
case 'testnet':
|
|
80
|
-
return
|
|
26
|
+
return STACKS_TESTNET;
|
|
81
27
|
case 'devnet':
|
|
82
|
-
return
|
|
28
|
+
return STACKS_DEVNET;
|
|
83
29
|
case 'mocknet':
|
|
84
|
-
return
|
|
30
|
+
return STACKS_MOCKNET;
|
|
85
31
|
default:
|
|
86
|
-
throw new Error(`
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
StacksNetwork.fromNameOrNetwork = (network) => {
|
|
90
|
-
if (typeof network !== 'string' && 'version' in network) {
|
|
91
|
-
return network;
|
|
92
|
-
}
|
|
93
|
-
return StacksNetwork.fromName(network);
|
|
94
|
-
};
|
|
95
|
-
export class StacksMainnet extends StacksNetwork {
|
|
96
|
-
constructor(opts) {
|
|
97
|
-
super({
|
|
98
|
-
url: opts?.url ?? HIRO_MAINNET_DEFAULT,
|
|
99
|
-
fetchFn: opts?.fetchFn,
|
|
100
|
-
});
|
|
101
|
-
this.version = TransactionVersion.Mainnet;
|
|
102
|
-
this.chainId = ChainID.Mainnet;
|
|
32
|
+
throw new Error(`Unknown network name: ${name}`);
|
|
103
33
|
}
|
|
104
34
|
}
|
|
105
|
-
export
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
fetchFn: opts?.fetchFn,
|
|
110
|
-
});
|
|
111
|
-
this.version = TransactionVersion.Testnet;
|
|
112
|
-
this.chainId = ChainID.Testnet;
|
|
113
|
-
}
|
|
35
|
+
export function networkFrom(network) {
|
|
36
|
+
if (typeof network === 'string')
|
|
37
|
+
return networkFromName(network);
|
|
38
|
+
return network;
|
|
114
39
|
}
|
|
115
|
-
export
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
40
|
+
export function deriveDefaultUrl(network) {
|
|
41
|
+
if (!network)
|
|
42
|
+
return HIRO_MAINNET_URL;
|
|
43
|
+
network = networkFrom(network);
|
|
44
|
+
return !network || network.transactionVersion === TransactionVersion.Mainnet
|
|
45
|
+
? HIRO_MAINNET_URL
|
|
46
|
+
: network.magicBytes === 'id'
|
|
47
|
+
? DEVNET_URL
|
|
48
|
+
: HIRO_TESTNET_URL;
|
|
124
49
|
}
|
|
125
|
-
export const StacksDevnet = StacksMocknet;
|
|
126
50
|
//# sourceMappingURL=network.js.map
|
package/dist/esm/network.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAUzE,MAAM,CAAC,MAAM,cAAc,GAAkB;IAC3C,OAAO,EAAE,OAAO,CAAC,OAAO;IACxB,kBAAkB,EAAE,kBAAkB,CAAC,OAAO;IAC9C,aAAa,EAAE,aAAa,CAAC,OAAO;IACpC,UAAU,EAAE,IAAI;CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAkB;IAC3C,OAAO,EAAE,OAAO,CAAC,OAAO;IACxB,kBAAkB,EAAE,kBAAkB,CAAC,OAAO;IAC9C,aAAa,EAAE,aAAa,CAAC,OAAO;IACpC,UAAU,EAAE,IAAI;CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,GAAG,cAAc;IACjB,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAkB,EAAE,GAAG,aAAa,EAAE,CAAC;AAGlE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAU,CAAC;AAInF,MAAM,UAAU,eAAe,CAAC,IAAuB;IACrD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,SAAS;YACZ,OAAO,cAAc,CAAC;QACxB,KAAK,SAAS;YACZ,OAAO,cAAc,CAAC;QACxB,KAAK,QAAQ;YACX,OAAO,aAAa,CAAC;QACvB,KAAK,SAAS;YACZ,OAAO,cAAc,CAAC;QACxB;YACE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAA0C;IACpE,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC;IACjE,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAsD;IACrF,IAAI,CAAC,OAAO;QAAE,OAAO,gBAAgB,CAAC;IAEtC,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAE/B,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,kBAAkB,KAAK,kBAAkB,CAAC,OAAO;QAC1E,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,OAAO,CAAC,UAAU,KAAK,IAAI;YAC3B,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,gBAAgB,CAAC;AACzB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './constants';
|
|
2
2
|
export * from './network';
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
18
18
|
__exportStar(require("./network"), exports);
|
|
19
19
|
//# 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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,4CAA0B"}
|
package/dist/network.d.ts
CHANGED
|
@@ -1,61 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
export interface StacksNetwork {
|
|
2
|
+
chainId: number;
|
|
3
|
+
transactionVersion: number;
|
|
4
|
+
peerNetworkId: number;
|
|
5
|
+
magicBytes: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const STACKS_MAINNET: StacksNetwork;
|
|
8
|
+
export declare const STACKS_TESTNET: StacksNetwork;
|
|
9
|
+
export declare const STACKS_DEVNET: StacksNetwork;
|
|
10
|
+
export declare const STACKS_MOCKNET: StacksNetwork;
|
|
10
11
|
export declare const StacksNetworks: readonly ["mainnet", "testnet", "devnet", "mocknet"];
|
|
11
12
|
export type StacksNetworkName = (typeof StacksNetworks)[number];
|
|
12
|
-
export declare
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
bnsLookupUrl: string;
|
|
16
|
-
broadcastEndpoint: string;
|
|
17
|
-
transferFeeEstimateEndpoint: string;
|
|
18
|
-
transactionFeeEstimateEndpoint: string;
|
|
19
|
-
accountEndpoint: string;
|
|
20
|
-
contractAbiEndpoint: string;
|
|
21
|
-
readOnlyFunctionCallEndpoint: string;
|
|
22
|
-
readonly coreApiUrl: string;
|
|
23
|
-
fetchFn: FetchFn;
|
|
24
|
-
constructor(networkConfig: NetworkConfig);
|
|
25
|
-
static fromName: (networkName: StacksNetworkName) => StacksNetwork;
|
|
26
|
-
static fromNameOrNetwork: (network: StacksNetworkName | StacksNetwork) => StacksNetwork;
|
|
27
|
-
isMainnet: () => boolean;
|
|
28
|
-
getBroadcastApiUrl: () => string;
|
|
29
|
-
getTransferFeeEstimateApiUrl: () => string;
|
|
30
|
-
getTransactionFeeEstimateApiUrl: () => string;
|
|
31
|
-
getAccountApiUrl: (address: string) => string;
|
|
32
|
-
getAccountExtendedBalancesApiUrl: (address: string) => string;
|
|
33
|
-
getAbiApiUrl: (address: string, contract: string) => string;
|
|
34
|
-
getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
|
|
35
|
-
getInfoUrl: () => string;
|
|
36
|
-
getBlockTimeInfoUrl: () => string;
|
|
37
|
-
getPoxInfoUrl: () => string;
|
|
38
|
-
getRewardsUrl: (address: string, options?: any) => string;
|
|
39
|
-
getRewardsTotalUrl: (address: string) => string;
|
|
40
|
-
getRewardHoldersUrl: (address: string, options?: any) => string;
|
|
41
|
-
getStackerInfoUrl: (contractAddress: string, contractName: string) => string;
|
|
42
|
-
getDataVarUrl: (contractAddress: string, contractName: string, dataVarName: string) => string;
|
|
43
|
-
getMapEntryUrl: (contractAddress: string, contractName: string, mapName: string) => string;
|
|
44
|
-
getNameInfo(fullyQualifiedName: string): Promise<any>;
|
|
45
|
-
}
|
|
46
|
-
export declare class StacksMainnet extends StacksNetwork {
|
|
47
|
-
version: TransactionVersion;
|
|
48
|
-
chainId: ChainID;
|
|
49
|
-
constructor(opts?: Partial<NetworkConfig>);
|
|
50
|
-
}
|
|
51
|
-
export declare class StacksTestnet extends StacksNetwork {
|
|
52
|
-
version: TransactionVersion;
|
|
53
|
-
chainId: ChainID;
|
|
54
|
-
constructor(opts?: Partial<NetworkConfig>);
|
|
55
|
-
}
|
|
56
|
-
export declare class StacksMocknet extends StacksNetwork {
|
|
57
|
-
version: TransactionVersion;
|
|
58
|
-
chainId: ChainID;
|
|
59
|
-
constructor(opts?: Partial<NetworkConfig>);
|
|
60
|
-
}
|
|
61
|
-
export declare const StacksDevnet: typeof StacksMocknet;
|
|
13
|
+
export declare function networkFromName(name: StacksNetworkName): StacksNetwork;
|
|
14
|
+
export declare function networkFrom(network: StacksNetworkName | StacksNetwork): StacksNetwork;
|
|
15
|
+
export declare function deriveDefaultUrl(network: StacksNetwork | StacksNetworkName | undefined): "https://api.mainnet.hiro.so" | "http://localhost:3999" | "https://api.testnet.hiro.so";
|
package/dist/network.js
CHANGED
|
@@ -1,133 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.deriveDefaultUrl = exports.networkFrom = exports.networkFromName = exports.StacksNetworks = exports.STACKS_MOCKNET = exports.STACKS_DEVNET = exports.STACKS_TESTNET = exports.STACKS_MAINNET = void 0;
|
|
4
4
|
const common_1 = require("@stacks/common");
|
|
5
|
-
const
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
exports.STACKS_MAINNET = {
|
|
7
|
+
chainId: constants_1.ChainId.Mainnet,
|
|
8
|
+
transactionVersion: constants_1.TransactionVersion.Mainnet,
|
|
9
|
+
peerNetworkId: constants_1.PeerNetworkId.Mainnet,
|
|
10
|
+
magicBytes: 'X2',
|
|
11
|
+
};
|
|
12
|
+
exports.STACKS_TESTNET = {
|
|
13
|
+
chainId: constants_1.ChainId.Testnet,
|
|
14
|
+
transactionVersion: constants_1.TransactionVersion.Testnet,
|
|
15
|
+
peerNetworkId: constants_1.PeerNetworkId.Testnet,
|
|
16
|
+
magicBytes: 'T2',
|
|
17
|
+
};
|
|
18
|
+
exports.STACKS_DEVNET = {
|
|
19
|
+
...exports.STACKS_TESTNET,
|
|
20
|
+
magicBytes: 'id',
|
|
21
|
+
};
|
|
22
|
+
exports.STACKS_MOCKNET = { ...exports.STACKS_DEVNET };
|
|
9
23
|
exports.StacksNetworks = ['mainnet', 'testnet', 'devnet', 'mocknet'];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.version = common_1.TransactionVersion.Mainnet;
|
|
13
|
-
this.chainId = common_1.ChainID.Mainnet;
|
|
14
|
-
this.bnsLookupUrl = 'https://api.mainnet.hiro.so';
|
|
15
|
-
this.broadcastEndpoint = '/v2/transactions';
|
|
16
|
-
this.transferFeeEstimateEndpoint = '/v2/fees/transfer';
|
|
17
|
-
this.transactionFeeEstimateEndpoint = '/v2/fees/transaction';
|
|
18
|
-
this.accountEndpoint = '/v2/accounts';
|
|
19
|
-
this.contractAbiEndpoint = '/v2/contracts/interface';
|
|
20
|
-
this.readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
|
|
21
|
-
this.isMainnet = () => this.version === common_1.TransactionVersion.Mainnet;
|
|
22
|
-
this.getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
|
|
23
|
-
this.getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
|
|
24
|
-
this.getTransactionFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`;
|
|
25
|
-
this.getAccountApiUrl = (address) => `${this.coreApiUrl}${this.accountEndpoint}/${address}?proof=0`;
|
|
26
|
-
this.getAccountExtendedBalancesApiUrl = (address) => `${this.coreApiUrl}/extended/v1/address/${address}/balances`;
|
|
27
|
-
this.getAbiApiUrl = (address, contract) => `${this.coreApiUrl}${this.contractAbiEndpoint}/${address}/${contract}`;
|
|
28
|
-
this.getReadOnlyFunctionCallApiUrl = (contractAddress, contractName, functionName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${contractAddress}/${contractName}/${encodeURIComponent(functionName)}`;
|
|
29
|
-
this.getInfoUrl = () => `${this.coreApiUrl}/v2/info`;
|
|
30
|
-
this.getBlockTimeInfoUrl = () => `${this.coreApiUrl}/extended/v1/info/network_block_times`;
|
|
31
|
-
this.getPoxInfoUrl = () => `${this.coreApiUrl}/v2/pox`;
|
|
32
|
-
this.getRewardsUrl = (address, options) => {
|
|
33
|
-
let url = `${this.coreApiUrl}/extended/v1/burnchain/rewards/${address}`;
|
|
34
|
-
if (options) {
|
|
35
|
-
url = `${url}?limit=${options.limit}&offset=${options.offset}`;
|
|
36
|
-
}
|
|
37
|
-
return url;
|
|
38
|
-
};
|
|
39
|
-
this.getRewardsTotalUrl = (address) => `${this.coreApiUrl}/extended/v1/burnchain/rewards/${address}/total`;
|
|
40
|
-
this.getRewardHoldersUrl = (address, options) => {
|
|
41
|
-
let url = `${this.coreApiUrl}/extended/v1/burnchain/reward_slot_holders/${address}`;
|
|
42
|
-
if (options) {
|
|
43
|
-
url = `${url}?limit=${options.limit}&offset=${options.offset}`;
|
|
44
|
-
}
|
|
45
|
-
return url;
|
|
46
|
-
};
|
|
47
|
-
this.getStackerInfoUrl = (contractAddress, contractName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}
|
|
48
|
-
${contractAddress}/${contractName}/get-stacker-info`;
|
|
49
|
-
this.getDataVarUrl = (contractAddress, contractName, dataVarName) => `${this.coreApiUrl}/v2/data_var/${contractAddress}/${contractName}/${dataVarName}?proof=0`;
|
|
50
|
-
this.getMapEntryUrl = (contractAddress, contractName, mapName) => `${this.coreApiUrl}/v2/map_entry/${contractAddress}/${contractName}/${mapName}?proof=0`;
|
|
51
|
-
this.coreApiUrl = networkConfig.url;
|
|
52
|
-
this.fetchFn = networkConfig.fetchFn ?? (0, fetch_1.createFetchFn)();
|
|
53
|
-
}
|
|
54
|
-
getNameInfo(fullyQualifiedName) {
|
|
55
|
-
const nameLookupURL = `${this.bnsLookupUrl}/v1/names/${fullyQualifiedName}`;
|
|
56
|
-
return this.fetchFn(nameLookupURL)
|
|
57
|
-
.then(resp => {
|
|
58
|
-
if (resp.status === 404) {
|
|
59
|
-
throw new Error('Name not found');
|
|
60
|
-
}
|
|
61
|
-
else if (resp.status !== 200) {
|
|
62
|
-
throw new Error(`Bad response status: ${resp.status}`);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
return resp.json();
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
.then(nameInfo => {
|
|
69
|
-
if (nameInfo.address) {
|
|
70
|
-
return Object.assign({}, nameInfo, { address: nameInfo.address });
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
return nameInfo;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.StacksNetwork = StacksNetwork;
|
|
79
|
-
StacksNetwork.fromName = (networkName) => {
|
|
80
|
-
switch (networkName) {
|
|
24
|
+
function networkFromName(name) {
|
|
25
|
+
switch (name) {
|
|
81
26
|
case 'mainnet':
|
|
82
|
-
return
|
|
27
|
+
return exports.STACKS_MAINNET;
|
|
83
28
|
case 'testnet':
|
|
84
|
-
return
|
|
29
|
+
return exports.STACKS_TESTNET;
|
|
85
30
|
case 'devnet':
|
|
86
|
-
return
|
|
31
|
+
return exports.STACKS_DEVNET;
|
|
87
32
|
case 'mocknet':
|
|
88
|
-
return
|
|
33
|
+
return exports.STACKS_MOCKNET;
|
|
89
34
|
default:
|
|
90
|
-
throw new Error(`
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
StacksNetwork.fromNameOrNetwork = (network) => {
|
|
94
|
-
if (typeof network !== 'string' && 'version' in network) {
|
|
95
|
-
return network;
|
|
96
|
-
}
|
|
97
|
-
return StacksNetwork.fromName(network);
|
|
98
|
-
};
|
|
99
|
-
class StacksMainnet extends StacksNetwork {
|
|
100
|
-
constructor(opts) {
|
|
101
|
-
super({
|
|
102
|
-
url: opts?.url ?? exports.HIRO_MAINNET_DEFAULT,
|
|
103
|
-
fetchFn: opts?.fetchFn,
|
|
104
|
-
});
|
|
105
|
-
this.version = common_1.TransactionVersion.Mainnet;
|
|
106
|
-
this.chainId = common_1.ChainID.Mainnet;
|
|
35
|
+
throw new Error(`Unknown network name: ${name}`);
|
|
107
36
|
}
|
|
108
37
|
}
|
|
109
|
-
exports.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
fetchFn: opts?.fetchFn,
|
|
115
|
-
});
|
|
116
|
-
this.version = common_1.TransactionVersion.Testnet;
|
|
117
|
-
this.chainId = common_1.ChainID.Testnet;
|
|
118
|
-
}
|
|
38
|
+
exports.networkFromName = networkFromName;
|
|
39
|
+
function networkFrom(network) {
|
|
40
|
+
if (typeof network === 'string')
|
|
41
|
+
return networkFromName(network);
|
|
42
|
+
return network;
|
|
119
43
|
}
|
|
120
|
-
exports.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
44
|
+
exports.networkFrom = networkFrom;
|
|
45
|
+
function deriveDefaultUrl(network) {
|
|
46
|
+
if (!network)
|
|
47
|
+
return common_1.HIRO_MAINNET_URL;
|
|
48
|
+
network = networkFrom(network);
|
|
49
|
+
return !network || network.transactionVersion === constants_1.TransactionVersion.Mainnet
|
|
50
|
+
? common_1.HIRO_MAINNET_URL
|
|
51
|
+
: network.magicBytes === 'id'
|
|
52
|
+
? common_1.DEVNET_URL
|
|
53
|
+
: common_1.HIRO_TESTNET_URL;
|
|
130
54
|
}
|
|
131
|
-
exports.
|
|
132
|
-
exports.StacksDevnet = StacksMocknet;
|
|
55
|
+
exports.deriveDefaultUrl = deriveDefaultUrl;
|
|
133
56
|
//# sourceMappingURL=network.js.map
|