Skip to content

Commit

Permalink
Query uses type bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Mar 28, 2016
1 parent a63bc3f commit f491c8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
32 changes: 17 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ const (
maxTxSize = 10240

typeByteBase = 0x01
typeByteGov = 0x02
typeByteEyes = 0x02
typeByteGov = 0x03

pluginNameBase = "base"
pluginNameEyes = "eyes"
pluginNameGov = "gov"
)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Account Types:
*/

type Tx interface {
AssertIsTx()
SignBytes(chainID string) []byte
}

Expand All @@ -28,6 +29,9 @@ const (
TxTypeApp = byte(0x02)
)

func (_ *SendTx) AssertIsTx() {}
func (_ *AppTx) AssertIsTx() {}

var _ = wire.RegisterInterface(
struct{ Tx }{},
wire.ConcreteType{&SendTx{}, TxTypeSend},
Expand Down

0 comments on commit f491c8d

Please sign in to comment.