Skip to content

Commit

Permalink
feat: print feed update references (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cafe137 authored Jun 26, 2024
1 parent 01bc9b7 commit 972c750
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/command/feed/print.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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<void> {
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([
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 972c750

Please sign in to comment.