fix: fix executor

This commit is contained in:
Alex 2025-04-03 19:29:50 +03:00
parent 370aedfe12
commit cdf5b58935
3 changed files with 37 additions and 21 deletions

View File

@ -1,7 +1,8 @@
import { constructClaim } from '@coinweb/contract-kit'; import { constructClaim } from '@coinweb/contract-kit';
import { storeOp } from 'cwait'; import { readOp, storeOp } from 'cwait';
import { AddWordArgs, createWordKey } from '../offchain/shared'; import { TypedClaim } from '../../../lib/dist/shared/types';
import { AddWordArgs, createWordKey, WordClaimBody } from '../offchain/shared';
function hashCode(str: string): string { function hashCode(str: string): string {
let hash = 0; let hash = 0;
@ -17,5 +18,12 @@ function hashCode(str: string): string {
export const addWord = async (...[word]: AddWordArgs) => { export const addWord = async (...[word]: AddWordArgs) => {
const id = hashCode(word); const id = hashCode(word);
storeOp(constructClaim(createWordKey(id), { word }, '0x0')); await storeOp(constructClaim(createWordKey(id), { word }, '0x0'));
const wordClaim = await readOp<TypedClaim<WordClaimBody>>(createWordKey(id));
const newWord = (wordClaim?.body.word ?? '') + '!!!';
const newId = hashCode(newWord);
storeOp(constructClaim(createWordKey(newId), { word: newWord }, '0x0'));
}; };

View File

@ -19,14 +19,15 @@ const handleState = () => {
const ctx = getRawContext(); const ctx = getRawContext();
const resolvedOps = extractContractArgs(ctx.tx); const resolvedOps = extractContractArgs(ctx.tx);
const currentArgs = getMethodArguments(ctx) as [unknown, unknown[], ResolvedOperation[]]; const methodArgs = getMethodArguments(ctx) as [unknown, unknown[], ResolvedOperation[]];
const initialArgs = currentArgs[1]; const initialArgs = methodArgs[1] ?? [];
const allResolvedOps = [...currentArgs[2], ...resolvedOps]; const previousOps = methodArgs[2] ?? [];
const allResolvedOps = [...previousOps, ...resolvedOps];
pushResolvedOp(allResolvedOps); pushResolvedOp(allResolvedOps);
return { args: initialArgs, methodName: currentArgs[0] as string, ops: allResolvedOps }; return { args: initialArgs, methodName: methodArgs[0] as string, ops: allResolvedOps };
}; };
export const executor = export const executor =
@ -56,7 +57,10 @@ export const executor =
const txFee = 700n + BigInt(awaitedOps.length) * 100n; const txFee = 700n + BigInt(awaitedOps.length) * 100n;
return [ return [
constructContinueTx(ctx, awaitedOps, [ constructContinueTx(
ctx,
[],
[
{ {
callInfo: { callInfo: {
ref: constructContractRef(context.issuer, []), ref: constructContractRef(context.issuer, []),
@ -68,10 +72,11 @@ export const executor =
providedCweb: availableCweb - txFee, providedCweb: availableCweb - txFee,
authenticated: authInfo, authenticated: authInfo,
}, },
contractArgs: [], contractArgs: awaitedOps,
}, },
}, },
]), ]
),
]; ];
}; };

View File

@ -1,3 +1,6 @@
export * from './awaited';
export * from './block'; export * from './block';
export * from './read';
export * from './resolved';
export * from './store'; export * from './store';
export * from './take'; export * from './take';