Skip to content

matiascabello/scout-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Payment channel

Overview

This folder contains a Soroban smart contract example for a payment channel. A payment channel is a smart contract that acts as a mediator between a person who wants to make a payment and another who has to receive that payment, in order to provide more security when carrying out the transaction.

Contract Functions

Function Name Parameters Return Type Description
initialize
env: Env
sender: Address
recipient: Address
token: Address
allowance: i128
expiration: Option
Result<PaymentChannelState, PCError> Initializes a new payment channel with provided parameters.
close
env: Env
Result<(), PCError> Allows the recipient to close the channel and withdraw funds. Unclaimed funds will go back to the sender.
withdraw
env: Env
Result<(), PCError> Allows the recipient to withdraw funds incrementally from the channel.
set_expiration
env: Env
sequence: u32
Result<(), PCError> Sets the expiration timestamp of the channel.
claim_timeout
env: Env
Result<(), PCError> Allows the sender to claim funds if the channel has expired.
get_recipient_address
env: Env
Result<Address, PCError> Retrieves the recipient's address associated with the payment channel.
get_sender_address
env: Env
Result<Address, PCError> Retrieves the sender's address associated with the payment channel.
modify_allowance
env: Env
amount: i128
Result<(), PCError> Allows the sender to modify the permitted maximum amount to be withdrawn by the recipient (considering the sum of all partial extractions).
get_state
env: Env
Result<PaymentChannelState, PCError> Retrieves the current state of the payment channel.

Interacting with the Contract

  1. Initialization of Payment Channel: Use the initialize function to initialize a new payment channel by providing the required parameters, such as sender address, recipient address, close duration, and token address.

  2. Making an Initial Payment: Deposit funds into the payment channel by sending the desired amount to the contract.

  3. Partial Fund Withdrawal: Make partial withdrawals of funds using the withdraw function.

  4. Closing the Payment Channel: Close the channel and receive the remaining funds using the close() function and providing the desired amount.

Set Expiration: The sender can set an expiration time for the channel using the set_expiration() function if desired.

Claim Timeout: If the channel has expired and the funds have not been claimed, the sender can claim the remaining funds using the claim_timeout() function.

Security Review

👉 Navigate to this link to view the security review.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages