-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ADR-006 stage 2 * add telemetry * Update domain/telemetry.go * lint metrics
- Loading branch information
Showing
50 changed files
with
1,055 additions
and
1,414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package chaininforepo | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
// ChainInfoRepository represents the contract for a repository handling chain information | ||
type ChainInfoRepository interface { | ||
// StoreLatestHeight stores the latest blockchain height | ||
StoreLatestHeight(height uint64) | ||
|
||
// GetLatestHeight retrieves the latest blockchain height | ||
GetLatestHeight() uint64 | ||
} | ||
|
||
var _ ChainInfoRepository = &chainInfoRepo{} | ||
|
||
type chainInfoRepo struct { | ||
latestHeight uint64 | ||
mu sync.RWMutex | ||
} | ||
|
||
// New creates a new repository for chain information | ||
func New() ChainInfoRepository { | ||
return &chainInfoRepo{ | ||
latestHeight: 0, | ||
mu: sync.RWMutex{}, | ||
} | ||
} | ||
|
||
// StoreLatestHeight stores the latest blockchain height into store | ||
func (r *chainInfoRepo) StoreLatestHeight(height uint64) { | ||
r.mu.Lock() | ||
defer r.mu.Unlock() | ||
|
||
r.latestHeight = height | ||
} | ||
|
||
// GetLatestHeight retrieves the latest blockchain height store. | ||
func (r *chainInfoRepo) GetLatestHeight() uint64 { | ||
r.mu.RLock() | ||
defer r.mu.RUnlock() | ||
|
||
return r.latestHeight | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package chaininforepo_test | ||
|
||
import ( | ||
"testing" | ||
|
||
chaininforepo "github.com/osmosis-labs/sqs/chaininfo/repository" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestStoreAndGetLatestHeight tests storing the latest blockchain height | ||
func TestStoreAndGetLatestHeight(t *testing.T) { | ||
repo := chaininforepo.New() | ||
height := uint64(100) | ||
|
||
repo.StoreLatestHeight(height) | ||
|
||
require.Equal(t, height, repo.GetLatestHeight()) | ||
|
||
// change height | ||
height = 200 | ||
repo.StoreLatestHeight(height) | ||
|
||
require.Equal(t, height, repo.GetLatestHeight()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.