From f056790c67c695a980dc5a194abfcb5313ffcdab Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 8 Aug 2025 12:23:15 -0700 Subject: [PATCH] Change block previous property to bytes. --- src/lib/block.ts | 10 +++++----- src/lib/ledger.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/block.ts b/src/lib/block.ts index 32ce1c3..e8a3e38 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -66,7 +66,7 @@ export class Block { subtype?: 'send' | 'receive' | 'change' account: Account balance: bigint - previous: string + previous: Uint8Array representative?: Account link?: Uint8Array signature?: string @@ -108,7 +108,7 @@ export class Block { } this.account = account this.balance = convert(balance, 'raw', 'raw', 'bigint') - this.previous = previous + this.previous = hex.toBytes(previous, 32) if (representative instanceof Account) { this.representative = representative } @@ -135,7 +135,7 @@ export class Block { const data = [ PREAMBLE, this.account.publicKey, - this.previous.padStart(64, '0'), + this.previous, this.representative.publicKey, dec.toHex(this.balance, 32), this.link @@ -173,7 +173,7 @@ export class Block { return { "type": "state", "account": this.account.address, - "previous": this.previous, + "previous": bytes.toHex(this.previous), "representative": this.representative.address ?? '', "balance": this.balance.toString(), "link": bytes.toHex(this.link), @@ -230,7 +230,7 @@ export class Block { const difficulty: bigint = (this.subtype === 'send' || this.subtype === 'change') ? DIFFICULTY_SEND : DIFFICULTY_RECEIVE - const hash = +this.previous === 0 ? this.account.publicKey : this.previous + const hash = this.previous.every(b => b === 0) ? this.account.publicKey : bytes.toHex(this.previous) if (work == null) { const result = await NanoPow.work_generate(hash, { difficulty }) if ('error' in result) { diff --git a/src/lib/ledger.ts b/src/lib/ledger.ts index babb9bd..9834c35 100644 --- a/src/lib/ledger.ts +++ b/src/lib/ledger.ts @@ -488,7 +488,7 @@ export class Ledger extends Wallet { const purpose = dec.toBytes(BIP44_PURPOSE + HARDENED_OFFSET, 4) const coin = dec.toBytes(BIP44_COIN_NANO + HARDENED_OFFSET, 4) const account = dec.toBytes(index + HARDENED_OFFSET, 4) - const previous = hex.toBytes(block.previous === block.account.publicKey ? '0' : block.previous, 32) + const previous = block.previous const link = block.link const representative = hex.toBytes(block.representative.publicKey, 32) const balance = hex.toBytes(block.balance.toString(16), 16) @@ -524,7 +524,7 @@ export class Ledger extends Wallet { } const account = dec.toBytes(index + HARDENED_OFFSET, 4) - const previous = hex.toBytes(block.previous, 32) + const previous = block.previous const link = block.link const representative = hex.toBytes(block.representative.publicKey, 32) const balance = hex.toBytes(BigInt(block.balance).toString(16), 16) -- 2.47.3