-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit for DexScreener POC * Added some boilerplate items to be integrated with the core ingestion logic * feat: Indexer service wiring (#8385) * feat: Indexer service wiring * wire supply listener * working version * progress * Added config for indexer service and wiring up app init sequences * feat(indexer): proper supply offset handling (#8404) * feat(indexer): proper supply offset handling * lint * test: token supply write listener (#8405) * test: token supply write listener * updates * feat: rename ingester to publisher, added block publishing code (#8407) * Rename ingester to publisher. Added block publishing code * additional renaming needed for publisher * Fixed lint --------- Co-authored-by: Calvin <calvin@osmosis.team> * Fixed compilation error after merge * clean up app.go * clean up --------- Co-authored-by: Calvin <calvin@osmosis.team> Co-authored-by: Calvin <1727450+cryptomatictrader@users.noreply.github.com>
- Loading branch information
1 parent
a1bf555
commit 32a78ad
Showing
18 changed files
with
869 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package domain | ||
|
||
import "time" | ||
|
||
type Block struct { | ||
ChainId string `json:"chain_id"` | ||
Height uint64 `json:"height"` | ||
BlockTime time.Time `json:"timestamp"` | ||
GasConsumed uint64 `json:"gas_consumed"` | ||
} |
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,29 @@ | ||
package domain | ||
|
||
// ColdStartManager is an interface for managing the cold start state of the indexer. | ||
type ColdStartManager interface { | ||
// HasIngestedInitialData returns true if the indexer has ingested the initial data. | ||
HasIngestedInitialData() bool | ||
|
||
// MarkInitialDataIngested marks the initial data as ingested. | ||
MarkInitialDataIngested() | ||
} | ||
|
||
type coldStartManager struct { | ||
hasIngestedInitialData bool | ||
} | ||
|
||
var _ ColdStartManager = &coldStartManager{} | ||
|
||
// NewColdStartManager creates a new cold start manager. | ||
func NewColdStartManager() ColdStartManager { | ||
return &coldStartManager{} | ||
} | ||
|
||
func (c *coldStartManager) HasIngestedInitialData() bool { | ||
return c.hasIngestedInitialData | ||
} | ||
|
||
func (c *coldStartManager) MarkInitialDataIngested() { | ||
c.hasIngestedInitialData = true | ||
} |
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,5 @@ | ||
package domain | ||
|
||
import "errors" | ||
|
||
var ErrColdStartManagerDidNotIngest = errors.New("cold start manager has not yet ingested initial data") |
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,9 @@ | ||
package domain | ||
|
||
import ( | ||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
) | ||
|
||
type Keepers struct { | ||
BankKeeper bankkeeper.Keeper | ||
} |
32 changes: 32 additions & 0 deletions
32
ingest/indexer/domain/mocks/token_supply_publisher_mock.go
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,32 @@ | ||
package mocks | ||
|
||
import ( | ||
"context" | ||
|
||
indexerdomain "github.com/osmosis-labs/osmosis/v25/ingest/indexer/domain" | ||
) | ||
|
||
// TokenSupplyPublisherMock is a mock for TokenSupplyPublisher. | ||
type TokenSupplyPublisherMock struct { | ||
CalledWithTokenSupply indexerdomain.TokenSupply | ||
ForceTokenSupplyError error | ||
|
||
CalledWithTokenSupplyOffset indexerdomain.TokenSupplyOffset | ||
ForceTokenSupplyOffsetError error | ||
} | ||
|
||
// PublishTokenSupply implements domain.PubSubClientI. | ||
func (p *TokenSupplyPublisherMock) PublishTokenSupply(ctx context.Context, tokenSupply indexerdomain.TokenSupply) error { | ||
p.CalledWithTokenSupply = tokenSupply | ||
return p.ForceTokenSupplyError | ||
} | ||
|
||
// PublishTokenSupplyOffset implements domain.PubSubClientI. | ||
func (p *TokenSupplyPublisherMock) PublishTokenSupplyOffset(ctx context.Context, tokenSupplyOffset indexerdomain.TokenSupplyOffset) error { | ||
p.CalledWithTokenSupplyOffset = tokenSupplyOffset | ||
return p.ForceTokenSupplyOffsetError | ||
} | ||
|
||
var ( | ||
_ indexerdomain.TokenSupplyPublisher = (*TokenSupplyPublisherMock)(nil) | ||
) |
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,5 @@ | ||
package domain | ||
|
||
type Pool struct { | ||
// TBD | ||
} |
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,20 @@ | ||
package domain | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// TokenSupplyPublisher is an interface for publishing token supply data. | ||
type TokenSupplyPublisher interface { | ||
PublishTokenSupply(ctx context.Context, tokenSupply TokenSupply) error | ||
PublishTokenSupplyOffset(ctx context.Context, tokenSupplyOffset TokenSupplyOffset) error | ||
} | ||
|
||
// Publisher is an interface for publishing various types of data. | ||
type Publisher interface { | ||
TokenSupplyPublisher | ||
|
||
PublishBlock(ctx context.Context, block Block) error | ||
PublishTransaction(ctx context.Context, txn Transaction) error | ||
PublishPool(ctx context.Context, pool Pool) error | ||
} |
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,13 @@ | ||
package domain | ||
|
||
import "github.com/osmosis-labs/osmosis/osmomath" | ||
|
||
type TokenSupply struct { | ||
Denom string `json:"denom"` | ||
Supply osmomath.Int `json:"supply"` | ||
} | ||
|
||
type TokenSupplyOffset struct { | ||
Denom string `json:"denom"` | ||
SupplyOffset osmomath.Int `json:"supply_offset"` | ||
} |
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,5 @@ | ||
package domain | ||
|
||
type Transaction struct { | ||
// TBD | ||
} |
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,59 @@ | ||
package indexer | ||
|
||
import ( | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
|
||
"github.com/osmosis-labs/osmosis/osmoutils" | ||
"github.com/osmosis-labs/osmosis/v25/ingest/indexer/domain" | ||
service "github.com/osmosis-labs/osmosis/v25/ingest/indexer/service/client" | ||
) | ||
|
||
// Config defines the config for the indexer. | ||
type Config struct { | ||
IsEnabled bool `mapstructure:"enabled"` | ||
GCPProjectId string `mapstructure:"gcp-project-id"` | ||
BlockTopicId string `mapstructure:"block-topic-id"` | ||
TransactionTopicId string `mapstructure:"transaction-topic-id"` | ||
PoolTopicId string `mapstructure:"pool-topic-id"` | ||
TokenSupplyTopicId string `mapstructure:"token-supply-topic-id"` | ||
TokenSupplyOffsetTopicId string `mapstructure:"token-supply-offset-topic-id"` | ||
} | ||
|
||
// groupOptName is the name of the indexer options group. | ||
const ( | ||
groupOptName = "osmosis-indexer" | ||
) | ||
|
||
// NewConfigFromOptions returns a new indexer config from the given options. | ||
func NewConfigFromOptions(opts servertypes.AppOptions) Config { | ||
isEnabled := osmoutils.ParseBool(opts, groupOptName, "is-enabled", false) | ||
|
||
if !isEnabled { | ||
return Config{ | ||
IsEnabled: false, | ||
} | ||
} | ||
|
||
gcpProjectId := osmoutils.ParseString(opts, groupOptName, "gcp-project-id") | ||
blockTopicId := osmoutils.ParseString(opts, groupOptName, "block-topic-id") | ||
transactionTopicId := osmoutils.ParseString(opts, groupOptName, "transaction-topic-id") | ||
poolTopicId := osmoutils.ParseString(opts, groupOptName, "pool-topic-id") | ||
tokenSupplyTopicId := osmoutils.ParseString(opts, groupOptName, "token-supply-topic-id") | ||
tokenSupplyOffsetTopicId := osmoutils.ParseString(opts, groupOptName, "token-supply-offset-topic-id") | ||
|
||
return Config{ | ||
IsEnabled: isEnabled, | ||
GCPProjectId: gcpProjectId, | ||
BlockTopicId: blockTopicId, | ||
TransactionTopicId: transactionTopicId, | ||
PoolTopicId: poolTopicId, | ||
TokenSupplyTopicId: tokenSupplyTopicId, | ||
TokenSupplyOffsetTopicId: tokenSupplyOffsetTopicId, | ||
} | ||
} | ||
|
||
// Initialize initializes the indexer by creating a new PubSubClient and returning a new IndexerIngester. | ||
func (c Config) Initialize() domain.Publisher { | ||
pubSubClient := service.NewPubSubCLient(c.GCPProjectId, c.BlockTopicId, c.TransactionTopicId, c.PoolTopicId, c.TokenSupplyTopicId, c.TokenSupplyOffsetTopicId) | ||
return NewIndexerPublisher(*pubSubClient) | ||
} |
Oops, something went wrong.