doProofOfWork method

void doProofOfWork(
  1. int difficulty
)

Implementation

void doProofOfWork(int difficulty) {
  if (difficulty < 0) {
    throw ArgumentError("PoW difficulty can't be negative", 'difficulty');
  }
  if (difficulty > 0) {
    final difficultyInBytes = (difficulty / 8).ceil();
    List<dynamic> result = [];
    for (List<dynamic> tag in tags) {
      result.add(tag);
    }
    result.add(["nonce", "0", difficulty.toString()]);
    tags = result;
    int nonce = 0;
    do {
      const int nonceIndex = 1;
      tags.last[nonceIndex] = (++nonce).toString();
      id = _getId(pubKey, createdAt, kind, tags, content);
    } while (_countLeadingZeroBytes(id) < difficultyInBytes);
  }
}