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

DDC Smart Contract v.1.0.0 #60

Merged
merged 102 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
8726ea0
Add all methods, implement them for standart contract object
CereVGello Jul 18, 2023
b20ad67
feat: implemented ClusterCreate, ClusterAddNode, ClusterRemoveNode, C…
samvel-vardanyan Jul 31, 2023
603d03d
feat: resolved merge conflicts
samvel-vardanyan Jul 31, 2023
2c6d8dc
feat: some more methods implemented
samvel-vardanyan Aug 7, 2023
7a1e830
feat: small change
samvel-vardanyan Aug 7, 2023
8927116
feat: fixed failed tests
samvel-vardanyan Aug 8, 2023
a4bdcb9
Methods implementation
Aug 11, 2023
f192f53
uint32 fix
Aug 11, 2023
86afffd
feat: Error types for ddc go sdk
samvel-vardanyan Aug 14, 2023
df9abfe
small fix
samvel-vardanyan Aug 14, 2023
014e493
feat: nodeStatus order corected
samvel-vardanyan Aug 14, 2023
3c4ace3
feat(ddc-schemas): numeric 'nodeID' is replaced with stringified 'nod…
yahortsaryk Aug 15, 2023
2e586c8
feat(topology): numeric 'nodeID' is replaced with stringified 'nodeKey'
yahortsaryk Aug 15, 2023
4bc94f8
feat(cluster): cluster response struct is updated
yahortsaryk Aug 15, 2023
e391485
test(scheduler): making testable node keys public
yahortsaryk Aug 15, 2023
2dc24e5
feat(topology): creating Topology object based on grouped vNodes
yahortsaryk Aug 15, 2023
925cbba
refactor(cluster): field name for grouped vNodes is changed
yahortsaryk Aug 15, 2023
89ee068
fix(topology): param object fields made public
yahortsaryk Aug 15, 2023
939ee03
feat: all event types added to go sdk
samvel-vardanyan Aug 16, 2023
0b30365
reloved merge conflicts
samvel-vardanyan Aug 16, 2023
fd478da
resolved merge conflicts
samvel-vardanyan Aug 16, 2023
cbc1ceb
resloved merge conflicts
samvel-vardanyan Aug 16, 2023
a07852b
chore(mock): adding some logging info
yahortsaryk Aug 16, 2023
f5d39e0
Merge branch 'feature/new_smart_contract' of github.com:Cerebellum-Ne…
yahortsaryk Aug 16, 2023
863ec78
chore(mock): adding some logging info
yahortsaryk Aug 16, 2023
3acad0f
chore(mock): adding some logging info
yahortsaryk Aug 17, 2023
9917475
clean up for removed endpoints and structs
samvel-vardanyan Aug 21, 2023
6c6f5ab
Merge branch 'feature/new_smart_contract' of github-cere-io:Cerebellu…
samvel-vardanyan Aug 21, 2023
f6b4307
feat: removed commented code
samvel-vardanyan Aug 21, 2023
ce6802c
chore: publicKey is removed from cdn node params
yahortsaryk Aug 23, 2023
f60e2dc
fix: storage and cdn node response struct is fixed
yahortsaryk Aug 23, 2023
48f32dc
chore: naming is changed for sc response structs; helpers methods are…
yahortsaryk Aug 23, 2023
7c720e6
chore: helpers methods for node status in cluster
yahortsaryk Aug 23, 2023
b503c90
fix: errors enum order is fixed
yahortsaryk Aug 25, 2023
a68fc83
feat: bucket and account methods for bucket_contract first commit
samvel-vardanyan Aug 28, 2023
b38e26b
fix: using correct substrate rpc types in public methods signatures
yahortsaryk Aug 28, 2023
e8ba328
Merge pull request #61 from Cerebellum-Network/fix/sdk-sc-v1-rebased
yahortsaryk Aug 29, 2023
7676e68
fix: BucketList
yahortsaryk Aug 29, 2023
d987a88
feat: bucket methods for bucket-contract
samvel-vardanyan Aug 29, 2023
94aee8c
feat: added all methods to the bucket contract
samvel-vardanyan Aug 29, 2023
7bf8115
changed account type for BucketChangeOwner method
samvel-vardanyan Sep 1, 2023
70cef53
small fix
samvel-vardanyan Sep 1, 2023
38b8fab
feat: fix for accountId type for bucket methods
samvel-vardanyan Sep 4, 2023
fc3dbee
small fix
samvel-vardanyan Sep 5, 2023
8a9cc63
fixed types for tests
samvel-vardanyan Sep 5, 2023
fef0962
BucketListForAccount types for mock
samvel33651 Sep 5, 2023
977f479
fix for mock types
samvel33651 Sep 5, 2023
91ebfa1
node get type corrected
samvel-vardanyan Sep 6, 2023
09a1469
Merge branch 'feature/new_smart_contract' of github-cere-io:Cerebellu…
samvel-vardanyan Sep 6, 2023
6e58b54
reverted back node status
samvel-vardanyan Sep 6, 2023
1387ca4
all types are checked and corrected
samvel-vardanyan Sep 6, 2023
a5ca7d8
small change
samvel-vardanyan Sep 6, 2023
5a7c8ff
feat: added event handlers
samvel-vardanyan Sep 11, 2023
db4ab0c
small fix
samvel-vardanyan Sep 11, 2023
97458d7
BucketList info struct fix
samvel-vardanyan Sep 15, 2023
35da6d6
fix: sc event listener function is fixed
yahortsaryk Sep 15, 2023
1ee47d1
fix: cyclic reference is fixed
yahortsaryk Sep 15, 2023
a05528e
chore: tidy up references
yahortsaryk Sep 15, 2023
780efd6
fix: bucket list endpoint is fixed
yahortsaryk Sep 15, 2023
e8a87fc
Merge branch 'fix/sc-event-listener' into feature/new_smart_contract
yahortsaryk Sep 15, 2023
a90c1aa
get accounts method
samvel-vardanyan Sep 18, 2023
84e801c
Merge branch 'feature/new_smart_contract' of github-cere-io:Cerebellu…
samvel-vardanyan Sep 18, 2023
ced782a
bucketList for account method fixed
samvel-vardanyan Sep 18, 2023
5d0cd8a
small fix
samvel-vardanyan Sep 18, 2023
d7c8836
small fix 2
samvel-vardanyan Sep 18, 2023
0c32670
made corrections to hasPermission and AccountGetUsdPerCere methods
samvel-vardanyan Sep 18, 2023
edb357c
feat: cluster create
yahortsaryk Sep 18, 2023
2cd8f3a
fix: cluster create call
yahortsaryk Sep 18, 2023
c1552b5
fix: gas limit type is fixed
yahortsaryk Sep 18, 2023
e89b2d7
fix: subscription additional check is added
yahortsaryk Sep 18, 2023
f034091
feat: passing params list for 'CreateCluster' endpoint
yahortsaryk Sep 18, 2023
805980a
fix: var names for eventKey
yahortsaryk Sep 18, 2023
56c4fa6
Merge branch 'feat/cluster-create' into feature/new_smart_contract
yahortsaryk Sep 18, 2023
b0d03be
bucket struct added flow property
samvel33651 Sep 20, 2023
12ae4c9
bucket struct fix
samvel33651 Sep 20, 2023
09e679e
bucket struct updated
samvel33651 Sep 20, 2023
0c7ae8d
signatur for cluster methods
samvel-vardanyan Sep 20, 2023
d31637e
signature for node methods
samvel-vardanyan Sep 20, 2023
7fd5dec
signature for bucket methods
samvel-vardanyan Sep 20, 2023
92d1b02
signature for account methods
samvel-vardanyan Sep 20, 2023
0d511aa
signature for permission methods
samvel-vardanyan Sep 20, 2023
15ee334
signature for account deposit method
samvel-vardanyan Sep 21, 2023
67bc2cb
bucketList for account
samvel-vardanyan Sep 25, 2023
79e8969
get bucketWriters method
samvel-vardanyan Sep 26, 2023
da254e3
getbucketreaders method
samvel-vardanyan Sep 26, 2023
8ccee3a
bucketList for account
samvel-vardanyan Sep 27, 2023
8394fde
bucketList for account return type
samvel-vardanyan Sep 27, 2023
e574244
small chnage
samvel-vardanyan Sep 27, 2023
ae7e4a5
bucketListfor account return type chnaged
samvel-vardanyan Sep 27, 2023
cf16596
removed flow type from bucket
samvel-vardanyan Sep 27, 2023
25edbcd
small change
samvel-vardanyan Sep 27, 2023
21ab859
accountgetUsdPerCere method
samvel-vardanyan Sep 27, 2023
a7f3727
small fix
samvel-vardanyan Sep 27, 2023
aa98609
type chnaged
samvel-vardanyan Sep 27, 2023
da15b5f
accountgetusdpercere test
samvel-vardanyan Sep 27, 2023
982fb0d
reverted accountgetUsdPerCere method types
samvel-vardanyan Sep 27, 2023
08d89e1
test number n
samvel-vardanyan Sep 27, 2023
105aaaf
bucketListforaccount types
samvel-vardanyan Sep 27, 2023
9b2a3e9
bucketList for account types reverted
samvel-vardanyan Sep 27, 2023
1e6982a
Feature/address for network2 (#68)
idmitriev Sep 28, 2023
59ccce9
Merging with 'master'
yahortsaryk Oct 17, 2023
6f3ba9d
fix: NodeCreate method signature is fixed
yahortsaryk Oct 17, 2023
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
packages = ./model/... ./core/... ./contract/... ./contentadrstorage/...

.PHONY: test
test:
go test ${packages}

Expand Down
2 changes: 1 addition & 1 deletion contract/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/cerebellum-network/cere-ddc-sdk-go/contract
require (
github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.8
github.com/decred/base58 v1.0.3
github.com/ethereum/go-ethereum v1.10.17
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
Expand All @@ -17,7 +18,6 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
github.com/ethereum/go-ethereum v1.10.17 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gtank/merlin v0.1.1 // indirect
Expand Down
5 changes: 3 additions & 2 deletions contract/pkg/actcapture/activity_capture_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package actcapture
import (
"context"
"encoding/hex"
"math/big"

"github.com/centrifuge/go-substrate-rpc-client/v4/signature"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg"
log "github.com/sirupsen/logrus"
"math/big"
)

const (
Expand Down Expand Up @@ -106,7 +107,7 @@ func (a *activityCaptureContract) SetCommit(ctx context.Context, hash []byte, ga
ContractAddressSS58: a.contractAddressSS58,
From: a.keyringPair,
Value: 0,
GasLimit: -1,
GasLimit: 0,
Method: a.setCommitMethodId,
Args: []interface{}{a.account, types.NewHash(hash), Gas, From, To},
}
Expand Down
7 changes: 3 additions & 4 deletions contract/pkg/bucket/cdn_node_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (

// Structure-helper for json on the CDN Node Params string
type CDNNodeParams struct {
Url string `json:"url"`
Size FlexInt `json:"size"`
Location string `json:"location"`
PublicKey string `json:"publicKey"`
Url string `json:"url"`
Size FlexInt `json:"size"`
Location string `json:"location"`
}

func ReadCDNNodeParams(s string) (p CDNNodeParams, err error) {
Expand Down
18 changes: 8 additions & 10 deletions contract/pkg/bucket/cdn_node_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,21 @@ func TestReadCDNNodeParams(t *testing.T) {
}{
{
name: "Positive test",
args: args{s: `{"url":"http://localhost:8080", "publicKey": "NodePublicKey", "size":1, "location":"US"}`},
args: args{s: `{"url":"http://localhost:8080", "size":1, "location":"US"}`},
wantP: CDNNodeParams{
Url: "http://localhost:8080",
Size: 1,
Location: "US",
PublicKey: "NodePublicKey",
Url: "http://localhost:8080",
Size: 1,
Location: "US",
},
wantErr: false,
},
{
name: "Positive test with size as string",
args: args{s: `{"url":"http://localhost:8080", "publicKey": "NodePublicKey", "size":"1", "location":"US"}`},
args: args{s: `{"url":"http://localhost:8080", "size":"1", "location":"US"}`},
wantP: CDNNodeParams{
Url: "http://localhost:8080",
Size: 1,
Location: "US",
PublicKey: "NodePublicKey",
Url: "http://localhost:8080",
Size: 1,
Location: "US",
},
wantErr: false,
},
Expand Down
902 changes: 832 additions & 70 deletions contract/pkg/bucket/ddc_bucket_contract.go

Large diffs are not rendered by default.

178 changes: 165 additions & 13 deletions contract/pkg/bucket/ddc_bucket_contract_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,183 @@ package bucket
import "errors"

const (
bucketDoesNotExist = iota
providerDoesNotExist
unauthorizedProvider
nodeDoesNotExist = iota
cdnNodeDoesNotExist
nodeAlreadyExists
cdnNodeAlreadyExists
accountDoesNotExist
paramsDoesNotExist
paramsSizeExceedsLimit
onlyOwner
onlyNodeProvider
onlyCdnNodeProvider
onlyClusterManager
onlyTrustedClusterManager
onlyValidator
onlySuperAdmin
onlyClusterManagerOrNodeProvider
onlyClusterManagerOrCdnNodeProvider
unauthorized
clusterDoesNotExist
clusterIsNotEmpty
topologyIsNotCreated
topologyAlreadyExists
nodesSizeExceedsLimit
cdnNodesSizeExceedsLimit
vNodesSizeExceedsLimit
accountsSizeExceedsLimit
nodeIsNotAddedToCluster
nodeIsAddedToCluster
cdnNodeIsNotAddedToCluster
cdnNodeIsAddedToCluster
vNodeDoesNotExistsInCluster
vNodeIsNotAssignedToNode
vNodeIsAlreadyAssignedToNode
atLeastOneVNodeHasToBeAssigned
nodeProviderIsNotSuperAdmin
cdnNodeOwnerIsNotSuperAdmin
bucketDoesNotExist
bondingPeriodNotFinished
transferFailed
insufficientBalance
insufficientNodeResources
insufficientClusterResources
eraSettingFailed
)

//ToDo update error regarding latest contract
// ToDo update error regarding latest contract
var (
ErrBucketDoesNotExist = errors.New("bucket doesn't exist")
ErrProviderDoesNotExist = errors.New("provider doesn't exist")
ErrUnauthorizedProvider = errors.New("unauthorized provider")
ErrTransferFailed = errors.New("transfer failed")
ErrUndefined = errors.New("undefined error")
ErrBucketDoesNotExist = errors.New("bucket doesn't exist")
ErrTransferFailed = errors.New("transfer failed")
ErrUndefined = errors.New("undefined error")
ErrNodeDoesNotExist = errors.New("node does not exist")
ErrCdnNodeDoesNotExist = errors.New("cdn node does not exist")
ErrNodeAlreadyExists = errors.New("node already exists")
ErrCdnNodeAlreadyExists = errors.New("cdn node already exists")
ErrAccountDoesNotExist = errors.New("account does not exist")
ErrParamsDoesNotExist = errors.New("params does not exist")
ErrParamsSizeExceedsLimit = errors.New("params size exceeds limit")
ErrOnlyOwner = errors.New("only owner")
ErrOnlyNodeProvider = errors.New("only node provider")
ErrOnlyCdnNodeProvider = errors.New("only cdn node provider")
ErrOnlyClusterManager = errors.New("only cluster manager")
ErrOnlyTrustedClusterManager = errors.New("only trusted cluster manager")
ErrOnlyValidator = errors.New("only validator")
ErrOnlySuperAdmin = errors.New("only super admin")
ErrOnlyClusterManagerOrNodeProvider = errors.New("only cluster manager or node provider")
ErrOnlyClusterManagerOrCdnNodeProvider = errors.New("only cluster manager or cdn node provider")
ErrUnauthorized = errors.New("unauthorized")
ErrClusterDoesNotExist = errors.New("cluster does not exist")
ErrClusterIsNotEmpty = errors.New("cluster is not empty")
ErrTopologyIsNotCreated = errors.New("topology is not created")
ErrTopologyAlreadyExists = errors.New("topology already exists")
ErrNodesSizeExceedsLimit = errors.New("nodes size exceeds limit")
ErrCdnNodesSizeExceedsLimit = errors.New("cdn nodes size exceeds limit")
ErrVNodesSizeExceedsLimit = errors.New("vnodes size exceeds limit")
ErrAccountsSizeExceedsLimit = errors.New("accounts size exceeds limit")
ErrNodeIsNotAddedToCluster = errors.New("node is not added to cluster")
ErrNodeIsAddedToCluster = errors.New("node is added to cluster")
ErrCdnNodeIsNotAddedToCluster = errors.New("cdn node is not added to cluster")
ErrCdnNodeIsAddedToCluster = errors.New("cdn node is added to cluster")
ErrVNodeDoesNotExistsInCluster = errors.New("vnode does not exists in cluster")
ErrVNodeIsNotAssignedToNode = errors.New("vnode is not assigned to node")
ErrVNodeIsAlreadyAssignedToNode = errors.New("vnode is already assigned to node")
ErrAtLeastOneVNodeHasToBeAssigned = errors.New("at least one vnode has to be assigned")
ErrNodeProviderIsNotSuperAdmin = errors.New("node provider is not super admin")
ErrCdnNodeOwnerIsNotSuperAdmin = errors.New("cdn node owner is not super admin")
ErrBondingPeriodNotFinished = errors.New("bonding period is not finished")
ErrInsufficientBalance = errors.New("insufficient balance")
ErrInsufficientNodeResources = errors.New("insufficient node resources")
ErrInsufficientClusterResources = errors.New("insufficient cluster resources")
ErrEraSettingFailed = errors.New("era setting failed")
)

func parseDdcBucketContractError(error uint8) error {
switch error {
case bucketDoesNotExist:
return ErrBucketDoesNotExist
case providerDoesNotExist:
return ErrProviderDoesNotExist
case unauthorizedProvider:
return ErrUnauthorizedProvider
case transferFailed:
return ErrTransferFailed
case nodeDoesNotExist:
return ErrNodeDoesNotExist
case cdnNodeDoesNotExist:
return ErrCdnNodeDoesNotExist
case nodeAlreadyExists:
return ErrNodeAlreadyExists
case cdnNodeAlreadyExists:
return ErrCdnNodeAlreadyExists
case accountDoesNotExist:
return ErrAccountDoesNotExist
case paramsDoesNotExist:
return ErrParamsDoesNotExist
case paramsSizeExceedsLimit:
return ErrParamsSizeExceedsLimit
case onlyOwner:
return ErrOnlyOwner
case onlyNodeProvider:
return ErrOnlyNodeProvider
case onlyCdnNodeProvider:
return ErrOnlyCdnNodeProvider
case onlyClusterManager:
return ErrOnlyClusterManager
case onlyTrustedClusterManager:
return ErrOnlyTrustedClusterManager
case onlyValidator:
return ErrOnlyValidator
case onlySuperAdmin:
return ErrOnlySuperAdmin
case onlyClusterManagerOrNodeProvider:
return ErrOnlyClusterManagerOrNodeProvider
case onlyClusterManagerOrCdnNodeProvider:
return ErrOnlyClusterManagerOrCdnNodeProvider
case unauthorized:
return ErrUnauthorized
case clusterDoesNotExist:
return ErrClusterDoesNotExist
case clusterIsNotEmpty:
return ErrClusterIsNotEmpty
case topologyIsNotCreated:
return ErrTopologyIsNotCreated
case topologyAlreadyExists:
return ErrTopologyAlreadyExists
case nodesSizeExceedsLimit:
return ErrNodesSizeExceedsLimit
case cdnNodesSizeExceedsLimit:
return ErrCdnNodesSizeExceedsLimit
case vNodesSizeExceedsLimit:
return ErrVNodesSizeExceedsLimit
case accountsSizeExceedsLimit:
return ErrAccountsSizeExceedsLimit
case nodeIsNotAddedToCluster:
return ErrNodeIsNotAddedToCluster
case nodeIsAddedToCluster:
return ErrNodeIsAddedToCluster
case cdnNodeIsNotAddedToCluster:
return ErrCdnNodeIsNotAddedToCluster
case cdnNodeIsAddedToCluster:
return ErrCdnNodeIsAddedToCluster
case vNodeDoesNotExistsInCluster:
return ErrVNodeDoesNotExistsInCluster
case vNodeIsNotAssignedToNode:
return ErrVNodeIsNotAssignedToNode
case vNodeIsAlreadyAssignedToNode:
return ErrVNodeIsAlreadyAssignedToNode
case atLeastOneVNodeHasToBeAssigned:
return ErrAtLeastOneVNodeHasToBeAssigned
case nodeProviderIsNotSuperAdmin:
return ErrNodeProviderIsNotSuperAdmin
case cdnNodeOwnerIsNotSuperAdmin:
return ErrCdnNodeOwnerIsNotSuperAdmin
case bondingPeriodNotFinished:
return ErrBondingPeriodNotFinished
case insufficientBalance:
return ErrInsufficientBalance
case insufficientNodeResources:
return ErrInsufficientNodeResources
case insufficientClusterResources:
return ErrInsufficientClusterResources
case eraSettingFailed:
return ErrEraSettingFailed
default:
return ErrUndefined
}
Expand Down
Loading
Loading