Skip to content

Commit

Permalink
fix: set cache only flag for state uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
wkolod committed Aug 23, 2023
1 parent 2dcf119 commit ac250a8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/core/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions src/core/membership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Membership>(
service.vaultId,
{ function: service.function, data },
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 });
}));
}
Expand Down Expand Up @@ -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<Membership>(
service.vaultId,
{ function: service.function, data },
Expand Down
4 changes: 2 additions & 2 deletions src/core/memo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MemoService extends NodeService<Memo> {
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<Memo>(
service.vaultId,
Expand All @@ -78,7 +78,7 @@ class MemoService extends NodeService<Memo> {
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<Memo>(
service.vaultId,
Expand Down
4 changes: 2 additions & 2 deletions src/core/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class NodeService<T> extends Service {
} as ContractInput;

if (state) {
const id = await this.uploadState(state);
const id = await this.uploadState(state, this.vault.cacheOnly);
input.data = id;
}

Expand All @@ -196,7 +196,7 @@ class NodeService<T> 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<T>(
Expand Down
6 changes: 3 additions & 3 deletions src/core/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class Service {
}
}

async uploadState(state: any, cacheOnly = false): Promise<string> {
async uploadState(state: any, cacheOnly = true): Promise<string> {
const signature = await this.signData(state);
const tags = [
new Tag(dataTags.DATA_TYPE, "State"),
Expand Down Expand Up @@ -266,10 +266,10 @@ class Service {
: {};
}

protected async mergeAndUploadState(stateUpdates: any): Promise<string> {
protected async mergeAndUploadState(stateUpdates: any, cacheOnly = true): Promise<string> {
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<string> {
Expand Down
8 changes: 4 additions & 4 deletions src/core/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vault>(
service.vaultId,
{ function: service.function, data: dataTxId },
Expand All @@ -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();

Expand Down Expand Up @@ -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<Vault>(
service.vaultId,
Expand Down Expand Up @@ -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<Vault>(
service.vaultId,
Expand Down

0 comments on commit ac250a8

Please sign in to comment.