channel

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: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeProofForLock

func ComputeProofForLock(lock *mtree.Lock, tree *mtree.Merkletree) *channeltype.UnlockProof

ComputeProofForLock returns unlockProof need by contracts

func MakeTestPairChannel

func MakeTestPairChannel() (*Channel, *Channel)

MakeTestPairChannel for test

func NewChannelSerialization

func NewChannelSerialization(c *Channel) *channeltype.Serialization

NewChannelSerialization serialize the channel to save to database

Types

type Channel

type Channel struct {
	OurState          *EndState
	PartnerState      *EndState
	ExternState       *ExternalState
	ChannelIdentifier contracts.ChannelUniqueID //this channel
	TokenAddress      common.Address
	RevealTimeout     int
	SettleTimeout     int

	State channeltype.State
	// contains filtered or unexported fields
}

Channel is the living representation of channel on blockchain. it contains all the transfers between two participants.

func NewChannel

func NewChannel(ourState, partnerState *EndState, externState *ExternalState, tokenAddr common.Address, channelIdentifier *contracts.ChannelUniqueID,
	revealTimeout, settleTimeout int) (c *Channel, err error)

NewChannel returns the living channel. channelIdentifier must be a valid contract adress settleTimeout must be valid, it cannot too small.

func (*Channel) Balance

func (c *Channel) Balance() *big.Int

Balance Return our current Balance.

OurBalance is equal to `initial_deposit + received_amount - sent_amount`, were both `receive_amount` and `sent_amount` are unlocked.

func (*Channel) CanContinueTransfer

func (c *Channel) CanContinueTransfer() bool

CanContinueTransfer unfinished transfer can continue?

func (*Channel) CanTransfer

func (c *Channel) CanTransfer() bool

CanTransfer a closed channel and has no Balance channel cannot transfer tokens to partner.

func (*Channel) CanWithdrawOrCooperativeSettle

func (c *Channel) CanWithdrawOrCooperativeSettle() bool

CanWithdrawOrCooperativeSettle 只有在任何锁的情况下才能进行 withdraw 和cooperative settle

  • CanWithdrawOrCooperativeSettle : function to check whether we can process Withdraw / CooperativeSettle. *
  • Note that we can do withdraw / CooperativeSettle without lock.

func (*Channel) CancelWithdrawOrCooperativeSettle

func (c *Channel) CancelWithdrawOrCooperativeSettle() error

CancelWithdrawOrCooperativeSettle 等待一段时间以后发现不能合作关闭通道,可以撤销 也可以直接选择调用 close

  • CancelWithdrawCooperativeSettle : function to switch channel state to StateOpened. *
  • Note that if we wait for some amount of time and found that we cannot cooperative settle, then we can cancel that
  • Or directly invoke close.

func (*Channel) Close

func (c *Channel) Close() (err error)

Close async close this channel

func (*Channel) ContractBalance

func (c *Channel) ContractBalance() *big.Int

ContractBalance Return the total amount of token we deposited in the channel

func (*Channel) CooperativeSettleChannel

func (c *Channel) CooperativeSettleChannel(res *encoding.SettleResponse) (result *utils.AsyncResult)

CooperativeSettleChannel 收到对方的 settle response, 关闭通道即可.

  • CooperativeSettleChannel : function to undergo CooperativeSettle *
  • Note that once a channel participant receives his partner's settle response, just close this channel.

func (*Channel) CooperativeSettleChannelOnRequest

func (c *Channel) CooperativeSettleChannelOnRequest(partnerSignature []byte, res *encoding.SettleResponse) (result *utils.AsyncResult)

CooperativeSettleChannelOnRequest 收到对方的 settle requet, 但是由于某些原因,需要我自己立即关闭通道

  • CooperativeSettleChannelOnRequest : function to handle channel cooperative channel request. *
  • Note that this is case that a channel participant receives a cooperative settle request,
  • but for some reasons that he has to close the channel immediately.

func (*Channel) CreateAnnouceDisposed

