diff --git a/app/app.go b/app/app.go index c4e5964739..459300bf66 100644 --- a/app/app.go +++ b/app/app.go @@ -15,13 +15,7 @@ const ( version = "0.1" maxTxSize = 10240 - PluginTypeByteBase = 0x01 - PluginTypeByteEyes = 0x02 - PluginTypeByteVote = 0x03 - PluginNameBase = "base" - PluginNameEyes = "eyes" - PluginNameVote = "vote" ) type Basecoin struct { @@ -47,8 +41,8 @@ func (app *Basecoin) Info() string { return Fmt("Basecoin v%v", version) } -func (app *Basecoin) RegisterPlugin(typeByte byte, name string, plugin types.Plugin) { - app.plugins.RegisterPlugin(typeByte, name, plugin) +func (app *Basecoin) RegisterPlugin(name string, plugin types.Plugin) { + app.plugins.RegisterPlugin(name, plugin) } // TMSP::SetOption diff --git a/plugins/vote/vote_test.go b/plugins/vote/vote_test.go index c2cce6f3a0..a210999ffd 100644 --- a/plugins/vote/vote_test.go +++ b/plugins/vote/vote_test.go @@ -12,6 +12,8 @@ import ( eyescli "github.com/tendermint/merkleeyes/client" ) +const PluginNameVote = "vote" + func TestVote(t *testing.T) { //base initialization eyesCli := eyescli.NewLocalClient() @@ -30,10 +32,8 @@ func TestVote(t *testing.T) { //vote initialization votePlugin := NewVoteInstance("humanRights") - var typeByte byte = app.PluginTypeByteVote bcApp.RegisterPlugin( - typeByte, - app.PluginNameVote, + PluginNameVote, votePlugin, ) @@ -52,7 +52,7 @@ func TestVote(t *testing.T) { tx := &types.AppTx{ Fee: fees, Gas: 0, - Type: typeByte, + Name: PluginNameVote, Input: cmn.MakeInput(test1Acc.PubKey, types.Coins{{"", sendCoins}}, seqNum), Data: wire.BinaryBytes(struct{ Tx }{Tx{voteYes: true}}), //a vote for human rights } diff --git a/state/execution.go b/state/execution.go index a00263ec31..c0e7e51024 100644 --- a/state/execution.go +++ b/state/execution.go @@ -102,10 +102,10 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e } // Validate call address - plugin := pgz.GetByByte(tx.Type) + plugin := pgz.GetByName(tx.Name) if plugin == nil { return tmsp.ErrBaseUnknownAddress.AppendLog( - Fmt("Unrecognized type byte %v", tx.Type)) + Fmt("Unrecognized plugin name%v", tx.Name)) } // Good! diff --git a/types/plugin.go b/types/plugin.go index 51ac122a11..78fa261da0 100644 --- a/types/plugin.go +++ b/types/plugin.go @@ -13,7 +13,6 @@ type Plugin interface { } type NamedPlugin struct { - Byte byte Name string Plugin } @@ -35,32 +34,24 @@ func NewCallContext(caller []byte, coins Coins) CallContext { //---------------------------------------- type Plugins struct { - byByte map[byte]Plugin byName map[string]Plugin plist []NamedPlugin } func NewPlugins() *Plugins { return &Plugins{ - byByte: make(map[byte]Plugin), byName: make(map[string]Plugin), } } -func (pgz *Plugins) RegisterPlugin(typeByte byte, name string, plugin Plugin) { - pgz.byByte[typeByte] = plugin +func (pgz *Plugins) RegisterPlugin(name string, plugin Plugin) { pgz.byName[name] = plugin pgz.plist = append(pgz.plist, NamedPlugin{ - Byte: typeByte, Name: name, Plugin: plugin, }) } -func (pgz *Plugins) GetByByte(typeByte byte) Plugin { - return pgz.byByte[typeByte] -} - func (pgz *Plugins) GetByName(name string) Plugin { return pgz.byName[name] } diff --git a/types/tx.go b/types/tx.go index e94271b086..c7fa15cee8 100644 --- a/types/tx.go +++ b/types/tx.go @@ -141,7 +141,7 @@ func (tx *SendTx) String() string { type AppTx struct { Fee int64 `json:"fee"` // Fee Gas int64 `json:"gas"` // Gas - Type byte `json:"type"` // Which app + Name string `json:"type"` // Which plugin Input TxInput `json:"input"` // Hmmm do we want coins? Data []byte `json:"data"` } @@ -161,7 +161,7 @@ func (tx *AppTx) SetSignature(sig crypto.Signature) bool { } func (tx *AppTx) String() string { - return Fmt("AppTx{%v/%v %v %v %X}", tx.Fee, tx.Gas, tx.Type, tx.Input, tx.Data) + return Fmt("AppTx{%v/%v %v %v %X}", tx.Fee, tx.Gas, tx.Name, tx.Input, tx.Data) } //----------------------------------------------------------------------------- diff --git a/types/tx_test.go b/types/tx_test.go index 92d54883c2..3a35b7ec7e 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -47,7 +47,7 @@ func TestAppTxSignable(t *testing.T) { callTx := &AppTx{ Fee: 111, Gas: 222, - Type: 0x01, + Name: "X", Input: TxInput{ Address: []byte("input1"), Coins: Coins{{"", 12345}}, @@ -57,7 +57,7 @@ func TestAppTxSignable(t *testing.T) { } signBytes := callTx.SignBytes(chainID) signBytesHex := Fmt("%X", signBytes) - expected := "010A746573745F636861696E01000000000000006F00000000000000DE010106696E70757431010100000000000000303903010932000001056461746131" + expected := "010A746573745F636861696E01000000000000006F00000000000000DE0101580106696E70757431010100000000000000303903010932000001056461746131" if signBytesHex != expected { t.Errorf("Got unexpected sign string for AppTx. Expected:\n%v\nGot:\n%v", expected, signBytesHex) }