Add doc comments

This commit is contained in:
Nick Johnson 2018-09-25 14:50:04 +01:00
parent 18090ea4ed
commit cf2039fe62
4 changed files with 16 additions and 0 deletions

View file

@ -319,6 +319,9 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
return nil return nil
} }
// getBlockHash returns the block hash of the requested block.
// `hash` is used if supplied; if not the canonoical block at `number` is looked up.
// If neither is supplied, the latest canonical block hash is returned.
func (b *SimulatedBackend) getBlockHash(number *big.Int, hash *common.Hash) (common.Hash, error) { func (b *SimulatedBackend) getBlockHash(number *big.Int, hash *common.Hash) (common.Hash, error) {
if hash != nil { if hash != nil {
return *hash, nil return *hash, nil

View file

@ -320,6 +320,9 @@ func (api *PublicFilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) {
return logsSub.ID, nil return logsSub.ID, nil
} }
// getBlockHash returns the block hash of the requested block.
// `hash` is used if supplied; if not the canonoical block at `number` is looked up.
// If neither is supplied, the latest canonical block hash is returned.
func (api *PublicFilterAPI) getBlockHash(ctx context.Context, number *big.Int, hash *common.Hash) (common.Hash, error) { func (api *PublicFilterAPI) getBlockHash(ctx context.Context, number *big.Int, hash *common.Hash) (common.Hash, error) {
if hash != nil { if hash != nil {
return *hash, nil return *hash, nil

View file

@ -115,6 +115,9 @@ func newFilter(backend Backend, addresses []common.Address, topics [][]common.Ha
} }
} }
// findCommonAncestor returns the highest numbered block that is the ancestor of
// both `begin` and `end`. `end` must have a block number greater than or equal
// to `begin`.
func (f *Filter) findCommonAncestor(ctx context.Context, begin, end *types.Header) (*types.Header, bool, error) { func (f *Filter) findCommonAncestor(ctx context.Context, begin, end *types.Header) (*types.Header, bool, error) {
var err error var err error
var mainChain bool var mainChain bool
@ -153,6 +156,7 @@ func (f *Filter) findCommonAncestor(ctx context.Context, begin, end *types.Heade
return end, mainChain, nil return end, mainChain, nil
} }
// logList allows sorting event logs by block number and log index
type logList []*types.Log type logList []*types.Log
func (l logList) Len() int { return len(l) } func (l logList) Len() int { return len(l) }

View file

@ -165,17 +165,22 @@ func (bn BlockNumber) Int64() int64 {
return (int64)(bn) return (int64)(bn)
} }
// BlockNumberOrHash permits JSON deserialization and parsing of a value that
// can be either a block number or block hash.
type BlockNumberOrHash string type BlockNumberOrHash string
// UnmarshalJSON parses the supplied JSON fragment as a BlockNumberOrHash.
func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error { func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
*bnh = BlockNumberOrHash(data) *bnh = BlockNumberOrHash(data)
return nil return nil
} }
// IsHash returns true iff the value is a block hash.
func (bnh BlockNumberOrHash) IsHash() bool { func (bnh BlockNumberOrHash) IsHash() bool {
return bnh[0] == '"' && bnh[len(bnh)-1] == '"' && len(bnh) == 44 return bnh[0] == '"' && bnh[len(bnh)-1] == '"' && len(bnh) == 44
} }
// Hash returns the hash value, or nil if the value is not a hash.
func (bnh BlockNumberOrHash) Hash() *common.Hash { func (bnh BlockNumberOrHash) Hash() *common.Hash {
if !bnh.IsHash() { if !bnh.IsHash() {
return nil return nil
@ -184,6 +189,7 @@ func (bnh BlockNumberOrHash) Hash() *common.Hash {
return &hash return &hash
} }
// Number returns the numeric value, or 0 if the value is not numeric.
func (bnh BlockNumberOrHash) Number() int64 { func (bnh BlockNumberOrHash) Number() int64 {
var bn BlockNumber var bn BlockNumber
(&bn).UnmarshalJSON([]byte(bnh)) (&bn).UnmarshalJSON([]byte(bnh))