Skip to content

Commit

Permalink
add logs with elizaLogger
Browse files Browse the repository at this point in the history
Signed-off-by: Agustín Ramiro Díaz <agustin.ramiro.diaz@gmail.com>
  • Loading branch information
AgustinRamiroDiaz committed Dec 11, 2024
1 parent 16a43e3 commit 526cb07
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 10 deletions.
20 changes: 19 additions & 1 deletion packages/plugin-genlayer/src/actions/deployContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
IAgentRuntime,
Memory,
State,
elizaLogger,
} from "@ai16z/eliza";
import { DeployContractParams } from "../types";
import { ClientProvider } from "../providers/client";
Expand Down Expand Up @@ -42,19 +43,36 @@ export const deployContractAction: Action = {
_options: any,
callback: HandlerCallback
) => {
elizaLogger.info("Starting deploy contract action");
elizaLogger.debug("User message:", message.content.text);

const clientProvider = new ClientProvider(runtime);
const options = await getParamsWithLLM<DeployContractParams>(
runtime,
message,
deployContractTemplate
);
if (!options)

if (!options) {
elizaLogger.error("Failed to parse deploy contract parameters");
throw new Error("Failed to parse deploy contract parameters");
}

elizaLogger.debug("Parsed parameters:", options);
elizaLogger.info(
"Deploying contract with code length:",
options.code.length
);

const result = await clientProvider.client.deployContract({
code: options.code,
args: options.args,
leaderOnly: options.leaderOnly,
});

elizaLogger.success(
`Successfully deployed contract at address: ${result}`
);
await callback(
{
text: `Successfully deployed contract at address: ${result}`,
Expand Down
23 changes: 21 additions & 2 deletions packages/plugin-genlayer/src/actions/getContractSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Action, HandlerCallback, IAgentRuntime, Memory } from "@ai16z/eliza";
import {
Action,
HandlerCallback,
IAgentRuntime,
Memory,
elizaLogger,
} from "@ai16z/eliza";
import { ClientProvider } from "../providers/client";

export const getContractSchemaAction: Action = {
Expand All @@ -16,13 +22,26 @@ export const getContractSchemaAction: Action = {
_options: any,
callback: HandlerCallback
) => {
elizaLogger.info("Starting get contract schema action");
elizaLogger.debug("User message:", message.content.text);

const clientProvider = new ClientProvider(runtime);
// Extract address from message
const addressMatch = message.content.text.match(/0x[a-fA-F0-9]{40}/);
if (!addressMatch) throw new Error("No valid address found in message");
if (!addressMatch) {
elizaLogger.error("No valid address found in message");
throw new Error("No valid address found in message");
}

elizaLogger.info(
`Getting contract schema for address: ${addressMatch[0]}`
);
const result = await clientProvider.client.getContractSchema(
addressMatch[0]
);

elizaLogger.success("Successfully retrieved contract schema");
elizaLogger.debug("Contract schema:", result);
await callback(
{
text: `Contract schema: ${JSON.stringify(result, null, 2)}`,
Expand Down
22 changes: 20 additions & 2 deletions packages/plugin-genlayer/src/actions/getCurrentNonce.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Action, HandlerCallback, IAgentRuntime, Memory } from "@ai16z/eliza";
import {
Action,
HandlerCallback,
IAgentRuntime,
Memory,
elizaLogger,
} from "@ai16z/eliza";
import { ClientProvider } from "../providers/client";

export const getCurrentNonceAction: Action = {
Expand All @@ -16,13 +22,25 @@ export const getCurrentNonceAction: Action = {
_options: any,
callback: HandlerCallback
) => {
elizaLogger.info("Starting get current nonce action");
elizaLogger.debug("User message:", message.content.text);

const clientProvider = new ClientProvider(runtime);
// Extract address from message
const addressMatch = message.content.text.match(/0x[a-fA-F0-9]{40}/);
if (!addressMatch) throw new Error("No valid address found in message");
if (!addressMatch) {
elizaLogger.error("No valid address found in message");
throw new Error("No valid address found in message");
}

elizaLogger.info(
`Getting current nonce for address: ${addressMatch[0]}`
);
const result = await clientProvider.client.getCurrentNonce({
address: addressMatch[0],
});

elizaLogger.success(`Successfully retrieved nonce: ${result}`);
await callback(
{
text: `Current nonce for address ${addressMatch[0]}: ${result}`,
Expand Down
22 changes: 20 additions & 2 deletions packages/plugin-genlayer/src/actions/getTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Action, HandlerCallback, IAgentRuntime, Memory } from "@ai16z/eliza";
import {
Action,
HandlerCallback,
IAgentRuntime,
Memory,
elizaLogger,
} from "@ai16z/eliza";
import { TransactionHash } from "genlayer-js/types";
import { ClientProvider } from "../providers/client";

Expand All @@ -17,14 +23,26 @@ export const getTransactionAction: Action = {
_options: any,
callback: HandlerCallback
) => {
elizaLogger.info("Starting get transaction action");
elizaLogger.debug("User message:", message.content.text);

const clientProvider = new ClientProvider(runtime);
// Extract transaction hash from message
const hashMatch = message.content.text.match(/0x[a-fA-F0-9]{64}/);
if (!hashMatch)
if (!hashMatch) {
elizaLogger.error("No valid transaction hash found in message");
throw new Error("No valid transaction hash found in message");
}

elizaLogger.info(
`Getting transaction details for hash: ${hashMatch[0]}`
);
const result = await clientProvider.client.getTransaction({
hash: hashMatch[0] as TransactionHash,
});

elizaLogger.success("Successfully retrieved transaction details");
elizaLogger.debug("Transaction details:", result);
await callback(
{
text: `Transaction details: ${JSON.stringify(result, null, 2)}`,
Expand Down
20 changes: 18 additions & 2 deletions packages/plugin-genlayer/src/actions/waitForTransactionReceipt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Action, HandlerCallback, IAgentRuntime, Memory } from "@ai16z/eliza";
import {
Action,
HandlerCallback,
IAgentRuntime,
Memory,
elizaLogger,
} from "@ai16z/eliza";
import { TransactionHash } from "genlayer-js/types";
import { ClientProvider } from "../providers/client";

Expand All @@ -17,14 +23,24 @@ export const waitForTransactionReceiptAction: Action = {
_options: any,
callback: HandlerCallback
) => {
elizaLogger.info("Starting wait for transaction receipt action");
elizaLogger.debug("User message:", message.content.text);

const clientProvider = new ClientProvider(runtime);
// Extract transaction hash from message
const hashMatch = message.content.text.match(/0x[a-fA-F0-9]{64}/);
if (!hashMatch)
if (!hashMatch) {
elizaLogger.error("No valid transaction hash found in message");
throw new Error("No valid transaction hash found in message");
}

elizaLogger.info(`Waiting for receipt of transaction: ${hashMatch[0]}`);
const result = await clientProvider.client.waitForTransactionReceipt({
hash: hashMatch[0] as TransactionHash,
});

elizaLogger.success("Successfully received transaction receipt");
elizaLogger.debug("Transaction receipt:", result);
await callback(
{
text: `Transaction receipt received: ${JSON.stringify(result, null, 2)}`,
Expand Down
19 changes: 18 additions & 1 deletion packages/plugin-genlayer/src/actions/writeContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
IAgentRuntime,
Memory,
State,
elizaLogger,
} from "@ai16z/eliza";
import { WriteContractParams } from "../types";
import { ClientProvider } from "../providers/client";
Expand Down Expand Up @@ -44,21 +45,37 @@ export const writeContractAction: Action = {
_options: any,
callback: HandlerCallback
) => {
elizaLogger.info("Starting write contract action");
elizaLogger.debug("User message:", message.content.text);

const clientProvider = new ClientProvider(runtime);
const options = await getParamsWithLLM<WriteContractParams>(
runtime,
message,
writeContractTemplate
);
if (!options)

if (!options) {
elizaLogger.error("Failed to parse write contract parameters");
throw new Error("Failed to parse write contract parameters");
}

elizaLogger.debug("Parsed parameters:", options);
elizaLogger.info(
`Writing to contract ${options.contractAddress} with function ${options.functionName}`
);

const result = await clientProvider.client.writeContract({
address: options.contractAddress,
functionName: options.functionName,
args: options.functionArgs,
value: options.value,
leaderOnly: options.leaderOnly,
});

elizaLogger.success(
`Successfully wrote to contract. Transaction hash: ${result}`
);
await callback(
{
text: `Successfully wrote to contract. Transaction hash: ${result}`,
Expand Down

0 comments on commit 526cb07

Please sign in to comment.