Skip to content

Commit

Permalink
fix(encode-integer): Add support for larger numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
gulcinuras committed Jul 15, 2024
1 parent 8100b9c commit 279e508
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/util/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export declare function sendAndWaitRawTransaction(client: Algodv2, signedTxnGrou
}[]>;
export declare function sumUpTxnFees(txns: SignerTransaction[]): number;
export declare function getTxnGroupID(txns: SignerTransaction[]): string;
export declare function encodeInteger(number: any): number[];
export declare function encodeInteger(number: bigint): number[];
/**
* Converts a text into bytes
*/
Expand Down
2 changes: 1 addition & 1 deletion src/contract/v1_1/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class TinymanContractV1_1 extends BaseTinymanContract<V1_1ValidatorApp> {
let start = v.index - offset;
let end = start + v.length;
// All of the template variables are ints
let value_encoded = encodeInteger(value);
let value_encoded = encodeInteger(BigInt(value));
let diff = v.length - value_encoded.length;

offset += diff;
Expand Down
6 changes: 3 additions & 3 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,16 @@ export function getTxnGroupID(txns: SignerTransaction[]) {
return bufferToBase64(txns[0].txn.group);
}

export function encodeInteger(number) {
export function encodeInteger(number: bigint) {
let buf: number[] = [];

/* eslint-disable no-bitwise */
/* eslint-disable no-constant-condition */
/* eslint-disable no-param-reassign */
while (true) {
let towrite = number & 0x7f;
let towrite = Number(number & BigInt(0x7f));

number >>= 7;
number >>= BigInt(7);

if (number) {
buf.push(towrite | 0x80);
Expand Down

0 comments on commit 279e508

Please sign in to comment.