Class
API for registry specific messages.
export default class RegistryAPI extends ADOAPI {
constructor(client: AndromedaClient, public address: string = "") {
super(client, address);
}
Check to ensure the registry has a valid address:
private preMessage() {
if (
!this.address ||
this.address.length === 0 ||
!validateAddress(this.address)
)
throw new Error("Registry has no assigned address");
}
setMsg
Provides a message object for the registry's SetValue
message.
setMsg(value: PrimitiveValue, key?: string) {
return {
set_value: {
value,
key,
},
};
}
PrimitiveValue
export type PrimitiveValue =
| StringPrimitive
| Uint128Primitive
| DecimalPrimitive
| CoinPrimitive
| BoolPrimitive
| VecPrimitive;
export interface StringPrimitive {
string: string;
}
export interface Uint128Primitive {
uin128: string;
}
export interface DecimalPrimitive {
decimal: string;
}
export interface CoinPrimitive {
coin: Coin;
}
export interface BoolPrimitive {
bool: Boolean;
}
export interface VecPrimitive {
vec: PrimitiveValue[];
}
set
Sets the value for a given key (default if empty) within the registry.
async set(
value: PrimitiveValue,
fee: Fee,
key?: string,
memo?: string,
) {
this.preMessage();
const msg = this.setMsg(value, key);
return this.client.execute(this.address, msg, fee, memo, funds);
}
Fee
export type Fee = number | StdFee | "auto"
getQuery
Provides a message object for the registry's GetValue
query.
getQuery(key: string) {
return {
andr_query: {
get: encode(key),
},
};
}
get
Gets the value for a given key from the registry.
async get<T = any>(key: string) {
this.preMessage();
const msg = this.getQuery(key);
const resp = await this.client.queryContract<{
key: string;
value: Record<PrimitiveValueType, any>;
}>(this.address, msg);
if (!resp.value) throw new Error("Could not query key");
const valueKey: PrimitiveValueType = Object.keys(
resp.value
)[0] as PrimitiveValueType;
const value: T = resp.value[valueKey];
return value;
}
getAddress
Simple wrapper for getting the address for a given key from the registry.
async getAddress(key: string) {
return this.get<string>(key);
}
setAddress
Simple wrpaper for setting the address for a given key within the registry.
async setAddress(
value: PrimitiveValue,
fee: Fee,
key?: string,
memo?: string,
) {
return this.set(value, fee, key, memo, funds);
}