Allow hex or number[] -> u8a conversion for 'bytes' (#155)

This commit is contained in:
Jaco Greeff
2018-06-28 17:15:09 +02:00
committed by GitHub
parent d5f4f1dea1
commit 544034bf2e
5 changed files with 14 additions and 6 deletions
+1 -1
View File
@@ -17,6 +17,6 @@
},
"devDependencies": {
"@polkadot/dev": "^0.20.8",
"@polkadot/ts": "^0.1.5"
"@polkadot/ts": "^0.1.6"
}
}
@@ -10,4 +10,10 @@ describe('bytesDecode', () => {
bytesDecode('0x0012345600')
).toEqual(new Uint8Array([0x00, 0x12, 0x34, 0x56, 0x00]));
});
it('decodes byte array (number', () => {
expect(
bytesDecode([0x00, 0x12, 0x34, 0x56, 0x00])
).toEqual(new Uint8Array([0x00, 0x12, 0x34, 0x56, 0x00]));
});
});
@@ -8,5 +8,7 @@ import { JsonBytes } from '../types';
import hexToU8a from '@polkadot/util/hex/toU8a';
export default function bytesDecode (value: JsonBytes): Bytes {
return hexToU8a(value);
return Array.isArray(value)
? new Uint8Array(value)
: hexToU8a(value);
}
+1 -1
View File
@@ -5,7 +5,7 @@
export type JsonBnType = string;
export type JsonHash = string;
export type JsonBytes = string;
export type JsonBytes = string | Array<number>;
export type JsonH160 = JsonHash;
export type JsonH256 = JsonHash;
export type JsonH512 = JsonHash;
+3 -3
View File
@@ -736,9 +736,9 @@
tslint-config-semistandard "^7.0.0"
typescript "^2.9.2"
"@polkadot/ts@^0.1.5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.5.tgz#bd944090a788d9379866059fb61b5708b4696cc7"
"@polkadot/ts@^0.1.6":
version "0.1.6"
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.6.tgz#0138490e0e625ea34a9931be94fd436dd6015c7d"
"@types/async@^2.0.49":
version "2.0.49"