update sequence tracker deserialization to account for bump and emitter type (#3578)

This commit is contained in:
Ben Guidarelli 2023-12-06 15:27:55 -05:00 committed by GitHub
parent dee0d1532b
commit 47f3e5e6fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 4 deletions

View File

@ -32,16 +32,29 @@ export async function getSequenceTracker(
export class SequenceTracker { export class SequenceTracker {
sequence: bigint; sequence: bigint;
bump?: number;
emitterType?: number;
constructor(sequence: bigint) { constructor(sequence: bigint, bump?: number, emitterType?: number) {
this.sequence = sequence; this.sequence = sequence;
this.bump = bump;
this.emitterType = emitterType;
} }
static deserialize(data: Buffer): SequenceTracker { static deserialize(data: Buffer): SequenceTracker {
if (data.length != 8) { if (data.length !== 8 && data.length !== 10) {
throw new Error("data.length != 8"); throw new Error("data.length != 8 or data.length != 10");
} }
return new SequenceTracker(data.readBigUInt64LE(0));
let bump, emitterType;
const sequence = data.readBigUInt64LE(0);
if (data.length === 10) {
bump = data[8];
emitterType = data[9];
}
return new SequenceTracker(sequence, bump, emitterType);
} }
value(): bigint { value(): bigint {