}
block.balance += convert(amount, unit, 'raw', 'bigint')
- if (typeof sendBlock !== 'string' && !(sendBlock instanceof (block.constructor as typeof Block))) {
- throw new TypeError('Invalid send block')
+ if (sendBlock instanceof (block.constructor as typeof Block)) {
+ sendBlock = sendBlock.hash
}
- block.link = (typeof sendBlock === 'string')
- ? hex.toBytes(sendBlock)
- : hex.toBytes(sendBlock.hash)
+ if (typeof sendBlock !== 'string' || sendBlock.length !== 64) {
+ throw new TypeError('Invalid send block hash', { cause: sendBlock })
+ }
+ block.link = hex.toBytes(sendBlock, 32)
return block
} catch (err) {
throw new RangeError('Insufficient funds', { cause: block.balance })
}
- if (typeof account !== 'string' && !(account instanceof Account)) {
+ if (typeof account === 'string') {
+ account = new Account(account)
+ }
+ if (!(account instanceof Account)) {
throw new TypeError('Invalid account', { cause: account })
}
- block.link = (typeof account === 'string')
- ? hex.toBytes(new Account(account).publicKey)
- : hex.toBytes(account.publicKey)
+ block.link = hex.toBytes(account.publicKey, 32)
return block
} catch (err) {