feat: interact wrtite; feat: tags and ar transfers

This commit is contained in:
ppedziwiatr
2021-08-29 00:16:38 +02:00
parent 71cc4217d3
commit 779bfa452d
16 changed files with 578 additions and 232 deletions

View File

@@ -21,7 +21,9 @@ export class CacheableExecutorFactory<Api> implements ExecutorFactory<Api> {
// with the same SwGlobal object being cached for all contracts with the same source code
// (eg. SwGlobal.contract.id field - which of course should have different value for different contracts
// that share the same source).
const cacheKey = contractDefinition.txId;
// warn#2: cache key MUST be a combination of both txId and srcTxId -
// as "evolve" feature changes the srcTxId for the given txId...
const cacheKey = `${contractDefinition.txId}_${contractDefinition.srcTxId}`;
if (!this.cache.contains(cacheKey)) {
logger.debug('Updating executor factory cache');
const handler = await this.baseImplementation.create(contractDefinition);

View File

@@ -24,8 +24,8 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator {
super(arweave, executionContextModifiers);
}
async eval<State, Api>(
executionContext: ExecutionContext<State>,
async eval<State>(
executionContext: ExecutionContext<State, HandlerApi<State>>,
currentTx: { interactionTxId: string; contractTxId: string }[]
): Promise<EvalStateResult<State>> {
const requestedBlockHeight = executionContext.blockHeight;

View File

@@ -50,7 +50,10 @@ export class Evolve implements ExecutionContextModifier {
this.modify = this.modify.bind(this);
}
async modify<State>(state: State, executionContext: ExecutionContext<State>): Promise<ExecutionContext<State>> {
async modify<State>(
state: State,
executionContext: ExecutionContext<State, HandlerApi<State>>
): Promise<ExecutionContext<State, HandlerApi<State>>> {
const contractTxId = executionContext.contractDefinition.txId;
logger.debug(`trying to evolve for: ${contractTxId}`);
if (!isEvolveCompatible(state)) {
@@ -79,10 +82,11 @@ export class Evolve implements ExecutionContextModifier {
if (currentSrcTxId !== evolve) {
try {
// note: that's really nasty IMO - loading original contract definition, but forcing different sourceTxId...
// note: that's really nasty IMO - loading original contract definition,
// but forcing different sourceTxId...
logger.info('Evolving to: ', evolve);
const newContractDefinition = await this.definitionLoader.load<State>(contractTxId, evolve);
const newHandler = await this.executorFactory.create<State>(newContractDefinition);
const newHandler = (await this.executorFactory.create<State>(newContractDefinition)) as HandlerApi<State>;
const modifiedContext = {
...executionContext,