transfer

package
v0.0.0-...-9f791b1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionCancelTransferStateChange

type ActionCancelTransferStateChange struct {
	LockSecretHash common.Hash
}

ActionCancelTransferStateChange The user requests the transfer to be cancelled.

This state change can fail, it depends on the node's role and the current
state of the transfer.

type ActionTransferDirectStateChange

type ActionTransferDirectStateChange struct {
	Amount       *big.Int
	TokenAddress common.Address
	NodeAddress  common.Address
}

ActionTransferDirectStateChange send a direct transfer

type BalanceProofState

type BalanceProofState struct {
	Nonce             uint64                    `json:"nonce"`
	TransferAmount    *big.Int                  `json:"transfer_amount"`
	LocksRoot         common.Hash               `json:"locks_root"`
	ChannelIdentifier contracts.ChannelUniqueID `json:"channel_identifier"`
	MessageHash       common.Hash               `json:"message_hash"`
	//signature is nonce + transferred_amount + locksroot + channel_identifier + message_hash
	Signature []byte `json:"signature,omitempty"`

	/*
		由于合约上并没有存储transferamount 和 locksroot,
		而用户 unlock 的时候会改变对方的 TransferAmount, 虽然说这个没有对方的签名,但是必须凭此在合约上settle 以及 unlock
	*/
	// Because contract does not cache transferAmount and locksroot
	// and my partner's transferAmount will be changed, even I have no signature of my partner, but we should settle and unlock via it.
	ContractTransferAmount *big.Int    `json:"contract_transfer_amount,omitempty"`
	ContractNonce          uint64      `json:"contract_nonce,omitempty"`
	ContractLocksRoot      common.Hash `json:"contract_locksroot,omitempty"`
}

BalanceProofState is proof need by contract

func NewBalanceProofState

func NewBalanceProofState(nonce uint64, transferAmount *big.Int, locksRoot common.Hash,
	channelIdentifier contracts.ChannelUniqueID, messageHash common.Hash, signature []byte) *BalanceProofState

NewBalanceProofState create BalanceProofState

func NewBalanceProofStateFromEnvelopMessage

func NewBalanceProofStateFromEnvelopMessage(msg encoding.EnvelopMessager) *BalanceProofState

NewBalanceProofStateFromEnvelopMessage from locked transfer

func NewEmptyBalanceProofState

func NewEmptyBalanceProofState() *BalanceProofState

NewEmptyBalanceProofState init BalanceProof with proper state

func (*BalanceProofState) IsBalanceProofValid

func (bpf *BalanceProofState) IsBalanceProofValid() bool

IsBalanceProofValid true if valid

func (*BalanceProofState) StateName

func (bpf *BalanceProofState) StateName() string

StateName name of state

type BlockStateChange

type BlockStateChange struct {
	BlockNumber int64
}

BlockStateChange used when a new block is mined.

type CooperativeSettleStateChange

type CooperativeSettleStateChange struct {
	Message *encoding.SettleRequest
}

CooperativeSettleStateChange user request to cooperative settle

type Event

type Event interface{}

Event produced by the execution of a state change.

Nomenclature convention:
- 'Send' prefix for protocol messages.
- 'ContractSend' prefix for smart contract function calls.
- 'Event' for node events.

Notes:
- This class is used as a marker for events.
- These objects don't have logic by design.
- Separate events are preferred because there is a decoupling of what the
  upper layer will use the events for.

type EventTransferReceivedSuccess

type EventTransferReceivedSuccess struct {
	LockSecretHash    common.Hash
	Amount            *big.Int
	Initiator         common.Address
	ChannelIdentifier common.Hash
	Data              string
}

EventTransferReceivedSuccess emitted when a payee has received a payment.

A payee knows if a lock withdraw has failed, but this is not sufficient
information to deduce when a transfer has failed, because the initiator may
try again at a different time and/or with different routes, for this reason
there is no correspoding `EventTransferReceivedFailed`.

type EventTransferSentFailed

type EventTransferSentFailed struct {
	LockSecretHash common.Hash
	Reason         string
	Target         common.Address //transfer's target, may be not the same as receipient
	Token          common.Address
}

