From 186b719a9451516f69574e68638001072518944f Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 15 May 2025 10:28:57 +0300 Subject: [PATCH] wip --- .env.yarn | 2 +- package.json | 2 +- .../contract.cm/src/offchain/shared/constants.ts | 2 +- packages/cwait/src/onchain/context/extractOps.ts | 2 +- .../executor/constructTx/prepareInThreadTxs.ts | 15 ++++++++++++--- .../executor/constructTx/prepareOutThreadTxs.ts | 1 + packages/cwait/src/onchain/executor/executor.ts | 4 ++-- .../cwait/src/onchain/features/cwait/cwait.ts | 5 ++++- packages/cwait/src/onchain/features/mutex/lock.ts | 4 ++-- packages/cwait/src/onchain/features/ops/read.ts | 6 +++++- .../onchain/mutex/calls/constructUnlockCall.ts | 5 +++-- .../cwait/src/onchain/mutex/methods/unlock.ts | 8 ++++++-- packages/cwait/src/onchain/runtime/resolvedOps.ts | 2 ++ packages/ui/.env | 2 +- yarn.lock | 10 +++++----- 15 files changed, 47 insertions(+), 23 deletions(-) diff --git a/.env.yarn b/.env.yarn index 0e3587e..0efe5b1 100644 --- a/.env.yarn +++ b/.env.yarn @@ -4,4 +4,4 @@ NPM_PASSWORD= # This is needed when working with WASM modules (nodeLinker: node-modules is mandatory) NODE_OPTIONS="--experimental-wasm-modules --no-warnings=ExperimentalWarning --max-old-space-size=8192" -REGISTRATION_PROFILE=devnet +REGISTRATION_PROFILE=test diff --git a/package.json b/package.json index 0e00e51..0a9303c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@coinweb/self-register": "0.1.3", "@coinweb/claims-client": "0.1.6-debug", "@coinweb/contract-kit": "0.2.6", - "@coinweb/testing-sdk": "0.0.9-remote", + "@coinweb/testing-sdk": "0.0.10-mutex", "@coinweb/minimal-sdk": "1.2.21" }, "devDependencies": { diff --git a/packages/contract.cm/src/offchain/shared/constants.ts b/packages/contract.cm/src/offchain/shared/constants.ts index ddb5d35..c28e3bb 100644 --- a/packages/contract.cm/src/offchain/shared/constants.ts +++ b/packages/contract.cm/src/offchain/shared/constants.ts @@ -9,5 +9,5 @@ export enum PUBLIC_METHODS { } export const FEE = { - ADD_WORD: 100000n, + ADD_WORD: 10000000n, }; diff --git a/packages/cwait/src/onchain/context/extractOps.ts b/packages/cwait/src/onchain/context/extractOps.ts index 1d3d302..153dc96 100644 --- a/packages/cwait/src/onchain/context/extractOps.ts +++ b/packages/cwait/src/onchain/context/extractOps.ts @@ -112,7 +112,7 @@ export const extractOps = ({ throw new Error('Wrong mutex unlock result'); } - extractedOps.push({ SlotOp: { ok: true } }); + extractedOps.push({ UnlockOp: 0 }); i += 2; continue; diff --git a/packages/cwait/src/onchain/executor/constructTx/prepareInThreadTxs.ts b/packages/cwait/src/onchain/executor/constructTx/prepareInThreadTxs.ts index 5f6c179..6c3c5b8 100644 --- a/packages/cwait/src/onchain/executor/constructTx/prepareInThreadTxs.ts +++ b/packages/cwait/src/onchain/executor/constructTx/prepareInThreadTxs.ts @@ -160,11 +160,12 @@ export const prepareInThreadTxs = ({ break; } case isPreparedUnlockOp(op): { + console.log('prepareInThreadTxs >>> unlockOp'); const { callInfo, fee, ops } = constructUnlockCall( context.issuer, op.UnlockOp.lockId, op.UnlockOp.timestamp, - false + true ); childCalls.push({ callInfo }); @@ -194,6 +195,9 @@ export const prepareInThreadTxs = ({ childCalls.push({ callInfo }); txFee += fee; + console.log(txFee); + console.log(context.funds.availableCweb); + callArgs.push(...ops); } @@ -206,6 +210,7 @@ export const prepareInThreadTxs = ({ if ('StoreOp' in latestCallArg && (latestCallArg.StoreOp.key.first_part as [string])[0] === resultKey) { //SAVE RESULT CLAIMS + console.log('SAVE RESULT CLAIMS'); if (callArgs.length > 1) { throw new Error('Unexpected count of result ops'); } @@ -221,10 +226,12 @@ export const prepareInThreadTxs = ({ const cwebToStore = availableCweb + storedCweb - BigInt(takeOps.length) * 100n - 500n; + console.log('cwebToStore: ', cwebToStore); + resultOps.push( - constructFundsClaimStore(context.parentId, cwebToStore), + passCwebFrom(context.issuer, availableCweb), ...takeOps, - passCwebFrom(context.issuer, availableCweb) + constructFundsClaimStore(context.parentId, cwebToStore) ); } @@ -235,6 +242,8 @@ export const prepareInThreadTxs = ({ txFee += 800n + outThreadFee + BigInt(takeOps.length) * 100n; callsPrepared++; + console.log('provided cweb: ', cwebPerCall - txFee + storedCweb); + returnTxs.push( constructContinueTx( getRawContext(), diff --git a/packages/cwait/src/onchain/executor/constructTx/prepareOutThreadTxs.ts b/packages/cwait/src/onchain/executor/constructTx/prepareOutThreadTxs.ts index d3096f3..419285e 100644 --- a/packages/cwait/src/onchain/executor/constructTx/prepareOutThreadTxs.ts +++ b/packages/cwait/src/onchain/executor/constructTx/prepareOutThreadTxs.ts @@ -95,6 +95,7 @@ export const prepareOutThreadTxs = ({ break; } case isPreparedUnlockOp(op): { + console.log('prepareOutThreadTxs >>> unlockOp'); const { callInfo, fee } = constructUnlockCall(context.issuer, op.UnlockOp.lockId, op.UnlockOp.timestamp, false); preparedCalls.push({ callInfo }); diff --git a/packages/cwait/src/onchain/executor/executor.ts b/packages/cwait/src/onchain/executor/executor.ts index 6a31392..23146d4 100644 --- a/packages/cwait/src/onchain/executor/executor.ts +++ b/packages/cwait/src/onchain/executor/executor.ts @@ -18,7 +18,7 @@ export const executor = (method: (...args: any[]) => Promise) => { } if (shouldRestart) { - console.log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< executor-finish'); + console.log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< executor-finish-restart'); return constructTx(false); } @@ -31,7 +31,7 @@ export const executor = (method: (...args: any[]) => Promise) => { try { setNextExec(() => method(...context.initialArgs)); const isFullyExecuted = await execLoop(); - console.log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< executor-finish'); + console.log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< executor-finish-end'); return constructTx(isFullyExecuted); } catch (error) { console.log((error as Error).message); diff --git a/packages/cwait/src/onchain/features/cwait/cwait.ts b/packages/cwait/src/onchain/features/cwait/cwait.ts index 93ee765..d24bec3 100644 --- a/packages/cwait/src/onchain/features/cwait/cwait.ts +++ b/packages/cwait/src/onchain/features/cwait/cwait.ts @@ -67,7 +67,10 @@ export const cwait = Promise Promise { - console.log('lockOp'); + console.log('unlockOp'); let opMarkerValue = false; const result = new Promise((resolve, reject) => { diff --git a/packages/cwait/src/onchain/features/ops/read.ts b/packages/cwait/src/onchain/features/ops/read.ts index d5477b8..0b07821 100644 --- a/packages/cwait/src/onchain/features/ops/read.ts +++ b/packages/cwait/src/onchain/features/ops/read.ts @@ -3,8 +3,8 @@ import { Claim, ClaimKey, constructRead, extractRead } from '@coinweb/contract-k import { TypedClaim } from '../../../types'; import { context } from '../../context'; import { opMarker } from '../../globals/promise'; -import { isResolvedReadOp, isResolvedSlotOp } from '../../utils'; import { pushAwaitedTask, shiftResolvedOp } from '../../runtime'; +import { isResolvedReadOp, isResolvedSlotOp } from '../../utils'; export const readOp = (key: ClaimKey) => { let opMarkerValue = false; @@ -22,10 +22,14 @@ export const readOp = (key: ClaimKey) => { } if (!isResolvedReadOp(op)) { + console.log(JSON.stringify(op)); + throw new Error('Read operation not found'); } const claim = (extractRead(op)?.[0]?.content ?? null) as TClaim | null; + + console.log('ResolveRead claim: ', claim); resolve(claim); } } catch (error) { diff --git a/packages/cwait/src/onchain/mutex/calls/constructUnlockCall.ts b/packages/cwait/src/onchain/mutex/calls/constructUnlockCall.ts index 72b6ec6..48d102c 100644 --- a/packages/cwait/src/onchain/mutex/calls/constructUnlockCall.ts +++ b/packages/cwait/src/onchain/mutex/calls/constructUnlockCall.ts @@ -2,6 +2,7 @@ import { constructContractRef, ContractIssuer } from '@coinweb/contract-kit'; import { constructMutexBlockUnlockClaimTake, constructMutexUnlockBlock } from '../claims'; import { unlockMethodName } from '../methods'; +import { unlockFee } from '../settings'; import { MutexUnlockArgs } from '../types'; export const constructUnlockCall = (issuer: ContractIssuer, ...[lockId, timestamp, notify]: MutexUnlockArgs) => { @@ -13,7 +14,7 @@ export const constructUnlockCall = (issuer: ContractIssuer, ...[lockId, timestam methodArgs: [lockId, timestamp] satisfies MutexUnlockArgs, }, contractInfo: { - providedCweb: 1000n, + providedCweb: unlockFee, authenticated: null, }, contractArgs: [], @@ -21,6 +22,6 @@ export const constructUnlockCall = (issuer: ContractIssuer, ...[lockId, timestam ops: notify ? ([constructMutexUnlockBlock(lockId, issuer), constructMutexBlockUnlockClaimTake(lockId)] as const) : [], - fee: 1200n, + fee: unlockFee + (notify ? 1000n : 800n), }; }; diff --git a/packages/cwait/src/onchain/mutex/methods/unlock.ts b/packages/cwait/src/onchain/mutex/methods/unlock.ts index c98abfe..9b6ab01 100644 --- a/packages/cwait/src/onchain/mutex/methods/unlock.ts +++ b/packages/cwait/src/onchain/mutex/methods/unlock.ts @@ -1,7 +1,7 @@ import { constructContinueTx, constructContractRef, constructTake, Context, passCwebFrom } from '@coinweb/contract-kit'; import { getCallParameters, getContractIssuer, getMethodArguments } from 'lib/onchain'; -import { constructMutexLockClaimKey } from '../claims'; +import { constructMutexBlockUnlockClaimStore, constructMutexLockClaimKey } from '../claims'; import { lockFee } from '../settings'; import { MutexUnlockArgs } from '../types'; @@ -16,7 +16,11 @@ export const mutexUnlock = (context: Context) => { return [ constructContinueTx( context, - [passCwebFrom(issuer, availableCweb), constructTake(constructMutexLockClaimKey(lockId, timestamp))], + [ + passCwebFrom(issuer, availableCweb), + constructTake(constructMutexLockClaimKey(lockId, timestamp)), + constructMutexBlockUnlockClaimStore(lockId), + ], [ { callInfo: { diff --git a/packages/cwait/src/onchain/runtime/resolvedOps.ts b/packages/cwait/src/onchain/runtime/resolvedOps.ts index 1cb6a4f..189314f 100644 --- a/packages/cwait/src/onchain/runtime/resolvedOps.ts +++ b/packages/cwait/src/onchain/runtime/resolvedOps.ts @@ -36,6 +36,8 @@ export const shiftResolvedOp = () => { usedOps.push(result.op); } + console.log('shiftResolvedOp: ', JSON.stringify(result)); + return result; }; diff --git a/packages/ui/.env b/packages/ui/.env index fc545dd..2b76c00 100644 --- a/packages/ui/.env +++ b/packages/ui/.env @@ -1,4 +1,4 @@ VITE_API_URL='https://api-cloud.coinweb.io/wallet' VITE_EXPLORER_URL='https://explorer.coinweb.io' -VITE_CONTRACT_ADDRESS="0xedca91a29553fa2466e89eef02ac06dc49ab68be5e81fa91d05765cab79ec02a" +VITE_CONTRACT_ADDRESS="0xc599810e4861b7b1ae25695d58eeef10556fc84f87f72fafa31c0921e86e92be" diff --git a/yarn.lock b/yarn.lock index 0e862fd..2bbc788 100644 --- a/yarn.lock +++ b/yarn.lock @@ -379,16 +379,16 @@ __metadata: languageName: node linkType: hard -"@coinweb/testing-sdk@npm:0.0.9-remote": - version: 0.0.9-remote - resolution: "@coinweb/testing-sdk@npm:0.0.9-remote" +"@coinweb/testing-sdk@npm:0.0.10-mutex": + version: 0.0.10-mutex + resolution: "@coinweb/testing-sdk@npm:0.0.10-mutex" dependencies: "@coinweb/contract-kit": "npm:0.2.0" - "@coinweb/minimal-sdk": "npm:1.2.19" + "@coinweb/minimal-sdk": "npm:1.2.18" json-stable-stringify: "npm:^1.1.1" lodash.isequal: "npm:^4.5.0" secp256k1: "npm:^5.0.0" - checksum: 10c0/80212780455d4bc2c1082d62ce382c6d07c6b5a107dc372f630c2257de686ec7e072c5d7a0b966e611b73f8b49ef9d6d8b68fbd66de1d968992a6b18444f218b + checksum: 10c0/84785ecc631510aa39189792826cff454700cba96d13d6c9f93f4166ee035fb1c8a8c0f2eab0f51d7d5fe127c661c7964792f8dfacffb9bec5eaf3a6da7fc744 languageName: node linkType: hard