import type { Block } from '.'
import { Account } from '../account'
-import { BURN_ADDRESS, BURN_PUBLIC_KEY } from '../constants'
+import { BURN_PUBLIC_KEY } from '../constants'
import { hex } from '../convert'
export function _change (block: Block, representative: unknown): Block {
- const { link, link_as_account, representative: rep, subtype } = block
+ const { link, representative: rep, subtype } = block
try {
if (block.subtype != null) {
throw new Error(`Block already configured as ${block.subtype}`)
: representative
block.link = hex.toBytes(BURN_PUBLIC_KEY)
- block.link_as_account = BURN_ADDRESS
return block
} catch (err) {
block.link = link
- block.link_as_account = link_as_account
block.representative = rep
block.subtype = subtype
throw new TypeError('Failed to configure change block', { cause: err })
previous: Bytes
representative?: Account
link?: Bytes
+ get link_as_account (): string {
+ return typeof this.link === 'undefined'
+ ? ''
+ : new Account(bytes.toHex(this.link)).address
+ }
signature?: string
work?: string
"representative": this.representative.address ?? '',
"balance": dec.toString(this.balance),
"link": bytes.toHex(this.link),
- "link_as_account": bytes.toHex(this.link),
+ "link_as_account": this.link_as_account,
"signature": this.signature ?? '',
"work": this.work ?? ''
}
//! SPDX-License-Identifier: GPL-3.0-or-later
import type { Block } from '.'
-import { Account } from '../account'
import { UNITS } from '../constants'
import { hex } from '../convert'
import { convert } from '../tools'
* @returns {Block} This block with balance, link, and subtype configured
*/
export function _receive (block: Block, sendBlock: unknown, amount: unknown, unit: unknown): Block {
- const { balance, link, link_as_account, subtype } = block
+ const { balance, link, subtype } = block
try {
if (block.subtype != null) {
throw new Error(`Block already configured as ${block.subtype}`)
throw new TypeError('Invalid send block hash', { cause: sendBlock })
}
block.link = hex.toBytes(sendBlock, 32)
- block.link_as_account = new Account(sendBlock).address
return block
} catch (err) {
block.balance = balance
block.link = link
- block.link_as_account = link_as_account
block.subtype = subtype
throw new TypeError('Failed to configure receive block', { cause: err })
}
throw new TypeError('Invalid account', { cause: account })
}
block.link = hex.toBytes(account.publicKey, 32)
- block.link_to_account = account.address
return block
} catch (err) {
block.balance = balance
block.link = link
- block.link_as_account = link_as_account
block.subtype = subtype
throw new TypeError('Failed to configure send block', { cause: err })
}