Skip to content

Commit 30e8170

Browse files
Resolve comments
1 parent fdfc2eb commit 30e8170

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

assembly/Bool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class Bool implements Codec {
6363

6464
/** Instantiates new Bool from u8[] SCALE encoded bytes */
6565
static fromU8a (value: u8[], index: i32 = 0): Bool {
66-
assert(value.length > 0 && (value[index] == 1 || value[index] == 0), 'Bool: Cannot decode invalid input');
66+
assert(value.length - index > 0 && (value[index] == 1 || value[index] == 0), 'Bool: Cannot decode invalid input');
6767

6868
return new Bool(value[index] == 1);
6969
}

assembly/ScaleString.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export class ScaleString extends ByteArray {
6969
assert(bytes.length - index - len.decBytes >= 1, "ScaleString: Incorrectly encoded input");
7070
const buff = new Uint8Array(bytesLength);
7171
Bytes.copyToTyped(bytes, buff, 0, index+stringStart);
72-
// constructor
7372
return String.UTF8.decode(buff.buffer);
7473
}
7574
/**

assembly/UInt/UInt128.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class UInt128 implements Codec {
6464
*/
6565
populateFromBytes(bytes: u8[], index: i32 = 0): void{
6666
assert(bytes.length - index > 0, 'Invalid input: Byte array should not be empty');
67-
const value = UInt128._computeValue(bytes.slice(index));
67+
const value = UInt128._computeValue(bytes, index);
6868
this._value = value;
6969
this.bitLength = UInt128._computeBitLength(this._value);
7070
}
@@ -80,15 +80,15 @@ export class UInt128 implements Codec {
8080
* @param bytes
8181
* @param index
8282
*/
83-
static _computeValue(bytes: u8[]): u128{
84-
const mode = bytes[0] & 0x03;
83+
static _computeValue(bytes: u8[], index: i32 = 0): u128{
84+
const mode = bytes[index] & 0x03;
8585
if (i32(mode) <= 2) {
86-
return new u128(u64(Bytes.decodeSmallInt(bytes, mode, 0).value), 0);
86+
return new u128(u64(Bytes.decodeSmallInt(bytes, mode, index).value), 0);
8787
}
88-
const topSixBits = bytes[0] >> 2;
88+
const topSixBits = bytes[index] >> 2;
8989
const byteLength = topSixBits + 4;
9090

91-
const value = bytes.slice(1, byteLength + 1);
91+
const value = bytes.slice(index + 1, byteLength + index + 1);
9292
Bytes.appendZeroBytes(value, BIT_LENGTH.INT_128);
9393
return u128.fromBytesLE(value)
9494
}
@@ -111,7 +111,7 @@ export class UInt128 implements Codec {
111111
/** Instantiates new UInt128 from u8[] SCALE encoded bytes */
112112
static fromU8a(input: u8[], index: i32 = 0): UInt128 {
113113
assert(input.length - index != 0, 'Invalid input: Byte array should not be empty');
114-
return new UInt128(UInt128._computeValue(input.slice(index)));
114+
return new UInt128(UInt128._computeValue(input, index));
115115
}
116116

117117
@inline @operator('==')

0 commit comments

Comments
 (0)