Skip to content

Commit

Permalink
Fixed all the issues (elizaOS#2970)
Browse files Browse the repository at this point in the history
Co-authored-by: Sayo <hi@sayo.wtf>
  • Loading branch information
AIFlowML and wtfsayo authored Jan 29, 2025
1 parent 8843976 commit 16e3a8d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/plugin-iq6900/src/functions/bringIQData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ interface TransactionData {
before_tx: string;
}

interface TransactionDataResponse {
code: string;
method: string;
decode_break: number;
}

interface CodeResult {
json_data: string;
commit_message: string;
Expand Down Expand Up @@ -82,7 +88,7 @@ async function fetchDBPDA(): Promise<string | null> {
}

async function getTransactionData(transactionData: TransactionData): Promise<{
data: any;
data: TransactionDataResponse | "fail";
before_tx: string;
}> {
if (!transactionData || !("code" in transactionData)) {
Expand Down Expand Up @@ -115,6 +121,10 @@ async function extractCommitMessage(dataTxid: string): Promise<string | null> {
return null;
}

function isTransactionDataResponse(data: TransactionDataResponse | "fail"): data is TransactionDataResponse {
return data !== "fail" && typeof data === "object" && "code" in data;
}

async function bringCode(dataTxid: string): Promise<CodeResult> {
const txInfo = await fetchTransactionInfo(dataTxid);
if (!txInfo || !txInfo.tail_tx) return ERROR_RESULT;
Expand Down Expand Up @@ -142,8 +152,8 @@ async function bringCode(dataTxid: string): Promise<CodeResult> {
const chunkData = await getTransactionData(
chunk as TransactionData
);
if (!chunkData.data || chunkData.data === null) {
elizaLogger.error("Chunk data undefined");
if (!chunkData.data || !isTransactionDataResponse(chunkData.data)) {
elizaLogger.error("Chunk data undefined or invalid");
return ERROR_RESULT;
}

Expand Down

0 comments on commit 16e3a8d

Please sign in to comment.