Skip to content

Commit

Permalink
add types to and rename numberToBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Aug 19, 2020
1 parent 4e18c23 commit b679f96
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions js/zksync.js/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export function serializeAccountId(accountId: number): Uint8Array {
if (accountId >= MAX_NUMBER_OF_ACCOUNTS) {
throw new Error("AccountId is too big");
}
return numberToBytes(accountId, 4);
return numberToBytesBE(accountId, 4);
}

export function serializeTokenId(tokenId: number): Uint8Array {
Expand All @@ -493,7 +493,7 @@ export function serializeTokenId(tokenId: number): Uint8Array {
if (tokenId >= MAX_NUMBER_OF_TOKENS) {
throw new Error("TokenId is too big");
}
return numberToBytes(tokenId, 2);
return numberToBytesBE(tokenId, 2);
}

export function serializeAmountPacked(amount: BigNumberish): Uint8Array {
Expand All @@ -513,10 +513,10 @@ export function serializeNonce(nonce: number): Uint8Array {
if (nonce < 0) {
throw new Error("Negative nonce");
}
return numberToBytes(nonce, 4);
return numberToBytesBE(nonce, 4);
}

function numberToBytes(number, bytes): Uint8Array {
function numberToBytesBE(number: number, bytes: number): Uint8Array {
const result = new Uint8Array(bytes);
for (let i = bytes - 1; i >= 0; i--) {
result[i] = number & 0xff;
Expand Down

0 comments on commit b679f96

Please sign in to comment.