es/channel/index.js
function withdraw (amount, sign, { onOnChainTx, onOwnWithdrawLocked, onWithdrawLocked } = {}) {
  return new Promise((resolve, reject) => {
    enqueueAction(
      this,
      (channel, state) => state.handler === handlers.channelOpen,
      (channel, state) => {
        send(channel, { jsonrpc: '2.0', method: 'channels.withdraw', params: { amount } })
        return {
          handler: handlers.awaitingWithdrawTx,
          state: {
            sign,
            resolve,
            reject,
            onOnChainTx,
            onOwnWithdrawLocked,
            onWithdrawLocked
          }
        }
      }
    )
  })
}
function withdraw (amount, sign, { onOnChainTx, onOwnWithdrawLocked, onWithdrawLocked } = {}) {
  return new Promise((resolve, reject) => {
    enqueueAction(
      this,
      (channel, state) => state.handler === handlers.channelOpen,
      (channel, state) => {
        send(channel, { jsonrpc: '2.0', method: 'channels.withdraw', params: { amount } })
        return {
          handler: handlers.awaitingWithdrawTx,
          state: {
            sign,
            resolve,
            reject,
            onOnChainTx,
            onOwnWithdrawLocked,
            onWithdrawLocked
          }
        }
      }
    )
  })
}
function withdraw ( amount , sign , { onOnChainTx , onOwnWithdrawLocked , onWithdrawLocked } = { } ) { return new Promise ( ( resolve , reject ) => { enqueueAction ( this , ( channel , state ) => state . handler === handlers . channelOpen , ( channel , state ) => { send ( channel , { jsonrpc : '2.0' , method : 'channels.withdraw' , params : { amount } } ) return { handler : handlers . awaitingWithdrawTx , state : { sign , resolve , reject , onOnChainTx , onOwnWithdrawLocked , onWithdrawLocked } } } ) } ) }
Withdraw tokens from the channel

After the channel had been opened any of the participants can initiate a withdrawal.
The process closely resembles the update. The most notable difference is that the
transaction has been co-signed: it is channel_withdraw_tx and after the procedure
is finished - it is being posted on-chain.

Any of the participants can initiate a withdrawal. The only requirements are:

- Channel is already opened
- No off-chain update/deposit/withdrawal is currently being performed
- Channel is not being closed or in a solo closing state
- The withdrawal amount must be equal to or greater than zero, and cannot exceed
the available balance on the channel (minus the channel_reserve)

After the other party had signed the withdraw transaction, the transaction is posted
on-chain and onOnChainTx callback is called with on-chain transaction as first argument.
After computing transaction hash it can be tracked on the chain: entering the mempool,
block inclusion and a number of confirmations.

After the minimum_depth block confirmations onOwnWithdrawLocked callback is called
(without any arguments).

When the other party had confirmed that the block height needed is reached
onWithdrawLocked callback is called (without any arguments).

@param {Number} amount - Amount of tokens to withdraw
@param {Function} sign - Function which verifies and signs withdraw transaction
@param {Object} [callbacks]
@param {Function} [callbacks.onOnChainTx] - Called when withdraw transaction has been posted on chain
@param {Function} [callbacks.onOwnWithdrawLocked]
@param {Function} [callbacks.onWithdrawLocked]
@return {Promise<Object>}
@example channel.withdraw(
100,
async (tx) => await account.signTransaction(tx),
{ onOnChainTx: (tx) => console.log('on_chain_tx', tx) }
).then(({ accepted, signedTx }) => {
if (accepted) {
console.log('Withdrawal has been accepted')
} else {
console.log('Withdrawal has been rejected')
}
})
Withdraw tokens from the channel