UNPKG

wowok

Version:

Wowok Blockchain TypeScript API

1 lines 2.08 kB
export class FaucetRateLimitError extends Error{}async function faucetRequest({host:a,path:b,body:c,headers:d,method:f}){const g=new URL(b,a)['toString'](),h={'Content-Type':'application/json'};d&&Object['assign'](h,d);const i=await fetch(g,{'method':f,'body':c?JSON['stringify'](c):undefined,'headers':h});if(i['status']===0x1ad)throw new FaucetRateLimitError('Too\x20many\x20requests\x20from\x20this\x20client\x20have\x20been\x20sent\x20to\x20the\x20faucet.\x20Please\x20retry\x20later');try{const j=await i['json']();return j;}catch(k){throw new Error('Encountered\x20error\x20when\x20parsing\x20response\x20from\x20faucet,\x20error:\x20'+k+',\x20status\x20'+i['status']+',\x20response\x20'+i);}}export async function requestWowFromFaucetV0(a){const b=await faucetRequest({'host':a['host'],'path':'/gas','body':{'FixedAmountRequest':{'recipient':a['recipient']}},'headers':a['headers'],'method':'POST'});if(b['error'])throw new Error('Faucet\x20request\x20failed:\x20'+b['error']);return b;}export async function requestWowFromFaucetV1(a){const b=await faucetRequest({'host':a['host'],'path':'/v1/gas','body':{'FixedAmountRequest':{'recipient':a['recipient']}},'headers':a['headers'],'method':'POST'});if(b['error'])throw new Error('Faucet\x20request\x20failed:\x20'+b['error']);return b;}export async function requestWowFromFaucetV2(a){const b=await faucetRequest({'host':a['host'],'path':'/v2/gas','body':{'FixedAmountRequest':{'recipient':a['recipient']}},'headers':a['headers'],'method':'POST'});if(b['status']!=='Success')throw new Error('Faucet\x20request\x20failed:\x20'+b['status']['Failure']['internal']);return b;}export async function getFaucetRequestStatus(a){const b=await faucetRequest({'host':a['host'],'path':'/v1/status/'+a['taskId'],'headers':a['headers'],'method':'GET'});if(b['error'])throw new Error('Faucet\x20request\x20failed:\x20'+b['error']);return b;}export function getFaucetHost(a){switch(a){case'testnet':return'https://faucet.testnet.wowok.net';case'localnet':return'http://127.0.0.1:9123';default:throw new Error('Unknown\x20network:\x20'+a);}}