diff --git a/chain/fileBank.go b/chain/fileBank.go index 1a19cb7..d253993 100644 --- a/chain/fileBank.go +++ b/chain/fileBank.go @@ -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 { diff --git a/chain/sminer.go b/chain/sminer.go index e531042..5ff1af2 100644 --- a/chain/sminer.go +++ b/chain/sminer.go @@ -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() { diff --git a/core/sdk/sdk.go b/core/sdk/sdk.go index dd2dd31..cf70ea3 100644 --- a/core/sdk/sdk.go +++ b/core/sdk/sdk.go @@ -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) @@ -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 diff --git a/example/process/process.go b/example/process/process.go index 6821e24..2c9d518 100644 --- a/example/process/process.go +++ b/example/process/process.go @@ -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" @@ -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) }