fix: fix executor
This commit is contained in:
parent
370aedfe12
commit
cdf5b58935
@ -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'));
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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,22 +57,26 @@ 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: {
|
[],
|
||||||
ref: constructContractRef(context.issuer, []),
|
[
|
||||||
methodInfo: {
|
{
|
||||||
methodName,
|
callInfo: {
|
||||||
methodArgs: [args, ops],
|
ref: constructContractRef(context.issuer, []),
|
||||||
|
methodInfo: {
|
||||||
|
methodName,
|
||||||
|
methodArgs: [args, ops],
|
||||||
|
},
|
||||||
|
contractInfo: {
|
||||||
|
providedCweb: availableCweb - txFee,
|
||||||
|
authenticated: authInfo,
|
||||||
|
},
|
||||||
|
contractArgs: awaitedOps,
|
||||||
},
|
},
|
||||||
contractInfo: {
|
|
||||||
providedCweb: availableCweb - txFee,
|
|
||||||
authenticated: authInfo,
|
|
||||||
},
|
|
||||||
contractArgs: [],
|
|
||||||
},
|
},
|
||||||
},
|
]
|
||||||
]),
|
),
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -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';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user