From f491c8d8fbd4082aaba3f449ddd4b5c786db14d1 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sun, 27 Mar 2016 21:51:04 -0700 Subject: [PATCH] Query uses type bytes --- app/app.go | 32 +++++++++++++++++--------------- types/tx.go | 4 ++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/app.go b/app/app.go index d9b91fe20..20efaea87 100644 --- a/app/app.go +++ b/app/app.go @@ -17,9 +17,11 @@ const ( maxTxSize = 10240 typeByteBase = 0x01 - typeByteGov = 0x02 + typeByteEyes = 0x02 + typeByteGov = 0x03 pluginNameBase = "base" + pluginNameEyes = "eyes" pluginNameGov = "gov" ) @@ -122,21 +124,21 @@ func (app *Basecoin) CheckTx(txBytes []byte) (res tmsp.Result) { // TMSP::Query func (app *Basecoin) Query(query []byte) (res tmsp.Result) { - pluginName, queryStr := splitKey(string(query)) - if pluginName != pluginNameBase { - plugin := app.plugins.GetByName(pluginName) - if plugin == nil { - return tmsp.ErrBaseUnknownPlugin.SetLog(Fmt("Unknown plugin %v", pluginName)) - } - return plugin.Query([]byte(queryStr)) - } else { - // TODO turn Basecoin ops into a plugin? - res = app.eyesCli.GetSync([]byte(queryStr)) - if res.IsErr() { - return res.PrependLog("Error querying eyesCli") - } - return res + if len(query) == 0 { + return tmsp.ErrEncodingError.SetLog("Query cannot be zero length") } + typeByte := query[0] + query = query[1:] + switch typeByte { + case typeByteBase: + return tmsp.OK.SetLog("This type of query not yet supported") + case typeByteEyes: + return app.eyesCli.QuerySync(query) + case typeByteGov: + return app.govMint.Query(query) + } + return tmsp.ErrBaseUnknownPlugin.SetLog( + Fmt("Unknown plugin with type byte %X", typeByte)) } // TMSP::Commit diff --git a/types/tx.go b/types/tx.go index feb509b46..774f7d465 100644 --- a/types/tx.go +++ b/types/tx.go @@ -18,6 +18,7 @@ Account Types: */ type Tx interface { + AssertIsTx() SignBytes(chainID string) []byte } @@ -28,6 +29,9 @@ const ( TxTypeApp = byte(0x02) ) +func (_ *SendTx) AssertIsTx() {} +func (_ *AppTx) AssertIsTx() {} + var _ = wire.RegisterInterface( struct{ Tx }{}, wire.ConcreteType{&SendTx{}, TxTypeSend},