-
Notifications
You must be signed in to change notification settings - Fork 33
/
getVersion.ts
41 lines (37 loc) · 1.15 KB
/
getVersion.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
import { shortString } from "starknet-410";
import { NetworkId } from "./types";
import { getRpcBatchProviderForNetworkId } from "./getProvider";
export async function getVersion(addresses: string[], networkId: NetworkId) {
const multicall = getRpcBatchProviderForNetworkId(networkId);
const versionAnswers = await Promise.allSettled(
addresses.map(async (address) => {
const getVersion = await multicall.callContract({
contractAddress: address,
entrypoint: "getVersion",
});
if (getVersion !== undefined) {
return getVersion;
}
const get_version = await multicall.callContract({
contractAddress: address,
entrypoint: "get_version",
});
if (get_version !== undefined) {
return get_version;
}
throw new Error("Unable to get version on chain");
})
);
const versions = versionAnswers
.map((answer) => {
if (answer.status === "fulfilled" && answer.value !== undefined) {
return answer.value;
} else {
return null;
}
})
.flat();
return versions.map((hex) =>
hex ? shortString.decodeShortString(hex) : null
);
}