Add socket send option to send script

This commit is contained in:
lash 2022-04-26 15:43:18 +00:00
parent 58d801aa86
commit f961345652
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 26 additions and 2 deletions

View File

@ -82,6 +82,20 @@ if config.get('_SOURCE') == None:
sys.exit(1)
class SocketSender:
def __init__(self, config):
self.path = config.get('_SOCKET')
def send(self, tx):
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(self.path)
s.sendall(tx.encode('utf-8'))
r = s.recv(68)
s.close()
return r
def main():
token_resolver = None
if config.get('TOKEN_MODULE') != None:
@ -103,6 +117,11 @@ def main():
sys.stderr.write('processing error: {}. processors: {}\n'.format(str(e), str(processor)))
sys.exit(1)
sender = None
if config.get('_RPC_SEND'):
if config.get('_SOCKET') != None:
sender = SocketSender(config)
tx_iter = iter(processor)
out = Outputter(mode)
while True:
@ -112,6 +131,9 @@ def main():
except StopIteration:
break
tx_hex = tx_bytes.hex()
if sender != None:
r = sender.send(tx_hex)
logg.info('sent {} result {}'.format(tx_hex, r))
print(out.do(tx_hex))

View File

@ -96,6 +96,8 @@ ctrl = SessionController(config, queue_adapter, process_outgoing)
signal.signal(signal.SIGINT, ctrl.shutdown)
signal.signal(signal.SIGTERM, ctrl.shutdown)
logg.info('session id is ' + config.get('SESSION_ID'))
logg.info('session socket path is ' + config.get('SESSION_SOCKET_PATH'))
def main():
while True:

View File

@ -1,7 +1,7 @@
[Unit]
Description=Chainqueue transaction dispatch interface
Requires=chaind-eth-sync@.service
After=chaind-eth-sync@.service
#Requires=chaind-eth-sync@.service
#After=chaind-eth-sync@.service
[Service]
Environment="SESSION_ID=%i"