secret-polar-reworks
Version:
Polar is a development environment to compile, deploy, test, run scrt contracts on different networks.
26 lines (24 loc) • 754 B
text/typescript
// Parses the response from contract query, init, deploy or execute
// and returns logs as a {key: value} object
export function getLogs (
response: any // eslint-disable-line @typescript-eslint/no-explicit-any
): Record<string, string|string[]> {
const logs: Record<string, string|string[]> = {};
for (const log of response.logs[0].events[1].attributes) {
if (log.key in logs) {
const presentVal = logs[log.key];
let newVal: string[] = [];
if (Array.isArray(presentVal)) {
newVal = presentVal;
newVal.push(log.value);
} else {
newVal.push(presentVal);
newVal.push(log.val);
}
logs[log.key] = newVal;
} else {
logs[log.key] = log.value;
}
}
return logs;
}