// Generated by Ignite ignite.com/cli
import { SigningStargateClient } from "@cosmjs/stargate";
import { Registry } from "@cosmjs/proto-signing";
import { msgTypes } from './registry';
import { Api } from "./rest";
import { MsgAddChain } from "./types/tokenmanager/tx";
import { MsgCreateInfo } from "./types/tokenmanager/tx";
import { MsgDeleteInfo } from "./types/tokenmanager/tx";
export { MsgAddChain, MsgCreateInfo, MsgDeleteInfo };
export const registry = new Registry(msgTypes);
const defaultFee = {
    amount: [],
    gas: "200000",
};
export const txClient = ({ signer, prefix, addr } = { addr: "http://localhost:26657", prefix: "cosmos" }) => {
    return {
        async sendMsgAddChain({ value, fee, memo }) {
            if (!signer) {
                throw new Error('TxClient:sendMsgAddChain: Unable to sign Tx. Signer is not present.');
            }
            try {
                const { address } = (await signer.getAccounts())[0];
                const signingClient = await SigningStargateClient.connectWithSigner(addr, signer, { registry, prefix });
                let msg = this.msgAddChain({ value: MsgAddChain.fromPartial(value) });
                return await signingClient.signAndBroadcast(address, [msg], fee ? fee : defaultFee, memo);
            }
            catch (e) {
                throw new Error('TxClient:sendMsgAddChain: Could not broadcast Tx: ' + e.message);
            }
        },
        async sendMsgCreateInfo({ value, fee, memo }) {
            if (!signer) {
                throw new Error('TxClient:sendMsgCreateInfo: Unable to sign Tx. Signer is not present.');
            }
            try {
                const { address } = (await signer.getAccounts())[0];
                const signingClient = await SigningStargateClient.connectWithSigner(addr, signer, { registry, prefix });
                let msg = this.msgCreateInfo({ value: MsgCreateInfo.fromPartial(value) });
                return await signingClient.signAndBroadcast(address, [msg], fee ? fee : defaultFee, memo);
            }
            catch (e) {
                throw new Error('TxClient:sendMsgCreateInfo: Could not broadcast Tx: ' + e.message);
            }
        },
        async sendMsgDeleteInfo({ value, fee, memo }) {
            if (!signer) {
                throw new Error('TxClient:sendMsgDeleteInfo: Unable to sign Tx. Signer is not present.');
            }
            try {
                const { address } = (await signer.getAccounts())[0];
                const signingClient = await SigningStargateClient.connectWithSigner(addr, signer, { registry, prefix });
                let msg = this.msgDeleteInfo({ value: MsgDeleteInfo.fromPartial(value) });
                return await signingClient.signAndBroadcast(address, [msg], fee ? fee : defaultFee, memo);
            }
            catch (e) {
                throw new Error('TxClient:sendMsgDeleteInfo: Could not broadcast Tx: ' + e.message);
            }
        },
        msgAddChain({ value }) {
            try {
                return { typeUrl: "/rarifyprotocol.rarimocore.tokenmanager.MsgAddChain", value: MsgAddChain.fromPartial(value) };
            }
            catch (e) {
                throw new Error('TxClient:MsgAddChain: Could not create message: ' + e.message);
            }
        },
        msgCreateInfo({ value }) {
            try {
                return { typeUrl: "/rarifyprotocol.rarimocore.tokenmanager.MsgCreateInfo", value: MsgCreateInfo.fromPartial(value) };
            }
            catch (e) {
                throw new Error('TxClient:MsgCreateInfo: Could not create message: ' + e.message);
            }
        },
        msgDeleteInfo({ value }) {
            try {
                return { typeUrl: "/rarifyprotocol.rarimocore.tokenmanager.MsgDeleteInfo", value: MsgDeleteInfo.fromPartial(value) };
            }
            catch (e) {
                throw new Error('TxClient:MsgDeleteInfo: Could not create message: ' + e.message);
            }
        },
    };
};
export const queryClient = ({ addr: addr } = { addr: "http://localhost:1317" }) => {
    return new Api({ baseURL: addr });
};
class SDKModule {
    query;
    tx;
    registry = [];
    constructor(client) {
        this.query = queryClient({ addr: client.env.apiURL });
        this.updateTX(client);
        client.on('signer-changed', (signer) => {
            this.updateTX(client);
        });
    }
    updateTX(client) {
        const methods = txClient({
            signer: client.signer,
            addr: client.env.rpcURL,
            prefix: client.env.prefix ?? "cosmos",
        });
        this.tx = methods;
        for (let m in methods) {
            this.tx[m] = methods[m].bind(this.tx);
        }
    }
}
;
const Module = (test) => {
    return {
        module: {
            RarifyprotocolRarimocoreTokenmanager: new SDKModule(test)
        },
        registry: msgTypes
    };
};
export default Module;
//# sourceMappingURL=module.js.map