Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
millken committed Apr 19, 2023
1 parent 3fb9a0f commit 679d327
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions blockindex/sgd.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,20 @@ func (sgd *sgdRegistry) DeleteTipBlock(context.Context, *block.Block) error {

// CheckContract checks if the contract is a SGD contract
func (sgd *sgdRegistry) CheckContract(contract string) (address.Address, uint64, bool) {
sgdIndex, err := sgd.GetSGDIndex(contract)
if err != nil {
return nil, 0, false
var (
sgdIndex *indexpb.SGDIndex
err error
)
//check if the SGDIndex is in cache
if v, ok := sgd.kvCache.Get(contract); ok {
sgdIndex = v.(*indexpb.SGDIndex)
} else {
sgdIndex, err = sgd.GetSGDIndex(contract)
if err != nil {
return nil, 0, false
}
}

addr, err := address.FromString(sgdIndex.Receiver)
if err != nil {
// if the receiver is no set or invalid
Expand All @@ -174,10 +184,6 @@ func (sgd *sgdRegistry) CheckContract(contract string) (address.Address, uint64,

// GetSGDIndex returns the SGDIndex of the contract
func (sgd *sgdRegistry) GetSGDIndex(contract string) (*indexpb.SGDIndex, error) {
//check if the SGDIndex is in cache
if v, ok := sgd.kvCache.Get(contract); ok {
return v.(*indexpb.SGDIndex), nil
}
//if not in cache, get it from db
buf, err := sgd.kvStore.Get(_sgdBucket, []byte(contract))
if err != nil {
Expand Down

0 comments on commit 679d327

Please sign in to comment.