@stacks/network 6.17.0 → 7.0.0-beta.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/dist/constants.d.ts +21 -0
- package/dist/constants.js +32 -0
- package/dist/constants.js.map +1 -0
- package/dist/esm/constants.d.ts +21 -0
- package/dist/esm/constants.js +28 -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 +28 -58
- package/dist/esm/network.js +65 -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 +28 -58
- package/dist/network.js +69 -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 +59 -0
- package/src/index.ts +1 -1
- package/src/network.ts +111 -194
- package/dist/esm/fetch.d.ts +0 -31
- package/dist/esm/fetch.js +0 -78
- package/dist/esm/fetch.js.map +0 -1
- package/dist/fetch.d.ts +0 -31
- package/dist/fetch.js +0 -87
- package/dist/fetch.js.map +0 -1
- package/src/fetch.ts +0 -180
|
@@ -0,0 +1,21 @@
|
|
|
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 enum AddressVersion {
|
|
15
|
+
MainnetSingleSig = 22,
|
|
16
|
+
MainnetMultiSig = 20,
|
|
17
|
+
TestnetSingleSig = 26,
|
|
18
|
+
TestnetMultiSig = 21
|
|
19
|
+
}
|
|
20
|
+
export declare const DEFAULT_TRANSACTION_VERSION = TransactionVersion.Mainnet;
|
|
21
|
+
export declare function whenTransactionVersion(transactionVersion: TransactionVersion): <T>(map: Record<TransactionVersion, T>) => T;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.whenTransactionVersion = exports.DEFAULT_TRANSACTION_VERSION = exports.AddressVersion = 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
|
+
var AddressVersion;
|
|
21
|
+
(function (AddressVersion) {
|
|
22
|
+
AddressVersion[AddressVersion["MainnetSingleSig"] = 22] = "MainnetSingleSig";
|
|
23
|
+
AddressVersion[AddressVersion["MainnetMultiSig"] = 20] = "MainnetMultiSig";
|
|
24
|
+
AddressVersion[AddressVersion["TestnetSingleSig"] = 26] = "TestnetSingleSig";
|
|
25
|
+
AddressVersion[AddressVersion["TestnetMultiSig"] = 21] = "TestnetMultiSig";
|
|
26
|
+
})(AddressVersion || (exports.AddressVersion = AddressVersion = {}));
|
|
27
|
+
exports.DEFAULT_TRANSACTION_VERSION = TransactionVersion.Mainnet;
|
|
28
|
+
function whenTransactionVersion(transactionVersion) {
|
|
29
|
+
return (map) => map[transactionVersion];
|
|
30
|
+
}
|
|
31
|
+
exports.whenTransactionVersion = whenTransactionVersion;
|
|
32
|
+
//# 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;AAQD,IAAY,cASX;AATD,WAAY,cAAc;IAExB,4EAAqB,CAAA;IAErB,0EAAoB,CAAA;IAEpB,4EAAqB,CAAA;IAErB,0EAAoB,CAAA;AACtB,CAAC,EATW,cAAc,8BAAd,cAAc,QASzB;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,21 @@
|
|
|
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 enum AddressVersion {
|
|
15
|
+
MainnetSingleSig = 22,
|
|
16
|
+
MainnetMultiSig = 20,
|
|
17
|
+
TestnetSingleSig = 26,
|
|
18
|
+
TestnetMultiSig = 21
|
|
19
|
+
}
|
|
20
|
+
export declare const DEFAULT_TRANSACTION_VERSION = TransactionVersion.Mainnet;
|
|
21
|
+
export declare function whenTransactionVersion(transactionVersion: TransactionVersion): <T>(map: Record<TransactionVersion, T>) => T;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 var AddressVersion;
|
|
18
|
+
(function (AddressVersion) {
|
|
19
|
+
AddressVersion[AddressVersion["MainnetSingleSig"] = 22] = "MainnetSingleSig";
|
|
20
|
+
AddressVersion[AddressVersion["MainnetMultiSig"] = 20] = "MainnetMultiSig";
|
|
21
|
+
AddressVersion[AddressVersion["TestnetSingleSig"] = 26] = "TestnetSingleSig";
|
|
22
|
+
AddressVersion[AddressVersion["TestnetMultiSig"] = 21] = "TestnetMultiSig";
|
|
23
|
+
})(AddressVersion || (AddressVersion = {}));
|
|
24
|
+
export const DEFAULT_TRANSACTION_VERSION = TransactionVersion.Mainnet;
|
|
25
|
+
export function whenTransactionVersion(transactionVersion) {
|
|
26
|
+
return (map) => map[transactionVersion];
|
|
27
|
+
}
|
|
28
|
+
//# 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;AAQD,MAAM,CAAN,IAAY,cASX;AATD,WAAY,cAAc;IAExB,4EAAqB,CAAA;IAErB,0EAAoB,CAAA;IAEpB,4EAAqB,CAAA;IAErB,0EAAoB,CAAA;AACtB,CAAC,EATW,cAAc,KAAd,cAAc,QASzB;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,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ClientOpts, FetchFn } from '@stacks/common';
|
|
2
|
+
import { ClientParam } from '@stacks/common';
|
|
3
|
+
export type StacksNetwork = {
|
|
4
|
+
chainId: number;
|
|
5
|
+
transactionVersion: number;
|
|
6
|
+
peerNetworkId: number;
|
|
7
|
+
magicBytes: string;
|
|
8
|
+
bootAddress: string;
|
|
9
|
+
addressVersion: {
|
|
10
|
+
singleSig: number;
|
|
11
|
+
multiSig: number;
|
|
12
|
+
};
|
|
13
|
+
client: {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
fetch?: FetchFn;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export interface NetworkParam {
|
|
19
|
+
network?: StacksNetworkName | StacksNetwork;
|
|
9
20
|
}
|
|
21
|
+
export type NetworkClientParam = NetworkParam & ClientParam;
|
|
22
|
+
export declare const STACKS_MAINNET: StacksNetwork;
|
|
23
|
+
export declare const STACKS_TESTNET: StacksNetwork;
|
|
24
|
+
export declare const STACKS_DEVNET: StacksNetwork;
|
|
25
|
+
export declare const STACKS_MOCKNET: StacksNetwork;
|
|
10
26
|
export declare const StacksNetworks: readonly ["mainnet", "testnet", "devnet", "mocknet"];
|
|
11
27
|
export type StacksNetworkName = (typeof StacksNetworks)[number];
|
|
12
|
-
export declare
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
28
|
+
export declare function networkFromName(name: StacksNetworkName): StacksNetwork;
|
|
29
|
+
export declare function networkFrom(network: StacksNetworkName | StacksNetwork): StacksNetwork;
|
|
30
|
+
export declare function defaultUrlFromNetwork(network?: StacksNetworkName | StacksNetwork): "https://api.mainnet.hiro.so" | "https://api.testnet.hiro.so" | "http://localhost:3999";
|
|
31
|
+
export declare function clientFromNetwork(network: StacksNetwork): Required<ClientOpts>;
|
package/dist/esm/network.js
CHANGED
|
@@ -1,126 +1,76 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { DEVNET_URL, HIRO_MAINNET_URL, HIRO_TESTNET_URL, createFetchFn, } from '@stacks/common';
|
|
2
|
+
import { AddressVersion, 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
|
+
bootAddress: 'SP000000000000000000002Q6VF78',
|
|
9
|
+
addressVersion: {
|
|
10
|
+
singleSig: AddressVersion.MainnetSingleSig,
|
|
11
|
+
multiSig: AddressVersion.MainnetMultiSig,
|
|
12
|
+
},
|
|
13
|
+
client: { baseUrl: HIRO_MAINNET_URL },
|
|
14
|
+
};
|
|
15
|
+
export const STACKS_TESTNET = {
|
|
16
|
+
chainId: ChainId.Testnet,
|
|
17
|
+
transactionVersion: TransactionVersion.Testnet,
|
|
18
|
+
peerNetworkId: PeerNetworkId.Testnet,
|
|
19
|
+
magicBytes: 'T2',
|
|
20
|
+
bootAddress: 'ST000000000000000000002AMW42H',
|
|
21
|
+
addressVersion: {
|
|
22
|
+
singleSig: AddressVersion.TestnetSingleSig,
|
|
23
|
+
multiSig: AddressVersion.TestnetMultiSig,
|
|
24
|
+
},
|
|
25
|
+
client: { baseUrl: HIRO_TESTNET_URL },
|
|
26
|
+
};
|
|
27
|
+
export const STACKS_DEVNET = {
|
|
28
|
+
...STACKS_TESTNET,
|
|
29
|
+
addressVersion: { ...STACKS_TESTNET.addressVersion },
|
|
30
|
+
magicBytes: 'id',
|
|
31
|
+
client: { baseUrl: DEVNET_URL },
|
|
32
|
+
};
|
|
33
|
+
export const STACKS_MOCKNET = {
|
|
34
|
+
...STACKS_DEVNET,
|
|
35
|
+
addressVersion: { ...STACKS_DEVNET.addressVersion },
|
|
36
|
+
client: { ...STACKS_DEVNET.client },
|
|
37
|
+
};
|
|
6
38
|
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) {
|
|
39
|
+
export function networkFromName(name) {
|
|
40
|
+
switch (name) {
|
|
77
41
|
case 'mainnet':
|
|
78
|
-
return
|
|
42
|
+
return STACKS_MAINNET;
|
|
79
43
|
case 'testnet':
|
|
80
|
-
return
|
|
44
|
+
return STACKS_TESTNET;
|
|
81
45
|
case 'devnet':
|
|
82
|
-
return
|
|
46
|
+
return STACKS_DEVNET;
|
|
83
47
|
case 'mocknet':
|
|
84
|
-
return
|
|
48
|
+
return STACKS_MOCKNET;
|
|
85
49
|
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;
|
|
50
|
+
throw new Error(`Unknown network name: ${name}`);
|
|
103
51
|
}
|
|
104
52
|
}
|
|
105
|
-
export
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
fetchFn: opts?.fetchFn,
|
|
110
|
-
});
|
|
111
|
-
this.version = TransactionVersion.Testnet;
|
|
112
|
-
this.chainId = ChainID.Testnet;
|
|
113
|
-
}
|
|
53
|
+
export function networkFrom(network) {
|
|
54
|
+
if (typeof network === 'string')
|
|
55
|
+
return networkFromName(network);
|
|
56
|
+
return network;
|
|
114
57
|
}
|
|
115
|
-
export
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
58
|
+
export function defaultUrlFromNetwork(network) {
|
|
59
|
+
if (!network)
|
|
60
|
+
return HIRO_MAINNET_URL;
|
|
61
|
+
network = networkFrom(network);
|
|
62
|
+
return !network || network.transactionVersion === TransactionVersion.Mainnet
|
|
63
|
+
? HIRO_MAINNET_URL
|
|
64
|
+
: network.magicBytes === 'id'
|
|
65
|
+
? DEVNET_URL
|
|
66
|
+
: HIRO_TESTNET_URL;
|
|
67
|
+
}
|
|
68
|
+
export function clientFromNetwork(network) {
|
|
69
|
+
if (network.client.fetch)
|
|
70
|
+
return network.client;
|
|
71
|
+
return {
|
|
72
|
+
...network.client,
|
|
73
|
+
fetch: createFetchFn(),
|
|
74
|
+
};
|
|
124
75
|
}
|
|
125
|
-
export const StacksDevnet = StacksMocknet;
|
|
126
76
|
//# 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,
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/network.ts"],"names":[],"mappings":"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"}
|
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,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ClientOpts, FetchFn } from '@stacks/common';
|
|
2
|
+
import { ClientParam } from '@stacks/common';
|
|
3
|
+
export type StacksNetwork = {
|
|
4
|
+
chainId: number;
|
|
5
|
+
transactionVersion: number;
|
|
6
|
+
peerNetworkId: number;
|
|
7
|
+
magicBytes: string;
|
|
8
|
+
bootAddress: string;
|
|
9
|
+
addressVersion: {
|
|
10
|
+
singleSig: number;
|
|
11
|
+
multiSig: number;
|
|
12
|
+
};
|
|
13
|
+
client: {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
fetch?: FetchFn;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export interface NetworkParam {
|
|
19
|
+
network?: StacksNetworkName | StacksNetwork;
|
|
9
20
|
}
|
|
21
|
+
export type NetworkClientParam = NetworkParam & ClientParam;
|
|
22
|
+
export declare const STACKS_MAINNET: StacksNetwork;
|
|
23
|
+
export declare const STACKS_TESTNET: StacksNetwork;
|
|
24
|
+
export declare const STACKS_DEVNET: StacksNetwork;
|
|
25
|
+
export declare const STACKS_MOCKNET: StacksNetwork;
|
|
10
26
|
export declare const StacksNetworks: readonly ["mainnet", "testnet", "devnet", "mocknet"];
|
|
11
27
|
export type StacksNetworkName = (typeof StacksNetworks)[number];
|
|
12
|
-
export declare
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
28
|
+
export declare function networkFromName(name: StacksNetworkName): StacksNetwork;
|
|
29
|
+
export declare function networkFrom(network: StacksNetworkName | StacksNetwork): StacksNetwork;
|
|
30
|
+
export declare function defaultUrlFromNetwork(network?: StacksNetworkName | StacksNetwork): "https://api.mainnet.hiro.so" | "https://api.testnet.hiro.so" | "http://localhost:3999";
|
|
31
|
+
export declare function clientFromNetwork(network: StacksNetwork): Required<ClientOpts>;
|