Skip to content

Commit

Permalink
Merge pull request #427 from insolar/MN-574-2
Browse files Browse the repository at this point in the history
NOISSUE: Merge MN-574-2 to the release/4.2
  • Loading branch information
pavlushev committed Sep 3, 2020
2 parents 412ef41 + 7634654 commit 33bb223
Show file tree
Hide file tree
Showing 118 changed files with 18,414 additions and 10,812 deletions.
35 changes: 16 additions & 19 deletions cmd/coin-market-cap-collector/main.go
Expand Up @@ -82,7 +82,6 @@ func main() {
Rank: stats.Rank,
MarketCap: stats.Quote.USD.MarketCap,
Volume24Hours: stats.Quote.USD.Volume24Hours,
CirculatingSupply: stats.CirculatingSupply,
Created: time.Now().UTC(),
})
if err != nil {
Expand All @@ -94,20 +93,19 @@ func main() {

// Calculates and replaces stats params
func replaceStats(stats *CmcInfo, db orm.DB) {
var circulatingFloat float64
var totalSupplyFloat float64
supplyStatsRepo := postgres.NewSupplyStatsRepository(db)
result, err := supplyStatsRepo.LastStats()
if err != nil {
circulatingFloat = 0
totalSupplyFloat = 0
} else {
circulatingFloat, err = strconv.ParseFloat(result.Total, 64)
totalSupplyFloat, err = strconv.ParseFloat(result.Total, 64)
if err != nil {
circulatingFloat = 0
totalSupplyFloat = 0
}
}
circulatingFloat /= 10000000000
stats.CirculatingSupply = circulatingFloat
stats.Quote.USD.MarketCap = circulatingFloat * stats.Quote.USD.Price
totalSupplyFloat /= 10000000000
stats.Quote.USD.MarketCap = totalSupplyFloat * stats.Quote.USD.Price
}

func initGlobalLogger(ctx context.Context, cfg insconf.Log) (context.Context, insolar.Logger) {
Expand Down Expand Up @@ -176,17 +174,16 @@ func getStats(token string, symbol string, logger insolar.Logger) *CmcInfo {
}

type CmcInfo struct {
ID int `json:"id"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Slug string `json:"slug"`
Rank int `json:"cmc_rank"`
CirculatingSupply float64 `json:"circulating_supply"`
TotalSupply float64 `json:"total_supply"`
MaxSupply float64 `json:"max_supply"`
LastUpdated time.Time `json:"last_updated"`
DateAdded time.Time `json:"date_added"`
Quote struct {
ID int `json:"id"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Slug string `json:"slug"`
Rank int `json:"cmc_rank"`
TotalSupply float64 `json:"total_supply"`
MaxSupply float64 `json:"max_supply"`
LastUpdated time.Time `json:"last_updated"`
DateAdded time.Time `json:"date_added"`
Quote struct {
USD struct {
Price float64 `json:"price"`
Volume24Hours float64 `json:"volume_24h"`
Expand Down
17 changes: 17 additions & 0 deletions cmd/stats-collector/main.go
Expand Up @@ -49,9 +49,26 @@ func main() {
logger.Fatal(err.Error())
}

calcSupply(logger, db)
calcNetwork(logger, db)
}

func calcSupply(log insolar.Logger, db *pg.DB) {
repo := postgres.NewSupplyStatsRepository(db)

stats, err := repo.CountStats()
if err != nil {
log.Fatal(errors.Wrapf(err, "failed to count supply stats"))
}

log.Debugf("collected supply stats: %+v", stats)

err = repo.InsertStats(stats)
if err != nil {
log.Fatal(errors.Wrapf(err, "failed to save supply stats"))
}
}

func calcNetwork(log insolar.Logger, db *pg.DB) {
repo := postgres.NewNetworkStatsRepository(db)

Expand Down
4 changes: 4 additions & 0 deletions component/beautifier_test.go
Expand Up @@ -22,8 +22,10 @@ import (
"github.com/insolar/insolar/ledger/heavy/exporter"
"github.com/insolar/insolar/log"
"github.com/insolar/insolar/logicrunner/builtin/foundation"
"github.com/insolar/mainnet/application/appfoundation"
"github.com/insolar/mainnet/application/builtin/contract/deposit"
"github.com/insolar/mainnet/application/builtin/proxy/migrationdaemon"
"github.com/insolar/observer/internal/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -187,6 +189,7 @@ func TestBeautifier_Deposit(t *testing.T) {
PulseDepositUnHold: pn + 10,
Vesting: 10,
VestingStep: 10,
VestingType: appfoundation.DefaultVesting,
}
memory, err := insolar.Serialize(dep)
if err != nil {
Expand Down Expand Up @@ -236,6 +239,7 @@ func TestBeautifier_Deposit(t *testing.T) {
DepositState: act.Record.ID,
Vesting: 10,
VestingStep: 10,
VestingType: models.DepositTypeNonLinear,
},
}, res.deposits)
assert.Equal(t, map[insolar.Reference]observer.DepositMemberUpdate{
Expand Down
7 changes: 7 additions & 0 deletions component/storer_test.go
Expand Up @@ -312,6 +312,7 @@ func TestStoreSimpleDeposit(t *testing.T) {
Vesting: 10,
VestingStep: 5,
InnerStatus: models.DepositStatusCreated,
VestingType: models.DepositTypeNonLinear,
},
}

Expand All @@ -330,6 +331,7 @@ func TestStoreSimpleDeposit(t *testing.T) {
DepositState: *insolar.NewIDFromBytes(expectedDeposit[0].State),
Vesting: expectedDeposit[0].Vesting,
VestingStep: expectedDeposit[0].VestingStep,
VestingType: expectedDeposit[0].VestingType,
DepositNumber: 100,
})
if err != nil {
Expand Down Expand Up @@ -375,6 +377,7 @@ func TestStoreSeveralDepositsWithDepositsNumbers(t *testing.T) {
VestingStep: 5,
Timestamp: transferDate,
DepositNumber: newInt(1),
VestingType: models.DepositTypeNonLinear,
},
{
Reference: ref.Bytes(),
Expand All @@ -388,6 +391,7 @@ func TestStoreSeveralDepositsWithDepositsNumbers(t *testing.T) {
VestingStep: 5,
Timestamp: transferDate,
DepositNumber: newInt(2),
VestingType: models.DepositTypeNonLinear,
},
{
Reference: gen.RecordReference().Bytes(),
Expand All @@ -401,6 +405,7 @@ func TestStoreSeveralDepositsWithDepositsNumbers(t *testing.T) {
VestingStep: 5,
Timestamp: transferDate,
DepositNumber: newInt(1),
VestingType: models.DepositTypeNonLinear,
},
}

Expand All @@ -421,6 +426,7 @@ func TestStoreSeveralDepositsWithDepositsNumbers(t *testing.T) {
Vesting: dep.Vesting,
VestingStep: dep.VestingStep,
DepositNumber: *dep.DepositNumber,
VestingType: models.DepositTypeNonLinear,
})
if err != nil {
return err
Expand Down Expand Up @@ -525,6 +531,7 @@ func TestStorerOK(t *testing.T) {
DepositState: gen.ID(),
Vesting: 10,
VestingStep: 10,
VestingType: models.DepositTypeNonLinear,
},
},
}, &state{})
Expand Down
9 changes: 4 additions & 5 deletions configuration/api.go
Expand Up @@ -26,11 +26,10 @@ type APIConfig interface {
}

type CMCMarketStatsParamsEnabled struct {
CirculatingSupply bool
DailyChange bool
MarketCap bool
Rank bool
Volume bool
DailyChange bool
MarketCap bool
Rank bool
Volume bool
}

type API struct {
Expand Down
9 changes: 4 additions & 5 deletions configuration/api_extended.go
Expand Up @@ -42,11 +42,10 @@ func (APIExtended) Default() *APIExtended {
Price: "0.05",
PriceOrigin: "const", // const|binance|coin_market_cap
CMCMarketStatsParams: CMCMarketStatsParamsEnabled{
CirculatingSupply: true,
DailyChange: true,
MarketCap: true,
Rank: true,
Volume: true,
DailyChange: true,
MarketCap: true,
Rank: true,
Volume: true,
},
}
}
Expand Down
1 change: 0 additions & 1 deletion configuration/testdata/observerapi.yaml
Expand Up @@ -8,7 +8,6 @@ feeamount: 2000000000
priceorigin: const
price: "0.05"
cmcmarketstatsparams:
circulatingsupply: false
dailychange: false
marketcap: false
rank: false
Expand Down
11 changes: 3 additions & 8 deletions go.mod
Expand Up @@ -14,13 +14,11 @@ require (
github.com/google/uuid v1.1.1
github.com/hashicorp/golang-lru v0.5.3
github.com/insolar/insconfig v0.0.0-20200227134411-011eca6dc866
github.com/insolar/insolar v1.7.2
github.com/insolar/mainnet v1.10.2
github.com/insolar/insolar v1.7.3
github.com/insolar/mainnet v1.11.0
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/labstack/echo/v4 v4.1.11
github.com/mitchellh/mapstructure v1.1.2
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/onsi/ginkgo v1.10.2 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/ory/dockertest/v3 v3.5.2
Expand All @@ -29,13 +27,10 @@ require (
github.com/prometheus/client_golang v1.1.0
github.com/prometheus/common v0.7.0 // indirect
github.com/prometheus/procfs v0.0.5 // indirect
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.6.1
go.opencensus.io v0.22.1 // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582 // indirect
golang.org/x/sys v0.0.0-20191020212454-3e7259c5e7c2 // indirect
gonum.org/v1/gonum v0.6.0 // indirect
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 // indirect
google.golang.org/grpc v1.21.0
gopkg.in/yaml.v2 v2.2.8
Expand Down

0 comments on commit 33bb223

Please sign in to comment.