Skip to content

Commit

Permalink
Base dinfo (#158)
Browse files Browse the repository at this point in the history
* update MinerTaskList

* update StorageOrder

* update SubmitFileReport and MinerTaskList
  • Loading branch information
AstaFrode authored Nov 7, 2023
1 parent 6572620 commit 019d40b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
23 changes: 11 additions & 12 deletions chain/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
keyring "github.com/CESSProject/go-keyring"
"github.com/btcsuite/btcutil/base58"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -584,14 +583,14 @@ func (c *chainClient) RetrieveObject(url, fid string) (io.ReadCloser, error) {
// }
// }

func (c *chainClient) QueryAssignedMinerPeerId(minerTaskList []pattern.MinerTaskList) ([]peer.ID, error) {
var peerids = make([]peer.ID, len(minerTaskList))
for i := 0; i < len(minerTaskList); i++ {
minerInfo, err := c.QueryStorageMiner(minerTaskList[i].Account[:])
if err != nil {
return peerids, err
}
peerids[i], _ = peer.Decode(string(minerInfo.PeerId[:]))
}
return peerids, nil
}
// func (c *chainClient) QueryAssignedMinerPeerId(minerTaskList []pattern.MinerTaskList) ([]peer.ID, error) {
// var peerids = make([]peer.ID, len(minerTaskList))
// for i := 0; i < len(minerTaskList); i++ {
// minerInfo, err := c.QueryStorageMiner(minerTaskList[i].Account[:])
// if err != nil {
// return peerids, err
// }
// peerids[i], _ = peer.Decode(string(minerInfo.PeerId[:]))
// }
// return peerids, nil
// }
16 changes: 12 additions & 4 deletions chain/fileBank.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ func (c *chainClient) DeleteFile(puk []byte, filehash []string) (string, []patte
}
}

func (c *chainClient) SubmitFileReport(roothash pattern.FileHash, accs []types.AccountID) (string, error) {
func (c *chainClient) SubmitFileReport(index types.U8, roothash pattern.FileHash, accs []types.AccountID) (string, error) {
c.lock.Lock()
defer func() {
c.lock.Unlock()
Expand All @@ -927,11 +927,19 @@ func (c *chainClient) SubmitFileReport(roothash pattern.FileHash, accs []types.A
accountInfo types.AccountInfo
)

if index == 0 || int(index) > (pattern.DataShards+pattern.ParShards) {
return "", errors.New("invalid index")
}

if len(accs) == 0 || len(accs) > 3 {
return "", errors.New("invalid tee list length")
}

if !c.GetChainState() {
return txhash, pattern.ERR_RPC_CONNECTION
}

call, err := types.NewCall(c.metadata, pattern.TX_FILEBANK_FILEREPORT, roothash)
call, err := types.NewCall(c.metadata, pattern.TX_FILEBANK_FILEREPORT, index, roothash, accs)
if err != nil {
return txhash, errors.Wrap(err, "[NewCall]")
}
Expand Down Expand Up @@ -1007,7 +1015,7 @@ func (c *chainClient) SubmitFileReport(roothash pattern.FileHash, accs []types.A
}
}

func (c *chainClient) ReportFile(roothash string, accs []string) (string, error) {
func (c *chainClient) ReportFile(index uint8, roothash string, accs []string) (string, error) {
var hashs pattern.FileHash
var accounts = make([]types.AccountID, 0)
for j := 0; j < len(roothash); j++ {
Expand All @@ -1025,7 +1033,7 @@ func (c *chainClient) ReportFile(roothash string, accs []string) (string, error)
accounts = append(accounts, *accountID)
}

return c.SubmitFileReport(hashs, accounts)
return c.SubmitFileReport(types.U8(index), hashs, accounts)
}

// QueryRestoralOrder
Expand Down
9 changes: 4 additions & 5 deletions core/pattern/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ type SegmentList struct {
}

type MinerTaskList struct {
Account types.AccountID
Hash []FileHash
Index types.U8
Miner types.Option[types.AccountID]
FragmentList []FileHash
}

type SegmentInfo struct {
Expand All @@ -341,10 +342,8 @@ type StorageOrder struct {
Count types.U8
FileSize types.U128
SegmentList []SegmentList
NeededList []SegmentList
User UserBrief
AssignedMiner []MinerTaskList
ShareInfo []SegmentInfo
MinerTaskList []MinerTaskList
CompleteList []types.AccountID
}

Expand Down
4 changes: 2 additions & 2 deletions core/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ type SDK interface {
// RestoralComplete reports order recovery completion.
RestoralComplete(restoralFragmentHash string) (string, error)
// SubmitFileReport submits a stored file report.
SubmitFileReport(roothash pattern.FileHash, accs []types.AccountID) (string, error)
ReportFile(roothash string, accs []string) (string, error)
SubmitFileReport(index types.U8, roothash pattern.FileHash, accs []types.AccountID) (string, error)
ReportFile(index uint8, roothash string, accs []string) (string, error)
// UploadDeclaration creates a storage order.
UploadDeclaration(filehash string, dealinfo []pattern.SegmentList, hashs [][]pattern.FileHash, user pattern.UserBrief, filesize uint64) (string, error)
// GenerateStorageOrder for generating storage orders
Expand Down

0 comments on commit 019d40b

Please sign in to comment.