From 22918ba3d28a1220861ec2049dc95b079bce1665 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 16 Jun 2017 17:35:37 +0200 Subject: [PATCH] Remove example-plugin code, need to fix docs --- docs/guide/src/example-plugin/cmd.go | 62 ----------- docs/guide/src/example-plugin/main.go | 35 ------- docs/guide/src/example-plugin/plugin.go | 134 ------------------------ 3 files changed, 231 deletions(-) delete mode 100644 docs/guide/src/example-plugin/cmd.go delete mode 100644 docs/guide/src/example-plugin/main.go delete mode 100644 docs/guide/src/example-plugin/plugin.go diff --git a/docs/guide/src/example-plugin/cmd.go b/docs/guide/src/example-plugin/cmd.go deleted file mode 100644 index b43917626..000000000 --- a/docs/guide/src/example-plugin/cmd.go +++ /dev/null @@ -1,62 +0,0 @@ -package main - -import ( - "github.com/spf13/cobra" - - wire "github.com/tendermint/go-wire" - - "github.com/tendermint/basecoin/cmd/commands" - "github.com/tendermint/basecoin/types" -) - -var ( - //CLI Flags - validFlag bool - - //CLI Plugin Commands - ExamplePluginTxCmd = &cobra.Command{ - Use: "example", - Short: "Create, sign, and broadcast a transaction to the example plugin", - RunE: examplePluginTxCmd, - } -) - -//Called during CLI initialization -func init() { - - //Set the Plugin Flags - ExamplePluginTxCmd.Flags().BoolVar(&validFlag, "valid", false, "Set this to make transaction valid") - - //Register a plugin specific CLI command as a subcommand of the tx command - commands.RegisterTxSubcommand(ExamplePluginTxCmd) - - //Register the example with basecoin at start - commands.RegisterStartPlugin("example-plugin", func() types.Plugin { return NewExamplePlugin() }) -} - -//Send a transaction -func examplePluginTxCmd(cmd *cobra.Command, args []string) error { - - // Create a transaction using the flag. - // The tx passes on custom information to the plugin - exampleTx := ExamplePluginTx{validFlag} - - // The tx is passed to the plugin in the form of - // a byte array. This is achieved by serializing the object using go-wire. - // Once received in the plugin, these exampleTxBytes are decoded back - // into the original ExamplePluginTx struct - exampleTxBytes := wire.BinaryBytes(exampleTx) - - // Send the transaction and return any errors. - // Here exampleTxBytes is packaged in the `tx.Data` field of an AppTx, - // and passed on to the plugin through the following sequence: - // - passed as `data` to `commands.AppTx` (cmd/commands/tx.go) - // - set as the `tx.Data` field of an AppTx, which is then passed to commands.broadcastTx (cmd/commands/tx.go) - // - the tx is broadcast to Tendermint, which runs it through app.CheckTx (app/app.go) - // - after passing CheckTx, it will eventually be included in a block and run through app.DeliverTx (app/app.go) - // - DeliverTx receives txBytes, which is the serialization of the full AppTx (app/app.go) - // - Once deserialized, the tx is passed to `state.ExecTx` (state/execution.go) - // - If the tx passes various checks, the `tx.Data` is forwarded as `txBytes` to `plugin.RunTx` (docs/guide/src/example-plugin/plugin.go) - // - Finally, it deserialized back to the ExamplePluginTx - return commands.AppTx("example-plugin", exampleTxBytes) -} diff --git a/docs/guide/src/example-plugin/main.go b/docs/guide/src/example-plugin/main.go deleted file mode 100644 index 328e22025..000000000 --- a/docs/guide/src/example-plugin/main.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "os" - - "github.com/spf13/cobra" - - "github.com/tendermint/basecoin/cmd/commands" - "github.com/tendermint/tmlibs/cli" -) - -func main() { - - //Initialize example-plugin root command - var RootCmd = &cobra.Command{ - Use: "example-plugin", - Short: "example-plugin usage description", - } - - //Add the default basecoin commands to the root command - RootCmd.AddCommand( - commands.InitCmd, - commands.StartCmd, - commands.TxCmd, - commands.QueryCmd, - commands.KeyCmd, - commands.VerifyCmd, - commands.BlockCmd, - commands.AccountCmd, - commands.UnsafeResetAllCmd, - ) - - cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin-example-plugin")) - cmd.Execute() -} diff --git a/docs/guide/src/example-plugin/plugin.go b/docs/guide/src/example-plugin/plugin.go deleted file mode 100644 index 97e80520a..000000000 --- a/docs/guide/src/example-plugin/plugin.go +++ /dev/null @@ -1,134 +0,0 @@ -package main - -import ( - abci "github.com/tendermint/abci/types" - "github.com/tendermint/basecoin/types" - "github.com/tendermint/go-wire" -) - -//----------------------------------------- -// Structs -// * Note the fields in each struct may be expanded/modified - -// Plugin State Struct -// * Intended to store the current state of the plugin -// * This example contains a field which holds the execution count -// * Serialized (by go-wire) and stored within the KVStore using the key retrieved -// from the ExamplePlugin.StateKey() function/ -// * All fields must be exposed for serialization by external libs (here go-wire) -type ExamplePluginState struct { - Counter int -} - -// Transaction Struct -// * Stores transaction-specific plugin-customized information -// * This example contains a dummy field 'Valid' intended to specify -// if the transaction is a valid and should proceed -// * Deserialized (by go-wire) from txBytes in ExamplePlugin.RunTx -// * All fields must be exposed for serialization by external libs (here go-wire) -type ExamplePluginTx struct { - Valid bool -} - -// Plugin Struct -// * Struct which satisfies the basecoin Plugin interface -// * Stores global plugin settings, in this example just the plugin name -type ExamplePlugin struct { - name string -} - -//----------------------------------------- -// Non-Mandatory Functions - -// Return a new ExamplePlugin pointer with a hard-coded name -func NewExamplePlugin() *ExamplePlugin { - return &ExamplePlugin{ - name: "example-plugin", - } -} - -// Return a byte array unique to this plugin which is used as the key -// to store the plugin state (ExamplePluginState) -func (ep *ExamplePlugin) StateKey() []byte { - return []byte("ExamplePlugin.State") -} - -//----------------------------------------- -// Basecoin Plugin Interface Functions - -//Return the name of the plugin -func (ep *ExamplePlugin) Name() string { - return ep.name -} - -// SetOption may be called during genesis of basecoin and can be used to set -// initial plugin parameters. Within genesis.json file entries are made in -// the format: "/", "" Where is the plugin name, -// in this file ExamplePlugin.name, and and are the strings passed -// into the plugin SetOption function. This function is intended to be used to -// set plugin specific information such as the plugin state. Within this example -// SetOption is left unimplemented. -func (ep *ExamplePlugin) SetOption(store types.KVStore, key string, value string) (log string) { - return "" -} - -// The core tx logic of the app is containted within the RunTx function -// Input fields: -// - store types.KVStore -// - This term provides read/write capabilities to the merkelized data store -// which holds the basecoin state and is accessible to all plugins -// - ctx types.CallContext -// - The ctx contains the callers address, a pointer to the callers account, -// and an amount of coins sent with the transaction -// - txBytes []byte -// - Used to send customized information to your plugin -// -// Other more complex plugins may have a variant on the process order within this -// example including loading and saving multiple or variable states, or not -// including a state stored in the KVStore whatsoever. -func (ep *ExamplePlugin) RunTx(store types.KVStore, ctx types.CallContext, txBytes []byte) (res abci.Result) { - - // Decode txBytes using go-wire. Attempt to write the txBytes to the variable - // tx, if the txBytes have not been properly encoded from a ExamplePluginTx - // struct wire will produce an error. - var tx ExamplePluginTx - err := wire.ReadBinaryBytes(txBytes, &tx) - if err != nil { - return abci.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error()) - } - - // Perform Transaction Validation - if !tx.Valid { - return abci.ErrInternalError.AppendLog("Valid must be true") - } - - // Load PluginState - var pluginState ExamplePluginState - stateBytes := store.Get(ep.StateKey()) - // If the state does not exist, stateBytes will be initialized - // as an empty byte array with length of zero - if len(stateBytes) > 0 { - err = wire.ReadBinaryBytes(stateBytes, &pluginState) //decode using go-wire - if err != nil { - return abci.ErrInternalError.AppendLog("Error decoding state: " + err.Error()) - } - } - - //App Logic - pluginState.Counter += 1 - - // Save PluginState - store.Set(ep.StateKey(), wire.BinaryBytes(pluginState)) - - return abci.OK -} - -func (ep *ExamplePlugin) InitChain(store types.KVStore, vals []*abci.Validator) { -} - -func (ep *ExamplePlugin) BeginBlock(store types.KVStore, hash []byte, header *abci.Header) { -} - -func (ep *ExamplePlugin) EndBlock(store types.KVStore, height uint64) abci.ResponseEndBlock { - return abci.ResponseEndBlock{} -}