3 from abci.wire import hex2bytes, decode_big_endian, encode_big_endian
4 from abci.server import ABCIServer
5 from abci.reader import BytesBuffer
8 class CounterApplication():
11 sys.exit("The python example is out of date. Upgrading the Python examples is currently left as an exercise to you.")
20 return ["hashes:%d, txs:%d" % (self.hashCount, self.txCount)], 0
22 def set_option(self, key, value):
23 if key == "serial" and value == "on":
27 def deliver_tx(self, txBytes):
29 txByteArray = bytearray(txBytes)
30 if len(txBytes) >= 2 and txBytes[:2] == "0x":
31 txByteArray = hex2bytes(txBytes[2:])
32 txValue = decode_big_endian(
33 BytesBuffer(txByteArray), len(txBytes))
34 if txValue != self.txCount:
39 def check_tx(self, txBytes):
41 txByteArray = bytearray(txBytes)
42 if len(txBytes) >= 2 and txBytes[:2] == "0x":
43 txByteArray = hex2bytes(txBytes[2:])
44 txValue = decode_big_endian(
45 BytesBuffer(txByteArray), len(txBytes))
46 if txValue < self.txCount:
54 h = encode_big_endian(self.txCount, 8)
58 def add_listener(self):
61 def rm_listener(self):
68 if __name__ == '__main__':
73 port = int(sys.argv[1])
75 print "too many arguments"
78 print 'ABCI Demo APP (Python)'
80 app = CounterApplication()
81 server = ABCIServer(app, port)