state

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0, MIT Imports: 12 Imported by: 0

Documentation

Overview

Package state defines the data structures which are signed by channel participants.

Index

Constants

This section is empty.

Variables

View Source
var TestOutcome = outcome.Exit{
	outcome.SingleAssetExit{
		Asset: types.Address{},
		AssetMetadata: outcome.AssetMetadata{
			AssetType: 0,
			Metadata:  make(types.Bytes, 0),
		},
		Allocations: outcome.Allocations{
			outcome.Allocation{
				Destination: types.AddressToDestination(common.HexToAddress(`0xF5A1BB5607C9D079E46d1B3Dc33f257d937b43BD`)),
				Amount:      big.NewInt(5),
			},
			outcome.Allocation{
				Destination: types.AddressToDestination(common.HexToAddress(`0xEe18fF1575055691009aa246aE608132C57a422c`)),
				Amount:      big.NewInt(5),
			},
		},
	},
}
View Source
var TestState = State{
	Participants: []types.Address{
		common.HexToAddress(`0xF5A1BB5607C9D079E46d1B3Dc33f257d937b43BD`),
		common.HexToAddress(`0x760bf27cd45036a6C486802D30B5D90CfFBE31FE`),
	},
	ChannelNonce:      37140676580,
	AppDefinition:     common.HexToAddress(`0x5e29E5Ab8EF33F050c7cc10B5a0456D975C5F88d`),
	ChallengeDuration: 60,
	AppData:           []byte{},
	Outcome:           TestOutcome,
	TurnNum:           5,
	IsFinal:           false,
}

Functions

This section is empty.

Types

type FixedPart

type FixedPart struct {
	Participants      []types.Address
	ChannelNonce      uint64
	AppDefinition     types.Address
	ChallengeDuration uint32
}

FixedPart contains the subset of State data which does not change during a state update.

func (FixedPart) ChannelId

func (fp FixedPart) ChannelId() types.Destination

func (FixedPart) Clone

func (f FixedPart) Clone() FixedPart

Clone returns a deep copy of the receiver.

func (FixedPart) Validate

func (fp FixedPart) Validate() error

Validate checks whether the receiver is malformed and returns an error if it is.

type Signature

type Signature = nc.Signature

func CloneSignature

func CloneSignature(s Signature) Signature

CloneSignature creates a deep copy of the provided signature.

type SignedState

type SignedState struct {
	// contains filtered or unexported fields
}

func NewSignedState

func NewSignedState(s State) SignedState

NewSignedState initializes a SignedState struct for the given The signedState returned will have no signatures.

func (SignedState) AddSignature

func (ss SignedState) AddSignature(sig Signature) error

AddSignature adds a participant's signature to the SignedState.

An error is returned if

  • the signer is not a participant, or
  • OR the signature was already stored

func (SignedState) ChannelId

func (ss SignedState) ChannelId() types.Destination

ChannelId returns the channel id of the state.

func (SignedState) Clone

func (ss SignedState) Clone() SignedState

Clone returns a deep copy of the receiver.

func (SignedState) GetParticipantSignature

func (ss SignedState) GetParticipantSignature(participantIndex uint) (crypto.Signature, error)

GetParticipantSignature returns the signature for the participant specified by participantIndex

func (SignedState) HasAllSignatures

func (ss SignedState) HasAllSignatures() bool

HasAllSignatures returns true if every participant has a valid signature.

func (SignedState) HasSignatureForParticipant

func (ss SignedState) HasSignatureForParticipant(participantIndex uint) bool

HasSignatureForParticipant returns true if the participant (at participantIndex) has a valid signature.

func (SignedState) MarshalJSON

func (ss SignedState) MarshalJSON() ([]byte, error)

MarshalJSON marshals the SignedState into JSON, implementing the Marshaler interface.

func (SignedState) Merge

func (ss SignedState) Merge(ss2 SignedState) error

Merge checks the passed SignedState's state and the receiver's state for equality, and adds each signature from the former to the latter.

func (SignedState) Signatures

func (ss SignedState) Signatures() []Signature

Signatures returns a slice of the signatures stored in the SignedState. There will be one signature per participant, in order of channel's Participants. Returned signatures are expected either to be valid or zero-valued.

func (SignedState) SortInfo

func (ss SignedState) SortInfo() (types.Destination, uint64)

SortInfo returns the channel id and turn number of the state, so the state can be easily sorted.

func (SignedState) State

func (ss SignedState) State() State

State returns the State part of the SignedState.

func (*SignedState) UnmarshalJSON

func (ss *SignedState) UnmarshalJSON(j []byte) error

UnmarshalJSON unmarshals the passed JSON into a SignedState, implementing the Unmarshaler interface.

type State

type State struct {
	Participants      []types.Address
	ChannelNonce      uint64
	AppDefinition     types.Address
	ChallengeDuration uint32
	AppData           types.Bytes
	Outcome           outcome.Exit
	TurnNum           uint64
	IsFinal           bool
}

State holds all of the data describing the state of a channel

func StateFromFixedAndVariablePart

func StateFromFixedAndVariablePart(f FixedPart, v VariablePart) State

StateFromFixedAndVariablePart constructs a State from a FixedPart and a VariablePart

func (State) ChannelId

func (s State) ChannelId() types.Destination

ChannelId computes and returns the channel id corresponding to the State, and an error if the id is an external destination.

Up to hash collisions, ChannelId distinguishes channels that have different FixedPart values

func (State) Clone

func (s State) Clone() State

Clone returns a deep copy of the receiver.

func (State) Equal

func (s State) Equal(r State) bool

Equal returns true if the given State is deeply equal to the receiever.

func (State) FixedPart

func (s State) FixedPart() FixedPart

FixedPart returns the FixedPart of the State

func (State) Hash

func (s State) Hash() (types.Bytes32, error)

Hash returns the keccak256 hash of the State

func (State) RecoverSigner

func (s State) RecoverSigner(sig Signature) (types.Address, error)

RecoverSigner computes the Ethereum address which generated Signature sig on State state

func (State) Sign

func (s State) Sign(secretKey []byte) (Signature, error)

Sign generates an ECDSA signature on the state using the supplied private key The state hash is prepended with \x19Ethereum Signed Message:\n32 and then rehashed to create a digest to sign

func (State) Validate

func (s State) Validate() error

Validate checks whether the state is malformed and returns an error if it is.

func (State) VariablePart

func (s State) VariablePart() VariablePart

VariablePart returns the VariablePart of the State

type VariablePart

type VariablePart struct {
	AppData types.Bytes
	Outcome outcome.Exit
	TurnNum uint64
	IsFinal bool
}

VariablePart contains the subset of State data which can change with each state update.

Directories

Path Synopsis
Package outcome defines the data structures for expressing how channel funds are to be distributed on-chain.
Package outcome defines the data structures for expressing how channel funds are to be distributed on-chain.

Jump to

Keyboard shortcuts

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