}
}
+ /**
+ * Set a block hash as the source send of a receive block.
+ *
+ * @param {string} hash - Hash of send block to be received
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ from (hash: string): Block
+ /**
+ * Set a send block as the source of a receive block.
+ *
+ * @param {Block} block - Send block to be received
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ from (block: Block): Block
+ from (send: unknown): Block {
+ try {
+ if (typeof send !== 'string' && !(send instanceof Block)) {
+ throw new TypeError('Invalid send to be received')
+ }
+ if (this.subtype !== 'receive') {
+ throw new TypeError('Invalid subtype')
+ }
+ this.link = (typeof send === 'string')
+ ? send
+ : send.hash
+ this.representative = this.account.representative
+ return this
+ } catch (err) {
+ throw new Error('Failed to receive a corresponding send', { cause: err })
+ }
+ }
+
/**
* Calculates proof-of-work using a pool of Web Workers.
*
return res.hash
}
+ /**
+ * Set the amount of nano that this block will receive from a paired send.
+ *
+ * @param {bigint} amount - Amount that was sent from sender in raw
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ receive (amount: bigint): Block
+ /**
+ * Set the amount of nano that this block will receive from a paired send.
+ *
+ * @param {number} amount - Amount that was sent from sender in nano (10³⁰ raw)
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ receive (amount: number): Block
+ /**
+ * Set the amount of nano that this block will receive from a paired send.
+ *
+ * @param {string} amount - Amount that was sent from sender in raw
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ receive (amount: string): Block
+ receive (amount: unknown): Block {
+ const currentBalance = this.balance
+ try {
+ if (this.subtype != null) {
+ throw new Error(`Block is already configured as ${this.subtype}`)
+ }
+ this.subtype = 'receive'
+ switch (typeof amount) {
+ case 'bigint': {
+ this.balance += amount
+ break
+ }
+ case 'number': {
+ this.balance += BigInt(amount) * (1n << 30n)
+ break
+ }
+ case 'string': {
+ this.balance += BigInt(amount)
+ break
+ }
+ default: {
+ throw new TypeError('Invalid amount')
+ }
+ }
+ return this
+ } catch (err) {
+ this.subtype = undefined
+ this.balance = currentBalance
+ throw new TypeError('Failed to configure receive block', { cause: err })
+ }
+ }
+
/**
* Set the amount of nano that this block will send to a recipient account.
*