-
Notifications
You must be signed in to change notification settings - Fork 74
/
artela.go
79 lines (66 loc) · 2.45 KB
/
artela.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package provider
import (
"context"
"errors"
"github.com/artela-network/artela/x/evm/artela/contract"
"github.com/artela-network/artela/x/evm/artela/types"
asptypes "github.com/artela-network/aspect-core/types"
"github.com/cometbft/cometbft/libs/log"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/ethereum/go-ethereum/common"
)
var _ asptypes.AspectProvider = (*ArtelaProvider)(nil)
type ArtelaProvider struct {
service *contract.AspectService
storeKey storetypes.StoreKey
}
func NewArtelaProvider(storeKey storetypes.StoreKey,
getBlockHeight types.GetLastBlockHeight,
logger log.Logger,
) *ArtelaProvider {
service := contract.NewAspectService(storeKey, getBlockHeight, logger)
return &ArtelaProvider{service, storeKey}
}
func (j *ArtelaProvider) GetTxBondAspects(ctx context.Context, address common.Address, point asptypes.PointCut) ([]*asptypes.AspectCode, error) {
if ctx == nil {
return nil, errors.New("invalid Context")
}
aspectCtx, ok := ctx.(*types.AspectRuntimeContext)
if !ok {
return nil, errors.New("failed to unwrap AspectRuntimeContext from context.Context")
}
return j.service.GetAspectsForJoinPoint(aspectCtx.CosmosContext(), address, point)
}
func (j *ArtelaProvider) GetAccountVerifiers(ctx context.Context, address common.Address) ([]*asptypes.AspectCode, error) {
if ctx == nil {
return nil, errors.New("invalid Context")
}
aspectCtx, ok := ctx.(*types.AspectRuntimeContext)
if !ok {
return nil, errors.New("failed to unwrap AspectRuntimeContext from context.Context")
}
return j.service.GetAccountVerifiers(aspectCtx.CosmosContext(), address)
}
func (j *ArtelaProvider) GetBlockBondAspects(ctx context.Context) ([]*asptypes.AspectCode, error) {
if ctx == nil {
return nil, errors.New("invalid Context")
}
aspectCtx, ok := ctx.(*types.AspectRuntimeContext)
if !ok {
return nil, errors.New("failed to unwrap AspectRuntimeContext from context.Context")
}
return j.service.GetAspectForBlock(aspectCtx.CosmosContext())
}
func (j *ArtelaProvider) GetAspectAccount(ctx context.Context, aspectId common.Address) (*common.Address, error) {
if ctx == nil {
return nil, errors.New("invalid Context")
}
aspectCtx, ok := ctx.(*types.AspectRuntimeContext)
if !ok {
return nil, errors.New("failed to unwrap AspectRuntimeContext from context.Context")
}
return j.service.GetAspectAccount(aspectCtx.CosmosContext(), aspectId)
}
func (j *ArtelaProvider) GetLatestBlock() int64 {
return j.service.GetBlockHeight()
}