Skip to content

Commit

Permalink
Extract variable
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Sep 16, 2024
1 parent c113ff5 commit 490dbec
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
11 changes: 3 additions & 8 deletions src/smartcontracts/codec/managedDecimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,12 @@ export class ManagedDecimalCodec {

encodeNested(value: ManagedDecimalValue): Buffer {
let buffers: Buffer[] = [];
const rawValue = new BigUIntValue(value.valueOf().shiftedBy(value.getScale()));
if (value.isVariable()) {
buffers.push(
Buffer.from(
this.binaryCodec.encodeNested(new BigUIntValue(value.valueOf().shiftedBy(value.getScale()))),
),
);
buffers.push(Buffer.from(this.binaryCodec.encodeNested(rawValue)));
buffers.push(Buffer.from(this.binaryCodec.encodeNested(new U32Value(value.getScale()))));
} else {
buffers.push(
this.binaryCodec.encodeTopLevel(new BigUIntValue(value.valueOf().shiftedBy(value.getScale()))),
);
buffers.push(this.binaryCodec.encodeTopLevel(rawValue));
}
return Buffer.concat(buffers);
}
Expand Down
15 changes: 3 additions & 12 deletions src/smartcontracts/codec/managedDecimalSigned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,12 @@ export class ManagedDecimalSignedCodec {

encodeNested(value: ManagedDecimalSignedValue): Buffer {
let buffers: Buffer[] = [];
const rawValue = new BigIntValue(value.valueOf().shiftedBy(value.getScale()));
if (value.isVariable()) {
buffers.push(
Buffer.from(
this.binaryCodec.encodeNested(
new BigIntValue(new BigNumber(value.valueOf().shiftedBy(value.getScale()))),
),
),
);
buffers.push(Buffer.from(this.binaryCodec.encodeNested(rawValue)));
buffers.push(Buffer.from(this.binaryCodec.encodeNested(new U32Value(value.getScale()))));
} else {
buffers.push(
Buffer.from(
this.binaryCodec.encodeTopLevel(new BigIntValue(value.valueOf().shiftedBy(value.getScale()))),
),
);
buffers.push(Buffer.from(this.binaryCodec.encodeTopLevel(rawValue)));
}
return Buffer.concat(buffers);
}
Expand Down
2 changes: 1 addition & 1 deletion src/smartcontracts/interaction.local.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe("test smart contract interactor", function () {
.withSender(alice.address)
.withValue(0);

// addition();
// addition()
let additionTransaction = additionInteraction
.withSender(alice.address)
.useThenIncrementNonceOf(alice.account)
Expand Down

0 comments on commit 490dbec

Please sign in to comment.