API for ADODB specific messages.
export default class FactoryAPI extends ADOAPI {
constructor(client: AndromedaClient, public address: string = "") {
super(client, address);
}
Fetches the factory address from the on chain registry.
async getAddressFromRegistry(registryAPI: RegistryAPI) {
try {
const factoryAddress = await registryAPI.getAddress("factory");
this.address = factoryAddress;
} catch (e) {
console.error(e);
console.warn("Could not fetch factory address");
}
}
updateCodeIdMsg(code_id_key: string, code_id: number) {
return {
update_code_id: {
code_id,
code_id_key,
},
};
}
Updates the Code ID for a given key within the factory.
async updateCodeId(
code_id_key: string,
code_id: number,
fee: Fee,
address?: string,
memo?: string
) {
const msg = this.updateCodeIdMsg(code_id_key, code_id);
if (!address && !this.address)
throw new Error("Please provide a valid factory address");
return this.client.execute(
address ?? this.address!,
msg,
fee,
memo ?? `Update Code ID (${code_id_key}, ${code_id})`
);
}
export type Fee = number | StdFee | "auto"
getCodeIdQuery(name: string) {
return {
code_id: {
key: name,
},
};
}
Gets the code ID for an ADO type from the factory.
async getCodeId(name: string, address?: string) {
if (!this.address && !address)
throw new Error("No provided factory address to retrieve code ID");
const msg = this.getCodeIdQuery(name);
return this.client.queryContract<number>(this.address ?? address!, msg);
}
}