s/CallTx/AppTx/g; NamedPlugins

This commit is contained in:
Jae Kwon
2016-03-27 12:47:50 -07:00
parent 601a654b7d
commit fa39c9da5c
9 changed files with 153 additions and 131 deletions
+8 -7
View File
@@ -10,7 +10,7 @@ import (
)
// If the tx is invalid, a TMSP error will be returned.
func ExecTx(state *State, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp.Result {
func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp.Result {
// TODO: do something with fees
fees := int64(0)
@@ -68,7 +68,7 @@ func ExecTx(state *State, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp
return tmsp.OK
case *types.CallTx:
case *types.AppTx:
// First, get input account
inAcc := state.GetAccount(tx.Input.Address)
if inAcc == nil {
@@ -93,9 +93,10 @@ func ExecTx(state *State, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp
}
// Validate call address
plugin := state.GetPlugin(string(tx.Address))
plugin := pgz.GetByByte(tx.Type)
if plugin != nil {
return tmsp.ErrBaseUnknownAddress.AppendLog(Fmt("Unrecognized address %X (%v)", tx.Address, string(tx.Address)))
return tmsp.ErrBaseUnknownAddress.AppendLog(
Fmt("Unrecognized type byte %v", tx.Type))
}
// Good!
@@ -105,7 +106,7 @@ func ExecTx(state *State, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp
state.SetCheckAccount(tx.Input.Address, inAcc.Sequence, inAcc.Balance)
inAccCopy := inAcc.Copy()
// If this is AppendTx, actually save accounts
// If this is a CheckTx, stop now.
if isCheckTx {
return tmsp.OK
}
@@ -115,7 +116,7 @@ func ExecTx(state *State, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp
cache.SetAccount(tx.Input.Address, inAcc)
gas := int64(1) // TODO
ctx := types.NewCallContext(cache, inAcc, value, &gas)
res = plugin.CallTx(ctx, tx.Data)
res = plugin.RunTx(ctx, tx.Data)
if res.IsOK() {
cache.Sync()
log.Info("Successful execution")
@@ -131,7 +132,7 @@ func ExecTx(state *State, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp
}
*/
} else {
log.Info("CallTx failed", "error", res)
log.Info("AppTx failed", "error", res)
// Just return the value and return.
// TODO: return gas?
inAccCopy.Balance += value
+3 -22
View File
@@ -8,11 +8,9 @@ import (
)
type State struct {
chainID string
eyesCli *eyes.Client
checkCache map[string]checkAccount
plugins map[string]types.Plugin
pluginsList []types.NamedPlugin
chainID string
eyesCli *eyes.Client
checkCache map[string]checkAccount
LastBlockHeight uint64
LastBlockHash []byte
@@ -24,7 +22,6 @@ func NewState(eyesCli *eyes.Client) *State {
chainID: "",
eyesCli: eyesCli,
checkCache: make(map[string]checkAccount),
plugins: make(map[string]types.Plugin),
}
return s
}
@@ -40,22 +37,6 @@ func (s *State) GetChainID() string {
return s.chainID
}
func (s *State) RegisterPlugin(name string, plugin types.Plugin) {
s.plugins[name] = plugin
s.pluginsList = append(s.pluginsList, types.NamedPlugin{
Name: name,
Plugin: plugin,
})
}
func (s *State) GetPlugin(name string) types.Plugin {
return s.plugins[name]
}
func (s *State) GetPlugins() []types.NamedPlugin {
return s.pluginsList
}
//----------------------------------------
// CheckTx state