Compare commits

..

No commits in common. "5e9b66fe7f47b745158737e9f1003af3a92fb4eb" and "cb4a2fb33d7aa0fd1b252b560f6ad7b859a03bfb" have entirely different histories.

15 changed files with 76 additions and 102 deletions

View File

@ -81,7 +81,7 @@ export default tseslint.config(
caughtErrorsIgnorePattern: '^_',
},
],
'@typescript-eslint/no-explicit-any': ['error', { ignoreRestArgs: true }],
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-misused-promises': ['error', { checksVoidReturn: false }],
'@typescript-eslint/no-empty-object-type': 'off',

View File

@ -9,6 +9,7 @@ export const constructAddWordUiCommand = ({ word, contractId }: { word: string;
methodName: PUBLIC_METHODS.ADD_WORD,
methodArgs: [[word] satisfies AddWordArgs],
cost: FEE.ADD_WORD,
withQueue: false,
}),
]);
};

View File

@ -26,14 +26,6 @@ export const addWord = cwait(async (...[word]: AddWordArgs) => {
console.log('await storeOp');
await storeOp(constructClaim(createWordKey(id), { word }, '0x0'));
console.log('await readOp');
const res = await readOp<TypedClaim<WordClaimBody>>(createWordKey(id));
console.log('await storeOp2');
await storeOp(
constructClaim(createWordKey(id + id), { word: (res?.body.word ?? '') + (res?.body.word ?? '') }, '0x0')
);
console.log('await extraLogic');
const wordClaim = await extraLogic(id);

View File

@ -1,9 +1,25 @@
import { constructCwebMain } from 'cwait';
import { SELF_REGISTER_HANDLER_NAME } from '@coinweb/contract-kit';
import { selfRegisterHandler } from '@coinweb/self-register';
import { addMethodHandler, ContractHandlers, executeHandler, executor } from 'cwait';
import { PUBLIC_METHODS } from '../offchain/shared';
import { addWord } from './addWord';
export const cwebMain = constructCwebMain({
[PUBLIC_METHODS.ADD_WORD]: addWord,
});
const createModule = (): ContractHandlers => {
const module: ContractHandlers = { handlers: {} };
addMethodHandler(module, PUBLIC_METHODS.ADD_WORD, executor(addWord));
addMethodHandler(module, SELF_REGISTER_HANDLER_NAME, selfRegisterHandler);
return module;
};
export const cwebMain = () => {
return (async () => {
const module = createModule();
await executeHandler(module);
})();
};

View File

@ -1,22 +0,0 @@
import { ContractHandlers as ContractHandlersOrig, SELF_REGISTER_HANDLER_NAME } from '@coinweb/contract-kit';
import { selfRegisterHandler } from '@coinweb/self-register';
import { queue } from 'lib/onchain';
import { addMethodHandler, ContractHandlers, executeHandler } from '../contract-kit';
import { executor } from './executor';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const constructCwebMain = (methods: Record<string, (...args: any[]) => Promise<void>>) => async () => {
const module: ContractHandlers = { handlers: {} };
Object.entries(methods).forEach(([name, handler]) => {
addMethodHandler(module, name, executor(handler));
});
addMethodHandler(module, SELF_REGISTER_HANDLER_NAME, selfRegisterHandler);
queue.applyQueue(module as ContractHandlersOrig, []);
await executeHandler(module);
};

View File

@ -1,5 +1,3 @@
export * from './context';
export * from './executor';
export * from './promisifiedOps';
export * from './createContract';
export * from './cwait';

View File

@ -1,15 +1,18 @@
import { constructStore } from '@coinweb/contract-kit/dist/esm/operations/store';
import { constructResultClaim } from './claims';
import { context } from './context';
import { stopExecution } from './executor';
import { opMarker } from './global';
import { getAwaitedTasks, pushAwaitedTask } from './promisifiedOps/awaited';
import { getUsedOps, saveUsedOps, shiftResolvedOp } from './promisifiedOps/resolved';
import { isResolvedChildOp, isResolvedExecOp, isResolvedSlotOp, uuid } from './utils';
import { constructResultClaim } from '../claims/result';
import { context } from '../context';
import { stopExecution } from '../executor';
import { opMarker } from '../global';
import { isResolvedChildOp, isResolvedExecOp, isResolvedSlotOp } from '../utils';
import { uuid } from '../utils';
import { getAwaitedTasks, pushAwaitedTask } from './awaited';
import { getUsedOps, saveUsedOps, shiftResolvedOp } from './resolved';
let isRootDetected = false;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const cwait = <TAsyncCallback extends (...args: any[]) => Promise<unknown>>(asyncCallback: TAsyncCallback) => {
console.log('cwait: ', asyncCallback.name);
let isRoot = false;

View File

@ -1,3 +1,4 @@
export * from './awaited';
export * from './cwait';
export * from './ops';
export * from './resolved';

View File

@ -0,0 +1,2 @@
export * from './jumpTx';
export * from './tx';

View File

@ -0,0 +1 @@
export const jumpTx = () => null;

View File

@ -0,0 +1 @@
export const tx = () => null;

View File

@ -5,14 +5,11 @@ import {
FullCallInfo,
NewTx,
passCwebFrom,
PreparedCallInfo,
PreparedOperation,
prepareQueueCall,
sendCwebInterface,
} from '@coinweb/contract-kit';
import { CwebBlock } from '@coinweb/contract-kit/dist/esm/operations/block';
import { GBlock } from '@coinweb/contract-kit/dist/types/operations/generics';
import { queue, queueCostFee, queueUnlockFee } from 'lib/onchain';
import { ExecutorMethodArgs, ResolvedOp, ResolvedSlotOp, Task } from '../../../types';
import { constructFundsClaimRangRead, constructFundsClaimStore } from '../../claims/funds';
@ -41,7 +38,7 @@ export const prepareInThreadTxs = ({
const restOfAvailableCweb = availableCweb - outThreadFee;
const restOfCweb = restOfAvailableCweb + storedCweb - BigInt(takeOps.length) * 100n - 3000n - queueCostFee;
const restOfCweb = restOfAvailableCweb + storedCweb - BigInt(takeOps.length) * 100n - 3000n;
const txs =
restOfCweb > 0n
@ -51,9 +48,8 @@ export const prepareInThreadTxs = ({
...takeOps,
...constructSendCweb(restOfCweb, user, null),
]),
...queue.gateway.unlock(getRawContext()),
]
: queue.gateway.unlock(getRawContext());
: [];
return { txs, calls: 0 };
}
@ -84,7 +80,8 @@ export const prepareInThreadTxs = ({
txFee += 200n;
childCalls.push({
callInfo: prepareQueueCall(context.issuer, {
callInfo: {
ref: constructContractRef(context.issuer, []),
methodInfo: {
methodName: context.methodName,
methodArgs: [
@ -94,15 +91,14 @@ export const prepareInThreadTxs = ({
id,
context.thisId,
true,
[],
] satisfies ExecutorMethodArgs,
},
contractInfo: {
providedCweb: cwebPerCall - 700n - queueCostFee,
providedCweb: cwebPerCall - 700n,
authenticated: null,
},
contractArgs: [],
}),
},
});
callsPrepared++;
@ -154,46 +150,32 @@ export const prepareInThreadTxs = ({
txFee += 800n + outThreadFee + BigInt(takeOps.length) * 100n;
callsPrepared++;
const isNeedToResetQueue = !!childCalls.length;
if (isNeedToResetQueue) {
console.log('isNeedToResetQueue');
txFee += queueUnlockFee;
txFee += queueCostFee;
}
let callInfo: PreparedCallInfo = {
ref: constructContractRef(context.issuer, []),
methodInfo: {
methodName: context.methodName,
methodArgs: [
context.initialArgs,
[...context.ops, ...resolvedSlotOps],
context.user,
context.thisId,
context.parentId,
context.needSaveResult,
takeOps.map((op) => (op.TakeOp.key.second_part as [string])[0]),
] satisfies ExecutorMethodArgs,
},
contractInfo: {
providedCweb: cwebPerCall - txFee + storedCweb,
authenticated: null,
},
contractArgs: [constructFundsClaimRangRead(context.thisId), ...callArgs],
};
if (isNeedToResetQueue) {
callInfo = prepareQueueCall(context.issuer, callInfo);
}
returnTxs.push(
constructContinueTx(
getRawContext(),
[passCwebFrom(context.issuer, cwebPerCall - outThreadFee), ...takeOps],
[
{
callInfo,
callInfo: {
ref: constructContractRef(context.issuer, []),
methodInfo: {
methodName: context.methodName,
methodArgs: [
context.initialArgs,
[...context.ops, ...resolvedSlotOps],
context.user,
context.thisId,
context.parentId,
context.needSaveResult,
takeOps.map((op) => (op.TakeOp.key.second_part as [string])[0]),
] satisfies ExecutorMethodArgs,
},
contractInfo: {
providedCweb: cwebPerCall - txFee + storedCweb,
authenticated: null,
},
contractArgs: [constructFundsClaimRangRead(context.thisId), ...callArgs],
},
},
]
)
@ -202,10 +184,6 @@ export const prepareInThreadTxs = ({
if (childCalls.length) {
returnTxs.push(constructContinueTx(getRawContext(), childBlocks, childCalls));
}
if (isNeedToResetQueue) {
returnTxs.push(...queue.gateway.unlock(getRawContext()));
}
}
}

View File

@ -1,5 +1,10 @@
import { constructContinueTx, FullCallInfo, NewTx, PreparedOperation, prepareQueueCall } from '@coinweb/contract-kit';
import { queueCostFee } from 'lib/onchain';
import {
constructContinueTx,
constructContractRef,
FullCallInfo,
NewTx,
PreparedOperation,
} from '@coinweb/contract-kit';
import { ExecutorMethodArgs, Task } from '../../../types';
import { context, getRawContext } from '../../context';
@ -35,7 +40,8 @@ export const prepareOutThreadTxs = ({
const id = task.op.ExecOp.id;
const callInfo = {
callInfo: prepareQueueCall(context.issuer, {
callInfo: {
ref: constructContractRef(context.issuer, []),
methodInfo: {
methodName: context.methodName,
methodArgs: [
@ -45,15 +51,14 @@ export const prepareOutThreadTxs = ({
id,
context.parentId ?? context.thisId,
false,
[],
] satisfies ExecutorMethodArgs,
},
contractInfo: {
providedCweb: cwebPerCall - 700n - queueCostFee,
providedCweb: cwebPerCall - 700n,
authenticated: null,
},
contractArgs: [],
}),
},
};
if (siblingTxInfo[task.batchId]) {

View File

@ -1,7 +1,5 @@
import { Queue } from '@coinweb/contract-kit';
export const queue = new Queue({ name: 'queue', executionDepth: 4 });
export const queue = new Queue({ name: 'queue', executionDepth: 2 });
export const queueUnlockFee = 3000n;
export const queueCostFee = Queue.queueCostFee();

View File

@ -1,4 +1,4 @@
VITE_API_URL='https://api-cloud.coinweb.io/wallet'
VITE_EXPLORER_URL='https://explorer.coinweb.io'
VITE_CONTRACT_ADDRESS="0xa1bd5281d39b1182db65565d90919aff15adf65ac8ba43d984048485df5a6d8d"
VITE_CONTRACT_ADDRESS="0x8c89cb42634cfe892290845d907af8ec2d482cead42afaef3ccc3cea4446fce5"