Skip to content

Commit

Permalink
SK-1698: future-proof (#1209)
Browse files Browse the repository at this point in the history
  • Loading branch information
arty-name committed Feb 24, 2023
1 parent 93c1bc4 commit a1e37dc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/backend/endpoints/liveness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { paths } from './paths';

export async function testLiveness() {
await initKilt();
reportBalance();
await reportBalance();

await canAccessTwitter();

Expand Down
11 changes: 0 additions & 11 deletions src/backend/utilities/cryptoCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ import {
import { keypairsPromise } from './keypairs';
import { fullDidPromise } from './fullDid';

export async function signWithAuthentication({ data }: { data: Uint8Array }) {
const { authentication } = await keypairsPromise;
const { fullDid } = await fullDidPromise;

return {
signature: authentication.sign(data, { withType: false }),
keyType: authentication.type,
keyUri: `${fullDid.uri}${fullDid.authentication[0].id}`,
};
}

export async function signWithAssertionMethod({ data }: { data: Uint8Array }) {
const { assertionMethod } = await keypairsPromise;
const { fullDid } = await fullDidPromise;
Expand Down
6 changes: 4 additions & 2 deletions src/backend/utilities/fullDid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import * as Did from '@kiltprotocol/did';
import { initKilt } from './initKilt';
import { keypairsPromise } from './keypairs';
import { configuration } from './configuration';
import { signWithAuthentication } from './cryptoCallbacks';
import { exitOnError } from './exitOnError';
import { logger } from './logger';

Expand All @@ -29,7 +28,10 @@ export async function createFullDid(): Promise<DidUri> {
keyAgreement: [keyAgreement],
},
identity.address,
signWithAuthentication,
async ({ data }) => ({
signature: authentication.sign(data, { withType: false }),
keyType: authentication.type,
}),
);

await Blockchain.signAndSubmitTx(extrinsic, identity);
Expand Down
16 changes: 10 additions & 6 deletions src/backend/utilities/reportBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,29 @@ This is an automatically generated email.`;
await sesClient.send(command);
}

export function reportBalance() {
setInterval(async () => {
export async function reportBalance() {
async function check() {
try {
const { identity } = await keypairsPromise;
const { address } = identity;
const api = ConfigService.get('api');
const balances = (await api.query.system.account(identity.address)).data;
const balances = (await api.query.system.account(address)).data;

const free = BalanceUtils.formatKiltBalance(balances.free);
const reserved = BalanceUtils.formatKiltBalance(balances.reserved);

logger.info(`Free: ${free}, bonded: ${reserved}`);
logger.info(`Free: ${free}, bonded: ${reserved}, address: ${address}`);

const { blockchainEndpoint } = configuration;

if (balances.free.lt(REPORT_THRESHOLD)) {
await sendLowBalanceAlert(free, blockchainEndpoint, identity.address);
await sendLowBalanceAlert(free, blockchainEndpoint, address);
}
} catch (error) {
logger.error(error, 'Error getting attester balance');
}
}, REPORT_FREQUENCY);
}

await check();
setInterval(check, REPORT_FREQUENCY);
}

0 comments on commit a1e37dc

Please sign in to comment.