UNPKG

dogecoinjs

Version:

The Comfiest Way to get Dogecoin info and events for the Web and NodeJS!

1 lines 2.65 kB
!function e(n,t,o){function r(i,a){if(!t[i]){if(!n[i]){var f="function"==typeof require&&require;if(!a&&f)return f(i,!0);if(s)return s(i,!0);var u=new Error("Cannot find module '"+i+"'");throw u.code="MODULE_NOT_FOUND",u}var c=t[i]={exports:{}};n[i][0].call(c.exports,(function(e){return r(n[i][1][e]||e)}),c,c.exports,e,n,t,o)}return t[i].exports}for(var s="function"==typeof require&&require,i=0;i<o.length;i++)r(o[i]);return r}({1:[function(e,n,t){var o=e("node-fetch"),r=e("ws");let s={},i=null,a=[];var f={isDebug:!1,version:function(){return"0.2.1"},lookup:async function(e,n=null){let t=o(`https://my.dogechain.info/api/v2/get_address_balance/DOGE/${e}`).then((e=>e.json()));if(!n)return t;n(await t)},qrcode:async function(e,n=null){let t=o(`https://dogechain.info/api/v1/address/qrcode/${e}`).then((e=>e.blob()));if(!n)return t;n(await t)},listen:async function(e,n){let t=i||await async function(){return new Promise((e=>{let n;i="undefined"!=typeof window?new WebSocket("wss://ws.dogechain.info/inv"):new r("wss://ws.dogechain.info/inv"),i.onopen=function(e){n=setInterval((()=>{i.send(JSON.stringify({op:"ping_block"}))}),6e4),a.forEach((e=>{i.send(JSON.stringify(e))}))},i.onerror=function(e){console.error(e)},i.onmessage=function(e){switch(message=JSON.parse(e.data),message.op){case"status":break;case"utx":Object.keys(s).forEach((e=>{s[e].listen&&(message.x.inputs.forEach((n=>{if(n.prev_out&&n.prev_out.addr===e){let t=n.prev_out.value/1e8;s[e].listen(e,-t,{id:message.x.hash,data:message.x})}})),message.x.outputs.forEach((n=>{if(n.addr===e){let t=n.value/1e8;s[e].listen(e,t,{id:message.x.hash,data:message.x})}})))}))}},i.onclose=function(){clearInterval(n),console.log("closed")},e(i)}))}(),o=[e];Array.isArray(e)&&(o=e),o.forEach((e=>{s[e]=s[e]||{},s[e].listen=n,t.readyState?t.send(JSON.stringify({op:"addr_sub",addr:e})):a.push({op:"addr_sub",addr:e})}))}};void 0!==n&&n.exports&&(n.exports=f),"undefined"!=typeof window&&(window.Dogecoin=f)},{"node-fetch":2,ws:3}],2:[function(e,n,t){(function(e){(function(){"use strict";var e=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==e)return e;throw new Error("unable to locate global object")}();n.exports=t=e.fetch,e.fetch&&(t.default=e.fetch.bind(e)),t.Headers=e.Headers,t.Request=e.Request,t.Response=e.Response}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],3:[function(e,n,t){"use strict";n.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},{}]},{},[1]);