Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch/parser updates for fixing message parsers #468

Merged
merged 12 commits into from
Sep 8, 2023
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
22 changes: 13 additions & 9 deletions core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,16 @@ var messageTypeIgnorer = map[string]interface{}{
staking.MsgCreateValidator: nil,
staking.MsgEditValidator: nil,
// Delegating and Locking are not taxable
superfluid.MsgSuperfluidDelegate: nil,
superfluid.MsgSuperfluidUndelegate: nil,
superfluid.MsgSuperfluidUnbondLock: nil,
superfluid.MsgLockAndSuperfluidDelegate: nil,
superfluid.MsgUnPoolWhitelistedPool: nil,
superfluid.MsgSuperfluidDelegate: nil,
superfluid.MsgSuperfluidUndelegate: nil,
superfluid.MsgSuperfluidUnbondLock: nil,
superfluid.MsgLockAndSuperfluidDelegate: nil,
superfluid.MsgUnPoolWhitelistedPool: nil,
superfluid.MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition: nil,
superfluid.MsgSuperfluidUndelegateAndUnbondLock: nil,
superfluid.MsgCreateFullRangePositionAndSuperfluidDelegate: nil,
superfluid.MsgAddToConcentratedLiquiditySuperfluidPosition: nil,
superfluid.MsgUnbondConvertAndStake: nil,

// Setting validator pref is not taxable
valsetpref.MsgSetValidatorSetPreference: nil,
Expand Down Expand Up @@ -424,12 +429,11 @@ func ProcessTx(db *gorm.DB, tx txtypes.MergedTx) (txDBWapper dbTypes.TxDBWrapper
config.Log.Fatal("Issue parsing a cosmos msg that we DO have a parser for! PLEASE INVESTIGATE")
}
// if this msg isn't include in our list of those we are explicitly ignoring, do something about it.
// we have decided to throw the error back up the call stack, which will prevent any indexing from happening on this block and add this to the failed block table
if _, ok := messageTypeIgnorer[msgType]; !ok {
config.Log.Warn(fmt.Sprintf("[Block: %v] ParseCosmosMessage failed for msg of type '%v'. We do not currently have a message handler for this message type", tx.TxResponse.Height, msgType))
config.Log.Error(fmt.Sprintf("[Block: %v] ParseCosmosMessage failed for msg of type '%v'. Missing parser and ignore list entry.", tx.TxResponse.Height, msgType))
return txDBWapper, txTime, fmt.Errorf("missing parser and ignore list entry for msg type '%v'", msgType)
}
// println("------------------Cosmos message parsing failed. MESSAGE FORMAT FOLLOWS:---------------- \n\n")
// spew.Dump(message)
// println("\n------------------END MESSAGE----------------------\n")
} else {
config.Log.Debug(fmt.Sprintf("[Block: %v] Cosmos message of known type: %s", tx.TxResponse.Height, cosmosMessage))
currMessageType.MessageType = cosmosMessage.GetType()
Expand Down
5 changes: 4 additions & 1 deletion cosmos/modules/bank/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ func (sf *WrapperMsgSend) HandleMsg(msgType string, msg sdk.Msg, log *txModule.L
return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)}
}

receiverAddress := txModule.GetValueForAttribute(bankTypes.AttributeKeyRecipient, receivedCoinsEvt)
receiverAddress, err := txModule.GetValueForAttribute(bankTypes.AttributeKeyRecipient, receivedCoinsEvt)
if err != nil {
return err
}
// coins_received := txModule.GetValueForAttribute("amount", receivedCoinsEvt)

if !strings.EqualFold(sf.CosmosMsgSend.ToAddress, receiverAddress) {
Expand Down
26 changes: 21 additions & 5 deletions cosmos/modules/distribution/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,21 @@ func (sf *WrapperMsgWithdrawValidatorCommission) HandleMsg(msgType string, msg s
}

// The attribute in the log message that shows you the delegator withdrawal address and amount received
delegatorReceivedCoinsEvt := txModule.GetEventWithType(distTypes.EventTypeWithdrawCommission, log)
delegatorReceivedCoinsEvt := txModule.GetEventWithType("coin_received", log)
if delegatorReceivedCoinsEvt == nil {
return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)}
}

