Skip to content

Commit

Permalink
Merge pull request #96 from Cerebellum-Network/feature/blockchain-v5.4.0
Browse files Browse the repository at this point in the history
Blockchain `v5.4.0` support
  • Loading branch information
khssnv authored May 27, 2024
2 parents 056d955 + 90f3ea9 commit 0d36ba0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions blockchain/pallets/ddcclusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Cluster struct {
ManagerId types.AccountID
ReserveId types.AccountID
Props ClusterProps
Status ClusterStatus
}

type ClusterProps struct {
Expand Down
51 changes: 51 additions & 0 deletions blockchain/pallets/primitives.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package pallets

import (
"errors"
"reflect"

"github.com/centrifuge/go-substrate-rpc-client/v4/scale"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
Expand Down Expand Up @@ -118,3 +119,53 @@ func (m StorageNodeMode) Encode(encoder scale.Encoder) error {

return nil
}

type ClusterStatus struct {
IsUnbonded bool
IsBonded bool
IsActivated bool
IsUnbonding bool
}

func (m *ClusterStatus) Decode(decoder scale.Decoder) error {
b, err := decoder.ReadOneByte()
if err != nil {
return err
}

i := int(b)

v := reflect.ValueOf(m)
if i > v.NumField() {
return ErrUnknownVariant
}

v.Field(i).SetBool(true)

return nil
}

func (m ClusterStatus) Encode(encoder scale.Encoder) error {
var err1, err2 error
v := reflect.ValueOf(m)

for i := 0; i < v.NumField(); i++ {
if v.Field(i).Bool() {
err1 = encoder.PushByte(byte(i))
err2 = encoder.Encode(i + 1) // values are defined from 1
break
}
if i == v.NumField()-1 {
return ErrUnknownVariant
}
}

if err1 != nil {
return err1
}
if err2 != nil {
return err2
}

return nil
}

0 comments on commit 0d36ba0

Please sign in to comment.