ethersphere/bee-js

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

Closed this issue · 0 comments

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.