Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update QueryPendingReplacements #174

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions chain/fileBank.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,48 +276,6 @@ func (c *chainClient) QueryStorageOrder(fid string) (pattern.StorageOrder, error
return data, nil
}

func (c *chainClient) QueryPendingReplacements(puk []byte) (types.U128, error) {
defer func() {
if err := recover(); err != nil {
log.Println(utils.RecoverError(err))
}
}()

var data types.U128

acc, err := types.NewAccountID(puk)
if err != nil {
return data, errors.Wrap(err, "[NewAccountID]")
}

owner, err := codec.Encode(*acc)
if err != nil {
return data, errors.Wrap(err, "[EncodeToBytes]")
}

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

key, err := types.CreateStorageKey(c.metadata, pattern.FILEBANK, pattern.PENDINGREPLACE, owner)
if err != nil {
err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] CreateStorageKey: %v", c.GetCurrentRpcAddr(), pattern.FILEBANK, pattern.PENDINGREPLACE, err)
c.SetChainState(false)
return data, err
}

ok, err := c.api.RPC.State.GetStorageLatest(key, &data)
if err != nil {
err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), pattern.FILEBANK, pattern.PENDINGREPLACE, err)
c.SetChainState(false)
return data, err
}
if !ok {
return data, pattern.ERR_RPC_EMPTY_VALUE
}
return data, nil
}

func (c *chainClient) QueryRestoralOrder(fragmentHash string) (pattern.RestoralOrderInfo, error) {
defer func() {
if err := recover(); err != nil {
Expand Down
42 changes: 42 additions & 0 deletions chain/sminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,48 @@ func (c *chainClient) QueryRestoralTarget(puk []byte) (pattern.RestoralTargetInf
return data, nil
}

func (c *chainClient) QueryPendingReplacements(puk []byte) (types.U128, error) {
defer func() {
if err := recover(); err != nil {
log.Println(utils.RecoverError(err))
}
}()

var data types.U128

acc, err := types.NewAccountID(puk)
if err != nil {
return data, errors.Wrap(err, "[NewAccountID]")
}

owner, err := codec.Encode(*acc)
if err != nil {
return data, errors.Wrap(err, "[EncodeToBytes]")
}

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

key, err := types.CreateStorageKey(c.metadata, pattern.SMINER, pattern.PENDINGREPLACE, owner)
if err != nil {
err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] CreateStorageKey: %v", c.GetCurrentRpcAddr(), pattern.SMINER, pattern.PENDINGREPLACE, err)
c.SetChainState(false)
return data, err
}

ok, err := c.api.RPC.State.GetStorageLatest(key, &data)
if err != nil {
err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), pattern.SMINER, pattern.PENDINGREPLACE, err)
c.SetChainState(false)
return data, err
}
if !ok {
return data, pattern.ERR_RPC_EMPTY_VALUE
}
return data, nil
}

func (c *chainClient) UpdateSminerPeerId(peerid pattern.PeerId) (string, error) {
c.lock.Lock()
defer func() {
Expand Down
6 changes: 3 additions & 3 deletions core/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ type SDK interface {
QueryFileMetadata(fid string) (pattern.FileMetadata, error)
// QueryFileMetadataByBlock queries the metadata of the roothash file.
QueryFileMetadataByBlock(fid string, block uint64) (pattern.FileMetadata, error)
// QueryPendingReplacements queries the amount of idle data that can be replaced
// Tip: accountID can only be a storage node account
QueryPendingReplacements(accountID []byte) (types.U128, error)
// QueryRestoralOrder queries a restore order info.
QueryRestoralOrder(roothash string) (pattern.RestoralOrderInfo, error)
QueryRestoralOrderList() ([]pattern.RestoralOrderInfo, error)
Expand Down Expand Up @@ -147,6 +144,9 @@ type SDK interface {
QueryRestoralTarget(accountID []byte) (pattern.RestoralTargetInfo, error)
// QueryRestoralTargetList queries the space recovery information of all exited storage nodes
QueryRestoralTargetList() ([]pattern.RestoralTargetInfo, error)
// QueryPendingReplacements queries the amount of idle data that can be replaced
// Tip: accountID can only be a storage node account
QueryPendingReplacements(accountID []byte) (types.U128, error)

// Sminer-Extrinsics

Expand Down
19 changes: 5 additions & 14 deletions example/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
package main

import (
"encoding/json"
"fmt"
"os"
"log"

"github.com/CESSProject/cess-go-sdk/core/pattern"
"github.com/CESSProject/cess-go-sdk/core/process"
Expand All @@ -22,23 +21,15 @@ type result struct {
}

func main() {
if len(os.Args) < 2 {
fmt.Println("missing parameter")
return
}
seg, rhash, err := process.ShardedEncryptionProcessing(os.Args[1], "")
var file = "process.go"
seg, rhash, err := process.ShardedEncryptionProcessing(file, "")
if err != nil {
fmt.Println(err)
log.Println(err)
return
}
var myResult = result{
Fid: rhash,
SegmentData: seg,
}
buf, err := json.Marshal(myResult)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(buf)
fmt.Println(myResult)
}