stormdb

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NonParticipantChannel

type NonParticipantChannel struct {
	ChannelIdentifierBytes []byte `storm:"id"`
	TokenAddressBytes      []byte `storm:"index"`
	Participant1Bytes      []byte
	Participant2Bytes      []byte
}

NonParticipantChannel 所有的通道信息在本地的存储 因为合约不提供直接查询通道信息,只能通过事件获取,所以需要在本地保存一份,以便查询

  • NonParticipantChannel : structure for back up of channel information at local storage.
  • Because contract does not provide direct check for channel information, so we need to backup at local storage.

type PubRewardDB

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

PubDB init

func OpenPubDB

func OpenPubDB(pubDataSource string) (DB *PubRewardDB, err error)

func (*PubRewardDB) InsertHistoryReward

func (pdb *PubRewardDB) InsertHistoryReward(clientid, ethaddr string, nowsum int) (lastid int64, err error)

InsertHistoryReward

func (*PubRewardDB) SelectHistoryReward

func (pdb *PubRewardDB) SelectHistoryReward(clientid, ethaddr string) (ri *RewardInfo, err error)

SelectHistoryReward

func (*PubRewardDB) UpdateHistoryReward

func (pdb *PubRewardDB) UpdateHistoryReward(clientid, ethaddr string, nowsum int) (affectid int64, err error)

UpdateHistoryReward

type RewardInfo

type RewardInfo struct {
	ClientId         string
	EthAddress       string
	HistoryRewardSum int
}

RewardInfo

type StormDB

type StormDB struct {
	Name string
	// contains filtered or unexported fields
}

StormDB is thread safe

func OpenDb

func OpenDb(dbPath string) (model *StormDB, err error)

OpenDb open or create a bolt db at dbPath

func (*StormDB) AddToken

func (model *StormDB) AddToken(token common.Address, tokenNetworkAddress common.Address) error

AddToken add a new token to db,

func (*StormDB) CheckChainEventDelivered

func (model *StormDB) CheckChainEventDelivered(id models.ChainEventID) (blockNumber uint64, delivered bool)

CheckChainEventDelivered check one ChainEvent is delivered or not

func (*StormDB) ClearOldChainEventRecord

func (model *StormDB) ClearOldChainEventRecord(blockNumber uint64)

ClearOldChainEventRecord delete records which blockNumber <= blockNumber in param

func (*StormDB) CloseDB

func (model *StormDB) CloseDB()

CloseDB close db

func (*StormDB) DeleteEnvelopMessager

func (model *StormDB) DeleteEnvelopMessager(echohash common.Hash)

DeleteEnvelopMessager delete a sending message from db

func (*StormDB) GetAck

func (model *StormDB) GetAck(echoHash common.Hash) []byte

GetAck get message related ack message

func (*StormDB) GetAllFeeChargeRecord

func (model *StormDB) GetAllFeeChargeRecord(tokenAddress common.Address, fromTime, toTime int64) (records []*models.FeeChargeRecord, err error)

GetAllFeeChargeRecord :

func (*StormDB) GetAllNonParticipantChannelByToken

func (model *StormDB) GetAllNonParticipantChannelByToken(token common.Address) (edges []common.Address, err error)

GetAllNonParticipantChannelByToken returna all channel on this `token`

func (*StormDB) GetAllOrderedSentEnvelopMessager

func (model *StormDB) GetAllOrderedSentEnvelopMessager() []*models.SentEnvelopMessager

GetAllOrderedSentEnvelopMessager returns all EnvelopMessager message that have not receive ack and order them by nonce

func (*StormDB) GetAllSettledChannel

func (model *StormDB) GetAllSettledChannel() (chs []*channeltype.Serialization, err error)

GetAllSettledChannel returns all settled channel

func (*StormDB) GetAllTokens

func (model *StormDB) GetAllTokens() (tokens models.AddressMap, err error)

GetAllTokens returna all tokens on this registry contract

func (*StormDB) GetChainID

func (model *StormDB) GetChainID() int64

GetChainID :

func (*StormDB) GetChannel

func (model *StormDB) GetChannel(token, partner common.Address) (c *channeltype.Serialization, err error)

GetChannel return a channel queried by (token,partner),this channel must not settled

func (*StormDB) GetChannelAnnounceDisposed

func (model *StormDB) GetChannelAnnounceDisposed(channelIdentifier common.Hash) []*models.ReceivedAnnounceDisposed

GetChannelAnnounceDisposed 获取指定 channel中对方声明放弃的锁,

  • GetChannelAnnounceDisposed : function to receive disposed locks claimed by channel partner in specific channel

func (*StormDB) GetChannelByAddress

func (model *StormDB) GetChannelByAddress(ChannelIdentifier common.Hash) (c *channeltype.Serialization, err error)

