Documentation ¶
Index ¶
- Variables
- func DiscoverFactoryAddress(chainID int64) (common.Address, bool)
- func RecoverCheque(cheque *SignedCheque, chaindID int64) (common.Address, error)
- type Backend
- type CashChequeResult
- type CashoutService
- type CashoutStatus
- type Cheque
- type ChequeSigner
- type ChequeStore
- type ERC20Binding
- type ERC20BindingFunc
- type Factory
- type RecoverChequeFunc
- type SendChequeFunc
- type Service
- type SignedCheque
- type SimpleSwapBinding
- type SimpleSwapBindingFunc
- type SimpleSwapFactoryBinding
- type SimpleSwapFactoryBindingFunc
- type TransactionService
- type TxRequest
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOutOfFunds is the error when the chequebook has not enough free funds for a cheque ErrOutOfFunds = errors.New("chequebook out of funds") // ErrInsufficientFunds is the error when the chequebook has not enough free funds for a user action ErrInsufficientFunds = errors.New("insufficient token balance") )
var ( // ErrNoCheque is the error returned if there is no prior cheque for a chequebook or beneficiary. ErrNoCheque = errors.New("no cheque") // ErrChequeNotIncreasing is the error returned if the cheque amount is the same or lower. ErrChequeNotIncreasing = errors.New("cheque cumulativePayout is not increasing") // ErrChequeInvalid is the error returned if the cheque itself is invalid. ErrChequeInvalid = errors.New("invalid cheque") // ErrWrongBeneficiary is the error returned if the cheque has the wrong beneficiary. ErrWrongBeneficiary = errors.New("wrong beneficiary") // ErrBouncingCheque is the error returned if the chequebook is demonstrably illiquid. ErrBouncingCheque = errors.New("bouncing cheque") )
var ( ErrInvalidFactory = errors.New("not a valid factory contract") ErrNotDeployedByFactory = errors.New("chequebook not deployed by factory") )
var ChequeTypes = eip712.Types{ "EIP712Domain": eip712.EIP712DomainType, "Cheque": []eip712.Type{ { Name: "chequebook", Type: "address", }, { Name: "beneficiary", Type: "address", }, { Name: "cumulativePayout", Type: "uint256", }, }, }
ChequeTypes are the needed type descriptions for cheque signing
var ( // ErrNoCashout is the error if there has not been any cashout action for the chequebook ErrNoCashout = errors.New("no prior cashout") )
var (
ErrTransactionReverted = errors.New("transaction reverted")
)
Functions ¶
func DiscoverFactoryAddress ¶
DiscoverFactoryAddress returns the canonical factory for this chainID
func RecoverCheque ¶
func RecoverCheque(cheque *SignedCheque, chaindID int64) (common.Address, error)
RecoverCheque recovers the issuer ethereum address from a signed cheque
Types ¶
type Backend ¶
type Backend interface { bind.ContractBackend TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error) }
Backend is the minimum of blockchain backend functions we need.
type CashChequeResult ¶
type CashChequeResult struct { Beneficiary common.Address // beneficiary of the cheque Recipient common.Address // address which received the funds Caller common.Address // caller of cashCheque TotalPayout *big.Int // total amount that was paid out in this call CumulativePayout *big.Int // cumulative payout of the cheque that was cashed CallerPayout *big.Int // payout for the caller of cashCheque Bounced bool // indicates wether parts of the cheque bounced }
CashChequeResult summarizes the result of a CashCheque or CashChequeBeneficiary call
func (*CashChequeResult) Equal ¶
func (r *CashChequeResult) Equal(o *CashChequeResult) bool
Equal compares to CashChequeResults
type CashoutService ¶
type CashoutService interface { // CashCheque sends a cashing transaction for the last cheque of the chequebook CashCheque(ctx context.Context, chequebook common.Address, recipient common.Address) (common.Hash, error) // CashoutStatus gets the status of the latest cashout transaction for the chequebook CashoutStatus(ctx context.Context, chequebookAddress common.Address) (*CashoutStatus, error) }
CashoutService is the service responsible for managing cashout actions
func NewCashoutService ¶
func NewCashoutService( store storage.StateStorer, simpleSwapBindingFunc SimpleSwapBindingFunc, backend Backend, transactionService TransactionService, chequeStore ChequeStore, ) (CashoutService, error)
NewCashoutService creates a new CashoutService
type CashoutStatus ¶
type CashoutStatus struct { TxHash common.Hash Cheque SignedCheque // the cheque that was used to cashout which may be different from the latest cheque Result *CashChequeResult Reverted bool }
CashoutStatus is the action plus its result
type Cheque ¶
type Cheque struct { Chequebook common.Address Beneficiary common.Address CumulativePayout *big.Int }
Cheque represents a cheque for a SimpleSwap chequebook
type ChequeSigner ¶
ChequeSigner signs cheque
func NewChequeSigner ¶
func NewChequeSigner(signer crypto.Signer, chainID int64) ChequeSigner
NewChequeSigner creates a new cheque signer for the given chainID.
type ChequeStore ¶
type ChequeStore interface { // ReceiveCheque verifies and stores a cheque. It returns the totam amount earned. ReceiveCheque(ctx context.Context, cheque *SignedCheque) (*big.Int, error) // LastCheque returns the last cheque we received from a specific chequebook. LastCheque(chequebook common.Address) (*SignedCheque, error) // LastCheques returns the last received cheques from every known chequebook. LastCheques() (map[common.Address]*SignedCheque, error) }
ChequeStore handles the verification and storage of received cheques
func NewChequeStore ¶
func NewChequeStore( store storage.StateStorer, backend Backend, factory Factory, chainID int64, beneficiary common.Address, simpleSwapBindingFunc SimpleSwapBindingFunc, recoverChequeFunc RecoverChequeFunc) ChequeStore
NewChequeStore creates new ChequeStore
type ERC20Binding ¶
ERC20Binding is the interface for the generated go bindings for ERC20
func NewERC20Bindings ¶
func NewERC20Bindings(address common.Address, backend bind.ContractBackend) (ERC20Binding, error)
NewERC20Bindings generates the default go bindings
type ERC20BindingFunc ¶
type ERC20BindingFunc = func(common.Address, bind.ContractBackend) (ERC20Binding, error)
type Factory ¶
type Factory interface { // ERC20Address returns the token for which this factory deploys chequebooks. ERC20Address(ctx context.Context) (common.Address, error) // Deploy deploys a new chequebook and returns once the transaction has been submitted. Deploy(ctx context.Context, issuer common.Address, defaultHardDepositTimeoutDuration *big.Int) (common.Hash, error) // WaitDeployed waits for the deployment transaction to confirm and returns the chequebook address WaitDeployed(ctx context.Context, txHash common.Hash) (common.Address, error) // VerifyBytecode checks that the factory is valid. VerifyBytecode(ctx context.Context) error // VerifyChequebook checks that the supplied chequebook has been deployed by this factory. VerifyChequebook(ctx context.Context, chequebook common.Address) error }
Factory is the main interface for interacting with the chequebook factory.
func NewFactory ¶
func NewFactory(backend Backend, transactionService TransactionService, address common.Address, simpleSwapFactoryBindingFunc SimpleSwapFactoryBindingFunc) (Factory, error)
NewFactory creates a new factory service for the provided factory contract.
type RecoverChequeFunc ¶
type RecoverChequeFunc func(cheque *SignedCheque, chainID int64) (common.Address, error)
type SendChequeFunc ¶
type SendChequeFunc func(cheque *SignedCheque) error
SendChequeFunc is a function to send cheques.
type Service ¶
type Service interface { // Deposit starts depositing erc20 token into the chequebook. This returns once the transactions has been broadcast. Deposit(ctx context.Context, amount *big.Int) (hash common.Hash, err error) // Withdraw starts withdrawing erc20 token from the chequebook. This returns once the transactions has been broadcast. Withdraw(ctx context.Context, amount *big.Int) (hash common.Hash, err error) // WaitForDeposit waits for the deposit transaction to confirm and verifies the result. WaitForDeposit(ctx context.Context, txHash common.Hash) error // Balance returns the token balance of the chequebook. Balance(ctx context.Context) (*big.Int, error) // AvailableBalance returns the token balance of the chequebook which is not yet used for uncashed cheques. AvailableBalance(ctx context.Context) (*big.Int, error) // Address returns the address of the used chequebook contract. Address() common.Address // Issue a new cheque for the beneficiary with an cumulativePayout amount higher than the last. Issue(ctx context.Context, beneficiary common.Address, amount *big.Int, sendChequeFunc SendChequeFunc) error // LastCheque returns the last cheque we issued for the beneficiary. LastCheque(beneficiary common.Address) (*SignedCheque, error) // LastCheque returns the last cheques for all beneficiaries. LastCheques() (map[common.Address]*SignedCheque, error) }
Service is the main interface for interacting with the nodes chequebook.
func Init ¶
func Init( ctx context.Context, chequebookFactory Factory, stateStore storage.StateStorer, logger logging.Logger, swapInitialDeposit uint64, transactionService TransactionService, swapBackend Backend, chainId int64, overlayEthAddress common.Address, chequeSigner ChequeSigner, simpleSwapBindingFunc SimpleSwapBindingFunc, erc20BindingFunc ERC20BindingFunc) (chequebookService Service, err error)
Init initialises the chequebook service.
func New ¶
func New(backend Backend, transactionService TransactionService, address, erc20Address, ownerAddress common.Address, store storage.StateStorer, chequeSigner ChequeSigner, simpleSwapBindingFunc SimpleSwapBindingFunc, erc20BindingFunc ERC20BindingFunc) (Service, error)
New creates a new chequebook service for the provided chequebook contract.
type SignedCheque ¶
SignedCheque represents a cheque together with its signature
func (*SignedCheque) Equal ¶
func (cheque *SignedCheque) Equal(other *SignedCheque) bool
type SimpleSwapBinding ¶
type SimpleSwapBinding interface { Balance(*bind.CallOpts) (*big.Int, error) Issuer(*bind.CallOpts) (common.Address, error) TotalPaidOut(*bind.CallOpts) (*big.Int, error) PaidOut(*bind.CallOpts, common.Address) (*big.Int, error) ParseChequeCashed(types.Log) (*simpleswapfactory.ERC20SimpleSwapChequeCashed, error) ParseChequeBounced(types.Log) (*simpleswapfactory.ERC20SimpleSwapChequeBounced, error) }
SimpleSwapBinding is the interface for the generated go bindings for ERC20SimpleSwap
func NewSimpleSwapBindings ¶
func NewSimpleSwapBindings(address common.Address, backend bind.ContractBackend) (SimpleSwapBinding, error)
NewSimpleSwapBindings generates the default go bindings
type SimpleSwapBindingFunc ¶
type SimpleSwapBindingFunc = func(common.Address, bind.ContractBackend) (SimpleSwapBinding, error)
type SimpleSwapFactoryBinding ¶
type SimpleSwapFactoryBinding interface { ParseSimpleSwapDeployed(types.Log) (*simpleswapfactory.SimpleSwapFactorySimpleSwapDeployed, error) DeployedContracts(*bind.CallOpts, common.Address) (bool, error) ERC20Address(*bind.CallOpts) (common.Address, error) }
SimpleSwapFactoryBinding is the interface for the generated go bindings for SimpleSwapFactory
func NewSimpleSwapFactoryBindingFunc ¶
func NewSimpleSwapFactoryBindingFunc(address common.Address, backend bind.ContractBackend) (SimpleSwapFactoryBinding, error)
NewSimpleSwapFactoryBindingFunc generates the default go bindings
type SimpleSwapFactoryBindingFunc ¶
type SimpleSwapFactoryBindingFunc = func(common.Address, bind.ContractBackend) (SimpleSwapFactoryBinding, error)
type TransactionService ¶
type TransactionService interface { // Send creates a transaction based on the request and sends it. Send(ctx context.Context, request *TxRequest) (txHash common.Hash, err error) // WaitForReceipt waits until either the transaction with the given hash has been mined or the context is cancelled. WaitForReceipt(ctx context.Context, txHash common.Hash) (receipt *types.Receipt, err error) }
TransactionService is the service to send transactions. It takes care of gas price, gas limit and nonce management.
func NewTransactionService ¶
func NewTransactionService(logger logging.Logger, backend Backend, signer crypto.Signer) (TransactionService, error)
NewTransactionService creates a new transaction service.
type TxRequest ¶
type TxRequest struct { To common.Address // recipient of the transaction Data []byte // transaction data GasPrice *big.Int // gas price or nil if suggested gas price should be used GasLimit uint64 // gas limit or 0 if it should be estimated Value *big.Int // amount of wei to send }
TxRequest describes a request for a transaction that can be executed.