Skip to content

Commit

Permalink
remove hex check & add null check to htx
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Aug 14, 2023
1 parent 50725a8 commit 78d6441
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/contracts/errors/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const KeyExistsError = new ContractError('Key already exists.');
export const KeyNotExistsError = new ContractError('Key does not exist.');
export const KeyNotHexadecimalError = new ContractError('Key expected to be hexadecimal.');
export const CantEvolveError = new ContractError('Evolving is disabled.');
export const NoVerificationKeyError = new ContractError('No verification key.');
export const UnknownProtocolError = new ContractError('Unknown protocol.');
Expand Down
11 changes: 6 additions & 5 deletions src/contracts/functions/htx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ContractState} from '../types';
import {KeyExistsError, KeyNotHexadecimalError} from '../errors';
import {KeyExistsError, NullValueError} from '../errors';
import {assertWhitelist, safeGet, verifyAuthProofImmediate} from '../utils';
import {HTXValueType, PutHTXInput, RemoveHTXInput, UpdateHTXInput} from '../types/htx';

Expand All @@ -10,11 +10,9 @@ export async function putHTX<State extends ContractState<{whitelists: ['put']; c
) {
assertWhitelist(state, caller, 'put');

// check hexadecimal
if (!/^0x[\da-f]+$/i.test(key)) {
throw KeyNotHexadecimalError;
if (value === null) {
throw NullValueError;
}

if ((await SmartWeave.kv.get(key)) !== null) {
throw KeyExistsError;
}
Expand Down Expand Up @@ -47,6 +45,9 @@ export async function updateHTX<State extends ContractState<{whitelists: ['updat
) {
assertWhitelist(state, caller, 'update');

if (value === null) {
throw NullValueError;
}
const dbValue = await safeGet<string>(key);
const [oldHash] = dbValue.split('.');
const [newHash] = value.split('.');
Expand Down

0 comments on commit 78d6441

Please sign in to comment.