Skip to content

Commit

Permalink
feat: allow to evaluate args
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed Dec 12, 2024
1 parent 5cd2591 commit 5bad97e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 29 deletions.
22 changes: 14 additions & 8 deletions src/components/Call.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,20 @@
</div>
<div class="mx-2 w-2/3">
<label class="text-xs block mb-1" for="args">Arguments</label>
<input
id="args"
v-model="callData.args"
class="w-full p-2"
type="text"
placeholder="comma separated args"
@keydown.enter="callContract"
/>
<div class="flex flex-row">
<input
id="args"
v-model="callData.args"
class="w-full p-2"
type="text"
placeholder="comma separated args (using eval as array)"
@keydown.enter="callContract"
/>
<div class="ml-2 flex flex-col">
<label class="text-xs block mb-1" for="staticEval">Eval</label>
<input id="staticEval" v-model="callData.eval" type="checkbox" />
</div>
</div>
</div>
</div>

Expand Down
26 changes: 18 additions & 8 deletions src/components/CallStatic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,24 @@
<div class="flex -mx-2 mt-4 mb-4">
<div class="mx-2 w-full">
<label class="text-xs block mb-1" for="staticArgs">Arguments</label>
<input
id="staticArgs"
v-model="callStaticData.args"
class="w-full p-2"
type="text"
placeholder="comma separated args"
@keydown.enter="callContractStatic"
/>
<div class="flex flex-row">
<input
id="staticArgs"
v-model="callStaticData.args"
class="w-full p-2"
type="text"
placeholder="comma separated args (using eval as array)"
@keydown.enter="callContractStatic"
/>
<div class="ml-2 flex flex-col">
<label class="text-xs block mb-1" for="staticEval">Eval</label>
<input
id="staticEval"
v-model="callStaticData.eval"
type="checkbox"
/>
</div>
</div>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/components/DecodedEvents.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<span class="text-xs block mb-1 font-bold" v-if="result?.events?.length">
<span v-if="result?.events?.length" class="text-xs block mb-1 font-bold">
Events:
</span>
<span
Expand Down
22 changes: 14 additions & 8 deletions src/components/Deploy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@
</div>
<div class="mx-2 w-2/3">
<label class="text-xs block mb-1" for="deployArgs">Arguments</label>
<input
id="deployArgs"
v-model="deployData.args"
class="w-full p-2"
type="text"
placeholder="comma separated args"
@keydown.enter="deployContract"
/>
<div class="flex flex-row">
<input
id="deployArgs"
v-model="deployData.args"
class="w-full p-2"
type="text"
placeholder="comma separated args (using eval as array)"
@keydown.enter="deployContract"
/>
<div class="ml-2 flex flex-col">
<label class="text-xs block mb-1" for="staticEval">Eval</label>
<input id="staticEval" v-model="deployData.eval" type="checkbox" />
</div>
</div>
</div>
</div>
<div class="flex -mx-2 mt-4 mb-4">
Expand Down
28 changes: 24 additions & 4 deletions src/stores/contractStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const useContractStore = defineStore("contract", () => {
bytecode: string;
aci: string;
args: string;
eval: boolean;
options: {
amount: number;
callData: string;
Expand All @@ -35,19 +36,27 @@ export const useContractStore = defineStore("contract", () => {
bytecode: "",
aci: "",
args: "",
eval: false,
options: structuredClone(defaultCallOptions),
});
const deployResult: Ref<Result<string>> = ref(new Result<string>());

const callStaticData: Ref<{ args: string; func: string; gas: number }> = ref({
const callStaticData: Ref<{
args: string;
func: string;
gas: number;
eval: boolean;
}> = ref({
func: "example",
gas: 1000000,
args: "",
eval: false,
});
const callStaticResult: Ref<Result<string>> = ref(new Result<string>());

const callData: Ref<{
args: string;
eval: boolean;
func: string;
options: {
amount: number;
Expand All @@ -59,6 +68,7 @@ export const useContractStore = defineStore("contract", () => {
}> = ref({
func: "example",
args: "",
eval: false,
options: structuredClone(defaultCallOptions),
});
const callResult: Ref<Result<string>> = ref(new Result<string>());
Expand Down Expand Up @@ -137,7 +147,9 @@ export const useContractStore = defineStore("contract", () => {
async function deployContract() {
resetDeployAndCallData(false);
deployResult.value.setInfo("Deploying Contract ...");
const args = argsStringToArgs(deployData.value.args);
const args = deployData.value.eval
? eval(deployData.value.args)
: argsStringToArgs(deployData.value.args);

contractInstance = await Contract.initialize({
...sdkStore.aeSdk.getContext(),
Expand Down Expand Up @@ -167,7 +179,9 @@ export const useContractStore = defineStore("contract", () => {

async function callContractStatic() {
callStaticResult.value.setInfo("Dry-Running ...");
const args = argsStringToArgs(callStaticData.value.args);
const args = callStaticData.value.eval
? eval(callStaticData.value.args)
: argsStringToArgs(callStaticData.value.args);
const options = { callStatic: true, gas: callStaticData.value.gas };

contractInstance
Expand All @@ -191,7 +205,10 @@ export const useContractStore = defineStore("contract", () => {

async function callContract() {
callResult.value.setInfo("Calling Contract ...");
const args = argsStringToArgs(callData.value.args);

const args = callData.value.eval
? eval(callData.value.args)
: argsStringToArgs(callData.value.args);
const options = Object.fromEntries(
Object.entries(callData.value.options).filter(([, v]) => v != null),
);
Expand Down Expand Up @@ -236,6 +253,7 @@ export const useContractStore = defineStore("contract", () => {
deployData.value = {
aci: "",
args: "",
eval: false,
bytecode: "",
options: structuredClone(defaultCallOptions),
};
Expand All @@ -246,12 +264,14 @@ export const useContractStore = defineStore("contract", () => {
func: "example",
gas: 1000000,
args: "",
eval: false,
};
callStaticResult.value = new Result();

callData.value = {
func: "example",
args: "",
eval: false,
options: structuredClone(defaultCallOptions),
};
callResult.value = new Result();
Expand Down

0 comments on commit 5bad97e

Please sign in to comment.