StorageKey with specific encoding (#480)

* StorageKey with specific encoding

* Comment typo
This commit is contained in:
Jaco Greeff
2018-12-17 12:22:01 +01:00
committed by GitHub
parent 4a699275c5
commit 535a9eac07
5 changed files with 65 additions and 42 deletions
+8 -5
View File
@@ -121,14 +121,17 @@ export default class AccountIndex extends U32 {
/**
* @description Encodes the value as a Uint8Array as per the parity-codec specifications
* @param isBare true when the value has none of the type-specific prefixes (internal)
* @param isStorageKey true when encoded as part of a key, taking case of specific logic
*/
toU8a (isBare?: boolean): Uint8Array {
// HACK 15 Oct 2018 For isBare assume that we are dealing with an AccountIndex
toU8a (isBare?: boolean, isStorageKey?: boolean): Uint8Array {
// HACK 15 Oct 2018 For isStorageKey assume that we are dealing with an AccountIndex
// lookup (it is the only place where AccountIndex is used in such a manner to
// construct a query). This is needed to get enumSet(AccountIndex) queries to
// work in the way it was intended
return isBare
? bnToU8a(this.div(ENUMSET_SIZE), 32, true)
: super.toU8a();
if (isStorageKey) {
return bnToU8a(this.div(ENUMSET_SIZE), 32, true);
}
return super.toU8a(isBare);
}
}
+2 -1
View File
@@ -44,8 +44,9 @@ export interface Codec {
/**
* @description Encodes the value as a Uint8Array as per the parity-codec specifications
* @param isBare true when the value has none of the type-specific prefixes (internal)
* @param isStorageKey true when encoded as part of a key, taking case of specific logic
*/
toU8a (isBare?: boolean): Uint8Array;
toU8a (isBare?: boolean, isStorageKey?: boolean): Uint8Array;
}
export type CodecTo = 'toHex' | 'toJSON' | 'toString' | 'toU8a';