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

fix: do not require stamp for feed print #520

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
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
17 changes: 7 additions & 10 deletions src/command/feed/feed-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { exit } from 'process'
import { getWalletFromIdentity, pickIdentity } from '../../service/identity'
import { Identity } from '../../service/identity/types'
import { printStamp } from '../../service/stamp'
import { stampProperties, topicProperties, topicStringProperties } from '../../utils/option'
import { topicProperties, topicStringProperties } from '../../utils/option'
import { createSpinner } from '../../utils/spinner'
import { createKeyValue } from '../../utils/text'
import { RootCommand } from '../root-command'
Expand All @@ -17,9 +17,6 @@ interface FeedInfo {
}

export class FeedCommand extends RootCommand {
@Option(stampProperties)
public stamp!: string

@Option({
key: 'identity',
alias: 'i',
Expand All @@ -38,10 +35,10 @@ export class FeedCommand extends RootCommand {
@Option({ key: 'password', alias: 'P', description: 'Password for the wallet' })
public password!: string

protected async updateFeedAndPrint(chunkReference: string): Promise<string> {
protected async updateFeedAndPrint(stamp: string, chunkReference: string): Promise<string> {
const wallet = await this.getWallet()
const topic = this.topic || this.bee.makeFeedTopic(this.topicString)
const { reference, manifest } = await this.writeFeed(wallet, topic, chunkReference)
const { reference, manifest } = await this.writeFeed(stamp, wallet, topic, chunkReference)

this.console.verbose(createKeyValue('Chunk Reference', chunkReference))
this.console.verbose(createKeyValue('Chunk Reference URL', `${this.bee.url}/bzz/${chunkReference}/`))
Expand All @@ -52,7 +49,7 @@ export class FeedCommand extends RootCommand {
this.console.quiet(manifest)

if (!this.quiet) {
printStamp(await this.bee.getPostageBatch(this.stamp), this.console, { shortenBatchId: true })
printStamp(await this.bee.getPostageBatch(stamp), this.console, { shortenBatchId: true })
}

return manifest
Expand All @@ -79,7 +76,7 @@ export class FeedCommand extends RootCommand {
return identities[this.identity] || identities[await pickIdentity(this.commandConfig, this.console)]
}

private async writeFeed(wallet: Wallet, topic: string, chunkReference: string): Promise<FeedInfo> {
private async writeFeed(stamp: string, wallet: Wallet, topic: string, chunkReference: string): Promise<FeedInfo> {
const spinner = createSpinner('Writing feed...')

if (this.verbosity !== VerbosityLevel.Quiet && !this.curl) {
Expand All @@ -88,9 +85,9 @@ export class FeedCommand extends RootCommand {

try {
const writer = this.bee.makeFeedWriter('sequence', topic, wallet.getPrivateKey())
const reference = await writer.upload(this.stamp, chunkReference as Reference)
const reference = await writer.upload(stamp, chunkReference as Reference)
const { reference: manifest } = await this.bee.createFeedManifest(
this.stamp,
stamp,
'sequence',
topic,
wallet.getAddressString(),
Expand Down
45 changes: 33 additions & 12 deletions src/command/feed/print.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { makeChunk } from '@fairdatasociety/bmt-js'
import { Binary } from 'cafe-utility'
import Wallet from 'ethereumjs-wallet'
import { LeafCommand, Option } from 'furious-commander'
import { exit } from 'process'
import { isSimpleWallet, isV3Wallet } from '../../service/identity'
import { Identity } from '../../service/identity/types'
import { pickStamp } from '../../service/stamp'
import { getFieldOrNull } from '../../utils'
import { createSpinner } from '../../utils/spinner'
import { createKeyValue } from '../../utils/text'
Expand All @@ -28,31 +29,51 @@ export class Print extends FeedCommand implements LeafCommand {
await super.init()

const topic = this.topic || this.bee.makeFeedTopic(this.topicString)

const body = Binary.concatBytes(
new Uint8Array(32),
new Uint8Array([
0x57, 0x68, 0xb3, 0xb6, 0xa7, 0xdb, 0x56, 0xd2, 0x1d, 0x1a, 0xbf, 0xf4, 0x0d, 0x41, 0xce, 0xbf, 0xc8, 0x34,
0x48, 0xfe, 0xd8, 0xd7, 0xe9, 0xb0, 0x6e, 0xc0, 0xd3, 0xb0, 0x73, 0xf2, 0x8f, 0x20,
]),
new Uint8Array(37),
new Uint8Array([0x80]),
new Uint8Array(26),
new Uint8Array([0x12, 0x01, 0x2f]),
new Uint8Array(29),
new Uint8Array([
0x85, 0x04, 0xf2, 0xa1, 0x07, 0xca, 0x94, 0x0b, 0xea, 0xfc, 0x4c, 0xe2, 0xf6, 0xc9, 0xa9, 0xf0, 0x96, 0x8c,
0x62, 0xa5, 0xb5, 0x89, 0x3f, 0xf0, 0xe4, 0xe1, 0xe2, 0x98, 0x30, 0x48, 0xd2, 0x76, 0x00, 0xbe,
]),
new TextEncoder().encode(
`{"swarm-feed-owner":"${this.address}","swarm-feed-topic":"${this.topic}","swarm-feed-type":"Sequence"}`,
),
new Uint8Array(12).fill(0x0a),
)

const manifest = Binary.uint8ArrayToHex(makeChunk(body).address())
this.console.quiet(manifest)

if (this.quiet) {
return
}
this.console.log(createKeyValue('Feed Manifest URL', `${this.bee.url}/bzz/${manifest}/`))

const spinner = createSpinner(`Looking up feed topic ${topic}`)
spinner.start()

try {
const addressString = this.address || (await this.getAddressString())
const reader = this.bee.makeFeedReader('sequence', topic, addressString)
const { reference, feedIndex, feedIndexNext } = await reader.download()

if (!this.stamp) {
spinner.stop()
this.stamp = await pickStamp(this.bee, this.console)
spinner.start()
}

const { reference: manifest } = await this.bee.createFeedManifest(this.stamp, 'sequence', topic, addressString)

spinner.stop()
this.console.verbose(createKeyValue('Chunk Reference', reference))
this.console.verbose(createKeyValue('Chunk Reference URL', `${this.bee.url}/bzz/${reference}/`))
this.console.verbose(createKeyValue('Feed Index', feedIndex as string))
this.console.verbose(createKeyValue('Next Index', feedIndexNext))
this.console.verbose(createKeyValue('Feed Manifest', manifest))

this.console.quiet(manifest)
this.console.log(createKeyValue('Topic', `${topic}`))
this.console.log(createKeyValue('Feed Manifest URL', `${this.bee.url}/bzz/${manifest}/`))
this.console.log(createKeyValue('Number of Updates', parseInt(feedIndex as string, 16) + 1))
} catch (error) {
spinner.stop()
Expand Down
6 changes: 5 additions & 1 deletion src/command/feed/update.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { LeafCommand, Option } from 'furious-commander'
import { pickStamp } from '../../service/stamp'
import { stampProperties } from '../../utils/option'
import { FeedCommand } from './feed-command'

export class Update extends FeedCommand implements LeafCommand {
public readonly name = 'update'

public readonly description = 'Update feed'

@Option(stampProperties)
public stamp!: string

@Option({ key: 'reference', alias: 'r', description: 'The new reference', required: true })
public reference!: string

Expand All @@ -17,7 +21,7 @@ export class Update extends FeedCommand implements LeafCommand {
this.stamp = await pickStamp(this.bee, this.console)
}

await this.updateFeedAndPrint(this.reference)
await this.updateFeedAndPrint(this.stamp, this.reference)
this.console.dim('Successfully updated feed.')
}
}
8 changes: 6 additions & 2 deletions src/command/feed/upload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Aggregation, LeafCommand } from 'furious-commander'
import { Aggregation, LeafCommand, Option } from 'furious-commander'
import { pickStamp } from '../../service/stamp'
import { stampProperties } from '../../utils/option'
import { Upload as FileUpload } from '../upload'
import { FeedCommand } from './feed-command'

Expand All @@ -13,6 +14,9 @@ export class Upload extends FeedCommand implements LeafCommand {
@Aggregation(['upload'])
public fileUpload!: FileUpload

@Option(stampProperties)
public stamp!: string

public async run(): Promise<void> {
await super.init()

Expand All @@ -23,7 +27,7 @@ export class Upload extends FeedCommand implements LeafCommand {
}

const reference = await this.runUpload()
this.feedManifest = await this.updateFeedAndPrint(reference)
this.feedManifest = await this.updateFeedAndPrint(this.stamp, reference)
this.console.dim('Successfully uploaded to feed.')
}

Expand Down
Loading