func (c *Channel) CreateAnnouceDisposed(lockSecretHash common.Hash, blockNumber int64, reason rerr.StandardError) (tr *encoding.AnnounceDisposed, err error)

CreateAnnouceDisposed 声明我放弃收到的某个锁

  • CreateAnnouceDisposed : function to create message of AnnounceDisposed
  • Note that it claims that I have abandoned a lock.

func (*Channel) CreateAnnounceDisposedResponse

func (c *Channel) CreateAnnounceDisposedResponse(lockSecretHash common.Hash, blockNumber int64) (tr *encoding.AnnounceDisposedResponse, err error)

CreateAnnounceDisposedResponse 必须先收到对方的AnnouceDisposedTransfer, 然后才能移除.

  • CreateAnnounceDisposedResponse : function to create message of AnnounceDisposedResponse.
  • Note that a channel participant must first receive AnnounceDisposedTransfer, then he can

func (*Channel) CreateCooperativeSettleRequest

func (c *Channel) CreateCooperativeSettleRequest() (s *encoding.SettleRequest, err error)

CreateCooperativeSettleRequest 一定要不持有任何锁,否则双方可能对金额分配有争议.

  • CreateCooperativeSettleRequest : function to create message of CooperativeSettleRequest.
  • Note that there should be no lock, or both participants may have conflict with token allocation.

func (*Channel) CreateCooperativeSettleResponse

func (c *Channel) CreateCooperativeSettleResponse(req *encoding.SettleRequest) (res *encoding.SettleResponse, err error)

CreateCooperativeSettleResponse : 我已经验证过了,对方的 settleRequest 是合理,可以接受的, 这里只是构建数据就可以了. 有可能在我收到对方 settleRequest 过程中,我在发起一笔交易, 当然这笔交易会失败,因为对方肯定不会接受.,就算对方接受了,也没有任何意义.不可能拿到此笔钱 所以 withdraw 和 cooperative settle都会影响到现在正在进行的交易,这些 statemanager 也需要处理.

  • CreateCooperativeSettleResponse : function to create message of CooperativeSettleResponse.
  • Note that a channel participant may send out another transfer to his partner, while receiving partner's settleRequest.
  • With no doubt that this new transfer will fail because his channel partner has no chance to accept it.
  • Even he accepts it, he cannot get that token.
  • So withdraw and cooperative settle may both impact ongoing transfers, which statemanager should handle.

func (*Channel) CreateDirectTransfer

func (c *Channel) CreateDirectTransfer(amount *big.Int) (tr *encoding.DirectTransfer, err error)

CreateDirectTransfer return a DirectTransfer message.

This message needs to be signed and registered with the channel before sent.

func (*Channel) CreateMediatedTransfer

func (c *Channel) CreateMediatedTransfer(initiator, target common.Address, fee *big.Int, amount *big.Int, expiration int64, lockSecretHash common.Hash, path []common.Address) (tr *encoding.MediatedTransfer, err error)

CreateMediatedTransfer return a MediatedTransfer message.

This message needs to be signed and registered with the channel before sent.

Args:

    initiator : The node that requested the transfer.
    target : The final destination node of the transfer
    amount : How much of a token is being transferred.
    expiration : The maximum block number until the transfer
        message can be received.
	fee: 手续费

func (*Channel) CreateRemoveExpiredHashLockTransfer

func (c *Channel) CreateRemoveExpiredHashLockTransfer(lockSecretHash common.Hash, blockNumber int64) (tr *encoding.RemoveExpiredHashlockTransfer, err error)

CreateRemoveExpiredHashLockTransfer create this transfer to notify my patner that this hashlock is expired and i want to remove it .

func (*Channel) CreateUnlock

func (c *Channel) CreateUnlock(lockSecretHash common.Hash) (tr *encoding.UnLock, err error)

CreateUnlock creates a unlock message

func (*Channel) CreateWithdrawRequest

func (c *Channel) CreateWithdrawRequest(withdrawAmount *big.Int) (w *encoding.WithdrawRequest, err error)

