예제 #1
0
func (app *MerkleEyesApp) Commit() tmsp.Result {
	if app.tree.Size() == 0 {
		return tmsp.NewResultOK(nil, "Empty hash for empty tree")
	}
	hash := app.tree.Hash()
	return tmsp.NewResultOK(hash, "")
}
예제 #2
0
func (cli *grpcClient) InfoSync() (res types.Result) {
	reqres := cli.InfoAsync()
	if res := cli.checkErrGetResult(); res.IsErr() {
		return res
	}
	resp := reqres.Response.GetInfo()
	return types.NewResultOK([]byte(resp.Info), LOG)
}
예제 #3
0
func (cli *grpcClient) EchoSync(msg string) (res types.Result) {
	reqres := cli.EchoAsync(msg)
	if res := cli.checkErrGetResult(); res.IsErr() {
		return res
	}
	resp := reqres.Response.GetEcho()
	return types.NewResultOK([]byte(resp.Message), LOG)
}
예제 #4
0
func (app *CounterApplication) Commit() tmsp.Result {
	app.mempoolTxCount = app.txCount
	if app.txCount == 0 {
		return tmsp.OK
	} else {
		hash := make([]byte, 8)
		binary.BigEndian.PutUint64(hash, uint64(app.txCount))
		return tmsp.NewResultOK(hash, "")
	}
}
예제 #5
0
파일: counter.go 프로젝트: tendermint/tmsp
func (app *CounterApplication) Commit() types.Result {
	app.hashCount += 1

	if app.txCount == 0 {
		return types.OK
	} else {
		hash := make([]byte, 8)
		binary.BigEndian.PutUint64(hash, uint64(app.txCount))
		return types.NewResultOK(hash, "")
	}
}
예제 #6
0
func (client *Client) GetSync(key []byte) (res tmsp.Result) {
	query := make([]byte, 1+wire.ByteSliceSize(key))
	buf := query
	buf[0] = 0x01 // Get TypeByte
	buf = buf[1:]
	wire.PutByteSlice(buf, key)
	res = client.QuerySync(query)
	if res.IsErr() {
		return res
	}
	value := res.Data
	return tmsp.NewResultOK(value, "")
}
예제 #7
0
func (app *MerkleEyesApp) Query(query []byte) tmsp.Result {
	if len(query) == 0 {
		return tmsp.OK
	}
	typeByte := query[0]
	query = query[1:]
	switch typeByte {
	case 0x01: // Get by key
		key, n, err := wire.GetByteSlice(query)
		if err != nil {
			return tmsp.ErrEncodingError.SetLog(Fmt("Error getting key: %v", err.Error()))
		}
		query = query[n:]
		if len(query) != 0 {
			return tmsp.ErrEncodingError.SetLog(Fmt("Got bytes left over"))
		}
		_, value, _ := app.tree.Get(key)
		return tmsp.NewResultOK(value, "")
	case 0x02: // Get by index
		index, n, err := wire.GetVarint(query)
		if err != nil {
			return tmsp.ErrEncodingError.SetLog(Fmt("Error getting index: %v", err.Error()))
		}
		query = query[n:]
		if len(query) != 0 {
			return tmsp.ErrEncodingError.SetLog(Fmt("Got bytes left over"))
		}
		_, value := app.tree.GetByIndex(index)
		return tmsp.NewResultOK(value, "")
	case 0x03: // Get size
		size := app.tree.Size()
		res := wire.BinaryBytes(size)
		return tmsp.NewResultOK(res, "")
	default:
		return tmsp.ErrUnknownRequest.SetLog(Fmt("Unexpected Query type byte %X", typeByte))
	}
}
예제 #8
0
파일: dummy.go 프로젝트: tendermint/tmsp
func (app *DummyApplication) Query(query []byte) types.Result {
	index, value, exists := app.state.Get(query)
	resStr := Fmt("Index=%v value=%v exists=%v", index, string(value), exists)
	return types.NewResultOK([]byte(resStr), "")
}
예제 #9
0
파일: dummy.go 프로젝트: tendermint/tmsp
func (app *DummyApplication) Commit() types.Result {
	hash := app.state.Hash()
	return types.NewResultOK(hash, "")
}
예제 #10
0
func (app *CounterApplication) Query(query []byte) tmsp.Result {
	return tmsp.NewResultOK(nil, Fmt("Query is not supported"))
}
예제 #11
0
파일: counter.go 프로젝트: tendermint/tmsp
func (app *CounterApplication) Query(query []byte) types.Result {
	return types.NewResultOK(nil, fmt.Sprintf("Query is not supported"))
}
예제 #12
0
파일: nil_app.go 프로젝트: tendermint/tmsp
func (app *NilApplication) Query(query []byte) types.Result {
	return types.NewResultOK(nil, "")
}
예제 #13
0
파일: nil_app.go 프로젝트: tendermint/tmsp
func (app *NilApplication) Commit() types.Result {
	return types.NewResultOK([]byte("nil"), "")
}
예제 #14
0
파일: nil_app.go 프로젝트: tendermint/tmsp
func (app *NilApplication) CheckTx(tx []byte) types.Result {
	return types.NewResultOK(nil, "")
}