Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Feature/read missed events #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions contract/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require (
github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.8
github.com/decred/base58 v1.0.3
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7
github.com/golang/mock v1.3.1
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
Expand Down
1 change: 1 addition & 0 deletions contract/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 h1:5ZkaAPbicIKTF
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down
11 changes: 6 additions & 5 deletions contract/pkg/actcapture/activity_capture_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"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"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/utils"
log "github.com/sirupsen/logrus"
"math/big"
)
Expand All @@ -26,7 +27,7 @@ type (
}

activityCaptureContract struct {
client pkg.BlockchainClient
client sdktypes.BlockchainClient
account types.AccountID
keyringPair signature.KeyringPair
contractAddress types.AccountID
Expand All @@ -37,7 +38,7 @@ type (
}
)

func CreateActivityCaptureContract(client pkg.BlockchainClient, contractAddressSS58 string, secret string) ActivityCaptureContract {
func CreateActivityCaptureContract(client sdktypes.BlockchainClient, contractAddressSS58 string, secret string) ActivityCaptureContract {
keyringPair, err := signature.KeyringPairFromSecret(secret, 42)
if err != nil {
log.WithError(err).Fatal("Can't initialize keyring pair for activity capture contract")
Expand All @@ -63,7 +64,7 @@ func CreateActivityCaptureContract(client pkg.BlockchainClient, contractAddressS
log.WithError(err).WithField("method", getEraSettings).Fatal("Can't decode method getEraSettingsMethod")
}

contractAddress, err := pkg.DecodeAccountIDFromSS58(contractAddressSS58)
contractAddress, err := utils.DecodeAccountIDFromSS58(contractAddressSS58)
if err != nil {
log.WithError(err).WithField("contractAddressSS58", contractAddressSS58).Fatal("Can't decode contract address SS58")
}
Expand Down Expand Up @@ -101,7 +102,7 @@ func (a *activityCaptureContract) SetCommit(ctx context.Context, hash []byte, ga
From := types.U64(from)
To := types.U64(to)

call := pkg.ContractCall{
call := sdktypes.ContractCall{
ContractAddress: a.contractAddress,
ContractAddressSS58: a.contractAddressSS58,
From: a.keyringPair,
Expand Down
16 changes: 8 additions & 8 deletions contract/pkg/bucket/ddc_bucket_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
_ "embed"
"encoding/hex"
"errors"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes"
"reflect"
"time"

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

Expand Down Expand Up @@ -50,11 +50,11 @@ type (
CDNNodeGet(nodeId uint32) (*CDNNodeStatus, error)
AccountGet(account types.AccountID) (*Account, error)
AddContractEventHandler(event string, handler func(interface{})) error
GetEventDispatcher() map[types.Hash]pkg.ContractEventDispatchEntry
GetEventDispatcher() map[types.Hash]sdktypes.ContractEventDispatchEntry
}

ddcBucketContract struct {
contract pkg.BlockchainClient
contract sdktypes.BlockchainClient
lastAccessTime time.Time
contractAddressSS58 string
keyringPair signature.KeyringPair
Expand All @@ -64,7 +64,7 @@ type (
cdnClusterGetMethodId []byte
cdnNodeGetMethodId []byte
accountGetMethodId []byte
eventDispatcher map[types.Hash]pkg.ContractEventDispatchEntry
eventDispatcher map[types.Hash]sdktypes.ContractEventDispatchEntry
}
)

Expand All @@ -85,7 +85,7 @@ var eventDispatchTable = map[string]reflect.Type{
GrantPermissionEventId: reflect.TypeOf(GrantPermissionEvent{}),
RevokePermissionEventId: reflect.TypeOf(RevokePermissionEvent{})}

func CreateDdcBucketContract(client pkg.BlockchainClient, contractAddressSS58 string) DdcBucketContract {
func CreateDdcBucketContract(client sdktypes.BlockchainClient, contractAddressSS58 string) DdcBucketContract {
bucketGetMethodId, err := hex.DecodeString(bucketGetMethod)
if err != nil {
log.WithError(err).WithField("method", bucketGetMethod).Fatal("Can't decode method bucketGetMethod")
Expand Down Expand Up @@ -116,12 +116,12 @@ func CreateDdcBucketContract(client pkg.BlockchainClient, contractAddressSS58 st
log.WithError(err).WithField("method", accountGetMethod).Fatal("Can't decode method accountGetMethod")
}

eventDispatcher := make(map[types.Hash]pkg.ContractEventDispatchEntry)
eventDispatcher := make(map[types.Hash]sdktypes.ContractEventDispatchEntry)
for k, v := range eventDispatchTable {
if key, err := types.NewHashFromHexString(k); err != nil {
log.WithError(err).WithField("hash", k).Fatalf("Bad event hash for event %s", v.Name())
} else {
eventDispatcher[key] = pkg.ContractEventDispatchEntry{ArgumentType: v}
eventDispatcher[key] = sdktypes.ContractEventDispatchEntry{ArgumentType: v}
}
}

Expand Down Expand Up @@ -224,6 +224,6 @@ func (d *ddcBucketContract) GetLastAccessTime() time.Time {
return d.lastAccessTime
}

func (d *ddcBucketContract) GetEventDispatcher() map[types.Hash]pkg.ContractEventDispatchEntry {
func (d *ddcBucketContract) GetEventDispatcher() map[types.Hash]sdktypes.ContractEventDispatchEntry {
return d.eventDispatcher
}
4 changes: 2 additions & 2 deletions contract/pkg/bucket/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package bucket

import (
"encoding/hex"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/utils"
"strings"
"testing"

Expand All @@ -16,7 +16,7 @@ func TestBucketWriteAccess(t *testing.T) {
publicKey := "0xd049e851567f16d68523a645ee96465ceb678ad983fc08e6a38408ad10410c4d"
publicKeyB, _ := hex.DecodeString(strings.TrimPrefix(publicKey, "0x"))

accountID, _ := pkg.DecodeAccountIDFromSS58(ss58)
accountID, _ := utils.DecodeAccountIDFromSS58(ss58)
bucketStatus := &BucketStatus{WriterIds: []types.AccountID{accountID}}

//when
Expand Down
4 changes: 2 additions & 2 deletions contract/pkg/cache/ddc_bucket_contract_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package cache

import (
"encoding/hex"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes"
"strconv"
"time"

"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/bucket"
"github.com/golang/groupcache/singleflight"
"github.com/patrickmn/go-cache"
Expand Down Expand Up @@ -184,7 +184,7 @@ func (d *ddcBucketContractCached) AddContractEventHandler(event string, handler
return d.ddcBucketContract.AddContractEventHandler(event, handler)
}

func (d *ddcBucketContractCached) GetEventDispatcher() map[types.Hash]pkg.ContractEventDispatchEntry {
func (d *ddcBucketContractCached) GetEventDispatcher() map[types.Hash]sdktypes.ContractEventDispatchEntry {
return d.ddcBucketContract.GetEventDispatcher()
}

Expand Down
4 changes: 2 additions & 2 deletions contract/pkg/cache/ddc_bucket_contract_cache_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cache

import (
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes"
"testing"
"time"

"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/bucket"
"github.com/patrickmn/go-cache"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -60,7 +60,7 @@ func (d *mockedDdcBucketContract) AddContractEventHandler(event string, handler
return nil
}

func (d *mockedDdcBucketContract) GetEventDispatcher() map[types.Hash]pkg.ContractEventDispatchEntry {
func (d *mockedDdcBucketContract) GetEventDispatcher() map[types.Hash]sdktypes.ContractEventDispatchEntry {
return nil
}

Expand Down
Loading