示例#1
0
 def __init__(self, private=None, public=None):
     self._factory = MessageFactory(
         encoding='application/protobuf',
         family_name=SUPPLYCHAIN_FAMILY_NAME,
         family_version=SUPPLYCHAIN_VERSION,
         namespace=[Addressing.agent_namespace(),
                    Addressing.application_namespace(),
                    Addressing.record_namespace()],
         private=private,
         public=public
     )
示例#2
0
 def application_list(self):
     result = self._send_get("state?address={}".format(
         Addressing.application_namespace()))
     try:
         data = self._get_result_list(result)
         out = []
         for state_obj in data:
             container = _decode_application_container(
                 _b64_dec(state_obj['data']))
             out.extend(container.entries)
         return out
     except BaseException:
         return None
示例#3
0
 def application_list(self):
     result = self._send_get("state?address={}".format(
         Addressing.application_namespace()))
     try:
         data = self._get_result_list(result)
         out = []
         for state_obj in data:
             container = _decode_application_container(
                 _b64_dec(state_obj['data']))
             out.extend(container.entries)
         return out
     except BaseException:
         return None
示例#4
0
 def _get(state, addresses):
     entries = state.get(addresses)
     if entries:
         out = {}
         for e in entries:
             addr = e.address
             if e.data:
                 if addr.startswith(Addressing.agent_namespace()):
                     container = AgentContainer()
                 elif addr.startswith(Addressing.application_namespace()):
                     container = ApplicationContainer()
                 elif addr.startswith(Addressing.record_namespace()):
                     container = RecordContainer()
                 else:
                     raise InvalidTransaction("Unknown namespaces.")
             else:
                 container = None
             container.ParseFromString(e.data)
             out[addr] = container
         return out
     return {}
示例#5
0
 def _get(state, addresses):
     entries = state.get(addresses)
     if entries:
         out = {}
         for e in entries:
             addr = e.address
             if e.data:
                 if addr.startswith(Addressing.agent_namespace()):
                     container = AgentContainer()
                 elif addr.startswith(Addressing.application_namespace()):
                     container = ApplicationContainer()
                 elif addr.startswith(Addressing.record_namespace()):
                     container = RecordContainer()
                 else:
                     raise InvalidTransaction("Unknown namespaces.")
             else:
                 container = None
             container.ParseFromString(e.data)
             out[addr] = container
         return out
     return {}
示例#6
0
    StateDeltaUnsubscribeRequest
from sawtooth_sdk.protobuf.state_delta_pb2 import StateDeltaEvent
from sawtooth_sdk.protobuf.transaction_receipt_pb2 import StateChange
from sawtooth_sdk.protobuf.validator_pb2 import Message

from sawtooth_supplychain.common.addressing import Addressing

from sawtooth_supplychain.protobuf.agent_pb2 import AgentContainer
from sawtooth_supplychain.protobuf.application_pb2 import ApplicationContainer
from sawtooth_supplychain.protobuf.application_pb2 import Application
from sawtooth_supplychain.protobuf.record_pb2 import RecordContainer

LOGGER = logging.getLogger(__name__)

AGENT_NAMESPACE = Addressing.agent_namespace()
APPLICATION_NAMESPACE = Addressing.application_namespace()
RECORD_NAMESPACE = Addressing.record_namespace()

MAX_BLOCK_NUMBER = int(math.pow(2, 63)) - 1


class Subscriber:
    """A State Delta Subscriber for supplychain.

    The Subscriber will send a StateDeltaSubscribeRequest, limited to the
    state values within the namespaces for the supplychain family.
    """
    def __init__(self, stream, db_connection):
        self._stream = stream
        self._db_connection = db_connection
示例#7
0
 def namespaces(self):
     return [
         Addressing.agent_namespace(),
         Addressing.application_namespace(),
         Addressing.record_namespace()
     ]
示例#8
0
 def namespaces(self):
     return [Addressing.agent_namespace(),
             Addressing.application_namespace(),
             Addressing.record_namespace()]