Convert and persist LogNote events as dent records
This commit is contained in:
Elizabeth
2018-09-11 14:01:45 -05:00
committed by GitHub
parent d4a4748246
commit 9abe3ffa68
29 changed files with 1116 additions and 49 deletions
+31
View File
@@ -0,0 +1,31 @@
// Copyright 2018 Vulcanize
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shared
import (
"github.com/ethereum/go-ethereum/common"
"math/big"
)
type Bid struct {
Bid *big.Int
Lot *big.Int
Guy common.Address
Tic *big.Int
End *big.Int
Lad [32]byte
Gal common.Address
Tab *big.Int
}
+45
View File
@@ -0,0 +1,45 @@
// Copyright 2018 Vulcanize
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shared
import (
"github.com/vulcanize/vulcanizedb/pkg/core"
)
type IBidFetcher interface {
FetchBid(contractAbi, contractAddress string, blockNumber int64, methodArgs interface{}) (Bid, error)
}
type BidFetcher struct {
blockChain core.BlockChain
}
func NewBidFetcher(blockchain core.BlockChain) IBidFetcher {
return BidFetcher{
blockChain: blockchain,
}
}
func (fetcher BidFetcher) FetchBid(contractAbi, contractAddress string, blockNumber int64, methodArgs interface{}) (Bid, error) {
method := "bids"
result := Bid{}
err := fetcher.blockChain.FetchContractData(contractAbi, contractAddress, method, methodArgs, &result, blockNumber)
if err != nil {
return result, err
}
return result, nil
}
@@ -0,0 +1,57 @@
// Copyright 2018 Vulcanize
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shared_test
import (
"math/big"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
)
var _ = Describe("Dent Bid BidFetcher", func() {
var blockChain *fakes.MockBlockChain
var fetcher shared.IBidFetcher
var blockNumber = int64(123)
var address = "0xfakeAddress"
var contractAbi = "contractAbi"
BeforeEach(func() {
blockChain = fakes.NewMockBlockChain()
fetcher = shared.NewBidFetcher(blockChain)
})
It("fetches a bid record for the given id", func() {
method := "bids"
bidId := big.NewInt(1)
result := &shared.Bid{}
_, err := fetcher.FetchBid(contractAbi, address, blockNumber, bidId)
Expect(err).NotTo(HaveOccurred())
blockChain.AssertFetchContractDataCalledWith(contractAbi, address, method, bidId, result, blockNumber)
})
It("returns an error if fetching the bid fails", func() {
blockChain.SetFetchContractDataErr(fakes.FakeError)
fetcher := shared.NewBidFetcher(blockChain)
_, err := fetcher.FetchBid(contractAbi, address, blockNumber, nil)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(fakes.FakeError))
})
})
+2
View File
@@ -16,6 +16,7 @@ package shared
var (
biteMethod = "Bite(bytes32,bytes32,uint256,uint256,uint256,uint256,uint256)"
dentMethod = "dent(uint256,uint256,uint256)"
flipKickMethod = "Kick(uint256,uint256,uint256,address,uint48,bytes32,uint256)"
frobMethod = "Frob(bytes32,bytes32,uint256,uint256,int256,int256,uint256)"
pitFileDebtCeilingMethod = "file(bytes32,uint256)"
@@ -31,6 +32,7 @@ var (
FlipperContractAddress = "0x6b59c42097e2fff7cad96cb08ceefd601081ad9c" //this is a temporary address deployed locally
BiteSignature = GetEventSignature(biteMethod)
DentFunctionSignature = GetLogNoteSignature(dentMethod)
FlipKickSignature = GetEventSignature(flipKickMethod)
FrobSignature = GetEventSignature(frobMethod)
LogValueSignature = GetEventSignature("")
+33
View File
@@ -0,0 +1,33 @@
// Copyright 2018 Vulcanize
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shared
import "math/big"
func ConvertNilToZeroTimeValue(value *big.Int) int64 {
if value == nil {
return int64(0)
} else {
return value.Int64()
}
}
func ConvertNilToEmptyString(value string) string {
if value == "<nil>" {
return ""
} else {
return value
}
}