Skip to content
New issue

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

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

Already on GitHub? # to your account

update to go-fil-markets v1.22.x #602

Merged
merged 1 commit into from
Jun 23, 2022
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
75 changes: 38 additions & 37 deletions db/deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"

"github.com/filecoin-project/boost/db/fielddef"
"github.com/filecoin-project/boost/storagemarket/types"
"github.com/filecoin-project/boost/storagemarket/types/dealcheckpoints"
"github.com/filecoin-project/go-state-types/builtin/v8/market"
Expand Down Expand Up @@ -35,7 +36,7 @@ func init() {
type dealAccessor struct {
db *sql.DB
deal *types.ProviderDealState
def map[string]fieldDefinition
def map[string]fielddef.FieldDefinition
}

func (d *DealsDB) newDealDef(deal *types.ProviderDealState) *dealAccessor {
Expand All @@ -46,39 +47,39 @@ func newDealAccessor(db *sql.DB, deal *types.ProviderDealState) *dealAccessor {
return &dealAccessor{
db: db,
deal: deal,
def: map[string]fieldDefinition{
"ID": &fieldDef{f: &deal.DealUuid},
"CreatedAt": &fieldDef{f: &deal.CreatedAt},
"DealProposalSignature": &sigFieldDef{f: &deal.ClientDealProposal.ClientSignature},
"PieceCID": &cidFieldDef{f: &deal.ClientDealProposal.Proposal.PieceCID},
"PieceSize": &fieldDef{f: &deal.ClientDealProposal.Proposal.PieceSize},
"VerifiedDeal": &fieldDef{f: &deal.ClientDealProposal.Proposal.VerifiedDeal},
"IsOffline": &fieldDef{f: &deal.IsOffline},
"ClientAddress": &addrFieldDef{f: &deal.ClientDealProposal.Proposal.Client},
"ProviderAddress": &addrFieldDef{f: &deal.ClientDealProposal.Proposal.Provider},
"Label": &labelFieldDef{f: &deal.ClientDealProposal.Proposal.Label},
"StartEpoch": &fieldDef{f: &deal.ClientDealProposal.Proposal.StartEpoch},
"EndEpoch": &fieldDef{f: &deal.ClientDealProposal.Proposal.EndEpoch},
"StoragePricePerEpoch": &bigIntFieldDef{f: &deal.ClientDealProposal.Proposal.StoragePricePerEpoch},
"ProviderCollateral": &bigIntFieldDef{f: &deal.ClientDealProposal.Proposal.ProviderCollateral},
"ClientCollateral": &bigIntFieldDef{f: &deal.ClientDealProposal.Proposal.ClientCollateral},
"ClientPeerID": &peerIDFieldDef{f: &deal.ClientPeerID},
"DealDataRoot": &cidFieldDef{f: &deal.DealDataRoot},
"InboundFilePath": &fieldDef{f: &deal.InboundFilePath},
"TransferType": &fieldDef{f: &deal.Transfer.Type},
"TransferParams": &fieldDef{f: &deal.Transfer.Params},
"TransferSize": &fieldDef{f: &deal.Transfer.Size},
"ChainDealID": &fieldDef{f: &deal.ChainDealID},
"PublishCID": &cidPtrFieldDef{f: &deal.PublishCID},
"SectorID": &fieldDef{f: &deal.SectorID},
"Offset": &fieldDef{f: &deal.Offset},
"Length": &fieldDef{f: &deal.Length},
"Checkpoint": &ckptFieldDef{f: &deal.Checkpoint},
"CheckpointAt": &fieldDef{f: &deal.CheckpointAt},
"Error": &fieldDef{f: &deal.Err},
"Retry": &fieldDef{f: &deal.Retry},
def: map[string]fielddef.FieldDefinition{
"ID": &fielddef.FieldDef{F: &deal.DealUuid},
"CreatedAt": &fielddef.FieldDef{F: &deal.CreatedAt},
"DealProposalSignature": &fielddef.SigFieldDef{F: &deal.ClientDealProposal.ClientSignature},
"PieceCID": &fielddef.CidFieldDef{F: &deal.ClientDealProposal.Proposal.PieceCID},
"PieceSize": &fielddef.FieldDef{F: &deal.ClientDealProposal.Proposal.PieceSize},
"VerifiedDeal": &fielddef.FieldDef{F: &deal.ClientDealProposal.Proposal.VerifiedDeal},
"IsOffline": &fielddef.FieldDef{F: &deal.IsOffline},
"ClientAddress": &fielddef.AddrFieldDef{F: &deal.ClientDealProposal.Proposal.Client},
"ProviderAddress": &fielddef.AddrFieldDef{F: &deal.ClientDealProposal.Proposal.Provider},
"Label": &fielddef.LabelFieldDef{F: &deal.ClientDealProposal.Proposal.Label},
"StartEpoch": &fielddef.FieldDef{F: &deal.ClientDealProposal.Proposal.StartEpoch},
"EndEpoch": &fielddef.FieldDef{F: &deal.ClientDealProposal.Proposal.EndEpoch},
"StoragePricePerEpoch": &fielddef.BigIntFieldDef{F: &deal.ClientDealProposal.Proposal.StoragePricePerEpoch},
"ProviderCollateral": &fielddef.BigIntFieldDef{F: &deal.ClientDealProposal.Proposal.ProviderCollateral},
"ClientCollateral": &fielddef.BigIntFieldDef{F: &deal.ClientDealProposal.Proposal.ClientCollateral},
"ClientPeerID": &fielddef.PeerIDFieldDef{F: &deal.ClientPeerID},
"DealDataRoot": &fielddef.CidFieldDef{F: &deal.DealDataRoot},
"InboundFilePath": &fielddef.FieldDef{F: &deal.InboundFilePath},
"TransferType": &fielddef.FieldDef{F: &deal.Transfer.Type},
"TransferParams": &fielddef.FieldDef{F: &deal.Transfer.Params},
"TransferSize": &fielddef.FieldDef{F: &deal.Transfer.Size},
"ChainDealID": &fielddef.FieldDef{F: &deal.ChainDealID},
"PublishCID": &fielddef.CidPtrFieldDef{F: &deal.PublishCID},
"SectorID": &fielddef.FieldDef{F: &deal.SectorID},
"Offset": &fielddef.FieldDef{F: &deal.Offset},
"Length": &fielddef.FieldDef{F: &deal.Length},
"Checkpoint": &fielddef.CkptFieldDef{F: &deal.Checkpoint},
"CheckpointAt": &fielddef.FieldDef{F: &deal.CheckpointAt},
"Error": &fielddef.FieldDef{F: &deal.Err},
"Retry": &fielddef.FieldDef{F: &deal.Retry},
// Needed so the deal can be looked up by signed proposal cid
"SignedProposalCID": &signedPropFieldDef{prop: deal.ClientDealProposal},
"SignedProposalCID": &fielddef.SignedPropFieldDef{Prop: deal.ClientDealProposal},
},
}
}
Expand All @@ -89,7 +90,7 @@ func (d *dealAccessor) scan(row Scannable) error {
for _, name := range dealFields {
// Get a pointer to the field that will receive the scanned value
fieldDef := d.def[name]
dest = append(dest, fieldDef.fieldPtr())
dest = append(dest, fieldDef.FieldPtr())
}

// Scan the row into each pointer
Expand All @@ -101,7 +102,7 @@ func (d *dealAccessor) scan(row Scannable) error {
// For each field
for name, fieldDef := range d.def {
// Unmarshall the scanned value into deal object
err := fieldDef.unmarshall()
err := fieldDef.Unmarshall()
if err != nil {
return fmt.Errorf("unmarshalling db field %s: %s", name, err)
}
Expand All @@ -119,7 +120,7 @@ func (d *dealAccessor) insert(ctx context.Context) error {
placeholders = append(placeholders, "?")

// Marshall the field into a value that can be stored in the database
v, err := fieldDef.marshall()
v, err := fieldDef.Marshall()
if err != nil {
return err
}
Expand Down Expand Up @@ -148,7 +149,7 @@ func (d *dealAccessor) update(ctx context.Context) error {
setNames = append(setNames, name+" = ?")

// Marshall the field into a value that can be stored in the database
v, err := fieldDef.marshall()
v, err := fieldDef.Marshall()
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions db/deals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db

import (
"context"
"github.com/filecoin-project/boost/db/migrations"
"testing"
"time"

Expand All @@ -17,7 +18,7 @@ func TestDealsDB(t *testing.T) {

sqldb := CreateTestTmpDB(t)
require.NoError(t, CreateAllBoostTables(ctx, sqldb, sqldb))
require.NoError(t, Migrate(sqldb))
require.NoError(t, migrations.Migrate(sqldb))

db := NewDealsDB(sqldb)
deals, err := GenerateDeals()
Expand Down Expand Up @@ -98,7 +99,7 @@ func TestDealsDBSearch(t *testing.T) {

sqldb := CreateTestTmpDB(t)
req.NoError(CreateAllBoostTables(ctx, sqldb, sqldb))
req.NoError(Migrate(sqldb))
req.NoError(migrations.Migrate(sqldb))

start := time.Now()
db := NewDealsDB(sqldb)
Expand Down
Loading