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

issue appending to loaded Log #274

Open
sdelvalle57 opened this issue Nov 1, 2019 · 1 comment
Open

issue appending to loaded Log #274

sdelvalle57 opened this issue Nov 1, 2019 · 1 comment

Comments

@sdelvalle57
Copy link

sdelvalle57 commented Nov 1, 2019

Hey Guys

I have an issue trying to append new data to a log loaded.
What Im doing so far is:

  1. Creating a new entry
    const uid = 12345;
    const identity = await IdentityProvider.createIdentity({ id: dbName });
    const log = new Log(ipfs, identity, { logId: uid });
    await log.append({uid});
    const hash = await log.toMultihash();
    console.log(log.toSnapshot().values.length) //1
   return hash;
  1. With the hash returned load the Log and append new object
    const newObj = {timestamp: 12345454555};
    const identity = await IdentityProvider.createIdentity({ id: dbName });
    const log = await Log.fromMultihash(ipfs, identity, hash, {});
    await log.append(dbObject)
    console.log(log.toSnapshot().values.length) //2

At this point everything seems ok, but when I reload to fetch the new data, Is like if I didnt append the last object:

    const identity = await IdentityProvider.createIdentity({ id: dbName });
    const log = await Log.fromMultihash(ipfs, identity, hash, {});
    console.log(log.toSnapshot().values.length) //1, and only shows the object created in step 1

I dont really know what Im missing to keep the new object I created in step 2

Thanks

@shamb0t
Copy link
Contributor

shamb0t commented Nov 1, 2019

Hey @sdelvalle57 👋

toMultihash will return a different hash after each append. You are using the hash which corresponds to the log with one entry. To retrieve subsequent entries you will need to call toMultihash again after the appends to get the correct hash:

    const newObj = {timestamp: 12345454555};
    const identity = await IdentityProvider.createIdentity({ id: dbName });
    const log = await Log.fromMultihash(ipfs, identity, hash, {});
    await log.append(newObject)
    console.log(log.toSnapshot().values.length) //2
    const newHash = await log.toMultihash() // Hash of log which includes `newObj`
...
    const identity = await IdentityProvider.createIdentity({ id: dbName });
    const log = await Log.fromMultihash(ipfs, identity, newHash, { logId: uid });
    console.log(log.toSnapshot().values.length) // should be 2

Does that fix your issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants