Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
Use the new dag api and use ipld links for both heads and next pointers
Browse files Browse the repository at this point in the history
This change is backwards compatible, meaning the old logs can still be read.

Also updated IPFS to latest version as the current installed one has breaking changes to the dag api.
This way, we are already using the new dag api.
  • Loading branch information
satazor committed Jan 3, 2019
1 parent 1e156dd commit 2a9ae2f
Show file tree
Hide file tree
Showing 12 changed files with 1,646 additions and 1,364 deletions.
32 changes: 18 additions & 14 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const tails = log.tails

#### append(data)

Append an entry to the log. Returns a *Promise* that resolves to the updated `Log`.
Append an entry to the log. Returns a *Promise* that resolves to the added `Entry`.

`ipfs` IPFS instance.

Expand All @@ -75,31 +75,31 @@ Append an entry to the log. Returns a *Promise* that resolves to the updated `Lo

```javascript
log.append({ some: 'data' })
.then(log => log.append('text'))
.then(log => console.log(log.values))
.then(() => log.append('text'))
.then(() => console.log(log.values))

// [
// {
// hash: 'QmV1KFxZnaguPFp57PMXz5Dd1tf6z9U8csJQoy4xWDzzts',
// [
// {
// hash: 'zdpuAkYarxnBQD7dQcr5onfzCTkTW8FebzC9nY5FviAveSzCL',
// id: 'A',
// payload: { some: 'data' },
// next: [],
// v: 0,
// clock: LamportClock { id: 'A', time: 0 }
// v: 1,
// clock: LamportClock { id: 'A', time: 0 }
// },
// { hash: 'QmSxe4Shd7jt4ExyoBjtvgi1UabNKrZfRJKptwUmSa843u',
// { hash: 'zdpuAx4RKTtSkrpA8LKP5vzUdAoWExxLHrRjK2s8YEayDBQDC',
// id: 'A',
// payload: 'text',
// next: [ 'QmV1KFxZnaguPFp57PMXz5Dd1tf6z9U8csJQoy4xWDzzts' ],
// v: 0,
// clock: LamportClock { id: 'A', time: 1 }
// }
// next: [ 'zdpuAkYarxnBQD7dQcr5onfzCTkTW8FebzC9nY5FviAveSzCL' ],
// v: 1,
// clock: LamportClock { id: 'A', time: 1 }
// }
// ]
```

#### join(log, [length], [id])

Join the log with another log. Returns a Promise that resolves to a `Log` instance. The size of the joined log can be specified by giving `length` argument.
Join the log with another log. Returns a Promise that resolves to a `Log` instance. The size of the joined log can be specified by giving `length` argument.

```javascript
// log1.values ==> ['A', 'B', 'C']
Expand All @@ -121,6 +121,8 @@ log1.toMultihash()
// QmSUrxz12UDsuuQMjzBQ4NDGyYprhFJbQefgeRiomQ5j6T
```

You can take the hash and inspect the DAG in [explore.ipld.io](https://explore.ipld.io/).

### toBuffer()

Converts the log to a `Buffer` that contains the log as JSON.stringified `string`. Returns a `Buffer`.
Expand Down Expand Up @@ -165,6 +167,8 @@ Returns the multihash of the log.

Converting the log to a multihash will persist the log to IPFS, thus causing side effects.

You can take the hash and inspect the DAG in [explore.ipld.io](https://explore.ipld.io/).

#### Log.fromMultihash(ipfs, multihash, [length=-1])

Create a `Log` from a multihash.
Expand Down
Loading

0 comments on commit 2a9ae2f

Please sign in to comment.