# ConsumerHost
# Overview
The ConsumerHost contract store and track all registered Consumers. Consumer can deposit and withdraw SQT. Consumer can approve contract, and then don't have to sign for every payment. Other contracts can verify the consumer and safeTransfer SQT.
# Consumer
struct Consumer {
uint256 balance;
uint256 nonce;
bool approved;
}
# STATES
# settings
contract ISettings settings
# signers
The Signer account address
address[] signers
# signerIndex
mapping(address => uint256) signerIndex
# fee
The fee charged from consumer payment service
uint256 fee
# feePercentage
The Percentage of FEE
uint256 feePercentage
# consumers
Consumers info that hosting in this contract
mapping(address => struct ConsumerHost.Consumer) consumers
# channels
StateChannels' belongs to consumer
mapping(uint256 => address) channels
# controllers
controller account belongs to consumer
mapping(address => address) controllers
# EVENTS
# Approve
Emitted when consumer approve host to manager the balance.
event Approve(address consumer)
# Disapprove
Emitted when consumer disapprove.
event Disapprove(address consumer)
# Deposit
Emitted when consumer deposit.
event Deposit(address consumer, uint256 amount, uint256 balance)
# Withdraw
Emitted when consumer withdraw.
event Withdraw(address consumer, uint256 amount, uint256 balance)
# Paid
Emitted when consumer pay for open a state channel
event Paid(uint256 channelId, address consumer, address caller, uint256 amount, uint256 balance, uint256 fee)
# Claimed
Emitted when consumer pay for open a state channel
event Claimed(uint256 channelId, address consumer, address caller, uint256 amount, uint256 balance)
# SetControllerAccount
Emitted when consumer set the controller account.
event SetControllerAccount(address consumer, address controller)
# RemoveControllerAccount
Emitted when consumer remove the controller account.
event RemoveControllerAccount(address consumer, address controller)
# FUNCTIONS
# initialize
Initialize the contract, setup the SQT, StateChannel, and feePercentage.
function initialize(contract ISettings _settings, address _sqt, address _channel, uint256 _feePercentage) external
Name | Type | Description |
---|---|---|
_settings | contract ISettings | Settings contract address |
_sqt | address | |
_channel | address | |
_feePercentage | uint256 | fee percentage |
# setSettings
Update setting state.
function setSettings(contract ISettings _settings) external
Name | Type | Description |
---|---|---|
_settings | contract ISettings | ISettings contract |
# setFeePercentage
Update fee percentage
function setFeePercentage(uint256 _feePercentage) external
Name | Type | Description |
---|---|---|
_feePercentage | uint256 | fee percentage |
# setControllerAccount
consumer call to set the controller account, since consumer only allowed to set one controller account, we need to remove the previous controller account.
function setControllerAccount(address controller) external
Name | Type | Description |
---|---|---|
controller | address | The address of controller account, consumer to set |
# removeControllerAccount
consumer call to remove the controller account.
function removeControllerAccount() public
# collectFee
Collect fee to account
function collectFee(address account, uint256 amount) external
Name | Type | Description |
---|---|---|
account | address | the receiver |
amount | uint256 | the amount |
# getSigners
Get contract signer
function getSigners() external view returns (address[])
Return: address[] -> the signer account
# addSigner
Update contract signer
function addSigner(address _signer) external
Name | Type | Description |
---|---|---|
_signer | address | new signer account |
# removeSigner
Update contract signer
function removeSigner(address _signer) external
Name | Type | Description |
---|---|---|
_signer | address | new signer account |
# isSigner
check sender is signer
function isSigner(address signer) external view returns (bool)
Name | Type | Description |
---|---|---|
signer | address | the checked address |
# approve
Approve host can use consumer balance
function approve() external
# disapprove
Disapprove host can use consumer balance
function disapprove() external
# deposit
Deposit amount to hosting, consumer can choose approve or not
function deposit(uint256 amount, bool isApprove) external
Name | Type | Description |
---|---|---|
amount | uint256 | the amount |
isApprove | bool |
# withdraw
Withdraw amount to the consumer(sender)
function withdraw(uint256 amount) external
Name | Type | Description |
---|---|---|
amount | uint256 | the amount |
# paid
Paied callback function, only support from StateChannel
function paid(uint256 channelId, address sender, uint256 amount, bytes callback) external
Name | Type | Description |
---|---|---|
channelId | uint256 | the opened channel ID |
sender | address | |
amount | uint256 | the amount need to pay |
callback | bytes | the info include consumer and signature(if approve, no signature)) |
# claimed
Claimed callback function, only support from StateChannel
function claimed(uint256 channelId, uint256 amount) external
Name | Type | Description |
---|---|---|
channelId | uint256 | the finalized channel ID |
amount | uint256 | the amount back to consumer |
# checkSign
check the signature from signer or valid consumer
function checkSign(uint256 channelId, bytes32 payload, bytes sign) external view returns (bool)
Name | Type | Description |
---|---|---|
channelId | uint256 | the finalized channel ID |
payload | bytes32 | the message signed by sender |
sign | bytes | the signature |
Return: bool -> Result of check
# checkSender
check the sender is from signer or valid consumer
function checkSender(uint256 channelId, address sender) external view returns (bool)
Name | Type | Description |
---|---|---|
channelId | uint256 | the finalized channel ID |
sender | address | the sender need to check |
Return: bool -> Result of check
# channelConsumer
return the consumer of a channel
function channelConsumer(uint256 channelId) external view returns (address)
Name | Type | Description |
---|---|---|
channelId | uint256 | the finalized channel ID |
Return: address -> Result of addresses
# supportsInterface
Check ERC165 interface
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool)
Name | Type | Description |
---|---|---|
interfaceId | bytes4 | interface ID |
Return: bool -> Result of support or not