swap

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package swap wraps the 'swap' Ethereum smart contract. It is an abstraction layer to hide implementation details about the different Swap contract iterations (Simple Swap, Soft Swap, etc.)

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotDeployedByFactory is given when a contract was not deployed by the factory
	ErrNotDeployedByFactory = errors.New("not deployed by factory")

	// Deployments maps from network ids to deployed contract factories
	Deployments = map[uint64]common.Address{

		3: common.HexToAddress("0x2e9C43E186eaF4fee10799d67e75f8CFc5BA3a0c"),
	}
)
View Source
var (
	// ErrTransactionReverted is given when the transaction that cashes a cheque is reverted
	ErrTransactionReverted = errors.New("Transaction reverted")
)
View Source
var WaitFunc = waitForTx

WaitFunc is the default function to wait for transactions We can overwrite this in tests so that we don't need to wait for mining

Functions

func FactoryAddressForNetwork added in v0.5.3

func FactoryAddressForNetwork(networkID uint64) (common.Address, error)

FactoryAddressForNetwork gets the default factory address for a given network id

Types

type Backend

type Backend interface {
	bind.ContractBackend
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
}

Backend wraps all methods required for contract deployment.

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

type Contract

type Contract interface {
	// Withdraw attempts to withdraw Wei from the chequebook
	Withdraw(auth *bind.TransactOpts, backend Backend, amount *big.Int) (*types.Receipt, error)
	// Deposit sends a raw transaction to the chequebook, triggering the fallback—depositing amount
	Deposit(auth *bind.TransactOpts, backend Backend, amout *big.Int) (*types.Receipt, error)
	// CashChequeBeneficiary cashes the cheque by the beneficiary
	CashChequeBeneficiary(auth *bind.TransactOpts, beneficiary common.Address, cumulativePayout *big.Int, ownerSig []byte) (*CashChequeResult, *types.Receipt, error)
	// LiquidBalance returns the LiquidBalance (total balance in Wei - total hard deposits in Wei) of the chequebook
	LiquidBalance(auth *bind.CallOpts) (*big.Int, error)
	// ContractParams returns contract info (e.g. deployed address)
	ContractParams() *Params
	// Issuer returns the contract owner from the blockchain
	Issuer(opts *bind.CallOpts) (common.Address, error)
	// PaidOut returns the total paid out amount for the given address
	PaidOut(opts *bind.CallOpts, addr common.Address) (*big.Int, error)
}

Contract interface defines the methods exported from the underlying go-bindings for the smart contract

func Deploy

func Deploy(auth *bind.TransactOpts, backend Backend, owner common.Address, harddepositTimeout time.Duration) (Contract, *types.Transaction, error)

Deploy deploys an instance of the underlying contract and returns its instance and the transaction identifier

func InstanceAt

func InstanceAt(address common.Address, backend Backend) (Contract, error)

InstanceAt creates a new instance of a contract at a specific address. It assumes that there is an existing contract instance at the given address, or an error is returned This function is needed to communicate with remote Swap contracts (e.g. sending a cheque)

type Params

type Params struct {
	ContractCode    string
	ContractAbi     string
	ContractAddress common.Address
}

Params encapsulates some contract parameters (currently mostly informational)

type SimpleSwapFactory added in v0.5.3

type SimpleSwapFactory interface {
	// DeploySimpleSwap deploys a new SimpleSwap contract from the factory and returns the ready to use Contract abstraction
	DeploySimpleSwap(auth *bind.TransactOpts, issuer common.Address, defaultHardDepositTimeoutDuration *big.Int) (Contract, error)
	// VerifyContract verifies that the supplied address was deployed by this factory
	VerifyContract(address common.Address) error
	// VerifySelf verifies that this is a valid factory on the network
	VerifySelf() error
}

SimpleSwapFactory interface defines the methods available for a factory contract for SimpleSwap

func FactoryAt added in v0.5.3

func FactoryAt(address common.Address, backend Backend) (SimpleSwapFactory, error)

FactoryAt creates a SimpleSwapFactory instance for the given address and backend

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL