Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const type = key.outputType || 'Raw';
const meta = key.meta || EMPTY_META;
const isEmpty = isNull(value);
// we convert to Uint8Array since it maps to the raw encoding, all
// data will be correctly encoded (incl. numbers, excl. :code)
const input = isEmpty
? null
: this.treatAsHex(key)
? value
: u8aToU8a(value);
if (meta.modifier.isOptional) {
return new Option(
this.registry,
createClass(this.registry, type),
isEmpty
? null
: createTypeUnsafe(this.registry, type, [input], true)
);
}
return createTypeUnsafe(this.registry, type, [isEmpty ? meta.fallback : input], true);
}
const isEmpty = isNull(value);
const input = isEmpty
? null
: this.treatAsHex(key)
? value
: u8aToU8a(value);
// store the retrieved result - the only issue with this cache is that there is no
// clearing of it, so very long running processes (not just a couple of hours, longer)
// will increase memory beyond what is allowed.
this._storageCache.set(hexKey, value);
if (meta.modifier.isOptional) {
return new Option(
this.registry,
createClass(this.registry, type),
isEmpty
? null
: createTypeUnsafe(this.registry, type, [input], true)
);
}
return createTypeUnsafe(this.registry, type, [isEmpty ? meta.fallback : input], true);
}
}
export function formatData (registry: Registry, data: Raw, { info, type }: TypeDef): Codec {
if (info === TypeDefInfo.Option) {
return new Option(
registry,
createClass(registry, type),
createTypeUnsafe(registry, type, [data], true)
);
}
return createTypeUnsafe(registry, type, [data], true);
}
function createArgClass (registry: Registry, args: ContractABIFnArg[], baseDef: Record): Constructor {
return createClass(
registry,
JSON.stringify(
args.reduce((base: Record, { name, type }): Record => {
base[name] = type.displayName || encodeType(type);
return base;
}, baseDef)
)
);
}
export function createArgClass (args: ContractABIFnArg[], baseDef: Record): Constructor {
return createClass(
JSON.stringify(
args.reduce((base: Record, { name, type }): Record => {
base[name] = encodeType(type);
return base;
}, baseDef)
)
);
}