Skip to content

Commit

Permalink
chore(sdk): add handlerName to OnIntervalConfig&TraceHandlerConfig (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rnons authored Dec 18, 2024
1 parent 2693ec4 commit dfd34d6
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/protos/processor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ message OnIntervalConfig {

// eth fetch config
EthFetchConfig fetch_config = 6;

string handler_name = 7;
}

message AptosOnIntervalConfig {
Expand Down Expand Up @@ -302,6 +304,7 @@ message TraceHandlerConfig {
message TransactionHandlerConfig {
int32 handler_id = 1;
EthFetchConfig fetch_config = 3;
string handler_name = 4;
}

message LogHandlerConfig {
Expand Down
35 changes: 34 additions & 1 deletion packages/protos/src/processor/protos/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ export interface OnIntervalConfig {
slot: number;
slotInterval?: HandleInterval | undefined;
fetchConfig: EthFetchConfig | undefined;
handlerName: string;
}

export interface AptosOnIntervalConfig {
Expand Down Expand Up @@ -664,6 +665,7 @@ export interface TraceHandlerConfig {
export interface TransactionHandlerConfig {
handlerId: number;
fetchConfig: EthFetchConfig | undefined;
handlerName: string;
}

export interface LogHandlerConfig {
Expand Down Expand Up @@ -3318,6 +3320,7 @@ function createBaseOnIntervalConfig(): OnIntervalConfig {
slot: 0,
slotInterval: undefined,
fetchConfig: undefined,
handlerName: "",
};
}

Expand All @@ -3341,6 +3344,9 @@ export const OnIntervalConfig = {
if (message.fetchConfig !== undefined) {
EthFetchConfig.encode(message.fetchConfig, writer.uint32(50).fork()).ldelim();
}
if (message.handlerName !== "") {
writer.uint32(58).string(message.handlerName);
}
return writer;
},

Expand Down Expand Up @@ -3393,6 +3399,13 @@ export const OnIntervalConfig = {

message.fetchConfig = EthFetchConfig.decode(reader, reader.uint32());
continue;
case 7:
if (tag !== 58) {
break;
}

message.handlerName = reader.string();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
Expand All @@ -3410,6 +3423,7 @@ export const OnIntervalConfig = {
slot: isSet(object.slot) ? globalThis.Number(object.slot) : 0,
slotInterval: isSet(object.slotInterval) ? HandleInterval.fromJSON(object.slotInterval) : undefined,
fetchConfig: isSet(object.fetchConfig) ? EthFetchConfig.fromJSON(object.fetchConfig) : undefined,
handlerName: isSet(object.handlerName) ? globalThis.String(object.handlerName) : "",
};
},

Expand All @@ -3433,6 +3447,9 @@ export const OnIntervalConfig = {
if (message.fetchConfig !== undefined) {
obj.fetchConfig = EthFetchConfig.toJSON(message.fetchConfig);
}
if (message.handlerName !== "") {
obj.handlerName = message.handlerName;
}
return obj;
},

Expand All @@ -3453,6 +3470,7 @@ export const OnIntervalConfig = {
message.fetchConfig = (object.fetchConfig !== undefined && object.fetchConfig !== null)
? EthFetchConfig.fromPartial(object.fetchConfig)
: undefined;
message.handlerName = object.handlerName ?? "";
return message;
},
};
Expand Down Expand Up @@ -4237,7 +4255,7 @@ export const TraceHandlerConfig = {
};

function createBaseTransactionHandlerConfig(): TransactionHandlerConfig {
return { handlerId: 0, fetchConfig: undefined };
return { handlerId: 0, fetchConfig: undefined, handlerName: "" };
}

export const TransactionHandlerConfig = {
Expand All @@ -4248,6 +4266,9 @@ export const TransactionHandlerConfig = {
if (message.fetchConfig !== undefined) {
EthFetchConfig.encode(message.fetchConfig, writer.uint32(26).fork()).ldelim();
}
if (message.handlerName !== "") {
writer.uint32(34).string(message.handlerName);
}
return writer;
},

Expand All @@ -4272,6 +4293,13 @@ export const TransactionHandlerConfig = {

message.fetchConfig = EthFetchConfig.decode(reader, reader.uint32());
continue;
case 4:
if (tag !== 34) {
break;
}

message.handlerName = reader.string();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
Expand All @@ -4285,6 +4313,7 @@ export const TransactionHandlerConfig = {
return {
handlerId: isSet(object.handlerId) ? globalThis.Number(object.handlerId) : 0,
fetchConfig: isSet(object.fetchConfig) ? EthFetchConfig.fromJSON(object.fetchConfig) : undefined,
handlerName: isSet(object.handlerName) ? globalThis.String(object.handlerName) : "",
};
},

Expand All @@ -4296,6 +4325,9 @@ export const TransactionHandlerConfig = {
if (message.fetchConfig !== undefined) {
obj.fetchConfig = EthFetchConfig.toJSON(message.fetchConfig);
}
if (message.handlerName !== "") {
obj.handlerName = message.handlerName;
}
return obj;
},

Expand All @@ -4308,6 +4340,7 @@ export const TransactionHandlerConfig = {
message.fetchConfig = (object.fetchConfig !== undefined && object.fetchConfig !== null)
? EthFetchConfig.fromPartial(object.fetchConfig)
: undefined;
message.handlerName = object.handlerName ?? "";
return message;
},
};
Expand Down
35 changes: 34 additions & 1 deletion packages/runtime/src/gen/processor/protos/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ export interface OnIntervalConfig {
slot: number;
slotInterval?: HandleInterval | undefined;
fetchConfig: EthFetchConfig | undefined;
handlerName: string;
}

export interface AptosOnIntervalConfig {
Expand Down Expand Up @@ -666,6 +667,7 @@ export interface TraceHandlerConfig {
export interface TransactionHandlerConfig {
handlerId: number;
fetchConfig: EthFetchConfig | undefined;
handlerName: string;
}

export interface LogHandlerConfig {
Expand Down Expand Up @@ -3357,6 +3359,7 @@ function createBaseOnIntervalConfig(): OnIntervalConfig {
slot: 0,
slotInterval: undefined,
fetchConfig: undefined,
handlerName: "",
};
}

Expand All @@ -3380,6 +3383,9 @@ export const OnIntervalConfig = {
if (message.fetchConfig !== undefined) {
EthFetchConfig.encode(message.fetchConfig, writer.uint32(50).fork()).ldelim();
}
if (message.handlerName !== "") {
writer.uint32(58).string(message.handlerName);
}
return writer;
},

Expand Down Expand Up @@ -3432,6 +3438,13 @@ export const OnIntervalConfig = {

message.fetchConfig = EthFetchConfig.decode(reader, reader.uint32());
continue;
case 7:
if (tag !== 58) {
break;
}

message.handlerName = reader.string();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
Expand All @@ -3449,6 +3462,7 @@ export const OnIntervalConfig = {
slot: isSet(object.slot) ? globalThis.Number(object.slot) : 0,
slotInterval: isSet(object.slotInterval) ? HandleInterval.fromJSON(object.slotInterval) : undefined,
fetchConfig: isSet(object.fetchConfig) ? EthFetchConfig.fromJSON(object.fetchConfig) : undefined,
handlerName: isSet(object.handlerName) ? globalThis.String(object.handlerName) : "",
};
},

Expand All @@ -3472,6 +3486,9 @@ export const OnIntervalConfig = {
if (message.fetchConfig !== undefined) {
obj.fetchConfig = EthFetchConfig.toJSON(message.fetchConfig);
}
if (message.handlerName !== "") {
obj.handlerName = message.handlerName;
}
return obj;
},

Expand All @@ -3492,6 +3509,7 @@ export const OnIntervalConfig = {
message.fetchConfig = (object.fetchConfig !== undefined && object.fetchConfig !== null)
? EthFetchConfig.fromPartial(object.fetchConfig)
: undefined;
message.handlerName = object.handlerName ?? "";
return message;
},
};
Expand Down Expand Up @@ -4276,7 +4294,7 @@ export const TraceHandlerConfig = {
};

function createBaseTransactionHandlerConfig(): TransactionHandlerConfig {
return { handlerId: 0, fetchConfig: undefined };
return { handlerId: 0, fetchConfig: undefined, handlerName: "" };
}

export const TransactionHandlerConfig = {
Expand All @@ -4287,6 +4305,9 @@ export const TransactionHandlerConfig = {
if (message.fetchConfig !== undefined) {
EthFetchConfig.encode(message.fetchConfig, writer.uint32(26).fork()).ldelim();
}
if (message.handlerName !== "") {
writer.uint32(34).string(message.handlerName);
}
return writer;
},

Expand All @@ -4311,6 +4332,13 @@ export const TransactionHandlerConfig = {

message.fetchConfig = EthFetchConfig.decode(reader, reader.uint32());
continue;
case 4:
if (tag !== 34) {
break;
}

message.handlerName = reader.string();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
Expand All @@ -4324,6 +4352,7 @@ export const TransactionHandlerConfig = {
return {
handlerId: isSet(object.handlerId) ? globalThis.Number(object.handlerId) : 0,
fetchConfig: isSet(object.fetchConfig) ? EthFetchConfig.fromJSON(object.fetchConfig) : undefined,
handlerName: isSet(object.handlerName) ? globalThis.String(object.handlerName) : "",
};
},

Expand All @@ -4335,6 +4364,9 @@ export const TransactionHandlerConfig = {
if (message.fetchConfig !== undefined) {
obj.fetchConfig = EthFetchConfig.toJSON(message.fetchConfig);
}
if (message.handlerName !== "") {
obj.handlerName = message.handlerName;
}
return obj;
},

Expand All @@ -4347,6 +4379,7 @@ export const TransactionHandlerConfig = {
message.fetchConfig = (object.fetchConfig !== undefined && object.fetchConfig !== null)
? EthFetchConfig.fromPartial(object.fetchConfig)
: undefined;
message.handlerName = object.handlerName ?? "";
return message;
},
};
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/src/aptos/aptos-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class AptosPlugin extends Plugin {
contractConfig.moveIntervalConfigs.push({
intervalConfig: {
handlerId: handlerId,
handlerName: handler.handlerName,
minutes: 0,
minutesInterval: handler.timeIntervalInMinutes,
slot: 0,
Expand Down Expand Up @@ -170,6 +171,7 @@ export class AptosPlugin extends Plugin {
accountConfig.moveIntervalConfigs.push({
intervalConfig: {
handlerId: handlerId,
handlerName: handler.handlerName,
minutes: 0,
minutesInterval: handler.timeIntervalInMinutes,
slot: 0,
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/src/aptos/aptos-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ALL_ADDRESS, Labels, PromiseOrVoid } from '../core/index.js'
import { TypeDescriptor } from '@typemove/move'
import { decodeResourceChange, ResourceChange } from '@typemove/aptos'
import { GeneralTransactionResponse } from './models.js'
import { getHandlerName, proxyProcessor } from '../utils/metrics.js'

const DEFAULT_FETCH_CONFIG: MoveFetchConfig = {
resourceChanges: false,
Expand Down Expand Up @@ -263,6 +264,7 @@ export class AptosTransactionProcessor<T extends GeneralTransactionResponse, CT
): this {
const processor = this
this.transactionIntervalHandlers.push({
handlerName: getHandlerName(),
handler: async function (data) {
const transaction = data.transaction as T
const timestampMicros = BigInt(transaction.timestamp)
Expand Down Expand Up @@ -402,6 +404,8 @@ export class AptosResourcesProcessor {
protected constructor(options: AptosBindOptions) {
this.config = configure(options)
AptosResourceProcessorState.INSTANCE.addValue(this)

return proxyProcessor(this)
}

getChainId(): string {
Expand All @@ -417,6 +421,7 @@ export class AptosResourcesProcessor {
): this {
const processor = this
this.resourceIntervalHandlers.push({
handlerName: getHandlerName(),
handler: async function (data) {
if (data.timestampMicros > Number.MAX_SAFE_INTEGER) {
throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')
Expand Down Expand Up @@ -487,6 +492,7 @@ export class AptosResourcesProcessor {
const processor = this
this.resourceIntervalHandlers.push({
fetchConfig: DEFAULT_RESOURCE_FETCH_CONFIG,
handlerName: getHandlerName(),
handler: async function (data) {
const timestamp = Number(data.timestampMicros)

Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/btc/btc-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class BTCPlugin extends Plugin {
minutes: 0,
minutesInterval: blockHandler.timeIntervalInMinutes,
handlerId,
handlerName: blockHandler.handlerName,
fetchConfig: {
transaction: blockHandler.fetchConfig?.getTransactions ?? false,
trace: false,
Expand Down
6 changes: 5 additions & 1 deletion packages/sdk/src/btc/btc-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Data_BTCBlock, Data_BTCTransaction, HandleInterval, ProcessResult } fro
import { TransactionFilters } from './filter.js'
import { PromiseOrVoid } from '../core/index.js'
import { ServerError, Status } from 'nice-grpc'
import { getHandlerName, proxyProcessor } from '../utils/metrics.js'

export class BTCProcessorState extends ListStateStorage<BTCProcessor> {
static INSTANCE = new BTCProcessorState()
Expand All @@ -13,7 +14,9 @@ export class BTCProcessor {
callHandlers: CallHandler<Data_BTCTransaction>[] = []
blockHandlers: BlockHandler[] = []

constructor(readonly config: BTCProcessorConfig) {}
constructor(readonly config: BTCProcessorConfig) {
return proxyProcessor(this)
}

static bind(config: BTCProcessorConfig): BTCProcessor {
const processor = new BTCProcessor(config)
Expand Down Expand Up @@ -61,6 +64,7 @@ export class BTCProcessor {
this.blockHandlers.push({
blockInterval,
timeIntervalInMinutes: timeInterval,
handlerName: getHandlerName(),
handler: async function (data: Data_BTCBlock) {
const header = data.block
if (!header) {
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/btc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export type BlockHandler = {
blockInterval?: HandleInterval
timeIntervalInMinutes?: HandleInterval
handler: (block: Data_BTCBlock) => Promise<ProcessResult>
handlerName: string
fetchConfig?: BTCOnIntervalFetchConfig
}

Expand Down
Loading

0 comments on commit dfd34d6

Please sign in to comment.