diff --git a/.changeset/young-lobsters-peel.md b/.changeset/young-lobsters-peel.md new file mode 100644 index 0000000000..43c5e8add4 --- /dev/null +++ b/.changeset/young-lobsters-peel.md @@ -0,0 +1,8 @@ +--- +"@farcaster/hub-nodejs": minor +"@farcaster/hub-web": minor +"@farcaster/core": minor +"@farcaster/hubble": minor +--- + +Added storage limits RPC diff --git a/apps/hubble/src/eth/l2EventsProvider.test.ts b/apps/hubble/src/eth/l2EventsProvider.test.ts index 409bae3189..f3abd5d695 100644 --- a/apps/hubble/src/eth/l2EventsProvider.test.ts +++ b/apps/hubble/src/eth/l2EventsProvider.test.ts @@ -1,4 +1,4 @@ -import { FarcasterNetwork, OnChainEventType, StorageRegistryEventType } from "@farcaster/hub-nodejs"; +import { FarcasterNetwork, OnChainEventType } from "@farcaster/hub-nodejs"; import { StorageRegistry } from "./abis.js"; import { jestRocksDB } from "../storage/db/jestUtils.js"; import Engine from "../storage/engine/index.js"; diff --git a/apps/hubble/src/rpc/server.ts b/apps/hubble/src/rpc/server.ts index 2b5e899ac9..189fc414fb 100644 --- a/apps/hubble/src/rpc/server.ts +++ b/apps/hubble/src/rpc/server.ts @@ -2,6 +2,7 @@ import { CastAddMessage, CastId, CastRemoveMessage, + DbStats, FidsResponse, getServer, HubAsyncResult, @@ -26,15 +27,15 @@ import { SignerAddMessage, SignerRemoveMessage, status, + StorageLimitsResponse, SyncIds, - DbStats, + SyncStatus, + SyncStatusResponse, TrieNodeMetadataResponse, TrieNodeSnapshotResponse, UserDataAddMessage, VerificationAddEthAddressMessage, VerificationRemoveMessage, - SyncStatusResponse, - SyncStatus, UserNameProof, UsernameProofsResponse, OnChainEventResponse, @@ -982,6 +983,18 @@ export default class Server { }, ); }, + getCurrentStorageLimitsByFid: async (call, callback) => { + const request = call.request; + const storageLimitsResult = await this.engine?.getCurrentStorageLimitsByFid(request.fid); + storageLimitsResult?.match( + (storageLimits: StorageLimitsResponse) => { + callback(null, storageLimits); + }, + (err: HubError) => { + callback(toServiceError(err)); + }, + ); + }, getFids: async (call, callback) => { const peer = Result.fromThrowable(() => call.getPeer())().unwrapOr("unknown"); log.debug({ method: "getFids", req: call.request }, `RPC call from ${peer}`); diff --git a/apps/hubble/src/rpc/test/bulkService.test.ts b/apps/hubble/src/rpc/test/bulkService.test.ts index 80884b23ba..ca7f3bdd27 100644 --- a/apps/hubble/src/rpc/test/bulkService.test.ts +++ b/apps/hubble/src/rpc/test/bulkService.test.ts @@ -10,10 +10,6 @@ import { IdRegistryEvent, Message, MessagesResponse, - OnChainEvent, - OnChainEventRequest, - OnChainEventResponse, - OnChainEventType, ReactionAddMessage, ReactionRemoveMessage, SignerAddMessage, @@ -28,7 +24,6 @@ import Server from "../server.js"; import { jestRocksDB } from "../../storage/db/jestUtils.js"; import Engine from "../../storage/engine/index.js"; import { MockHub } from "../../test/mocks.js"; -import { Ok } from "neverthrow"; const db = jestRocksDB("protobufs.rpc.bulkService.test"); const network = FarcasterNetwork.TESTNET; @@ -72,12 +67,6 @@ const assertMessagesMatchResult = (result: HubResult, messages expect(result._unsafeUnwrap().messages.map((m) => Message.toJSON(m))).toEqual(messages.map((m) => Message.toJSON(m))); }; -const assertEventsMatchResult = (result: HubResult, events: OnChainEvent[]) => { - expect(result._unsafeUnwrap().events.map((e) => OnChainEvent.toJSON(e))).toEqual( - events.map((e) => OnChainEvent.toJSON(e)), - ); -}; - describe("getAllCastMessagesByFid", () => { let castAdd: CastAddMessage; let castRemove: CastRemoveMessage; @@ -251,31 +240,3 @@ describe("getAllUserDataMessagesByFid", () => { expect(result._unsafeUnwrap().messages.length).toEqual(0); }); }); - -describe("getOnChainEvents", () => { - test("succeeds", async () => { - const idRegistryEvent = Factories.IdRegistryOnChainEvent.build({ fid }); - const idRegistryEvent2 = Factories.IdRegistryOnChainEvent.build({ fid: fid + 1 }); - const signerEvent = Factories.KeyRegistryOnChainEvent.build({ fid }); - const signerEvent2 = Factories.KeyRegistryOnChainEvent.build({ blockNumber: signerEvent.blockNumber + 1, fid }); - await expect(engine.mergeOnChainEvent(idRegistryEvent)).resolves.toBeInstanceOf(Ok); - await expect(engine.mergeOnChainEvent(idRegistryEvent2)).resolves.toBeInstanceOf(Ok); - await expect(engine.mergeOnChainEvent(signerEvent)).resolves.toBeInstanceOf(Ok); - await expect(engine.mergeOnChainEvent(signerEvent2)).resolves.toBeInstanceOf(Ok); - - const idResult = await client.getOnChainEvents( - OnChainEventRequest.create({ eventType: OnChainEventType.EVENT_TYPE_ID_REGISTER, fid }), - ); - assertEventsMatchResult(idResult, [idRegistryEvent]); - - const signerResult = await client.getOnChainEvents( - OnChainEventRequest.create({ eventType: OnChainEventType.EVENT_TYPE_SIGNER, fid }), - ); - assertEventsMatchResult(signerResult, [signerEvent, signerEvent2]); - - const emptyResult = await client.getOnChainEvents( - OnChainEventRequest.create({ eventType: OnChainEventType.EVENT_TYPE_STORAGE_RENT, fid }), - ); - expect(emptyResult._unsafeUnwrap().events.length).toEqual(0); - }); -}); diff --git a/apps/hubble/src/rpc/test/server.test.ts b/apps/hubble/src/rpc/test/server.test.ts new file mode 100644 index 0000000000..93dc6e88b2 --- /dev/null +++ b/apps/hubble/src/rpc/test/server.test.ts @@ -0,0 +1,163 @@ +import { jestRocksDB } from "../../storage/db/jestUtils.js"; +import { + Factories, + FarcasterNetwork, + FidRequest, + getInsecureHubRpcClient, + HubResult, + HubRpcClient, + IdRegistryEvent, + OnChainEvent, + OnChainEventRequest, + OnChainEventResponse, + OnChainEventType, + SignerAddMessage, + StorageLimit, + StorageLimitsResponse, + StoreType, +} from "@farcaster/hub-nodejs"; +import Engine from "../../storage/engine/index.js"; +import { MockHub } from "../../test/mocks.js"; +import Server from "../server.js"; +import SyncEngine from "../../network/sync/syncEngine.js"; +import { Ok } from "neverthrow"; +import { CAST_PRUNE_SIZE_LIMIT_DEFAULT } from "../../storage/stores/castStore.js"; +import { REACTION_PRUNE_SIZE_LIMIT_DEFAULT } from "../../storage/stores/reactionStore.js"; +import { LINK_PRUNE_SIZE_LIMIT_DEFAULT } from "../../storage/stores/linkStore.js"; +import { USER_DATA_PRUNE_SIZE_LIMIT_DEFAULT } from "../../storage/stores/userDataStore.js"; +import { VERIFICATION_PRUNE_SIZE_LIMIT_DEFAULT } from "../../storage/stores/verificationStore.js"; + +const db = jestRocksDB("protobufs.rpc.server.test"); +const network = FarcasterNetwork.TESTNET; +const engine = new Engine(db, network); +const hub = new MockHub(db, engine); + +let server: Server; +let client: HubRpcClient; + +beforeAll(async () => { + server = new Server(hub, engine, new SyncEngine(hub, db)); + const port = await server.start(); + client = getInsecureHubRpcClient(`127.0.0.1:${port}`); +}); + +afterAll(async () => { + client.close(); + await server.stop(); + await engine.stop(); +}); + +const fid = Factories.Fid.build(); +const signer = Factories.Ed25519Signer.build(); +const custodySigner = Factories.Eip712Signer.build(); + +let custodyEvent: IdRegistryEvent; +let signerAdd: SignerAddMessage; + +beforeAll(async () => { + const signerKey = (await signer.getSignerKey())._unsafeUnwrap(); + const custodySignerKey = (await custodySigner.getSignerKey())._unsafeUnwrap(); + custodyEvent = Factories.IdRegistryEvent.build({ fid, to: custodySignerKey }); + + signerAdd = await Factories.SignerAddMessage.create( + { data: { fid, network, signerAddBody: { signer: signerKey } } }, + { transient: { signer: custodySigner } }, + ); +}); + +describe("server rpc tests", () => { + beforeEach(async () => { + await engine.mergeIdRegistryEvent(custodyEvent); + await engine.mergeMessage(signerAdd); + }); + + describe("getOnChainEvents", () => { + const assertEventsMatchResult = (result: HubResult, events: OnChainEvent[]) => { + expect(result._unsafeUnwrap().events.map((e) => OnChainEvent.toJSON(e))).toEqual( + events.map((e) => OnChainEvent.toJSON(e)), + ); + }; + + test("succeeds", async () => { + const idRegistryEvent = Factories.IdRegistryOnChainEvent.build({ fid }); + const idRegistryEvent2 = Factories.IdRegistryOnChainEvent.build({ fid: fid + 1 }); + const signerEvent = Factories.SignerOnChainEvent.build({ fid }); + const signerEvent2 = Factories.SignerOnChainEvent.build({ blockNumber: signerEvent.blockNumber + 1, fid }); + await expect(engine.mergeOnChainEvent(idRegistryEvent)).resolves.toBeInstanceOf(Ok); + await expect(engine.mergeOnChainEvent(idRegistryEvent2)).resolves.toBeInstanceOf(Ok); + await expect(engine.mergeOnChainEvent(signerEvent)).resolves.toBeInstanceOf(Ok); + await expect(engine.mergeOnChainEvent(signerEvent2)).resolves.toBeInstanceOf(Ok); + + const idResult = await client.getOnChainEvents( + OnChainEventRequest.create({ eventType: OnChainEventType.EVENT_TYPE_ID_REGISTER, fid }), + ); + assertEventsMatchResult(idResult, [idRegistryEvent]); + + const signerResult = await client.getOnChainEvents( + OnChainEventRequest.create({ eventType: OnChainEventType.EVENT_TYPE_SIGNER, fid }), + ); + assertEventsMatchResult(signerResult, [signerEvent, signerEvent2]); + + const emptyResult = await client.getOnChainEvents( + OnChainEventRequest.create({ eventType: OnChainEventType.EVENT_TYPE_STORAGE_RENT, fid }), + ); + expect(emptyResult._unsafeUnwrap().events.length).toEqual(0); + }); + }); + + describe("getCurrentStorageLimitsByFid", () => { + test("succeeds for user with no storage", async () => { + const result = await client.getCurrentStorageLimitsByFid(FidRequest.create({ fid })); + expect(result._unsafeUnwrap().limits.map((l) => l.limit)).toEqual([0, 0, 0, 0, 0]); + }); + + test("succeeds for user with storage", async () => { + const rentEvent = Factories.StorageRentOnChainEvent.build({ + fid, + storageRentEventBody: Factories.StorageRentEventBody.build({ units: 1 }), + }); + await engine.mergeOnChainEvent(rentEvent); + const result = await client.getCurrentStorageLimitsByFid(FidRequest.create({ fid })); + const storageLimits = StorageLimitsResponse.fromJSON(result._unsafeUnwrap()).limits; + expect(storageLimits).toContainEqual( + StorageLimit.create({ limit: CAST_PRUNE_SIZE_LIMIT_DEFAULT, storeType: StoreType.CASTS }), + ); + expect(storageLimits).toContainEqual( + StorageLimit.create({ limit: REACTION_PRUNE_SIZE_LIMIT_DEFAULT, storeType: StoreType.REACTIONS }), + ); + expect(storageLimits).toContainEqual( + StorageLimit.create({ limit: LINK_PRUNE_SIZE_LIMIT_DEFAULT, storeType: StoreType.LINKS }), + ); + expect(storageLimits).toContainEqual( + StorageLimit.create({ limit: USER_DATA_PRUNE_SIZE_LIMIT_DEFAULT, storeType: StoreType.USER_DATA }), + ); + expect(storageLimits).toContainEqual( + StorageLimit.create({ limit: VERIFICATION_PRUNE_SIZE_LIMIT_DEFAULT, storeType: StoreType.VERIFICATIONS }), + ); + + // add 2 more units + const rentEvent2 = Factories.StorageRentOnChainEvent.build({ + fid, + storageRentEventBody: Factories.StorageRentEventBody.build({ units: 2 }), + }); + await engine.mergeOnChainEvent(rentEvent2); + const result2 = await client.getCurrentStorageLimitsByFid(FidRequest.create({ fid })); + const newLimits = StorageLimitsResponse.fromJSON(result2._unsafeUnwrap()).limits; + expect(newLimits).toContainEqual( + StorageLimit.create({ limit: CAST_PRUNE_SIZE_LIMIT_DEFAULT * 3, storeType: StoreType.CASTS }), + ); + expect(newLimits).toContainEqual( + StorageLimit.create({ limit: REACTION_PRUNE_SIZE_LIMIT_DEFAULT * 3, storeType: StoreType.REACTIONS }), + ); + expect(newLimits).toContainEqual( + StorageLimit.create({ limit: LINK_PRUNE_SIZE_LIMIT_DEFAULT * 3, storeType: StoreType.LINKS }), + ); + expect(newLimits).toContainEqual( + StorageLimit.create({ limit: USER_DATA_PRUNE_SIZE_LIMIT_DEFAULT * 3, storeType: StoreType.USER_DATA }), + ); + expect(newLimits).toContainEqual( + StorageLimit.create({ limit: VERIFICATION_PRUNE_SIZE_LIMIT_DEFAULT * 3, storeType: StoreType.VERIFICATIONS }), + ); + }); + }); +}); diff --git a/apps/hubble/src/rpc/test/signerService.test.ts b/apps/hubble/src/rpc/test/signerService.test.ts index f7025b97e0..45b1bd4eed 100644 --- a/apps/hubble/src/rpc/test/signerService.test.ts +++ b/apps/hubble/src/rpc/test/signerService.test.ts @@ -68,7 +68,7 @@ beforeAll(async () => { { data: { fid, network, signerAddBody: { signer: signerKey } } }, { transient: { signer: custodySigner } }, ); - onChainSigner = Factories.KeyRegistryOnChainEvent.build({ + onChainSigner = Factories.SignerOnChainEvent.build({ fid: fid, signerEventBody: Factories.SignerEventBody.build({ key: signerKey, diff --git a/apps/hubble/src/storage/db/onChainEvent.test.ts b/apps/hubble/src/storage/db/onChainEvent.test.ts index 8363438a40..8a7f725b0e 100644 --- a/apps/hubble/src/storage/db/onChainEvent.test.ts +++ b/apps/hubble/src/storage/db/onChainEvent.test.ts @@ -13,7 +13,7 @@ let onChainEvent: OnChainEvent; let anotherEvent: OnChainEvent; beforeEach(async () => { - onChainEvent = Factories.KeyRegistryOnChainEvent.build(); + onChainEvent = Factories.SignerOnChainEvent.build(); anotherEvent = Factories.IdRegistryOnChainEvent.build(); let txn = db.transaction(); txn = putOnChainEventTransaction(txn, onChainEvent); @@ -37,7 +37,7 @@ describe("makeOnChainEventPrimaryKey", () => { describe("putOnChainEvent", () => { test("succeeds", async () => { - const onChainEvent = Factories.KeyRegistryOnChainEvent.build(); + const onChainEvent = Factories.SignerOnChainEvent.build(); const txn = db.transaction(); putOnChainEventTransaction(txn, onChainEvent); await db.commit(txn); diff --git a/apps/hubble/src/storage/engine/index.test.ts b/apps/hubble/src/storage/engine/index.test.ts index 9b60cba5fa..9d30fbccf6 100644 --- a/apps/hubble/src/storage/engine/index.test.ts +++ b/apps/hubble/src/storage/engine/index.test.ts @@ -759,7 +759,7 @@ describe("mergeMessage", () => { test("succeeds with l2 id registry event and on chain signer", async () => { const idRegistryOnChainEvent = Factories.IdRegistryOnChainEvent.build({ fid }); const signerEventBody = Factories.SignerEventBody.build({ key: signerAdd.data.signerAddBody.signer }); - const onChainSignerEvent = Factories.KeyRegistryOnChainEvent.build({ fid, signerEventBody }); + const onChainSignerEvent = Factories.SignerOnChainEvent.build({ fid, signerEventBody }); await migratedEngine.mergeOnChainEvent(idRegistryOnChainEvent); await migratedEngine.mergeOnChainEvent(onChainSignerEvent); @@ -770,13 +770,13 @@ describe("mergeMessage", () => { test("fails if signer is removed on chain", async () => { const idRegistryOnChainEvent = Factories.IdRegistryOnChainEvent.build({ fid }); const signerEventBody = Factories.SignerEventBody.build({ key: signerAdd.data.signerAddBody.signer }); - const onChainSignerEvent = Factories.KeyRegistryOnChainEvent.build({ fid, signerEventBody }); + const onChainSignerEvent = Factories.SignerOnChainEvent.build({ fid, signerEventBody }); const signerRemovalBody = Factories.SignerEventBody.build({ eventType: SignerEventType.REMOVE, key: signerAdd.data.signerAddBody.signer, }); - const signerRemovalEvent = Factories.KeyRegistryOnChainEvent.build({ fid, signerEventBody: signerRemovalBody }); + const signerRemovalEvent = Factories.SignerOnChainEvent.build({ fid, signerEventBody: signerRemovalBody }); await migratedEngine.mergeOnChainEvent(idRegistryOnChainEvent); await migratedEngine.mergeOnChainEvent(onChainSignerEvent); @@ -982,7 +982,7 @@ describe("with listeners and workers", () => { test("revokes messages when onchain signer is removed", async () => { const idRegistryOnChainEvent = Factories.IdRegistryOnChainEvent.build({ fid }); const signerEventBody = Factories.SignerEventBody.build({ key: signerAdd.data.signerAddBody.signer }); - const onChainSignerEvent = Factories.KeyRegistryOnChainEvent.build({ fid, signerEventBody }); + const onChainSignerEvent = Factories.SignerOnChainEvent.build({ fid, signerEventBody }); await liveEngine.mergeOnChainEvent(idRegistryOnChainEvent); await liveEngine.mergeOnChainEvent(onChainSignerEvent); @@ -992,7 +992,7 @@ describe("with listeners and workers", () => { eventType: SignerEventType.REMOVE, key: signerEventBody.key, }); - const signerRemovalEvent = Factories.KeyRegistryOnChainEvent.build({ fid, signerEventBody: signerRemovalBody }); + const signerRemovalEvent = Factories.SignerOnChainEvent.build({ fid, signerEventBody: signerRemovalBody }); await liveEngine.mergeOnChainEvent(signerRemovalEvent); expect(revokedMessages).toEqual([]); diff --git a/apps/hubble/src/storage/engine/index.ts b/apps/hubble/src/storage/engine/index.ts index 251b28309b..26ebe083b1 100644 --- a/apps/hubble/src/storage/engine/index.ts +++ b/apps/hubble/src/storage/engine/index.ts @@ -40,6 +40,8 @@ import { SignerEventType, SignerOnChainEvent, SignerRemoveMessage, + StorageLimitsResponse, + StoreType, UserDataAddMessage, UserDataType, UserNameProof, @@ -55,14 +57,14 @@ import { Worker } from "worker_threads"; import { getMessage, getMessagesBySignerIterator, typeToSetPostfix } from "../db/message.js"; import RocksDB from "../db/rocksdb.js"; import { TSHASH_LENGTH, UserPostfix } from "../db/types.js"; -import CastStore from "../stores/castStore.js"; -import LinkStore from "../stores/linkStore.js"; -import ReactionStore from "../stores/reactionStore.js"; +import CastStore, { CAST_PRUNE_SIZE_LIMIT_DEFAULT } from "../stores/castStore.js"; +import LinkStore, { LINK_PRUNE_SIZE_LIMIT_DEFAULT } from "../stores/linkStore.js"; +import ReactionStore, { REACTION_PRUNE_SIZE_LIMIT_DEFAULT } from "../stores/reactionStore.js"; import SignerStore from "../stores/signerStore.js"; import StoreEventHandler from "../stores/storeEventHandler.js"; import { MessagesPage, PageOptions } from "../stores/types.js"; -import UserDataStore from "../stores/userDataStore.js"; -import VerificationStore from "../stores/verificationStore.js"; +import UserDataStore, { USER_DATA_PRUNE_SIZE_LIMIT_DEFAULT } from "../stores/userDataStore.js"; +import VerificationStore, { VERIFICATION_PRUNE_SIZE_LIMIT_DEFAULT } from "../stores/verificationStore.js"; import { logger } from "../../utils/logger.js"; import { RevokeMessagesBySignerJobQueue, RevokeMessagesBySignerJobWorker } from "../jobs/revokeMessagesBySignerJob.js"; import { ensureAboveTargetFarcasterVersion } from "../../utils/versions.js"; @@ -735,6 +737,44 @@ class Engine { ); } + async getCurrentStorageLimitsByFid(fid: number): HubAsyncResult { + const validatedFid = validations.validateFid(fid); + if (validatedFid.isErr()) { + return err(validatedFid.error); + } + + const units = await this.eventHandler.getCurrentStorageUnitsForFid(fid); + + if (units.isErr()) { + return err(units.error); + } + + return ok({ + limits: [ + { + storeType: StoreType.CASTS, + limit: CAST_PRUNE_SIZE_LIMIT_DEFAULT * units.value, + }, + { + storeType: StoreType.LINKS, + limit: LINK_PRUNE_SIZE_LIMIT_DEFAULT * units.value, + }, + { + storeType: StoreType.REACTIONS, + limit: REACTION_PRUNE_SIZE_LIMIT_DEFAULT * units.value, + }, + { + storeType: StoreType.USER_DATA, + limit: USER_DATA_PRUNE_SIZE_LIMIT_DEFAULT * units.value, + }, + { + storeType: StoreType.VERIFICATIONS, + limit: VERIFICATION_PRUNE_SIZE_LIMIT_DEFAULT * units.value, + }, + ], + }); + } + async getUserNameProof(name: Uint8Array): HubAsyncResult { const nameString = bytesToUtf8String(name); if (nameString.isErr()) { diff --git a/apps/hubble/src/storage/stores/castStore.ts b/apps/hubble/src/storage/stores/castStore.ts index 832877081e..39c086ad5f 100644 --- a/apps/hubble/src/storage/stores/castStore.ts +++ b/apps/hubble/src/storage/stores/castStore.ts @@ -23,6 +23,8 @@ import { RootPrefix, TRUE_VALUE, UserMessagePostfix, UserPostfix } from "../db/t import { MessagesPage, PageOptions } from "../stores/types.js"; import { Store } from "./store.js"; +export const CAST_PRUNE_SIZE_LIMIT_DEFAULT = 10_000; + /** * Generates unique keys used to store or fetch CastAdd messages in the adds set index * @@ -132,7 +134,7 @@ class CastStore extends Store { override _removeMessageType = MessageType.CAST_REMOVE; protected override get PRUNE_SIZE_LIMIT_DEFAULT() { - return 10_000; + return CAST_PRUNE_SIZE_LIMIT_DEFAULT; } protected override get PRUNE_TIME_LIMIT_DEFAULT() { diff --git a/apps/hubble/src/storage/stores/linkStore.ts b/apps/hubble/src/storage/stores/linkStore.ts index f9aa9035d3..972fccf267 100644 --- a/apps/hubble/src/storage/stores/linkStore.ts +++ b/apps/hubble/src/storage/stores/linkStore.ts @@ -21,7 +21,7 @@ import { Store } from "./store.js"; import { ResultAsync, err, ok } from "neverthrow"; import { Transaction } from "../db/rocksdb.js"; -const PRUNE_SIZE_LIMIT_DEFAULT = 2_500; +export const LINK_PRUNE_SIZE_LIMIT_DEFAULT = 2_500; const makeTargetKey = (target: number): Buffer => { return makeFidKey(target); @@ -152,7 +152,7 @@ class LinkStore extends Store { override _removeMessageType = MessageType.LINK_REMOVE; protected override get PRUNE_SIZE_LIMIT_DEFAULT() { - return PRUNE_SIZE_LIMIT_DEFAULT; + return LINK_PRUNE_SIZE_LIMIT_DEFAULT; } override async buildSecondaryIndices(txn: Transaction, message: LinkAddMessage): HubAsyncResult { diff --git a/apps/hubble/src/storage/stores/onchainEventStore.test.ts b/apps/hubble/src/storage/stores/onchainEventStore.test.ts index aa575d3f7c..30ffb394a8 100644 --- a/apps/hubble/src/storage/stores/onchainEventStore.test.ts +++ b/apps/hubble/src/storage/stores/onchainEventStore.test.ts @@ -17,21 +17,21 @@ const set = new OnChainEventStore(db, eventHandler); describe("OnChainEventStore", () => { describe("mergeOnChainEvent", () => { test("should merge event", async () => { - const onChainEvent = Factories.KeyRegistryOnChainEvent.build(); + const onChainEvent = Factories.SignerOnChainEvent.build(); await set.mergeOnChainEvent(onChainEvent); expect(await set.getOnChainEvents(OnChainEventType.EVENT_TYPE_SIGNER, onChainEvent.fid)).toEqual([onChainEvent]); }); test("does not merge duplicate events", async () => { - const onChainEvent = Factories.KeyRegistryOnChainEvent.build(); + const onChainEvent = Factories.SignerOnChainEvent.build(); await set.mergeOnChainEvent(onChainEvent); await expect(set.mergeOnChainEvent(onChainEvent)).rejects.toThrow("already exists"); }); describe("signers", () => { test("can add same signer for multiple fids", async () => { - const firstSigner = Factories.KeyRegistryOnChainEvent.build(); - const secondSigner = Factories.KeyRegistryOnChainEvent.build({ + const firstSigner = Factories.SignerOnChainEvent.build(); + const secondSigner = Factories.SignerOnChainEvent.build({ fid: firstSigner.fid + 1, signerEventBody: Factories.SignerEventBody.build({ key: firstSigner.signerEventBody.key, @@ -42,8 +42,8 @@ describe("OnChainEventStore", () => { await set.mergeOnChainEvent(secondSigner); }); test("does not allow re-adding removed keys", async () => { - const signer = Factories.KeyRegistryOnChainEvent.build(); - const signerRemoved = Factories.KeyRegistryOnChainEvent.build({ + const signer = Factories.SignerOnChainEvent.build(); + const signerRemoved = Factories.SignerOnChainEvent.build({ fid: signer.fid, signerEventBody: Factories.SignerEventBody.build({ eventType: SignerEventType.REMOVE, @@ -54,7 +54,7 @@ describe("OnChainEventStore", () => { await set.mergeOnChainEvent(signer); await set.mergeOnChainEvent(signerRemoved); - const signerReAdd = Factories.KeyRegistryOnChainEvent.build({ + const signerReAdd = Factories.SignerOnChainEvent.build({ fid: signer.fid, signerEventBody: Factories.SignerEventBody.build({ eventType: SignerEventType.ADD, @@ -82,8 +82,8 @@ describe("OnChainEventStore", () => { describe("getOnChainEvents", () => { test("returns onchain events by type and fid", async () => { - const keyRegistryEvent = Factories.KeyRegistryOnChainEvent.build(); - const keyRegistryEvent2 = Factories.KeyRegistryOnChainEvent.build({ + const keyRegistryEvent = Factories.SignerOnChainEvent.build(); + const keyRegistryEvent2 = Factories.SignerOnChainEvent.build({ fid: keyRegistryEvent.fid, blockNumber: keyRegistryEvent.blockNumber + 1, }); @@ -105,14 +105,14 @@ describe("OnChainEventStore", () => { describe("getActiveSigner", () => { test("returns signer if it's not removed", async () => { - const signer = Factories.KeyRegistryOnChainEvent.build(); + const signer = Factories.SignerOnChainEvent.build(); await set.mergeOnChainEvent(signer); await expect(set.getActiveSigner(signer.fid, signer.signerEventBody.key)).resolves.toEqual(signer); }); test("does not return signer if it's removed", async () => { - const signer = Factories.KeyRegistryOnChainEvent.build(); - const signerRemoved = Factories.KeyRegistryOnChainEvent.build({ + const signer = Factories.SignerOnChainEvent.build(); + const signerRemoved = Factories.SignerOnChainEvent.build({ fid: signer.fid, signerEventBody: Factories.SignerEventBody.build({ eventType: SignerEventType.REMOVE, @@ -165,7 +165,7 @@ describe("OnChainEventStore", () => { test("emits events on merge", async () => { const idRegisterEvent = Factories.IdRegistryOnChainEvent.build(); - const keyRegistryEvent = Factories.KeyRegistryOnChainEvent.build(); + const keyRegistryEvent = Factories.SignerOnChainEvent.build(); const signerMigratedEvent = Factories.SignerMigratedOnChainEvent.build(); await set.mergeOnChainEvent(idRegisterEvent); await set.mergeOnChainEvent(keyRegistryEvent); diff --git a/apps/hubble/src/storage/stores/reactionStore.ts b/apps/hubble/src/storage/stores/reactionStore.ts index a8822c613c..e492e2e0cc 100644 --- a/apps/hubble/src/storage/stores/reactionStore.ts +++ b/apps/hubble/src/storage/stores/reactionStore.ts @@ -24,7 +24,7 @@ import { RootPrefix, TSHASH_LENGTH, UserMessagePostfix, UserPostfix } from "../d import { MessagesPage, PAGE_SIZE_MAX, PageOptions } from "../stores/types.js"; import { Store } from "./store.js"; -const PRUNE_SIZE_LIMIT_DEFAULT = 5_000; +export const REACTION_PRUNE_SIZE_LIMIT_DEFAULT = 5_000; const PRUNE_TIME_LIMIT_DEFAULT = 60 * 60 * 24 * 90; // 90 days const makeTargetKey = (target: CastId | string): Buffer => { @@ -147,7 +147,7 @@ class ReactionStore extends Store { override _removeMessageType = MessageType.REACTION_REMOVE; protected override get PRUNE_SIZE_LIMIT_DEFAULT() { - return PRUNE_SIZE_LIMIT_DEFAULT; + return REACTION_PRUNE_SIZE_LIMIT_DEFAULT; } protected override get PRUNE_TIME_LIMIT_DEFAULT() { diff --git a/apps/hubble/src/storage/stores/signerStore.ts b/apps/hubble/src/storage/stores/signerStore.ts index d89777dd2f..12f3b488b1 100644 --- a/apps/hubble/src/storage/stores/signerStore.ts +++ b/apps/hubble/src/storage/stores/signerStore.ts @@ -22,7 +22,7 @@ import { MessagesPage, PAGE_SIZE_MAX, PageOptions } from "./types.js"; import { eventCompare } from "./utils.js"; import { Store } from "./store.js"; -const PRUNE_SIZE_LIMIT_DEFAULT = 100; +export const SIGNER_PRUNE_SIZE_LIMIT_DEFAULT = 100; /** * Generates a unique key used to store a SignerAdd message key in the SignerAdds set index @@ -98,7 +98,7 @@ class SignerStore extends Store { override _removeMessageType = MessageType.SIGNER_REMOVE; protected override get PRUNE_SIZE_LIMIT_DEFAULT() { - return PRUNE_SIZE_LIMIT_DEFAULT; + return SIGNER_PRUNE_SIZE_LIMIT_DEFAULT; } override async findMergeAddConflicts(_message: SignerAddMessage): HubAsyncResult { diff --git a/apps/hubble/src/storage/stores/userDataStore.ts b/apps/hubble/src/storage/stores/userDataStore.ts index 7de2f16ebb..f3a67dfdf4 100644 --- a/apps/hubble/src/storage/stores/userDataStore.ts +++ b/apps/hubble/src/storage/stores/userDataStore.ts @@ -24,7 +24,7 @@ import { eventCompare, usernameProofCompare } from "../stores/utils.js"; import { Store } from "./store.js"; import { Transaction } from "../db/rocksdb.js"; -const PRUNE_SIZE_LIMIT_DEFAULT = 100; +export const USER_DATA_PRUNE_SIZE_LIMIT_DEFAULT = 100; /** * Generates unique keys used to store or fetch UserDataAdd messages in the UserDataAdd set index @@ -85,7 +85,7 @@ class UserDataStore extends Store { override _removeMessageType = undefined; protected override get PRUNE_SIZE_LIMIT_DEFAULT() { - return PRUNE_SIZE_LIMIT_DEFAULT; + return USER_DATA_PRUNE_SIZE_LIMIT_DEFAULT; } /** diff --git a/apps/hubble/src/storage/stores/verificationStore.ts b/apps/hubble/src/storage/stores/verificationStore.ts index 963cd6a9ed..6ee67aa5b3 100644 --- a/apps/hubble/src/storage/stores/verificationStore.ts +++ b/apps/hubble/src/storage/stores/verificationStore.ts @@ -12,7 +12,7 @@ import { UserMessagePostfix, UserPostfix } from "../db/types.js"; import { MessagesPage, PageOptions } from "./types.js"; import { Store } from "./store.js"; -const PRUNE_SIZE_LIMIT_DEFAULT = 50; +export const VERIFICATION_PRUNE_SIZE_LIMIT_DEFAULT = 50; /** * Generates a unique key used to store a VerificationAdds message key in the VerificationsAdds @@ -94,7 +94,7 @@ class VerificationStore extends Store(() => { return StorageRentEventBody.create({ payer: EthAddressFactory.build(), - units: faker.datatype.number({ min: 1, max: 1_000 }), + units: faker.datatype.number({ min: 1, max: 10 }), expiry: getFarcasterTime()._unsafeUnwrap() + 60 * 60 * 24 * 365, // a year }); }); @@ -768,7 +768,7 @@ export const Factories = { UsernameProofMessage: UsernameProofMessageFactory, OnChainEvent: OnChainEventFactory, SignerEventBody: SignerEventBodyFactory, - KeyRegistryOnChainEvent: SignerOnChainEventFactory, + SignerOnChainEvent: SignerOnChainEventFactory, IdRegistryOnChainEvent: IdRegisterOnChainEventFactory, SignerMigratedOnChainEvent: SignerMigratedOnChainEventFactory, StorageRentEventBody: StorageRentEventBodyFactory, diff --git a/packages/core/src/protobufs/generated/request_response.ts b/packages/core/src/protobufs/generated/request_response.ts index 337b7087d9..cb7a549166 100644 --- a/packages/core/src/protobufs/generated/request_response.ts +++ b/packages/core/src/protobufs/generated/request_response.ts @@ -15,6 +15,59 @@ import { import { OnChainEvent, OnChainEventType, onChainEventTypeFromJSON, onChainEventTypeToJSON } from "./onchain_event"; import { UserNameProof } from "./username_proof"; +export enum StoreType { + NONE = 0, + CASTS = 1, + LINKS = 2, + REACTIONS = 3, + USER_DATA = 4, + VERIFICATIONS = 5, +} + +export function storeTypeFromJSON(object: any): StoreType { + switch (object) { + case 0: + case "STORE_TYPE_NONE": + return StoreType.NONE; + case 1: + case "STORE_TYPE_CASTS": + return StoreType.CASTS; + case 2: + case "STORE_TYPE_LINKS": + return StoreType.LINKS; + case 3: + case "STORE_TYPE_REACTIONS": + return StoreType.REACTIONS; + case 4: + case "STORE_TYPE_USER_DATA": + return StoreType.USER_DATA; + case 5: + case "STORE_TYPE_VERIFICATIONS": + return StoreType.VERIFICATIONS; + default: + throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StoreType"); + } +} + +export function storeTypeToJSON(object: StoreType): string { + switch (object) { + case StoreType.NONE: + return "STORE_TYPE_NONE"; + case StoreType.CASTS: + return "STORE_TYPE_CASTS"; + case StoreType.LINKS: + return "STORE_TYPE_LINKS"; + case StoreType.REACTIONS: + return "STORE_TYPE_REACTIONS"; + case StoreType.USER_DATA: + return "STORE_TYPE_USER_DATA"; + case StoreType.VERIFICATIONS: + return "STORE_TYPE_VERIFICATIONS"; + default: + throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StoreType"); + } +} + export interface Empty { } @@ -169,6 +222,15 @@ export interface StorageAdminRegistryEventRequest { transactionHash: Uint8Array; } +export interface StorageLimitsResponse { + limits: StorageLimit[]; +} + +export interface StorageLimit { + storeType: StoreType; + limit: number; +} + export interface UsernameProofRequest { name: Uint8Array; } @@ -2460,6 +2522,137 @@ export const StorageAdminRegistryEventRequest = { }, }; +function createBaseStorageLimitsResponse(): StorageLimitsResponse { + return { limits: [] }; +} + +export const StorageLimitsResponse = { + encode(message: StorageLimitsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + for (const v of message.limits) { + StorageLimit.encode(v!, writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): StorageLimitsResponse { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseStorageLimitsResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag != 10) { + break; + } + + message.limits.push(StorageLimit.decode(reader, reader.uint32())); + continue; + } + if ((tag & 7) == 4 || tag == 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): StorageLimitsResponse { + return { limits: Array.isArray(object?.limits) ? object.limits.map((e: any) => StorageLimit.fromJSON(e)) : [] }; + }, + + toJSON(message: StorageLimitsResponse): unknown { + const obj: any = {}; + if (message.limits) { + obj.limits = message.limits.map((e) => e ? StorageLimit.toJSON(e) : undefined); + } else { + obj.limits = []; + } + return obj; + }, + + create, I>>(base?: I): StorageLimitsResponse { + return StorageLimitsResponse.fromPartial(base ?? {}); + }, + + fromPartial, I>>(object: I): StorageLimitsResponse { + const message = createBaseStorageLimitsResponse(); + message.limits = object.limits?.map((e) => StorageLimit.fromPartial(e)) || []; + return message; + }, +}; + +function createBaseStorageLimit(): StorageLimit { + return { storeType: 0, limit: 0 }; +} + +export const StorageLimit = { + encode(message: StorageLimit, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.storeType !== 0) { + writer.uint32(8).int32(message.storeType); + } + if (message.limit !== 0) { + writer.uint32(16).uint64(message.limit); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): StorageLimit { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseStorageLimit(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag != 8) { + break; + } + + message.storeType = reader.int32() as any; + continue; + case 2: + if (tag != 16) { + break; + } + + message.limit = longToNumber(reader.uint64() as Long); + continue; + } + if ((tag & 7) == 4 || tag == 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): StorageLimit { + return { + storeType: isSet(object.storeType) ? storeTypeFromJSON(object.storeType) : 0, + limit: isSet(object.limit) ? Number(object.limit) : 0, + }; + }, + + toJSON(message: StorageLimit): unknown { + const obj: any = {}; + message.storeType !== undefined && (obj.storeType = storeTypeToJSON(message.storeType)); + message.limit !== undefined && (obj.limit = Math.round(message.limit)); + return obj; + }, + + create, I>>(base?: I): StorageLimit { + return StorageLimit.fromPartial(base ?? {}); + }, + + fromPartial, I>>(object: I): StorageLimit { + const message = createBaseStorageLimit(); + message.storeType = object.storeType ?? 0; + message.limit = object.limit ?? 0; + return message; + }, +}; + function createBaseUsernameProofRequest(): UsernameProofRequest { return { name: new Uint8Array() }; } diff --git a/packages/core/src/protobufs/generated/storage_event.ts b/packages/core/src/protobufs/generated/storage_event.ts deleted file mode 100644 index 55208ae73c..0000000000 --- a/packages/core/src/protobufs/generated/storage_event.ts +++ /dev/null @@ -1,491 +0,0 @@ -/* eslint-disable */ -import Long from "long"; -import _m0 from "protobufjs/minimal"; - -export enum StorageRegistryEventType { - NONE = 0, - RENT = 1, - SET_PRICE = 2, - SET_MAX_UNITS = 3, - SET_DEPRECATION_TIMESTAMP = 4, - SET_GRACE_PERIOD = 5, -} - -export function storageRegistryEventTypeFromJSON(object: any): StorageRegistryEventType { - switch (object) { - case 0: - case "STORAGE_REGISTRY_EVENT_TYPE_NONE": - return StorageRegistryEventType.NONE; - case 1: - case "STORAGE_REGISTRY_EVENT_TYPE_RENT": - return StorageRegistryEventType.RENT; - case 2: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_PRICE": - return StorageRegistryEventType.SET_PRICE; - case 3: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_MAX_UNITS": - return StorageRegistryEventType.SET_MAX_UNITS; - case 4: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_DEPRECATION_TIMESTAMP": - return StorageRegistryEventType.SET_DEPRECATION_TIMESTAMP; - case 5: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_GRACE_PERIOD": - return StorageRegistryEventType.SET_GRACE_PERIOD; - default: - throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StorageRegistryEventType"); - } -} - -export function storageRegistryEventTypeToJSON(object: StorageRegistryEventType): string { - switch (object) { - case StorageRegistryEventType.NONE: - return "STORAGE_REGISTRY_EVENT_TYPE_NONE"; - case StorageRegistryEventType.RENT: - return "STORAGE_REGISTRY_EVENT_TYPE_RENT"; - case StorageRegistryEventType.SET_PRICE: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_PRICE"; - case StorageRegistryEventType.SET_MAX_UNITS: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_MAX_UNITS"; - case StorageRegistryEventType.SET_DEPRECATION_TIMESTAMP: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_DEPRECATION_TIMESTAMP"; - case StorageRegistryEventType.SET_GRACE_PERIOD: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_GRACE_PERIOD"; - default: - throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StorageRegistryEventType"); - } -} - -export interface RentRegistryEvent { - blockNumber: number; - blockHash: Uint8Array; - transactionHash: Uint8Array; - logIndex: number; - payer: Uint8Array; - fid: number; - type: StorageRegistryEventType; - units: number; - expiry: number; -} - -export interface StorageAdminRegistryEvent { - blockNumber: number; - blockHash: Uint8Array; - transactionHash: Uint8Array; - logIndex: number; - timestamp: number; - from: Uint8Array; - type: StorageRegistryEventType; - value: Uint8Array; -} - -function createBaseRentRegistryEvent(): RentRegistryEvent { - return { - blockNumber: 0, - blockHash: new Uint8Array(), - transactionHash: new Uint8Array(), - logIndex: 0, - payer: new Uint8Array(), - fid: 0, - type: 0, - units: 0, - expiry: 0, - }; -} - -export const RentRegistryEvent = { - encode(message: RentRegistryEvent, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { - if (message.blockNumber !== 0) { - writer.uint32(8).uint32(message.blockNumber); - } - if (message.blockHash.length !== 0) { - writer.uint32(18).bytes(message.blockHash); - } - if (message.transactionHash.length !== 0) { - writer.uint32(26).bytes(message.transactionHash); - } - if (message.logIndex !== 0) { - writer.uint32(32).uint32(message.logIndex); - } - if (message.payer.length !== 0) { - writer.uint32(42).bytes(message.payer); - } - if (message.fid !== 0) { - writer.uint32(48).uint64(message.fid); - } - if (message.type !== 0) { - writer.uint32(56).int32(message.type); - } - if (message.units !== 0) { - writer.uint32(64).uint32(message.units); - } - if (message.expiry !== 0) { - writer.uint32(72).uint32(message.expiry); - } - return writer; - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): RentRegistryEvent { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); - let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseRentRegistryEvent(); - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - if (tag != 8) { - break; - } - - message.blockNumber = reader.uint32(); - continue; - case 2: - if (tag != 18) { - break; - } - - message.blockHash = reader.bytes(); - continue; - case 3: - if (tag != 26) { - break; - } - - message.transactionHash = reader.bytes(); - continue; - case 4: - if (tag != 32) { - break; - } - - message.logIndex = reader.uint32(); - continue; - case 5: - if (tag != 42) { - break; - } - - message.payer = reader.bytes(); - continue; - case 6: - if (tag != 48) { - break; - } - - message.fid = longToNumber(reader.uint64() as Long); - continue; - case 7: - if (tag != 56) { - break; - } - - message.type = reader.int32() as any; - continue; - case 8: - if (tag != 64) { - break; - } - - message.units = reader.uint32(); - continue; - case 9: - if (tag != 72) { - break; - } - - message.expiry = reader.uint32(); - continue; - } - if ((tag & 7) == 4 || tag == 0) { - break; - } - reader.skipType(tag & 7); - } - return message; - }, - - fromJSON(object: any): RentRegistryEvent { - return { - blockNumber: isSet(object.blockNumber) ? Number(object.blockNumber) : 0, - blockHash: isSet(object.blockHash) ? bytesFromBase64(object.blockHash) : new Uint8Array(), - transactionHash: isSet(object.transactionHash) ? bytesFromBase64(object.transactionHash) : new Uint8Array(), - logIndex: isSet(object.logIndex) ? Number(object.logIndex) : 0, - payer: isSet(object.payer) ? bytesFromBase64(object.payer) : new Uint8Array(), - fid: isSet(object.fid) ? Number(object.fid) : 0, - type: isSet(object.type) ? storageRegistryEventTypeFromJSON(object.type) : 0, - units: isSet(object.units) ? Number(object.units) : 0, - expiry: isSet(object.expiry) ? Number(object.expiry) : 0, - }; - }, - - toJSON(message: RentRegistryEvent): unknown { - const obj: any = {}; - message.blockNumber !== undefined && (obj.blockNumber = Math.round(message.blockNumber)); - message.blockHash !== undefined && - (obj.blockHash = base64FromBytes(message.blockHash !== undefined ? message.blockHash : new Uint8Array())); - message.transactionHash !== undefined && - (obj.transactionHash = base64FromBytes( - message.transactionHash !== undefined ? message.transactionHash : new Uint8Array(), - )); - message.logIndex !== undefined && (obj.logIndex = Math.round(message.logIndex)); - message.payer !== undefined && - (obj.payer = base64FromBytes(message.payer !== undefined ? message.payer : new Uint8Array())); - message.fid !== undefined && (obj.fid = Math.round(message.fid)); - message.type !== undefined && (obj.type = storageRegistryEventTypeToJSON(message.type)); - message.units !== undefined && (obj.units = Math.round(message.units)); - message.expiry !== undefined && (obj.expiry = Math.round(message.expiry)); - return obj; - }, - - create, I>>(base?: I): RentRegistryEvent { - return RentRegistryEvent.fromPartial(base ?? {}); - }, - - fromPartial, I>>(object: I): RentRegistryEvent { - const message = createBaseRentRegistryEvent(); - message.blockNumber = object.blockNumber ?? 0; - message.blockHash = object.blockHash ?? new Uint8Array(); - message.transactionHash = object.transactionHash ?? new Uint8Array(); - message.logIndex = object.logIndex ?? 0; - message.payer = object.payer ?? new Uint8Array(); - message.fid = object.fid ?? 0; - message.type = object.type ?? 0; - message.units = object.units ?? 0; - message.expiry = object.expiry ?? 0; - return message; - }, -}; - -function createBaseStorageAdminRegistryEvent(): StorageAdminRegistryEvent { - return { - blockNumber: 0, - blockHash: new Uint8Array(), - transactionHash: new Uint8Array(), - logIndex: 0, - timestamp: 0, - from: new Uint8Array(), - type: 0, - value: new Uint8Array(), - }; -} - -export const StorageAdminRegistryEvent = { - encode(message: StorageAdminRegistryEvent, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { - if (message.blockNumber !== 0) { - writer.uint32(8).uint32(message.blockNumber); - } - if (message.blockHash.length !== 0) { - writer.uint32(18).bytes(message.blockHash); - } - if (message.transactionHash.length !== 0) { - writer.uint32(26).bytes(message.transactionHash); - } - if (message.logIndex !== 0) { - writer.uint32(32).uint32(message.logIndex); - } - if (message.timestamp !== 0) { - writer.uint32(40).uint64(message.timestamp); - } - if (message.from.length !== 0) { - writer.uint32(50).bytes(message.from); - } - if (message.type !== 0) { - writer.uint32(56).int32(message.type); - } - if (message.value.length !== 0) { - writer.uint32(66).bytes(message.value); - } - return writer; - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): StorageAdminRegistryEvent { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); - let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseStorageAdminRegistryEvent(); - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - if (tag != 8) { - break; - } - - message.blockNumber = reader.uint32(); - continue; - case 2: - if (tag != 18) { - break; - } - - message.blockHash = reader.bytes(); - continue; - case 3: - if (tag != 26) { - break; - } - - message.transactionHash = reader.bytes(); - continue; - case 4: - if (tag != 32) { - break; - } - - message.logIndex = reader.uint32(); - continue; - case 5: - if (tag != 40) { - break; - } - - message.timestamp = longToNumber(reader.uint64() as Long); - continue; - case 6: - if (tag != 50) { - break; - } - - message.from = reader.bytes(); - continue; - case 7: - if (tag != 56) { - break; - } - - message.type = reader.int32() as any; - continue; - case 8: - if (tag != 66) { - break; - } - - message.value = reader.bytes(); - continue; - } - if ((tag & 7) == 4 || tag == 0) { - break; - } - reader.skipType(tag & 7); - } - return message; - }, - - fromJSON(object: any): StorageAdminRegistryEvent { - return { - blockNumber: isSet(object.blockNumber) ? Number(object.blockNumber) : 0, - blockHash: isSet(object.blockHash) ? bytesFromBase64(object.blockHash) : new Uint8Array(), - transactionHash: isSet(object.transactionHash) ? bytesFromBase64(object.transactionHash) : new Uint8Array(), - logIndex: isSet(object.logIndex) ? Number(object.logIndex) : 0, - timestamp: isSet(object.timestamp) ? Number(object.timestamp) : 0, - from: isSet(object.from) ? bytesFromBase64(object.from) : new Uint8Array(), - type: isSet(object.type) ? storageRegistryEventTypeFromJSON(object.type) : 0, - value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(), - }; - }, - - toJSON(message: StorageAdminRegistryEvent): unknown { - const obj: any = {}; - message.blockNumber !== undefined && (obj.blockNumber = Math.round(message.blockNumber)); - message.blockHash !== undefined && - (obj.blockHash = base64FromBytes(message.blockHash !== undefined ? message.blockHash : new Uint8Array())); - message.transactionHash !== undefined && - (obj.transactionHash = base64FromBytes( - message.transactionHash !== undefined ? message.transactionHash : new Uint8Array(), - )); - message.logIndex !== undefined && (obj.logIndex = Math.round(message.logIndex)); - message.timestamp !== undefined && (obj.timestamp = Math.round(message.timestamp)); - message.from !== undefined && - (obj.from = base64FromBytes(message.from !== undefined ? message.from : new Uint8Array())); - message.type !== undefined && (obj.type = storageRegistryEventTypeToJSON(message.type)); - message.value !== undefined && - (obj.value = base64FromBytes(message.value !== undefined ? message.value : new Uint8Array())); - return obj; - }, - - create, I>>(base?: I): StorageAdminRegistryEvent { - return StorageAdminRegistryEvent.fromPartial(base ?? {}); - }, - - fromPartial, I>>(object: I): StorageAdminRegistryEvent { - const message = createBaseStorageAdminRegistryEvent(); - message.blockNumber = object.blockNumber ?? 0; - message.blockHash = object.blockHash ?? new Uint8Array(); - message.transactionHash = object.transactionHash ?? new Uint8Array(); - message.logIndex = object.logIndex ?? 0; - message.timestamp = object.timestamp ?? 0; - message.from = object.from ?? new Uint8Array(); - message.type = object.type ?? 0; - message.value = object.value ?? new Uint8Array(); - return message; - }, -}; - -declare var self: any | undefined; -declare var window: any | undefined; -declare var global: any | undefined; -var tsProtoGlobalThis: any = (() => { - if (typeof globalThis !== "undefined") { - return globalThis; - } - if (typeof self !== "undefined") { - return self; - } - if (typeof window !== "undefined") { - return window; - } - if (typeof global !== "undefined") { - return global; - } - throw "Unable to locate global object"; -})(); - -function bytesFromBase64(b64: string): Uint8Array { - if (tsProtoGlobalThis.Buffer) { - return Uint8Array.from(tsProtoGlobalThis.Buffer.from(b64, "base64")); - } else { - const bin = tsProtoGlobalThis.atob(b64); - const arr = new Uint8Array(bin.length); - for (let i = 0; i < bin.length; ++i) { - arr[i] = bin.charCodeAt(i); - } - return arr; - } -} - -function base64FromBytes(arr: Uint8Array): string { - if (tsProtoGlobalThis.Buffer) { - return tsProtoGlobalThis.Buffer.from(arr).toString("base64"); - } else { - const bin: string[] = []; - arr.forEach((byte) => { - bin.push(String.fromCharCode(byte)); - }); - return tsProtoGlobalThis.btoa(bin.join("")); - } -} - -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; - -type DeepPartial = T extends Builtin ? T - : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> - : T extends {} ? { [K in keyof T]?: DeepPartial } - : Partial; - -type KeysOfUnion = T extends T ? keyof T : never; -type Exact = P extends Builtin ? P - : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; - -function longToNumber(long: Long): number { - if (long.gt(Number.MAX_SAFE_INTEGER)) { - throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); - } - return long.toNumber(); -} - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any; - _m0.configure(); -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined; -} diff --git a/packages/core/src/protobufs/index.ts b/packages/core/src/protobufs/index.ts index dc928d48ba..e03102d4e4 100644 --- a/packages/core/src/protobufs/index.ts +++ b/packages/core/src/protobufs/index.ts @@ -5,7 +5,6 @@ export * from "./generated/id_registry_event"; export * from "./generated/job"; export * from "./generated/message"; export * from "./generated/name_registry_event"; -export * from "./generated/storage_event"; export * from "./generated/onchain_event"; export * from "./generated/username_proof"; export * from "./generated/sync_trie"; diff --git a/packages/core/src/protobufs/types.ts b/packages/core/src/protobufs/types.ts index 0da1d7c835..344bdcf090 100644 --- a/packages/core/src/protobufs/types.ts +++ b/packages/core/src/protobufs/types.ts @@ -2,7 +2,6 @@ import { IdRegistryEvent } from "./generated/id_registry_event"; import { NameRegistryEvent } from "./generated/name_registry_event"; import * as hubEventProtobufs from "./generated/hub_event"; import * as protobufs from "./generated/message"; -import { RentRegistryEvent, StorageAdminRegistryEvent } from "./generated/storage_event"; import * as onchainEventProtobufs from "./generated/onchain_event"; import { UserNameProof } from "./generated/username_proof"; import { OnChainEvent } from "./generated/onchain_event"; diff --git a/packages/hub-nodejs/src/generated/request_response.ts b/packages/hub-nodejs/src/generated/request_response.ts index 337b7087d9..cb7a549166 100644 --- a/packages/hub-nodejs/src/generated/request_response.ts +++ b/packages/hub-nodejs/src/generated/request_response.ts @@ -15,6 +15,59 @@ import { import { OnChainEvent, OnChainEventType, onChainEventTypeFromJSON, onChainEventTypeToJSON } from "./onchain_event"; import { UserNameProof } from "./username_proof"; +export enum StoreType { + NONE = 0, + CASTS = 1, + LINKS = 2, + REACTIONS = 3, + USER_DATA = 4, + VERIFICATIONS = 5, +} + +export function storeTypeFromJSON(object: any): StoreType { + switch (object) { + case 0: + case "STORE_TYPE_NONE": + return StoreType.NONE; + case 1: + case "STORE_TYPE_CASTS": + return StoreType.CASTS; + case 2: + case "STORE_TYPE_LINKS": + return StoreType.LINKS; + case 3: + case "STORE_TYPE_REACTIONS": + return StoreType.REACTIONS; + case 4: + case "STORE_TYPE_USER_DATA": + return StoreType.USER_DATA; + case 5: + case "STORE_TYPE_VERIFICATIONS": + return StoreType.VERIFICATIONS; + default: + throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StoreType"); + } +} + +export function storeTypeToJSON(object: StoreType): string { + switch (object) { + case StoreType.NONE: + return "STORE_TYPE_NONE"; + case StoreType.CASTS: + return "STORE_TYPE_CASTS"; + case StoreType.LINKS: + return "STORE_TYPE_LINKS"; + case StoreType.REACTIONS: + return "STORE_TYPE_REACTIONS"; + case StoreType.USER_DATA: + return "STORE_TYPE_USER_DATA"; + case StoreType.VERIFICATIONS: + return "STORE_TYPE_VERIFICATIONS"; + default: + throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StoreType"); + } +} + export interface Empty { } @@ -169,6 +222,15 @@ export interface StorageAdminRegistryEventRequest { transactionHash: Uint8Array; } +export interface StorageLimitsResponse { + limits: StorageLimit[]; +} + +export interface StorageLimit { + storeType: StoreType; + limit: number; +} + export interface UsernameProofRequest { name: Uint8Array; } @@ -2460,6 +2522,137 @@ export const StorageAdminRegistryEventRequest = { }, }; +function createBaseStorageLimitsResponse(): StorageLimitsResponse { + return { limits: [] }; +} + +export const StorageLimitsResponse = { + encode(message: StorageLimitsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + for (const v of message.limits) { + StorageLimit.encode(v!, writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): StorageLimitsResponse { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseStorageLimitsResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag != 10) { + break; + } + + message.limits.push(StorageLimit.decode(reader, reader.uint32())); + continue; + } + if ((tag & 7) == 4 || tag == 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): StorageLimitsResponse { + return { limits: Array.isArray(object?.limits) ? object.limits.map((e: any) => StorageLimit.fromJSON(e)) : [] }; + }, + + toJSON(message: StorageLimitsResponse): unknown { + const obj: any = {}; + if (message.limits) { + obj.limits = message.limits.map((e) => e ? StorageLimit.toJSON(e) : undefined); + } else { + obj.limits = []; + } + return obj; + }, + + create, I>>(base?: I): StorageLimitsResponse { + return StorageLimitsResponse.fromPartial(base ?? {}); + }, + + fromPartial, I>>(object: I): StorageLimitsResponse { + const message = createBaseStorageLimitsResponse(); + message.limits = object.limits?.map((e) => StorageLimit.fromPartial(e)) || []; + return message; + }, +}; + +function createBaseStorageLimit(): StorageLimit { + return { storeType: 0, limit: 0 }; +} + +export const StorageLimit = { + encode(message: StorageLimit, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.storeType !== 0) { + writer.uint32(8).int32(message.storeType); + } + if (message.limit !== 0) { + writer.uint32(16).uint64(message.limit); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): StorageLimit { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseStorageLimit(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag != 8) { + break; + } + + message.storeType = reader.int32() as any; + continue; + case 2: + if (tag != 16) { + break; + } + + message.limit = longToNumber(reader.uint64() as Long); + continue; + } + if ((tag & 7) == 4 || tag == 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): StorageLimit { + return { + storeType: isSet(object.storeType) ? storeTypeFromJSON(object.storeType) : 0, + limit: isSet(object.limit) ? Number(object.limit) : 0, + }; + }, + + toJSON(message: StorageLimit): unknown { + const obj: any = {}; + message.storeType !== undefined && (obj.storeType = storeTypeToJSON(message.storeType)); + message.limit !== undefined && (obj.limit = Math.round(message.limit)); + return obj; + }, + + create, I>>(base?: I): StorageLimit { + return StorageLimit.fromPartial(base ?? {}); + }, + + fromPartial, I>>(object: I): StorageLimit { + const message = createBaseStorageLimit(); + message.storeType = object.storeType ?? 0; + message.limit = object.limit ?? 0; + return message; + }, +}; + function createBaseUsernameProofRequest(): UsernameProofRequest { return { name: new Uint8Array() }; } diff --git a/packages/hub-nodejs/src/generated/rpc.ts b/packages/hub-nodejs/src/generated/rpc.ts index 7fe3d20b54..033fde9f9c 100644 --- a/packages/hub-nodejs/src/generated/rpc.ts +++ b/packages/hub-nodejs/src/generated/rpc.ts @@ -40,6 +40,7 @@ import { ReactionsByFidRequest, ReactionsByTargetRequest, SignerRequest, + StorageLimitsResponse, SubscribeRequest, SyncIds, SyncStatusRequest, @@ -197,6 +198,15 @@ export const HubServiceService = { responseSerialize: (value: OnChainEventResponse) => Buffer.from(OnChainEventResponse.encode(value).finish()), responseDeserialize: (value: Buffer) => OnChainEventResponse.decode(value), }, + getCurrentStorageLimitsByFid: { + path: "/HubService/GetCurrentStorageLimitsByFid", + requestStream: false, + responseStream: false, + requestSerialize: (value: FidRequest) => Buffer.from(FidRequest.encode(value).finish()), + requestDeserialize: (value: Buffer) => FidRequest.decode(value), + responseSerialize: (value: StorageLimitsResponse) => Buffer.from(StorageLimitsResponse.encode(value).finish()), + responseDeserialize: (value: Buffer) => StorageLimitsResponse.decode(value), + }, /** Username Proof */ getUsernameProof: { path: "/HubService/GetUsernameProof", @@ -455,6 +465,7 @@ export interface HubServiceServer extends UntypedServiceImplementation { getUserDataByFid: handleUnaryCall; getNameRegistryEvent: handleUnaryCall; getOnChainEvents: handleUnaryCall; + getCurrentStorageLimitsByFid: handleUnaryCall; /** Username Proof */ getUsernameProof: handleUnaryCall; getUserNameProofsByFid: handleUnaryCall; @@ -702,6 +713,21 @@ export interface HubServiceClient extends Client { options: Partial, callback: (error: ServiceError | null, response: OnChainEventResponse) => void, ): ClientUnaryCall; + getCurrentStorageLimitsByFid( + request: FidRequest, + callback: (error: ServiceError | null, response: StorageLimitsResponse) => void, + ): ClientUnaryCall; + getCurrentStorageLimitsByFid( + request: FidRequest, + metadata: Metadata, + callback: (error: ServiceError | null, response: StorageLimitsResponse) => void, + ): ClientUnaryCall; + getCurrentStorageLimitsByFid( + request: FidRequest, + metadata: Metadata, + options: Partial, + callback: (error: ServiceError | null, response: StorageLimitsResponse) => void, + ): ClientUnaryCall; /** Username Proof */ getUsernameProof( request: UsernameProofRequest, diff --git a/packages/hub-nodejs/src/generated/storage_event.ts b/packages/hub-nodejs/src/generated/storage_event.ts deleted file mode 100644 index 55208ae73c..0000000000 --- a/packages/hub-nodejs/src/generated/storage_event.ts +++ /dev/null @@ -1,491 +0,0 @@ -/* eslint-disable */ -import Long from "long"; -import _m0 from "protobufjs/minimal"; - -export enum StorageRegistryEventType { - NONE = 0, - RENT = 1, - SET_PRICE = 2, - SET_MAX_UNITS = 3, - SET_DEPRECATION_TIMESTAMP = 4, - SET_GRACE_PERIOD = 5, -} - -export function storageRegistryEventTypeFromJSON(object: any): StorageRegistryEventType { - switch (object) { - case 0: - case "STORAGE_REGISTRY_EVENT_TYPE_NONE": - return StorageRegistryEventType.NONE; - case 1: - case "STORAGE_REGISTRY_EVENT_TYPE_RENT": - return StorageRegistryEventType.RENT; - case 2: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_PRICE": - return StorageRegistryEventType.SET_PRICE; - case 3: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_MAX_UNITS": - return StorageRegistryEventType.SET_MAX_UNITS; - case 4: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_DEPRECATION_TIMESTAMP": - return StorageRegistryEventType.SET_DEPRECATION_TIMESTAMP; - case 5: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_GRACE_PERIOD": - return StorageRegistryEventType.SET_GRACE_PERIOD; - default: - throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StorageRegistryEventType"); - } -} - -export function storageRegistryEventTypeToJSON(object: StorageRegistryEventType): string { - switch (object) { - case StorageRegistryEventType.NONE: - return "STORAGE_REGISTRY_EVENT_TYPE_NONE"; - case StorageRegistryEventType.RENT: - return "STORAGE_REGISTRY_EVENT_TYPE_RENT"; - case StorageRegistryEventType.SET_PRICE: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_PRICE"; - case StorageRegistryEventType.SET_MAX_UNITS: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_MAX_UNITS"; - case StorageRegistryEventType.SET_DEPRECATION_TIMESTAMP: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_DEPRECATION_TIMESTAMP"; - case StorageRegistryEventType.SET_GRACE_PERIOD: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_GRACE_PERIOD"; - default: - throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StorageRegistryEventType"); - } -} - -export interface RentRegistryEvent { - blockNumber: number; - blockHash: Uint8Array; - transactionHash: Uint8Array; - logIndex: number; - payer: Uint8Array; - fid: number; - type: StorageRegistryEventType; - units: number; - expiry: number; -} - -export interface StorageAdminRegistryEvent { - blockNumber: number; - blockHash: Uint8Array; - transactionHash: Uint8Array; - logIndex: number; - timestamp: number; - from: Uint8Array; - type: StorageRegistryEventType; - value: Uint8Array; -} - -function createBaseRentRegistryEvent(): RentRegistryEvent { - return { - blockNumber: 0, - blockHash: new Uint8Array(), - transactionHash: new Uint8Array(), - logIndex: 0, - payer: new Uint8Array(), - fid: 0, - type: 0, - units: 0, - expiry: 0, - }; -} - -export const RentRegistryEvent = { - encode(message: RentRegistryEvent, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { - if (message.blockNumber !== 0) { - writer.uint32(8).uint32(message.blockNumber); - } - if (message.blockHash.length !== 0) { - writer.uint32(18).bytes(message.blockHash); - } - if (message.transactionHash.length !== 0) { - writer.uint32(26).bytes(message.transactionHash); - } - if (message.logIndex !== 0) { - writer.uint32(32).uint32(message.logIndex); - } - if (message.payer.length !== 0) { - writer.uint32(42).bytes(message.payer); - } - if (message.fid !== 0) { - writer.uint32(48).uint64(message.fid); - } - if (message.type !== 0) { - writer.uint32(56).int32(message.type); - } - if (message.units !== 0) { - writer.uint32(64).uint32(message.units); - } - if (message.expiry !== 0) { - writer.uint32(72).uint32(message.expiry); - } - return writer; - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): RentRegistryEvent { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); - let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseRentRegistryEvent(); - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - if (tag != 8) { - break; - } - - message.blockNumber = reader.uint32(); - continue; - case 2: - if (tag != 18) { - break; - } - - message.blockHash = reader.bytes(); - continue; - case 3: - if (tag != 26) { - break; - } - - message.transactionHash = reader.bytes(); - continue; - case 4: - if (tag != 32) { - break; - } - - message.logIndex = reader.uint32(); - continue; - case 5: - if (tag != 42) { - break; - } - - message.payer = reader.bytes(); - continue; - case 6: - if (tag != 48) { - break; - } - - message.fid = longToNumber(reader.uint64() as Long); - continue; - case 7: - if (tag != 56) { - break; - } - - message.type = reader.int32() as any; - continue; - case 8: - if (tag != 64) { - break; - } - - message.units = reader.uint32(); - continue; - case 9: - if (tag != 72) { - break; - } - - message.expiry = reader.uint32(); - continue; - } - if ((tag & 7) == 4 || tag == 0) { - break; - } - reader.skipType(tag & 7); - } - return message; - }, - - fromJSON(object: any): RentRegistryEvent { - return { - blockNumber: isSet(object.blockNumber) ? Number(object.blockNumber) : 0, - blockHash: isSet(object.blockHash) ? bytesFromBase64(object.blockHash) : new Uint8Array(), - transactionHash: isSet(object.transactionHash) ? bytesFromBase64(object.transactionHash) : new Uint8Array(), - logIndex: isSet(object.logIndex) ? Number(object.logIndex) : 0, - payer: isSet(object.payer) ? bytesFromBase64(object.payer) : new Uint8Array(), - fid: isSet(object.fid) ? Number(object.fid) : 0, - type: isSet(object.type) ? storageRegistryEventTypeFromJSON(object.type) : 0, - units: isSet(object.units) ? Number(object.units) : 0, - expiry: isSet(object.expiry) ? Number(object.expiry) : 0, - }; - }, - - toJSON(message: RentRegistryEvent): unknown { - const obj: any = {}; - message.blockNumber !== undefined && (obj.blockNumber = Math.round(message.blockNumber)); - message.blockHash !== undefined && - (obj.blockHash = base64FromBytes(message.blockHash !== undefined ? message.blockHash : new Uint8Array())); - message.transactionHash !== undefined && - (obj.transactionHash = base64FromBytes( - message.transactionHash !== undefined ? message.transactionHash : new Uint8Array(), - )); - message.logIndex !== undefined && (obj.logIndex = Math.round(message.logIndex)); - message.payer !== undefined && - (obj.payer = base64FromBytes(message.payer !== undefined ? message.payer : new Uint8Array())); - message.fid !== undefined && (obj.fid = Math.round(message.fid)); - message.type !== undefined && (obj.type = storageRegistryEventTypeToJSON(message.type)); - message.units !== undefined && (obj.units = Math.round(message.units)); - message.expiry !== undefined && (obj.expiry = Math.round(message.expiry)); - return obj; - }, - - create, I>>(base?: I): RentRegistryEvent { - return RentRegistryEvent.fromPartial(base ?? {}); - }, - - fromPartial, I>>(object: I): RentRegistryEvent { - const message = createBaseRentRegistryEvent(); - message.blockNumber = object.blockNumber ?? 0; - message.blockHash = object.blockHash ?? new Uint8Array(); - message.transactionHash = object.transactionHash ?? new Uint8Array(); - message.logIndex = object.logIndex ?? 0; - message.payer = object.payer ?? new Uint8Array(); - message.fid = object.fid ?? 0; - message.type = object.type ?? 0; - message.units = object.units ?? 0; - message.expiry = object.expiry ?? 0; - return message; - }, -}; - -function createBaseStorageAdminRegistryEvent(): StorageAdminRegistryEvent { - return { - blockNumber: 0, - blockHash: new Uint8Array(), - transactionHash: new Uint8Array(), - logIndex: 0, - timestamp: 0, - from: new Uint8Array(), - type: 0, - value: new Uint8Array(), - }; -} - -export const StorageAdminRegistryEvent = { - encode(message: StorageAdminRegistryEvent, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { - if (message.blockNumber !== 0) { - writer.uint32(8).uint32(message.blockNumber); - } - if (message.blockHash.length !== 0) { - writer.uint32(18).bytes(message.blockHash); - } - if (message.transactionHash.length !== 0) { - writer.uint32(26).bytes(message.transactionHash); - } - if (message.logIndex !== 0) { - writer.uint32(32).uint32(message.logIndex); - } - if (message.timestamp !== 0) { - writer.uint32(40).uint64(message.timestamp); - } - if (message.from.length !== 0) { - writer.uint32(50).bytes(message.from); - } - if (message.type !== 0) { - writer.uint32(56).int32(message.type); - } - if (message.value.length !== 0) { - writer.uint32(66).bytes(message.value); - } - return writer; - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): StorageAdminRegistryEvent { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); - let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseStorageAdminRegistryEvent(); - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - if (tag != 8) { - break; - } - - message.blockNumber = reader.uint32(); - continue; - case 2: - if (tag != 18) { - break; - } - - message.blockHash = reader.bytes(); - continue; - case 3: - if (tag != 26) { - break; - } - - message.transactionHash = reader.bytes(); - continue; - case 4: - if (tag != 32) { - break; - } - - message.logIndex = reader.uint32(); - continue; - case 5: - if (tag != 40) { - break; - } - - message.timestamp = longToNumber(reader.uint64() as Long); - continue; - case 6: - if (tag != 50) { - break; - } - - message.from = reader.bytes(); - continue; - case 7: - if (tag != 56) { - break; - } - - message.type = reader.int32() as any; - continue; - case 8: - if (tag != 66) { - break; - } - - message.value = reader.bytes(); - continue; - } - if ((tag & 7) == 4 || tag == 0) { - break; - } - reader.skipType(tag & 7); - } - return message; - }, - - fromJSON(object: any): StorageAdminRegistryEvent { - return { - blockNumber: isSet(object.blockNumber) ? Number(object.blockNumber) : 0, - blockHash: isSet(object.blockHash) ? bytesFromBase64(object.blockHash) : new Uint8Array(), - transactionHash: isSet(object.transactionHash) ? bytesFromBase64(object.transactionHash) : new Uint8Array(), - logIndex: isSet(object.logIndex) ? Number(object.logIndex) : 0, - timestamp: isSet(object.timestamp) ? Number(object.timestamp) : 0, - from: isSet(object.from) ? bytesFromBase64(object.from) : new Uint8Array(), - type: isSet(object.type) ? storageRegistryEventTypeFromJSON(object.type) : 0, - value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(), - }; - }, - - toJSON(message: StorageAdminRegistryEvent): unknown { - const obj: any = {}; - message.blockNumber !== undefined && (obj.blockNumber = Math.round(message.blockNumber)); - message.blockHash !== undefined && - (obj.blockHash = base64FromBytes(message.blockHash !== undefined ? message.blockHash : new Uint8Array())); - message.transactionHash !== undefined && - (obj.transactionHash = base64FromBytes( - message.transactionHash !== undefined ? message.transactionHash : new Uint8Array(), - )); - message.logIndex !== undefined && (obj.logIndex = Math.round(message.logIndex)); - message.timestamp !== undefined && (obj.timestamp = Math.round(message.timestamp)); - message.from !== undefined && - (obj.from = base64FromBytes(message.from !== undefined ? message.from : new Uint8Array())); - message.type !== undefined && (obj.type = storageRegistryEventTypeToJSON(message.type)); - message.value !== undefined && - (obj.value = base64FromBytes(message.value !== undefined ? message.value : new Uint8Array())); - return obj; - }, - - create, I>>(base?: I): StorageAdminRegistryEvent { - return StorageAdminRegistryEvent.fromPartial(base ?? {}); - }, - - fromPartial, I>>(object: I): StorageAdminRegistryEvent { - const message = createBaseStorageAdminRegistryEvent(); - message.blockNumber = object.blockNumber ?? 0; - message.blockHash = object.blockHash ?? new Uint8Array(); - message.transactionHash = object.transactionHash ?? new Uint8Array(); - message.logIndex = object.logIndex ?? 0; - message.timestamp = object.timestamp ?? 0; - message.from = object.from ?? new Uint8Array(); - message.type = object.type ?? 0; - message.value = object.value ?? new Uint8Array(); - return message; - }, -}; - -declare var self: any | undefined; -declare var window: any | undefined; -declare var global: any | undefined; -var tsProtoGlobalThis: any = (() => { - if (typeof globalThis !== "undefined") { - return globalThis; - } - if (typeof self !== "undefined") { - return self; - } - if (typeof window !== "undefined") { - return window; - } - if (typeof global !== "undefined") { - return global; - } - throw "Unable to locate global object"; -})(); - -function bytesFromBase64(b64: string): Uint8Array { - if (tsProtoGlobalThis.Buffer) { - return Uint8Array.from(tsProtoGlobalThis.Buffer.from(b64, "base64")); - } else { - const bin = tsProtoGlobalThis.atob(b64); - const arr = new Uint8Array(bin.length); - for (let i = 0; i < bin.length; ++i) { - arr[i] = bin.charCodeAt(i); - } - return arr; - } -} - -function base64FromBytes(arr: Uint8Array): string { - if (tsProtoGlobalThis.Buffer) { - return tsProtoGlobalThis.Buffer.from(arr).toString("base64"); - } else { - const bin: string[] = []; - arr.forEach((byte) => { - bin.push(String.fromCharCode(byte)); - }); - return tsProtoGlobalThis.btoa(bin.join("")); - } -} - -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; - -type DeepPartial = T extends Builtin ? T - : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> - : T extends {} ? { [K in keyof T]?: DeepPartial } - : Partial; - -type KeysOfUnion = T extends T ? keyof T : never; -type Exact = P extends Builtin ? P - : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; - -function longToNumber(long: Long): number { - if (long.gt(Number.MAX_SAFE_INTEGER)) { - throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); - } - return long.toNumber(); -} - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any; - _m0.configure(); -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined; -} diff --git a/packages/hub-web/src/generated/request_response.ts b/packages/hub-web/src/generated/request_response.ts index 337b7087d9..cb7a549166 100644 --- a/packages/hub-web/src/generated/request_response.ts +++ b/packages/hub-web/src/generated/request_response.ts @@ -15,6 +15,59 @@ import { import { OnChainEvent, OnChainEventType, onChainEventTypeFromJSON, onChainEventTypeToJSON } from "./onchain_event"; import { UserNameProof } from "./username_proof"; +export enum StoreType { + NONE = 0, + CASTS = 1, + LINKS = 2, + REACTIONS = 3, + USER_DATA = 4, + VERIFICATIONS = 5, +} + +export function storeTypeFromJSON(object: any): StoreType { + switch (object) { + case 0: + case "STORE_TYPE_NONE": + return StoreType.NONE; + case 1: + case "STORE_TYPE_CASTS": + return StoreType.CASTS; + case 2: + case "STORE_TYPE_LINKS": + return StoreType.LINKS; + case 3: + case "STORE_TYPE_REACTIONS": + return StoreType.REACTIONS; + case 4: + case "STORE_TYPE_USER_DATA": + return StoreType.USER_DATA; + case 5: + case "STORE_TYPE_VERIFICATIONS": + return StoreType.VERIFICATIONS; + default: + throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StoreType"); + } +} + +export function storeTypeToJSON(object: StoreType): string { + switch (object) { + case StoreType.NONE: + return "STORE_TYPE_NONE"; + case StoreType.CASTS: + return "STORE_TYPE_CASTS"; + case StoreType.LINKS: + return "STORE_TYPE_LINKS"; + case StoreType.REACTIONS: + return "STORE_TYPE_REACTIONS"; + case StoreType.USER_DATA: + return "STORE_TYPE_USER_DATA"; + case StoreType.VERIFICATIONS: + return "STORE_TYPE_VERIFICATIONS"; + default: + throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StoreType"); + } +} + export interface Empty { } @@ -169,6 +222,15 @@ export interface StorageAdminRegistryEventRequest { transactionHash: Uint8Array; } +export interface StorageLimitsResponse { + limits: StorageLimit[]; +} + +export interface StorageLimit { + storeType: StoreType; + limit: number; +} + export interface UsernameProofRequest { name: Uint8Array; } @@ -2460,6 +2522,137 @@ export const StorageAdminRegistryEventRequest = { }, }; +function createBaseStorageLimitsResponse(): StorageLimitsResponse { + return { limits: [] }; +} + +export const StorageLimitsResponse = { + encode(message: StorageLimitsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + for (const v of message.limits) { + StorageLimit.encode(v!, writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): StorageLimitsResponse { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseStorageLimitsResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag != 10) { + break; + } + + message.limits.push(StorageLimit.decode(reader, reader.uint32())); + continue; + } + if ((tag & 7) == 4 || tag == 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): StorageLimitsResponse { + return { limits: Array.isArray(object?.limits) ? object.limits.map((e: any) => StorageLimit.fromJSON(e)) : [] }; + }, + + toJSON(message: StorageLimitsResponse): unknown { + const obj: any = {}; + if (message.limits) { + obj.limits = message.limits.map((e) => e ? StorageLimit.toJSON(e) : undefined); + } else { + obj.limits = []; + } + return obj; + }, + + create, I>>(base?: I): StorageLimitsResponse { + return StorageLimitsResponse.fromPartial(base ?? {}); + }, + + fromPartial, I>>(object: I): StorageLimitsResponse { + const message = createBaseStorageLimitsResponse(); + message.limits = object.limits?.map((e) => StorageLimit.fromPartial(e)) || []; + return message; + }, +}; + +function createBaseStorageLimit(): StorageLimit { + return { storeType: 0, limit: 0 }; +} + +export const StorageLimit = { + encode(message: StorageLimit, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.storeType !== 0) { + writer.uint32(8).int32(message.storeType); + } + if (message.limit !== 0) { + writer.uint32(16).uint64(message.limit); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): StorageLimit { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseStorageLimit(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag != 8) { + break; + } + + message.storeType = reader.int32() as any; + continue; + case 2: + if (tag != 16) { + break; + } + + message.limit = longToNumber(reader.uint64() as Long); + continue; + } + if ((tag & 7) == 4 || tag == 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): StorageLimit { + return { + storeType: isSet(object.storeType) ? storeTypeFromJSON(object.storeType) : 0, + limit: isSet(object.limit) ? Number(object.limit) : 0, + }; + }, + + toJSON(message: StorageLimit): unknown { + const obj: any = {}; + message.storeType !== undefined && (obj.storeType = storeTypeToJSON(message.storeType)); + message.limit !== undefined && (obj.limit = Math.round(message.limit)); + return obj; + }, + + create, I>>(base?: I): StorageLimit { + return StorageLimit.fromPartial(base ?? {}); + }, + + fromPartial, I>>(object: I): StorageLimit { + const message = createBaseStorageLimit(); + message.storeType = object.storeType ?? 0; + message.limit = object.limit ?? 0; + return message; + }, +}; + function createBaseUsernameProofRequest(): UsernameProofRequest { return { name: new Uint8Array() }; } diff --git a/packages/hub-web/src/generated/rpc.ts b/packages/hub-web/src/generated/rpc.ts index da182bf97d..693b4759bd 100644 --- a/packages/hub-web/src/generated/rpc.ts +++ b/packages/hub-web/src/generated/rpc.ts @@ -31,6 +31,7 @@ import { ReactionsByFidRequest, ReactionsByTargetRequest, SignerRequest, + StorageLimitsResponse, SubscribeRequest, SyncIds, SyncStatusRequest, @@ -76,6 +77,10 @@ export interface HubService { metadata?: grpcWeb.grpc.Metadata, ): Promise; getOnChainEvents(request: DeepPartial, metadata?: grpcWeb.grpc.Metadata): Promise; + getCurrentStorageLimitsByFid( + request: DeepPartial, + metadata?: grpcWeb.grpc.Metadata, + ): Promise; /** Username Proof */ getUsernameProof(request: DeepPartial, metadata?: grpcWeb.grpc.Metadata): Promise; getUserNameProofsByFid(request: DeepPartial, metadata?: grpcWeb.grpc.Metadata): Promise; @@ -141,6 +146,7 @@ export class HubServiceClientImpl implements HubService { this.getUserDataByFid = this.getUserDataByFid.bind(this); this.getNameRegistryEvent = this.getNameRegistryEvent.bind(this); this.getOnChainEvents = this.getOnChainEvents.bind(this); + this.getCurrentStorageLimitsByFid = this.getCurrentStorageLimitsByFid.bind(this); this.getUsernameProof = this.getUsernameProof.bind(this); this.getUserNameProofsByFid = this.getUserNameProofsByFid.bind(this); this.getVerification = this.getVerification.bind(this); @@ -237,6 +243,13 @@ export class HubServiceClientImpl implements HubService { return this.rpc.unary(HubServiceGetOnChainEventsDesc, OnChainEventRequest.fromPartial(request), metadata); } + getCurrentStorageLimitsByFid( + request: DeepPartial, + metadata?: grpcWeb.grpc.Metadata, + ): Promise { + return this.rpc.unary(HubServiceGetCurrentStorageLimitsByFidDesc, FidRequest.fromPartial(request), metadata); + } + getUsernameProof(request: DeepPartial, metadata?: grpcWeb.grpc.Metadata): Promise { return this.rpc.unary(HubServiceGetUsernameProofDesc, UsernameProofRequest.fromPartial(request), metadata); } @@ -701,6 +714,29 @@ export const HubServiceGetOnChainEventsDesc: UnaryMethodDefinitionish = { } as any, }; +export const HubServiceGetCurrentStorageLimitsByFidDesc: UnaryMethodDefinitionish = { + methodName: "GetCurrentStorageLimitsByFid", + service: HubServiceDesc, + requestStream: false, + responseStream: false, + requestType: { + serializeBinary() { + return FidRequest.encode(this).finish(); + }, + } as any, + responseType: { + deserializeBinary(data: Uint8Array) { + const value = StorageLimitsResponse.decode(data); + return { + ...value, + toObject() { + return value; + }, + }; + }, + } as any, +}; + export const HubServiceGetUsernameProofDesc: UnaryMethodDefinitionish = { methodName: "GetUsernameProof", service: HubServiceDesc, diff --git a/packages/hub-web/src/generated/storage_event.ts b/packages/hub-web/src/generated/storage_event.ts deleted file mode 100644 index 55208ae73c..0000000000 --- a/packages/hub-web/src/generated/storage_event.ts +++ /dev/null @@ -1,491 +0,0 @@ -/* eslint-disable */ -import Long from "long"; -import _m0 from "protobufjs/minimal"; - -export enum StorageRegistryEventType { - NONE = 0, - RENT = 1, - SET_PRICE = 2, - SET_MAX_UNITS = 3, - SET_DEPRECATION_TIMESTAMP = 4, - SET_GRACE_PERIOD = 5, -} - -export function storageRegistryEventTypeFromJSON(object: any): StorageRegistryEventType { - switch (object) { - case 0: - case "STORAGE_REGISTRY_EVENT_TYPE_NONE": - return StorageRegistryEventType.NONE; - case 1: - case "STORAGE_REGISTRY_EVENT_TYPE_RENT": - return StorageRegistryEventType.RENT; - case 2: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_PRICE": - return StorageRegistryEventType.SET_PRICE; - case 3: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_MAX_UNITS": - return StorageRegistryEventType.SET_MAX_UNITS; - case 4: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_DEPRECATION_TIMESTAMP": - return StorageRegistryEventType.SET_DEPRECATION_TIMESTAMP; - case 5: - case "STORAGE_REGISTRY_EVENT_TYPE_SET_GRACE_PERIOD": - return StorageRegistryEventType.SET_GRACE_PERIOD; - default: - throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StorageRegistryEventType"); - } -} - -export function storageRegistryEventTypeToJSON(object: StorageRegistryEventType): string { - switch (object) { - case StorageRegistryEventType.NONE: - return "STORAGE_REGISTRY_EVENT_TYPE_NONE"; - case StorageRegistryEventType.RENT: - return "STORAGE_REGISTRY_EVENT_TYPE_RENT"; - case StorageRegistryEventType.SET_PRICE: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_PRICE"; - case StorageRegistryEventType.SET_MAX_UNITS: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_MAX_UNITS"; - case StorageRegistryEventType.SET_DEPRECATION_TIMESTAMP: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_DEPRECATION_TIMESTAMP"; - case StorageRegistryEventType.SET_GRACE_PERIOD: - return "STORAGE_REGISTRY_EVENT_TYPE_SET_GRACE_PERIOD"; - default: - throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum StorageRegistryEventType"); - } -} - -export interface RentRegistryEvent { - blockNumber: number; - blockHash: Uint8Array; - transactionHash: Uint8Array; - logIndex: number; - payer: Uint8Array; - fid: number; - type: StorageRegistryEventType; - units: number; - expiry: number; -} - -export interface StorageAdminRegistryEvent { - blockNumber: number; - blockHash: Uint8Array; - transactionHash: Uint8Array; - logIndex: number; - timestamp: number; - from: Uint8Array; - type: StorageRegistryEventType; - value: Uint8Array; -} - -function createBaseRentRegistryEvent(): RentRegistryEvent { - return { - blockNumber: 0, - blockHash: new Uint8Array(), - transactionHash: new Uint8Array(), - logIndex: 0, - payer: new Uint8Array(), - fid: 0, - type: 0, - units: 0, - expiry: 0, - }; -} - -export const RentRegistryEvent = { - encode(message: RentRegistryEvent, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { - if (message.blockNumber !== 0) { - writer.uint32(8).uint32(message.blockNumber); - } - if (message.blockHash.length !== 0) { - writer.uint32(18).bytes(message.blockHash); - } - if (message.transactionHash.length !== 0) { - writer.uint32(26).bytes(message.transactionHash); - } - if (message.logIndex !== 0) { - writer.uint32(32).uint32(message.logIndex); - } - if (message.payer.length !== 0) { - writer.uint32(42).bytes(message.payer); - } - if (message.fid !== 0) { - writer.uint32(48).uint64(message.fid); - } - if (message.type !== 0) { - writer.uint32(56).int32(message.type); - } - if (message.units !== 0) { - writer.uint32(64).uint32(message.units); - } - if (message.expiry !== 0) { - writer.uint32(72).uint32(message.expiry); - } - return writer; - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): RentRegistryEvent { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); - let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseRentRegistryEvent(); - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - if (tag != 8) { - break; - } - - message.blockNumber = reader.uint32(); - continue; - case 2: - if (tag != 18) { - break; - } - - message.blockHash = reader.bytes(); - continue; - case 3: - if (tag != 26) { - break; - } - - message.transactionHash = reader.bytes(); - continue; - case 4: - if (tag != 32) { - break; - } - - message.logIndex = reader.uint32(); - continue; - case 5: - if (tag != 42) { - break; - } - - message.payer = reader.bytes(); - continue; - case 6: - if (tag != 48) { - break; - } - - message.fid = longToNumber(reader.uint64() as Long); - continue; - case 7: - if (tag != 56) { - break; - } - - message.type = reader.int32() as any; - continue; - case 8: - if (tag != 64) { - break; - } - - message.units = reader.uint32(); - continue; - case 9: - if (tag != 72) { - break; - } - - message.expiry = reader.uint32(); - continue; - } - if ((tag & 7) == 4 || tag == 0) { - break; - } - reader.skipType(tag & 7); - } - return message; - }, - - fromJSON(object: any): RentRegistryEvent { - return { - blockNumber: isSet(object.blockNumber) ? Number(object.blockNumber) : 0, - blockHash: isSet(object.blockHash) ? bytesFromBase64(object.blockHash) : new Uint8Array(), - transactionHash: isSet(object.transactionHash) ? bytesFromBase64(object.transactionHash) : new Uint8Array(), - logIndex: isSet(object.logIndex) ? Number(object.logIndex) : 0, - payer: isSet(object.payer) ? bytesFromBase64(object.payer) : new Uint8Array(), - fid: isSet(object.fid) ? Number(object.fid) : 0, - type: isSet(object.type) ? storageRegistryEventTypeFromJSON(object.type) : 0, - units: isSet(object.units) ? Number(object.units) : 0, - expiry: isSet(object.expiry) ? Number(object.expiry) : 0, - }; - }, - - toJSON(message: RentRegistryEvent): unknown { - const obj: any = {}; - message.blockNumber !== undefined && (obj.blockNumber = Math.round(message.blockNumber)); - message.blockHash !== undefined && - (obj.blockHash = base64FromBytes(message.blockHash !== undefined ? message.blockHash : new Uint8Array())); - message.transactionHash !== undefined && - (obj.transactionHash = base64FromBytes( - message.transactionHash !== undefined ? message.transactionHash : new Uint8Array(), - )); - message.logIndex !== undefined && (obj.logIndex = Math.round(message.logIndex)); - message.payer !== undefined && - (obj.payer = base64FromBytes(message.payer !== undefined ? message.payer : new Uint8Array())); - message.fid !== undefined && (obj.fid = Math.round(message.fid)); - message.type !== undefined && (obj.type = storageRegistryEventTypeToJSON(message.type)); - message.units !== undefined && (obj.units = Math.round(message.units)); - message.expiry !== undefined && (obj.expiry = Math.round(message.expiry)); - return obj; - }, - - create, I>>(base?: I): RentRegistryEvent { - return RentRegistryEvent.fromPartial(base ?? {}); - }, - - fromPartial, I>>(object: I): RentRegistryEvent { - const message = createBaseRentRegistryEvent(); - message.blockNumber = object.blockNumber ?? 0; - message.blockHash = object.blockHash ?? new Uint8Array(); - message.transactionHash = object.transactionHash ?? new Uint8Array(); - message.logIndex = object.logIndex ?? 0; - message.payer = object.payer ?? new Uint8Array(); - message.fid = object.fid ?? 0; - message.type = object.type ?? 0; - message.units = object.units ?? 0; - message.expiry = object.expiry ?? 0; - return message; - }, -}; - -function createBaseStorageAdminRegistryEvent(): StorageAdminRegistryEvent { - return { - blockNumber: 0, - blockHash: new Uint8Array(), - transactionHash: new Uint8Array(), - logIndex: 0, - timestamp: 0, - from: new Uint8Array(), - type: 0, - value: new Uint8Array(), - }; -} - -export const StorageAdminRegistryEvent = { - encode(message: StorageAdminRegistryEvent, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { - if (message.blockNumber !== 0) { - writer.uint32(8).uint32(message.blockNumber); - } - if (message.blockHash.length !== 0) { - writer.uint32(18).bytes(message.blockHash); - } - if (message.transactionHash.length !== 0) { - writer.uint32(26).bytes(message.transactionHash); - } - if (message.logIndex !== 0) { - writer.uint32(32).uint32(message.logIndex); - } - if (message.timestamp !== 0) { - writer.uint32(40).uint64(message.timestamp); - } - if (message.from.length !== 0) { - writer.uint32(50).bytes(message.from); - } - if (message.type !== 0) { - writer.uint32(56).int32(message.type); - } - if (message.value.length !== 0) { - writer.uint32(66).bytes(message.value); - } - return writer; - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): StorageAdminRegistryEvent { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); - let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseStorageAdminRegistryEvent(); - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - if (tag != 8) { - break; - } - - message.blockNumber = reader.uint32(); - continue; - case 2: - if (tag != 18) { - break; - } - - message.blockHash = reader.bytes(); - continue; - case 3: - if (tag != 26) { - break; - } - - message.transactionHash = reader.bytes(); - continue; - case 4: - if (tag != 32) { - break; - } - - message.logIndex = reader.uint32(); - continue; - case 5: - if (tag != 40) { - break; - } - - message.timestamp = longToNumber(reader.uint64() as Long); - continue; - case 6: - if (tag != 50) { - break; - } - - message.from = reader.bytes(); - continue; - case 7: - if (tag != 56) { - break; - } - - message.type = reader.int32() as any; - continue; - case 8: - if (tag != 66) { - break; - } - - message.value = reader.bytes(); - continue; - } - if ((tag & 7) == 4 || tag == 0) { - break; - } - reader.skipType(tag & 7); - } - return message; - }, - - fromJSON(object: any): StorageAdminRegistryEvent { - return { - blockNumber: isSet(object.blockNumber) ? Number(object.blockNumber) : 0, - blockHash: isSet(object.blockHash) ? bytesFromBase64(object.blockHash) : new Uint8Array(), - transactionHash: isSet(object.transactionHash) ? bytesFromBase64(object.transactionHash) : new Uint8Array(), - logIndex: isSet(object.logIndex) ? Number(object.logIndex) : 0, - timestamp: isSet(object.timestamp) ? Number(object.timestamp) : 0, - from: isSet(object.from) ? bytesFromBase64(object.from) : new Uint8Array(), - type: isSet(object.type) ? storageRegistryEventTypeFromJSON(object.type) : 0, - value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(), - }; - }, - - toJSON(message: StorageAdminRegistryEvent): unknown { - const obj: any = {}; - message.blockNumber !== undefined && (obj.blockNumber = Math.round(message.blockNumber)); - message.blockHash !== undefined && - (obj.blockHash = base64FromBytes(message.blockHash !== undefined ? message.blockHash : new Uint8Array())); - message.transactionHash !== undefined && - (obj.transactionHash = base64FromBytes( - message.transactionHash !== undefined ? message.transactionHash : new Uint8Array(), - )); - message.logIndex !== undefined && (obj.logIndex = Math.round(message.logIndex)); - message.timestamp !== undefined && (obj.timestamp = Math.round(message.timestamp)); - message.from !== undefined && - (obj.from = base64FromBytes(message.from !== undefined ? message.from : new Uint8Array())); - message.type !== undefined && (obj.type = storageRegistryEventTypeToJSON(message.type)); - message.value !== undefined && - (obj.value = base64FromBytes(message.value !== undefined ? message.value : new Uint8Array())); - return obj; - }, - - create, I>>(base?: I): StorageAdminRegistryEvent { - return StorageAdminRegistryEvent.fromPartial(base ?? {}); - }, - - fromPartial, I>>(object: I): StorageAdminRegistryEvent { - const message = createBaseStorageAdminRegistryEvent(); - message.blockNumber = object.blockNumber ?? 0; - message.blockHash = object.blockHash ?? new Uint8Array(); - message.transactionHash = object.transactionHash ?? new Uint8Array(); - message.logIndex = object.logIndex ?? 0; - message.timestamp = object.timestamp ?? 0; - message.from = object.from ?? new Uint8Array(); - message.type = object.type ?? 0; - message.value = object.value ?? new Uint8Array(); - return message; - }, -}; - -declare var self: any | undefined; -declare var window: any | undefined; -declare var global: any | undefined; -var tsProtoGlobalThis: any = (() => { - if (typeof globalThis !== "undefined") { - return globalThis; - } - if (typeof self !== "undefined") { - return self; - } - if (typeof window !== "undefined") { - return window; - } - if (typeof global !== "undefined") { - return global; - } - throw "Unable to locate global object"; -})(); - -function bytesFromBase64(b64: string): Uint8Array { - if (tsProtoGlobalThis.Buffer) { - return Uint8Array.from(tsProtoGlobalThis.Buffer.from(b64, "base64")); - } else { - const bin = tsProtoGlobalThis.atob(b64); - const arr = new Uint8Array(bin.length); - for (let i = 0; i < bin.length; ++i) { - arr[i] = bin.charCodeAt(i); - } - return arr; - } -} - -function base64FromBytes(arr: Uint8Array): string { - if (tsProtoGlobalThis.Buffer) { - return tsProtoGlobalThis.Buffer.from(arr).toString("base64"); - } else { - const bin: string[] = []; - arr.forEach((byte) => { - bin.push(String.fromCharCode(byte)); - }); - return tsProtoGlobalThis.btoa(bin.join("")); - } -} - -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; - -type DeepPartial = T extends Builtin ? T - : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> - : T extends {} ? { [K in keyof T]?: DeepPartial } - : Partial; - -type KeysOfUnion = T extends T ? keyof T : never; -type Exact = P extends Builtin ? P - : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; - -function longToNumber(long: Long): number { - if (long.gt(Number.MAX_SAFE_INTEGER)) { - throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); - } - return long.toNumber(); -} - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any; - _m0.configure(); -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined; -} diff --git a/protobufs/docs/rpc.md b/protobufs/docs/rpc.md index 3dd8870e5b..1b6781b2b8 100644 --- a/protobufs/docs/rpc.md +++ b/protobufs/docs/rpc.md @@ -42,11 +42,13 @@ Used to retrieve valid and revoked Signers Users to retrieve the current metadata associated with a user -| Method Name | Request Type | Response Type | Description | -| --------------------------- | --------------- | ---------------- | -------------------------------------- | -| GetUserData | UserDataRequest | Message | Returns a specific UserData for an Fid | -| GetUserDataByFid | FidRequest | MessagesResponse | Returns all UserData for an Fid | -| GetAllUserDataMessagesByFid | FidRequest | MessagesResponse | Returns all UserData for an Fid | +| Method Name | Request Type | Response Type | Description | +| ---------------------------- | ------------------------- | -------------------------- | ----------------------------------------- | +| GetUserData | UserDataRequest | Message | Returns a specific UserData for an Fid | +| GetUserDataByFid | FidRequest | MessagesResponse | Returns all UserData for an Fid | +| GetAllUserDataMessagesByFid | FidRequest | MessagesResponse | Returns all UserData for an Fid | +| GetRentRegistryEvents | RentRegistryEventsRequest | RentRegistryEventsResponse | Returns all RentRegistryEvents for an Fid | +| GetCurrentStorageLimitsByFid | FidRequest | StorageLimitsResponse | Returns StorageLimits for an Fid | #### UserData Request @@ -55,6 +57,20 @@ Users to retrieve the current metadata associated with a user | fid | [uint64](#) | | Farcaster ID of the user who generated the UserData | | user_data_type | [UserDataType](#) | | Type of UserData being requested | + +#### StorageLimitsResponse + +| Field | Type | Label | Description | +| -------------- | ---------------------------- | -------- | ----------------------------- | +| limits | [StorageLimit](#) | repeated | Storage limits per store type | + +#### StorageLimit + +| Field | Type | Label | Description | +| ---------- |----------------| ----- | ------------------------------------------------------ | +| store_type | [StoreType](#) | | The specific type being managed by the store | +| limit | [uint64](#) | | The limit of the store type, scaled by the user's rent | + ## 3. Cast Service Used to retrieve valid casts or tombstones for deleted casts diff --git a/protobufs/schemas/request_response.proto b/protobufs/schemas/request_response.proto index 64c7ba3e05..0b7b2606af 100644 --- a/protobufs/schemas/request_response.proto +++ b/protobufs/schemas/request_response.proto @@ -160,8 +160,22 @@ message OnChainEventResponse { repeated OnChainEvent events = 1; } -message StorageAdminRegistryEventRequest { - bytes transaction_hash = 1; +message StorageLimitsResponse { + repeated StorageLimit limits = 1; +} + +enum StoreType { + STORE_TYPE_NONE = 0; + STORE_TYPE_CASTS = 1; + STORE_TYPE_LINKS = 2; + STORE_TYPE_REACTIONS = 3; + STORE_TYPE_USER_DATA = 4; + STORE_TYPE_VERIFICATIONS = 5; +} + +message StorageLimit { + StoreType store_type = 1; + uint64 limit = 2; } message UsernameProofRequest { diff --git a/protobufs/schemas/rpc.proto b/protobufs/schemas/rpc.proto index 69bb4d4276..e72a825a23 100644 --- a/protobufs/schemas/rpc.proto +++ b/protobufs/schemas/rpc.proto @@ -33,6 +33,7 @@ service HubService { rpc GetUserDataByFid(FidRequest) returns (MessagesResponse); rpc GetNameRegistryEvent(NameRegistryEventRequest) returns (NameRegistryEvent); rpc GetOnChainEvents(OnChainEventRequest) returns (OnChainEventResponse); + rpc GetCurrentStorageLimitsByFid(FidRequest) returns (StorageLimitsResponse); // Username Proof rpc GetUsernameProof(UsernameProofRequest) returns (UserNameProof);