-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aggregator should be writing the queue items
- Loading branch information
1 parent
871bd31
commit 4571972
Showing
6 changed files
with
113 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package aggregator | ||
|
||
import ( | ||
tokenAggregator "github.com/bluzelle/curium/x/oracle/aggregators/token" | ||
"github.com/bluzelle/curium/x/oracle/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
var aggregators = []Aggregator{ | ||
tokenAggregator.NewTokenAggregator(), | ||
} | ||
|
||
func NotifyAggregators(ctx sdk.Context, value types.SourceValue, updateFn func(prefix []byte, key []byte, value interface{})) { | ||
for _, aggregator := range aggregators { | ||
aggregator.SourceValueUpdated(ctx, value, updateFn) | ||
} | ||
} | ||
|
||
|
||
type Aggregator interface { | ||
SourceValueUpdated(ctx sdk.Context, value types.SourceValue, updateFn func(prefix []byte, key []byte, value interface{})) | ||
} | ||
|
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,54 @@ | ||
package aggregators | ||
|
||
import ( | ||
"fmt" | ||
"github.com/bluzelle/curium/x/oracle/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"strings" | ||
) | ||
|
||
var queueStoreKey = types.NewOracleStoreKey(0x10) | ||
|
||
type TokenAggregator struct { | ||
} | ||
|
||
type AggregatorValue struct { | ||
Batch string | ||
Symbol string | ||
InSymbol string | ||
Value sdk.Dec | ||
Count int64 | ||
Height int64 | ||
} | ||
|
||
type AggregatorQueueItem struct { | ||
SourceName string | ||
Batch string | ||
Symbol string | ||
InSymbol string | ||
Value sdk.Dec | ||
Height int64 | ||
Weight int64 | ||
} | ||
|
||
func NewTokenAggregator() TokenAggregator { | ||
return TokenAggregator{} | ||
} | ||
|
||
func (ta TokenAggregator) SourceValueUpdated(ctx sdk.Context, value types.SourceValue, updateFn func(prefix []byte, key []byte, value interface{})) { | ||
fmt.Println(ctx, value) | ||
parts := strings.Split(value.SourceName, "-") | ||
aggQueueItem := AggregatorQueueItem{ | ||
Batch: value.Batch, | ||
SourceName: value.SourceName, | ||
Symbol: parts[1], | ||
InSymbol: parts[3], | ||
Value: value.Value, | ||
Height: value.Height, | ||
Weight: value.Weight, | ||
} | ||
|
||
blockStr := fmt.Sprintf("%020d", aggQueueItem.Height) | ||
key := queueStoreKey.MakeKey(blockStr, aggQueueItem.Batch, aggQueueItem.SourceName) | ||
updateFn(queueStoreKey.Prefix, key, aggQueueItem) | ||
} |
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,12 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (k Keeper) StoreAggregatorValue(ctx sdk.Context, key []byte, value []byte) error { | ||
// TODO: finish here | ||
fmt.Println(ctx, key, value) | ||
return 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
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