66 "fmt"
77 "strings"
88
9+ "github.com/filecoin-project/boost/db/fielddef"
910 "github.com/filecoin-project/boost/storagemarket/types"
1011 "github.com/filecoin-project/boost/storagemarket/types/dealcheckpoints"
1112 "github.com/filecoin-project/go-state-types/builtin/v8/market"
@@ -35,7 +36,7 @@ func init() {
3536type dealAccessor struct {
3637 db * sql.DB
3738 deal * types.ProviderDealState
38- def map [string ]fieldDefinition
39+ def map [string ]fielddef. FieldDefinition
3940}
4041
4142func (d * DealsDB ) newDealDef (deal * types.ProviderDealState ) * dealAccessor {
@@ -46,39 +47,39 @@ func newDealAccessor(db *sql.DB, deal *types.ProviderDealState) *dealAccessor {
4647 return & dealAccessor {
4748 db : db ,
4849 deal : deal ,
49- def : map [string ]fieldDefinition {
50- "ID" : & fieldDef { f : & deal .DealUuid },
51- "CreatedAt" : & fieldDef { f : & deal .CreatedAt },
52- "DealProposalSignature" : & sigFieldDef { f : & deal .ClientDealProposal .ClientSignature },
53- "PieceCID" : & cidFieldDef { f : & deal .ClientDealProposal .Proposal .PieceCID },
54- "PieceSize" : & fieldDef { f : & deal .ClientDealProposal .Proposal .PieceSize },
55- "VerifiedDeal" : & fieldDef { f : & deal .ClientDealProposal .Proposal .VerifiedDeal },
56- "IsOffline" : & fieldDef { f : & deal .IsOffline },
57- "ClientAddress" : & addrFieldDef { f : & deal .ClientDealProposal .Proposal .Client },
58- "ProviderAddress" : & addrFieldDef { f : & deal .ClientDealProposal .Proposal .Provider },
59- "Label" : & labelFieldDef { f : & deal .ClientDealProposal .Proposal .Label },
60- "StartEpoch" : & fieldDef { f : & deal .ClientDealProposal .Proposal .StartEpoch },
61- "EndEpoch" : & fieldDef { f : & deal .ClientDealProposal .Proposal .EndEpoch },
62- "StoragePricePerEpoch" : & bigIntFieldDef { f : & deal .ClientDealProposal .Proposal .StoragePricePerEpoch },
63- "ProviderCollateral" : & bigIntFieldDef { f : & deal .ClientDealProposal .Proposal .ProviderCollateral },
64- "ClientCollateral" : & bigIntFieldDef { f : & deal .ClientDealProposal .Proposal .ClientCollateral },
65- "ClientPeerID" : & peerIDFieldDef { f : & deal .ClientPeerID },
66- "DealDataRoot" : & cidFieldDef { f : & deal .DealDataRoot },
67- "InboundFilePath" : & fieldDef { f : & deal .InboundFilePath },
68- "TransferType" : & fieldDef { f : & deal .Transfer .Type },
69- "TransferParams" : & fieldDef { f : & deal .Transfer .Params },
70- "TransferSize" : & fieldDef { f : & deal .Transfer .Size },
71- "ChainDealID" : & fieldDef { f : & deal .ChainDealID },
72- "PublishCID" : & cidPtrFieldDef { f : & deal .PublishCID },
73- "SectorID" : & fieldDef { f : & deal .SectorID },
74- "Offset" : & fieldDef { f : & deal .Offset },
75- "Length" : & fieldDef { f : & deal .Length },
76- "Checkpoint" : & ckptFieldDef { f : & deal .Checkpoint },
77- "CheckpointAt" : & fieldDef { f : & deal .CheckpointAt },
78- "Error" : & fieldDef { f : & deal .Err },
79- "Retry" : & fieldDef { f : & deal .Retry },
50+ def : map [string ]fielddef. FieldDefinition {
51+ "ID" : & fielddef. FieldDef { F : & deal .DealUuid },
52+ "CreatedAt" : & fielddef. FieldDef { F : & deal .CreatedAt },
53+ "DealProposalSignature" : & fielddef. SigFieldDef { F : & deal .ClientDealProposal .ClientSignature },
54+ "PieceCID" : & fielddef. CidFieldDef { F : & deal .ClientDealProposal .Proposal .PieceCID },
55+ "PieceSize" : & fielddef. FieldDef { F : & deal .ClientDealProposal .Proposal .PieceSize },
56+ "VerifiedDeal" : & fielddef. FieldDef { F : & deal .ClientDealProposal .Proposal .VerifiedDeal },
57+ "IsOffline" : & fielddef. FieldDef { F : & deal .IsOffline },
58+ "ClientAddress" : & fielddef. AddrFieldDef { F : & deal .ClientDealProposal .Proposal .Client },
59+ "ProviderAddress" : & fielddef. AddrFieldDef { F : & deal .ClientDealProposal .Proposal .Provider },
60+ "Label" : & fielddef. LabelFieldDef { F : & deal .ClientDealProposal .Proposal .Label },
61+ "StartEpoch" : & fielddef. FieldDef { F : & deal .ClientDealProposal .Proposal .StartEpoch },
62+ "EndEpoch" : & fielddef. FieldDef { F : & deal .ClientDealProposal .Proposal .EndEpoch },
63+ "StoragePricePerEpoch" : & fielddef. BigIntFieldDef { F : & deal .ClientDealProposal .Proposal .StoragePricePerEpoch },
64+ "ProviderCollateral" : & fielddef. BigIntFieldDef { F : & deal .ClientDealProposal .Proposal .ProviderCollateral },
65+ "ClientCollateral" : & fielddef. BigIntFieldDef { F : & deal .ClientDealProposal .Proposal .ClientCollateral },
66+ "ClientPeerID" : & fielddef. PeerIDFieldDef { F : & deal .ClientPeerID },
67+ "DealDataRoot" : & fielddef. CidFieldDef { F : & deal .DealDataRoot },
68+ "InboundFilePath" : & fielddef. FieldDef { F : & deal .InboundFilePath },
69+ "TransferType" : & fielddef. FieldDef { F : & deal .Transfer .Type },
70+ "TransferParams" : & fielddef. FieldDef { F : & deal .Transfer .Params },
71+ "TransferSize" : & fielddef. FieldDef { F : & deal .Transfer .Size },
72+ "ChainDealID" : & fielddef. FieldDef { F : & deal .ChainDealID },
73+ "PublishCID" : & fielddef. CidPtrFieldDef { F : & deal .PublishCID },
74+ "SectorID" : & fielddef. FieldDef { F : & deal .SectorID },
75+ "Offset" : & fielddef. FieldDef { F : & deal .Offset },
76+ "Length" : & fielddef. FieldDef { F : & deal .Length },
77+ "Checkpoint" : & fielddef. CkptFieldDef { F : & deal .Checkpoint },
78+ "CheckpointAt" : & fielddef. FieldDef { F : & deal .CheckpointAt },
79+ "Error" : & fielddef. FieldDef { F : & deal .Err },
80+ "Retry" : & fielddef. FieldDef { F : & deal .Retry },
8081 // Needed so the deal can be looked up by signed proposal cid
81- "SignedProposalCID" : & signedPropFieldDef { prop : deal .ClientDealProposal },
82+ "SignedProposalCID" : & fielddef. SignedPropFieldDef { Prop : deal .ClientDealProposal },
8283 },
8384 }
8485}
@@ -89,7 +90,7 @@ func (d *dealAccessor) scan(row Scannable) error {
8990 for _ , name := range dealFields {
9091 // Get a pointer to the field that will receive the scanned value
9192 fieldDef := d .def [name ]
92- dest = append (dest , fieldDef .fieldPtr ())
93+ dest = append (dest , fieldDef .FieldPtr ())
9394 }
9495
9596 // Scan the row into each pointer
@@ -101,7 +102,7 @@ func (d *dealAccessor) scan(row Scannable) error {
101102 // For each field
102103 for name , fieldDef := range d .def {
103104 // Unmarshall the scanned value into deal object
104- err := fieldDef .unmarshall ()
105+ err := fieldDef .Unmarshall ()
105106 if err != nil {
106107 return fmt .Errorf ("unmarshalling db field %s: %s" , name , err )
107108 }
@@ -119,7 +120,7 @@ func (d *dealAccessor) insert(ctx context.Context) error {
119120 placeholders = append (placeholders , "?" )
120121
121122 // Marshall the field into a value that can be stored in the database
122- v , err := fieldDef .marshall ()
123+ v , err := fieldDef .Marshall ()
123124 if err != nil {
124125 return err
125126 }
@@ -148,7 +149,7 @@ func (d *dealAccessor) update(ctx context.Context) error {
148149 setNames = append (setNames , name + " = ?" )
149150
150151 // Marshall the field into a value that can be stored in the database
151- v , err := fieldDef .marshall ()
152+ v , err := fieldDef .Marshall ()
152153 if err != nil {
153154 return err
154155 }
0 commit comments