Ejemplo n.º 1
0
    def _send_transaction(self, method, data_pb, addresses_input,
                          addresses_output):
        '''
           Signs and sends transaction to the network using rest-api.

           :param str method: The method (defined in proto) for Transaction Processor to process the request.
           :param dict data: Dictionary that is required by TP to process the transaction.
           :param str addresses_input: list of addresses(keys) for which to get state.
           :param str addresses_output: list of addresses(keys) for which to save state.
        '''
        addresses_input_output = []
        addresses_input_output.extend(addresses_input)
        addresses_input_output.extend(addresses_output)
        addresses_input_output = list(set(addresses_input_output))
        # forward transaction to test helper
        if self.test_helper:
            self.test_helper.send_transaction(method, data_pb,
                                              addresses_input_output)
            return

        payload = TransactionPayload()
        payload.method = method
        payload.data = data_pb.SerializeToString()

        for address in addresses_input_output:
            if not is_address(address):
                raise ClientException(
                    'one of addresses_input_output {} is not an address'.
                    format(addresses_input_output))

        batch_list = self.make_batch_list(payload, addresses_input,
                                          addresses_output)

        return get_batch_id(self._send_request('batches', batch_list,
                                               'socket'))
Ejemplo n.º 2
0
    def _send_raw_transaction(self, transaction_pb):
        batch_list = self._sign_batch_list(self._signer, [transaction_pb])

        return get_batch_id(self._send_request('batches', batch_list,
                                               'socket'))