import { bytes, dec, hex } from './convert'
import { NanoNaCl } from './nano-nacl'
import { Rpc } from './rpc'
+import { convert } from './tools'
import { Wallet } from './wallet'
/**
* the other parameters instead of passing them into the constructor.
*
* @param {(string|Account)} account - Target of the transaction; can include `balance`, `frontier`, `representative`
- * @param {(bigint|number|string)} [balance] - Current balance of the target account
+ * @param {(bigint|number|string)} [balance] - Current balance of the target account in raw
* @param {string} [previous] - Current frontier block hash of the target account
* @param {(string|Account)} [representative] - Current representative of the target account
*/
throw new TypeError('Account frontier is unknown')
}
this.account = account
- this.balance = BigInt(balance)
+ this.balance = convert(balance, 'raw', 'raw', 'bigint')
this.previous = previous
if (representative instanceof Account) {
this.representative = representative
if (typeof amount !== 'bigint' && typeof amount !== 'number' && typeof amount !== 'string') {
throw new TypeError('Invalid amount')
}
- this.balance += BigInt(amount) * (10n ** BigInt(UNITS[unit.toUpperCase()]))
+ this.balance += convert(amount, unit, 'raw', 'bigint')
if (typeof sendBlock !== 'string' && !(sendBlock instanceof Block)) {
throw new TypeError('Invalid send block')
unit ??= 'RAW'
if (typeof unit !== 'string' || typeof UNITS[unit] !== 'number') {
- throw new TypeError('Invalid unit')
+ throw new TypeError('Invalid unit', { cause: unit })
}
if (typeof amount !== 'bigint' && typeof amount !== 'number' && typeof amount !== 'string') {
- throw new TypeError('Invalid amount')
+ throw new TypeError(`Invalid amount ${amount}`, { cause: typeof amount })
}
- this.balance -= BigInt(amount) * (10n ** BigInt(UNITS[unit.toUpperCase()]))
+ this.balance -= convert(amount, unit, 'raw', 'bigint')
if (this.balance < 0) {
throw new RangeError('Insufficient funds', { cause: this.balance })