CreateWithdrawRequest 一定要不持有任何锁,否则双方可能对金额分配有争议.

  • CreateWithdrawRequest : function to create message of request withdraw.
  • Note that there must not be any lock, or conflict will reside in token allocation.

func (*Channel) CreateWithdrawResponse

func (c *Channel) CreateWithdrawResponse(req *encoding.WithdrawRequest) (w *encoding.WithdrawResponse, err error)

CreateWithdrawResponse : 我已经验证过了,对方的 withdrawRequest 是合理,可以接受的, 这里只是构建数据就可以了. 有可能在我收到对方 withdrawRequest 过程中,我在发起一笔交易, 当然这笔交易会失败,因为对方肯定不会接受.,就算对方接受了,也没有任何意义.不可能拿到此笔钱 所以 withdraw 和 cooperative settle都会影响到现在正在进行的交易,这些 statemanager 也需要处理.

  • CreateWithdrawResponse : function to create message of WithdrawResponse. *
  • Note that there is possibilities that I send out another transfer when receiving `withdrawRequest` from my partner.
  • With no doubt that this transfer will fail because my partner has no chance to accept it. Even he accepts it, he still
  • can not get the token.
  • So withdraw and cooperative settle may both impact ongoing transfers which statemanager should deal with.

func (*Channel) Distributable

func (c *Channel) Distributable() *big.Int

Distributable return the available amount of the token that our end of the channel can transfer to the partner.

func (*Channel) GetNeedRegisterSecrets

func (c *Channel) GetNeedRegisterSecrets(blockNumber int64) (secrets []common.Hash)

GetNeedRegisterSecrets find all secres need to reveal on secret

func (*Channel) GetNextNonce

func (c *Channel) GetNextNonce() uint64

GetNextNonce change nonce means banlance proof state changed

func (*Channel) GetSettleExpiration

func (c *Channel) GetSettleExpiration(blocknumer int64) int64

GetSettleExpiration returns how many blocks have to wait before settle.

func (*Channel) GetStateFor

func (c *Channel) GetStateFor(nodeAddress common.Address) (*EndState, error)

GetStateFor returns the latest status of one participant

func (*Channel) HandleBalanceProofUpdated

func (c *Channel) HandleBalanceProofUpdated(updatedParticipant common.Address, transferAmount *big.Int, locksRoot common.Hash)

HandleBalanceProofUpdated 有可能对方使用了旧的信息,这样的话将会导致我无法 settle 通道

  • HandleBalanceProofUpdated : It handles events that channel partners submitting BalanceProof that is not the most recent,
  • which leads to inability to settle channel.

func (*Channel) HandleChannelPunished

func (c *Channel) HandleChannelPunished(beneficiaries common.Address)

HandleChannelPunished 发生了 Punish 事件,意味着受益方合约上的信息发生了变化.

  • HandleChannelPunished : Punish event occurs,
  • which means that information on contract of beneficiary has been changed.

func (*Channel) HandleClosed

func (c *Channel) HandleClosed(closingAddress common.Address, transferredAmount *big.Int, locksRoot common.Hash)

HandleClosed handles this channel was closed on blockchain 1. 更新NonClosing 一方的 ContractTransferAmount 和 LocksRoot, 2. 对方可能用旧的BalanceProof, 所以未必与我保存的 TransferAmount 和 LocksRoot一致 3. 如果我不是关闭方,那么需要更新对方的 BalanceProof 4. 我持有的知道密码的锁,需要解锁.

  • HandleClosed : It handles events of closing channel. *
  • 1. Update ContractTransferAmount & LocksRoot of the non-closing participant.
  • 2. That participant may submit used BalanceProof, in which TransferAmount & LocksRoot are not consistent with mine.
  • 3. If I am not the non-closing participant, then update the BalanceProof of my channel partner.
  • 4. All locks I am holding that have known secrets must be unlocked.

func (*Channel) HandleSettled

func (c *Channel) HandleSettled(blockNumber int64)

HandleSettled handles this channel was settled on blockchain there is nothing tod rightnow

