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

feat: print feed update references #522

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading