// 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 { MsgCreateConfirmation } from "./types/rarimocore/tx";
import { MsgCreateTransferOp } from "./types/rarimocore/tx";
import { MsgCreateChangeKeyECDSA } from "./types/rarimocore/tx";
export { MsgCreateConfirmation, MsgCreateTransferOp, MsgCreateChangeKeyECDSA };
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 sendMsgCreateConfirmation({ value, fee, memo }) {
            if (!signer) {
                throw new Error('TxClient:sendMsgCreateConfirmation: 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.msgCreateConfirmation({ value: MsgCreateConfirmation.fromPartial(value) });
                return await signingClient.signAndBroadcast(address, [msg], fee ? fee : defaultFee, memo);
            }
            catch (e) {
                throw new Error('TxClient:sendMsgCreateConfirmation: Could not broadcast Tx: ' + e.message);
            }
        },
        async sendMsgCreateTransferOp({ value, fee, memo }) {
            if (!signer) {
                throw new Error('TxClient:sendMsgCreateTransferOp: 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.msgCreateTransferOp({ value: MsgCreateTransferOp.fromPartial(value) });
                return await signingClient.signAndBroadcast(address, [msg], fee ? fee : defaultFee, memo);
            }
            catch (e) {
                throw new Error('TxClient:sendMsgCreateTransferOp: Could not broadcast Tx: ' + e.message);
            }
        },
        async sendMsgCreateChangeKeyECDSA({ value, fee, memo }) {
            if (!signer) {
                throw new Error('TxClient:sendMsgCreateChangeKeyECDSA: 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.msgCreateChangeKeyECDSA({ value: MsgCreateChangeKeyECDSA.fromPartial(value) });
                return await signingClient.signAndBroadcast(address, [msg], fee ? fee : defaultFee, memo);
            }
            catch (e) {
                throw new Error('TxClient:sendMsgCreateChangeKeyECDSA: Could not broadcast Tx: ' + e.message);
            }
        },
        msgCreateConfirmation({ value }) {
            try {
                return { typeUrl: "/rarifyprotocol.rarimocore.rarimocore.MsgCreateConfirmation", value: MsgCreateConfirmation.fromPartial(value) };
            }
            catch (e) {
                throw new Error('TxClient:MsgCreateConfirmation: Could not create message: ' + e.message);
            }
        },
        msgCreateTransferOp({ value }) {
            try {
                return { typeUrl: "/rarifyprotocol.rarimocore.rarimocore.MsgCreateTransferOp", value: MsgCreateTransferOp.fromPartial(value) };
            }
            catch (e) {
                throw new Error('TxClient:MsgCreateTransferOp: Could not create message: ' + e.message);
            }
        },
        msgCreateChangeKeyECDSA({ value }) {
            try {
                return { typeUrl: "/rarifyprotocol.rarimocore.rarimocore.MsgCreateChangeKeyECDSA", value: MsgCreateChangeKeyECDSA.fromPartial(value) };
            }
            catch (e) {
                throw new Error('TxClient:MsgCreateChangeKeyECDSA: 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: {
            RarifyprotocolRarimocoreRarimocore: new SDKModule(test)
        },
        registry: msgTypes
    };
};
export default Module;
//# sourceMappingURL=module.js.map