diff --git a/src/command/feed/feed-command.ts b/src/command/feed/feed-command.ts index 4bfdba40..397a92a1 100644 --- a/src/command/feed/feed-command.ts +++ b/src/command/feed/feed-command.ts @@ -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' @@ -17,9 +17,6 @@ interface FeedInfo { } export class FeedCommand extends RootCommand { - @Option(stampProperties) - public stamp!: string - @Option({ key: 'identity', alias: 'i', @@ -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 { + protected async updateFeedAndPrint(stamp: string, chunkReference: string): Promise { 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}/`)) @@ -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 @@ -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 { + private async writeFeed(stamp: string, wallet: Wallet, topic: string, chunkReference: string): Promise { const spinner = createSpinner('Writing feed...') if (this.verbosity !== VerbosityLevel.Quiet && !this.curl) { @@ -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(), diff --git a/src/command/feed/print.ts b/src/command/feed/print.ts index d0b76b44..753163ef 100644 --- a/src/command/feed/print.ts +++ b/src/command/feed/print.ts @@ -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' @@ -28,21 +29,43 @@ 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}/`)) @@ -50,9 +73,7 @@ export class Print extends FeedCommand implements LeafCommand { 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() diff --git a/src/command/feed/update.ts b/src/command/feed/update.ts index c4dbd5d4..a46ae421 100644 --- a/src/command/feed/update.ts +++ b/src/command/feed/update.ts @@ -1,5 +1,6 @@ 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 { @@ -7,6 +8,9 @@ export class Update extends FeedCommand implements LeafCommand { public readonly description = 'Update feed' + @Option(stampProperties) + public stamp!: string + @Option({ key: 'reference', alias: 'r', description: 'The new reference', required: true }) public reference!: string @@ -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.') } } diff --git a/src/command/feed/upload.ts b/src/command/feed/upload.ts index 03207637..c9590031 100644 --- a/src/command/feed/upload.ts +++ b/src/command/feed/upload.ts @@ -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' @@ -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 { await super.init() @@ -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.') }