-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdrand_contract.ts
51 lines (47 loc) · 1.45 KB
/
drand_contract.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { MsgExecuteContract } from "npm:cosmjs-types/cosmwasm/wasm/v1/tx.js";
import { assert, CosmWasmClient, MsgExecuteContractEncodeObject, toUtf8 } from "./deps.ts";
export function makeAddBeaconMessage(
senderAddress: string,
drandAddress: string,
beacon: { round: number; signature: string },
): MsgExecuteContractEncodeObject {
return {
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
value: MsgExecuteContract.fromPartial({
sender: senderAddress,
contract: drandAddress,
msg: toUtf8(JSON.stringify({
add_round: {
round: beacon.round,
signature: beacon.signature,
},
})),
funds: [],
}),
};
}
export async function queryIsAllowlisted(
client: CosmWasmClient,
drandAddress: string,
botAddress: string,
): Promise<boolean> {
const { listed } = await client.queryContractSmart(drandAddress, {
is_allowlisted: { bot: botAddress },
});
return listed;
}
export async function queryIsIncentivized(
client: CosmWasmClient,
drandAddress: string,
round: number,
botAddress: string,
): Promise<boolean> {
const { incentivized } = await client.queryContractSmart(drandAddress, {
is_incentivized: { rounds: [round], sender: botAddress },
});
// console.log(`#${rounds[0]} incentivized query returned at ${publishedSince(rounds[0])}ms`)
assert(Array.isArray(incentivized));
const first = incentivized[0];
assert(typeof first === "boolean");
return first;
}