func (*Channel) HandleWithdrawed

func (c *Channel) HandleWithdrawed(newOpenBlockNumber int64, participant1, participant2 common.Address, participant1Balance, participant2Balance *big.Int)

HandleWithdrawed 需要重新分配初始化整个通道的信息

  • HandleWithdrawed : function to handle withdraw message.
  • This function will re-allocate the messages that initialize the whole payment channel.

func (*Channel) HasAnyUnkonwnSecretTransferOnRoad

func (c *Channel) HasAnyUnkonwnSecretTransferOnRoad() bool

HasAnyUnkonwnSecretTransferOnRoad 是否还有任何我发出的交易,并且对方不知道密码的

  • HasAnyUnknownSecretTransferOnRoad : function to check whether there is any transfer sent out from me
  • that my partner has no idea about the secret.

func (*Channel) IsClosed

func (c *Channel) IsClosed() bool

IsClosed returns true when this channel closed

func (*Channel) Locked

func (c *Channel) Locked() *big.Int

Locked return the current amount of our token that is locked waiting for a

secret.

The locked value is equal to locked transfers that have been initialized but their secret has not being revealed.

func (*Channel) Outstanding

func (c *Channel) Outstanding() *big.Int

Outstanding is the tokens on road...

func (*Channel) PartnerBalance

func (c *Channel) PartnerBalance() *big.Int

PartnerBalance return partner current Balance. OurBalance is equal to `initial_deposit + received_amount - sent_amount`, were both `receive_amount` and `sent_amount` are unlocked.

func (*Channel) PreCheckRecievedTransfer

func (c *Channel) PreCheckRecievedTransfer(tr encoding.EnvelopMessager) (fromState *EndState, toState *EndState, err error)

PreCheckRecievedTransfer pre check received message(directtransfer,mediatedtransfer,refundtransfer) is valid or not

func (*Channel) PrepareForCooperativeSettle

func (c *Channel) PrepareForCooperativeSettle() error

PrepareForCooperativeSettle : 由于 withdraw 和 合作settle 需要事先没有任何锁,因此必须先标记不进行任何交易 等现有交易完成以后再

  • PrepareForCooperativeSettle : function to switch channel state to StatePrepareForCooperativeSettle. *
  • Note that because withdraw and cooperative settle require no lock,
  • hence we should tag that any new transfer is forbidden, and after ongoing transfers finish,
  • we can do channel withdraw.

func (*Channel) PrepareForWithdraw

func (c *Channel) PrepareForWithdraw() error

PrepareForWithdraw : 由于 withdraw 和 合作settle 需要事先没有任何锁,因此必须先标记不进行任何交易 等现有交易完成以后再

  • PrepareForWithdraw : function to change channel state to StatePrepareForWithdraw
  • Note that because withdraw and cooperative settle require no lock,
  • hence we should tag that any new transfer is forbidden, and after ongoing transfers finish,
  • we can do channel withdraw.

func (*Channel) RegisterAnnouceDisposed

func (c *Channel) RegisterAnnouceDisposed(tr *encoding.AnnounceDisposed) (err error)

RegisterAnnouceDisposed 收到对方的 AnnouceDisposed 消息 签名验证已经进行过了.

  • RegisterAnnouceDisposed : function to register message of AnnounceDisposed.
  • Note that signature verification has been undergone.

func (*Channel) RegisterAnnounceDisposedResponse

func (c *Channel) RegisterAnnounceDisposedResponse(response *encoding.AnnounceDisposedResponse, blockNumber int64) (err error)

RegisterAnnounceDisposedResponse 从我这里发出或者收到来自对方的announceDisposedTransferResponse, 注意收到对方消息的话,一定要验证事先发出去过AnnounceDisposedTransfer.

  • RegisterAnnounceDisposedResponse : function to register AnnounceDisposedRespnse, and send out or receive announceDisposedTransferResponse from channel partner. *
  • Note that everytime a participant receives message from his partner, he must verify the AnnounceDisposedTransfer he sent out beforehand.

