Documentation
¶
Index ¶
- Constants
- Variables
- type ChannelDataDetail
- type Db
- type KnownSecret
- type MockChannelDb
- func (f *MockChannelDb) GetChannelByAddress(channelIdentifier common.Hash) (c *Serialization, err error)
- func (f *MockChannelDb) IsLockSecretHashChannelIdentifierDisposed(lockSecretHash common.Hash, ChannelIdentifier common.Hash) bool
- func (f *MockChannelDb) IsThisLockHasUnlocked(channel common.Hash, lockhash common.Hash) bool
- func (f *MockChannelDb) IsThisLockRemoved(channel common.Hash, sender common.Address, secretHash common.Hash) bool
- func (f *MockChannelDb) RemoveLock(channel common.Hash, sender common.Address, secretHash common.Hash)
- func (f *MockChannelDb) UnlockThisLock(channel common.Hash, secretHash common.Hash)
- type PendingLock
- type Serialization
- func (s *Serialization) ChannleAddress() common.Hash
- func (s *Serialization) GetKey() []byte
- func (s *Serialization) MinExpiration(blockNumber int64) int64
- func (s *Serialization) OurAmountLocked() *big.Int
- func (s *Serialization) OurBalance() *big.Int
- func (s *Serialization) OurLock2PendingLocks() map[common.Hash]PendingLock
- func (s *Serialization) OurLock2UnclaimedLocks() map[common.Hash]UnlockPartialProof
- func (s *Serialization) PartnerAddress() common.Address
- func (s *Serialization) PartnerAmountLocked() *big.Int
- func (s *Serialization) PartnerBalance() *big.Int
- func (s *Serialization) PartnerLock2PendingLocks() map[common.Hash]PendingLock
- func (s *Serialization) PartnerLock2UnclaimedLocks() map[common.Hash]UnlockPartialProof
- func (s *Serialization) TokenAddress() common.Address
- type State
- type UnlockPartialProof
- type UnlockProof
Constants ¶
const ( //StateInValid channel never exist StateInValid = iota //StateOpened channel is ready for transfer StateOpened //StateClosed 不能再发起交易了,还可以接受交易. // StateClosed : cannot send out transfer, but able to receive. StateClosed //StateSettled 通道已经彻底结算,和 invalid 状态意义相同 // StateSettled : Channel has been settled, which has the same meaning as invalid. StateSettled /*StateClosing 用户发起了关闭通道的请求,正在处理 正在进行交易,可以继续,不再新开交易 */ // StateClosing : Clients requests to close channel. // ongoing transfers can be processed, but no more new transfer StateClosing /*StateSettling 用户发起了 结算请求,正在处理 正常情况下此时不应该还有未完成交易, 不能新开交易,正在进行的交易也没必要继续了.因为已经提交到链上了. */ // StateSettling : Clients request to settle channel. // Normally no incomplete transfer remains in the channel, and stop ongoing transfers and forbid openning transfers. StateSettling //StateWithdraw 用户发出了 withdraw 请求,这时候正在进行的交易只能立即放弃,因为没有任何意义了 // StateWithdraw : Clients send `withdraw` request. // Abandon ongoing transfers StateWithdraw //StateCooprativeSettle 用户发出了 cooperative settle 请求,这时候正在进行的交易只能立即放弃,因为没有任何意义了 // StateCooprativeSettle : Clients send `cooperativesettle` request. // Abandon ongoing transfers StateCooprativeSettle /*StatePrepareForCooperativeSettle 收到了用户 cooperative 请求,但是有正在处理的交易,这时候不再接受新的交易了,可以等待一段时间,然后settle 已开始交易,可以继续 */ // StatePrepareForCooperativeSettle : `CooperativeSettle` of a client has been received. // Ongoing transfers can continue, but no more new transfer. Wait for a while then settle. StatePrepareForCooperativeSettle /*StatePrepareForWithdraw 收到用户请求,要发起 withdraw, 但是目前还持有锁,不再发起或者接受任何交易,可以等待一段时间进行 withdraw 已开始交易,可以继续 */ // StatePrepareForWithdraw : Clients request received, and prepare to send `withdraw`. // Still there are locks inside the channel, no more transfer sending or receiving. // After waiting for a while, `withdraw` can be processed. // Ongoing transfer continues without any obstacle. StatePrepareForWithdraw /*StateError 比如收到了明显错误的消息,又是对方签名的,如何处理? 比如自己未发送 withdrawRequest,但是收到了 withdrawResponse todo 这种情况应该的实现是关闭通道.这样真的合理吗? */ StateError // StatePartnerCooperativeSettling 用户收到对方发来的CooperativeSettle请求并同意后,将通道置为该状态 StatePartnerCooperativeSettling // StatePartnerWithdrawing 用户收到的了对方发来的withdraw请求并同意后,将通道置为该状态 StatePartnerWithdrawing )
Variables ¶
var CanDealUnlock map[State]bool
CanDealUnlock these states can receive unlock and deal
var CanTransferMap map[State]bool
CanTransferMap these states can start and accept new transfers
var CannotReceiveAnyTransferAndAnnounceDisposedImmediately map[State]bool
CannotReceiveAnyTransferAndAnnounceDisposedImmediately these states cannot receive transfer,and need send annouce disposed immediately
var TransferCannotBeContinuedMap map[State]bool
TransferCannotBeContinuedMap these states means any transfer cannot continued
Functions ¶
This section is empty.
Types ¶
type ChannelDataDetail ¶
type ChannelDataDetail struct {
ChannelIdentifier string `json:"channel_identifier"`
OpenBlockNumber int64 `json:"open_block_number"`
PartnerAddress string `json:"partner_address"`
Balance *big.Int `json:"balance"`
PartnerBalance *big.Int `json:"partner_balance"`
LockedAmount *big.Int `json:"locked_amount"`
PartnerLockedAmount *big.Int `json:"partner_locked_amount"`
TokenAddress string `json:"token_address"`
State State `json:"state"`
StateString string `json:"state_string"`
SettleTimeout int `json:"settle_timeout"`
RevealTimeout int `json:"reveal_timeout"`
/*
extended
*/
ClosedBlock int64 `json:"closed_block"`
SettledBlock int64 `json:"settled_block"`
OurUnknownSecretLocks map[common.Hash]PendingLock `json:"our_unknown_secret_locks,omitempty"`
OurKnownSecretLocks map[common.Hash]UnlockPartialProof `json:"our_known_secret_locks,omitempty"`
PartnerUnknownSecretLocks map[common.Hash]PendingLock `json:"partner_unknown_secret_locks,omitempty"`
PartnerKnownSecretLocks map[common.Hash]UnlockPartialProof `json:"partner_known_secret_locks,omitempty"`
OurLeaves []*mtree.Lock `json:"our_leaves,omitempty"`
PartnerLeaves []*mtree.Lock `json:"partner_leaves,omitempty"`
OurBalanceProof *transfer.BalanceProofState `json:"our_balance_proof,omitempty"`
PartnerBalanceProof *transfer.BalanceProofState `json:"partner_balance_proof,omitempty"`
Signature []byte `json:"signature,omitempty"` //my signature of PartnerBalanceProof
}
ChannelDataDetail for user api
func ChannelSerialization2ChannelDataDetail ¶
func ChannelSerialization2ChannelDataDetail(c *Serialization) *ChannelDataDetail
ChannelSerialization2ChannelDataDetail 辅助函数
type Db ¶
type Db interface {
/*
is secret has withdrawed on channel?
*/
IsThisLockHasUnlocked(channel common.Hash, lockHash common.Hash) bool
/*
I have withdrawed this secret on channel.
*/
UnlockThisLock(channel common.Hash, lockHash common.Hash)
/*
is a expired hashlock has been removed from channel status.
*/
IsThisLockRemoved(channel common.Hash, sender common.Address, lockHash common.Hash) bool
/*
remember this lock has been removed from channel status.
*/
RemoveLock(channel common.Hash, sender common.Address, lockHash common.Hash)
/*
get the latest channel status
*/
GetChannelByAddress(channelIdentifier common.Hash) (c *Serialization, err error)
/*
要记录自己放在某个 channel 上放弃了某个锁,到时候一定不能unlock
*/
IsLockSecretHashChannelIdentifierDisposed(lockSecretHash common.Hash, ChannelIdentifier common.Hash) bool
}
Db is the interface of Database operations about channel
type KnownSecret ¶
type KnownSecret struct {
Secret common.Hash `json:"secret"`
IsRegisteredOnChain bool `json:"is_registered_on_chain"` //该密码是通过链上注册获知的还是通过普通的RevealSecret得知的. 如果是链上注册得知,那么一定是没有过期的.
}
KnownSecret is used to save to db
type MockChannelDb ¶
MockChannelDb for test only
func (*MockChannelDb) GetChannelByAddress ¶
func (f *MockChannelDb) GetChannelByAddress(channelIdentifier common.Hash) (c *Serialization, err error)
GetChannelByAddress get the latest channel status
func (*MockChannelDb) IsLockSecretHashChannelIdentifierDisposed ¶
func (f *MockChannelDb) IsLockSecretHashChannelIdentifierDisposed(lockSecretHash common.Hash, ChannelIdentifier common.Hash) bool
IsLockSecretHashChannelIdentifierDisposed is this lock I have annouced disposed
func (*MockChannelDb) IsThisLockHasUnlocked ¶
IsThisLockHasUnlocked is secret has withdrawed on channel
func (*MockChannelDb) IsThisLockRemoved ¶
func (f *MockChannelDb) IsThisLockRemoved(channel common.Hash, sender common.Address, secretHash common.Hash) bool
IsThisLockRemoved is a expired hashlock has been removed from channel status.
func (*MockChannelDb) RemoveLock ¶
func (f *MockChannelDb) RemoveLock(channel common.Hash, sender common.Address, secretHash common.Hash)
RemoveLock remember this lock has been removed from channel status.
func (*MockChannelDb) UnlockThisLock ¶
func (f *MockChannelDb) UnlockThisLock(channel common.Hash, secretHash common.Hash)
UnlockThisLock I have withdrawed this secret on channel.
type PendingLock ¶
type PendingLock struct {
Lock *mtree.Lock `json:"lock"`
LockHash common.Hash `json:"lock_hash"` //hash of this lock
}
PendingLock is lock of HTLC
type Serialization ¶
type Serialization struct {
ChannelIdentifier *contracts.ChannelUniqueID
Key []byte `storm:"id"`
TokenAddressBytes []byte `storm:"index"`
PartnerAddressBytes []byte `storm:"index"`
OurAddress common.Address
RevealTimeout int
OurBalanceProof *transfer.BalanceProofState
PartnerBalanceProof *transfer.BalanceProofState
OurLeaves []*mtree.Lock
PartnerLeaves []*mtree.Lock
OurKnownSecrets []*KnownSecret
PartnerKnownSecrets []*KnownSecret
State State
OurContractBalance *big.Int
PartnerContractBalance *big.Int
ClosedBlock int64
SettledBlock int64
SettleTimeout int
}
Serialization is the living channel in the database
func NewEmptySerialization ¶
func NewEmptySerialization() *Serialization
NewEmptySerialization contstructs empty serialization to avoid panic
func (*Serialization) ChannleAddress ¶
func (s *Serialization) ChannleAddress() common.Hash
ChannleAddress address of channel
func (*Serialization) MinExpiration ¶
func (s *Serialization) MinExpiration(blockNumber int64) int64
MinExpiration 返回对方所有锁中, 知道密码过期时间最小的那个,如果已经超过了 expiration,忽略就可.
- MinExpiration : return the block number of all locks in channel partner
- which is closest to `expiration` of knownsecrets
- if none, return 0.
func (*Serialization) OurAmountLocked ¶
func (s *Serialization) OurAmountLocked() *big.Int
OurAmountLocked sending token on road
func (*Serialization) OurBalance ¶
func (s *Serialization) OurBalance() *big.Int
OurBalance our abalance
func (*Serialization) OurLock2PendingLocks ¶
func (s *Serialization) OurLock2PendingLocks() map[common.Hash]PendingLock
OurLock2PendingLocks our lock and don't know secret
func (*Serialization) OurLock2UnclaimedLocks ¶
func (s *Serialization) OurLock2UnclaimedLocks() map[common.Hash]UnlockPartialProof
OurLock2UnclaimedLocks our lock and know secret
func (*Serialization) PartnerAddress ¶
func (s *Serialization) PartnerAddress() common.Address
PartnerAddress partner's address
func (*Serialization) PartnerAmountLocked ¶
func (s *Serialization) PartnerAmountLocked() *big.Int
PartnerAmountLocked received token on road
func (*Serialization) PartnerBalance ¶
func (s *Serialization) PartnerBalance() *big.Int
PartnerBalance partner's balance
func (*Serialization) PartnerLock2PendingLocks ¶
func (s *Serialization) PartnerLock2PendingLocks() map[common.Hash]PendingLock
PartnerLock2PendingLocks partner's lock and don't know secret
func (*Serialization) PartnerLock2UnclaimedLocks ¶
func (s *Serialization) PartnerLock2UnclaimedLocks() map[common.Hash]UnlockPartialProof
PartnerLock2UnclaimedLocks partner's lock and known secret
func (*Serialization) TokenAddress ¶
func (s *Serialization) TokenAddress() common.Address
TokenAddress address of token
type UnlockPartialProof ¶
type UnlockPartialProof struct {
Lock *mtree.Lock `json:"lock"`
LockHash common.Hash `json:"lock_hash"`
Secret common.Hash `json:"secret"`
IsRegisteredOnChain bool `json:"is_registered_on_chain"` //该密码是通过链上注册获知的还是通过普通的RevealSecret得知的. 如果是链上注册得知,那么一定是没有过期的.
}
UnlockPartialProof is the lock that I have known the secret ,but haven't receive the Balance proof