sf.DelegatorReceiverAddress = txModule.GetValueForAttribute(bankTypes.AttributeKeyReceiver, delegatorReceivedCoinsEvt)
coinsReceived := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt)
receiverAddress, err := txModule.GetValueForAttribute(bankTypes.AttributeKeyReceiver, delegatorReceivedCoinsEvt)
if err != nil {
return err
}

sf.DelegatorReceiverAddress = receiverAddress
coinsReceived, err := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt)
if err != nil {
return err
}

coin, err := stdTypes.ParseCoinNormalized(coinsReceived)
if err != nil {
Expand Down Expand Up @@ -114,8 +122,16 @@ func (sf *WrapperMsgWithdrawDelegatorReward) HandleMsg(msgType string, msg stdTy
return nil
}

sf.RecipientAddress = txModule.GetValueForAttribute(bankTypes.AttributeKeyRecipient, delegatorReceivedCoinsEvt)
coinsReceived := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt)
recipientAddress, err := txModule.GetValueForAttribute(bankTypes.AttributeKeyRecipient, delegatorReceivedCoinsEvt)
if err != nil {
return err
}

sf.RecipientAddress = recipientAddress
coinsReceived, err := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt)
if err != nil {
return err
}

// This may be able to be optimized by doing one or the other
coin, err := stdTypes.ParseCoinNormalized(coinsReceived)
Expand Down
27 changes: 23 additions & 4 deletions cosmos/modules/gov/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,16 @@ func (sf *WrapperMsgSubmitProposal) HandleMsg(msgType string, msg stdTypes.Msg,
return nil
}

coinsReceived := txModule.GetValueForAttribute("amount", proposerDepositedCoinsEvt)
recipientAccount := txModule.GetValueForAttribute("recipient", proposerDepositedCoinsEvt)
coinsReceived, err := txModule.GetValueForAttribute("amount", proposerDepositedCoinsEvt)
if err != nil {
return err
}

recipientAccount, err := txModule.GetValueForAttribute("recipient", proposerDepositedCoinsEvt)
if err != nil {
return err
}

sf.DepositReceiverAddress = recipientAccount

// This may be able to be optimized by doing one or the other
Expand Down Expand Up @@ -132,11 +140,22 @@ func (sf *WrapperMsgDeposit) HandleMsg(msgType string, msg stdTypes.Msg, log *tx
return nil
}

coinsReceived := txModule.GetValueForAttribute("amount", proposerDepositedCoinsEvt)
coinsReceived, err := txModule.GetValueForAttribute("amount", proposerDepositedCoinsEvt)
if err != nil {
return err
}

// This may be able to be optimized by doing one or the other
coin, err := stdTypes.ParseCoinNormalized(coinsReceived)
recipientAccount := txModule.GetValueForAttribute("recipient", proposerDepositedCoinsEvt)
if err != nil {
return err
}

recipientAccount, err := txModule.GetValueForAttribute("recipient", proposerDepositedCoinsEvt)
if err != nil {
return err
}

sf.DepositReceiverAddress = recipientAccount

if err != nil {
Expand Down
14 changes: 12 additions & 2 deletions cosmos/modules/staking/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,18 @@ func (sf *WrapperMsgDelegate) HandleMsg(msgType string, msg stdTypes.Msg, log *t
sf.AutoWithdrawalReward = nil
sf.DelegatorAddress = sf.CosmosMsgDelegate.DelegatorAddress
} else {
sf.DelegatorAddress = txModule.GetValueForAttribute("recipient", delegatorReceivedCoinsEvt)
coinsReceived := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt)
delegatorAddress, err := txModule.GetValueForAttribute("recipient", delegatorReceivedCoinsEvt)
if err != nil {
return err
}

sf.DelegatorAddress = delegatorAddress

coinsReceived, err := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt)
if err != nil {
return err
}