GetChannelByAddress return a channel queried by channel address

func (*StormDB) GetChannelList

func (model *StormDB) GetChannelList(token, partner common.Address) (cs []*channeltype.Serialization, err error)

GetChannelList returns all related channels one of token and partner must be empty

func (*StormDB) GetContractStatus

func (model *StormDB) GetContractStatus() models.ContractStatus

GetContractStatus returns registry address in db

func (*StormDB) GetFeeChargeRecordByLockSecretHash

func (model *StormDB) GetFeeChargeRecordByLockSecretHash(lockSecretHash common.Hash) (records []*models.FeeChargeRecord, err error)

GetFeeChargeRecordByLockSecretHash :

func (*StormDB) GetFeePolicy

func (model *StormDB) GetFeePolicy() (fp *models.FeePolicy)

GetFeePolicy :

func (*StormDB) GetLastBlockNumberTime

func (model *StormDB) GetLastBlockNumberTime() time.Time

GetLastBlockNumberTime return when last block received

func (*StormDB) GetLatestBlockNumber

func (model *StormDB) GetLatestBlockNumber() int64

GetLatestBlockNumber lastest block number

func (*StormDB) GetNonParticipantChannelByID

func (model *StormDB) GetNonParticipantChannelByID(channelIdentifierForQuery common.Hash) (
	tokenAddress common.Address, participant1, participant2 common.Address, err error)

GetNonParticipantChannelByID return one channel's information

func (*StormDB) GetReceivedAnnounceDisposed

func (model *StormDB) GetReceivedAnnounceDisposed(lockHash, channelIdentifier common.Hash) *models.ReceivedAnnounceDisposed

GetReceivedAnnounceDisposed return a ReceivedAnnounceDisposed ,if not exist,return nil

func (*StormDB) GetReceivedTransfer

func (model *StormDB) GetReceivedTransfer(key string) (*models.ReceivedTransfer, error)

GetReceivedTransfer return the received transfer by key

func (*StormDB) GetReceivedTransferList

func (model *StormDB) GetReceivedTransferList(tokenAddress common.Address, fromBlock, toBlock, fromTime, toTime int64) (transfers []*models.ReceivedTransfer, err error)

GetReceivedTransferList returns the received transfer between from and to blocks

func (*StormDB) GetSentTransferDetail

func (model *StormDB) GetSentTransferDetail(tokenAddress common.Address, lockSecretHash common.Hash) (*models.SentTransferDetail, error)

GetSentTransferDetail :

func (*StormDB) GetSentTransferDetailList

func (model *StormDB) GetSentTransferDetailList(tokenAddress common.Address, fromTime, toTime int64, fromBlock, toBlock int64) (transfers []*models.SentTransferDetail, err error)

GetSentTransferDetailList : 参数均为查询条件,传空值或负值代表不限制

func (*StormDB) GetSettledChannel

func (model *StormDB) GetSettledChannel(channelIdentifier common.Hash, openBlockNumber int64) (c *channeltype.Serialization, err error)

GetSettledChannel 返回某个指定的已经 settle 的 channel GetSettledChannel : function to return a specific settled channel.

func (*StormDB) GetTXInfoList

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

GetTXInfoList : 如果参数不为空,则根据参数查询

func (*StormDB) GetTokenNodes

func (model *StormDB) GetTokenNodes(token common.Address) (nodes []common.Address)

GetTokenNodes return all nodes has channel with me

func (*StormDB) IsDbCrashedLastTime

func (model *StormDB) IsDbCrashedLastTime() bool

IsDbCrashedLastTime return true when quit but db not closed

func (*StormDB) IsLockHashCanPunish

func (model *StormDB) IsLockHashCanPunish(lockHash, channelIdentifier common.Hash) bool

IsLockHashCanPunish can punish this unlock?

func (*StormDB) IsLockSecretHashChannelIdentifierDisposed

func (model *StormDB) IsLockSecretHashChannelIdentifierDisposed(lockSecretHash common.Hash, ChannelIdentifier common.Hash) bool

IsLockSecretHashChannelIdentifierDisposed `lockSecretHash` and `ChannelIdentifier` is the id of AnnounceDisposed

func (*StormDB) IsLockSecretHashDisposed

func (model *StormDB) IsLockSecretHashDisposed(lockSecretHash common.Hash) bool

IsLockSecretHashDisposed this lockSecretHash has Announced Disposed

func (*StormDB) IsThisLockHasUnlocked

func (model *StormDB) IsThisLockHasUnlocked(channel common.Hash, lockHash common.Hash) bool

IsThisLockHasUnlocked return ture when lockhash has unlocked on channel?

func (*StormDB) IsThisLockRemoved

func (model *StormDB) IsThisLockRemoved(channel common.Hash, sender common.Address, lockHash common.Hash) bool

