wip
This commit is contained in:
parent
eb32dcfe55
commit
5e9b66fe7f
@ -9,7 +9,6 @@ export const constructAddWordUiCommand = ({ word, contractId }: { word: string;
|
|||||||
methodName: PUBLIC_METHODS.ADD_WORD,
|
methodName: PUBLIC_METHODS.ADD_WORD,
|
||||||
methodArgs: [[word] satisfies AddWordArgs],
|
methodArgs: [[word] satisfies AddWordArgs],
|
||||||
cost: FEE.ADD_WORD,
|
cost: FEE.ADD_WORD,
|
||||||
withQueue: false,
|
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { constructClaim } from '@coinweb/contract-kit';
|
import { constructClaim } from '@coinweb/contract-kit';
|
||||||
import { readOp, storeOp, cwait, queue } from 'cwait';
|
import { readOp, storeOp, cwait } from 'cwait';
|
||||||
|
|
||||||
import { TypedClaim } from '../../../lib/dist/shared/types';
|
import { TypedClaim } from '../../../lib/dist/shared/types';
|
||||||
import { AddWordArgs, createWordKey, WordClaimBody } from '../offchain/shared';
|
import { AddWordArgs, createWordKey, WordClaimBody } from '../offchain/shared';
|
||||||
@ -26,15 +26,13 @@ export const addWord = cwait(async (...[word]: AddWordArgs) => {
|
|||||||
console.log('await storeOp');
|
console.log('await storeOp');
|
||||||
await storeOp(constructClaim(createWordKey(id), { word }, '0x0'));
|
await storeOp(constructClaim(createWordKey(id), { word }, '0x0'));
|
||||||
|
|
||||||
await queue(async () => {
|
console.log('await readOp');
|
||||||
console.log('await readOp');
|
const res = await readOp<TypedClaim<WordClaimBody>>(createWordKey(id));
|
||||||
const res = await readOp<TypedClaim<WordClaimBody>>(createWordKey(id));
|
|
||||||
|
|
||||||
console.log('await storeOp2');
|
console.log('await storeOp2');
|
||||||
await storeOp(
|
await storeOp(
|
||||||
constructClaim(createWordKey(id + id), { word: (res?.body.word ?? '') + (res?.body.word ?? '') }, '0x0')
|
constructClaim(createWordKey(id + id), { word: (res?.body.word ?? '') + (res?.body.word ?? '') }, '0x0')
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
console.log('await extraLogic');
|
console.log('await extraLogic');
|
||||||
const wordClaim = await extraLogic(id);
|
const wordClaim = await extraLogic(id);
|
||||||
|
|||||||
@ -92,7 +92,4 @@ export const context = {
|
|||||||
get needSaveResult() {
|
get needSaveResult() {
|
||||||
return getMethodArgs()[6] ?? false;
|
return getMethodArgs()[6] ?? false;
|
||||||
},
|
},
|
||||||
get isQueue() {
|
|
||||||
return getMethodArgs()[8] ?? false;
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,4 +3,3 @@ export * from './executor';
|
|||||||
export * from './promisifiedOps';
|
export * from './promisifiedOps';
|
||||||
export * from './createContract';
|
export * from './createContract';
|
||||||
export * from './cwait';
|
export * from './cwait';
|
||||||
export * from './queue';
|
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
export * from './queue';
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
const queues = new Set<number>();
|
|
||||||
|
|
||||||
let queueId = 0;
|
|
||||||
|
|
||||||
export const queue = <TCallback extends () => Promise<void>>(callback: TCallback) => {
|
|
||||||
const id = queueId++;
|
|
||||||
queues.add(id);
|
|
||||||
|
|
||||||
const promise = new Promise<void>((resolve) => {
|
|
||||||
callback().finally(() => {
|
|
||||||
queues.delete(id);
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const isQueueLocked = () => {
|
|
||||||
return queues.size > 0;
|
|
||||||
};
|
|
||||||
@ -18,7 +18,6 @@ import { ExecutorMethodArgs, ResolvedOp, ResolvedSlotOp, Task } from '../../../t
|
|||||||
import { constructFundsClaimRangRead, constructFundsClaimStore } from '../../claims/funds';
|
import { constructFundsClaimRangRead, constructFundsClaimStore } from '../../claims/funds';
|
||||||
import { constructResultBlockFilter, constructResultClaimTake, resultKey } from '../../claims/result';
|
import { constructResultBlockFilter, constructResultClaimTake, resultKey } from '../../claims/result';
|
||||||
import { context, getRawContext } from '../../context';
|
import { context, getRawContext } from '../../context';
|
||||||
import { isQueueLocked } from '../../queue/queue';
|
|
||||||
import { isPreparedBlockOp, isPreparedExecOp } from '../typeGuards';
|
import { isPreparedBlockOp, isPreparedExecOp } from '../typeGuards';
|
||||||
|
|
||||||
export const prepareInThreadTxs = ({
|
export const prepareInThreadTxs = ({
|
||||||
@ -42,7 +41,7 @@ export const prepareInThreadTxs = ({
|
|||||||
|
|
||||||
const restOfAvailableCweb = availableCweb - outThreadFee;
|
const restOfAvailableCweb = availableCweb - outThreadFee;
|
||||||
|
|
||||||
const restOfCweb = restOfAvailableCweb + storedCweb - BigInt(takeOps.length) * 100n - 3000n;
|
const restOfCweb = restOfAvailableCweb + storedCweb - BigInt(takeOps.length) * 100n - 3000n - queueCostFee;
|
||||||
|
|
||||||
const txs =
|
const txs =
|
||||||
restOfCweb > 0n
|
restOfCweb > 0n
|
||||||
@ -52,8 +51,9 @@ export const prepareInThreadTxs = ({
|
|||||||
...takeOps,
|
...takeOps,
|
||||||
...constructSendCweb(restOfCweb, user, null),
|
...constructSendCweb(restOfCweb, user, null),
|
||||||
]),
|
]),
|
||||||
|
...queue.gateway.unlock(getRawContext()),
|
||||||
]
|
]
|
||||||
: [];
|
: queue.gateway.unlock(getRawContext());
|
||||||
|
|
||||||
return { txs, calls: 0 };
|
return { txs, calls: 0 };
|
||||||
}
|
}
|
||||||
@ -84,8 +84,7 @@ export const prepareInThreadTxs = ({
|
|||||||
txFee += 200n;
|
txFee += 200n;
|
||||||
|
|
||||||
childCalls.push({
|
childCalls.push({
|
||||||
callInfo: {
|
callInfo: prepareQueueCall(context.issuer, {
|
||||||
ref: constructContractRef(context.issuer, []),
|
|
||||||
methodInfo: {
|
methodInfo: {
|
||||||
methodName: context.methodName,
|
methodName: context.methodName,
|
||||||
methodArgs: [
|
methodArgs: [
|
||||||
@ -96,15 +95,14 @@ export const prepareInThreadTxs = ({
|
|||||||
context.thisId,
|
context.thisId,
|
||||||
true,
|
true,
|
||||||
[],
|
[],
|
||||||
isQueueLocked(),
|
|
||||||
] satisfies ExecutorMethodArgs,
|
] satisfies ExecutorMethodArgs,
|
||||||
},
|
},
|
||||||
contractInfo: {
|
contractInfo: {
|
||||||
providedCweb: cwebPerCall - 700n,
|
providedCweb: cwebPerCall - 700n - queueCostFee,
|
||||||
authenticated: null,
|
authenticated: null,
|
||||||
},
|
},
|
||||||
contractArgs: [],
|
contractArgs: [],
|
||||||
},
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
callsPrepared++;
|
callsPrepared++;
|
||||||
@ -156,17 +154,12 @@ export const prepareInThreadTxs = ({
|
|||||||
txFee += 800n + outThreadFee + BigInt(takeOps.length) * 100n;
|
txFee += 800n + outThreadFee + BigInt(takeOps.length) * 100n;
|
||||||
callsPrepared++;
|
callsPrepared++;
|
||||||
|
|
||||||
const isNeedToLockQueue = !context.isQueue && isQueueLocked();
|
const isNeedToResetQueue = !!childCalls.length;
|
||||||
const isNeedToUnlockQueue = context.isQueue && !isQueueLocked();
|
|
||||||
|
|
||||||
if (isNeedToLockQueue) {
|
if (isNeedToResetQueue) {
|
||||||
console.log('isNeedToLockQueue');
|
console.log('isNeedToResetQueue');
|
||||||
txFee += queueCostFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNeedToUnlockQueue) {
|
|
||||||
console.log('isNeedToUnlockQueue');
|
|
||||||
txFee += queueUnlockFee;
|
txFee += queueUnlockFee;
|
||||||
|
txFee += queueCostFee;
|
||||||
}
|
}
|
||||||
|
|
||||||
let callInfo: PreparedCallInfo = {
|
let callInfo: PreparedCallInfo = {
|
||||||
@ -181,7 +174,6 @@ export const prepareInThreadTxs = ({
|
|||||||
context.parentId,
|
context.parentId,
|
||||||
context.needSaveResult,
|
context.needSaveResult,
|
||||||
takeOps.map((op) => (op.TakeOp.key.second_part as [string])[0]),
|
takeOps.map((op) => (op.TakeOp.key.second_part as [string])[0]),
|
||||||
isQueueLocked(),
|
|
||||||
] satisfies ExecutorMethodArgs,
|
] satisfies ExecutorMethodArgs,
|
||||||
},
|
},
|
||||||
contractInfo: {
|
contractInfo: {
|
||||||
@ -191,7 +183,7 @@ export const prepareInThreadTxs = ({
|
|||||||
contractArgs: [constructFundsClaimRangRead(context.thisId), ...callArgs],
|
contractArgs: [constructFundsClaimRangRead(context.thisId), ...callArgs],
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isNeedToLockQueue) {
|
if (isNeedToResetQueue) {
|
||||||
callInfo = prepareQueueCall(context.issuer, callInfo);
|
callInfo = prepareQueueCall(context.issuer, callInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +203,7 @@ export const prepareInThreadTxs = ({
|
|||||||
returnTxs.push(constructContinueTx(getRawContext(), childBlocks, childCalls));
|
returnTxs.push(constructContinueTx(getRawContext(), childBlocks, childCalls));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNeedToUnlockQueue) {
|
if (isNeedToResetQueue) {
|
||||||
returnTxs.push(...queue.gateway.unlock(getRawContext()));
|
returnTxs.push(...queue.gateway.unlock(getRawContext()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,8 @@
|
|||||||
import {
|
import { constructContinueTx, FullCallInfo, NewTx, PreparedOperation, prepareQueueCall } from '@coinweb/contract-kit';
|
||||||
constructContinueTx,
|
import { queueCostFee } from 'lib/onchain';
|
||||||
constructContractRef,
|
|
||||||
FullCallInfo,
|
|
||||||
NewTx,
|
|
||||||
PreparedOperation,
|
|
||||||
} from '@coinweb/contract-kit';
|
|
||||||
|
|
||||||
import { ExecutorMethodArgs, Task } from '../../../types';
|
import { ExecutorMethodArgs, Task } from '../../../types';
|
||||||
import { context, getRawContext } from '../../context';
|
import { context, getRawContext } from '../../context';
|
||||||
import { isQueueLocked } from '../../queue/queue';
|
|
||||||
import { isPreparedExecOp } from '../typeGuards';
|
import { isPreparedExecOp } from '../typeGuards';
|
||||||
|
|
||||||
export const prepareOutThreadTxs = ({
|
export const prepareOutThreadTxs = ({
|
||||||
@ -41,8 +35,7 @@ export const prepareOutThreadTxs = ({
|
|||||||
const id = task.op.ExecOp.id;
|
const id = task.op.ExecOp.id;
|
||||||
|
|
||||||
const callInfo = {
|
const callInfo = {
|
||||||
callInfo: {
|
callInfo: prepareQueueCall(context.issuer, {
|
||||||
ref: constructContractRef(context.issuer, []),
|
|
||||||
methodInfo: {
|
methodInfo: {
|
||||||
methodName: context.methodName,
|
methodName: context.methodName,
|
||||||
methodArgs: [
|
methodArgs: [
|
||||||
@ -53,15 +46,14 @@ export const prepareOutThreadTxs = ({
|
|||||||
context.parentId ?? context.thisId,
|
context.parentId ?? context.thisId,
|
||||||
false,
|
false,
|
||||||
[],
|
[],
|
||||||
isQueueLocked(),
|
|
||||||
] satisfies ExecutorMethodArgs,
|
] satisfies ExecutorMethodArgs,
|
||||||
},
|
},
|
||||||
contractInfo: {
|
contractInfo: {
|
||||||
providedCweb: cwebPerCall - 700n,
|
providedCweb: cwebPerCall - 700n - queueCostFee,
|
||||||
authenticated: null,
|
authenticated: null,
|
||||||
},
|
},
|
||||||
contractArgs: [],
|
contractArgs: [],
|
||||||
},
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (siblingTxInfo[task.batchId]) {
|
if (siblingTxInfo[task.batchId]) {
|
||||||
|
|||||||
@ -45,5 +45,4 @@ export type ExecutorMethodArgs = [
|
|||||||
parentId?: string,
|
parentId?: string,
|
||||||
saveResult?: boolean,
|
saveResult?: boolean,
|
||||||
takenFundsIds?: string[],
|
takenFundsIds?: string[],
|
||||||
isQueue?: boolean,
|
|
||||||
];
|
];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user