coin, err := stdTypes.ParseCoinNormalized(coinsReceived)
if err != nil {
sf.AutoWithdrawalRewards, err = stdTypes.ParseCoinsNormalized(coinsReceived)
Expand Down
8 changes: 4 additions & 4 deletions cosmos/modules/tx/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ func ParseTransferEvent(evt LogMessageEvent) ([]TransferEvent, error) {

// If order is reversed, the last attribute containing the given key will be returned
// otherwise the first attribute will be returned
func GetValueForAttribute(key string, evt *LogMessageEvent) string {
func GetValueForAttribute(key string, evt *LogMessageEvent) (string, error) {
if evt == nil || evt.Attributes == nil {
return ""
return "", nil
}

for _, attr := range evt.Attributes {
if attr.Key == key {
return attr.Value
return attr.Value, nil
}
}

return ""
return "", fmt.Errorf("Attribute %s missing from event", key)
}

func GetCoinsSpent(spender string, evts []LogMessageEvent) []string {
Expand Down
12 changes: 12 additions & 0 deletions csv/parsers/accointing/accointing.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/DefiantLabs/cosmos-indexer/csv/parsers"
"github.com/DefiantLabs/cosmos-indexer/db"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/gamm"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/poolmanager"
)

func (p *Parser) TimeLayout() string {
Expand Down Expand Up @@ -259,6 +260,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgTransfer(address, event)
case ibc.MsgRecvPacket:
newRow, err = ParseMsgTransfer(address, event)
case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut:
newRow, err = ParsePoolManagerSwap(event)
default:
config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType)
continue
Expand Down Expand Up @@ -394,3 +397,12 @@ func ParseOsmosisReward(event db.TaxableEvent) (Row, error) {
}
return *row, err
}

func ParsePoolManagerSwap(event db.TaxableTransaction) (Row, error) {
row := &Row{}
err := row.ParseSwap(event)
if err != nil {
config.Log.Error("Error with ParseMsgSwapExactAmountOut.", err)
}
return *row, err
}
12 changes: 12 additions & 0 deletions csv/parsers/cointracker/cointracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/DefiantLabs/cosmos-indexer/csv/parsers"
"github.com/DefiantLabs/cosmos-indexer/db"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/gamm"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/poolmanager"
)

func (p *Parser) TimeLayout() string {
Expand Down Expand Up @@ -251,6 +252,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgTransfer(address, event)
case ibc.MsgRecvPacket:
newRow, err = ParseMsgTransfer(address, event)
case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut:
newRow, err = ParsePoolManagerSwap(event)
default:
config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType)
continue
Expand Down Expand Up @@ -365,6 +368,15 @@ func ParseMsgDeposit(address string, event db.TaxableTransaction) (Row, error) {
return *row, err
}

func ParsePoolManagerSwap(event db.TaxableTransaction) (Row, error) {
row := &Row{}
err := row.ParseSwap(event)
if err != nil {
config.Log.Error("Error with ParseMsgSwapExactAmountOut.", err)
}
return *row, err
}

func ParseOsmosisReward(event db.TaxableEvent) (Row, error) {
row := &Row{}
err := row.EventParseBasic(event)
Expand Down
12 changes: 12 additions & 0 deletions csv/parsers/cryptotaxcalculator/cryptotaxcalculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/DefiantLabs/cosmos-indexer/csv/parsers"
"github.com/DefiantLabs/cosmos-indexer/db"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/gamm"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/poolmanager"
)

func (p *Parser) TimeLayout() string {
Expand Down Expand Up @@ -193,6 +194,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgTransfer(address, event)
case ibc.MsgRecvPacket:
newRow, err = ParseMsgTransfer(address, event)
case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut:
newRow, err = ParsePoolManagerSwap(address, event)
default:
config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType)
continue
Expand Down Expand Up @@ -317,3 +320,12 @@ func ParseMsgSwapExactAmountOut(address string, event db.TaxableTransaction) (Ro
}
return *row, err
}

func ParsePoolManagerSwap(address string, event db.TaxableTransaction) (Row, error) {
row := &Row{}
err := row.ParseSwap(event, address, Buy)
if err != nil {
config.Log.Error("Error with ParsePoolManagerSwap.", err)
}
return *row, err
}
12 changes: 12 additions & 0 deletions csv/parsers/koinly/koinly.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/DefiantLabs/cosmos-indexer/csv/parsers"
"github.com/DefiantLabs/cosmos-indexer/db"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/gamm"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/poolmanager"
)

