diff --git a/README.md b/README.md index b8e904f..c436e29 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,10 @@ DB_DSN=delta.db MAX_CLEANUP_WORKERS=1500 ``` +## Install and run `Delta` using `docker` + Running this the first time will generate a wallet. Make sure to get FIL/DataCap from the [faucet](https://verify.glif.io/) and fund the wallet -## Install and run `Delta` using `docker` Make sure you have docker installed on your machine. ### Run the current delta clone using docker-compose diff --git a/api/deal.go b/api/deal.go index 025f34b..4b6b638 100644 --- a/api/deal.go +++ b/api/deal.go @@ -58,7 +58,7 @@ type DealRequest struct { AutoRetry bool `json:"auto_retry"` Label string `json:"label,omitempty"` DealVerifyState string `json:"deal_verify_state,omitempty"` - UnverifiedDealMaxPrice int64 `json:"unverified_deal_max_price,omitempty"` + UnverifiedDealMaxPrice string `json:"unverified_deal_max_price,omitempty"` } // DealResponse Creating a new struct called DealResponse and then returning it. @@ -387,11 +387,11 @@ func handleExistingContentsAdd(c echo.Context, node *core.DeltaNode) error { dealProposalParam.CreatedAt = time.Now() dealProposalParam.UpdatedAt = time.Now() dealProposalParam.Content = content.ID - dealProposalParam.UnverifiedDealMaxPrice = func() int64 { - if dealRequest.UnverifiedDealMaxPrice != 0 { + dealProposalParam.UnverifiedDealMaxPrice = func() string { + if dealRequest.UnverifiedDealMaxPrice != "" { return dealRequest.UnverifiedDealMaxPrice } - return 0 + return "0" }() dealProposalParam.Label = func() string { @@ -593,11 +593,11 @@ func handleExistingContentAdd(c echo.Context, node *core.DeltaNode) error { dealProposalParam.CreatedAt = time.Now() dealProposalParam.UpdatedAt = time.Now() dealProposalParam.Content = content.ID - dealProposalParam.UnverifiedDealMaxPrice = func() int64 { - if dealRequest.UnverifiedDealMaxPrice != 0 { + dealProposalParam.UnverifiedDealMaxPrice = func() string { + if dealRequest.UnverifiedDealMaxPrice != "" { return dealRequest.UnverifiedDealMaxPrice } - return 0 + return "0" }() dealProposalParam.Label = func() string { if dealRequest.Label != "" { @@ -809,11 +809,11 @@ func handleEndToEndDeal(c echo.Context, node *core.DeltaNode) error { dealProposalParam.CreatedAt = time.Now() dealProposalParam.UpdatedAt = time.Now() dealProposalParam.Content = content.ID - dealProposalParam.UnverifiedDealMaxPrice = func() int64 { - if dealRequest.UnverifiedDealMaxPrice != 0 { + dealProposalParam.UnverifiedDealMaxPrice = func() string { + if dealRequest.UnverifiedDealMaxPrice != "" { return dealRequest.UnverifiedDealMaxPrice } - return 0 + return "0" }() dealProposalParam.Label = func() string { if dealRequest.Label != "" { @@ -1050,11 +1050,11 @@ func handleImportDeal(c echo.Context, node *core.DeltaNode) error { dealProposalParam.CreatedAt = time.Now() dealProposalParam.UpdatedAt = time.Now() dealProposalParam.Content = content.ID - dealProposalParam.UnverifiedDealMaxPrice = func() int64 { - if dealRequest.UnverifiedDealMaxPrice != 0 { + dealProposalParam.UnverifiedDealMaxPrice = func() string { + if dealRequest.UnverifiedDealMaxPrice != "" { return dealRequest.UnverifiedDealMaxPrice } - return 0 + return "0" }() dealProposalParam.Label = func() string { if dealRequest.Label != "" { @@ -1262,11 +1262,11 @@ func handleMultipleImportDeals(c echo.Context, node *core.DeltaNode) error { dealProposalParam.CreatedAt = time.Now() dealProposalParam.UpdatedAt = time.Now() dealProposalParam.Content = content.ID - dealProposalParam.UnverifiedDealMaxPrice = func() int64 { - if dealRequest.UnverifiedDealMaxPrice != 0 { + dealProposalParam.UnverifiedDealMaxPrice = func() string { + if dealRequest.UnverifiedDealMaxPrice != "" { return dealRequest.UnverifiedDealMaxPrice } - return 0 + return "0" }() dealProposalParam.Label = func() string { if dealRequest.Label != "" { @@ -1372,7 +1372,7 @@ type ValidateMetaResult struct { Message string } -// `ValidateMeta` validates the `DealRequest` struct and returns an error if the request is invalid +// ValidatePieceCommitmentMeta `ValidateMeta` validates the `DealRequest` struct and returns an error if the request is invalid func ValidatePieceCommitmentMeta(pieceCommitmentRequest PieceCommitmentRequest) error { if (PieceCommitmentRequest{} == pieceCommitmentRequest) { return errors.New("invalid piece_commitment request. piece_commitment is required") @@ -1392,9 +1392,23 @@ func ValidateMeta(dealRequest DealRequest) error { // return errors.New("miner is required") //} - if (DealRequest{} != dealRequest && dealRequest.UnverifiedDealMaxPrice > 0) { + if (DealRequest{} != dealRequest && dealRequest.UnverifiedDealMaxPrice != "") { if dealRequest.DealVerifyState != utils.DEAL_UNVERIFIED { - return errors.New("unverified_deal_max_price is only valid for unverified deals") + return errors.New("unverified_deal_max_price is only valid for unverified deals, make sure to pass deal_verify_state as unverified") + } + } + + if (DealRequest{} != dealRequest && dealRequest.DealVerifyState == utils.DEAL_UNVERIFIED) { + if dealRequest.UnverifiedDealMaxPrice == "" { + return errors.New("unverified_deal_max_price is required for unverified deals") + } + } + + // check if dealRequest.UnverifiedDealMaxPrice is a valid number + if (DealRequest{} != dealRequest && dealRequest.UnverifiedDealMaxPrice != "") { + _, err := strconv.ParseFloat(dealRequest.UnverifiedDealMaxPrice, 64) + if err != nil { + return errors.New("unverified_deal_max_price is not a valid number") } } diff --git a/go.mod b/go.mod index 9425c56..9c9450a 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( contrib.go.opencensus.io/exporter/prometheus v0.4.2 - github.com/application-research/delta-db v0.0.2-0.20230413035837-02ac624c0e96 + github.com/application-research/delta-db v0.0.2-0.20230416042304-c1aecd417eae github.com/application-research/filclient v0.5.0-rc1.0.20230331195738-9826f79f0648 github.com/application-research/whypfs-core v0.1.1 github.com/caarlos0/env/v6 v6.10.1 diff --git a/go.sum b/go.sum index 5e2b866..141ad78 100644 --- a/go.sum +++ b/go.sum @@ -88,6 +88,8 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/application-research/delta-db v0.0.2-0.20230413035837-02ac624c0e96 h1:Q11YFk3nAu6zH690TxEnYLG/7lH3fW/DygKLJvAfQf4= github.com/application-research/delta-db v0.0.2-0.20230413035837-02ac624c0e96/go.mod h1:LkFnhccvtKmSNHCatQNlKNjEAV/30w/e50n+A9hzCaU= +github.com/application-research/delta-db v0.0.2-0.20230416042304-c1aecd417eae h1:9Ky8CpmByiU/ShDJtc+a3Bz7GwX1JXottI95DZ4eJHc= +github.com/application-research/delta-db v0.0.2-0.20230416042304-c1aecd417eae/go.mod h1:LkFnhccvtKmSNHCatQNlKNjEAV/30w/e50n+A9hzCaU= github.com/application-research/filclient v0.5.0-rc1.0.20230331195738-9826f79f0648 h1:58+odb1yvlrhuWbmpcAu7IKN4/0+LOP8XjKP3JxOPGo= github.com/application-research/filclient v0.5.0-rc1.0.20230331195738-9826f79f0648/go.mod h1:HSCZh+v53XTGMwHGyoKpedQH+PlwcmKkMFCYx/Q3hMk= github.com/application-research/whypfs-core v0.1.1 h1:BY40N15Ge9BlyAT3f4T4B/CAlaL7A1RYaRrNS3HIyEk= diff --git a/jobs/storage_deal_maker.go b/jobs/storage_deal_maker.go index 8709afe..08c2a9e 100644 --- a/jobs/storage_deal_maker.go +++ b/jobs/storage_deal_maker.go @@ -127,7 +127,7 @@ func (i *StorageDealMakerProcessor) makeStorageDeal(content *model.Content, piec var priceBigInt types.BigInt if !dealProposal.VerifiedDeal { - unverifiedDealPrice, errPrice := types.BigFromString(string(dealProposal.UnverifiedDealMaxPrice)) + unverifiedDealPrice, errPrice := types.BigFromString(dealProposal.UnverifiedDealMaxPrice) if errPrice != nil { contentToUpdate.UpdatedAt = time.Now() contentToUpdate.LastMessage = errPrice.Error()