Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const storageFn = (arg?: any): Uint8Array => {
let key = rawKey;
if (meta.type.isMap) {
assert(!isUndefined(arg) && !isNull(arg), `${meta.name} expects one argument`);
const type = meta.type.asMap.key.toString();
const param = createType(type, arg).toU8a(false);
key = u8aConcat(key, param);
}
// StorageKey is a Bytes, so is length-prefixed
return Compact.addLengthPrefix(
options.isUnhashed
? key
: xxhashAsU8a(key, 128)
);
};
export function createParam (hex: string | String, length = -1): StateParam {
let u8a;
try {
u8a = hexToU8a(hex.toString());
} catch (error) {
u8a = new Uint8Array([]);
}
const isValid = length !== -1
? u8a.length === length
: u8a.length !== 0;
return {
isValid,
u8a: Compact.addLengthPrefix(u8a)
};
}
const encoder = (...params: CodecArg[]): Uint8Array => {
assert(params.length === args.length, `Expected ${args.length} arguments to contract ${name}, found ${params.length}`);
const u8a = new Clazz(
this.registry,
args.reduce((mapped, { name }, index): Record => {
mapped[name] = params[index];
return mapped;
}, { ...baseStruct })
).toU8a();
return Compact.addLengthPrefix(u8a);
};
const _onChange = (hex: string): void => {
let [isValid, value] = convertInput(hex);
isValid = isValid && validate(value) && (
length !== -1
? value.length === length
: value.length !== 0
);
if (withLength && isValid) {
value = Compact.addLengthPrefix(value);
}
onChange && onChange({
isValid,
value: asHex
? u8aToHex(value)
: value
});
setIsValid(isValid);
};
const _onChangeKey = (key: string): void => {
const u8a = u8aToU8a(key);
const isValid = u8a.length !== 0;
setValue({
isValid,
key: Compact.addLengthPrefix(u8a)
});
};
const _onChangeFile = (value: Uint8Array): void => {
onChange && onChange({
isValid: value.length !== 0,
value: Compact.addLengthPrefix(value)
});
};
const _onChangeFile = (value: Uint8Array): void => {
onChange && onChange({
isValid: value.length !== 0,
value: Compact.addLengthPrefix(value)
});
};