Skip to content

Commit

Permalink
feat(aptos): compatible with raw transation data (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 authored Nov 16, 2024
1 parent 974b484 commit 4779d57
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 18 deletions.
3 changes: 3 additions & 0 deletions packages/protos/processor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -628,14 +628,17 @@ message Data {
message AptEvent {
// google.protobuf.Struct event = 1;
google.protobuf.Struct transaction = 2;
string raw_transaction = 3;
}
message AptCall {
google.protobuf.Struct transaction = 2;
string raw_transaction = 3;
}
message AptResource {
repeated google.protobuf.Struct resources = 4;
int64 version = 2;
int64 timestampMicros = 5;
repeated string raw_resources = 6;
}
message SuiEvent {
google.protobuf.Struct transaction = 1;
Expand Down
64 changes: 59 additions & 5 deletions packages/protos/src/processor/protos/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1078,16 +1078,19 @@ export interface Data_SolInstruction {

export interface Data_AptEvent {
transaction: { [key: string]: any } | undefined;
rawTransaction: string;
}

export interface Data_AptCall {
transaction: { [key: string]: any } | undefined;
rawTransaction: string;
}

export interface Data_AptResource {
resources: { [key: string]: any }[];
version: bigint;
timestampMicros: bigint;
rawResources: string[];
}

export interface Data_SuiEvent {
Expand Down Expand Up @@ -9236,14 +9239,17 @@ export const Data_SolInstruction = {
};

function createBaseData_AptEvent(): Data_AptEvent {
return { transaction: undefined };
return { transaction: undefined, rawTransaction: "" };
}

export const Data_AptEvent = {
encode(message: Data_AptEvent, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.transaction !== undefined) {
Struct.encode(Struct.wrap(message.transaction), writer.uint32(18).fork()).ldelim();
}
if (message.rawTransaction !== "") {
writer.uint32(26).string(message.rawTransaction);
}
return writer;
},

Expand All @@ -9261,6 +9267,13 @@ export const Data_AptEvent = {

message.transaction = Struct.unwrap(Struct.decode(reader, reader.uint32()));
continue;
case 3:
if (tag !== 26) {
break;
}

message.rawTransaction = reader.string();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
Expand All @@ -9271,14 +9284,20 @@ export const Data_AptEvent = {
},

fromJSON(object: any): Data_AptEvent {
return { transaction: isObject(object.transaction) ? object.transaction : undefined };
return {
transaction: isObject(object.transaction) ? object.transaction : undefined,
rawTransaction: isSet(object.rawTransaction) ? globalThis.String(object.rawTransaction) : "",
};
},

toJSON(message: Data_AptEvent): unknown {
const obj: any = {};
if (message.transaction !== undefined) {
obj.transaction = message.transaction;
}
if (message.rawTransaction !== "") {
obj.rawTransaction = message.rawTransaction;
}
return obj;
},

Expand All @@ -9288,19 +9307,23 @@ export const Data_AptEvent = {
fromPartial(object: DeepPartial<Data_AptEvent>): Data_AptEvent {
const message = createBaseData_AptEvent();
message.transaction = object.transaction ?? undefined;
message.rawTransaction = object.rawTransaction ?? "";
return message;
},
};

function createBaseData_AptCall(): Data_AptCall {
return { transaction: undefined };
return { transaction: undefined, rawTransaction: "" };
}

export const Data_AptCall = {
encode(message: Data_AptCall, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.transaction !== undefined) {
Struct.encode(Struct.wrap(message.transaction), writer.uint32(18).fork()).ldelim();
}
if (message.rawTransaction !== "") {
writer.uint32(26).string(message.rawTransaction);
}
return writer;
},

Expand All @@ -9318,6 +9341,13 @@ export const Data_AptCall = {

message.transaction = Struct.unwrap(Struct.decode(reader, reader.uint32()));
continue;
case 3:
if (tag !== 26) {
break;
}

message.rawTransaction = reader.string();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
Expand All @@ -9328,14 +9358,20 @@ export const Data_AptCall = {
},

fromJSON(object: any): Data_AptCall {
return { transaction: isObject(object.transaction) ? object.transaction : undefined };
return {
transaction: isObject(object.transaction) ? object.transaction : undefined,
rawTransaction: isSet(object.rawTransaction) ? globalThis.String(object.rawTransaction) : "",
};
},

toJSON(message: Data_AptCall): unknown {
const obj: any = {};
if (message.transaction !== undefined) {
obj.transaction = message.transaction;
}
if (message.rawTransaction !== "") {
obj.rawTransaction = message.rawTransaction;
}
return obj;
},

Expand All @@ -9345,12 +9381,13 @@ export const Data_AptCall = {
fromPartial(object: DeepPartial<Data_AptCall>): Data_AptCall {
const message = createBaseData_AptCall();
message.transaction = object.transaction ?? undefined;
message.rawTransaction = object.rawTransaction ?? "";
return message;
},
};

function createBaseData_AptResource(): Data_AptResource {
return { resources: [], version: BigInt("0"), timestampMicros: BigInt("0") };
return { resources: [], version: BigInt("0"), timestampMicros: BigInt("0"), rawResources: [] };
}

export const Data_AptResource = {
Expand All @@ -9370,6 +9407,9 @@ export const Data_AptResource = {
}
writer.uint32(40).int64(message.timestampMicros.toString());
}
for (const v of message.rawResources) {
writer.uint32(50).string(v!);
}
return writer;
},

Expand Down Expand Up @@ -9401,6 +9441,13 @@ export const Data_AptResource = {

message.timestampMicros = longToBigint(reader.int64() as Long);
continue;
case 6:
if (tag !== 50) {
break;
}

message.rawResources.push(reader.string());
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
Expand All @@ -9415,6 +9462,9 @@ export const Data_AptResource = {
resources: globalThis.Array.isArray(object?.resources) ? [...object.resources] : [],
version: isSet(object.version) ? BigInt(object.version) : BigInt("0"),
timestampMicros: isSet(object.timestampMicros) ? BigInt(object.timestampMicros) : BigInt("0"),
rawResources: globalThis.Array.isArray(object?.rawResources)
? object.rawResources.map((e: any) => globalThis.String(e))
: [],
};
},

Expand All @@ -9429,6 +9479,9 @@ export const Data_AptResource = {
if (message.timestampMicros !== BigInt("0")) {
obj.timestampMicros = message.timestampMicros.toString();
}
if (message.rawResources?.length) {
obj.rawResources = message.rawResources;
}
return obj;
},

Expand All @@ -9440,6 +9493,7 @@ export const Data_AptResource = {
message.resources = object.resources?.map((e) => e) || [];
message.version = object.version ?? BigInt("0");
message.timestampMicros = object.timestampMicros ?? BigInt("0");
message.rawResources = object.rawResources?.map((e) => e) || [];
return message;
},
};
Expand Down
17 changes: 17 additions & 0 deletions packages/protos/src/service/common/protos/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ export interface ApiKey {
expiresAt: bigint;
source: string;
ownerType: string;
revealable: boolean;
}

export interface TimeRangeLite {
Expand Down Expand Up @@ -4488,6 +4489,7 @@ function createBaseApiKey(): ApiKey {
expiresAt: BigInt("0"),
source: "",
ownerType: "",
revealable: false,
};
}

Expand Down Expand Up @@ -4529,6 +4531,9 @@ export const ApiKey = {
if (message.ownerType !== "") {
writer.uint32(82).string(message.ownerType);
}
if (message.revealable !== false) {
writer.uint32(88).bool(message.revealable);
}
return writer;
},

Expand Down Expand Up @@ -4602,6 +4607,13 @@ export const ApiKey = {

message.ownerType = reader.string();
continue;
case 11:
if (tag !== 88) {
break;
}

message.revealable = reader.bool();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
Expand All @@ -4622,6 +4634,7 @@ export const ApiKey = {
expiresAt: isSet(object.expiresAt) ? BigInt(object.expiresAt) : BigInt("0"),
source: isSet(object.source) ? globalThis.String(object.source) : "",
ownerType: isSet(object.ownerType) ? globalThis.String(object.ownerType) : "",
revealable: isSet(object.revealable) ? globalThis.Boolean(object.revealable) : false,
};
},

Expand Down Expand Up @@ -4654,6 +4667,9 @@ export const ApiKey = {
if (message.ownerType !== "") {
obj.ownerType = message.ownerType;
}
if (message.revealable !== false) {
obj.revealable = message.revealable;
}
return obj;
},

Expand All @@ -4671,6 +4687,7 @@ export const ApiKey = {
message.expiresAt = object.expiresAt ?? BigInt("0");
message.source = object.source ?? "";
message.ownerType = object.ownerType ?? "";
message.revealable = object.revealable ?? false;
return message;
},
};
Expand Down
22 changes: 17 additions & 5 deletions packages/runtime/src/full-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,25 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
switch (dataBinding.handlerType) {
case HandlerType.APT_EVENT:
if (dataBinding.data?.aptEvent) {
// const aptEvent = dataBinding.data.aptEvent
// if (aptEvent.event && this.sdkMinorVersion < 40) {
// assert.ok(aptEvent.transaction, 'No Transaction')
// aptEvent.transaction.events = [aptEvent.event]
// }
if (dataBinding.data.aptEvent.rawTransaction && !dataBinding.data.aptEvent.transaction) {
dataBinding.data.aptEvent.transaction = JSON.parse(dataBinding.data.aptEvent.rawTransaction)
}
}
break
case HandlerType.APT_CALL:
if (dataBinding.data?.aptCall) {
if (dataBinding.data.aptCall.rawTransaction && !dataBinding.data.aptCall.transaction) {
dataBinding.data.aptCall.transaction = JSON.parse(dataBinding.data.aptCall.rawTransaction)
}
}
break
// case HandlerType.APT_RESOURCE:
// if (dataBinding.data?.aptResource) {
// if (dataBinding.data.aptResource.rawResources && dataBinding.data.aptResource.rawResources.length > 0) {
// dataBinding.data.aptResource.resources = dataBinding.data.aptResource.rawResources.map(e => JSON.parse(e))
// }
// }
// break
case HandlerType.UNKNOWN:
if (dataBinding.data?.ethBlock) {
if (dataBinding.data.raw.length === 0) {
Expand Down
Loading

0 comments on commit 4779d57

Please sign in to comment.