fix: fix executor
This commit is contained in:
parent
370aedfe12
commit
cdf5b58935
@ -1,7 +1,8 @@
|
||||
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 {
|
||||
let hash = 0;
|
||||
@ -17,5 +18,12 @@ function hashCode(str: string): string {
|
||||
|
||||
export const addWord = async (...[word]: AddWordArgs) => {
|
||||
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'));
|
||||
};
|
||||
|
||||
@ -19,14 +19,15 @@ const handleState = () => {
|
||||
const ctx = getRawContext();
|
||||
|
||||
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 allResolvedOps = [...currentArgs[2], ...resolvedOps];
|
||||
const initialArgs = methodArgs[1] ?? [];
|
||||
const previousOps = methodArgs[2] ?? [];
|
||||
const allResolvedOps = [...previousOps, ...resolvedOps];
|
||||
|
||||
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 =
|
||||
@ -56,7 +57,10 @@ export const executor =
|
||||
const txFee = 700n + BigInt(awaitedOps.length) * 100n;
|
||||
|
||||
return [
|
||||
constructContinueTx(ctx, awaitedOps, [
|
||||
constructContinueTx(
|
||||
ctx,
|
||||
[],
|
||||
[
|
||||
{
|
||||
callInfo: {
|
||||
ref: constructContractRef(context.issuer, []),
|
||||
@ -68,10 +72,11 @@ export const executor =
|
||||
providedCweb: availableCweb - txFee,
|
||||
authenticated: authInfo,
|
||||
},
|
||||
contractArgs: [],
|
||||
contractArgs: awaitedOps,
|
||||
},
|
||||
},
|
||||
]),
|
||||
]
|
||||
),
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
export * from './awaited';
|
||||
export * from './block';
|
||||
export * from './read';
|
||||
export * from './resolved';
|
||||
export * from './store';
|
||||
export * from './take';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user