Skip to content

Commit

Permalink
move chain indexing to astra indexing (#1)
Browse files Browse the repository at this point in the history
* move chain indexing to astra indexing

* add metrics block height
  • Loading branch information
hoanguyenkh committed Sep 29, 2022
1 parent 2c8ea0b commit 28b751a
Show file tree
Hide file tree
Showing 861 changed files with 549,607 additions and 123 deletions.
28 changes: 23 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# OS
.DS_Store

# IDE
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
.idea/*

# Local History for Visual Studio Code
.history/

# Binaries for programs and plugins
*.exe
*.exe~
Expand All @@ -8,12 +23,15 @@
# Test binary, built with `go test -c`
*.test

# Rust build
target/
# Go build
bin/

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

.idea
config/config.yaml
log/
*.log
.env

60 changes: 60 additions & 0 deletions appinterface/cosmosapp/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package cosmosapp

const ACCOUNT_MODULE = "/cosmos.auth.v1beta1.ModuleAccount"
const ACCOUNT_BASE = "/cosmos.auth.v1beta1.BaseAccount"
const ACCOUNT_VESTING_DELAYED = "/cosmos.vesting.v1beta1.DelayedVestingAccount"
const ACCOUNT_VESTING_CONTINUOUS = "/cosmos.vesting.v1beta1.ContinuousVestingAccount"
const ACCOUNT_VESTING_PERIODIC = "/cosmos.vesting.v1beta1.PeriodicVestingAccount"
const ACCOUNT_ETHERMINT = "/ethermint.types.v1.EthAccount"

type Account struct {
Type string `json:"type"`
Address string `json:"address"`
MaybePubkey *PubKey `json:"pubkey"`
AccountNumber string `json:"account_number"`
Sequence string `json:"sequence"`

MaybeModuleAccount *ModuleAccount `json:"module_account"`
MaybeDelayedVestingAccount *DelayedVestingAccount `json:"delayed_vesting_account"`
MaybeContinuousVestingAccount *ContinuousVestingAccount `json:"continuous_vesting_account"`
MaybePeriodicVestingAccount *PeriodicVestingAccount `json:"periodic_vesting_account"`
}

type ModuleAccount struct {
Name string `json:"name"`
Permissions []string `json:"permissions"`
}

type DelayedVestingAccount struct {
OriginalVesting []VestingBalance `json:"original_vesting"`
DelegatedFree []VestingBalance `json:"delegated_free"`
DelegatedVesting []VestingBalance `json:"delegated_vesting"`
EndTime string `json:"end_time"`
}

type ContinuousVestingAccount struct {
OriginalVesting []VestingBalance `json:"original_vesting"`
DelegatedFree []VestingBalance `json:"delegated_free"`
DelegatedVesting []VestingBalance `json:"delegated_vesting"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
}

type PeriodicVestingAccount struct {
OriginalVesting []VestingBalance `json:"original_vesting"`
DelegatedFree []VestingBalance `json:"delegated_free"`
DelegatedVesting []VestingBalance `json:"delegated_vesting"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
VestingPeriods []VestingPeriod `json:"vesting_periods"`
}

type VestingPeriod struct {
Amount []VestingBalance `json:"amount"`
Length string `json:"length"`
}

type VestingBalance struct {
Denom string `json:"denom"`
Amount string `json:"amount"`
}
35 changes: 35 additions & 0 deletions appinterface/cosmosapp/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cosmosapp

import (
"errors"

"github.com/AstraProtocol/astra-indexing/usecase/coin"
"github.com/AstraProtocol/astra-indexing/usecase/model"
)

type Client interface {
Account(accountAddress string) (*Account, error)
Balances(accountAddress string) (coin.Coins, error)
BondedBalance(accountAddress string) (coin.Coins, error)
RedelegatingBalance(accountAddress string) (coin.Coins, error)
UnbondingBalance(accountAddress string) (coin.Coins, error)

TotalRewards(accountAddress string) (coin.DecCoins, error)
Commission(validatorAddress string) (coin.DecCoins, error)

Validator(validatorAddress string) (*Validator, error)
Delegation(delegator string, validator string) (*DelegationResponse, error)
TotalBondedBalance() (coin.Coin, error)

AnnualProvisions() (coin.DecCoin, error)

Proposals() ([]Proposal, error)
ProposalById(id string) (Proposal, error)
ProposalTally(id string) (Tally, error)

Tx(txHash string) (*model.Tx, error)
}

var ErrAccountNotFound = errors.New("account not found")
var ErrAccountNoDelegation = errors.New("account has no delegation")
var ErrProposalNotFound = errors.New("proposal not found")
17 changes: 17 additions & 0 deletions appinterface/cosmosapp/delegation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cosmosapp

type DelegationResponse struct {
Delegation Delegation `json:"delegation"`
Balance DelegationBalance `json:"balance"`
}

type Delegation struct {
DelegatorAddress string `json:"delegator_address"`
ValidatorAddress string `json:"validator_address"`
Shares string `json:"shares"`
}

type DelegationBalance struct {
Denom string `json:"denom"`
Amount string `json:"amount"`
}
102 changes: 102 additions & 0 deletions appinterface/cosmosapp/mockclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package cosmosapp

import (
"github.com/AstraProtocol/astra-indexing/usecase/coin"
"github.com/AstraProtocol/astra-indexing/usecase/model"
"github.com/stretchr/testify/mock"
)

type MockClient struct {
mock.Mock
}

func NewMockClient() *MockClient {
return &MockClient{}
}

func (conn *MockClient) Account(accountAddress string) (*Account, error) {
mockArgs := conn.Called(accountAddress)
result, _ := mockArgs.Get(0).(*Account)
return result, mockArgs.Error(1)
}

func (conn *MockClient) Balances(accountAddress string) (coin.Coins, error) {
mockArgs := conn.Called(accountAddress)
result, _ := mockArgs.Get(0).(coin.Coins)
return result, mockArgs.Error(1)
}

func (conn *MockClient) BondedBalance(accountAddress string) (coin.Coins, error) {
mockArgs := conn.Called(accountAddress)
result, _ := mockArgs.Get(0).(coin.Coins)
return result, mockArgs.Error(1)
}

func (conn *MockClient) RedelegatingBalance(accountAddress string) (coin.Coins, error) {
mockArgs := conn.Called(accountAddress)
result, _ := mockArgs.Get(0).(coin.Coins)
return result, mockArgs.Error(1)
}

func (conn *MockClient) UnbondingBalance(accountAddress string) (coin.Coins, error) {
mockArgs := conn.Called(accountAddress)
result, _ := mockArgs.Get(0).(coin.Coins)
return result, mockArgs.Error(1)
}

func (conn *MockClient) TotalRewards(accountAddress string) (coin.DecCoins, error) {
mockArgs := conn.Called(accountAddress)
result, _ := mockArgs.Get(0).(coin.DecCoins)
return result, mockArgs.Error(1)
}

func (conn *MockClient) Commission(validatorAddress string) (coin.DecCoins, error) {
mockArgs := conn.Called(validatorAddress)
result, _ := mockArgs.Get(0).(coin.DecCoins)
return result, mockArgs.Error(1)
}

func (conn *MockClient) Validator(validatorAddress string) (*Validator, error) {
mockArgs := conn.Called(validatorAddress)
result, _ := mockArgs.Get(0).(*Validator)
return result, mockArgs.Error(1)
}

func (conn *MockClient) Delegation(delegator string, validator string) (*DelegationResponse, error) {
mockArgs := conn.Called(delegator, validator)
result, _ := mockArgs.Get(0).(*DelegationResponse)
return result, mockArgs.Error(1)
}

func (conn *MockClient) TotalBondedBalance() (coin.Coin, error) {
args := conn.Called()
return args.Get(0).(coin.Coin), args.Error(1)
}

func (conn *MockClient) AnnualProvisions() (coin.DecCoin, error) {
args := conn.Called()
return args.Get(0).(coin.DecCoin), args.Error(1)
}

func (conn *MockClient) Proposals() ([]Proposal, error) {
args := conn.Called()
return args.Get(0).([]Proposal), args.Error(1)
}

func (conn *MockClient) ProposalById(id string) (Proposal, error) {
mockArgs := conn.Called(id)
result, _ := mockArgs.Get(0).(Proposal)
return result, mockArgs.Error(1)
}

func (conn *MockClient) ProposalTally(id string) (Tally, error) {
mockArgs := conn.Called(id)
result, _ := mockArgs.Get(0).(Tally)
return result, mockArgs.Error(1)
}

func (conn *MockClient) Tx(txHash string) (*model.Tx, error) {
mockArgs := conn.Called(txHash)
result, _ := mockArgs.Get(0).(*model.Tx)
return result, mockArgs.Error(1)
}
45 changes: 45 additions & 0 deletions appinterface/cosmosapp/proposal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cosmosapp

type Proposal struct {
ProposalID string `json:"proposal_id"`
Content Content `json:"content"`
Status string `json:"status"`
FinalTallyResult FinalTallyResult `json:"final_tally_result"`
SubmitTime string `json:"submit_time"`
DepositEndTime string `json:"deposit_end_time"`
TotalDeposit []TotalDeposit `json:"total_deposit"`
VotingStartTime string `json:"voting_start_time"`
VotingEndTime string `json:"voting_end_time"`
}

type Content struct {
Type string `json:"@type"`
Title string `json:"title"`
Description string `json:"description"`
Changes []Change `json:"changes"`
}

type Change struct {
Subspace string `json:"subspace"`
Key string `json:"key"`
Value string `json:"value"`
}

type FinalTallyResult struct {
Yes string `json:"yes"`
Abstain string `json:"abstain"`
No string `json:"no"`
NoWithVeto string `json:"no_with_veto"`
}

type TotalDeposit struct {
Denom string `json:"denom"`
Amount string `json:"amount"`
}

type Tally struct {
Yes string `json:"yes"`
Abstain string `json:"abstain"`
No string `json:"no"`
NoWithVeto string `json:"no_with_veto"`
}
6 changes: 6 additions & 0 deletions appinterface/cosmosapp/pubkey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cosmosapp

type PubKey struct {
Type string `json:"@type"`
Key string `json:"key"`
}
34 changes: 34 additions & 0 deletions appinterface/cosmosapp/validator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cosmosapp

type Validator struct {
OperatorAddress string `json:"operator_address"`
ConsensusPubkey PubKey `json:"consensus_pubkey"`
Jailed bool `json:"jailed"`
Status string `json:"status"`
Tokens string `json:"tokens"`
DelegatorShares string `json:"delegator_shares"`
Description ValidatorDescription `json:"description"`
UnbondingHeight string `json:"unbonding_height"`
UnbondingTime string `json:"unbonding_time"`
Commission ValidatorCommission `json:"commission"`
MinSelfDelegation string `json:"min_self_delegation"`
}

type ValidatorCommission struct {
CommissionRates ValidatorCommissionRates `json:"commission_rates"`
UpdateTime string `json:"update_time"`
}

type ValidatorCommissionRates struct {
Rate string `json:"rate"`
MaxRate string `json:"max_rate"`
MaxChangeRate string `json:"max_change_rate"`
}

type ValidatorDescription struct {
Moniker string `json:"moniker"`
Identity string `json:"identity"`
Website string `json:"website"`
SecurityContact string `json:"security_contact"`
Details string `json:"details"`
}
13 changes: 13 additions & 0 deletions appinterface/event/rdbeventstore_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package event_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestEvent(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Event Suite")
}
Loading

0 comments on commit 28b751a

Please sign in to comment.