@effectai/sdk
Version:
Effect Network Javscript/Typescript SDK (for [https://effect.network](https://effect.network))
61 lines • 2.05 kB
JavaScript
import { UInt32, UInt64 } from "@wharfkit/antelope";
import { createCompositeU64Key } from "../../../utils/keys";
import { useEFXContracts } from "../../../utils/state";
export const getReservations = async ({ client, lowerBound, upperBound, indexPosition = "secondary", }) => {
const { tasks } = useEFXContracts(client);
const response = (await client.provider.v1.chain.get_table_rows({
scope: tasks,
code: tasks,
table: "reservation",
index_position: indexPosition,
upper_bound: upperBound,
lower_bound: lowerBound,
}));
const { rows } = response;
return rows;
};
export const getReservationsForCampaign = async ({ client, campaignId, }) => {
try {
const lowerBound = createCompositeU64Key(campaignId, 0);
const upperBound = createCompositeU64Key(campaignId, Number(UInt32.max));
return await getReservations({ client, lowerBound, upperBound });
}
catch (e) {
console.error(e);
throw e;
}
};
export const getReservationsForVAccount = async ({ client, vAccountId, }) => {
try {
if (!vAccountId)
throw new Error("vAccountId is required");
return await getReservations({
client,
lowerBound: UInt64.from(vAccountId),
upperBound: UInt64.from(vAccountId),
indexPosition: "fourth",
});
}
catch (e) {
console.error(e);
throw e;
}
};
// TODO: This function name is unclear, we should rename it to: getVAccountReservationForCampaign
export const getReservationForCampaign = async ({ client, campaignId, vAccountId, }) => {
try {
const bound = createCompositeU64Key(campaignId, vAccountId);
const data = await getReservations({
client,
lowerBound: bound,
upperBound: bound,
});
const [reservation] = data;
return reservation;
}
catch (e) {
console.error(e);
throw e;
}
};
//# sourceMappingURL=getReservations.js.map