Skip to content

Commit

Permalink
Merge pull request #187 from FogMeta/main
Browse files Browse the repository at this point in the history
New: support to import deals using `Boost`
  • Loading branch information
Normalnoise committed Jan 5, 2023
2 parents 4465d4c + 4a68abf commit 6024dc8
Show file tree
Hide file tree
Showing 20 changed files with 3,227 additions and 132 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "extern/filecoin-ffi"]
path = extern/filecoin-ffi
url = https://github.com/filecoin-project/filecoin-ffi.git
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ BINARY_NAME=$(PROJECT_NAME)
PKG := "$(PROJECT_NAME)"
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)

.PHONY: all build clean test help
.PHONY: all ffi build clean test help

all: build

test: ## Run unittests
@go test -short ${PKG_LIST}
@echo "Done testing."

ffi:
./extern/filecoin-ffi/install-filcrypto
.PHONY: ffi

build: ## Build the binary file
@go mod download
@go mod tidy
Expand All @@ -40,3 +44,10 @@ build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(GOBIN)/$(BINARY_NAME) -v main.go
build_win: test
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(GOBIN)/$(BINARY_NAME) -v main.go

build_boost:
git clone https://github.com/filecoin-project/boost
cd boost && git checkout v1.5.0
cd boost && make build && sudo mv boostd /usr/local/bin/
rm -rf boost
.PHONY: build_boost
8 changes: 6 additions & 2 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[![Twitter Follow](https://img.shields.io/twitter/follow/0xfilswan)](https://twitter.com/0xfilswan)
[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg)](https://github.com/RichardLitt/standard-readme)

- 加入FilSwan的[Slack](https://filswan.slack.com)频道,了解新闻、讨论和状态更新。
- 查看FilSwan的[Medium](https://filswan.medium.com),获取最新动态和公告。
`Web3 service providers`提供多种区块链服务,包括但不限于Filecoin、AR和Polygon的RPC服务。 通过FilSwan服务的提供, 我们可以连接到web3服务市场,使web3服务的提供变的更容易。
典型的Web3市场有:

- Filecoin 网络的数据订单市场
- Pocket 网络的RPC市场(即将实现···)


## 目录

Expand Down
3 changes: 3 additions & 0 deletions build_from_source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ sudo systemctl restart aria2c.service # Start Aria2

BINARY_NAME=swan-provider

git submodule update --init --recursive
make build_boost
make ffi
make
chmod +x ./build/${BINARY_NAME}
./build/${BINARY_NAME} daemon # Run swan provider
Expand Down
11 changes: 11 additions & 0 deletions common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ const (

UPDATE_OFFLINE_DEAL_STATUS_FAIL = "failed to update offline deal status"
NOT_UPDATE_OFFLINE_DEAL_STATUS = "no need to update deal status in swan"

CHECKPOINT_ACCEPTED = "Accepted"
CHECKPOINT_TRANSFERRED = "Transferred"
CHECKPOINT_PULISHED = "Published"
CHECKPOINT_CONFIRMED = "PublishConfirmed"
CHECKPOINT_ADDPIECE = "AddedPiece"
CHECKPOINT_INDEX = "IndexedAndAnnounced"
CHECKPOINT_COMPLETE = "Complete"

MARKET_TYPE_LOTUS = "lotus"
MARKET_TYPE_BOOST = "boost"
)
87 changes: 87 additions & 0 deletions common/hql/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package hql

import (
"context"
"errors"
"github.com/Khan/genqlient/graphql"
"net/http"
"swan-provider/common/hql/gen"
)

type Client struct {
hqlClient graphql.Client
}

func NewClient(endpoint string) (*Client, error) {
if endpoint == "" || len(endpoint) == 0 {
return nil, errors.New("graphql url is required")
}
client := graphql.NewClient(endpoint, http.DefaultClient)
return &Client{client}, nil
}

func (c Client) GetDealByUuid(dealUuid string) (*gen.DealResponse, error) {
return gen.Deal(context.TODO(), c.hqlClient, dealUuid)
}

var Checkpoint = map[string]string{
"Accepted": "Accepted",
"Transferred": "Transferred",
"Published": "Published",
"PublishConfirmed": "PublishConfirmed",
"AddedPiece": "AddedPiece",
"IndexedAndAnnounced": "IndexedAndAnnounced",
"Complete": "Complete",
}

func DealStatus(checkpoint, err string) string {
switch checkpoint {
case "Accepted":
return "StorageDealWaitingForData"
case "Transferred":
fallthrough
case "Published":
fallthrough
case "PublishConfirmed":
return "StorageDealAwaitingPreCommit"
case "AddedPiece":
fallthrough
case "IndexedAndAnnounced":
return "StorageDealSealing"
case "Complete":
switch err {
case "":
return "StorageDealActive"
case "Cancelled":
return "StorageDealNotFound"
}
return "StorageDealError"
}
return "StorageDealNotFound"
}

func Message(checkpoint, err string) string {
switch checkpoint {
case "Accepted":
return "Awaiting Offline Data Import"
case "Transferred":
return "Ready to Publish"
case "Published":
return "Awaiting Publish Confirmation"
case "PublishConfirmed":
return "Adding to Sector"
case "AddedPiece":
fallthrough
case "IndexedAndAnnounced":
return "sealing"
case "Complete":
switch err {
case "":
return "Complete"
case "Cancelled":
return "Cancelled"
}
return "Error: " + err
}
return "unknow"
}
111 changes: 111 additions & 0 deletions common/hql/gen/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions common/hql/gen/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package gen

type ChainDealID struct {
TypeName string `json:"__typename"`
Value string `json:"n"`
}
14 changes: 14 additions & 0 deletions common/hql/genqlient.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
query Deal($uuid: ID!){
deal(id: $uuid) {
ID
ProviderAddress
PieceCid
IsVerified
SignedProposalCid
InboundFilePath
ChainDealID
Checkpoint
Err
Message
}
}
11 changes: 11 additions & 0 deletions common/hql/genqlient.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Default genqlient config; for full documentation see:
# https://github.com/Khan/genqlient/blob/main/docs/genqlient.yaml
schema: schema.graphql
operations:
- genqlient.graphql
generated: gen/generated.go
package: gen
context_type: context.Context
bindings:
Uint64:
type: swan-provider/common/gen.ChainDealID
Loading

0 comments on commit 6024dc8

Please sign in to comment.