Skip to content
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
16 changes: 11 additions & 5 deletions src/core/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ export const uint128 = (property: string): Layout<bigint> => {
return uint128Layout;
};

export const stringLayout = (property: string, maxLength: number = 32): Layout<string> => {
const layout = blob(maxLength, property);
export const stringLayout = (property: string): Layout<string> => {
const layout = blob(4, property);
const stringLayout = layout as Layout<unknown> as Layout<string>;
const decode = layout.decode.bind(layout);

stringLayout.decode = (buffer: Buffer, offset: number) => {
const src = decode(buffer, offset);
return Buffer.from(src).toString('utf-8', 4).trim();
const length = buffer.readUInt32LE(offset);
return buffer.slice(offset + 4, offset + 4 + length).toString('utf-8');
};

stringLayout.getSpan = (buffer: Buffer, offset: number) => {
const length = buffer.readUInt32LE(offset);
return 4 + length;
};

return stringLayout;
};

Expand Down
6 changes: 3 additions & 3 deletions src/parser/pumpfun/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { CreateEvent, TradeEvent, CompleteEvent } from './types';
import { stringLayout, pubKey, uint64, boolean } from '../../core/layout';

export const CREATE_EVENT_LAYOUT = struct<CreateEvent>([
stringLayout('name', 20),
stringLayout('symbol', 9),
stringLayout('uri', 71),
stringLayout('name'),
stringLayout('symbol'),
stringLayout('uri'),
pubKey('mint'),
pubKey('bondingCurve'),
pubKey('user'),
Expand Down