8 lines
15 KiB
JavaScript
8 lines
15 KiB
JavaScript
import{a as U,b as k,c as j,d as R,e as p,f as v,g as m,h as T,i as $,j as H}from"./chunk-X6ZP5JNU.js";import{qa as V}from"./chunk-QY24TFF7.js";import{o as n,q as c}from"./chunk-QTLWQ5AJ.js";n();c();n();c();n();c();n();c();var J="1.9.0",K="1.34.0";n();c();var rt={"-32700":"ParseError","-32701":"OversizedRequest","-32702":"OversizedResponse","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError","-32604":"ServerBusy","-32000":"CallExecutionFailed","-32001":"UnknownError","-32003":"SubscriptionClosed","-32004":"SubscriptionClosedWithError","-32005":"BatchesNotSupported","-32006":"TooManySubscriptions","-32050":"TransientError","-32002":"TransactionExecutionClientError"},M=class extends Error{},_=class extends M{constructor(t,e){super(t),this.code=e,this.type=rt[e]??"ServerError"}},B=class extends M{constructor(t,e,r){super(t),this.status=e,this.statusText=r}};n();c();var X=s=>{throw TypeError(s)},D=(s,t,e)=>t.has(s)||X("Cannot "+e),i=(s,t,e)=>(D(s,t,"read from private field"),e?e.call(s):t.get(s)),w=(s,t,e)=>t.has(s)?X("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,e),S=(s,t,e,r)=>(D(s,t,"write to private field"),r?r.call(s,e):t.set(s,e),e),Y=(s,t,e)=>(D(s,t,"access private method"),e),at=(s,t,e,r)=>({set _(a){S(s,t,a,e)},get _(){return i(s,t,r)}}),g,E,h,y,q,b,A,Q,Z;function it(s){let t=new URL(s);return t.protocol=t.protocol.replace("http","ws"),t.toString()}var ot={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},N=class{constructor(t,e={}){if(w(this,A),w(this,g,0),w(this,E,0),w(this,h,null),w(this,y,null),w(this,q,new Set),w(this,b,new Map),this.endpoint=t,this.options={...ot,...e},!this.options.WebSocketConstructor)throw new Error("Missing WebSocket constructor");this.endpoint.startsWith("http")&&(this.endpoint=it(this.endpoint))}async makeRequest(t,e){let r=await Y(this,A,Q).call(this);return new Promise((a,o)=>{S(this,g,i(this,g)+1),i(this,b).set(i(this,g),{resolve:a,reject:o,timeout:setTimeout(()=>{i(this,b).delete(i(this,g)),o(new Error(`Request timeout: ${t}`))},this.options.callTimeout)}),r.send(JSON.stringify({jsonrpc:"2.0",id:i(this,g),method:t,params:e}))}).then(({error:a,result:o})=>{if(a)throw new _(a.message,a.code);return o})}async subscribe(t){let e=new F(t);return i(this,q).add(e),await e.subscribe(this),()=>e.unsubscribe(this)}};g=new WeakMap;E=new WeakMap;h=new WeakMap;y=new WeakMap;q=new WeakMap;b=new WeakMap;A=new WeakSet;Q=function(){return i(this,y)?i(this,y):(S(this,y,new Promise(s=>{i(this,h)?.close(),S(this,h,new this.options.WebSocketConstructor(this.endpoint)),i(this,h).addEventListener("open",()=>{S(this,E,0),s(i(this,h))}),i(this,h).addEventListener("close",()=>{at(this,E)._++,i(this,E)<=this.options.maxReconnects&&setTimeout(()=>{Y(this,A,Z).call(this)},this.options.reconnectTimeout)}),i(this,h).addEventListener("message",({data:t})=>{let e;try{e=JSON.parse(t)}catch(r){console.error(new Error(`Failed to parse RPC message: ${t}`,{cause:r}));return}if("id"in e&&e.id!=null&&i(this,b).has(e.id)){let{resolve:r,timeout:a}=i(this,b).get(e.id);clearTimeout(a),r(e)}else if("params"in e){let{params:r}=e;i(this,q).forEach(a=>{a.subscriptionId===r.subscription&&r.subscription===a.subscriptionId&&a.onMessage(r.result)})}})})),i(this,y))};Z=async function(){return i(this,h)?.close(),S(this,y,null),Promise.allSettled([...i(this,q)].map(s=>s.subscribe(this)))};var F=class{constructor(t){this.subscriptionId=null,this.subscribed=!1,this.input=t}onMessage(t){this.subscribed&&this.input.onMessage(t)}async unsubscribe(t){let{subscriptionId:e}=this;return this.subscribed=!1,e==null?!1:(this.subscriptionId=null,t.makeRequest(this.input.unsubscribe,[e]))}async subscribe(t){this.subscriptionId=null,this.subscribed=!0;let e=await t.makeRequest(this.input.method,this.input.params);this.subscribed&&(this.subscriptionId=e)}};var tt=s=>{throw TypeError(s)},L=(s,t,e)=>t.has(s)||tt("Cannot "+e),u=(s,t,e)=>(L(s,t,"read from private field"),e?e.call(s):t.get(s)),O=(s,t,e)=>t.has(s)?tt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,e),z=(s,t,e,r)=>(L(s,t,"write to private field"),r?r.call(s,e):t.set(s,e),e),nt=(s,t,e)=>(L(s,t,"access private method"),e),C,d,x,G,et,P=class{constructor(t){O(this,G),O(this,C,0),O(this,d),O(this,x),z(this,d,t)}fetch(t,e){let r=u(this,d).fetch??fetch;if(!r)throw new Error("The current environment does not support fetch, you can provide a fetch implementation in the options for SuiHTTPTransport.");return r(t,e)}async request(t){z(this,C,u(this,C)+1);let e=await this.fetch(u(this,d).rpc?.url??u(this,d).url,{method:"POST",headers:{"Content-Type":"application/json","Client-Sdk-Type":"typescript","Client-Sdk-Version":J,"Client-Target-Api-Version":K,...u(this,d).rpc?.headers},body:JSON.stringify({jsonrpc:"2.0",id:u(this,C),method:t.method,params:t.params})});if(!e.ok)throw new B(`Unexpected status code: ${e.status}`,e.status,e.statusText);let r=await e.json();if("error"in r&&r.error!=null)throw new _(r.error.message,r.error.code);return r.result}async subscribe(t){let e=await nt(this,G,et).call(this).subscribe(t);return async()=>!!await e()}};C=new WeakMap;d=new WeakMap;x=new WeakMap;G=new WeakSet;et=function(){if(!u(this,x)){let s=u(this,d).WebSocketConstructor??WebSocket;if(!s)throw new Error("The current environment does not support WebSocket, you can provide a WebSocketConstructor in the options for SuiHTTPTransport.");z(this,x,new N(u(this,d).websocket?.url??u(this,d).url,{WebSocketConstructor:s,...u(this,d).websocket}))}return u(this,x)};n();c();var ct=Symbol.for("@mysten/SuiClient");var I=class{get[ct](){return!0}constructor(t){this.transport=t.transport??new P({url:t.url})}async getRpcApiVersion(){return(await this.transport.request({method:"rpc.discover",params:[]})).info.version}async getCoins(t){if(!t.owner||!p(m(t.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getCoins",params:[t.owner,t.coinType,t.cursor,t.limit]})}async getAllCoins(t){if(!t.owner||!p(m(t.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getAllCoins",params:[t.owner,t.cursor,t.limit]})}async getBalance(t){if(!t.owner||!p(m(t.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getBalance",params:[t.owner,t.coinType]})}async getAllBalances(t){if(!t.owner||!p(m(t.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getAllBalances",params:[t.owner]})}async getCoinMetadata(t){return await this.transport.request({method:"suix_getCoinMetadata",params:[t.coinType]})}async getTotalSupply(t){return await this.transport.request({method:"suix_getTotalSupply",params:[t.coinType]})}async call(t,e){return await this.transport.request({method:t,params:e})}async getMoveFunctionArgTypes(t){return await this.transport.request({method:"sui_getMoveFunctionArgTypes",params:[t.package,t.module,t.function]})}async getNormalizedMoveModulesByPackage(t){return await this.transport.request({method:"sui_getNormalizedMoveModulesByPackage",params:[t.package]})}async getNormalizedMoveModule(t){return await this.transport.request({method:"sui_getNormalizedMoveModule",params:[t.package,t.module]})}async getNormalizedMoveFunction(t){return await this.transport.request({method:"sui_getNormalizedMoveFunction",params:[t.package,t.module,t.function]})}async getNormalizedMoveStruct(t){return await this.transport.request({method:"sui_getNormalizedMoveStruct",params:[t.package,t.module,t.struct]})}async getOwnedObjects(t){if(!t.owner||!p(m(t.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getOwnedObjects",params:[t.owner,{filter:t.filter,options:t.options},t.cursor,t.limit]})}async getObject(t){if(!t.id||!v(T(t.id)))throw new Error("Invalid Sui Object id");return await this.transport.request({method:"sui_getObject",params:[t.id,t.options]})}async tryGetPastObject(t){return await this.transport.request({method:"sui_tryGetPastObject",params:[t.id,t.version,t.options]})}async multiGetObjects(t){if(t.ids.forEach(r=>{if(!r||!v(T(r)))throw new Error(`Invalid Sui Object id ${r}`)}),t.ids.length!==new Set(t.ids).size)throw new Error(`Duplicate object ids in batch call ${t.ids}`);return await this.transport.request({method:"sui_multiGetObjects",params:[t.ids,t.options]})}async queryTransactionBlocks(t){return await this.transport.request({method:"suix_queryTransactionBlocks",params:[{filter:t.filter,options:t.options},t.cursor,t.limit,(t.order||"descending")==="descending"]})}async getTransactionBlock(t){if(!R(t.digest))throw new Error("Invalid Transaction digest");return await this.transport.request({method:"sui_getTransactionBlock",params:[t.digest,t.options]})}async multiGetTransactionBlocks(t){if(t.digests.forEach(r=>{if(!R(r))throw new Error(`Invalid Transaction digest ${r}`)}),t.digests.length!==new Set(t.digests).size)throw new Error(`Duplicate digests in batch call ${t.digests}`);return await this.transport.request({method:"sui_multiGetTransactionBlocks",params:[t.digests,t.options]})}async executeTransactionBlock({transactionBlock:t,signature:e,options:r,requestType:a}){let o=await this.transport.request({method:"sui_executeTransactionBlock",params:[typeof t=="string"?t:k(t),Array.isArray(e)?e:[e],r]});if(a==="WaitForLocalExecution")try{await this.waitForTransaction({digest:o.digest})}catch{}return o}async signAndExecuteTransaction({transaction:t,signer:e,...r}){let a;t instanceof Uint8Array?a=t:(t.setSenderIfNotSet(e.toSuiAddress()),a=await t.build({client:this}));let{signature:o,bytes:l}=await e.signTransaction(a);return this.executeTransactionBlock({transactionBlock:l,signature:o,...r})}async getTotalTransactionBlocks(){let t=await this.transport.request({method:"sui_getTotalTransactionBlocks",params:[]});return BigInt(t)}async getReferenceGasPrice(){let t=await this.transport.request({method:"suix_getReferenceGasPrice",params:[]});return BigInt(t)}async getStakes(t){if(!t.owner||!p(m(t.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getStakes",params:[t.owner]})}async getStakesByIds(t){return t.stakedSuiIds.forEach(e=>{if(!e||!v(T(e)))throw new Error(`Invalid Sui Stake id ${e}`)}),await this.transport.request({method:"suix_getStakesByIds",params:[t.stakedSuiIds]})}async getLatestSuiSystemState(){return await this.transport.request({method:"suix_getLatestSuiSystemState",params:[]})}async queryEvents(t){return await this.transport.request({method:"suix_queryEvents",params:[t.query,t.cursor,t.limit,(t.order||"descending")==="descending"]})}async subscribeEvent(t){return this.transport.subscribe({method:"suix_subscribeEvent",unsubscribe:"suix_unsubscribeEvent",params:[t.filter],onMessage:t.onMessage})}async subscribeTransaction(t){return this.transport.subscribe({method:"suix_subscribeTransaction",unsubscribe:"suix_unsubscribeTransaction",params:[t.filter],onMessage:t.onMessage})}async devInspectTransactionBlock(t){let e;if(H(t.transactionBlock))t.transactionBlock.setSenderIfNotSet(t.sender),e=k(await t.transactionBlock.build({client:this,onlyTransactionKind:!0}));else if(typeof t.transactionBlock=="string")e=t.transactionBlock;else if(t.transactionBlock instanceof Uint8Array)e=k(t.transactionBlock);else throw new Error("Unknown transaction block format.");return await this.transport.request({method:"sui_devInspectTransactionBlock",params:[t.sender,e,t.gasPrice?.toString(),t.epoch]})}async dryRunTransactionBlock(t){return await this.transport.request({method:"sui_dryRunTransactionBlock",params:[typeof t.transactionBlock=="string"?t.transactionBlock:k(t.transactionBlock)]})}async getDynamicFields(t){if(!t.parentId||!v(T(t.parentId)))throw new Error("Invalid Sui Object id");return await this.transport.request({method:"suix_getDynamicFields",params:[t.parentId,t.cursor,t.limit]})}async getDynamicFieldObject(t){return await this.transport.request({method:"suix_getDynamicFieldObject",params:[t.parentId,t.name]})}async getLatestCheckpointSequenceNumber(){let t=await this.transport.request({method:"sui_getLatestCheckpointSequenceNumber",params:[]});return String(t)}async getCheckpoint(t){return await this.transport.request({method:"sui_getCheckpoint",params:[t.id]})}async getCheckpoints(t){return await this.transport.request({method:"sui_getCheckpoints",params:[t.cursor,t?.limit,t.descendingOrder]})}async getCommitteeInfo(t){return await this.transport.request({method:"suix_getCommitteeInfo",params:[t?.epoch]})}async getNetworkMetrics(){return await this.transport.request({method:"suix_getNetworkMetrics",params:[]})}async getAddressMetrics(){return await this.transport.request({method:"suix_getLatestAddressMetrics",params:[]})}async getEpochMetrics(t){return await this.transport.request({method:"suix_getEpochMetrics",params:[t?.cursor,t?.limit,t?.descendingOrder]})}async getAllEpochAddressMetrics(t){return await this.transport.request({method:"suix_getAllEpochAddressMetrics",params:[t?.descendingOrder]})}async getEpochs(t){return await this.transport.request({method:"suix_getEpochs",params:[t?.cursor,t?.limit,t?.descendingOrder]})}async getMoveCallMetrics(){return await this.transport.request({method:"suix_getMoveCallMetrics",params:[]})}async getCurrentEpoch(){return await this.transport.request({method:"suix_getCurrentEpoch",params:[]})}async getValidatorsApy(){return await this.transport.request({method:"suix_getValidatorsApy",params:[]})}async getChainIdentifier(){let t=await this.getCheckpoint({id:"0"}),e=U(t.digest);return j(e.slice(0,4))}async resolveNameServiceAddress(t){return await this.transport.request({method:"suix_resolveNameServiceAddress",params:[t.name]})}async resolveNameServiceNames({format:t="dot",...e}){let{nextCursor:r,hasNextPage:a,data:o}=await this.transport.request({method:"suix_resolveNameServiceNames",params:[e.address,e.cursor,e.limit]});return{hasNextPage:a,nextCursor:r,data:o.map(l=>$(l,t))}}async getProtocolConfig(t){return await this.transport.request({method:"sui_getProtocolConfig",params:[t?.version]})}async waitForTransaction({signal:t,timeout:e=60*1e3,pollInterval:r=2*1e3,...a}){let o=AbortSignal.timeout(e),l=new Promise((st,W)=>{o.addEventListener("abort",()=>W(o.reason))});for(l.catch(()=>{});!o.aborted;){t?.throwIfAborted();try{return await this.getTransactionBlock(a)}catch{await Promise.race([new Promise(W=>setTimeout(W,r)),l])}}throw o.throwIfAborted(),new Error("Unexpected error while waiting for transaction block.")}};var Gt=new I({transport:{request:async({method:s,params:t})=>{try{return(await V({method:s,params:t})).result}catch{return{}}}}});export{Gt as a};
|
|
|
|
window.inOKXExtension = true;
|
|
window.inMiniApp = false;
|
|
window.ASSETS_BUILD_TYPE = "publish";
|
|
|
|
//# sourceMappingURL=chunk-3CS2YPJP.js.map
|