Cleanup code, remove plugin type byte
This commit is contained in:
parent
0f90f51262
commit
8a6e4095b7
10
app/app.go
10
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue