Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The upload function returned by makeFeedWriter can't utilise the index option #904

Closed
LevilkTheReal opened this issue Feb 12, 2024 · 0 comments

Comments

@LevilkTheReal
Copy link
Contributor

LevilkTheReal commented Feb 12, 2024

The returned upload function can have an option parameter:

  const upload = async (
    postageBatchId: string | Address,
    reference: BytesReference | Reference,
    options?: FeedUploadOptions,
  ) => {
    assertAddress(postageBatchId)
    const canonicalReference = makeBytesReference(reference)

    return updateFeed(requestOptions, signer, topic, canonicalReference, postageBatchId, { ...options, type })
  }

This option parameter might have an explicit index for the feed.

The problem is that the called updateFeed is using an additional parameter named index instead of the index from the options object param thus we can't set the index explicitly.

 export async function updateFeed(
  requestOptions: BeeRequestOptions,
  signer: Signer,
  topic: Topic,
  reference: BytesReference,
  postageBatchId: BatchId,
  options?: FeedUploadOptions,
  index: Index = 'latest',
): Promise<Reference> {
  const ownerHex = makeHexEthAddress(signer.address)
  const nextIndex = index === 'latest' ? await findNextIndex(requestOptions, ownerHex, topic, options) : index

  const identifier = makeFeedIdentifier(topic, nextIndex)
  const at = options?.at ?? Date.now() / 1000.0
  const timestamp = writeUint64BigEndian(at)
  const payloadBytes = serializeBytes(timestamp, reference)

  return uploadSingleOwnerChunkData(requestOptions, signer, postageBatchId, identifier, payloadBytes, options)
}

Recommended solution:
Remove the index param and use the index from the options object param.

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

No branches or pull requests

2 participants