var m = Object.defineProperty;
var w = (i, e, t) => e in i ? m(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
var a = (i, e, t) => w(i, typeof e != "symbol" ? e + "" : e, t);
import { C as u } from "./cosmwasm-DvwgrLe6.mjs";
import { cL as g, c9 as l, u as h, bR as p, a9 as f } from "./index-CjwA7HmM.mjs";
class c {
  constructor(e, t, s, r) {
    a(this, "network");
    a(this, "chain");
    a(this, "rpc");
    a(this, "contracts");
    a(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 u.chainFromRpc(e), n = t[r];
    if (n.network !== s)
      throw new Error(`Network mismatch: ${n.network} != ${s}`);
    return new c(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 [c.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 [c.parseWormholeMessage(this.chain, this.coreAddress, t)];
  }
  static parseWormholeMessage(e, t, s) {
    const r = s.events.filter((o) => o.type === "wasm" && o.attributes[0].key === "_contract_address" && o.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, d = Object.fromEntries(n.attributes.map((o) => [o.key.split(".")[1], o.value]));
    return g("Uint8Array", {
      emitterChain: e,
      emitterAddress: new l(h.decode(d.sender)),
      sequence: BigInt(d.sequence),
      guardianSet: 0,
      // TODO: need to implement guardian set idx
      timestamp: Number(d.block_time),
      consistencyLevel: 0,
      nonce: Number(d.nonce),
      signatures: [],
      payload: h.decode(d.message)
    });
  }
  static parseWormholeMessageId(e, t, s) {
    const r = c.parseWormholeMessage(e, t, s);
    return {
      chain: r.emitterChain,
      emitter: r.emitterAddress,
      sequence: r.sequence
    };
  }
}
p(f, "WormholeCore", c);
export {
  c as CosmwasmWormholeCore
};
