コード例 #1
1
ファイル: FullHashToId.java プロジェクト: andriybobyr/lnk
 @Override
 JSONStreamAware processRequest(HttpServletRequest req) {
   JSONObject response = new JSONObject();
   long longId = Convert.fullHashToId(Convert.parseHexString(req.getParameter("fullHash")));
   response.put("longId", String.valueOf(longId));
   response.put("stringId", Long.toUnsignedString(longId));
   return response;
 }
コード例 #2
0
 private void loadPassPhrases() {
   try {
     List<String> passphrases =
         Files.readAllLines(Paths.get("passphrases.txt"), Charset.forName("US-ASCII"));
     for (String ps : passphrases) {
       if (!ps.isEmpty()) {
         byte[] publicKey = Crypto.getPublicKey(ps);
         byte[] publicKeyHash = Crypto.sha256().digest(publicKey);
         Long id = Convert.fullHashToId(publicKeyHash);
         loadedPassPhrases.put(id, ps);
         LOGGER.info("Added key: {" + ps + "} -> {" + Convert.toUnsignedLong(id) + "}");
       }
     }
   } catch (IOException e) {
     LOGGER.info("Warning: no passphrases.txt found");
   }
 }
コード例 #3
0
  @Override
  public Transaction parseTransaction(byte[] bytes) throws NxtException.ValidationException {

    try {
      boolean useNQT = Nxt.getBlockchain().getLastBlock().getHeight() >= Constants.NQT_BLOCK;
      ByteBuffer buffer = ByteBuffer.wrap(bytes);
      buffer.order(ByteOrder.LITTLE_ENDIAN);

      byte type = buffer.get();
      byte subtype = buffer.get();
      int timestamp = buffer.getInt();
      short deadline = buffer.getShort();
      byte[] senderPublicKey = new byte[32];
      buffer.get(senderPublicKey);
      Long recipientId = buffer.getLong();
      long amountNQT;
      long feeNQT;
      String referencedTransactionFullHash = null;
      Long referencedTransactionId = null;
      if (!useNQT) {
        amountNQT = ((long) buffer.getInt()) * Constants.ONE_NXT;
        feeNQT = ((long) buffer.getInt()) * Constants.ONE_NXT;
        referencedTransactionId = Convert.zeroToNull(buffer.getLong());
      } else {
        amountNQT = buffer.getLong();
        feeNQT = buffer.getLong();
        byte[] referencedTransactionFullHashBytes = new byte[32];
        buffer.get(referencedTransactionFullHashBytes);
        if (Convert.emptyToNull(referencedTransactionFullHashBytes) != null) {
          referencedTransactionFullHash = Convert.toHexString(referencedTransactionFullHashBytes);
          referencedTransactionId = Convert.fullHashToId(referencedTransactionFullHash);
        }
      }
      byte[] signature = new byte[64];
      buffer.get(signature);
      signature = Convert.emptyToNull(signature);

      TransactionType transactionType = TransactionType.findTransactionType(type, subtype);
      TransactionImpl transaction;
      if (!useNQT) {
        transaction =
            new TransactionImpl(
                transactionType,
                timestamp,
                deadline,
                senderPublicKey,
                recipientId,
                amountNQT,
                feeNQT,
                referencedTransactionId,
                signature);
      } else {
        transaction =
            new TransactionImpl(
                transactionType,
                timestamp,
                deadline,
                senderPublicKey,
                recipientId,
                amountNQT,
                feeNQT,
                referencedTransactionFullHash,
                signature);
      }
      transactionType.loadAttachment(transaction, buffer);

      return transaction;

    } catch (RuntimeException e) {
      throw new NxtException.ValidationException(e.toString(), e);
    }
  }
コード例 #4
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 public static long getId(byte[] publicKey) {
   byte[] publicKeyHash = Crypto.sha256().digest(publicKey);
   return Convert.fullHashToId(publicKeyHash);
 }