Cleanup code, remove plugin type byte
This commit is contained in:
+1
-10
@@ -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]
|
||||
}
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user