signature?: string
work?: string
- constructor (account: string | Account, balance?: bigint | string, previous?: string, representative?: string | Account)
- constructor (account: unknown, balance: unknown, previous: unknown, representative: unknown) {
- if (typeof account === 'string') {
- account = Account.import(account)
- }
- if (typeof representative === 'string') {
- representative = Account.import(representative)
- }
- if (!(account instanceof Account)) {
- throw new TypeError('Invalid account')
- }
- balance ??= account.balance
- previous ??= account.frontier
- representative ??= account.representative
- if (typeof balance !== 'bigint' && typeof balance !== 'string') {
- throw new TypeError('Account balance is unknown')
- }
- if (typeof previous !== 'string') {
- throw new TypeError('Account frontier is unknown')
- }
- if (!(representative instanceof Account)) {
- throw new TypeError('Account representative is unknown')
+ constructor (account: string | Account, balance?: bigint | string, previous?: string, representative?: string | Account, signature?: string, work?: string)
+ constructor (account: unknown, balance: unknown, previous: unknown, representative: unknown, signature: unknown, work: unknown) {
+ try {
+ if (typeof account === 'string') {
+ account = Account.import(account)
+ }
+ if (typeof representative === 'string') {
+ representative = Account.import(representative)
+ }
+ if (!(account instanceof Account)) {
+ throw new TypeError('Invalid account')
+ }
+ balance ??= account.balance
+ previous ??= account.frontier
+ representative ??= account.representative
+ if (typeof balance !== 'bigint' && typeof balance !== 'string') {
+ throw new TypeError('Account balance is unknown')
+ }
+ if (typeof previous !== 'string') {
+ throw new TypeError('Account frontier is unknown')
+ }
+ if (!(representative instanceof Account)) {
+ throw new TypeError('Account representative is unknown')
+ }
+ this.account = account
+ this.balance = BigInt(balance)
+ this.previous = previous
+ this.representative = representative
+ if (typeof signature === 'string') {
+ this.signature = signature
+ }
+ if (typeof work === 'string') {
+ this.work = work
+ }
+ } catch (err) {
+ throw new Error('Failed to initialize Block', { cause: err })
}
- this.account = account
- this.balance = BigInt(balance)
- this.previous = previous
- this.representative = representative
}
/**