PHP WebShell

Текущая директория: /opt/BitGoJS/node_modules/@stacks/network/dist

Просмотр файла: network.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StacksMocknet = exports.StacksTestnet = exports.StacksMainnet = exports.StacksNetwork = exports.StacksNetworks = exports.HIRO_MOCKNET_DEFAULT = exports.HIRO_TESTNET_DEFAULT = exports.HIRO_MAINNET_DEFAULT = void 0;
const common_1 = require("@stacks/common");
const fetch_1 = require("./fetch");
exports.HIRO_MAINNET_DEFAULT = 'https://stacks-node-api.mainnet.stacks.co';
exports.HIRO_TESTNET_DEFAULT = 'https://stacks-node-api.testnet.stacks.co';
exports.HIRO_MOCKNET_DEFAULT = 'http://localhost:3999';
exports.StacksNetworks = ['mainnet', 'testnet'];
class StacksNetwork {
    constructor(networkConfig) {
        var _a;
        this.version = common_1.TransactionVersion.Mainnet;
        this.chainId = common_1.ChainID.Mainnet;
        this.bnsLookupUrl = 'https://stacks-node-api.mainnet.stacks.co';
        this.broadcastEndpoint = '/v2/transactions';
        this.transferFeeEstimateEndpoint = '/v2/fees/transfer';
        this.transactionFeeEstimateEndpoint = '/v2/fees/transaction';
        this.accountEndpoint = '/v2/accounts';
        this.contractAbiEndpoint = '/v2/contracts/interface';
        this.readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
        this.isMainnet = () => this.version === common_1.TransactionVersion.Mainnet;
        this.getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
        this.getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
        this.getTransactionFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`;
        this.getAccountApiUrl = (address) => `${this.coreApiUrl}${this.accountEndpoint}/${address}?proof=0`;
        this.getAbiApiUrl = (address, contract) => `${this.coreApiUrl}${this.contractAbiEndpoint}/${address}/${contract}`;
        this.getReadOnlyFunctionCallApiUrl = (contractAddress, contractName, functionName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${contractAddress}/${contractName}/${encodeURIComponent(functionName)}`;
        this.getInfoUrl = () => `${this.coreApiUrl}/v2/info`;
        this.getBlockTimeInfoUrl = () => `${this.coreApiUrl}/extended/v1/info/network_block_times`;
        this.getPoxInfoUrl = () => `${this.coreApiUrl}/v2/pox`;
        this.getRewardsUrl = (address, options) => {
            let url = `${this.coreApiUrl}/extended/v1/burnchain/rewards/${address}`;
            if (options) {
                url = `${url}?limit=${options.limit}&offset=${options.offset}`;
            }
            return url;
        };
        this.getRewardsTotalUrl = (address) => `${this.coreApiUrl}/extended/v1/burnchain/rewards/${address}/total`;
        this.getRewardHoldersUrl = (address, options) => {
            let url = `${this.coreApiUrl}/extended/v1/burnchain/reward_slot_holders/${address}`;
            if (options) {
                url = `${url}?limit=${options.limit}&offset=${options.offset}`;
            }
            return url;
        };
        this.getStackerInfoUrl = (contractAddress, contractName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}
    ${contractAddress}/${contractName}/get-stacker-info`;
        this.coreApiUrl = networkConfig.url;
        this.fetchFn = (_a = networkConfig.fetchFn) !== null && _a !== void 0 ? _a : (0, fetch_1.createFetchFn)();
    }
    getNameInfo(fullyQualifiedName) {
        const nameLookupURL = `${this.bnsLookupUrl}/v1/names/${fullyQualifiedName}`;
        return this.fetchFn(nameLookupURL)
            .then(resp => {
            if (resp.status === 404) {
                throw new Error('Name not found');
            }
            else if (resp.status !== 200) {
                throw new Error(`Bad response status: ${resp.status}`);
            }
            else {
                return resp.json();
            }
        })
            .then(nameInfo => {
            if (nameInfo.address) {
                return Object.assign({}, nameInfo, { address: nameInfo.address });
            }
            else {
                return nameInfo;
            }
        });
    }
}
exports.StacksNetwork = StacksNetwork;
StacksNetwork.fromName = (networkName) => {
    switch (networkName) {
        case 'mainnet':
            return new StacksMainnet();
        case 'testnet':
            return new StacksTestnet();
        default:
            throw new Error(`Invalid network name provided. Must be one of the following: ${exports.StacksNetworks.join(', ')}`);
    }
};
StacksNetwork.fromNameOrNetwork = (network) => {
    if (typeof network !== 'string' && 'version' in network) {
        return network;
    }
    return StacksNetwork.fromName(network);
};
class StacksMainnet extends StacksNetwork {
    constructor(opts) {
        var _a;
        super({
            url: (_a = opts === null || opts === void 0 ? void 0 : opts.url) !== null && _a !== void 0 ? _a : exports.HIRO_MAINNET_DEFAULT,
            fetchFn: opts === null || opts === void 0 ? void 0 : opts.fetchFn,
        });
        this.version = common_1.TransactionVersion.Mainnet;
        this.chainId = common_1.ChainID.Mainnet;
    }
}
exports.StacksMainnet = StacksMainnet;
class StacksTestnet extends StacksNetwork {
    constructor(opts) {
        var _a;
        super({
            url: (_a = opts === null || opts === void 0 ? void 0 : opts.url) !== null && _a !== void 0 ? _a : exports.HIRO_TESTNET_DEFAULT,
            fetchFn: opts === null || opts === void 0 ? void 0 : opts.fetchFn,
        });
        this.version = common_1.TransactionVersion.Testnet;
        this.chainId = common_1.ChainID.Testnet;
    }
}
exports.StacksTestnet = StacksTestnet;
class StacksMocknet extends StacksNetwork {
    constructor(opts) {
        var _a;
        super({
            url: (_a = opts === null || opts === void 0 ? void 0 : opts.url) !== null && _a !== void 0 ? _a : exports.HIRO_MOCKNET_DEFAULT,
            fetchFn: opts === null || opts === void 0 ? void 0 : opts.fetchFn,
        });
        this.version = common_1.TransactionVersion.Testnet;
        this.chainId = common_1.ChainID.Testnet;
    }
}
exports.StacksMocknet = StacksMocknet;
//# sourceMappingURL=network.js.map

Выполнить команду


Для локальной разработки. Не используйте в интернете!