func (*Channel) RegisterCooperativeSettleRequest

func (c *Channel) RegisterCooperativeSettleRequest(msg *encoding.SettleRequest) error

RegisterCooperativeSettleRequest check settle request and update state 该方法在收到对方的CooperativeRequest时调用,自己发送CooperativeRequest时不应该使用该方法

func (*Channel) RegisterCooperativeSettleResponse

func (c *Channel) RegisterCooperativeSettleResponse(msg *encoding.SettleResponse) error

RegisterCooperativeSettleResponse check settle response and update state

func (*Channel) RegisterRemoveExpiredHashlockTransfer

func (c *Channel) RegisterRemoveExpiredHashlockTransfer(tr *encoding.RemoveExpiredHashlockTransfer, blockNumber int64) (err error)

RegisterRemoveExpiredHashlockTransfer register a request to remove a expired hashlock and this hashlock must be sent out from the sender.

func (*Channel) RegisterRevealedSecretHash

func (c *Channel) RegisterRevealedSecretHash(lockSecretHash, secret common.Hash, blockNumber int64) error

RegisterRevealedSecretHash 链上对应的密码注册了 RegisterRevealedSecretHash : secret has been registered on chain.

func (*Channel) RegisterSecret

func (c *Channel) RegisterSecret(secret common.Hash) error

RegisterSecret Register a secret to this channel

This wont claim the lock (update the transferred_amount), it will only
save the secret in case that a proof needs to be created. This method
can be used for any of the ends of the channel.

Note:
    When a secret is revealed a message could be in-transit containing
    the older lockroot, for this reason the recipient cannot update
    their locksroot at the moment a secret was revealed.

    The protocol is to register the secret so that it can compute a
    proof of Balance, if necessary, forward the secret to the sender
    and wait for the update from it. It's the sender's duty to order the
    current in-transit (and possible the transfers in queue) transfers
    and the secret/locksroot update.

    The channel and its queue must be changed in sync, a transfer must
    not be created while we update the balance_proof.

Args:
    secret: The secret that releases a locked transfer.

func (*Channel) RegisterTransfer

func (c *Channel) RegisterTransfer(blocknumber int64, tr encoding.EnvelopMessager) error

RegisterTransfer register a signed transfer, updating the channel's state accordingly. 这些消息会改变 channel 的balance Proof

  • RegisterTransfer : register a signed transfer, updating the channel's state accordingly.
  • This transfer will change BalanceProof of this channel.

func (*Channel) RegisterWithdrawRequest

func (c *Channel) RegisterWithdrawRequest(tr *encoding.WithdrawRequest) (err error)

RegisterWithdrawRequest : 1. 验证信息准确 2. 通道状态要切换到StateWithdraw

  • RegisterWithdrawRequest : function to register WithdrawRequest. *
  • 1. verify the information is correct.
  • 2. channel state must switch to StateWithdraw.

func (*Channel) RegisterWithdrawResponse

func (c *Channel) RegisterWithdrawResponse(tr *encoding.WithdrawResponse) error

RegisterWithdrawResponse check withdraw response 外部应该验证响应与请求是一致的

  • RegisterWithdrawResponse : function to check withdraw response. *
  • Explicit verify that withdraw response should be consistent with withdraw request.

func (*Channel) Settle

func (c *Channel) Settle(blockNumber int64) (err error)

Settle async settle this channel,blockNumber is the current blockNumber

func (*Channel) String

func (c *Channel) String() string

String fmt.Stringer

func (*Channel) TransferAmount

func (c *Channel) TransferAmount() *big.Int

TransferAmount Return how much we transferred to partner.

func (*Channel) Withdraw

func (c *Channel) Withdraw(res *encoding.WithdrawResponse) (result *utils.AsyncResult)

Withdraw 收到对方的 withdraw response, 需要先验证参数有效

  • Withdraw : function to undergo channel withdraw. *
  • Note that this function has to work after verify parameter is valid.

type EndState

