micro-stacks
Version:
Tiny libraries for building Stacks apps.
24 lines (19 loc) • 3.29 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var common = require('micro-stacks/common');
var g="https://stacks-node-api.mainnet.stacks.co",p="https://stacks-node-api.testnet.stacks.co",d="http://localhost:3999",i=class{version=common.TransactionVersion.Mainnet;chainId=common.ChainID.Mainnet;broadcastEndpoint="/v2/transactions";transferFeeEstimateEndpoint="/v2/fees/transfer";accountEndpoint="/v2/accounts";contractAbiEndpoint="/v2/contracts/interface";readOnlyFunctionCallEndpoint="/v2/contracts/call-read";bnsLookupUrl;_coreApiUrl;fetcher;get coreApiUrl(){return this._coreApiUrl}set coreApiUrl(t){throw new Error("Cannot modify property `coreApiUrl` after object initialization")}constructor(t={url:g}){if(!t.url&&!t.coreApiUrl)throw Error("[miro-stacks] Network initialized with no api url");this._coreApiUrl=t.url||t.coreApiUrl,this.bnsLookupUrl=t.bnsLookupUrl||t.url||t.coreApiUrl,this.fetcher=t.fetcher||common.fetchPrivate;}getCoreApiUrl=()=>this._coreApiUrl;isMainnet=()=>this.version===common.TransactionVersion.Mainnet;getBroadcastApiUrl=()=>`${this.getCoreApiUrl()}${this.broadcastEndpoint}`;getTransferFeeEstimateApiUrl=()=>`${this.getCoreApiUrl()}${this.transferFeeEstimateEndpoint}`;getAccountApiUrl=t=>`${this.getCoreApiUrl()}${this.accountEndpoint}/${t}?proof=0`;getAbiApiUrl=(t,e)=>`${this.getCoreApiUrl()}${this.contractAbiEndpoint}/${t}/${e}`;getReadOnlyFunctionCallApiUrl=(t,e,r)=>`${this.getCoreApiUrl()}${this.readOnlyFunctionCallEndpoint}/${t}/${e}/${encodeURIComponent(r)}`;getInfoUrl=()=>`${this.getCoreApiUrl()}/v2/info`;getBlockTimeInfoUrl=()=>`${this.getCoreApiUrl()}/extended/v1/info/network_block_times`;getPoxInfoUrl=()=>`${this.getCoreApiUrl()}/v2/pox`;getRewardsUrl=(t,e)=>{let r=`${this.getCoreApiUrl()}/extended/v1/burnchain/rewards/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r};getRewardsTotalUrl=t=>`${this.getCoreApiUrl()}/extended/v1/burnchain/rewards/${t}/total`;getRewardHoldersUrl=(t,e)=>{let r=`${this.getCoreApiUrl()}/extended/v1/burnchain/reward_slot_holders/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r};getStackerInfoUrl=(t,e)=>`${this.getCoreApiUrl()}${this.readOnlyFunctionCallEndpoint}
${t}/${e}/get-stacker-info`;getNameInfo(t){let e=`${this.bnsLookupUrl}/v1/names/${t}`;return this.fetcher(e).then(r=>{if(r.status===404)throw new Error("Name not found");if(r.status!==200)throw new Error(`Bad response status: ${r.status}`);return r.json()}).then(r=>r.address?Object.assign({},r,{address:r.address}):r)}},l=class extends i{version=common.TransactionVersion.Testnet;chainId=common.ChainID.Testnet;constructor(t={url:p,fetcher:common.fetchPrivate}){super(t);}},c=class extends i{version=common.TransactionVersion.Testnet;chainId=common.ChainID.Testnet;constructor(t={url:d,fetcher:common.fetchPrivate}){super(t);}};
Object.defineProperty(exports, 'ChainID', {
enumerable: true,
get: function () { return common.ChainID; }
});
Object.defineProperty(exports, 'TransactionVersion', {
enumerable: true,
get: function () { return common.TransactionVersion; }
});
exports.HIRO_MAINNET_DEFAULT = g;
exports.HIRO_MOCKNET_DEFAULT = d;
exports.HIRO_TESTNET_DEFAULT = p;
exports.StacksMainnet = i;
exports.StacksMocknet = c;
exports.StacksTestnet = l;