Skip to content

Commit

Permalink
Base 075rfile (#157)
Browse files Browse the repository at this point in the history
* update SubmitFileReport

* updatw PoISKeyInfo

* update GenerateStorageOrder
  • Loading branch information
AstaFrode authored Nov 6, 2023
1 parent 4bb5251 commit 6572620
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 33 deletions.
10 changes: 9 additions & 1 deletion chain/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func (c *chainClient) GenerateStorageOrder(
var err error
var segmentList = make([]pattern.SegmentList, len(segment))
var user pattern.UserBrief
var assignedData = make([][]pattern.FileHash, len(segment))
for i := 0; i < len(segment); i++ {
hash := filepath.Base(segment[i].SegmentHash)
for k := 0; k < len(hash); k++ {
Expand All @@ -301,14 +302,21 @@ func (c *chainClient) GenerateStorageOrder(
}
}
}
for i := 0; i < len(segmentList); i++ {
assignedData[i] = make([]pattern.FileHash, len(segmentList[i].FragmentHash))
for j := 0; j < len(segmentList[i].FragmentHash); j++ {
assignedData[i][j] = segmentList[i].FragmentHash[j]
}
}

acc, err := types.NewAccountID(owner)
if err != nil {
return "", err
}
user.User = *acc
user.BucketName = types.NewBytes([]byte(buckname))
user.FileName = types.NewBytes([]byte(filename))
return c.UploadDeclaration(roothash, segmentList, user, filesize)
return c.UploadDeclaration(roothash, segmentList, assignedData, user, filesize)
}

func ExtractSegmenthash(segment []string) []string {
Expand Down
63 changes: 37 additions & 26 deletions chain/fileBank.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ func (c *chainClient) DeleteBucket(owner_pkey []byte, name string) (string, erro
}
}

func (c *chainClient) UploadDeclaration(filehash string, dealinfo []pattern.SegmentList, user pattern.UserBrief, filesize uint64) (string, error) {
func (c *chainClient) UploadDeclaration(filehash string, dealinfo []pattern.SegmentList, hashs [][]pattern.FileHash, user pattern.UserBrief, filesize uint64) (string, error) {
c.lock.Lock()
defer func() {
c.lock.Unlock()
Expand All @@ -710,14 +710,19 @@ func (c *chainClient) UploadDeclaration(filehash string, dealinfo []pattern.Segm
if filesize <= 0 {
return txhash, errors.New("invalid filesize")
}
if !c.GetChainState() {
return txhash, fmt.Errorf("chainSDK.UploadDeclaration(): GetChainState(): %v", pattern.ERR_RPC_CONNECTION)
}
for i := 0; i < len(hash); i++ {
hash[i] = types.U8(filehash[i])
}

call, err := types.NewCall(c.metadata, pattern.TX_FILEBANK_UPLOADDEC, hash, dealinfo, user, types.NewU128(*new(big.Int).SetUint64(filesize)))
if len(hashs) > pattern.MaxSegmentNum {
return txhash, errors.New("segment length exceeds limit")
}

if !c.GetChainState() {
return txhash, fmt.Errorf("chainSDK.UploadDeclaration(): GetChainState(): %v", pattern.ERR_RPC_CONNECTION)
}

call, err := types.NewCall(c.metadata, pattern.TX_FILEBANK_UPLOADDEC, hash, dealinfo, hashs, user, types.NewU128(*new(big.Int).SetUint64(filesize)))
if err != nil {
return txhash, errors.Wrap(err, "[NewCall]")
}
Expand Down Expand Up @@ -908,7 +913,7 @@ func (c *chainClient) DeleteFile(puk []byte, filehash []string) (string, []patte
}
}

func (c *chainClient) SubmitFileReport(roothash pattern.FileHash) (string, []pattern.FileHash, error) {
func (c *chainClient) SubmitFileReport(roothash pattern.FileHash, accs []types.AccountID) (string, error) {
c.lock.Lock()
defer func() {
c.lock.Unlock()
Expand All @@ -923,25 +928,25 @@ func (c *chainClient) SubmitFileReport(roothash pattern.FileHash) (string, []pat
)

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

call, err := types.NewCall(c.metadata, pattern.TX_FILEBANK_FILEREPORT, roothash)
if err != nil {
return txhash, nil, errors.Wrap(err, "[NewCall]")
return txhash, errors.Wrap(err, "[NewCall]")
}

key, err := types.CreateStorageKey(c.metadata, pattern.SYSTEM, pattern.ACCOUNT, c.keyring.PublicKey)
if err != nil {
return txhash, nil, errors.Wrap(err, "[CreateStorageKey]")
return txhash, errors.Wrap(err, "[CreateStorageKey]")
}

ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo)
if err != nil {
return txhash, nil, errors.Wrap(err, "[GetStorageLatest]")
return txhash, errors.Wrap(err, "[GetStorageLatest]")
}
if !ok {
return txhash, nil, pattern.ERR_RPC_EMPTY_VALUE
return txhash, pattern.ERR_RPC_EMPTY_VALUE
}

o := types.SignatureOptions{
Expand All @@ -959,7 +964,7 @@ func (c *chainClient) SubmitFileReport(roothash pattern.FileHash) (string, []pat
// Sign the transaction
err = ext.Sign(c.keyring, o)
if err != nil {
return txhash, nil, errors.Wrap(err, "[Sign]")
return txhash, errors.Wrap(err, "[Sign]")
}

// Do the transfer and track the actual status
Expand All @@ -969,16 +974,16 @@ func (c *chainClient) SubmitFileReport(roothash pattern.FileHash) (string, []pat
o.Nonce = types.NewUCompactFromUInt(uint64(accountInfo.Nonce + 1))
err = ext.Sign(c.keyring, o)
if err != nil {
return txhash, nil, errors.Wrap(err, "[Sign]")
return txhash, errors.Wrap(err, "[Sign]")
}
sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext)
if err != nil {
c.SetChainState(false)
return txhash, nil, errors.Wrap(err, "[SubmitAndWatchExtrinsic]")
return txhash, errors.Wrap(err, "[SubmitAndWatchExtrinsic]")
}
} else {
c.SetChainState(false)
return txhash, nil, errors.Wrap(err, "[SubmitAndWatchExtrinsic]")
return txhash, errors.Wrap(err, "[SubmitAndWatchExtrinsic]")
}
}
defer sub.Unsubscribe()
Expand All @@ -992,29 +997,35 @@ func (c *chainClient) SubmitFileReport(roothash pattern.FileHash) (string, []pat
if status.IsInBlock {
txhash = status.AsInBlock.Hex()
_, err = c.RetrieveEvent_FileBank_TransferReport(status.AsInBlock)
return txhash, nil, err
return txhash, err
}
case err = <-sub.Err():
return txhash, nil, errors.Wrap(err, "[sub]")
return txhash, errors.Wrap(err, "[sub]")
case <-timeout.C:
return txhash, nil, pattern.ERR_RPC_TIMEOUT
return txhash, pattern.ERR_RPC_TIMEOUT
}
}
}

func (c *chainClient) ReportFiles(roothash string) (string, []string, error) {
func (c *chainClient) ReportFile(roothash string, accs []string) (string, error) {
var hashs pattern.FileHash

var accounts = make([]types.AccountID, 0)
for j := 0; j < len(roothash); j++ {
hashs[j] = types.U8(roothash[j])
}

txhash, failed, err := c.SubmitFileReport(hashs)
var failedfiles = make([]string, len(failed))
for k, v := range failed {
failedfiles[k] = string(v[:])
for _, v := range accs {
pubkey, err := utils.ParsingPublickey(v)
if err != nil {
continue
}
accountID, err := types.NewAccountID(pubkey)
if err != nil {
continue
}
accounts = append(accounts, *accountID)
}
return txhash, failedfiles, err

return c.SubmitFileReport(hashs, accounts)
}

// QueryRestoralOrder
Expand Down
6 changes: 3 additions & 3 deletions core/pattern/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ const (
AccumulatorLen = 256
SpaceChallengeParamLen = 8
BloomFilterLen = 256
MaxSegmentNum = 1000
)

type FileHash [FileHashLen]types.U8
Expand Down Expand Up @@ -463,9 +464,8 @@ type ExpendersInfo struct {
}

type PoISKeyInfo struct {
Acc types.AccountID
G PoISKey_G
N PoISKey_N
G PoISKey_G
N PoISKey_N
}

type IdleSignInfo struct {
Expand Down
6 changes: 3 additions & 3 deletions core/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ type SDK interface {
// RestoralComplete reports order recovery completion.
RestoralComplete(restoralFragmentHash string) (string, error)
// SubmitFileReport submits a stored file report.
SubmitFileReport(roothash pattern.FileHash) (string, []pattern.FileHash, error)
ReportFiles(roothash string) (string, []string, error)
SubmitFileReport(roothash pattern.FileHash, accs []types.AccountID) (string, error)
ReportFile(roothash string, accs []string) (string, error)
// UploadDeclaration creates a storage order.
UploadDeclaration(roothash string, dealinfo []pattern.SegmentList, user pattern.UserBrief, filesize uint64) (string, error)
UploadDeclaration(filehash string, dealinfo []pattern.SegmentList, hashs [][]pattern.FileHash, user pattern.UserBrief, filesize uint64) (string, error)
// GenerateStorageOrder for generating storage orders
GenerateStorageOrder(roothash string, segment []pattern.SegmentDataInfo, owner []byte, filename, buckname string, filesize uint64) (string, error)
// SubmitIdleMetadata Submit idle file metadata.
Expand Down

0 comments on commit 6572620

Please sign in to comment.