Skip to content

Commit

Permalink
sdk/js: Refactor WrappedMeta class constructor to include
Browse files Browse the repository at this point in the history
lastUpdatedSequence
  • Loading branch information
kev1n-peters authored and evan-gray committed Dec 4, 2023
1 parent 62e7801 commit 390e86e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
12 changes: 12 additions & 0 deletions sdk/js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 0.10.6

### Added

Celestia support

Scroll testnet support

### Changes

Solana WrappedMeta deserialization fix

## 0.10.5

### Changes
Expand Down
22 changes: 18 additions & 4 deletions sdk/js/src/solana/tokenBridge/accounts/wrapped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,34 @@ export class WrappedMeta {
chain: number;
tokenAddress: Buffer;
originalDecimals: number;
lastUpdatedSequence?: bigint;

constructor(chain: number, tokenAddress: Buffer, originalDecimals: number) {
constructor(
chain: number,
tokenAddress: Buffer,
originalDecimals: number,
lastUpdatedSequence?: bigint
) {
this.chain = chain;
this.tokenAddress = tokenAddress;
this.originalDecimals = originalDecimals;
this.lastUpdatedSequence = lastUpdatedSequence;
}

static deserialize(data: Buffer): WrappedMeta {
if (data.length != 35) {
throw new Error("data.length != 35");
if (data.length !== 35 && data.length !== 43) {
throw new Error(`invalid wrapped meta length: ${data.length}`);
}
const chain = data.readUInt16LE(0);
const tokenAddress = data.subarray(2, 34);
const originalDecimals = data.readUInt8(34);
return new WrappedMeta(chain, tokenAddress, originalDecimals);
const lastUpdatedSequence =
data.length === 43 ? data.readBigUInt64LE(35) : undefined;
return new WrappedMeta(
chain,
tokenAddress,
originalDecimals,
lastUpdatedSequence
);
}
}

0 comments on commit 390e86e

Please sign in to comment.