IsThisLockRemoved return true when a expired hashlock has been removed from channel status.

func (*StormDB) MakeChainEventID

func (model *StormDB) MakeChainEventID(l *types.Log) models.ChainEventID

MakeChainEventID :

func (*StormDB) MarkDbOpenedStatus

func (model *StormDB) MarkDbOpenedStatus()

MarkDbOpenedStatus First step open the database Second step detection for normal closure IsDbCrashedLastTime Third step recovers the data according to the second step Fourth step mark the database for processing the data normally. MarkDbOpenedStatus

func (*StormDB) MarkLockHashCanPunish

func (model *StormDB) MarkLockHashCanPunish(r *models.ReceivedAnnounceDisposed) error

MarkLockHashCanPunish 收到了一个放弃声明,需要保存,在收到 unlock 事件的时候进行 punish

  • MarkLockHashCanPunish : Once receiving an AnnounceDisposed message, we need to store it
  • and submit it to enforce punishment procedure while receiving unlock.

func (*StormDB) MarkLockSecretHashDisposed

func (model *StormDB) MarkLockSecretHashDisposed(lockSecretHash common.Hash, ChannelIdentifier common.Hash) error

MarkLockSecretHashDisposed mark `locksecrethash` disposed on channel `ChannelIdentifier`

func (*StormDB) NewChannel

func (model *StormDB) NewChannel(c *channeltype.Serialization) error

NewChannel save a just created channel to db

func (*StormDB) NewDeliveredChainEvent

func (model *StormDB) NewDeliveredChainEvent(id models.ChainEventID, blockNumber uint64)

NewDeliveredChainEvent save one

func (*StormDB) NewNonParticipantChannel

func (model *StormDB) NewNonParticipantChannel(token common.Address, channel common.Hash, participant1, participant2 common.Address) error

NewNonParticipantChannel 需要保存 channel identifier, 通道的事件都是与此有关系的

func (*StormDB) NewPendingTXInfo

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

NewPendingTXInfo 创建pending状态的TXInfo,即自己发起的tx

func (*StormDB) NewReceivedTransfer

func (model *StormDB) NewReceivedTransfer(blockNumber int64, channelIdentifier common.Hash, openBlockNumber int64, tokenAddr, fromAddr common.Address, nonce uint64, amount *big.Int, lockSecretHash common.Hash, data string) *models.ReceivedTransfer

NewReceivedTransfer save a new received transfer to db

func (*StormDB) NewSentEnvelopMessager

func (model *StormDB) NewSentEnvelopMessager(msg encoding.EnvelopMessager, receiver common.Address)

NewSentEnvelopMessager create a sending EnvelopMessager in db

func (*StormDB) NewSentTransferDetail

func (model *StormDB) NewSentTransferDetail(tokenAddress, target common.Address, amount *big.Int, data string, isDirect bool, lockSecretHash common.Hash)

NewSentTransferDetail :

func (*StormDB) NewSettledChannel

func (model *StormDB) NewSettledChannel(c *channeltype.Serialization) error

NewSettledChannel save a settled channel to db

func (*StormDB) RegisterChannelDepositCallback

func (model *StormDB) RegisterChannelDepositCallback(f cb.ChannelCb)

RegisterChannelDepositCallback register channel deposit callback

func (*StormDB) RegisterChannelSettleCallback

func (model *StormDB) RegisterChannelSettleCallback(f cb.ChannelCb)

RegisterChannelSettleCallback notify when channel settled

func (*StormDB) RegisterChannelStateCallback

func (model *StormDB) RegisterChannelStateCallback(f cb.ChannelCb)

RegisterChannelStateCallback notify when channel closed

func (*StormDB) RegisterNewChannelCallback

func (model *StormDB) RegisterNewChannelCallback(f cb.ChannelCb)

RegisterNewChannelCallback register a new channel callback

func (*StormDB) RegisterNewTokenCallback

func (model *StormDB) RegisterNewTokenCallback(f cb.NewTokenCb)

RegisterNewTokenCallback register a new token callback

func (*StormDB) RemoveChannel

func (model *StormDB) RemoveChannel(c *channeltype.Serialization) error

RemoveChannel a settled channel from db

func (*StormDB) RemoveLock

func (model *StormDB) RemoveLock(channel common.Hash, sender common.Address, lockHash common.Hash)

RemoveLock remember this lock has been removed from channel status.

func (*StormDB) RemoveNonParticipantChannel

func (model *StormDB) RemoveNonParticipantChannel(channel common.Hash) error

RemoveNonParticipantChannel a channel is settled

func (*StormDB) SaveAck

func (model *StormDB) SaveAck(echoHash common.Hash, ack []byte, tx models.TX)

SaveAck save a new ack to db

