Ejemplo n.º 1
0
  @Override
  public APIHeader mine(Address address) throws BCSAPIException {
    try (ConnectorSession session = connection.createSession()) {
      log.trace("mine to " + address);

      ConnectorProducer producer = session.createProducer(session.createTopic("mine"));

      ConnectorMessage m = session.createMessage();
      BCSAPIMessage.Script.Builder builder =
          BCSAPIMessage.Script.newBuilder()
              .setScript(ByteString.copyFrom(address.getAddressScript().toByteArray()));
      m.setPayload(builder.build().toByteArray());
      byte[] reply = synchronousRequest(session, producer, m);
      if (reply != null) {
        return APIHeader.fromProtobuf(BCSAPIMessage.BLK.parseFrom(reply));
      }
    } catch (ConnectorException | InvalidProtocolBufferException | HyperLedgerException e) {
      throw new BCSAPIException(e);
    }
    return null;
  }
Ejemplo n.º 2
0
  @Override
  public APIHeader getBlockHeader(BID hash) throws BCSAPIException {
    try (ConnectorSession session = connection.createSession()) {
      log.trace("get block header" + hash);

      ConnectorProducer blockHeaderRequestProducer =
          session.createProducer(session.createQueue("headerRequest"));

      ConnectorMessage m = session.createMessage();
      BCSAPIMessage.Hash.Builder builder = BCSAPIMessage.Hash.newBuilder();
      builder.addHash(ByteString.copyFrom(hash.unsafeGetArray()));
      m.setPayload(builder.build().toByteArray());
      byte[] response = synchronousRequest(session, blockHeaderRequestProducer, m);
      if (response != null) {
        return APIHeader.fromProtobuf(BCSAPIMessage.BLK.parseFrom(response));
      }
    } catch (ConnectorException | InvalidProtocolBufferException e) {
      throw new BCSAPIException(e);
    }

    return null;
  }