mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-21 08:51:32 +00:00
Remove TMSP Commit/Rollback; Add CheckTx
This commit is contained in:
@ -5,36 +5,25 @@ util = require("util")
|
||||
function CounterApp(){
|
||||
this.hashCount = 0;
|
||||
this.txCount = 0;
|
||||
this.commitCount = 0;
|
||||
this.serial = false;
|
||||
};
|
||||
|
||||
CounterApp.prototype.open = function(){
|
||||
return new CounterAppContext(this);
|
||||
}
|
||||
|
||||
function CounterAppContext(app) {
|
||||
this.hashCount = app.hashCount;
|
||||
this.txCount = app.txCount;
|
||||
this.commitCount = app.commitCount;
|
||||
this.serial = false;
|
||||
}
|
||||
|
||||
CounterAppContext.prototype.echo = function(msg){
|
||||
CounterApp.prototype.echo = function(msg){
|
||||
return {"response": msg, "ret_code":0}
|
||||
}
|
||||
|
||||
CounterAppContext.prototype.info = function(){
|
||||
return {"response": [util.format("hash, tx, commit counts: %d, %d, %d", this.hashCount, this.txCount, this.commitCount)]}
|
||||
CounterApp.prototype.info = function(){
|
||||
return {"response": [util.format("hashes:%d, txs:%d", this.hashCount, this.txCount)]}
|
||||
}
|
||||
|
||||
CounterAppContext.prototype.set_option = function(key, value){
|
||||
CounterApp.prototype.set_option = function(key, value){
|
||||
if (key == "serial" && value == "on"){
|
||||
this.serial = true;
|
||||
}
|
||||
return {"ret_code":0}
|
||||
}
|
||||
|
||||
CounterAppContext.prototype.append_tx = function(txBytes){
|
||||
CounterApp.prototype.append_tx = function(txBytes){
|
||||
if (this.serial) {
|
||||
txByteArray = new Buffer(txBytes)
|
||||
if (txBytes.length >= 2 && txBytes.slice(0, 2) == "0x") {
|
||||
@ -50,7 +39,22 @@ CounterAppContext.prototype.append_tx = function(txBytes){
|
||||
return {"ret_code":0} // TODO: return events
|
||||
}
|
||||
|
||||
CounterAppContext.prototype.get_hash = function(){
|
||||
CounterApp.prototype.check_tx = function(txBytes){
|
||||
if (this.serial) {
|
||||
txByteArray = new Buffer(txBytes)
|
||||
if (txBytes.length >= 2 && txBytes.slice(0, 2) == "0x") {
|
||||
txByteArray = wire.hex2bytes(txBytes.slice(2));
|
||||
}
|
||||
r = new msg.buffer(txByteArray)
|
||||
txValue = wire.decode_big_endian(r, txBytes.length)
|
||||
if (txValue < this.txCount){
|
||||
return {"ret_code":1}
|
||||
}
|
||||
}
|
||||
return {"ret_code":0}
|
||||
}
|
||||
|
||||
CounterApp.prototype.get_hash = function(){
|
||||
this.hashCount += 1;
|
||||
if (this.txCount == 0){
|
||||
return {"response": "", "ret_code":0}
|
||||
@ -60,24 +64,15 @@ CounterAppContext.prototype.get_hash = function(){
|
||||
return {"response": h.toString(), "ret_code":0}
|
||||
}
|
||||
|
||||
CounterAppContext.prototype.commit = function(){
|
||||
this.commitCount += 1;
|
||||
CounterApp.prototype.add_listener = function(){
|
||||
return {"ret_code":0}
|
||||
}
|
||||
|
||||
CounterAppContext.prototype.rollback = function(){
|
||||
CounterApp.prototype.rm_listener = function(){
|
||||
return {"ret_code":0}
|
||||
}
|
||||
|
||||
CounterAppContext.prototype.add_listener = function(){
|
||||
return {"ret_code":0}
|
||||
}
|
||||
|
||||
CounterAppContext.prototype.rm_listener = function(){
|
||||
return {"ret_code":0}
|
||||
}
|
||||
|
||||
CounterAppContext.prototype.event = function(){
|
||||
CounterApp.prototype.event = function(){
|
||||
}
|
||||
|
||||
console.log("Counter app in Javascript")
|
||||
|
@ -7,17 +7,13 @@ module.exports = {
|
||||
0x03 : "info",
|
||||
0x04 : "set_option",
|
||||
0x21 : "append_tx",
|
||||
0x22 : "get_hash",
|
||||
0x23 : "commit",
|
||||
0x24 : "rollback",
|
||||
0x25 : "add_listener",
|
||||
0x26 : "rm_listener",
|
||||
0x22 : "check_tx",
|
||||
0x23 : "get_hash",
|
||||
0x24 : "add_listener",
|
||||
0x25 : "rm_listener",
|
||||
},
|
||||
|
||||
decoder : RequestDecoder,
|
||||
|
||||
buffer: BytesBuffer
|
||||
|
||||
}
|
||||
|
||||
function RequestDecoder(buf){
|
||||
@ -32,9 +28,8 @@ RequestDecoder.prototype.flush = function(){};
|
||||
RequestDecoder.prototype.info = function(){};
|
||||
RequestDecoder.prototype.set_option = function(){ return [decode_string(this.buf), decode_string(this.buf)] };
|
||||
RequestDecoder.prototype.append_tx = function(){ return decode_string(this.buf)};
|
||||
RequestDecoder.prototype.check_tx = function(){ return decode_string(this.buf)};
|
||||
RequestDecoder.prototype.get_hash = function(){ };
|
||||
RequestDecoder.prototype.commit = function(){ };
|
||||
RequestDecoder.prototype.rollback = function(){ };
|
||||
RequestDecoder.prototype.add_listener = function(){ }; // TODO
|
||||
RequestDecoder.prototype.rm_listener = function(){ }; // TODO
|
||||
|
||||
|
@ -27,8 +27,6 @@ AppServer.prototype.createServer = function(){
|
||||
socket.name = socket.remoteAddress + ":" + socket.remotePort
|
||||
console.log("new connection from", socket.name)
|
||||
|
||||
appCtx = app.open()
|
||||
|
||||
var conn = {
|
||||
recBuf: new msg.buffer(new Buffer(0)),
|
||||
resBuf: new msg.buffer(new Buffer(0)),
|
||||
@ -90,11 +88,11 @@ AppServer.prototype.createServer = function(){
|
||||
|
||||
var res = function(){
|
||||
if (args == null){
|
||||
return appCtx[reqType]();
|
||||
return app[reqType]();
|
||||
} else if (Array.isArray(args)){
|
||||
return appCtx[reqType].apply(appCtx, args);
|
||||
return app[reqType].apply(app, args);
|
||||
} else {
|
||||
return appCtx[reqType](args)
|
||||
return app[reqType](args)
|
||||
}
|
||||
}()
|
||||
|
||||
|
Reference in New Issue
Block a user