EventTransferSentFailed emitted by the payer when a transfer has failed.

Note:
    Mediators cannot use this event since they don't know when a transfer
    has failed, they may infer about lock successes and failures.

type EventTransferSentSuccess

type EventTransferSentSuccess struct {
	LockSecretHash    common.Hash
	Amount            *big.Int
	Target            common.Address
	ChannelIdentifier common.Hash
	Token             common.Address
	Data              string
}

EventTransferSentSuccess emitted by the initiator when a transfer is considered sucessful.

A transfer is considered sucessful when the initiator's payee hop sends the
reveal secret message, assuming that each hop in the mediator chain has
also learned the secret and unlock/withdraw its token.

This definition of sucessful is used to avoid the following corner case:

- The reveal secret message is sent, since the network is unreliable and we
  assume byzantine behavior the message is considered delivered without an
  acknowledgement.
- The transfer is considered sucessful because of the above.
- The reveal secret message was not delivered because of actual network
  problems.
- The lock expires and an EventUnlockFailed follows, contradicting the
  EventTransferSentSuccess.

    Mediators cannot use this event, since an unlock may be locally
    sucessful but there is no knowledge about the global transfer.

type FuncStateTransition

type FuncStateTransition func(state State, stateChange StateChange) *TransitionResult

FuncStateTransition The mutable storage for the application state, this storage can do

state transitions by applying the StateChanges to the current State.

type MessageTag

type MessageTag struct {
	EchoHash common.Hash
}

MessageTag for save and restore

type ReceiveTransferDirectStateChange

type ReceiveTransferDirectStateChange struct {
	Amount       *big.Int
	TokenAddress common.Address
	Sender       common.Address
	Message      *encoding.DirectTransfer
}

ReceiveTransferDirectStateChange receive a direct transfer

type State

type State interface{}

State is An isolated state, modified by StateChange messages.

Notes: - Don't duplicate the same state data in two different States, instead use identifiers.

  • State objects may be nested.
  • State classes don't have logic by design.
  • Each iteration must operate on fresh copy of the state, treating the old objects as immutable.
  • This class is used as a marker for states.

type StateChange

type StateChange interface{}

StateChange Declare the transition to be applied in a state object.

StateChanges are incoming events that change this node state (eg. a
blockchain event, a new packet, an error). It is not used for the node to
communicate with the outer world.

Nomenclature convention:
- 'Receive' prefix for protocol messages.
- 'ContractReceive' prefix for smart contract logs.
- 'Action' prefix for other interactions.

Notes:
- These objects don't have logic by design.
- This class is used as a marker for state changes.

type StateManager

type StateManager struct {
	ID                  int64 `storm:"id,increment"`
	FuncStateTransition FuncStateTransition
	CurrentState        State
	Identifier          common.Hash //transfer identifier
	Name                string
	LastReceivedMessage encoding.SignedMessager
}

StateManager corresponding one MediatedTransfer it has State of the Transfer and Other Info for save and restore

func NewStateManager

func NewStateManager(stateTransition FuncStateTransition, currentState State, name string, identifier common.Hash, tokenAddress common.Address) *StateManager

NewStateManager create a StateManager

func (*StateManager) Dispatch

func (sm *StateManager) Dispatch(stateChange StateChange) (events []Event)

Dispatch Apply the `state_change` in the current machine and return the

 resulting events.
    stateChange : An object representation of a state
    change.

Return:
    events: A list of events produced by the state transition, it's
    the upper layer's responsibility to decided how to handle these
    events.

type StopTransferRightNowStateChange

type StopTransferRightNowStateChange struct {
	TokenAddress      common.Address
	ChannelIdentifier common.Hash
}

StopTransferRightNowStateChange 收到了 WithdrawRequest 或者 CooperativeSettleRequest, 应该理解停止进行中的交易.

type TransitionResult

type TransitionResult struct {
	NewState State
	Events   []Event
}

TransitionResult result of next state transition

type WithdrawRequestStateChange

type WithdrawRequestStateChange struct {
	Message *encoding.WithdrawRequest
}

WithdrawRequestStateChange user request to withdraw on chain

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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