Skip to content

Commit

Permalink
Merge pull request #95 from Cerebellum-Network/chore/remove-dead-code
Browse files Browse the repository at this point in the history
Remove dead code
  • Loading branch information
khssnv authored May 24, 2024
2 parents 6d19906 + 06c7187 commit 056d955
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 136 deletions.
4 changes: 4 additions & 0 deletions blockchain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Cere Blockchain RPC Client

This package supports a minimal subset of Cere Network blockchain types definitions and RPCs explicitly requested by users.
Please [create an issue](https://github.com/Cerebellum-Network/cere-ddc-sdk-go/issues/new) requesting support for a missing RPC you need.
2 changes: 0 additions & 2 deletions blockchain/pallets/ddcclusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ type Cluster struct {
Props ClusterProps
}

type ClustersNodes map[ClusterId][]NodePubKey

type ClusterProps struct {
NodeProviderAuthContract types.OptionAccountID
ErasureCodingRequired types.U32
Expand Down
134 changes: 0 additions & 134 deletions blockchain/pallets/ddcpayouts.go
Original file line number Diff line number Diff line change
@@ -1,98 +1,12 @@
package pallets

import (
"reflect"

gsrpc "github.com/centrifuge/go-substrate-rpc-client/v4"
"github.com/centrifuge/go-substrate-rpc-client/v4/scale"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
)

type BatchIndex = types.U16

type BillingReport struct {
State State
Vault types.AccountID
TotalCustomerCharges CustomerCharge
TotalDistributedReward types.U128
TotalNodeUsage NodeUsage
ChargingMaxBatchIndex BatchIndex
ChargingProcessedBatches []BatchIndex
RewardingMaxBatchIndex BatchIndex
RewardingProcessedBatches []BatchIndex
}

type CustomerCharge struct {
Transfer types.U128
Storage types.U128
Puts types.U128
Gets types.U128
}

type NodeUsage struct {
TransferredBytes types.U64
StoredBytes types.U64
NumberOfPuts types.U128
NumberOfGets types.U128
}

type State struct {
IsNotInitialized bool
IsInitialized bool
IsChargingCustomers bool
IsCustomersChargedWithFees bool
IsRewardingProviders bool
IsProvidersRewarded bool
IsFinalized bool
}

func (m *State) 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 State) 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
}

type DdcPayoutsApi interface {
GetActiveBillingReports(cluster ClusterId, era DdcEra) (types.Option[BillingReport], error)
GetAuthorisedCaller() (types.Option[types.AccountID], error)
GetDebtorCustomers(cluster ClusterId, account types.AccountID) (types.Option[types.U128], error)
}

Expand All @@ -108,54 +22,6 @@ func NewDdcPayoutsApi(substrateApi *gsrpc.SubstrateAPI, meta *types.Metadata) Dd
}
}

func (api *ddcPayoutsApi) GetActiveBillingReports(cluster ClusterId, era DdcEra) (types.Option[BillingReport], error) {
maybeV := types.NewEmptyOption[BillingReport]()

bytesCluster, err := codec.Encode(cluster)
if err != nil {
return maybeV, err
}

bytesEra, err := codec.Encode(era)
if err != nil {
return maybeV, err
}

key, err := types.CreateStorageKey(api.meta, "DdcPayouts", "DebtorCustomers", bytesCluster, bytesEra)
if err != nil {
return maybeV, err
}

var v BillingReport
ok, err := api.substrateApi.RPC.State.GetStorageLatest(key, &v)
if !ok || err != nil {
return maybeV, err
}

maybeV.SetSome(v)

return maybeV, nil
}

func (api *ddcPayoutsApi) GetAuthorisedCaller() (types.Option[types.AccountID], error) {
maybeV := types.NewEmptyOption[types.AccountID]()

key, err := types.CreateStorageKey(api.meta, "DdcPayouts", "AuthorisedCaller")
if err != nil {
return maybeV, err
}

var v types.AccountID
ok, err := api.substrateApi.RPC.State.GetStorageLatest(key, &v)
if !ok || err != nil {
return maybeV, err
}

maybeV.SetSome(v)

return maybeV, nil
}

func (api *ddcPayoutsApi) GetDebtorCustomers(cluster ClusterId, account types.AccountID) (types.Option[types.U128], error) {
maybeV := types.NewEmptyOption[types.U128]()

Expand Down

0 comments on commit 056d955

Please sign in to comment.