Skip to content

Commit

Permalink
feat: add unused submitLegacyMessage endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
aditiharini committed Dec 5, 2024
1 parent 45e7ae1 commit 4fe4059
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 2 deletions.
10 changes: 10 additions & 0 deletions apps/hubble/src/rpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,16 @@ export default class Server {
getSyncSnapshotByPrefix: async (call, callback) => this.getSyncSnapshotByPrefixRPC(call, callback),
getOnChainSignersByFid: async (call, callback) => this.getOnChainSignersByFidRPC(call, callback),
getOnChainEvents: async (call, callback) => this.getOnChainEventsRPC(call, callback),
submitLegacyMessage: async (_call, callback) => {
callback(
toServiceError(
new HubError(
"not_implemented",
"submitLegacyMessage is only implemented on Snapchain nodes, not existing hubs",
),
),
);
},
submitMessage: async (call, callback) => {
// Identify peer that is calling, if available. This is used for rate limiting.
const peer = Result.fromThrowable(
Expand Down
62 changes: 62 additions & 0 deletions packages/core/src/protobufs/generated/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ export function protocolToJSON(object: Protocol): string {
}
}

/** This message exists to support uploading messages from existing hubs to new snapchain nodes via HubRpcClient */
export interface LegacyMessage {
data: Uint8Array;
}

/**
* A Message is a delta operation on the Farcaster network. The message protobuf is an envelope
* that wraps a MessageData object and contains a hash and signature which can verify its authenticity.
Expand Down Expand Up @@ -590,6 +595,63 @@ export interface FrameActionBody {
address: Uint8Array;
}

function createBaseLegacyMessage(): LegacyMessage {
return { data: new Uint8Array() };
}

export const LegacyMessage = {
encode(message: LegacyMessage, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.data.length !== 0) {
writer.uint32(10).bytes(message.data);
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): LegacyMessage {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseLegacyMessage();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag != 10) {
break;
}

message.data = reader.bytes();
continue;
}
if ((tag & 7) == 4 || tag == 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},

fromJSON(object: any): LegacyMessage {
return { data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array() };
},

toJSON(message: LegacyMessage): unknown {
const obj: any = {};
message.data !== undefined &&
(obj.data = base64FromBytes(message.data !== undefined ? message.data : new Uint8Array()));
return obj;
},

create<I extends Exact<DeepPartial<LegacyMessage>, I>>(base?: I): LegacyMessage {
return LegacyMessage.fromPartial(base ?? {});
},

fromPartial<I extends Exact<DeepPartial<LegacyMessage>, I>>(object: I): LegacyMessage {
const message = createBaseLegacyMessage();
message.data = object.data ?? new Uint8Array();
return message;
},
};

function createBaseMessage(): Message {
return {
data: undefined,
Expand Down
1 change: 1 addition & 0 deletions packages/hub-nodejs/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const fromServiceError = (err: ServiceError): HubError => {
if (err.code === 14 && err.details === "No connection established") {
context = `Connection failed: please check that the hub’s address, ports and authentication config are correct. ${context}`;
}
console.log(err);
return new HubError(err.metadata.get("errCode")[0] as HubErrorCode, context);
};

Expand Down
62 changes: 62 additions & 0 deletions packages/hub-nodejs/src/generated/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ export function protocolToJSON(object: Protocol): string {
}
}

/** This message exists to support uploading messages from existing hubs to new snapchain nodes via HubRpcClient */
export interface LegacyMessage {
data: Uint8Array;
}

/**
* A Message is a delta operation on the Farcaster network. The message protobuf is an envelope
* that wraps a MessageData object and contains a hash and signature which can verify its authenticity.
Expand Down Expand Up @@ -590,6 +595,63 @@ export interface FrameActionBody {
address: Uint8Array;
}

function createBaseLegacyMessage(): LegacyMessage {
return { data: new Uint8Array() };
}

export const LegacyMessage = {
encode(message: LegacyMessage, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.data.length !== 0) {
writer.uint32(10).bytes(message.data);
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): LegacyMessage {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseLegacyMessage();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag != 10) {
break;
}

message.data = reader.bytes();
continue;
}
if ((tag & 7) == 4 || tag == 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},

fromJSON(object: any): LegacyMessage {
return { data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array() };
},

toJSON(message: LegacyMessage): unknown {
const obj: any = {};
message.data !== undefined &&
(obj.data = base64FromBytes(message.data !== undefined ? message.data : new Uint8Array()));
return obj;
},

create<I extends Exact<DeepPartial<LegacyMessage>, I>>(base?: I): LegacyMessage {
return LegacyMessage.fromPartial(base ?? {});
},

fromPartial<I extends Exact<DeepPartial<LegacyMessage>, I>>(object: I): LegacyMessage {
const message = createBaseLegacyMessage();
message.data = object.data ?? new Uint8Array();
return message;
},
};

function createBaseMessage(): Message {
return {
data: undefined,
Expand Down
27 changes: 26 additions & 1 deletion packages/hub-nodejs/src/generated/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
UntypedServiceImplementation,
} from "@grpc/grpc-js";
import { HubEvent } from "./hub_event";
import { CastId, Message } from "./message";
import { CastId, LegacyMessage, Message } from "./message";
import { OnChainEvent } from "./onchain_event";
import {
CastsByParentRequest,
Expand Down Expand Up @@ -74,6 +74,15 @@ export const HubServiceService = {
responseSerialize: (value: Message) => Buffer.from(Message.encode(value).finish()),
responseDeserialize: (value: Buffer) => Message.decode(value),
},
submitLegacyMessage: {
path: "/HubService/SubmitLegacyMessage",
requestStream: false,
responseStream: false,
requestSerialize: (value: LegacyMessage) => Buffer.from(LegacyMessage.encode(value).finish()),
requestDeserialize: (value: Buffer) => LegacyMessage.decode(value),
responseSerialize: (value: LegacyMessage) => Buffer.from(LegacyMessage.encode(value).finish()),
responseDeserialize: (value: Buffer) => LegacyMessage.decode(value),
},
/** Validation Methods */
validateMessage: {
path: "/HubService/ValidateMessage",
Expand Down Expand Up @@ -554,6 +563,7 @@ export const HubServiceService = {
export interface HubServiceServer extends UntypedServiceImplementation {
/** Submit Methods */
submitMessage: handleUnaryCall<Message, Message>;
submitLegacyMessage: handleUnaryCall<LegacyMessage, LegacyMessage>;
/** Validation Methods */
validateMessage: handleUnaryCall<Message, ValidationResponse>;
/**
Expand Down Expand Up @@ -680,6 +690,21 @@ export interface HubServiceClient extends Client {
options: Partial<CallOptions>,
callback: (error: ServiceError | null, response: Message) => void,
): ClientUnaryCall;
submitLegacyMessage(
request: LegacyMessage,
callback: (error: ServiceError | null, response: LegacyMessage) => void,
): ClientUnaryCall;
submitLegacyMessage(
request: LegacyMessage,
metadata: Metadata,
callback: (error: ServiceError | null, response: LegacyMessage) => void,
): ClientUnaryCall;
submitLegacyMessage(
request: LegacyMessage,
metadata: Metadata,
options: Partial<CallOptions>,
callback: (error: ServiceError | null, response: LegacyMessage) => void,
): ClientUnaryCall;
/** Validation Methods */
validateMessage(
request: Message,
Expand Down
62 changes: 62 additions & 0 deletions packages/hub-web/src/generated/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ export function protocolToJSON(object: Protocol): string {
}
}

/** This message exists to support uploading messages from existing hubs to new snapchain nodes via HubRpcClient */
export interface LegacyMessage {
data: Uint8Array;
}

/**
* A Message is a delta operation on the Farcaster network. The message protobuf is an envelope
* that wraps a MessageData object and contains a hash and signature which can verify its authenticity.
Expand Down Expand Up @@ -590,6 +595,63 @@ export interface FrameActionBody {
address: Uint8Array;
}

function createBaseLegacyMessage(): LegacyMessage {
return { data: new Uint8Array() };
}

export const LegacyMessage = {
encode(message: LegacyMessage, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.data.length !== 0) {
writer.uint32(10).bytes(message.data);
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): LegacyMessage {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseLegacyMessage();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag != 10) {
break;
}

message.data = reader.bytes();
continue;
}
if ((tag & 7) == 4 || tag == 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},

fromJSON(object: any): LegacyMessage {
return { data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array() };
},

toJSON(message: LegacyMessage): unknown {
const obj: any = {};
message.data !== undefined &&
(obj.data = base64FromBytes(message.data !== undefined ? message.data : new Uint8Array()));
return obj;
},

create<I extends Exact<DeepPartial<LegacyMessage>, I>>(base?: I): LegacyMessage {
return LegacyMessage.fromPartial(base ?? {});
},

fromPartial<I extends Exact<DeepPartial<LegacyMessage>, I>>(object: I): LegacyMessage {
const message = createBaseLegacyMessage();
message.data = object.data ?? new Uint8Array();
return message;
},
};

function createBaseMessage(): Message {
return {
data: undefined,
Expand Down
31 changes: 30 additions & 1 deletion packages/hub-web/src/generated/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BrowserHeaders } from "browser-headers";
import { Observable } from "rxjs";
import { share } from "rxjs/operators";
import { HubEvent } from "./hub_event";
import { CastId, Message } from "./message";
import { CastId, LegacyMessage, Message } from "./message";
import { OnChainEvent } from "./onchain_event";
import {
CastsByParentRequest,
Expand Down Expand Up @@ -53,6 +53,7 @@ import { UserNameProof } from "./username_proof";
export interface HubService {
/** Submit Methods */
submitMessage(request: DeepPartial<Message>, metadata?: grpcWeb.grpc.Metadata): Promise<Message>;
submitLegacyMessage(request: DeepPartial<LegacyMessage>, metadata?: grpcWeb.grpc.Metadata): Promise<LegacyMessage>;
/** Validation Methods */
validateMessage(request: DeepPartial<Message>, metadata?: grpcWeb.grpc.Metadata): Promise<ValidationResponse>;
/**
Expand Down Expand Up @@ -216,6 +217,7 @@ export class HubServiceClientImpl implements HubService {
constructor(rpc: Rpc) {
this.rpc = rpc;
this.submitMessage = this.submitMessage.bind(this);
this.submitLegacyMessage = this.submitLegacyMessage.bind(this);
this.validateMessage = this.validateMessage.bind(this);
this.subscribe = this.subscribe.bind(this);
this.getEvent = this.getEvent.bind(this);
Expand Down Expand Up @@ -267,6 +269,10 @@ export class HubServiceClientImpl implements HubService {
return this.rpc.unary(HubServiceSubmitMessageDesc, Message.fromPartial(request), metadata);
}

submitLegacyMessage(request: DeepPartial<LegacyMessage>, metadata?: grpcWeb.grpc.Metadata): Promise<LegacyMessage> {
return this.rpc.unary(HubServiceSubmitLegacyMessageDesc, LegacyMessage.fromPartial(request), metadata);
}

validateMessage(request: DeepPartial<Message>, metadata?: grpcWeb.grpc.Metadata): Promise<ValidationResponse> {
return this.rpc.unary(HubServiceValidateMessageDesc, Message.fromPartial(request), metadata);
}
Expand Down Expand Up @@ -534,6 +540,29 @@ export const HubServiceSubmitMessageDesc: UnaryMethodDefinitionish = {
} as any,
};

export const HubServiceSubmitLegacyMessageDesc: UnaryMethodDefinitionish = {
methodName: "SubmitLegacyMessage",
service: HubServiceDesc,
requestStream: false,
responseStream: false,
requestType: {
serializeBinary() {
return LegacyMessage.encode(this).finish();
},
} as any,
responseType: {
deserializeBinary(data: Uint8Array) {
const value = LegacyMessage.decode(data);
return {
...value,
toObject() {
return value;
},
};
},
} as any,
};

export const HubServiceValidateMessageDesc: UnaryMethodDefinitionish = {
methodName: "ValidateMessage",
service: HubServiceDesc,
Expand Down
8 changes: 8 additions & 0 deletions protobufs/schemas/message.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
syntax = "proto3";
import "username_proof.proto";


/**
* This message exists to support uploading messages from existing hubs to new snapchain nodes via HubRpcClient
*/
message LegacyMessage {
bytes data = 1;
}

/**
* A Message is a delta operation on the Farcaster network. The message protobuf is an envelope
* that wraps a MessageData object and contains a hash and signature which can verify its authenticity.
Expand Down
1 change: 1 addition & 0 deletions protobufs/schemas/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import "onchain_event.proto";
service HubService {
// Submit Methods
rpc SubmitMessage(Message) returns (Message);
rpc SubmitLegacyMessage(LegacyMessage) returns (LegacyMessage);

// Validation Methods
rpc ValidateMessage(Message) returns (ValidationResponse);
Expand Down

0 comments on commit 4fe4059

Please sign in to comment.