Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uint 256 #1250

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions governance/xc_admin/packages/xc_admin_common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@solana/buffer-layout": "^4.0.1",
"@solana/web3.js": "^1.73.0",
"@sqds/mesh": "^1.0.6",
"bigint-buffer": "^1.1.5",
"ethers": "^5.7.2",
"lodash": "^4.17.21",
"typescript": "^4.9.4"
Expand All @@ -34,9 +35,9 @@
"@types/bn.js": "^5.1.1",
"@types/jest": "^29.2.5",
"@types/lodash": "^4.14.191",
"fast-check": "^3.10.0",
"jest": "^29.3.1",
"prettier": "^2.8.1",
"ts-jest": "^29.0.3",
"fast-check": "^3.10.0"
"ts-jest": "^29.0.3"
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import { Layout } from "@solana/buffer-layout";
import { toBigIntBE, toBufferBE } from "bigint-buffer";

export class UInt64BE extends Layout<bigint> {
export class UIntBE extends Layout<bigint> {
// span is the number of bytes to read
constructor(span: number, property?: string) {
super(span, property);
}

// Note: we can not use read/writeBigUInt64BE because it is not supported in the browsers
override decode(b: Uint8Array, offset?: number): bigint {
let o = offset ?? 0;
const buffer = Buffer.from(b.slice(o, o + this.span));
const hi32 = buffer.readUInt32BE();
const lo32 = buffer.readUInt32BE(4);
return BigInt(lo32) + (BigInt(hi32) << BigInt(32));
return toBigIntBE(buffer);
}

override encode(src: bigint, b: Uint8Array, offset?: number): number {
const buffer = Buffer.alloc(this.span);
const hi32 = Number(src >> BigInt(32));
const lo32 = Number(src & BigInt(0xffffffff));
buffer.writeUInt32BE(hi32, 0);
buffer.writeUInt32BE(lo32, 4);
const buffer = toBufferBE(src, this.span);
b.set(buffer, offset);
return this.span;
}
Expand All @@ -45,8 +40,13 @@ export class HexBytes extends Layout<string> {
}

/** A big-endian u64, returned as a bigint. */
export function u64be(property?: string | undefined): UInt64BE {
return new UInt64BE(8, property);
export function u64be(property?: string | undefined): UIntBE {
return new UIntBE(8, property);
}

/** A big-endian u256, returned as a bigint. */
export function u256be(property?: string | undefined): UIntBE {
return new UIntBE(32, property);
}

/** An array of numBytes bytes, returned as a hexadecimal string. */
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading