Skip to content

Commit

Permalink
feat: add pmt channel tx (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdp2121 authored Feb 5, 2025
1 parent 70aeb24 commit c50e688
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 1 deletion.
26 changes: 26 additions & 0 deletions shared/requests/submit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ components:
NFTokenCancelOffer: '../transactions/nftoken_cancel_offer.yaml#/components/schemas/NFTokenCancelOfferTransaction'
NFTokenCreateOffer: '../transactions/nftoken_create_offer.yaml#/components/schemas/NFTokenCreateOfferTransaction'
NFTokenMint: '../transactions/nftoken_mint.yaml#/components/schemas/NFTokenMintTransaction'
PaymentChannelClaim: '../transactions/payment_channel_claim.yaml#/components/schemas/PaymentChannelClaimTransaction'
PaymentChannelCreate: '../transactions/payment_channel_create.yaml#/components/schemas/PaymentChannelCreateTransaction'
PaymentChannelFund: '../transactions/payment_channel_fund.yaml#/components/schemas/PaymentChannelFundTransaction'
oneOf:
- $ref: '../transactions/payment.yaml#/components/schemas/PaymentTransactionV1'
- $ref: '../transactions/oracle_set.yaml#/components/schemas/OracleSetTransaction'
Expand Down Expand Up @@ -135,6 +138,9 @@ components:
- $ref: '../transactions/nftoken_cancel_offer.yaml#/components/schemas/NFTokenCancelOfferTransaction'
- $ref: '../transactions/nftoken_create_offer.yaml#/components/schemas/NFTokenCreateOfferTransaction'
- $ref: '../transactions/nftoken_mint.yaml#/components/schemas/NFTokenMintTransaction'
- $ref: '../transactions/payment_channel_claim.yaml#/components/schemas/PaymentChannelClaimTransaction'
- $ref: '../transactions/payment_channel_create.yaml#/components/schemas/PaymentChannelCreateTransaction'
- $ref: '../transactions/payment_channel_fund.yaml#/components/schemas/PaymentChannelFundTransaction'
# TODO: Add other transaction types here

description: 'Transaction definition in JSON format, optionally omitting any auto-fillable fields.'
Expand Down Expand Up @@ -184,6 +190,9 @@ components:
NFTokenCancelOffer: '../transactions/nftoken_cancel_offer.yaml#/components/schemas/NFTokenCancelOfferTransaction'
NFTokenCreateOffer: '../transactions/nftoken_create_offer.yaml#/components/schemas/NFTokenCreateOfferTransaction'
NFTokenMint: '../transactions/nftoken_mint.yaml#/components/schemas/NFTokenMintTransaction'
PaymentChannelClaim: '../transactions/payment_channel_claim.yaml#/components/schemas/PaymentChannelClaimTransaction'
PaymentChannelCreate: '../transactions/payment_channel_create.yaml#/components/schemas/PaymentChannelCreateTransaction'
PaymentChannelFund: '../transactions/payment_channel_fund.yaml#/components/schemas/PaymentChannelFundTransaction'
oneOf:
- $ref: '../transactions/payment.yaml#/components/schemas/PaymentTransactionV2'
- $ref: '../transactions/oracle_set.yaml#/components/schemas/OracleSetTransaction'
Expand Down Expand Up @@ -218,6 +227,9 @@ components:
- $ref: '../transactions/nftoken_cancel_offer.yaml#/components/schemas/NFTokenCancelOfferTransaction'
- $ref: '../transactions/nftoken_create_offer.yaml#/components/schemas/NFTokenCreateOfferTransaction'
- $ref: '../transactions/nftoken_mint.yaml#/components/schemas/NFTokenMintTransaction'
- $ref: '../transactions/payment_channel_claim.yaml#/components/schemas/PaymentChannelClaimTransaction'
- $ref: '../transactions/payment_channel_create.yaml#/components/schemas/PaymentChannelCreateTransaction'
- $ref: '../transactions/payment_channel_fund.yaml#/components/schemas/PaymentChannelFundTransaction'
# TODO: Add other transaction types here
description: 'Transaction definition in JSON format, optionally omitting any auto-fillable fields.'
required:
Expand Down Expand Up @@ -326,6 +338,9 @@ components:
NFTokenCancelOffer: '../transactions/nftoken_cancel_offer.yaml#/components/schemas/NFTokenCancelOfferTransaction'
NFTokenCreateOffer: '../transactions/nftoken_create_offer.yaml#/components/schemas/NFTokenCreateOfferTransaction'
NFTokenMint: '../transactions/nftoken_mint.yaml#/components/schemas/NFTokenMintTransaction'
PaymentChannelClaim: '../transactions/payment_channel_claim.yaml#/components/schemas/PaymentChannelClaimTransaction'
PaymentChannelCreate: '../transactions/payment_channel_create.yaml#/components/schemas/PaymentChannelCreateTransaction'
PaymentChannelFund: '../transactions/payment_channel_fund.yaml#/components/schemas/PaymentChannelFundTransaction'
# TODO: Add other transaction types here
oneOf:
- $ref: '../transactions/payment.yaml#/components/schemas/PaymentTransactionV1'
Expand Down Expand Up @@ -361,6 +376,9 @@ components:
- $ref: '../transactions/nftoken_cancel_offer.yaml#/components/schemas/NFTokenCancelOfferTransaction'
- $ref: '../transactions/nftoken_create_offer.yaml#/components/schemas/NFTokenCreateOfferTransaction'
- $ref: '../transactions/nftoken_mint.yaml#/components/schemas/NFTokenMintTransaction'
- $ref: '../transactions/payment_channel_claim.yaml#/components/schemas/PaymentChannelClaimTransaction'
- $ref: '../transactions/payment_channel_create.yaml#/components/schemas/PaymentChannelCreateTransaction'
- $ref: '../transactions/payment_channel_fund.yaml#/components/schemas/PaymentChannelFundTransaction'
# TODO: Add other transaction types here

SubmitSuccessResponseV2:
Expand Down Expand Up @@ -405,6 +423,9 @@ components:
NFTokenCancelOffer: '../transactions/nftoken_cancel_offer.yaml#/components/schemas/NFTokenCancelOfferTransaction'
NFTokenCreateOffer: '../transactions/nftoken_create_offer.yaml#/components/schemas/NFTokenCreateOfferTransaction'
NFTokenMint: '../transactions/nftoken_mint.yaml#/components/schemas/NFTokenMintTransaction'
PaymentChannelClaim: '../transactions/payment_channel_claim.yaml#/components/schemas/PaymentChannelClaimTransaction'
PaymentChannelCreate: '../transactions/payment_channel_create.yaml#/components/schemas/PaymentChannelCreateTransaction'
PaymentChannelFund: '../transactions/payment_channel_fund.yaml#/components/schemas/PaymentChannelFundTransaction'
# TODO: Add other transaction types here
oneOf:
- $ref: '../transactions/payment.yaml#/components/schemas/PaymentTransactionV2'
Expand Down Expand Up @@ -440,6 +461,9 @@ components:
- $ref: '../transactions/nftoken_cancel_offer.yaml#/components/schemas/NFTokenCancelOfferTransaction'
- $ref: '../transactions/nftoken_create_offer.yaml#/components/schemas/NFTokenCreateOfferTransaction'
- $ref: '../transactions/nftoken_mint.yaml#/components/schemas/NFTokenMintTransaction'
- $ref: '../transactions/payment_channel_claim.yaml#/components/schemas/PaymentChannelClaimTransaction'
- $ref: '../transactions/payment_channel_create.yaml#/components/schemas/PaymentChannelCreateTransaction'
- $ref: '../transactions/payment_channel_fund.yaml#/components/schemas/PaymentChannelFundTransaction'
# TODO: Add other transaction types here

SubmitErrorResponse:
Expand Down Expand Up @@ -470,6 +494,8 @@ components:
- $ref: '../transactions/nftoken_cancel_offer.yaml#/components/schemas/NFTokenCancelOfferErrorCode'
- $ref: '../transactions/nftoken_create_offer.yaml#/components/schemas/NFTokenCreateOfferErrorCode'
- $ref: '../transactions/nftoken_mint.yaml#/components/schemas/NFTokenMintErrorCode'
- $ref: '../transactions/payment_channel_create.yaml#/components/schemas/PaymentChannelCreateErrorCode'
- $ref: '../transactions/payment_channel_fund.yaml#/components/schemas/PaymentChannelFundErrorCode'
- enum:
- amendmentBlocked
- highFee
Expand Down
4 changes: 3 additions & 1 deletion shared/transactions/account_delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ components:
for the recipient of the deleted account's leftover XRP.
required:
- Destination

x-custom-validation:
validCredentials:
field: CredentialIDs
AccountDeleteErrorCode:
$id: AccountDeleteErrorCode
type: string
Expand Down
2 changes: 2 additions & 0 deletions shared/transactions/escrow_finish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ components:
mutualPresence:
- field1: Condition
field2: Fulfillment
validCredentials:
field: CredentialIDs
71 changes: 71 additions & 0 deletions shared/transactions/payment_channel_claim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
components:
schemas:
PaymentChannelClaimTransaction:
$id: PaymentChannelClaimTransaction
allOf:
- $ref: '../base.yaml#/components/schemas/BaseTransaction'
type: object
description: |
Claim XRP from a payment channel, adjust the payment channel's expiration, or both.
This transaction can be used differently depending on the transaction sender's role in the specified channel:
The source address of a channel can:
- Send XRP from the channel to the destination with or without a signed Claim.
- Set the channel to expire as soon as the channel's SettleDelay has passed.
- Clear a pending Expiration time.
- Close a channel immediately, with or without processing a claim first. The source address cannot close the channel immediately if the channel has XRP remaining.
The destination address of a channel can:
- Receive XRP from the channel using a signed Claim.
- Close the channel immediately after processing a Claim, refunding any unclaimed XRP to the channel's source.
Any address sending this transaction can:
- Cause a channel to be closed if its Expiration or CancelAfter time is older than the previous ledger's close time. Any validly-formed PaymentChannelClaim transaction has this effect regardless of the contents of the transaction.
required:
- Channel
properties:
Amount:
type: string
description: |
(Optional) The amount of XRP, in drops, authorized by the Signature. This must match the amount in the signed message. This is the cumulative amount of XRP that can be dispensed by the channel, including XRP previously redeemed.
Balance:
type: string
description: |
(Optional) Total amount of XRP, in drops, delivered by this channel after processing this claim. Required to deliver XRP. Must be more than the total amount delivered by the channel so far, but not greater than the Amount of the signed claim. Must be provided except when closing the channel.
Channel:
type: string
description: |
The unique ID of the channel, as a 64-character hexadecimal string.
CredentialIDs:
type: array
items:
type: string
description: |
(Optional) Set of Credentials to authorize a deposit made by this transaction. Each member of the array must be the ledger entry ID of a Credential entry in the ledger.
PublicKey:
type: string
description: |
(Optional) The public key used for the signature, as hexadecimal. This must match the PublicKey stored in the ledger for the channel. Required unless the sender of the transaction is the source address of the channel and the Signature field is omitted.
Signature:
type: string
description: |
(Optional) The signature of this claim, as hexadecimal. The signed message contains the channel ID and the amount of the claim. Required unless the sender of the transaction is the source address of the channel.
Flags:
type: integer
format: uint32
description: |
Flags modifying the behavior of the transaction. See PaymentChannelClaimFlag for details.
x-custom-validation:
validCredentials:
field: CredentialIDs
PaymentChannelClaimFlag:
$id: PaymentChannelClaimFlag
type: string
enum:
- tfRenew: 0x00010000
- tfClose: 0x00020000
description: Enum representing flags for PaymentChannelClaim transactions.
x-enum-descriptions:
tfRenew: Clear the channel's Expiration time. Only the source address of the payment channel can use this flag.
tfClose: Request to close the channel. Only the channel source and destination addresses can use this flag. This flag closes the channel immediately if it has no more XRP allocated after processing the current claim, or if the destination address uses it. If the source address uses this flag when the channel still holds XRP, this schedules the channel to close after SettleDelay seconds have passed.
64 changes: 64 additions & 0 deletions shared/transactions/payment_channel_create.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
components:
schemas:
PaymentChannelCreateTransaction:
$id: PaymentChannelCreateTransaction
allOf:
- $ref: '../base.yaml#/components/schemas/BaseTransaction'
type: object
description: |
Create a payment channel and fund it with XRP. The address sending this transaction becomes
the "source address" of the payment channel.
required:
- Amount
- Destination
- SettleDelay
- PublicKey
properties:
Amount:
type: string
description: |
Amount of XRP, in drops, to deduct from the sender's balance and set aside in this channel.
While the channel is open, the XRP can only go to the Destination address. When the channel closes,
any unclaimed XRP is returned to the source address's balance.
Destination:
type: string
description: |
Address to receive XRP claims against this channel. This is also known as the "destination address"
for the channel. Cannot be the same as the sender (Account).
SettleDelay:
type: integer
format: uint32
description: |
Amount of time the source address must wait before closing the channel if it has unclaimed XRP.
PublicKey:
type: string
description: |
The 33-byte public key of the key pair the source will use to sign claims against this channel,
in hexadecimal. This can be any secp256k1 or Ed25519 public key.
CancelAfter:
type: integer
format: uint32
description: |
(Optional) The time, in seconds since the Ripple Epoch, when this channel expires. Any transaction
that would modify the channel after this time closes the channel without otherwise affecting it.
This value is immutable; the channel can be closed earlier than this time but cannot remain open
after this time.
DestinationTag:
type: integer
format: uint32
description: |
(Optional) Arbitrary tag to further specify the destination for this payment channel, such as a
hosted recipient at the destination address.
x-custom-validation:
notEqual:
- field: Destination
toField: Account
message: 'Destination cannot be the same as the sender.'
PaymentChannelCreateErrorCode:
$id: PaymentChannelCreateErrorCode
type: string
enum:
- tecNO_PERMISSION
description: Enum representing possible error codes for PaymentChannelCreate transactions.
x-enum-descriptions:
tecNO_PERMISSION: The Destination account is blocking incoming payment channels.
56 changes: 56 additions & 0 deletions shared/transactions/payment_channel_fund.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
components:
schemas:
PaymentChannelFundTransaction:
$id: PaymentChannelFundTransaction
allOf:
- $ref: '../base.yaml#/components/schemas/BaseTransaction'
type: object
description: |
Add additional XRP to an open payment channel, and optionally update the expiration time of the channel.
Only the source address of the channel can use this transaction.
required:
- Channel
- Amount
properties:
Channel:
type: string
description: |
The unique ID of the channel to fund, as a 64-character hexadecimal string.
Amount:
type: string
description: |
Amount of XRP, in drops, to add to the channel. Must be a positive amount of XRP.
Expiration:
type: integer
format: uint32
description: |
(Optional) New Expiration time to set for the channel, in seconds since the Ripple Epoch.
This must be later than either the current time plus the SettleDelay of the channel, or the
existing Expiration of the channel. After the Expiration time, any transaction that would access
the channel closes the channel without taking its normal action. Any unspent XRP is returned to
the source address when the channel closes.
x-custom-validation:
greaterThan:
- field: Amount
value: 0
message: 'Amount must be a positive number.'
PaymentChannelFundErrorCode:
$id: PaymentChannelFundErrorCode
type: string
enum:
- tecINSUFFICIENT_RESERVE
- tecNO_DST
- tecNO_ENTRY
- tecNO_PERMISSION
- tecUNFUNDED
- temBAD_AMOUNT
- temBAD_EXPIRATION
description: Enum representing possible error codes for PaymentChannelFund transactions.
x-enum-descriptions:
tecINSUFFICIENT_RESERVE: The sending account has less XRP than the reserve requirement.
tecNO_DST: The destination account of the channel has been deleted. This is only possible if the payment channel was created before the fixPayChanRecipientOwnerDir amendment became enabled (on 2020-05-01).
tecNO_ENTRY: The Payment Channel identified by the Channel field does not exist.
tecNO_PERMISSION: The sender of the transaction is not the source address for the channel.
tecUNFUNDED: The sending account does not have enough XRP to fund the channel with the requested amount and still meet the reserve requirement.
temBAD_AMOUNT: The Amount field of the transaction is invalid. The amount must be XRP and it cannot be zero or negative.
temBAD_EXPIRATION: The Expiration field is invalid.

0 comments on commit c50e688

Please sign in to comment.