Documentation ¶
Index ¶
- Variables
- func FundingKey(id channel.ID, addr wallet.Address) string
- func IDKey(id channel.ID) string
- func IsAdjudicatorError(err error) bool
- func IsNotFoundError(err error) bool
- func SetNewTimestamp(newts func() Timestamp)
- func ValidateChannel(ch *SignedChannel) error
- func VerifySig(signer wallet.Address, state State, sig wallet.Sig) (bool, error)
- type AccountID
- type Adjudicator
- func (a *Adjudicator) BalanceOfID(id AccountID) (*big.Int, error)
- func (a *Adjudicator) Burn(callee AccountID, amount *big.Int) error
- func (a *Adjudicator) Deposit(callee AccountID, chID channel.ID, part wallet.Address, amount *big.Int) error
- func (a *Adjudicator) Holding(id channel.ID, part wallet.Address) (*big.Int, error)
- func (a *Adjudicator) Mint(callee AccountID, amount *big.Int) error
- func (a *Adjudicator) Register(ch *SignedChannel) error
- func (a *Adjudicator) StateReg(id channel.ID) (*StateReg, error)
- func (a *Adjudicator) TotalHolding(id channel.ID, parts []wallet.Address) (*big.Int, error)
- func (a *Adjudicator) Transfer(sender AccountID, receiver AccountID, amount *big.Int) error
- func (a *Adjudicator) Withdraw(swr SignedWithdrawReq) (*big.Int, error)
- type Asset
- type AssetHolder
- func (a *AssetHolder) Deposit(id channel.ID, part wallet.Address, amount *big.Int) error
- func (a *AssetHolder) Holding(id channel.ID, part wallet.Address) (*big.Int, error)
- func (a *AssetHolder) SetHolding(id channel.ID, part wallet.Address, holding *big.Int) error
- func (a *AssetHolder) TotalHolding(id channel.ID, parts []wallet.Address) (*big.Int, error)
- func (a *AssetHolder) Withdraw(id channel.ID, part wallet.Address) (*big.Int, error)
- type ChallengeTimeoutError
- type HoldingLedger
- type Ledger
- type MemAsset
- type MemLedger
- func (m *MemLedger) GetHolding(id channel.ID, addr wallet.Address) (*big.Int, error)
- func (m *MemLedger) GetState(id channel.ID) (*StateReg, error)
- func (m *MemLedger) Now() Timestamp
- func (m *MemLedger) PutHolding(id channel.ID, addr wallet.Address, holding *big.Int) error
- func (m *MemLedger) PutState(s *StateReg) error
- type NotFoundError
- type Params
- type SignedChannel
- type SignedWithdrawReq
- type State
- type StateLedger
- type StateReg
- type Timestamp
- func (t Timestamp) Add(d uint64) Timestamp
- func (t Timestamp) After(other Timestamp) bool
- func (t Timestamp) Before(other Timestamp) bool
- func (t Timestamp) Clone() Timestamp
- func (t Timestamp) Equal(other Timestamp) bool
- func (t Timestamp) MarshalJSON() ([]byte, error)
- func (t Timestamp) Time() time.Time
- func (t *Timestamp) UnmarshalJSON(data []byte) error
- type UnderfundedError
- type ValidationError
- type VersionError
- type WithdrawReq
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownChannel = errors.New("unknown channel")
ErrUnknownChannel indicates that no information for a channel id could be found by the chaincode.
Functions ¶
func FundingKey ¶
FundingKey creates the key used for storing a funding amount in the holdings map.
func IsAdjudicatorError ¶
IsAdjudicatorError returns true if the given error is one of the following: ValidationError, ChallengeTimeoutError, VersionError, UnderfundedError.
func IsNotFoundError ¶
IsNotFoundError returns true if given err is a NotFoundError.
func SetNewTimestamp ¶
func SetNewTimestamp(newts func() Timestamp)
SetNewTimestamp sets the Timestamp factory used during json unmarshaling of structs containing a Timestamp, e.g., StateRegs.
It is set to return Timestamp instances by default.
func ValidateChannel ¶
func ValidateChannel(ch *SignedChannel) error
ValidateChannel checks if the given parameters in SignedChannel are in itself consistent.
Types ¶
type AccountID ¶
type AccountID string
AccountID represents the ID of a client. It is used for minting, burning, receiving and sending funds. Ensure it is unique for every client interacting with Asset and no impersonation is possible.
type Adjudicator ¶
type Adjudicator struct {
// contains filtered or unexported fields
}
Adjudicator is an abstract implementation of the adjudicator smart contract.
func NewAdjudicator ¶
func NewAdjudicator(id string, ledger Ledger, asset Asset) *Adjudicator
NewAdjudicator generates a new Adjudicator with an identifier, holding ledger and asset ledger.
func (*Adjudicator) BalanceOfID ¶
func (a *Adjudicator) BalanceOfID(id AccountID) (*big.Int, error)
BalanceOfID returns the asset token balance of the given user identifier.
func (*Adjudicator) Burn ¶
func (a *Adjudicator) Burn(callee AccountID, amount *big.Int) error
Burn destroys the given amount of asset tokens for the callee.
func (*Adjudicator) Deposit ¶
func (a *Adjudicator) Deposit(callee AccountID, chID channel.ID, part wallet.Address, amount *big.Int) error
Deposit transfers the given amount of coins from the callee to the channel with the specified channel ID. The funds are stored in the channel under the participant's wallet address.
func (*Adjudicator) Holding ¶
Holding returns the current holding amount of the given participant in the channel.
func (*Adjudicator) Mint ¶
func (a *Adjudicator) Mint(callee AccountID, amount *big.Int) error
Mint generates the given amount of asset tokens for the callee.
func (*Adjudicator) Register ¶
func (a *Adjudicator) Register(ch *SignedChannel) error
Register verifies the given SignedChannel, updates the holdings and saves a new StateReg.
func (*Adjudicator) StateReg ¶
func (a *Adjudicator) StateReg(id channel.ID) (*StateReg, error)
StateReg fetches the current state from the ledger and returns it. If no state is found under the given channel.ID an error is returned.
func (*Adjudicator) TotalHolding ¶
TotalHolding returns the sum of all participant holdings in the channel.
func (*Adjudicator) Transfer ¶
Transfer sends the given amount of asset tokens from the sender to the receiver.
func (*Adjudicator) Withdraw ¶
func (a *Adjudicator) Withdraw(swr SignedWithdrawReq) (*big.Int, error)
Withdraw withdraws all funds of participant Part in the finalized channel id to the given Receiver. It returns the withdrawn amount.
type Asset ¶
type Asset interface { // Mint creates the desired amount of token for the given id. // Note that id must be authenticated first. Mint(id AccountID, amount *big.Int) error // Burn removes the desired amount of token from the given id. // Note that id must be authenticated first. Burn(id AccountID, amount *big.Int) error // Transfer sends the desired amount of tokens from sender to receiver. // Note that sender must be authenticated first. Transfer(sender AccountID, receiver AccountID, amount *big.Int) error // BalanceOf returns the amount of tokens the given id holds. BalanceOf(id AccountID) (*big.Int, error) }
Asset is a basic interface for creating tokens with.
type AssetHolder ¶
type AssetHolder struct {
// contains filtered or unexported fields
}
AssetHolder tracks deposits and withdrawals of channel participants over a HoldingLedger.
func NewAssetHolder ¶
func NewAssetHolder(ledger HoldingLedger) *AssetHolder
NewAssetHolder returns a new AssetHolder operating on the given ledger.
func (*AssetHolder) Deposit ¶
Deposit registers a deposit for channel `id` and participant `part` of amount `amount`, possibly adding to an already existent deposit.
Deposit throws an error if `amount` is negative.
Ledger access errors are propagated.
func (*AssetHolder) Holding ¶
Holding returns the holdings of participant `part` in the channel of id `id`.
func (*AssetHolder) SetHolding ¶
SetHolding sets the holding of part in channel id to holding.
Panics if `holding` is negative.
func (*AssetHolder) TotalHolding ¶
TotalHolding returns the total amount deposited into the channel specified by `params`.
type ChallengeTimeoutError ¶
ChallengeTimeoutError indicates that the challenge timeout passed.
func (ChallengeTimeoutError) Error ¶
func (te ChallengeTimeoutError) Error() string
type HoldingLedger ¶
type HoldingLedger interface { GetHolding(channel.ID, wallet.Address) (*big.Int, error) //nolint:forbidigo PutHolding(channel.ID, wallet.Address, *big.Int) error }
HoldingLedger stores the channel's holdings.
type Ledger ¶
type Ledger interface { StateLedger HoldingLedger Now() Timestamp }
Ledger contains the read and write operations required by the Adjudicator.
type MemAsset ¶
type MemAsset struct {
// contains filtered or unexported fields
}
MemAsset is an in-memory asset for testing. As it is for testing there is no central banker.
func (MemAsset) BalanceOf ¶
BalanceOf returns the amount of tokens the given id holds. If the id is unknown, zero is returned.
type MemLedger ¶
type MemLedger struct {
// contains filtered or unexported fields
}
MemLedger is a simple in-memory ledger, using Go maps. time.Time is used as Timestamps.
func NewMemLedger ¶
func NewMemLedger() *MemLedger
NewMemLedger generates a new local in-memory ledger for testing purposes.
func (*MemLedger) GetHolding ¶
GetHolding retrieves the current channel holding of the given address.
func (*MemLedger) PutHolding ¶
PutHolding overwrites the current address channel holdings with the given holding.
type NotFoundError ¶
NotFoundError should be returned by getters of Ledger implementations if there's no entry under a given key.
func (*NotFoundError) Error ¶
func (err *NotFoundError) Error() string
type Params ¶
type Params struct { ChallengeDuration uint64 `json:"challengeDuration"` Parts []wallet.Address `json:"parts"` Nonce channel.Nonce `json:"nonce"` }
Params are the parameters of a state channel.
func (Params) CoreParams ¶
CoreParams returns the equivalent representation of p as channel.Params. The returned Params is set to have no App, LedgerChannel is set to true and VirtualChannel is set to false.
It is not a deep copy, e.g., field Parts references the same participants.
func (*Params) UnmarshalJSON ¶
UnmarshalJSON implements custom unmarshalling for Params.
type SignedChannel ¶
type SignedChannel struct { Params Params `json:"params"` State State `json:"state"` Sigs []wallet.Sig `json:"sigs"` }
SignedChannel contains signatures on Params and State and is used for registering new states.
func ConvertToSignedChannel ¶
func ConvertToSignedChannel(req channel.AdjudicatorReq) (*SignedChannel, error)
ConvertToSignedChannel takes a AdjudicatorReq and generates a SignedChannel from it.
func SignChannel ¶
SignChannel creates signatures on the provided channel state for each provided account. The signatures are in the same order as the accounts.
func (*SignedChannel) Clone ¶
func (ch *SignedChannel) Clone() *SignedChannel
Clone duplicates a SignedChannel.
type SignedWithdrawReq ¶
type SignedWithdrawReq struct { Req WithdrawReq `json:"req"` Sig wallet.Sig `json:"sig"` }
SignedWithdrawReq contains a signature over a WithdrawReq to check its validity.
func SignWithdrawRequest ¶
func SignWithdrawRequest(acc wallet.Account, channel channel.ID, receiver AccountID) (*SignedWithdrawReq, error)
SignWithdrawRequest generates a WithdrawReq and signs it with the given account to return a SignedWithdrawReq.
type State ¶
type State struct { ID channel.ID `json:"id"` Version uint64 `json:"version"` Balances []channel.Bal `json:"balances"` IsFinal bool `json:"final"` }
State is a state of a state channel.
func (State) CoreState ¶
CoreState returns the equivalent representation of s as channel.State. The returned State is set to have no App, no Data, contains one asset that is default initialized and this first assets' balances are set to the Balances of s.
Use the State returned by CoreState to create or verify signatures with the go-perun channel backend.
It is not a deep copy, e.g., field Balances references the same balances slice.
type StateLedger ¶
type StateLedger interface { GetState(channel.ID) (*StateReg, error) //nolint:forbidigo PutState(*StateReg) error }
StateLedger stores the channel's state.
type StateReg ¶
StateReg adds a Timeout to the State to indicate the states challenge timeout.
func (*StateReg) IsFinalizedAt ¶
IsFinalizedAt checks if the registered state is final. This is the case if either the isFinal flag is true or the timeout passed.
type Timestamp ¶
A Timestamp is a point in time that can be compared to others.
func NewTimestamp ¶
func NewTimestamp() Timestamp
NewTimestamp returns new Timestamp instances used during json unmarshaling of structs containing a Timestamp, e.g., StateRegs.
It returns Timestamp instances by default.
func (Timestamp) After ¶
After evaluates if the given Timestamp is after the Timestamp it is being called on.
func (Timestamp) Before ¶
Before evaluates if the given Timestamp is before the Timestamp it is being called on.
func (Timestamp) MarshalJSON ¶
MarshalJSON marshals the Timestamp as time.Time.
func (*Timestamp) UnmarshalJSON ¶
UnmarshalJSON unmarshals the Timestamp as time.Time.
type UnderfundedError ¶
UnderfundedError indicates that the sum of the proposed balances are higher than the actual funding.
func (UnderfundedError) Error ¶
func (ue UnderfundedError) Error() string
type ValidationError ¶
type ValidationError struct {
// contains filtered or unexported fields
}
ValidationError indicates that the given arguments could not be validated successfully.
func (ValidationError) Unwrap ¶
func (ve ValidationError) Unwrap() error
type VersionError ¶
VersionError indicates that the chaincode holds a newer version of the proposed channel state.
func (VersionError) Error ¶
func (ve VersionError) Error() string
type WithdrawReq ¶
type WithdrawReq struct { ID channel.ID `json:"id"` Part wallet.Address `json:"part"` Receiver AccountID `json:"receiver"` }
WithdrawReq are parameters needed to withdraw funds from a state channel.
func (WithdrawReq) Decode ¶
func (wr WithdrawReq) Decode(r io.Reader) error
Decode decodes a withdraw request from an `io.Reader` or returns an `error`.
func (WithdrawReq) Encode ¶
func (wr WithdrawReq) Encode(w io.Writer) error
Encode encodes a withdraw request into an `io.Writer` or returns an `error`.
func (*WithdrawReq) MarshalJSON ¶
func (wr *WithdrawReq) MarshalJSON() ([]byte, error)
MarshalJSON implements custom marshalling for WithdrawReq to deal with custom data types.
func (WithdrawReq) Sign ¶
Sign signs a withdraw request with the given Account. Returns the signature or an error.
func (*WithdrawReq) UnmarshalJSON ¶
func (wr *WithdrawReq) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshalling for WithdrawReq to deal with custom data types.