Skip to content

Commit

Permalink
Add encoded nested for managed decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Sep 5, 2024
1 parent ab476cf commit 9dceb18
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/smartcontracts/codec/managedDecimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ export class ManagedDecimalCodec {
}

decodeNested(buffer: Buffer, type: ManagedDecimalType): [ManagedDecimalValue, number] {
let [bytesValue, length] = this.binaryCodec.decodeNested(buffer, type);
return [new ManagedDecimalValue(new BigNumber(1), 1), length];
let offset = 0;
let length = buffer.readUInt32BE(0);

let payload = buffer.slice(offset, offset + length);
let result = this.decodeTopLevel(payload, type);
let decodedLength = length + offset;
return [result, decodedLength];
}

decodeTopLevel(buffer: Buffer, type: ManagedDecimalType): ManagedDecimalValue {
Expand All @@ -26,7 +31,6 @@ export class ManagedDecimalCodec {
const u32Size = 4;
const bigUintSize = buffer.length - u32Size;

// Read BigUInt (dynamic size)
const bigUintBuffer = buffer.slice(0, bigUintSize);
const bigUint = new BigNumber(bigUintBuffer.toString("hex"), 16);

Expand All @@ -39,7 +43,6 @@ export class ManagedDecimalCodec {
}

encodeNested(value: ManagedDecimalValue): Buffer {
value.getType().getMetadata();
let buffers: Buffer[] = [];
if (value.getType().getMetadata() == "usize") {
buffers.push(Buffer.from(this.binaryCodec.encodeNested(new BigUIntValue(value.valueOf()))));
Expand Down

0 comments on commit 9dceb18

Please sign in to comment.