type EndState struct {
	Address             common.Address
	ContractBalance     *big.Int                                //lock protect race codition with Photonapi
	Lock2PendingLocks   map[common.Hash]channeltype.PendingLock //the lock I have sent
	Lock2UnclaimedLocks map[common.Hash]channeltype.UnlockPartialProof
	Tree                *mtree.Merkletree
	BalanceProofState   *transfer.BalanceProofState //race codition with Photonapi
}

EndState Tracks the state of one of the participants in a channel all the transfer (whenever lock or not ) I have sent.

func NewChannelEndState

func NewChannelEndState(participantAddress common.Address, participantBalance *big.Int,
	balanceProof *transfer.BalanceProofState, tree *mtree.Merkletree) *EndState

NewChannelEndState create EndState

func (*EndState) Balance

func (node *EndState) Balance(counterpart *EndState) *big.Int

Balance returns the availabe tokens i have

func (*EndState) Distributable

func (node *EndState) Distributable(counterpart *EndState) *big.Int

Distributable returns the availabe tokens i can send to partner. this equals `Balance`-`amountLocked`

func (*EndState) GetCanUnlockOnChainLocks

func (node *EndState) GetCanUnlockOnChainLocks() []*channeltype.UnlockProof

GetCanUnlockOnChainLocks generate unlocking proofs for the known secrets

func (*EndState) GetSecret

func (node *EndState) GetSecret(lockSecretHash common.Hash) (secret common.Hash, found bool)

GetSecret returns the secret corresponds to the lockSecretHash if found

func (*EndState) GetUnkownSecretLockByHashlock

func (node *EndState) GetUnkownSecretLockByHashlock(lockSecretHash common.Hash) *mtree.Lock

GetUnkownSecretLockByHashlock returns the hash corresponding Lock,nil if not found

func (*EndState) IsKnown

func (node *EndState) IsKnown(lockSecretHash common.Hash) bool

IsKnown returns True if the `hashlock` corresponds to a known lock.

func (*EndState) IsLocked

func (node *EndState) IsLocked(hashlock common.Hash) bool

IsLocked returns True if the `hashlock` is known and the correspoding secret is not.

func (*EndState) RegisterRevealedSecretHash

func (node *EndState) RegisterRevealedSecretHash(lockSecretHash, secret common.Hash, blockNumber int64) error

RegisterRevealedSecretHash a SecretReveal event on chain

func (*EndState) RegisterSecret

func (node *EndState) RegisterSecret(secret common.Hash) error

RegisterSecret register a secret(not secret message) so that it can be used in a Balance proof.

This methods needs to be called once a `Secret` message is received

func (*EndState) SetContractLocksroot

func (node *EndState) SetContractLocksroot(locksroot common.Hash)

SetContractLocksroot update node's locksroot by contract event

func (*EndState) SetContractNonce

func (node *EndState) SetContractNonce(nonce uint64)

SetContractNonce update node's nonce by contract event

func (*EndState) SetContractTransferAmount

func (node *EndState) SetContractTransferAmount(amount *big.Int)

SetContractTransferAmount update node's transfer amount by contract event

func (*EndState) TransferAmount

func (node *EndState) TransferAmount() *big.Int

TransferAmount is how many tokens I have sent to partner.

func (*EndState) TryRemoveHashLock

func (node *EndState) TryRemoveHashLock(lockSecretHash common.Hash, blockNumber int64, mustExpired bool) (lock *mtree.Lock, newtree *mtree.Merkletree, newlocksroot common.Hash, err error)

TryRemoveHashLock try to remomve a expired hashlock

func (*EndState) UpdateContractBalance

func (node *EndState) UpdateContractBalance(balance *big.Int) error

UpdateContractBalance returns Update the contract Balance, it must always increase.

return error If the `contract_balance` is smaller than the current

Balance.

type ExternalState

