Skip to content

Commit

Permalink
feat(sdk): add contract on interval processors, add object id/version…
Browse files Browse the repository at this point in the history
… into object context (#1082)
  • Loading branch information
zfy0701 authored Dec 13, 2024
1 parent 51be6e0 commit e73fade
Show file tree
Hide file tree
Showing 17 changed files with 707 additions and 74 deletions.
17 changes: 12 additions & 5 deletions packages/protos/processor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ message ProcessConfigResponse {
message ContractConfig {
ContractInfo contract = 1;
repeated OnIntervalConfig interval_configs = 11;
repeated MoveOnIntervalConfig move_interval_configs = 19;

repeated LogHandlerConfig log_configs = 3;
repeated TraceHandlerConfig trace_configs = 2;
repeated TransactionHandlerConfig transaction_config = 7;
Expand Down Expand Up @@ -251,9 +253,11 @@ enum MoveOwnerType {

message MoveOnIntervalConfig {
OnIntervalConfig interval_config = 1;
// type of the owned object to filter
string type = 2;
MoveOwnerType owner_type = 3;
MoveAccountFetchConfig fetch_config = 4;
MoveAccountFetchConfig resource_fetch_config = 4;
MoveFetchConfig fetch_config = 5;
}

message ContractInfo {
Expand Down Expand Up @@ -653,10 +657,13 @@ message Data {
uint64 slot = 3;
}
message SuiObject {
repeated google.protobuf.Struct objects = 1;
optional google.protobuf.Struct self = 4;
google.protobuf.Timestamp timestamp = 2;
uint64 slot = 3;
repeated google.protobuf.Struct objects = 1; // just details.content
optional google.protobuf.Struct self = 4; // just details.content
string object_id = 5; // self object property
uint64 object_version = 6; // self object property
string object_digest = 7; // self object property
google.protobuf.Timestamp timestamp = 2; // checkpoint timestamp
uint64 slot = 3; // checkpoint number
}
message SuiObjectChange {
repeated google.protobuf.Struct changes = 1;
Expand Down
114 changes: 106 additions & 8 deletions packages/protos/src/processor/protos/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ export interface ProcessConfigResponse {
export interface ContractConfig {
contract: ContractInfo | undefined;
intervalConfigs: OnIntervalConfig[];
moveIntervalConfigs: MoveOnIntervalConfig[];
logConfigs: LogHandlerConfig[];
traceConfigs: TraceHandlerConfig[];
transactionConfig: TransactionHandlerConfig[];
Expand Down Expand Up @@ -618,7 +619,8 @@ export interface MoveOnIntervalConfig {
intervalConfig: OnIntervalConfig | undefined;
type: string;
ownerType: MoveOwnerType;
fetchConfig: MoveAccountFetchConfig | undefined;
resourceFetchConfig: MoveAccountFetchConfig | undefined;
fetchConfig: MoveFetchConfig | undefined;
}

export interface ContractInfo {
Expand Down Expand Up @@ -1110,6 +1112,9 @@ export interface Data_SuiCall {
export interface Data_SuiObject {
objects: { [key: string]: any }[];
self?: { [key: string]: any } | undefined;
objectId: string;
objectVersion: bigint;
objectDigest: string;
timestamp: Date | undefined;
slot: bigint;
}
Expand Down Expand Up @@ -1724,6 +1729,7 @@ function createBaseContractConfig(): ContractConfig {
return {
contract: undefined,
intervalConfigs: [],
moveIntervalConfigs: [],
logConfigs: [],
traceConfigs: [],
transactionConfig: [],
Expand Down Expand Up @@ -1751,6 +1757,9 @@ export const ContractConfig = {
for (const v of message.intervalConfigs) {
OnIntervalConfig.encode(v!, writer.uint32(90).fork()).ldelim();
}
for (const v of message.moveIntervalConfigs) {
MoveOnIntervalConfig.encode(v!, writer.uint32(154).fork()).ldelim();
}
for (const v of message.logConfigs) {
LogHandlerConfig.encode(v!, writer.uint32(26).fork()).ldelim();
}
Expand Down Expand Up @@ -1829,6 +1838,13 @@ export const ContractConfig = {

message.intervalConfigs.push(OnIntervalConfig.decode(reader, reader.uint32()));
continue;
case 19:
if (tag !== 154) {
break;
}

message.moveIntervalConfigs.push(MoveOnIntervalConfig.decode(reader, reader.uint32()));
continue;
case 3:
if (tag !== 26) {
break;
Expand Down Expand Up @@ -1956,6 +1972,9 @@ export const ContractConfig = {
intervalConfigs: globalThis.Array.isArray(object?.intervalConfigs)
? object.intervalConfigs.map((e: any) => OnIntervalConfig.fromJSON(e))
: [],
moveIntervalConfigs: globalThis.Array.isArray(object?.moveIntervalConfigs)
? object.moveIntervalConfigs.map((e: any) => MoveOnIntervalConfig.fromJSON(e))
: [],
logConfigs: globalThis.Array.isArray(object?.logConfigs)
? object.logConfigs.map((e: any) => LogHandlerConfig.fromJSON(e))
: [],
Expand Down Expand Up @@ -2009,6 +2028,9 @@ export const ContractConfig = {
if (message.intervalConfigs?.length) {
obj.intervalConfigs = message.intervalConfigs.map((e) => OnIntervalConfig.toJSON(e));
}
if (message.moveIntervalConfigs?.length) {
obj.moveIntervalConfigs = message.moveIntervalConfigs.map((e) => MoveOnIntervalConfig.toJSON(e));
}
if (message.logConfigs?.length) {
obj.logConfigs = message.logConfigs.map((e) => LogHandlerConfig.toJSON(e));
}
Expand Down Expand Up @@ -2069,6 +2091,7 @@ export const ContractConfig = {
? ContractInfo.fromPartial(object.contract)
: undefined;
message.intervalConfigs = object.intervalConfigs?.map((e) => OnIntervalConfig.fromPartial(e)) || [];
message.moveIntervalConfigs = object.moveIntervalConfigs?.map((e) => MoveOnIntervalConfig.fromPartial(e)) || [];
message.logConfigs = object.logConfigs?.map((e) => LogHandlerConfig.fromPartial(e)) || [];
message.traceConfigs = object.traceConfigs?.map((e) => TraceHandlerConfig.fromPartial(e)) || [];
message.transactionConfig = object.transactionConfig?.map((e) => TransactionHandlerConfig.fromPartial(e)) || [];
Expand Down Expand Up @@ -3511,7 +3534,7 @@ export const AptosOnIntervalConfig = {
};

function createBaseMoveOnIntervalConfig(): MoveOnIntervalConfig {
return { intervalConfig: undefined, type: "", ownerType: 0, fetchConfig: undefined };
return { intervalConfig: undefined, type: "", ownerType: 0, resourceFetchConfig: undefined, fetchConfig: undefined };
}

export const MoveOnIntervalConfig = {
Expand All @@ -3525,8 +3548,11 @@ export const MoveOnIntervalConfig = {
if (message.ownerType !== 0) {
writer.uint32(24).int32(message.ownerType);
}
if (message.resourceFetchConfig !== undefined) {
MoveAccountFetchConfig.encode(message.resourceFetchConfig, writer.uint32(34).fork()).ldelim();
}
if (message.fetchConfig !== undefined) {
MoveAccountFetchConfig.encode(message.fetchConfig, writer.uint32(34).fork()).ldelim();
MoveFetchConfig.encode(message.fetchConfig, writer.uint32(42).fork()).ldelim();
}
return writer;
},
Expand Down Expand Up @@ -3564,7 +3590,14 @@ export const MoveOnIntervalConfig = {
break;
}

message.fetchConfig = MoveAccountFetchConfig.decode(reader, reader.uint32());
message.resourceFetchConfig = MoveAccountFetchConfig.decode(reader, reader.uint32());
continue;
case 5:
if (tag !== 42) {
break;
}

message.fetchConfig = MoveFetchConfig.decode(reader, reader.uint32());
continue;
}
if ((tag & 7) === 4 || tag === 0) {
Expand All @@ -3580,7 +3613,10 @@ export const MoveOnIntervalConfig = {
intervalConfig: isSet(object.intervalConfig) ? OnIntervalConfig.fromJSON(object.intervalConfig) : undefined,
type: isSet(object.type) ? globalThis.String(object.type) : "",
ownerType: isSet(object.ownerType) ? moveOwnerTypeFromJSON(object.ownerType) : 0,
fetchConfig: isSet(object.fetchConfig) ? MoveAccountFetchConfig.fromJSON(object.fetchConfig) : undefined,
resourceFetchConfig: isSet(object.resourceFetchConfig)
? MoveAccountFetchConfig.fromJSON(object.resourceFetchConfig)
: undefined,
fetchConfig: isSet(object.fetchConfig) ? MoveFetchConfig.fromJSON(object.fetchConfig) : undefined,
};
},

Expand All @@ -3595,8 +3631,11 @@ export const MoveOnIntervalConfig = {
if (message.ownerType !== 0) {
obj.ownerType = moveOwnerTypeToJSON(message.ownerType);
}
if (message.resourceFetchConfig !== undefined) {
obj.resourceFetchConfig = MoveAccountFetchConfig.toJSON(message.resourceFetchConfig);
}
if (message.fetchConfig !== undefined) {
obj.fetchConfig = MoveAccountFetchConfig.toJSON(message.fetchConfig);
obj.fetchConfig = MoveFetchConfig.toJSON(message.fetchConfig);
}
return obj;
},
Expand All @@ -3611,8 +3650,11 @@ export const MoveOnIntervalConfig = {
: undefined;
message.type = object.type ?? "";
message.ownerType = object.ownerType ?? 0;
message.resourceFetchConfig = (object.resourceFetchConfig !== undefined && object.resourceFetchConfig !== null)
? MoveAccountFetchConfig.fromPartial(object.resourceFetchConfig)
: undefined;
message.fetchConfig = (object.fetchConfig !== undefined && object.fetchConfig !== null)
? MoveAccountFetchConfig.fromPartial(object.fetchConfig)
? MoveFetchConfig.fromPartial(object.fetchConfig)
: undefined;
return message;
},
Expand Down Expand Up @@ -9716,7 +9758,15 @@ export const Data_SuiCall = {
};

function createBaseData_SuiObject(): Data_SuiObject {
return { objects: [], self: undefined, timestamp: undefined, slot: BigInt("0") };
return {
objects: [],
self: undefined,
objectId: "",
objectVersion: BigInt("0"),
objectDigest: "",
timestamp: undefined,
slot: BigInt("0"),
};
}

export const Data_SuiObject = {
Expand All @@ -9727,6 +9777,18 @@ export const Data_SuiObject = {
if (message.self !== undefined) {
Struct.encode(Struct.wrap(message.self), writer.uint32(34).fork()).ldelim();
}
if (message.objectId !== "") {
writer.uint32(42).string(message.objectId);
}
if (message.objectVersion !== BigInt("0")) {
if (BigInt.asUintN(64, message.objectVersion) !== message.objectVersion) {
throw new globalThis.Error("value provided for field message.objectVersion of type uint64 too large");
}
writer.uint32(48).uint64(message.objectVersion.toString());
}
if (message.objectDigest !== "") {
writer.uint32(58).string(message.objectDigest);
}
if (message.timestamp !== undefined) {
Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(18).fork()).ldelim();
}
Expand Down Expand Up @@ -9760,6 +9822,27 @@ export const Data_SuiObject = {

message.self = Struct.unwrap(Struct.decode(reader, reader.uint32()));
continue;
case 5:
if (tag !== 42) {
break;
}

message.objectId = reader.string();
continue;
case 6:
if (tag !== 48) {
break;
}

message.objectVersion = longToBigint(reader.uint64() as Long);
continue;
case 7:
if (tag !== 58) {
break;
}

message.objectDigest = reader.string();
continue;
case 2:
if (tag !== 18) {
break;
Expand Down Expand Up @@ -9787,6 +9870,9 @@ export const Data_SuiObject = {
return {
objects: globalThis.Array.isArray(object?.objects) ? [...object.objects] : [],
self: isObject(object.self) ? object.self : undefined,
objectId: isSet(object.objectId) ? globalThis.String(object.objectId) : "",
objectVersion: isSet(object.objectVersion) ? BigInt(object.objectVersion) : BigInt("0"),
objectDigest: isSet(object.objectDigest) ? globalThis.String(object.objectDigest) : "",
timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined,
slot: isSet(object.slot) ? BigInt(object.slot) : BigInt("0"),
};
Expand All @@ -9800,6 +9886,15 @@ export const Data_SuiObject = {
if (message.self !== undefined) {
obj.self = message.self;
}
if (message.objectId !== "") {
obj.objectId = message.objectId;
}
if (message.objectVersion !== BigInt("0")) {
obj.objectVersion = message.objectVersion.toString();
}
if (message.objectDigest !== "") {
obj.objectDigest = message.objectDigest;
}
if (message.timestamp !== undefined) {
obj.timestamp = message.timestamp.toISOString();
}
Expand All @@ -9816,6 +9911,9 @@ export const Data_SuiObject = {
const message = createBaseData_SuiObject();
message.objects = object.objects?.map((e) => e) || [];
message.self = object.self ?? undefined;
message.objectId = object.objectId ?? "";
message.objectVersion = object.objectVersion ?? BigInt("0");
message.objectDigest = object.objectDigest ?? "";
message.timestamp = object.timestamp ?? undefined;
message.slot = object.slot ?? BigInt("0");
return message;
Expand Down
Loading

0 comments on commit e73fade

Please sign in to comment.