def create_stuff_transaction(verb, name, value, signer, to=None): payload = BgtPayload(verb=verb, name=name, value=value, to=to) # The prefix should eventually be looked up from the # validator's namespace registry. addr = make_stuff_address(name) inputs = [addr] outputs = [addr] if to is not None: addr_to = make_stuff_address(to) inputs.append(addr_to) outputs.append(addr_to) header = transaction_pb2.TransactionHeader( signer_public_key=signer.get_public_key().as_hex(), family_name='bgt', family_version='1.0', inputs=inputs, outputs=outputs, 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_stuff_address(name) if value is not None: data = self._dumps({name: value}) else: data = None return self._factory.create_set_request({address: data})
def create_stuff_transaction(verb, name, value, deps, signer): """Creates a signed bgt 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 bgt transaction """ payload = BgtPayload( verb=verb, name=name, value=value) # The prefix should eventually be looked up from the # validator's namespace registry. addr = make_stuff_address(name) header = transaction_pb2.TransactionHeader( signer_public_key=signer.get_public_key().as_hex(), family_name='bgt', 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_stuff_address(name)] return self._factory.create_set_response(addresses)
def create_get_request(self, name): addresses = [make_stuff_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_stuff_address(name)] return txn_function(payload, addresses, addresses, [])