From 2a27f34e8776968c34fbf510e01a107be4b7440d Mon Sep 17 00:00:00 2001 From: Cafe137 Date: Thu, 27 Jun 2024 01:51:36 +0200 Subject: [PATCH] feat: print feed update references --- src/command/feed/print.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/command/feed/print.ts b/src/command/feed/print.ts index 753163ef..de514d23 100644 --- a/src/command/feed/print.ts +++ b/src/command/feed/print.ts @@ -1,3 +1,4 @@ +import { Utils } from '@ethersphere/bee-js' import { makeChunk } from '@fairdatasociety/bmt-js' import { Binary } from 'cafe-utility' import Wallet from 'ethereumjs-wallet' @@ -25,11 +26,15 @@ export class Print extends FeedCommand implements LeafCommand { }) public address!: string + @Option({ key: 'list', type: 'boolean', description: 'List all updates' }) + public list!: boolean + public async run(): Promise { await super.init() const topic = this.topic || this.bee.makeFeedTopic(this.topicString) + // construct the feed manifest chunk const body = Binary.concatBytes( new Uint8Array(32), new Uint8Array([ @@ -74,7 +79,25 @@ export class Print extends FeedCommand implements LeafCommand { this.console.verbose(createKeyValue('Feed Manifest', manifest)) this.console.log(createKeyValue('Topic', `${topic}`)) - this.console.log(createKeyValue('Number of Updates', parseInt(feedIndex as string, 16) + 1)) + const numberOfUpdates = parseInt(feedIndex as string, 16) + 1 + this.console.log(createKeyValue('Number of Updates', numberOfUpdates)) + + if (this.list) { + for (let i = 0; i < numberOfUpdates; i++) { + const indexBytes = Binary.numberToUint64BE(i) + const identifier = Utils.keccak256Hash(Binary.hexToUint8Array(topic), indexBytes) + const owner = Binary.hexToUint8Array(this.address) + const soc = Binary.uint8ArrayToHex(Utils.keccak256Hash(identifier, owner)) + const chunk = await this.bee.downloadChunk(soc) + // span + identifier + signature + span + const cac = Binary.uint8ArrayToHex(chunk.slice(8 + 32 + 65 + 8, 8 + 32 + 65 + 32 + 8)) + this.console.log('') + this.console.log(createKeyValue(`Update ${i}`, cac)) + this.console.log(`${this.bee.url}/bzz/${cac}/`) + } + } else { + this.console.log('Run with --list to see all updates') + } } catch (error) { spinner.stop() const message = getFieldOrNull(error, 'message')