示例#1
0
def create_zenroom_transaction(verb, name, value, signer):
    payload = ZenroomPayload(verb=verb, name=name, value=value)

    # The prefix should eventually be looked up from the
    # validator's namespace registry.
    addr = make_zenroom_address(name)

    header = transaction_pb2.TransactionHeader(
        signer_public_key=signer.get_public_key().as_hex(),
        family_name='zenroom',
        family_version='1.0',
        inputs=[addr],
        outputs=[addr],
        dependencies=[],
        payload_sha512=payload.sha512(),
        batcher_public_key=signer.get_public_key().as_hex(),
        nonce=hex(random.randint(0, 2**64)))

    header_bytes = header.SerializeToString()

    signature = signer.sign(header_bytes)

    transaction = transaction_pb2.Transaction(header=header_bytes,
                                              payload=payload.to_cbor(),
                                              header_signature=signature)

    return transaction
    def create_set_request(self, name, value):
        address = make_zenroom_address(name)

        if value is not None:
            data = self._dumps({name: value})
        else:
            data = None

        return self._factory.create_set_request({address: data})
示例#3
0
def create_zenroom_transaction(verb, name, value, deps, signer):
    """Creates a signed zenroom transaction.

    Args:
        verb (str): the action the transaction takes, either 'set', 'inc',
            or 'dec'
        name (str): the variable name which is altered by verb and value
        value (int): the amount to set, increment, or decrement
        deps ([str]): a list of transaction header_signatures which are
            required dependencies which must be processed prior to
            processing this transaction
        signer (:obj:`Signer`): the cryptographic signer for signing the
            transaction

    Returns:
        transaction (transaction_pb2.Transaction): the signed zenroom
            transaction
    """
    payload = ZenroomPayload(verb=verb, name=name, value=value)

    # The prefix should eventually be looked up from the
    # validator's namespace registry.
    addr = make_zenroom_address(name)

    header = transaction_pb2.TransactionHeader(
        signer_public_key=signer.get_public_key().as_hex(),
        family_name='zenroom',
        family_version='1.0',
        inputs=[addr],
        outputs=[addr],
        dependencies=deps,
        payload_sha512=payload.sha512(),
        batcher_public_key=signer.get_public_key().as_hex(),
        nonce=hex(random.randint(0, 2**64)))

    header_bytes = header.SerializeToString()

    signature = signer.sign(header_bytes)

    transaction = transaction_pb2.Transaction(header=header_bytes,
                                              payload=payload.to_cbor(),
                                              header_signature=signature)

    return transaction
 def create_set_response(self, name):
     addresses = [make_zenroom_address(name)]
     return self._factory.create_set_response(addresses)
 def create_get_request(self, name):
     addresses = [make_zenroom_address(name)]
     return self._factory.create_get_request(addresses)
    def _create_txn(self, txn_function, verb, name, value):
        payload = self._dumps({'Verb': verb, 'Name': name, 'Value': value})

        addresses = [make_zenroom_address(name)]

        return txn_function(payload, addresses, addresses, [])