def accept_offer(txn_key, batch_key, identifier, offerer, receiver, count): """Create an AcceptOffer txn and wrap it in a Batch and list. Args: txn_key (sawtooth_signing.Signer): The Txn signer key pair. batch_key (sawtooth_signing.Signer): The Batch signer key pair. identifier (str): The identifier of the Offer. offerer (OfferParticipant): The participant who made the offer. receiver (OfferParticipant): The participant who is accepting the offer. count (int): The number of units of exchange. Returns: tuple: List of Batch, signature tuple """ inputs = [ addresser.make_asset_address(receiver.target), addresser.make_asset_address(offerer.source), addresser.make_resource_address(receiver.target_resource), addresser.make_resource_address(offerer.source_resource), addresser.make_offer_history_address(offer_id=identifier), addresser.make_offer_account_address( offer_id=identifier, account=txn_key.get_public_key().as_hex()), addresser.make_offer_address(identifier) ] outputs = [ addresser.make_asset_address(receiver.target), addresser.make_asset_address(offerer.source), addresser.make_offer_history_address(offer_id=identifier), addresser.make_offer_account_address( offer_id=identifier, account=txn_key.get_public_key().as_hex()) ] if receiver.source is not None: inputs.append(addresser.make_asset_address(receiver.source)) inputs.append(addresser.make_resource_address( receiver.source_resource)) outputs.append(addresser.make_asset_address(receiver.source)) if offerer.target is not None: inputs.append(addresser.make_asset_address(offerer.target)) inputs.append(addresser.make_resource_address(offerer.target_resource)) outputs.append(addresser.make_asset_address(offerer.target)) accept_txn = payload_pb2.AcceptOffer(id=identifier, source=receiver.source, target=receiver.target, count=count) payload = payload_pb2.TransactionPayload( payload_type=payload_pb2.TransactionPayload.ACCEPT_OFFER, accept_offer=accept_txn) return make_header_and_batch(payload=payload, inputs=inputs, outputs=outputs, txn_key=txn_key, batch_key=batch_key)
def save_offer_receipt(self, offer_id): address = addresser.make_offer_history_address(offer_id=offer_id) container = _get_history_container(self._state_entries, address) offer_history = container.entries.add() offer_history.offer_id = offer_id state_entries_send = {} state_entries_send[address] = container.SerializeToString() return self._context.set_state(state_entries_send, self._timeout)
def save_offer_receipt(self, offer_id): address = addresser.make_offer_history_address(offer_id=offer_id) container = _get_history_container(self._state_entries, address) offer_history = container.entries.add() offer_history.offer_id = offer_id state_entries_send = {} state_entries_send[address] = container.SerializeToString() return self._context.set_state( state_entries_send, self._timeout)
def offer_has_receipt(self, offer_id): address = addresser.make_offer_history_address(offer_id=offer_id) self._state_entries.extend( self._context.get_state(addresses=[address], timeout=self._timeout)) container = _get_history_container(self._state_entries, address) try: _get_history_by_offer_id(container, offer_id=offer_id) return True except KeyError: return False
def offer_has_receipt(self, offer_id): address = addresser.make_offer_history_address( offer_id=offer_id) self._state_entries.extend(self._context.get_state( addresses=[address], timeout=self._timeout)) container = _get_history_container(self._state_entries, address) try: _get_history_by_offer_id( container, offer_id=offer_id) return True except KeyError: return False
def accept_offer(txn_key, batch_key, identifier, offerer, receiver, count): """Create an AcceptOffer txn and wrap it in a Batch and list. Args: txn_key (sawtooth_signing.Signer): The Txn signer key pair. batch_key (sawtooth_signing.Signer): The Batch signer key pair. identifier (str): The identifier of the Offer. offerer (OfferParticipant): The participant who made the offer. receiver (OfferParticipant): The participant who is accepting the offer. count (int): The number of units of exchange. Returns: tuple: List of Batch, signature tuple """ inputs = [addresser.make_holding_address(receiver.target), addresser.make_holding_address(offerer.source), addresser.make_asset_address(receiver.target_asset), addresser.make_asset_address(offerer.source_asset), addresser.make_offer_history_address(offer_id=identifier), addresser.make_offer_account_address( offer_id=identifier, account=txn_key.get_public_key().as_hex()), addresser.make_offer_address(identifier)] outputs = [addresser.make_holding_address(receiver.target), addresser.make_holding_address(offerer.source), addresser.make_offer_history_address(offer_id=identifier), addresser.make_offer_account_address( offer_id=identifier, account=txn_key.get_public_key().as_hex())] if receiver.source is not None: inputs.append(addresser.make_holding_address(receiver.source)) inputs.append(addresser.make_asset_address(receiver.source_asset)) outputs.append(addresser.make_holding_address(receiver.source)) if offerer.target is not None: inputs.append(addresser.make_holding_address(offerer.target)) inputs.append(addresser.make_asset_address(offerer.target_asset)) outputs.append(addresser.make_holding_address(offerer.target)) accept_txn = payload_pb2.AcceptOffer( id=identifier, source=receiver.source, target=receiver.target, count=count) payload = payload_pb2.TransactionPayload( payload_type=payload_pb2.TransactionPayload.ACCEPT_OFFER, accept_offer=accept_txn) return make_header_and_batch( payload=payload, inputs=inputs, outputs=outputs, txn_key=txn_key, batch_key=batch_key)