Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions appinterface/cosmosapp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ import (
)

type Client interface {
Account(accountAddress string) (*Account, error)
Balances(accountAddress string) (coin.Coins, error)
BalanceByDenom(accountAddresss string, denom string) (coin.Coin, error)
BondedBalance(accountAddress string) (coin.Coins, error)
RedelegatingBalance(accountAddress string) (coin.Coins, error)
UnbondingBalance(accountAddress string) (coin.Coins, error)
Account(accountAddress string, cosmosAPIVersion string) (*Account, error)
Balances(accountAddress string, cosmosAPIVersion string) (coin.Coins, error)
BalanceByDenom(accountAddresss string, denom string, cosmosAPIVersion string) (coin.Coin, error)
BondedBalance(accountAddress string, cosmosAPIVersion string) (coin.Coins, error)
RedelegatingBalance(accountAddress string, cosmosAPIVersion string) (coin.Coins, error)
UnbondingBalance(accountAddress string, cosmosAPIVersion string) (coin.Coins, error)

SupplyByDenom(denom string) (coin.Coin, error)
SupplyByDenom(denom string, cosmosAPIVersion string) (coin.Coin, error)

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

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

AnnualProvisions() (coin.DecCoin, error)
AnnualProvisions(cosmosAPIVersion string) (coin.DecCoin, error)

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

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

var ErrAccountNotFound = errors.New("account not found")
Expand Down
76 changes: 38 additions & 38 deletions appinterface/cosmosapp/mockclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,112 +16,112 @@ func NewMockClient() *MockClient {
return &MockClient{}
}

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

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

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

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

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

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

func (conn *MockClient) SupplyByDenom(denom string) (coin.Coin, error) {
mockArgs := conn.Called(denom)
func (conn *MockClient) SupplyByDenom(denom string, cosmosAPIVersion string) (coin.Coin, error) {
mockArgs := conn.Called(denom, cosmosAPIVersion)
result, _ := mockArgs.Get(0).(coin.Coin)
return result, mockArgs.Error(1)
}

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

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

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

func (conn *MockClient) Validator(validatorAddress string) (*Validator, error) {
mockArgs := conn.Called(validatorAddress)
func (conn *MockClient) Validator(validatorAddress string, cosmosAPIVersion string) (*Validator, error) {
mockArgs := conn.Called(validatorAddress, cosmosAPIVersion)
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)
func (conn *MockClient) Delegation(delegator string, validator string, cosmosAPIVersion string) (*DelegationResponse, error) {
mockArgs := conn.Called(delegator, validator, cosmosAPIVersion)
result, _ := mockArgs.Get(0).(*DelegationResponse)
return result, mockArgs.Error(1)
}

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

func (conn *MockClient) CommunityTax() (*big.Float, error) {
args := conn.Called()
func (conn *MockClient) CommunityTax(cosmosAPIVersion string) (*big.Float, error) {
args := conn.Called(cosmosAPIVersion)
return args.Get(0).(*big.Float), args.Error(1)
}

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

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

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

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

func (conn *MockClient) Tx(txHash string) (*model.Tx, error) {
mockArgs := conn.Called(txHash)
func (conn *MockClient) Tx(txHash string, cosmosAPIVersion string) (*model.Tx, error) {
mockArgs := conn.Called(txHash, cosmosAPIVersion)
result, _ := mockArgs.Get(0).(*model.Tx)
return result, mockArgs.Error(1)
}
7 changes: 7 additions & 0 deletions appinterface/cosmosapp/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ type Tally struct {
No string `json:"no"`
NoWithVeto string `json:"no_with_veto"`
}

type TallyV1 struct {
YesCount string `json:"yes_count"`
AbstainCount string `json:"abstain_count"`
NoCount string `json:"no_count"`
NoWithVetoCount string `json:"no_with_veto_count"`
}
3 changes: 2 additions & 1 deletion bootstrap/syncmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
eventhandler_interface "github.com/crypto-com/chain-indexing/appinterface/eventhandler"
tendermint_interface "github.com/crypto-com/chain-indexing/appinterface/tendermint"
"github.com/crypto-com/chain-indexing/external/ethereumtxinnermsgdecoder"
"github.com/crypto-com/chain-indexing/external/tmcosmosutils"
"github.com/crypto-com/chain-indexing/external/txdecoder"
cosmosapp_infrastructure "github.com/crypto-com/chain-indexing/infrastructure/cosmosapp"
"github.com/crypto-com/chain-indexing/usecase/model"
Expand Down Expand Up @@ -277,7 +278,7 @@ func (manager *SyncManager) syncBlockWorker(blockHeight int64) ([]command_entity
decodedTx, err = manager.txDecoder.DecodeBase64(txHex)
if err != nil {
var resTx *model.Tx
resTx, err = manager.cosmosClient.Tx(txHash)
resTx, err = manager.cosmosClient.Tx(txHash, tmcosmosutils.DefaultCosmosAPIVersion)
if err != nil {
return nil, fmt.Errorf("error requesting chain txs (%s) at height %d: %v", txHex, blockHeight, err)
}
Expand Down
7 changes: 7 additions & 0 deletions entity/event/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Base struct {
EventVersion int `json:"version"`
BlockHeight int64 `json:"height"`
EventUUID string `json:"uuid"`
MsgVersion string `json:"msgVersion"`
}

func NewBase(params BaseParams) Base {
Expand All @@ -19,6 +20,7 @@ func NewBase(params BaseParams) Base {
EventVersion: params.Version,
BlockHeight: params.BlockHeight,
EventUUID: uuid.New().String(),
MsgVersion: params.MsgVersion,
}
}

Expand All @@ -38,8 +40,13 @@ func (event *Base) UUID() string {
return event.EventUUID
}

func (event *Base) MessageVersion() string {
return event.MsgVersion
}

type BaseParams struct {
Name string
Version int
BlockHeight int64
MsgVersion string
}
27 changes: 27 additions & 0 deletions external/tmcosmosutils/cosmosapiversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package tmcosmosutils

import (
"strings"
)

const (
DefaultCosmosAPIVersion = "v1beta1"
CosmosAPIVersionV1 = "v1"
)

var CosmosAPIVersionMap = map[string]bool{
DefaultCosmosAPIVersion: true,
CosmosAPIVersionV1: true,
}

func GetMsgVersionFromMsgType(msgType string) string {
msgVersion := DefaultCosmosAPIVersion
parts := strings.Split(msgType, ".")
if len(parts) >= 2 {
msgVersion = parts[len(parts)-2]
if _, exists := CosmosAPIVersionMap[msgVersion]; !exists {
msgVersion = DefaultCosmosAPIVersion
}
}
return msgVersion
}
Loading
Loading