From 02853014b20f09da0effdaee2c526c0daeadc928 Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Wed, 26 Sep 2018 09:14:18 -0500 Subject: [PATCH] Fix Pit file converters - Use topics 2 & 3 instead of topic 1 (call data instead of msg.sender) - Prefer extracting fields from topics rather than data --- .../pit_file/debt_ceiling/converter.go | 7 +++---- .../pit_file/stability_fee/converter.go | 2 +- pkg/transformers/test_data/pit_file.go | 14 +++++++------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pkg/transformers/pit_file/debt_ceiling/converter.go b/pkg/transformers/pit_file/debt_ceiling/converter.go index 58595ab4..90108411 100644 --- a/pkg/transformers/pit_file/debt_ceiling/converter.go +++ b/pkg/transformers/pit_file/debt_ceiling/converter.go @@ -18,8 +18,8 @@ import ( "encoding/json" "math/big" + "bytes" "errors" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" ) @@ -35,9 +35,8 @@ func (PitFileDebtCeilingConverter) ToModel(ethLog types.Log) (PitFileDebtCeiling if err != nil { return PitFileDebtCeilingModel{}, err } - what := common.HexToAddress(ethLog.Topics[1].String()).String() - riskBytes := ethLog.Data[len(ethLog.Data)-shared.DataItemLength:] - data := big.NewInt(0).SetBytes(riskBytes).String() + what := string(bytes.Trim(ethLog.Topics[2].Bytes(), "\x00")) + data := big.NewInt(0).SetBytes(ethLog.Topics[3].Bytes()).String() raw, err := json.Marshal(ethLog) return PitFileDebtCeilingModel{ diff --git a/pkg/transformers/pit_file/stability_fee/converter.go b/pkg/transformers/pit_file/stability_fee/converter.go index c5aa9bf5..0cd12db0 100644 --- a/pkg/transformers/pit_file/stability_fee/converter.go +++ b/pkg/transformers/pit_file/stability_fee/converter.go @@ -35,7 +35,7 @@ func (PitFileStabilityFeeConverter) ToModel(ethLog types.Log) (PitFileStabilityF return PitFileStabilityFeeModel{}, err } what := string(bytes.Trim(ethLog.Topics[2].Bytes(), "\x00")) - data := common.HexToAddress(ethLog.Topics[1].String()).Hex() + data := common.HexToAddress(ethLog.Topics[3].String()).Hex() raw, err := json.Marshal(ethLog) return PitFileStabilityFeeModel{ diff --git a/pkg/transformers/test_data/pit_file.go b/pkg/transformers/test_data/pit_file.go index 8b2daaf8..e4249d4d 100644 --- a/pkg/transformers/test_data/pit_file.go +++ b/pkg/transformers/test_data/pit_file.go @@ -33,10 +33,10 @@ var EthPitFileDebtCeilingLog = types.Log{ Topics: []common.Hash{ common.HexToHash("0x29ae811400000000000000000000000000000000000000000000000000000000"), common.HexToHash("0x00000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a092"), - common.HexToHash("0x6472697000000000000000000000000000000000000000000000000000000000"), - common.HexToHash("0x000000000000000000000000000000000000000000000000000000000000007b"), + common.HexToHash("0x4c696e6500000000000000000000000000000000000000000000000000000000"), + common.HexToHash("0x000000000000000000000000000000000000000000000000000000000001e240"), }, - Data: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004429ae81146472697000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b"), + Data: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004429ae81144c696e6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e240"), BlockNumber: 22, TxHash: common.HexToHash("0xd744878a0b6655e3ba729e1019f56b563b4a16750196b8ad6104f3977db43f42"), TxIndex: 333, @@ -47,8 +47,8 @@ var EthPitFileDebtCeilingLog = types.Log{ var rawPitFileDebtCeilingLog, _ = json.Marshal(EthPitFileDebtCeilingLog) var PitFileDebtCeilingModel = debt_ceiling.PitFileDebtCeilingModel{ - What: "0x64d922894153BE9EEf7b7218dc565d1D0Ce2a092", - Data: big.NewInt(123).String(), + What: "Line", + Data: big.NewInt(123456).String(), TransactionIndex: EthPitFileDebtCeilingLog.TxIndex, Raw: rawPitFileDebtCeilingLog, } @@ -85,7 +85,7 @@ var EthPitFileStabilityFeeLog = types.Log{ common.HexToHash("0xd4e8be8300000000000000000000000000000000000000000000000000000000"), common.HexToHash("0x00000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a092"), common.HexToHash("0x6472697000000000000000000000000000000000000000000000000000000000"), - common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + common.HexToHash("0x0000000000000000000000008e84a1e068d77059cbe263c43ad0cdc130863313"), }, Data: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000044d4e8be8364726970000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), BlockNumber: 12, @@ -99,7 +99,7 @@ var EthPitFileStabilityFeeLog = types.Log{ var rawPitFileStabilityFeeLog, _ = json.Marshal(EthPitFileStabilityFeeLog) var PitFileStabilityFeeModel = stability_fee.PitFileStabilityFeeModel{ What: "drip", - Data: "0x64d922894153BE9EEf7b7218dc565d1D0Ce2a092", + Data: "0x8E84a1e068d77059Cbe263C43AD0cDc130863313", TransactionIndex: EthPitFileStabilityFeeLog.TxIndex, Raw: rawPitFileStabilityFeeLog, }