VirtualFileSystemAPI
Class
Class to interact with the VFS aOS contract.
export default class VirtualFileSystemAPI extends ADOAPI {
constructor(public client: AndromedaClient, public address: string) {
super(client, address);
}
resolvePathMsg
Generates a 'ResolvePath' query message for the VFS.
resolvePathMsg(path: string) {
return {
resolve_path: {
path,
},
};
}
path
string
The path to resolve.
resolvePath
Resolves the specified path to its corresponding address.
async resolvePath(path: string) {
this.preMessage();
if (!path || path.length === 0)
throw new Error("Cannot resolve an empty path using the VFS");
return this.client.queryContract(this.address, this.resolvePathMsg(path));
}
path
string
The path to resolve.
registerUserMsg
Generates a 'RegisterUser' message for the VFS.
registerUserMsg(username: string) {
return {
register_user: {
username,
},
};
}
username
string
The username to register.
registerUser
Registers a username for the currently used signing address.
async registerUser(
username: string,
msgParams?: OptionalExecuteParams
) {
this.preMessage();
if (!username || username.length === 0)
throw new Error("Cannot register an empty username");
return this.client.execute(
this.address,
this.registerUserMsg(username),
msgParams?.fee,
msgParams?.memo,
msgParams?.funds
);
}
username
string
The username to register.
msgParams
Optional parameters to add to the execute message such as funds, memo or fee.
OptionalExecuteParams
export interface OptionalExecuteParams {
funds?: readonly Coin[] | Coin[];
memo?: string;
fee?: StdFee;
}
addPathMsg
Generates a 'AddPath' message for the VFS.
addPathMsg(name: string, address: string) {
return {
add_path: {
name,
address,
},
};
}
name
string
The name of the path to register the address to.
address
string
The address to register the path to.
addPath
Registers a path for the currently used signing address.
async addPath(
name: string,
address: string,
msgParams?: OptionalExecuteParams
) {
this.preMessage();
if (!name || name.length === 0)
throw new Error("Cannot register an empty path");
if (!address || address.length === 0 || !validateAddress(address))
throw new Error(
"Cannot register an invalid address for a path within the VFS"
);
return this.client.execute(
this.address,
this.addPathMsg(name, address),
msgParams?.fee,
msgParams?.memo,
msgParams?.funds
);
}
name
string
The name of the path to register the address to.
address
string
The address to register the path to.
msgParams
Optional parameters to add to the execute message such as funds, memo or fee.
getUsernameMsg
Generates a 'GetUsername' query message for the VFS.
getUsernameMsg(address: string) {
return {
get_username: {
address,
},
};
}
address
string
The address to get the username for.
getUsername
Resolves the username for the given address
async getUsername(address: string) {
this.preMessage();
return this.client.queryContract(this.address, this.getUsernameMsg(address));
}
address
string
The address to get the username for.
subDirMsg
Generates a 'SubDir' query message for the VFS.
subDirMsg(path: string) {
return {
sub_dir: {
path,
},
};
}
path
string
The path to get sub paths for.
subDir
Resolves the sub dir for a given path.
async subDir(path: string) {
this.preMessage();
if (!path || path.length === 0)
throw new Error("Cannot resolve an empty path using the VFS");
return this.client.queryContract(this.address, this.subDirMsg(path));
}
path
string
The path to get sub paths for.
pathsMsg
Generates a 'paths' query message for the VFS.
pathsMsg(addr: string) {
return {
paths: {
addr,
},
};
}
addr
string
The addr to get the paths for.
paths
Resolves the paths for a given address
async paths(addr: string) {
this.preMessage();
if (
!addr ||
addr.length === 0 ||
!validateAddress(addr)
)
throw new Error(
"Cannot resolve an invalid address using the VFS"
);
return this.client.queryContract<string[]>(this.address, this.pathsMsg(addr));
}
}
addr
string
The addr to get the paths for.
Last updated