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

Sprint5 chain #27

Merged
merged 3 commits into from
Apr 14, 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
8 changes: 7 additions & 1 deletion core/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ type Chain interface {
// Register is used to register OSS or BUCKET roles
Register(name, multiaddr string, income string, pledge uint64) (string, error)
// Update is used to update the communication address of the scheduling service
Update(name, multiaddr string) (string, error)
UpdateAddress(name, multiaddr string) (string, error)
//
UpdateIncomeAccount(pubkey []byte) (string, error)
// CreateBucket is used to create a bucket for users
CreateBucket(owner_pkey []byte, name string) (string, error)
// DeleteBucket is used to delete buckets created by users
Expand All @@ -78,6 +80,10 @@ type Chain interface {
QueryUserSpaceInfo(pubkey []byte) (UserSpaceInfo, error)
//
IncreaseStakes(tokens *big.Int) (string, error)
//
Exit(role string) (string, error)
//
QuerySpacePricePerGib() (string, error)
}

type chainClient struct {
Expand Down
7 changes: 7 additions & 0 deletions core/chain/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ type Event_OssUpdate struct {
Topics []types.Hash
}

type Event_OssDestroy struct {
Phase types.Phase
Acc types.AccountID
Topics []types.Hash
}

// ------------------------System------------------------
type Event_UnsignedPhaseStarted struct {
Phase types.Phase
Expand Down Expand Up @@ -430,6 +436,7 @@ type EventRecords struct {
// OSS
Oss_OssRegister []Event_OssRegister
Oss_OssUpdate []Event_OssUpdate
Oss_OssDestroy []Event_OssDestroy
// System
types.EventRecords
}
35 changes: 35 additions & 0 deletions core/chain/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package chain

import (
"fmt"
"log"

"github.com/CESSProject/sdk-go/core/utils"
Expand Down Expand Up @@ -563,6 +564,40 @@ func (c *chainClient) QueryUserSpaceInfo(pubkey []byte) (UserSpaceInfo, error) {
return data, nil
}

func (c *chainClient) QuerySpacePricePerGib() (string, error) {
defer func() {
if err := recover(); err != nil {
println(utils.RecoverError(err))
}
}()
var data types.U128

if !c.IsChainClientOk() {
c.SetChainState(false)
return "", ERR_RPC_CONNECTION
}
c.SetChainState(true)

key, err := types.CreateStorageKey(
c.metadata,
STORAGEHANDLER,
UNITPRICE,
)
if err != nil {
return "", errors.Wrap(err, "[CreateStorageKey]")
}

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

return fmt.Sprintf("%v", data), nil
}

// Pallert
const (
_FILEBANK = "FileBank"
Expand Down
Loading