Skip to content

Commit

Permalink
feat: support for unverified deal price setting (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvin Reyes authored Apr 16, 2023
2 parents a9dae79 + 4d723dd commit 0f6e00e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 33 additions & 19 deletions api/deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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")
Expand All @@ -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")
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion jobs/storage_deal_maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0f6e00e

Please sign in to comment.