From ac250a8907d92344dfb5f53626620a8a30bb971a Mon Sep 17 00:00:00 2001 From: Weronika K Date: Wed, 23 Aug 2023 11:10:15 +0200 Subject: [PATCH] fix: set cache only flag for state uploads --- src/core/batch.ts | 4 ++-- src/core/membership.ts | 12 ++++++------ src/core/memo.ts | 4 ++-- src/core/node.ts | 4 ++-- src/core/service.ts | 6 +++--- src/core/vault.ts | 8 ++++---- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/core/batch.ts b/src/core/batch.ts index 6b19dd8f..70062521 100644 --- a/src/core/batch.ts +++ b/src/core/batch.ts @@ -174,7 +174,7 @@ class BatchService extends Service { versions: [version], tags: service.tags }; - const id = await service.uploadState(state); + const id = await service.uploadState(state, service.vault.cacheOnly); // queue the stack transaction for posting transactions.push({ @@ -278,7 +278,7 @@ class BatchService extends Service { service.arweaveTags = [new Tag(protocolTags.MEMBER_ADDRESS, address)] .concat(await service.getTxTags()); - const dataTxId = await service.uploadState(state); + const dataTxId = await service.uploadState(state, service.vault.cacheOnly); transactions.push({ vaultId, diff --git a/src/core/membership.ts b/src/core/membership.ts index 9e2cbb32..6c69a670 100644 --- a/src/core/membership.ts +++ b/src/core/membership.ts @@ -107,7 +107,7 @@ class MembershipService extends Service { service.arweaveTags = [new Tag(protocolTags.MEMBER_ADDRESS, address)] .concat(await service.getTxTags()); - const dataTxId = await service.uploadState(state); + const dataTxId = await service.uploadState(state, service.vault.cacheOnly); const input = { function: service.function, @@ -161,7 +161,7 @@ class MembershipService extends Service { memberDetails: await service.processMemberDetails({ name: member.options?.name }, service.vault.cacheOnly), }; - const data = await service.uploadState(state); + const data = await service.uploadState(state, service.vault.cacheOnly); dataArray.push({ id: membershipId, data @@ -209,7 +209,7 @@ class MembershipService extends Service { service.setActionRef(actionRefs.MEMBERSHIP_ACCEPT); service.setFunction(functions.MEMBERSHIP_ACCEPT); - const data = await service.mergeAndUploadState(state); + const data = await service.mergeAndUploadState(state, service.vault.cacheOnly); const { id, object } = await this.api.postContractTransaction( service.vaultId, { function: service.function, data }, @@ -238,7 +238,7 @@ class MembershipService extends Service { service.arweaveTags = [new Tag(protocolTags.MEMBER_ADDRESS, address)] .concat(await service.getTxTags()); - const dataTxId = await service.uploadState(state); + const dataTxId = await service.uploadState(state, service.vault.cacheOnly); const input = { function: service.function, @@ -329,7 +329,7 @@ class MembershipService extends Service { memberService.setVaultId(service.vaultId); memberService.setObjectId(member.id); memberService.setObject(member); - const dataTx = await memberService.mergeAndUploadState({ keys: memberKeys.get(member.id) }); + const dataTx = await memberService.mergeAndUploadState({ keys: memberKeys.get(member.id) }, service.vault.cacheOnly); data.push({ id: member.id, value: dataTx }); })); } @@ -407,7 +407,7 @@ class MembershipService extends Service { service.setActionRef(actionRefs.MEMBERSHIP_PROFILE_UPDATE); service.setFunction(functions.MEMBERSHIP_UPDATE); - const data = await service.mergeAndUploadState({ memberDetails }); + const data = await service.mergeAndUploadState({ memberDetails }, service.vault.cacheOnly); const { id, object } = await this.api.postContractTransaction( service.vaultId, { function: service.function, data }, diff --git a/src/core/memo.ts b/src/core/memo.ts index 0824d9ea..3389cca3 100644 --- a/src/core/memo.ts +++ b/src/core/memo.ts @@ -54,7 +54,7 @@ class MemoService extends NodeService { const currentState = await service.getCurrentState(); const newState = lodash.cloneDeepWith(currentState); newState.versions[newState.versions.length - 1].reactions.push(await service.memoReaction(reaction)); - const dataTxId = await service.uploadState(newState); + const dataTxId = await service.uploadState(newState, service.vault.cacheOnly); const { id, object } = await this.api.postContractTransaction( service.vaultId, @@ -78,7 +78,7 @@ class MemoService extends NodeService { service.arweaveTags = await service.getTxTags(); const state = await service.deleteReaction(reaction); - const dataTxId = await service.uploadState(state); + const dataTxId = await service.uploadState(state, service.vault.cacheOnly); const { id, object } = await this.api.postContractTransaction( service.vaultId, diff --git a/src/core/node.ts b/src/core/node.ts index a8581b9c..afd5203a 100644 --- a/src/core/node.ts +++ b/src/core/node.ts @@ -173,7 +173,7 @@ class NodeService extends Service { } as ContractInput; if (state) { - const id = await this.uploadState(state); + const id = await this.uploadState(state, this.vault.cacheOnly); input.data = id; } @@ -196,7 +196,7 @@ class NodeService extends Service { this.arweaveTags = await this.getTxTags(); if (stateUpdates) { - const id = await this.mergeAndUploadState(stateUpdates); + const id = await this.mergeAndUploadState(stateUpdates, this.vault.cacheOnly); input.data = id; } const { id, object } = await this.api.postContractTransaction( diff --git a/src/core/service.ts b/src/core/service.ts index 3bb2b817..26f5e9ee 100644 --- a/src/core/service.ts +++ b/src/core/service.ts @@ -165,7 +165,7 @@ class Service { } } - async uploadState(state: any, cacheOnly = false): Promise { + async uploadState(state: any, cacheOnly = true): Promise { const signature = await this.signData(state); const tags = [ new Tag(dataTags.DATA_TYPE, "State"), @@ -266,10 +266,10 @@ class Service { : {}; } - protected async mergeAndUploadState(stateUpdates: any): Promise { + protected async mergeAndUploadState(stateUpdates: any, cacheOnly = true): Promise { const currentState = await this.getCurrentState(); const mergedState = mergeState(currentState, stateUpdates); - return this.uploadState(mergedState); + return this.uploadState(mergedState, cacheOnly); } private async signData(data: any): Promise { diff --git a/src/core/vault.ts b/src/core/vault.ts index f6de76ba..75c7e717 100644 --- a/src/core/vault.ts +++ b/src/core/vault.ts @@ -193,7 +193,7 @@ class VaultService extends Service { service.setAkordTags((options.name && service.isPublic ? [options.name] : []).concat(options.tags)); service.arweaveTags = await service.getTxTags(); - const dataTxId = await service.uploadState(newState); + const dataTxId = await service.uploadState(newState, service.vault.cacheOnly); const { id, object } = await this.api.postContractTransaction( service.vaultId, { function: service.function, data: dataTxId }, @@ -216,7 +216,7 @@ class VaultService extends Service { const state = { name: await service.processWriteString(name) }; - const data = await service.mergeAndUploadState(state); + const data = await service.mergeAndUploadState(state, service.vault.cacheOnly); service.setAkordTags(service.isPublic ? [name] : []); service.arweaveTags = await service.getTxTags(); @@ -253,7 +253,7 @@ class VaultService extends Service { newState.tags.push(tag); } } - const dataTxId = await service.uploadState(newState); + const dataTxId = await service.uploadState(newState, service.vault.cacheOnly); const { id, object } = await this.api.postContractTransaction( service.vaultId, @@ -285,7 +285,7 @@ class VaultService extends Service { const index = this.getTagIndex(newState.tags, tag); newState.tags.splice(index, 1); } - const dataTxId = await service.uploadState(newState); + const dataTxId = await service.uploadState(newState, service.vault.cacheOnly); const { id, object } = await this.api.postContractTransaction( service.vaultId,