func (*StormDB) SaveAckNoTx

func (model *StormDB) SaveAckNoTx(echoHash common.Hash, ack []byte)

SaveAckNoTx save a ack to db

func (*StormDB) SaveChainID

func (model *StormDB) SaveChainID(chainID int64)

SaveChainID :

func (*StormDB) SaveContractStatus

func (model *StormDB) SaveContractStatus(contractStatus models.ContractStatus)

SaveContractStatus save registry address to db

func (*StormDB) SaveEventToTXInfo

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

SaveEventToTXInfo 保存事件到TXInfo里面,当收到链上事件的时候调用 如果tx存在,保存事件到tx的事件列表里面 如果tx不存在,说明该tx非自己发起,直接创建success状态的tx并保存 TODO

func (*StormDB) SaveFeeChargeRecord

func (model *StormDB) SaveFeeChargeRecord(r *models.FeeChargeRecord) (err error)

SaveFeeChargeRecord :

func (*StormDB) SaveFeePolicy

func (model *StormDB) SaveFeePolicy(fp *models.FeePolicy) (err error)

SaveFeePolicy :

func (*StormDB) SaveLatestBlockNumber

func (model *StormDB) SaveLatestBlockNumber(blockNumber int64)

SaveLatestBlockNumber block numer has been processed

func (*StormDB) StartTx

func (model *StormDB) StartTx() (tx models.TX)

StartTx start a new tx of db

func (*StormDB) UnlockThisLock

func (model *StormDB) UnlockThisLock(channel common.Hash, lockHash common.Hash)

UnlockThisLock marks that I have withdrawed this secret on channel.

func (*StormDB) UpdateChannel

func (model *StormDB) UpdateChannel(c *channeltype.Serialization, tx models.TX) error

UpdateChannel update channel status in a Tx

func (*StormDB) UpdateChannelAndSaveAck

func (model *StormDB) UpdateChannelAndSaveAck(c *channeltype.Serialization, echohash common.Hash, ack []byte) (err error)

UpdateChannelAndSaveAck update channel and save ack, must atomic

func (*StormDB) UpdateChannelContractBalance

func (model *StormDB) UpdateChannelContractBalance(c *channeltype.Serialization) error

UpdateChannelContractBalance update channel balance

func (*StormDB) UpdateChannelNoTx

func (model *StormDB) UpdateChannelNoTx(c *channeltype.Serialization) error

UpdateChannelNoTx update channel status without a Tx

func (*StormDB) UpdateChannelState

func (model *StormDB) UpdateChannelState(c *channeltype.Serialization) error

UpdateChannelState update channel state ,close settle

func (*StormDB) UpdateSentTransferDetailStatus

func (model *StormDB) UpdateSentTransferDetailStatus(tokenAddress common.Address, lockSecretHash common.Hash, status models.TransferStatusCode, statusMessage string, otherParams interface{}) (transfer *models.SentTransferDetail)

UpdateSentTransferDetailStatus :

func (*StormDB) UpdateSentTransferDetailStatusMessage

func (model *StormDB) UpdateSentTransferDetailStatusMessage(tokenAddress common.Address, lockSecretHash common.Hash, statusMessage string) (transfer *models.SentTransferDetail)

UpdateSentTransferDetailStatusMessage :

func (*StormDB) UpdateTXInfoStatus

func (model *StormDB) UpdateTXInfoStatus(txHash common.Hash, status models.TXInfoStatus, packBlockNumber int64, gasUsed uint64) (txInfo *models.TXInfo, err error)

UpdateTXInfoStatus :

func (*StormDB) UpdateTokenNodes

func (model *StormDB) UpdateTokenNodes(token common.Address, nodes []common.Address) error

UpdateTokenNodes update all nodes that open channel

func (*StormDB) XMPPIsAddrSubed

func (model *StormDB) XMPPIsAddrSubed(addr common.Address) bool

XMPPIsAddrSubed return true when `addr` already subscirbed

func (*StormDB) XMPPMarkAddrSubed

func (model *StormDB) XMPPMarkAddrSubed(addr common.Address)

XMPPMarkAddrSubed mark `addr` subscribed

func (*StormDB) XMPPUnMarkAddr

func (model *StormDB) XMPPUnMarkAddr(addr common.Address)

XMPPUnMarkAddr mark `addr` has been unsubscribed

type StormTx

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

StormTx :

func (*StormTx) Commit

func (stx *StormTx) Commit() error

Commit :

func (*StormTx) Rollback

func (stx *StormTx) Rollback() error

Rollback :

func (*StormTx) Save

func (stx *StormTx) Save(v models.KeyGetter) error

Save :

func (*StormTx) Set

func (stx *StormTx) Set(table string, key interface{}, value interface{}) error

Set :

Jump to

Keyboard shortcuts

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