var unsupportedCoins = []string{
Expand Down Expand Up @@ -325,6 +326,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgTransfer(address, event)
case ibc.MsgRecvPacket:
newRow, err = ParseMsgTransfer(address, event)
case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut:
newRow, err = ParsePoolManagerSwap(event)
default:
config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType)
continue
Expand Down Expand Up @@ -447,3 +450,12 @@ func ParseOsmosisReward(event db.TaxableEvent) (Row, error) {
}
return *row, err
}

func ParsePoolManagerSwap(event db.TaxableTransaction) (Row, error) {
row := &Row{}
err := row.ParseSwap(event)
if err != nil {
config.Log.Error("Error with ParseMsgSwapExactAmountOut.", err)
}
return *row, err
}
12 changes: 12 additions & 0 deletions csv/parsers/taxbit/taxbit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/DefiantLabs/cosmos-indexer/csv/parsers"
"github.com/DefiantLabs/cosmos-indexer/db"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/gamm"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/poolmanager"
)

func (p *Parser) TimeLayout() string {
Expand Down Expand Up @@ -255,6 +256,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgTransfer(address, event)
case ibc.MsgRecvPacket:
newRow, err = ParseMsgTransfer(address, event)
case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut:
newRow, err = ParsePoolManagerSwap(event)
default:
config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType)
continue
Expand Down Expand Up @@ -377,3 +380,12 @@ func ParseOsmosisReward(event db.TaxableEvent) (Row, error) {
}
return *row, err
}

func ParsePoolManagerSwap(event db.TaxableTransaction) (Row, error) {
row := &Row{}
err := row.ParseSwap(event)
if err != nil {
config.Log.Error("Error with ParseMsgSwapExactAmountOut.", err)
}
return *row, err
}
25 changes: 20 additions & 5 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,30 @@ func IndexNewBlock(db *gorm.DB, blockHeight int64, blockTime time.Time, txs []Tx

// It is possible to have more than 1 taxable TX for a single msg. In most cases it should only be 1 or 2, but
// more is possible. Keying off of msg ID and amount may be sufficient....
if err := dbTransaction.

var foundRecord TaxableTransaction
dbTransaction.
Where(TaxableTransaction{
MessageID: taxableTxOnly.MessageID,
AmountSent: taxableTxOnly.AmountSent,
AmountReceived: taxableTxOnly.AmountReceived,
}).
FirstOrCreate(&taxableTxOnly).Error; err != nil {
config.Log.Error("Error creating taxable transaction.", err)
return err
}).Limit(1).Find(&foundRecord)

// If not found, do a create
if foundRecord.ID == 0 {
res := dbTransaction.Create(&taxableTxOnly)

if res.Error != nil {
config.Log.Error("Error creating taxable transaction.", res.Error)
return res.Error
}
} else {
// Force update with new data
res := dbTransaction.Model(&foundRecord).Updates(&taxableTxOnly)
if res.Error != nil {
config.Log.Error("Error updating taxable transaction.", res.Error)
return res.Error
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions osmosis/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var MessageTypeHandler = map[string][]func() txTypes.CosmosMessage{
gamm.MsgCreateBalancerPool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgCreateBalancerPool{} }},
poolmanager.MsgSwapExactAmountIn: {func() txTypes.CosmosMessage { return &poolmanager.WrapperMsgSwapExactAmountIn{} }},
poolmanager.MsgSwapExactAmountOut: {func() txTypes.CosmosMessage { return &poolmanager.WrapperMsgSwapExactAmountOut{} }},
poolmanager.MsgSplitRouteSwapExactAmountIn: {func() txTypes.CosmosMessage { return &poolmanager.WrapperMsgSplitRouteSwapExactAmountIn{} }},
concentratedliquidity.MsgCreatePosition: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgCreatePosition{} }},
concentratedliquidity.MsgWithdrawPosition: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgWithdrawPosition{} }},
concentratedliquidity.MsgCollectSpreadRewards: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgCollectSpreadRewards{} }},
Expand Down
Loading
Loading