Skip to content

Commit 4415bec

Browse files
authored
feat: add support for backfilling lend storage messages (#2655)
## Why is this change needed? Add support for backfilling lend storage messages from snapchain to clients. ## Merge Checklist _Choose all relevant options below by adding an `x` now or at any time before submitting for review_ - [x] PR title adheres to the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) standard - [x] PR has a [changeset](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#35-adding-changesets) - [x] PR has been tagged with a change label(s) (i.e. documentation, feature, bugfix, or chore) - [ ] PR includes [documentation](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#32-writing-docs) if necessary. <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on updating the `@farcaster/shuttle` package to version `0.9.5`, adding support for backfilling lend storage messages, and introducing new methods related to lend storage message retrieval. ### Detailed summary - Updated version in `package.json` files to `0.9.5`. - Added support for backfilling lend storage messages in `CHANGELOG.md`. - Introduced `getAllLendStorageMessagesByFid` method in `shuttle.integration.test.ts`. - Included `LEND_STORAGE` message type in message reconciliation logic in `messageReconciliation.ts`. - Created `getAllLendStorageMessagesByFidInBatchesOf` for batch processing of lend storage messages. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent e48efa3 commit 4415bec

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

packages/shuttle/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @farcaster/hub-shuttle
22

3+
## 0.9.5
4+
5+
### Patch Changes
6+
7+
- 872c2c78: feat: add support for backfilling lend storage messages
8+
39
## 0.9.4
410

511
### Patch Changes

packages/shuttle/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@farcaster/shuttle",
3-
"version": "0.9.4",
3+
"version": "0.9.5",
44
"main": "./dist/index.js",
55
"module": "./dist/index.mjs",
66
"types": "./dist/index.d.ts",

packages/shuttle/src/example-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"main": "./app.ts",
55
"license": "MIT",
66
"dependencies": {
7-
"@farcaster/shuttle": "^0.9.3",
7+
"@farcaster/shuttle": "^0.9.5",
88
"@figma/hot-shots": "^9.0.0-figma.1",
99
"commander": "^11.0.0",
1010
"ioredis": "^5.3.2",

packages/shuttle/src/shuttle.integration.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,18 @@ describe("shuttle", () => {
621621
}),
622622
);
623623
},
624+
getAllLendStorageMessagesByFid: async (
625+
_request: FidRequest,
626+
_metadata: Metadata,
627+
_options: Partial<CallOptions>,
628+
) => {
629+
return ok(
630+
MessagesResponse.create({
631+
messages: [],
632+
nextPageToken: undefined,
633+
}),
634+
);
635+
},
624636
};
625637

626638
// Only include 2 of the 3 messages in the time window

packages/shuttle/src/shuttle/messageReconciliation.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ export class MessageReconciliation {
4747
startTimestamp?: number,
4848
stopTimestamp?: number,
4949
) {
50-
// Don't reconcile storage lends
5150
for (const type of [
5251
MessageType.CAST_ADD,
5352
MessageType.REACTION_ADD,
5453
MessageType.LINK_ADD,
5554
MessageType.VERIFICATION_ADD_ETH_ADDRESS,
5655
MessageType.USER_DATA_ADD,
56+
MessageType.LEND_STORAGE,
5757
]) {
5858
this.log.debug(`Reconciling messages for FID ${fid} of type ${type}`);
5959
await this.reconcileMessagesOfTypeForFid(fid, type, onHubMessage, onDbMessage, startTimestamp, stopTimestamp);
@@ -149,6 +149,9 @@ export class MessageReconciliation {
149149
case MessageType.USER_DATA_ADD:
150150
fn = this.getAllUserDataMessagesByFidInBatchesOf;
151151
break;
152+
case MessageType.LEND_STORAGE:
153+
fn = this.getAllLendStorageMessagesByFidInBatchesOf;
154+
break;
152155
default:
153156
throw `Unknown message type ${type}`;
154157
}
@@ -177,6 +180,10 @@ export class MessageReconciliation {
177180
return await this.client.getAllUserDataMessagesByFid(request);
178181
}
179182

183+
private async getAllLendStorageMessagesByFid(request: FidTimestampRequest) {
184+
return await this.client.getAllLendStorageMessagesByFid(request);
185+
}
186+
180187
private async *getAllCastMessagesByFidInBatchesOf(
181188
fid: number,
182189
pageSize: number,
@@ -314,6 +321,33 @@ export class MessageReconciliation {
314321
}
315322
}
316323

324+
private async *getAllLendStorageMessagesByFidInBatchesOf(
325+
fid: number,
326+
pageSize: number,
327+
startTimestamp?: number,
328+
stopTimestamp?: number,
329+
) {
330+
let result = await this.getAllLendStorageMessagesByFid({ pageSize, fid, startTimestamp, stopTimestamp });
331+
for (;;) {
332+
if (result.isErr()) {
333+
throw new Error(`Unable to get all lend storage messages for FID ${fid}: ${result.error?.message}`);
334+
}
335+
336+
const { messages, nextPageToken: pageToken } = result.value;
337+
338+
yield messages;
339+
340+
if (!pageToken?.length) break;
341+
result = await this.getAllLendStorageMessagesByFid({
342+
pageSize,
343+
pageToken,
344+
fid,
345+
startTimestamp,
346+
stopTimestamp,
347+
});
348+
}
349+
}
350+
317351
private async allActiveDbMessagesOfTypeForFid(
318352
fid: number,
319353
type: MessageType,

0 commit comments

Comments
 (0)