aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorViktor TrĂ³n <viktor.tron@gmail.com>2018-10-03 20:59:41 +0800
committerGitHub <noreply@github.com>2018-10-03 20:59:41 +0800
commite5677114dc7461fe39ebe353a4657aa4cb03fde4 (patch)
tree8605f9a8b726b158fd01b4befced1e3ba92ca1f9 /cmd
parent303b99663e963a520aaa44eca68e042d9fe230af (diff)
parentde01178c18766b9f744acc94fe2b96804f998e40 (diff)
downloadgo-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar
go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar.gz
go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar.bz2
go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar.lz
go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar.xz
go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar.zst
go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.zip
Merge pull request #17796 from epiclabs-io/mru-feeds
swarm/storage/feeds: Renamed MRU to Swarm Feeds
Diffstat (limited to 'cmd')
-rw-r--r--cmd/swarm/feeds.go (renamed from cmd/swarm/mru.go)72
-rw-r--r--cmd/swarm/feeds_test.go (renamed from cmd/swarm/mru_test.go)44
-rw-r--r--cmd/swarm/main.go66
3 files changed, 91 insertions, 91 deletions
diff --git a/cmd/swarm/mru.go b/cmd/swarm/feeds.go
index cc7f634cb..6806c6cf4 100644
--- a/cmd/swarm/mru.go
+++ b/cmd/swarm/feeds.go
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
-// Command resource allows the user to create and update signed mutable resource updates
+// Command feed allows the user to create and update signed Swarm feeds
package main
import (
@@ -27,17 +27,17 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
swarm "github.com/ethereum/go-ethereum/swarm/api/client"
- "github.com/ethereum/go-ethereum/swarm/storage/mru"
+ "github.com/ethereum/go-ethereum/swarm/storage/feed"
"gopkg.in/urfave/cli.v1"
)
-func NewGenericSigner(ctx *cli.Context) mru.Signer {
- return mru.NewGenericSigner(getPrivKey(ctx))
+func NewGenericSigner(ctx *cli.Context) feed.Signer {
+ return feed.NewGenericSigner(getPrivKey(ctx))
}
-func getTopic(ctx *cli.Context) (topic mru.Topic) {
- var name = ctx.String(SwarmResourceNameFlag.Name)
- var relatedTopic = ctx.String(SwarmResourceTopicFlag.Name)
+func getTopic(ctx *cli.Context) (topic feed.Topic) {
+ var name = ctx.String(SwarmFeedNameFlag.Name)
+ var relatedTopic = ctx.String(SwarmFeedTopicFlag.Name)
var relatedTopicBytes []byte
var err error
@@ -48,42 +48,42 @@ func getTopic(ctx *cli.Context) (topic mru.Topic) {
}
}
- topic, err = mru.NewTopic(name, relatedTopicBytes)
+ topic, err = feed.NewTopic(name, relatedTopicBytes)
if err != nil {
utils.Fatalf("Error parsing topic: %s", err)
}
return topic
}
-// swarm resource create <frequency> [--name <name>] [--data <0x Hexdata> [--multihash=false]]
-// swarm resource update <Manifest Address or ENS domain> <0x Hexdata> [--multihash=false]
-// swarm resource info <Manifest Address or ENS domain>
+// swarm feed create <frequency> [--name <name>] [--data <0x Hexdata> [--multihash=false]]
+// swarm feed update <Manifest Address or ENS domain> <0x Hexdata> [--multihash=false]
+// swarm feed info <Manifest Address or ENS domain>
-func resourceCreate(ctx *cli.Context) {
+func feedCreateManifest(ctx *cli.Context) {
var (
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
client = swarm.NewClient(bzzapi)
)
- newResourceRequest := mru.NewFirstRequest(getTopic(ctx))
- newResourceRequest.View.User = resourceGetUser(ctx)
+ newFeedUpdateRequest := feed.NewFirstRequest(getTopic(ctx))
+ newFeedUpdateRequest.Feed.User = feedGetUser(ctx)
- manifestAddress, err := client.CreateResource(newResourceRequest)
+ manifestAddress, err := client.CreateFeedWithManifest(newFeedUpdateRequest)
if err != nil {
- utils.Fatalf("Error creating resource: %s", err.Error())
+ utils.Fatalf("Error creating feed manifest: %s", err.Error())
return
}
fmt.Println(manifestAddress) // output manifest address to the user in a single line (useful for other commands to pick up)
}
-func resourceUpdate(ctx *cli.Context) {
+func feedUpdate(ctx *cli.Context) {
args := ctx.Args()
var (
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
client = swarm.NewClient(bzzapi)
- manifestAddressOrDomain = ctx.String(SwarmResourceManifestFlag.Name)
+ manifestAddressOrDomain = ctx.String(SwarmFeedManifestFlag.Name)
)
if len(args) < 1 {
@@ -100,20 +100,20 @@ func resourceUpdate(ctx *cli.Context) {
return
}
- var updateRequest *mru.Request
- var query *mru.Query
+ var updateRequest *feed.Request
+ var query *feed.Query
if manifestAddressOrDomain == "" {
- query = new(mru.Query)
+ query = new(feed.Query)
query.User = signer.Address()
query.Topic = getTopic(ctx)
}
- // Retrieve resource status and metadata out of the manifest
- updateRequest, err = client.GetResourceMetadata(query, manifestAddressOrDomain)
+ // Retrieve a feed update request
+ updateRequest, err = client.GetFeedRequest(query, manifestAddressOrDomain)
if err != nil {
- utils.Fatalf("Error retrieving resource status: %s", err.Error())
+ utils.Fatalf("Error retrieving feed status: %s", err.Error())
}
// set the new data
@@ -121,34 +121,34 @@ func resourceUpdate(ctx *cli.Context) {
// sign update
if err = updateRequest.Sign(signer); err != nil {
- utils.Fatalf("Error signing resource update: %s", err.Error())
+ utils.Fatalf("Error signing feed update: %s", err.Error())
}
// post update
- err = client.UpdateResource(updateRequest)
+ err = client.UpdateFeed(updateRequest)
if err != nil {
- utils.Fatalf("Error updating resource: %s", err.Error())
+ utils.Fatalf("Error updating feed: %s", err.Error())
return
}
}
-func resourceInfo(ctx *cli.Context) {
+func feedInfo(ctx *cli.Context) {
var (
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
client = swarm.NewClient(bzzapi)
- manifestAddressOrDomain = ctx.String(SwarmResourceManifestFlag.Name)
+ manifestAddressOrDomain = ctx.String(SwarmFeedManifestFlag.Name)
)
- var query *mru.Query
+ var query *feed.Query
if manifestAddressOrDomain == "" {
- query = new(mru.Query)
+ query = new(feed.Query)
query.Topic = getTopic(ctx)
- query.User = resourceGetUser(ctx)
+ query.User = feedGetUser(ctx)
}
- metadata, err := client.GetResourceMetadata(query, manifestAddressOrDomain)
+ metadata, err := client.GetFeedRequest(query, manifestAddressOrDomain)
if err != nil {
- utils.Fatalf("Error retrieving resource metadata: %s", err.Error())
+ utils.Fatalf("Error retrieving feed metadata: %s", err.Error())
return
}
encodedMetadata, err := metadata.MarshalJSON()
@@ -158,8 +158,8 @@ func resourceInfo(ctx *cli.Context) {
fmt.Println(string(encodedMetadata))
}
-func resourceGetUser(ctx *cli.Context) common.Address {
- var user = ctx.String(SwarmResourceUserFlag.Name)
+func feedGetUser(ctx *cli.Context) common.Address {
+ var user = ctx.String(SwarmFeedUserFlag.Name)
if user != "" {
return common.HexToAddress(user)
}
diff --git a/cmd/swarm/mru_test.go b/cmd/swarm/feeds_test.go
index 142cf9cfd..46727c21d 100644
--- a/cmd/swarm/mru_test.go
+++ b/cmd/swarm/feeds_test.go
@@ -26,11 +26,11 @@ import (
"testing"
"github.com/ethereum/go-ethereum/swarm/api"
- "github.com/ethereum/go-ethereum/swarm/storage/mru/lookup"
+ "github.com/ethereum/go-ethereum/swarm/storage/feed/lookup"
"github.com/ethereum/go-ethereum/swarm/testutil"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/swarm/storage/mru"
+ "github.com/ethereum/go-ethereum/swarm/storage/feed"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
@@ -38,12 +38,12 @@ import (
swarmhttp "github.com/ethereum/go-ethereum/swarm/api/http"
)
-func TestCLIResourceUpdate(t *testing.T) {
+func TestCLIFeedUpdate(t *testing.T) {
srv := testutil.NewTestSwarmServer(t, func(api *api.API) testutil.TestServer {
return swarmhttp.NewServer(api, "")
}, nil)
- log.Info("starting 1 node cluster")
+ log.Info("starting a test swarm server")
defer srv.Close()
// create a private key file for signing
@@ -65,7 +65,7 @@ func TestCLIResourceUpdate(t *testing.T) {
}
// compose a topic. We'll be doing quotes about Miguel de Cervantes
- var topic mru.Topic
+ var topic feed.Topic
subject := []byte("Miguel de Cervantes")
copy(topic[:], subject[:])
name := "quotes"
@@ -77,13 +77,13 @@ func TestCLIResourceUpdate(t *testing.T) {
flags := []string{
"--bzzapi", srv.URL,
"--bzzaccount", pkfile.Name(),
- "resource", "update",
+ "feed", "update",
"--topic", topic.Hex(),
"--name", name,
hexData}
// create an update and expect an exit without errors
- log.Info(fmt.Sprintf("updating a resource with 'swarm resource update'"))
+ log.Info(fmt.Sprintf("updating a feed with 'swarm feed update'"))
cmd := runSwarm(t, flags...)
cmd.ExpectExit()
@@ -95,22 +95,22 @@ func TestCLIResourceUpdate(t *testing.T) {
// build the same topic as before, this time
// we use NewTopic to create a topic automatically.
- topic, err = mru.NewTopic(name, subject)
+ topic, err = feed.NewTopic(name, subject)
if err != nil {
t.Fatal(err)
}
- // View configures whose updates we will be looking up.
- view := mru.View{
+ // Feed configures whose updates we will be looking up.
+ fd := feed.Feed{
Topic: topic,
User: address,
}
// Build a query to get the latest update
- query := mru.NewQueryLatest(&view, lookup.NoClue)
+ query := feed.NewQueryLatest(&fd, lookup.NoClue)
// retrieve content!
- reader, err := client.GetResource(query, "")
+ reader, err := client.QueryFeed(query, "")
if err != nil {
t.Fatal(err)
}
@@ -128,45 +128,45 @@ func TestCLIResourceUpdate(t *testing.T) {
// Now retrieve info for the next update
flags = []string{
"--bzzapi", srv.URL,
- "resource", "info",
+ "feed", "info",
"--topic", topic.Hex(),
"--user", address.Hex(),
}
- log.Info(fmt.Sprintf("getting resource info with 'swarm resource info'"))
+ log.Info(fmt.Sprintf("getting feed info with 'swarm feed info'"))
cmd = runSwarm(t, flags...)
_, matches := cmd.ExpectRegexp(`.*`) // regex hack to extract stdout
cmd.ExpectExit()
// verify we can deserialize the result as a valid JSON
- var request mru.Request
+ var request feed.Request
err = json.Unmarshal([]byte(matches[0]), &request)
if err != nil {
t.Fatal(err)
}
- // make sure the retrieved view is the same
- if request.View != view {
- t.Fatalf("Expected view to be: %s, got %s", view, request.View)
+ // make sure the retrieved feed is the same
+ if request.Feed != fd {
+ t.Fatalf("Expected feed to be: %s, got %s", fd, request.Feed)
}
// test publishing a manifest
flags = []string{
"--bzzapi", srv.URL,
"--bzzaccount", pkfile.Name(),
- "resource", "create",
+ "feed", "create",
"--topic", topic.Hex(),
}
- log.Info(fmt.Sprintf("Publishing manifest with 'swarm resource create'"))
+ log.Info(fmt.Sprintf("Publishing manifest with 'swarm feed create'"))
cmd = runSwarm(t, flags...)
_, matches = cmd.ExpectRegexp(`[a-f\d]{64}`) // regex hack to extract stdout
cmd.ExpectExit()
- manifestAddress := matches[0] // read the received resource manifest
+ manifestAddress := matches[0] // read the received feed manifest
// now attempt to lookup the latest update using a manifest instead
- reader, err = client.GetResource(nil, manifestAddress)
+ reader, err = client.QueryFeed(nil, manifestAddress)
if err != nil {
t.Fatal(err)
}
diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go
index 14d8b4c6b..88e6b0b0b 100644
--- a/cmd/swarm/main.go
+++ b/cmd/swarm/main.go
@@ -207,25 +207,25 @@ var (
Name: "compressed",
Usage: "Prints encryption keys in compressed form",
}
- SwarmResourceNameFlag = cli.StringFlag{
+ SwarmFeedNameFlag = cli.StringFlag{
Name: "name",
- Usage: "User-defined name for the new resource, limited to 32 characters. If combined with topic, the resource will be a subtopic with this name",
+ Usage: "User-defined name for the new feed, limited to 32 characters. If combined with topic, it will refer to a subtopic with this name",
}
- SwarmResourceTopicFlag = cli.StringFlag{
+ SwarmFeedTopicFlag = cli.StringFlag{
Name: "topic",
- Usage: "User-defined topic this resource is tracking, hex encoded. Limited to 64 hexadecimal characters",
+ Usage: "User-defined topic this feed is tracking, hex encoded. Limited to 64 hexadecimal characters",
}
- SwarmResourceDataOnCreateFlag = cli.StringFlag{
+ SwarmFeedDataOnCreateFlag = cli.StringFlag{
Name: "data",
- Usage: "Initializes the resource with the given hex-encoded data. Data must be prefixed by 0x",
+ Usage: "Initializes the feed with the given hex-encoded data. Data must be prefixed by 0x",
}
- SwarmResourceManifestFlag = cli.StringFlag{
+ SwarmFeedManifestFlag = cli.StringFlag{
Name: "manifest",
- Usage: "Refers to the resource through a manifest",
+ Usage: "Refers to the feed through a manifest",
}
- SwarmResourceUserFlag = cli.StringFlag{
+ SwarmFeedUserFlag = cli.StringFlag{
Name: "user",
- Usage: "Indicates the user who updates the resource",
+ Usage: "Indicates the user who updates the feed",
}
)
@@ -346,62 +346,62 @@ func init() {
},
{
CustomHelpTemplate: helpTemplate,
- Name: "resource",
- Usage: "(Advanced) Create and update Mutable Resources",
+ Name: "feed",
+ Usage: "(Advanced) Create and update Swarm Feeds",
ArgsUsage: "<create|update|info>",
- Description: "Works with Mutable Resource Updates",
+ Description: "Works with Swarm Feeds",
Subcommands: []cli.Command{
{
- Action: resourceCreate,
+ Action: feedCreateManifest,
CustomHelpTemplate: helpTemplate,
Name: "create",
- Usage: "creates and publishes a new Mutable Resource manifest",
- Description: `creates and publishes a new Mutable Resource manifest pointing to a specified user's updates about a particular topic.
- The resource topic can be built in the following ways:
+ Usage: "creates and publishes a new feed manifest",
+ Description: `creates and publishes a new feed manifest pointing to a specified user's updates about a particular topic.
+ The feed topic can be built in the following ways:
* use --topic to set the topic to an arbitrary binary hex string.
* use --name to set the topic to a human-readable name.
- For example --name could be set to "profile-picture", meaning this Mutable Resource allows to get this user's current profile picture.
+ For example --name could be set to "profile-picture", meaning this feed allows to get this user's current profile picture.
* use both --topic and --name to create named subtopics.
For example, --topic could be set to an Ethereum contract address and --name could be set to "comments", meaning
- the Mutable Resource tracks a discussion about that contract.
+ this feed tracks a discussion about that contract.
The --user flag allows to have this manifest refer to a user other than yourself. If not specified,
it will then default to your local account (--bzzaccount)`,
- Flags: []cli.Flag{SwarmResourceNameFlag, SwarmResourceTopicFlag, SwarmResourceUserFlag},
+ Flags: []cli.Flag{SwarmFeedNameFlag, SwarmFeedTopicFlag, SwarmFeedUserFlag},
},
{
- Action: resourceUpdate,
+ Action: feedUpdate,
CustomHelpTemplate: helpTemplate,
Name: "update",
- Usage: "updates the content of an existing Mutable Resource",
+ Usage: "updates the content of an existing Swarm Feed",
ArgsUsage: "<0x Hex data>",
Description: `publishes a new update on the specified topic
- The resource topic can be built in the following ways:
+ The feed topic can be built in the following ways:
* use --topic to set the topic to an arbitrary binary hex string.
* use --name to set the topic to a human-readable name.
- For example --name could be set to "profile-picture", meaning this Mutable Resource allows to get this user's current profile picture.
+ For example --name could be set to "profile-picture", meaning this feed allows to get this user's current profile picture.
* use both --topic and --name to create named subtopics.
For example, --topic could be set to an Ethereum contract address and --name could be set to "comments", meaning
- the Mutable Resource tracks a discussion about that contract.
+ this feed tracks a discussion about that contract.
- If you have a manifest, you can specify it with --manifest to refer to the resource,
+ If you have a manifest, you can specify it with --manifest to refer to the feed,
instead of using --topic / --name
`,
- Flags: []cli.Flag{SwarmResourceManifestFlag, SwarmResourceNameFlag, SwarmResourceTopicFlag},
+ Flags: []cli.Flag{SwarmFeedManifestFlag, SwarmFeedNameFlag, SwarmFeedTopicFlag},
},
{
- Action: resourceInfo,
+ Action: feedInfo,
CustomHelpTemplate: helpTemplate,
Name: "info",
- Usage: "obtains information about an existing Mutable Resource",
- Description: `obtains information about an existing Mutable Resource
+ Usage: "obtains information about an existing Swarm feed",
+ Description: `obtains information about an existing Swarm feed
The topic can be specified directly with the --topic flag as an hex string
If no topic is specified, the default topic (zero) will be used
The --name flag can be used to specify subtopics with a specific name.
The --user flag allows to refer to a user other than yourself. If not specified,
it will then default to your local account (--bzzaccount)
If you have a manifest, you can specify it with --manifest instead of --topic / --name / ---user
- to refer to the resource`,
- Flags: []cli.Flag{SwarmResourceManifestFlag, SwarmResourceNameFlag, SwarmResourceTopicFlag, SwarmResourceUserFlag},
+ to refer to the feed`,
+ Flags: []cli.Flag{SwarmFeedManifestFlag, SwarmFeedNameFlag, SwarmFeedTopicFlag, SwarmFeedUserFlag},
},
},
},
@@ -730,7 +730,7 @@ func getAccount(bzzaccount string, ctx *cli.Context, stack *node.Node) *ecdsa.Pr
}
// getPrivKey returns the private key of the specified bzzaccount
-// Used only by client commands, such as `resource`
+// Used only by client commands, such as `feed`
func getPrivKey(ctx *cli.Context) *ecdsa.PrivateKey {
// booting up the swarm node just as we do in bzzd action
bzzconfig, err := buildConfig(ctx)