Pay Channel
(Added by the [PayChan amendment][].)
The PayChannel
object type represents a payment channel. Payment channels enable small, rapid off-ledger payments of XAH or IOU that can be later reconciled with the consensus ledger. A payment channel holds a balance of XAH or IOU that can only be paid out to a specific destination address until the channel is closed. Any unspent XAH or IOU is returned to the channel's owner (the source address that created and funded it) when the channel closes.
The [PaymentChannelCreate transaction][] type creates a PayChannel
object. The [PaymentChannelFund][] and [PaymentChannelClaim transaction][] types modify existing PayChannel
objects.
When a payment channel expires, at first it remains on the ledger, because only new transactions can modify ledger contents. Transaction processing automatically closes a payment channel when any transaction accesses it after the expiration. To close an expired channel and return the unspent XAH or IOU to the owner, some addresses must send a new PaymentChannelClaim or PaymentChannelFund transaction accessing the channel.
For an example of using payment channels, see the Payment Channels Tutorial.
Example JSON
Fields
A PayChannel
object has the following fields:
Setting Channel Expiration
The Expiration
field of a payment channel is the mutable expiration time, in contrast to the immutable expiration time represented by the CancelAfter
field. The expiration of a channel is always considered relative to the close_time
field of the previous ledger. The Expiration
field is omitted when a PayChannel
object is created. There are several ways the Expiration
field of a PayChannel
object can be updated, which can be summarized as follows: a channel's source address can set the Expiration
of the channel freely as long as the channel always remains open at least SettleDelay
seconds after the first attempt to close it.
Source Address
The source address can set the Expiration
directly with the PaymentChannelFund transaction type. The new value must not be earlier than whichever of the following values is earliest:
The current
Expiration
value (if one is set)The previous ledger's close time plus the
SettleDelay
of the channel
In other words, the source address can always make the Expiration
later if an expiration is already set. The source can make an Expiration
value earlier or set an Expiration
if one isn't currently set, as long as the new value is at least SettleDelay
seconds in the future. If the source address attempts to set an invalid Expiration
date, the transaction fails with the temBAD_EXPIRATION
error code.
The source address can also set the Expiration
with the tfClose
flag of the PaymentChannelClaim transaction type. If the flag is enabled, the ledger automatically sets the Expiration
to whichever of the following values is earlier:
The current
Expiration
value (if one is set)The previous ledger's close time plus the
SettleDelay
of the channel
The source address can remove the Expiration
with the tfRenew
flag of the PaymentChannelClaim transaction type.
Destination Address
The destination address cannot set the Expiration
field. However, the destination address can use the PaymentChannelClaim's tfClose
flag to close a channel immediately.
Other Addresses
If any other address attempts to set an Expiration
field, the transaction fails with the tecNO_PERMISSION
error code. However, if the channel is already expired, the transaction causes the channel to close and results in tesSUCCESS
instead.
PayChannel ID Format
The ID of a PayChannel
object is the [SHA-512Half][] of the following values, concatenated in order:
The PayChannel space key (
0x0078
)The AccountID of the source account
The AccountID of the destination account
The Sequence number of the [PaymentChannelCreate transaction][] that created the channel If the PaymentChannelCreate transaction used a Ticket, use the
TicketSequence
value instead.
Last updated