我正在按照sawtooth hyperledger api doc中给出的步骤创建增量事件订阅服务器。
由于某种原因它无法正常工作,我在锯齿形日志中看到以下内容
[2019-07-18 18:14:41.003 INFO派遣]从fc9a2db054180e53269ec4c0cad18482afe6f4307251ca7d673f8b723c3293abc5b1c2c07b827ccdf0d9a145f4f [2019-07-18 18:16:46.474 INFO互连]来自fc9a2db054180e53269ec4c0cad18482afe6f4307251ca7d673f8b723c3293abc5b1c2c07b827705cdf0d9a145f8f44cdf546971c05fd67244a01e4cb1ccc9982的连接没有响应
我也尝试使用Sawtooth Simple Supply,但仍然看到相同的错误。有人可以告诉我我可能做错了什么吗?
锯齿:1.1.5
Python:3.6.8
尝试使用不同的示例。 代码:
import zmq
from sawtooth_sdk.protobuf.events_pb2 import EventSubscription, EventFilter, EventList
from sawtooth_sdk.protobuf.client_event_pb2 import ClientEventsSubscribeRequest, ClientEventsSubscribeResponse
from sawtooth_sdk.protobuf import block_pb2, events_pb2, client_event_pb2
from sawtooth_sdk.protobuf import state_context_pb2
from sawtooth_sdk.protobuf import transaction_receipt_pb2
from sawtooth_sdk.protobuf.validator_pb2 import Message
from sawtooth_sdk.processor.core import TransactionProcessor
import time
AUTH_KEY_NAMESPACE = '7f1029.*'
URL='tcp://192.168.17.185:8800'
subscription = EventSubscription(
event_type="sawtooth/state-delta",
filters=[
# Filter to only addresses in the "xo" namespace using a regex
EventFilter(
key="address",
match_string=AUTH_KEY_NAMESPACE,
filter_type=EventFilter.REGEX_ANY)
])
ctx = zmq.Context()
socket = ctx.socket(zmq.DEALER)
socket.connect(URL)
# Construct the request
request = ClientEventsSubscribeRequest(
subscriptions=[subscription]).SerializeToString()
# Construct the message wrapper
correlation_id = "123" # This must be unique for all in-process requests
msg = Message(
correlation_id=correlation_id,
message_type=Message.MessageType.CLIENT_EVENTS_SUBSCRIBE_REQUEST,
content=request)
# Send the request
socket.send_multipart([msg.SerializeToString()])
# Receive the response
resp = socket.recv_multipart()[-1]
# Parse the message wrapper
msg = Message()
msg.ParseFromString(resp)
# Validate the response type
if msg.message_type != Message.MessageType.CLIENT_EVENTS_SUBSCRIBE_RESPONSE:
print("Unexpected message type")
exit(1)
print("Got Subscribe Response")
# Parse the response
msg = Message()
msg.ParseFromString(resp)
# Validate the response type
if msg.message_type != Message.MessageType.CLIENT_EVENTS_SUBSCRIBE_RESPONSE:
print("Unexpected message type")
exit(1)
print("Got Subscribe Response")
# Parse the response
response = ClientEventsSubscribeResponse()
response.ParseFromString(msg.content)
# Validate the response status
if response.status != ClientEventsSubscribeResponse.OK:
print("Subscription failed: {}".format(response.response_message))
exit(1)
print("Subscribe response is ok")
while True:
resp = socket.recv_multipart()[-1]
# Parse the message wrapper
msg = Message()
msg.ParseFromString(resp)
# Validate the response type
if msg.message_type != CLIENT_EVENTS:
print("Unexpected message type")
exit(1)
# Parse the response
events = EventList()
events.ParseFromString(msg.content)
for event in events:
print(event)
答案 0 :(得分:2)
我在Python3中有一个Hyperledger Sawtooth事件处理程序的有效示例。 我也有一个用Go写的。参见:
https://github.com/danintel/sawtooth-cookiejar/tree/master/events
摆脱EventFilter,看看它是否有效。
我从来没有碰过使用ZMQ的运气。我使用锯齿流界面发送请求。