Skip to content

Commit

Permalink
fix: using correct substrate rpc types in public methods signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Aug 29, 2023
1 parent a68fc83 commit b38e26b
Show file tree
Hide file tree
Showing 8 changed files with 663 additions and 361 deletions.
307 changes: 162 additions & 145 deletions contract/pkg/bucket/ddc_bucket_contract.go

Large diffs are not rendered by default.

66 changes: 44 additions & 22 deletions contract/pkg/bucket/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ import (
type (
Balance = types.U128
Cash = Balance
Resource = uint32
Token = uint64
ClusterId = uint32
Resource = types.U32
Token = types.U64
ClusterId = types.U32
AccountId = types.AccountID
ProviderId = AccountId
BucketId = uint32
BucketId = types.U32
Params = string
BucketParams = Params
NodeParams = Params
CdnNodeParams = Params
NodeStatusInCluster = byte
NodeKey = string
NodeStatusInCluster = uint8
NodeKey = AccountId
CdnNodeKey = AccountId
)

const (
Expand All @@ -49,7 +51,7 @@ type Cluster struct {
ResourceUsed Resource
Revenues Cash
TotalRent Balance
CdnNodesKeys []NodeKey
CdnNodesKeys []CdnNodeKey
CdnRevenues Cash
CdnUsdPerGb Balance
}
Expand All @@ -65,6 +67,11 @@ type ClusterInfo struct {
NodesVNodes []NodeVNodesInfo
}

type ClusterListInfo struct {
Clusters []ClusterInfo
Total types.U32
}

type NewCluster struct {
Params Params
ResourcePerVNode Resource
Expand All @@ -74,28 +81,38 @@ type Node struct {
ProviderId ProviderId
RentPerMonth Balance
FreeResources Resource
Params string
Params NodeParams
ClusterId types.OptionU32
StatusInCluster types.OptionBytes
StatusInCluster types.OptionU8
}

type NodeInfo struct {
Key string
Key NodeKey
Node Node
VNodes []Token
}

type CDNNode struct {
type NodeListInfo struct {
Nodes []NodeInfo
Total types.U32
}

type CdnNode struct {
ProviderId ProviderId
UndistributedPayment Balance
Params string
Params CdnNodeParams
ClusterId types.OptionU32
StatusInCluster types.OptionBytes
StatusInCluster types.OptionU8
}

type CDNNodeInfo struct {
Key string
Node CDNNode
type CdnNodeInfo struct {
Key CdnNodeKey
Node CdnNode
}

type CdnNodeListInfo struct {
Nodes []CdnNodeInfo
Total types.U32
}

type Bucket struct {
Expand All @@ -120,6 +137,11 @@ type BucketInfo struct {
RentCoveredUntilMs uint64
}

type BucketListInfo struct {
Buckets []BucketListInfo
Total types.U32
}

type Account struct {
Deposit Cash
Bonded Cash
Expand Down Expand Up @@ -370,27 +392,27 @@ func (b *BucketInfo) isReader(address types.Address) bool {
}

func (n *Node) GetStatusInCluster() (NodeStatusInCluster, error) {
hasValue, status := n.StatusInCluster.Unwrap()
hasValue, val := n.StatusInCluster.Unwrap()
if !hasValue {
return UNKNOWN_NODE_STATUS_IN_CLUSTER, fmt.Errorf("unknown storage node status in cluster")
} else {
return status[0], nil
return uint8(val), nil
}
}

func (n *CDNNode) GetStatusInCluster() (NodeStatusInCluster, error) {
hasValue, status := n.StatusInCluster.Unwrap()
func (n *CdnNode) GetStatusInCluster() (NodeStatusInCluster, error) {
hasValue, val := n.StatusInCluster.Unwrap()
if !hasValue {
return UNKNOWN_NODE_STATUS_IN_CLUSTER, fmt.Errorf("unknown cdn node status in cluster")
} else {
return status[0], nil
return uint8(val), nil
}
}

func (n *NodeInfo) GetStatusInCluster() (NodeStatusInCluster, error) {
return n.Node.GetStatusInCluster()
}

func (n *CDNNodeInfo) GetStatusInCluster() (NodeStatusInCluster, error) {
func (n *CdnNodeInfo) GetStatusInCluster() (NodeStatusInCluster, error) {
return n.Node.GetStatusInCluster()
}
1 change: 1 addition & 0 deletions contract/pkg/bucket/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Result struct {
}

func (result *Result) decodeDdcBucketContract(encodedData string) error {

if strings.HasPrefix(encodedData, okPrefix) {
encodedData = strings.TrimPrefix(encodedData, okPrefix)
if err := codec.DecodeFromHex(encodedData, result.data); err != nil {
Expand Down
Loading

0 comments on commit b38e26b

Please sign in to comment.