Skip to content

Commit

Permalink
fix(core): use correct CID format
Browse files Browse the repository at this point in the history
  • Loading branch information
oed committed Apr 3, 2020
1 parent bd4cc52 commit 4ca5b8d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const RECORDS = {
genesis: { doctype: '3id', owners: [ '0x123' ], content: { publicKeys: { test: '0xabc' } } },
r1: {
desiredContent: { publicKeys: { test: '0xabc' }, other: 'data' },
record: { content: [ { op: 'add', path: '/other', value: 'data' } ], next: 'cid1', header: 'aaaa', signature: 'cccc' }
record: { content: [ { op: 'add', path: '/other', value: 'data' } ], next: { '/': 'cid1' }, header: 'aaaa', signature: 'cccc' }
},
r2: { proof: { blockNumber: 123456 } }
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ceramic-core/src/doctypes/threeIdHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ThreeIdHandler extends DoctypeHandler {
async makeRecord (state: DocState, newContent: any): Promise<any> {
if (!this.user) throw new Error('No user authenticated')
const patch = jsonpatch.compare(state.content, newContent)
const record: any = { content: patch, next: head(state.log) }
const record: any = { content: patch, next: { '/': head(state.log) } }
// TODO - use the dag-jose library for properly encoded signed records
record.iss = this.user.DID
const jwt = await this.user.sign(record, { useMgmt: true})
Expand Down
2 changes: 1 addition & 1 deletion packages/ceramic-core/src/doctypes/tileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class TileHandler extends DoctypeHandler {
async makeRecord (state: DocState, newContent: any): Promise<any> {
if (!this.user) throw new Error('No user authenticated')
const patch = jsonpatch.compare(state.content, newContent)
const record = { content: patch, next: head(state.log) }
const record = { content: patch, next: { '/': head(state.log) } }
return this.signRecord(record)
}

Expand Down
8 changes: 4 additions & 4 deletions packages/ceramic-core/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Document extends EventEmitter {
return []
}
const record = await this.dispatcher.retrieveRecord(cid)
const nextCid = record.next?.toString()
const nextCid = record.next ? record.next['/'].toString() : null
if (!nextCid) { // this is a fake log
return []
}
Expand All @@ -145,14 +145,14 @@ class Document extends EventEmitter {
if (log[log.length - 1] === this.head) return // log already applied
const cid = log[0]
const record = await this.dispatcher.retrieveRecord(cid)
if (record.next.toString() === this.head) {
if (record.next['/'].toString() === this.head) {
// the new log starts where the previous one ended
this._state = await this._applyLogToState(log, deepCopy(this._state))
modified = true
} else {
// we have a conflict since next is in the log of the
// local state, but isn't the head
const conflictIdx = this._state.log.indexOf(record.next.toString()) + 1
const conflictIdx = this._state.log.indexOf(record.next['/'].toString()) + 1
const canonicalLog = this._state.log.slice() // copy log
const localLog = canonicalLog.splice(conflictIdx)
// Compute state up till conflictIdx
Expand Down Expand Up @@ -207,7 +207,7 @@ class Document extends EventEmitter {
txHash: 'eth-cid',
root: 'cid'
}
const record = { proof, path: 'ipld path for witness', next: this.head }
const record = { proof, path: 'ipld path for witness', next: { '/': this.head } }
const cid = (await this.dispatcher.storeRecord(record)).toString()
this._state = await this._doctype.applyRecord(record, cid, this._state)
return true
Expand Down

0 comments on commit 4ca5b8d

Please sign in to comment.