UNPKG

@hashgraph/sdk

Version:
3 lines (2 loc) 1.19 kB
import{ALL_WEB_NETWORK_NODES as t}from"../constants/ClientConstants.js";import s from"../grpc/GrpcServiceError.js";import r from"../grpc/GrpcStatus.js";import e from"../http/HttpError.js";import o from"../http/HttpStatus.js";import{SDK_NAME as a,SDK_VERSION as n}from"../version.js";import p,{encodeRequest as c,decodeUnaryResponse as i}from"./Channel.js";class l extends p{constructor(t){super(),this._address=t}close(){}_createUnaryClient(p){return async(l,d,m)=>{try{const u=!(this._address.includes("localhost")||this._address.includes("127.0.0.1"))?`https://${this._address}`:`http://${this._address}`,h=await fetch(`${u}/proto.${p}/${l.name}`,{method:"POST",headers:{"content-type":"application/grpc-web+proto","x-user-agent":`${a}/${n}`,"x-grpc-web":"1"},body:c(d)});if(!h.ok){m(new e(o._fromValue(h.status)),null)}const f=h.headers.get("grpc-status"),g=h.headers.get("grpc-message");if(null!=f&&null!=g){const e=new s(r._fromValue(parseInt(f)),t?.[this._address]?.toString());e.message=g,m(e,null)}const _=await h.arrayBuffer();m(null,i(_))}catch(e){m(new s(r._fromValue(18),t?.[this._address]?.toString()),null)}}}}export{l as default}; //# sourceMappingURL=WebChannel.js.map