From b66f953f204768521f7bed2409aaba34b320b212 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 3 Dec 2024 13:21:59 -0800 Subject: [PATCH] Move threshold constants into CONSTANTS and use them in block pow. --- src/lib/block.ts | 7 +++++-- src/lib/constants.ts | 2 ++ src/lib/pow.ts | 3 --- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/block.ts b/src/lib/block.ts index 1e409f9..691ec1f 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2024 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later -import { BURN_ADDRESS, PREAMBLE } from './constants.js' +import { BURN_ADDRESS, PREAMBLE, THRESHOLD_RECEIVE, THRESHOLD_SEND } from './constants.js' import { Account } from './account.js' import { Blake2b } from './blake2b.js' import { bytes, dec, hex } from './convert.js' @@ -84,7 +84,10 @@ abstract class Block { async pow (): Promise { const pool = new Pool(Pow) const data = { - "hash": this.previous + "hash": this.previous, + "threshold": (this instanceof SendBlock || this instanceof ChangeBlock) + ? THRESHOLD_SEND + : THRESHOLD_RECEIVE } const [{ work }] = await pool.work('converge', [data]) this.work = work diff --git a/src/lib/constants.ts b/src/lib/constants.ts index f746364..16a7f01 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -16,6 +16,8 @@ export const PREFIX_LEGACY = 'xrb_' export const SEED_LENGTH_BIP44 = 128 export const SEED_LENGTH_BLAKE2B = 64 export const SLIP10_ED25519 = 'ed25519 seed' +export const THRESHOLD_RECEIVE = '0xfffffe' +export const THRESHOLD_SEND = '0xfffffff8' export const XNO = 'Ó¾' export const LEDGER_STATUS_CODES: { [key: number]: string } = Object.freeze({ diff --git a/src/lib/pow.ts b/src/lib/pow.ts index 1c67600..5f8485c 100644 --- a/src/lib/pow.ts +++ b/src/lib/pow.ts @@ -4,10 +4,7 @@ import { Blake2b } from './blake2b.js' const p = () => { - const NONCE_BYTES = 8 - const RECEIVE_THRESHOLD = '0xfffffe' const SEND_THRESHOLD = '0xfffffff8' - /** * Listens for messages from a calling function. */ -- 2.34.1