Skip to content

Commit

Permalink
Rename top-level property to transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioberger committed Dec 15, 2023
1 parent 38d407f commit 1768682
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
24 changes: 9 additions & 15 deletions packages/explorerkit-server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Message, MessageV0, VersionedTransaction } from "@solana/web3.js";
import {
checkIfAccountParser,
ParserType,
InstructionParserInterface,
AccountParserInterface,
SolanaFMParser,
} from "@solanafm/explorer-kit";
import { ParserType, InstructionParserInterface, AccountParserInterface, SolanaFMParser } from "@solanafm/explorer-kit";
import { getProgramIdl } from "@solanafm/explorer-kit-idls";
import bodyParser from "body-parser";
import bs58 from "bs58";
Expand Down Expand Up @@ -102,15 +96,15 @@ app.post("/decode/transactions", async (req: Request, res: Response) => {
const { transactions } = req.body as DecodeTransactionsRequestBody;

let instructionParsers: { [key: string]: InstructionParserInterface } = {};
let decodedAccounts: DecodedTransactions[] = [];
let decodedTransactions: DecodedTransactions[] = [];
for (var encodedTx of transactions) {
let txBuffer = null;
if (isValidBase58(encodedTx)) {
txBuffer = Buffer.from(bs58.decode(encodedTx));
} else if (isValidBase64(encodedTx)) {
txBuffer = Buffer.from(encodedTx, "base64");
} else {
decodedAccounts.push({ error: "'transaction' is not a valid base64 string.", decodedInstructions: null });
decodedTransactions.push({ error: "'transaction' is not a valid base64 string.", decodedInstructions: null });
continue;
}

Expand All @@ -121,7 +115,7 @@ app.post("/decode/transactions", async (req: Request, res: Response) => {
for (var ix of tx.message.instructions) {
let programId = tx.message.accountKeys[ix.programIdIndex];
if (programId === undefined) {
decodedAccounts.push({ error: "programId not found in accounts", decodedInstructions: null });
decodedTransactions.push({ error: "programId not found in accounts", decodedInstructions: null });
continue;
}
instructions.push({
Expand All @@ -133,7 +127,7 @@ app.post("/decode/transactions", async (req: Request, res: Response) => {
for (var inst of tx.message.compiledInstructions) {
let programId = tx.message.staticAccountKeys[inst.programIdIndex];
if (programId === undefined) {
decodedAccounts.push({ error: "programId not found in staticAccountKeys", decodedInstructions: null });
decodedTransactions.push({ error: "programId not found in staticAccountKeys", decodedInstructions: null });
continue;
}
instructions.push({
Expand All @@ -157,7 +151,7 @@ app.post("/decode/transactions", async (req: Request, res: Response) => {
instructionParser = parser.createParser(ParserType.INSTRUCTION) as InstructionParserInterface;
instructionParsers[programId] = instructionParser;
} else {
decodedAccounts.push({ error: "Failed to find program IDL", decodedInstructions: null });
decodedTransactions.push({ error: "Failed to find program IDL", decodedInstructions: null });
continue;
}
}
Expand All @@ -167,13 +161,13 @@ app.post("/decode/transactions", async (req: Request, res: Response) => {
decodedInstructions.push({ name: decodedInstruction?.name, data: decodedInstruction?.data, programId });
}

decodedAccounts.push({ error: null, decodedInstructions });
decodedTransactions.push({ error: null, decodedInstructions });
} catch (e: any) {
decodedAccounts.push({ error: e.message, decodedInstructions: null });
decodedTransactions.push({ error: e.message, decodedInstructions: null });
}
}

return res.status(200).json({ decodedAccounts });
return res.status(200).json({ decodedTransactions });
});

function isValidBase58(str: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/explorerkit-server/tests/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("Server API Tests", () => {

expect(res.status).toBe(200);
expect(res.body).toMatchObject({
decodedAccounts: [
decodedTransactions: [
{
error: null,
decodedInstructions: [
Expand Down

0 comments on commit 1768682

Please sign in to comment.