type ExternalState struct {
	TokenNetwork *rpc.TokenNetworkProxy

	Client            *helper.SafeEthClient
	ClosedBlock       int64 //通道被强制关闭的block,
	SettledBlock      int64 //初始为0,通道被强制关闭以后则是可以进行settle的块数,通道被settle以后,则是通道被settle的块数
	ChannelIdentifier contracts.ChannelUniqueID
	MyAddress         common.Address
	PartnerAddress    common.Address
	// contains filtered or unexported fields
}

ExternalState operation on nettingchannelcontract

func NewChannelExternalState

func NewChannelExternalState(fun FuncRegisterChannelForHashlock,
	tokenNetwork *rpc.TokenNetworkProxy, channelIdentifier *contracts.ChannelUniqueID, privkey *ecdsa.PrivateKey, client *helper.SafeEthClient, db channeltype.Db, closedBlock int64, MyAddress, PartnerAddress common.Address) *ExternalState

NewChannelExternalState create a new channel external state

func (*ExternalState) Close

func (e *ExternalState) Close(balanceProof *transfer.BalanceProofState) (err error)

Close call close function of smart contract

func (*ExternalState) PunishObsoleteUnlock

func (e *ExternalState) PunishObsoleteUnlock(lockhash, additionalHash common.Hash, cheaterSignature []byte) (result *utils.AsyncResult)

PunishObsoleteUnlock 惩罚对手 unlock 一个声明放弃了的锁.

  • PunishObsoleteUnlock : function to punishment channel participant who unlocks a transfer lock that has been claimed abandoned.

func (*ExternalState) SetClosed

func (e *ExternalState) SetClosed(blocknumber int64) bool

SetClosed set the closed blocknubmer of this channel

func (*ExternalState) SetSettled

func (e *ExternalState) SetSettled(blocknumber int64) bool

SetSettled set the settled number of this channel

func (*ExternalState) Settle

func (e *ExternalState) Settle(MyTransferAmount, PartnerTransferAmount *big.Int, MyLocksroot, PartnerLocksroot common.Hash) (err error)

Settle call settle function of contract

func (*ExternalState) Unlock

func (e *ExternalState) Unlock(unlockproofs []*channeltype.UnlockProof, argTransferdAmount *big.Int) (result *utils.AsyncResult)

Unlock call withdraw function of contract 调用者要确保不包含自己声明放弃过的锁

  • Unlock : function to unlock. *
  • Note that caller has to ensure that there aren't locks that claimed abandoned by him contained.

func (*ExternalState) UpdateTransfer

func (e *ExternalState) UpdateTransfer(bp *transfer.BalanceProofState) (result *utils.AsyncResult)

UpdateTransfer call updateTransfer of contract

type FakeTXINfoDao

type FakeTXINfoDao struct{}

FakeTXINfoDao only for test

func (*FakeTXINfoDao) GetTXInfoList

func (dao *FakeTXINfoDao) GetTXInfoList(channelIdentifier common.Hash, openBlockNumber int64, tokenAddress common.Address, txType models.TXInfoType, status models.TXInfoStatus) (list []*models.TXInfo, err error)

GetTXInfoList :

func (*FakeTXINfoDao) NewPendingTXInfo

func (dao *FakeTXINfoDao) NewPendingTXInfo(tx *types.Transaction, txType models.TXInfoType, channelIdentifier common.Hash, openBlockNumber int64, txParams models.TXParams) (txInfo *models.TXInfo, err error)

NewPendingTXInfo :

func (*FakeTXINfoDao) SaveEventToTXInfo

func (dao *FakeTXINfoDao) SaveEventToTXInfo(event interface{}) (txInfo *models.TXInfo, err error)

SaveEventToTXInfo :

func (*FakeTXINfoDao) UpdateTXInfoStatus

func (dao *FakeTXINfoDao) UpdateTXInfoStatus(txHash common.Hash, status models.TXInfoStatus, pendingBlockNumber int64, gasUsed uint64) (txInfo *models.TXInfo, err error)

UpdateTXInfoStatus :

type FuncRegisterChannelForHashlock

type FuncRegisterChannelForHashlock func(channel *Channel, hashlock common.Hash)

FuncRegisterChannelForHashlock is the callback for notify a new hashlock comes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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