"use strict";var m=Object.defineProperty;var u=(d,e,t)=>e in d?m(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t;var i=(d,e,t)=>u(d,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./cosmwasm-Dg8T1AeT.js"),c=require("./index-uRFn7LyP.js");class o{constructor(e,t,s,r){i(this,"network");i(this,"chain");i(this,"rpc");i(this,"contracts");i(this,"coreAddress");this.network=e,this.chain=t,this.rpc=s,this.contracts=r;const n=this.contracts.coreBridge;if(!n)throw new Error(`Wormhole Token Bridge contract for domain ${t} not found`);this.coreAddress=n}getGuardianSet(e){throw new Error("Method not implemented.")}getGuardianSetIndex(){throw new Error("Method not implemented.")}getMessageFee(){throw new Error("Method not implemented.")}static async fromRpc(e,t){const[s,r]=await w.CosmwasmPlatform.chainFromRpc(e),n=t[r];if(n.network!==s)throw new Error(`Network mismatch: ${n.network} != ${s}`);return new o(s,r,e,n.contracts)}async*publishMessage(e,t,s,r){throw new Error("Method not implemented.")}async*verifyMessage(e,t){throw new Error("Not implemented.")}async parseTransaction(e){const t=await this.rpc.getTx(e);if(!t)throw new Error("No transaction found for txid: "+e);return[o.parseWormholeMessageId(this.chain,this.coreAddress,t)]}async parseMessages(e){const t=await this.rpc.getTx(e);if(!t)throw new Error("No transaction found for txid: "+e);return[o.parseWormholeMessage(this.chain,this.coreAddress,t)]}static parseWormholeMessage(e,t,s){const r=s.events.filter(a=>a.type==="wasm"&&a.attributes[0].key==="_contract_address"&&a.attributes[0].value===t);if(r.length===0)throw new Error("No wormhole message found in tx");r.length>1&&console.error(`Expected single message, found ${r.length}`);const[n]=r,h=Object.fromEntries(n.attributes.map(a=>[a.key.split(".")[1],a.value]));return c.createVAA("Uint8Array",{emitterChain:e,emitterAddress:new c.UniversalAddress(c.hex.decode(h.sender)),sequence:BigInt(h.sequence),guardianSet:0,timestamp:Number(h.block_time),consistencyLevel:0,nonce:Number(h.nonce),signatures:[],payload:c.hex.decode(h.message)})}static parseWormholeMessageId(e,t,s){const r=o.parseWormholeMessage(e,t,s);return{chain:r.emitterChain,emitter:r.emitterAddress,sequence:r.sequence}}}c.registerProtocol(c._platform$3,"WormholeCore",o);exports.CosmwasmWormholeCore=o;
