Skip to content

Commit 4e5a115

Browse files
committed
fixed some bugs
1 parent 026eca4 commit 4e5a115

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/data/collections/causal/CausalArray.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class CausalArray<T> extends BaseCausalCollection<T> implements CausalCollection
178178
_ordinals : Array<Ordinal>;
179179

180180
constructor(config?: MutableArrayConfig & CausalCollectionConfig) {
181-
super(CausalArray.opClasses, config);
181+
super(CausalArray.opClasses, {...config, supportsUndo: true});
182182

183183
this.setRandomId();
184184

@@ -593,6 +593,8 @@ class CausalArray<T> extends BaseCausalCollection<T> implements CausalCollection
593593

594594
shouldAcceptMutationOp(op: MutationOp, opReferences: Map<Hash, HashedObject>): boolean {
595595

596+
console.log('VALIDATING....')
597+
596598
if (!super.shouldAcceptMutationOp(op, opReferences)) {
597599
return false;
598600
}
@@ -610,16 +612,24 @@ class CausalArray<T> extends BaseCausalCollection<T> implements CausalCollection
610612
this.createDeleteAuthorizerByHash(
611613
HashedObject.hashElement(op.getInsertOp().element), author);
612614

615+
console.log('verifying mutation op for ' + this.hash());
616+
console.log('auth', auth);
617+
613618
const usedKeys = new Set<string>();
614619

615620
if (!auth.verify(op, usedKeys)) {
621+
console.log('verification failed')
616622
return false;
617623
}
618624

625+
console.log('verification OK')
626+
619627
if (!Verification.checkKeys(usedKeys, op)) {
620628
return false;
621629
}
622630

631+
console.log('keys OK: ', usedKeys);
632+
623633
}
624634

625635
return true;

src/data/model/causal/Authorization.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { HashedMap } from 'data/model';
12
import { HashedSet } from '../immutable/HashedSet';
23
import { MutationOp } from '../mutable/MutationOp';
34

@@ -48,12 +49,12 @@ class Attestation {
4849
= (a1: Attestator, a2?: Attestator) =>
4950
( async (op: MutationOp) => {
5051

51-
const savedCausalOps = op.getCausalOps().entries();
52+
const savedCausalOps = new HashedMap(op.getCausalOps().entries());
5253

5354
if (await a1(op) && (a2 === undefined || await a2(op))) {
5455
return true;
5556
} else {
56-
op.setCausalOps(savedCausalOps)
57+
op.setCausalOps(savedCausalOps.entries())
5758
return false;
5859
}
5960
}
@@ -77,11 +78,11 @@ class Attestation {
7778
= (authorizers: Array<Attestator>) =>
7879
async (op: MutationOp) => {
7980

80-
const savedCausalOps = op.getCausalOps().entries();
81+
const savedCausalOps = new HashedMap(op.getCausalOps().entries());
8182

8283
for (const authorize of authorizers) {
8384
if (!(await authorize(op))) {
84-
op.setCausalOps(savedCausalOps);
85+
op.setCausalOps(savedCausalOps.entries());
8586
return false;
8687
}
8788
}

src/data/model/immutable/HashedObject.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ abstract class HashedObject {
101101
// would be).
102102

103103
this.author = author;
104-
this._signOnSave = true;
105-
104+
105+
if (author !== undefined) {
106+
this._signOnSave = true;
107+
}
106108
}
107109

108110
getAuthor() {

0 commit comments

Comments
 (0)