Class: ChannelState

ChannelState(options)

channel state endpoint; each Channel is composed of two channel state represent both actors

Constructor

new ChannelState(options)

Parameters:
Name Type Description
options object
Properties:
Name Type Default Description
proof-the message.Proof proof snapshot of this endpoint. If this channel state represents the peer, this proof is submitted during channel closing.
pendingLocks Object.<string, message.Lock> the pending locks that have not had their secrets revealed. The key is the hashLock value
openLocks Object.<string, message.OpenLock> the opened locks that have had their secrets revealed. The key is the hashLock value
merkleTree merkletree.MerkleTree the merkleTree based on the pending and open locks
depositBalance BN 0 the amount of funds deposited on-chain by this channel state endpoint
address Buffer the ethereum address of the particpant who's state this endpoint represents
Source:
See:

Members

minOpenLockExpiration

Properties:
Name Type Description
return BN the minimum lock expiration time across all open locks. This effectively give an upper bound for how long the channel can remain open unless the lock is converted to a transfer via message.SecretToProof message sent from counterparty.
Source:

nonce

Properties:
Name Type Description
the BN nonce that ensures transfer ordering as retreived from the proof
Source:

transferredAmount

Properties:
Name Type Description
the BN monotonically increasing transferredAmount retrieved from the proof
Source:

Methods

_computeMerkleTreeWithHashlock(lock) → {merkletree.MerkleTree}

Internal computes merkle tree including a new leaf element
Parameters:
Name Type Description
lock message.Lock
Source:
Returns:
Type
merkletree.MerkleTree

_computeMerkleTreeWithoutHashlock(lock) → {merkletree.MerkleTree}

Internal computes merkle tree without a particular leaf element
Parameters:
Name Type Description
lock message.Lock
Source:
Returns:
Type
merkletree.MerkleTree

_lockAmount(locksArray, safeBlock) → {BN}

the total amount of funds that are availble regarding both locked and unlocked funds
Parameters:
Name Type Description
locksArray Array.<message.Lock>
safeBlock BN safe expiration time
Source:
Returns:
Type
BN

applyDirectTransfer(directTransfer)

update the channel state to reflect direct transfer
Parameters:
Name Type Description
directTransfer message.DirectTransfer
Source:
Throws:
  • "Invalid Message Type: DirectTransfer expected"
  • "Invalid hashLockRoot"

applyLockedTransfer(lockedTransfer)

update the channel state to reflect locked transfer
Parameters:
Name Type Description
lockedTransfer message.LockedTransfer | message.MediatedTransfer
Source:
Throws:
  • "Invalid Message Type: DirectTransfer expected"
  • "Invalid Lock: lock already registered"
  • "Invalid hashLockRoot"

applyRevealSecret(revealSecret)

applies the secret to to unlock a pending lock
Parameters:
Name Type Description
revealSecret message.RevealSecret
Source:
Throws:
  • "Invalid Message Type: RevealSecret expected"
  • "Invalid Lock: uknown lock secret received"

applySecretToProof(secretToProof)

removes the open lock and applies the locked amount to the transferredAmount allowing indefinte channel lifetime
Parameters:
Name Type Description
secretToProof message.SecretToProof
Source:
Throws:
  • "Invalid Message Type: SecretToProof expected"
  • "Invalid Lock: uknown lock secret received"
  • "Invalid hashLockRoot in SecretToProof"

balance()

Deprecated
Source:

containsLock(lock) → {bool}

determine if this channel has the lock in pending or open state
Parameters:
Name Type Description
lock message.Lock
Source:
Returns:
Type
bool

generateLockProof(lock) → {Array.<Buffer>}

create a lock proof that maybe submitted for onchain withdrawal of lock during the settlement period
Parameters:
Name Type Description
lock message.OpenLock
Source:
Returns:
Type
Array.<Buffer>

getLockFromSecret(secret) → {message.Lock|message.OpenLock|null}

retreive the lock corresponding to the keccak256 hash of the secret
Parameters:
Name Type Description
secret Buffer
Source:
Returns:
Type
message.Lock | message.OpenLock | null

lockedAmount(safeBlock) → {BN}

determine the amount of funds that are locked. The safeblock parameter is required if you want to prevent channel exhaustion due to lock expirations.
Parameters:
Name Type Description
safeBlock BN
Source:
Returns:
Type
BN

transferrable()

Deprecated
Source:

unlockedAmount() → {BN}

the amount of funds that are unlocked and usable in the netting channel
Source:
Returns:
Type
BN