Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Incede committed May 10, 2023
1 parent 11fdb90 commit 8b9ea09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
21 changes: 14 additions & 7 deletions framework/src/modules/random/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import { validator } from '@liskhq/lisk-validator';
import * as cryptography from '@liskhq/lisk-cryptography';
import { NotFoundError } from '@liskhq/lisk-db';
import { ModuleEndpointContext } from '../../types';
import { BaseEndpoint } from '../base_endpoint';
import { ADDRESS_LENGTH, EMPTY_KEY } from './constants';
Expand All @@ -33,7 +34,7 @@ import {
import { ValidatorRevealsStore } from './stores/validator_reveals';
import { getSeedRevealValidity } from './utils';
import { HashOnionStore } from './stores/hash_onion';
import { UsedHashOnionsStore } from './stores/used_hash_onions';
import { UsedHashOnionStoreObject, UsedHashOnionsStore } from './stores/used_hash_onions';

export class RandomEndpoint extends BaseEndpoint {
public async isSeedRevealValid(ctx: ModuleEndpointContext): Promise<{ valid: boolean }> {
Expand Down Expand Up @@ -141,12 +142,18 @@ export class RandomEndpoint extends BaseEndpoint {
const seed = hashOnion.hashes[hashOnion.hashes.length - 1].toString('hex');

const usedHashOnionStore = this.offchainStores.get(UsedHashOnionsStore);
const usedHashOnion = await usedHashOnionStore.get(ctx, address);
if (!usedHashOnion) {
return {
usedHashOnions: [{ count: 0, height: 0 }],
seed,
};

let usedHashOnion: UsedHashOnionStoreObject;
try {
usedHashOnion = await usedHashOnionStore.get(ctx, address);
} catch (error) {
if (error instanceof NotFoundError) {
return {
usedHashOnions: [{ count: 0, height: 0 }],
seed,
};
}
throw error;
}

return { usedHashOnions: usedHashOnion.usedHashOnions, seed };
Expand Down
20 changes: 8 additions & 12 deletions framework/src/modules/random/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,24 @@ export const getHashOnionUsageResponse = {
properties: {
usedHashOnions: {
type: 'array',
fieldNumber: 1,
items: {
type: 'object',
required: ['count', 'height'],
properties: {
count: {
dataType: 'uint32',
fieldNumber: 1,
type: 'integer',
format: 'uint32',
},
height: {
dataType: 'uint32',
fieldNumber: 2,
type: 'integer',
format: 'uint32',
},
},
},
},
seed: {
type: 'string',
format: 'hex',
fieldNumber: 2,
},
},
};
Expand All @@ -144,23 +142,21 @@ export const setHashOnionUsageRequest = {
address: {
type: 'string',
format: 'lisk32',
fieldNumber: 1,
},
usedHashOnions: {
type: 'array',
fieldNumber: 2,
items: {
type: 'object',
required: ['count', 'height'],
properties: {
count: {
dataType: 'uint32',
fieldNumber: 1,
type: 'integer',
format: 'uint32',
minimum: 1,
},
height: {
dataType: 'uint32',
fieldNumber: 2,
type: 'integer',
format: 'uint32',
},
},
},
Expand Down

0 comments on commit 8b9ea09

Please sign in to comment.