mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-14 13:51:21 +00:00
Remove TMSP Commit/Rollback; Add CheckTx
This commit is contained in:
@ -10,28 +10,13 @@ class CounterApplication():
|
||||
def __init__(self):
|
||||
self.hashCount = 0
|
||||
self.txCount = 0
|
||||
self.commitCount = 0
|
||||
|
||||
def open(self):
|
||||
return CounterAppContext(self)
|
||||
|
||||
|
||||
class CounterAppContext():
|
||||
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.hashCount = app.hashCount
|
||||
self.txCount = app.txCount
|
||||
self.commitCount = app.commitCount
|
||||
self.serial = False
|
||||
|
||||
def echo(self, msg):
|
||||
return msg, 0
|
||||
|
||||
def info(self):
|
||||
return ["hash, tx, commit counts:%d, %d, %d" % (self.hashCount,
|
||||
self.txCount,
|
||||
self.commitCount)], 0
|
||||
return ["hashes:%d, txs:%d" % (self.hashCount, self.txCount)], 0
|
||||
|
||||
def set_option(self, key, value):
|
||||
if key == "serial" and value == "on":
|
||||
@ -50,6 +35,17 @@ class CounterAppContext():
|
||||
self.txCount += 1
|
||||
return None, 0
|
||||
|
||||
def check_tx(self, txBytes):
|
||||
if self.serial:
|
||||
txByteArray = bytearray(txBytes)
|
||||
if len(txBytes) >= 2 and txBytes[:2] == "0x":
|
||||
txByteArray = hex2bytes(txBytes[2:])
|
||||
txValue = decode_big_endian(
|
||||
BytesBuffer(txByteArray), len(txBytes))
|
||||
if txValue < self.txCount:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def get_hash(self):
|
||||
self.hashCount += 1
|
||||
if self.txCount == 0:
|
||||
@ -58,13 +54,6 @@ class CounterAppContext():
|
||||
h.reverse()
|
||||
return h.decode(), 0
|
||||
|
||||
def commit(self):
|
||||
self.commitCount += 1
|
||||
return 0
|
||||
|
||||
def rollback(self):
|
||||
return 0
|
||||
|
||||
def add_listener(self):
|
||||
return 0
|
||||
|
||||
|
@ -7,16 +7,14 @@ message_types = {
|
||||
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",
|
||||
}
|
||||
|
||||
# return the decoded arguments of tmsp messages
|
||||
|
||||
|
||||
class RequestDecoder():
|
||||
|
||||
def __init__(self, reader):
|
||||
@ -37,15 +35,12 @@ class RequestDecoder():
|
||||
def append_tx(self):
|
||||
return decode_string(self.reader)
|
||||
|
||||
def check_tx(self):
|
||||
return decode_string(self.reader)
|
||||
|
||||
def get_hash(self):
|
||||
return
|
||||
|
||||
def commit(self):
|
||||
return
|
||||
|
||||
def rollback(self):
|
||||
return
|
||||
|
||||
def add_listener(self):
|
||||
# TODO
|
||||
return
|
||||
|
@ -12,12 +12,11 @@ from .msg import RequestDecoder, message_types
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Connection():
|
||||
|
||||
def __init__(self, fd, appCtx):
|
||||
def __init__(self, fd, app):
|
||||
self.fd = fd
|
||||
self.appCtx = appCtx
|
||||
self.app = app
|
||||
self.recBuf = BytesBuffer(bytearray())
|
||||
self.resBuf = BytesBuffer(bytearray())
|
||||
self.msgLength = 0
|
||||
@ -32,12 +31,11 @@ class Connection():
|
||||
|
||||
# TMSP server responds to messges by calling methods on the app
|
||||
|
||||
|
||||
class TMSPServer():
|
||||
|
||||
def __init__(self, app, port=5410):
|
||||
self.app = app
|
||||
# map conn file descriptors to (appContext, reqBuf, resBuf, msgDecoder)
|
||||
# map conn file descriptors to (app, reqBuf, resBuf, msgDecoder)
|
||||
self.appMap = {}
|
||||
|
||||
self.port = port
|
||||
@ -62,8 +60,7 @@ class TMSPServer():
|
||||
self.write_list.append(new_fd)
|
||||
print('new connection to', new_addr)
|
||||
|
||||
appContext = self.app.open()
|
||||
self.appMap[new_fd] = Connection(new_fd, appContext)
|
||||
self.appMap[new_fd] = Connection(new_fd, self.app)
|
||||
|
||||
def handle_conn_closed(self, r):
|
||||
self.read_list.remove(r)
|
||||
@ -72,7 +69,7 @@ class TMSPServer():
|
||||
print("connection closed")
|
||||
|
||||
def handle_recv(self, r):
|
||||
# appCtx, recBuf, resBuf, conn
|
||||
# app, recBuf, resBuf, conn
|
||||
conn = self.appMap[r]
|
||||
while True:
|
||||
try:
|
||||
@ -129,7 +126,7 @@ class TMSPServer():
|
||||
conn.msgLength = 0
|
||||
conn.inProgress = False
|
||||
|
||||
req_f = getattr(conn.appCtx, req_type)
|
||||
req_f = getattr(conn.app, req_type)
|
||||
if req_args is None:
|
||||
res = req_f()
|
||||
elif isinstance(req_args, tuple):
|
||||
|
Reference in New Issue
Block a user