mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 18:43:10 -06:00
Updated generated GO types for Zion Space Manager contracts (#41)
* Refresh generated types * Added Permission enum
This commit is contained in:
parent
c2d57b8679
commit
c5a753d6e2
|
|
@ -17,7 +17,7 @@ package authorization
|
||||||
type AuthorizationArgs struct {
|
type AuthorizationArgs struct {
|
||||||
RoomId string
|
RoomId string
|
||||||
UserId string
|
UserId string
|
||||||
Permission string
|
Permission Permission
|
||||||
}
|
}
|
||||||
|
|
||||||
type Authorization interface {
|
type Authorization interface {
|
||||||
|
|
|
||||||
59
authorization/permissions.go
Normal file
59
authorization/permissions.go
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
package authorization
|
||||||
|
|
||||||
|
type Permission int64
|
||||||
|
|
||||||
|
const (
|
||||||
|
// since iota starts with 0, the first value
|
||||||
|
// defined here will be the default
|
||||||
|
PermissionUndefined Permission = iota
|
||||||
|
PermissionRead
|
||||||
|
PermissionWrite
|
||||||
|
PermissionPing
|
||||||
|
PermissionInvite
|
||||||
|
PermissionRedact
|
||||||
|
PermissionBan
|
||||||
|
PermissionModifyChannelProfile
|
||||||
|
PermissionModifyChannelPermissions
|
||||||
|
PermissionPinMessages
|
||||||
|
PermissionAddRemoveChannels
|
||||||
|
PermissionModifySpacePermissions
|
||||||
|
PermissionModifyChannelDefaults
|
||||||
|
PermissionModifySpaceProfile
|
||||||
|
PermissionOwner
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p Permission) String() string {
|
||||||
|
switch p {
|
||||||
|
case PermissionUndefined:
|
||||||
|
return "Undefined"
|
||||||
|
case PermissionRead:
|
||||||
|
return "Read"
|
||||||
|
case PermissionWrite:
|
||||||
|
return "Write"
|
||||||
|
case PermissionPing:
|
||||||
|
return "Ping"
|
||||||
|
case PermissionInvite:
|
||||||
|
return "Invite"
|
||||||
|
case PermissionRedact:
|
||||||
|
return "Redact"
|
||||||
|
case PermissionBan:
|
||||||
|
return "Ban"
|
||||||
|
case PermissionModifyChannelProfile:
|
||||||
|
return "ModifyChannelProfile"
|
||||||
|
case PermissionModifyChannelPermissions:
|
||||||
|
return "ModifyChannelPermissions"
|
||||||
|
case PermissionPinMessages:
|
||||||
|
return "PinMessages"
|
||||||
|
case PermissionAddRemoveChannels:
|
||||||
|
return "AddRemoveChannels"
|
||||||
|
case PermissionModifySpacePermissions:
|
||||||
|
return "ModifySpacePermissions"
|
||||||
|
case PermissionModifyChannelDefaults:
|
||||||
|
return "ModifyChannelDefaults"
|
||||||
|
case PermissionModifySpaceProfile:
|
||||||
|
return "ModifySpaceProfile"
|
||||||
|
case PermissionOwner:
|
||||||
|
return "Owner"
|
||||||
|
}
|
||||||
|
return "Unknown"
|
||||||
|
}
|
||||||
|
|
@ -259,7 +259,7 @@ func Setup(
|
||||||
isAllowed, _ := authorization.IsAllowed(authz.AuthorizationArgs{
|
isAllowed, _ := authorization.IsAllowed(authz.AuthorizationArgs{
|
||||||
RoomId: vars["roomIDOrAlias"],
|
RoomId: vars["roomIDOrAlias"],
|
||||||
UserId: device.UserID,
|
UserId: device.UserID,
|
||||||
Permission: "Zion-Join",
|
Permission: authz.PermissionRead,
|
||||||
})
|
})
|
||||||
|
|
||||||
logrus.Debugf("/join/%s isAllowed = %t", vars["roomIDOrAlias"], isAllowed)
|
logrus.Debugf("/join/%s isAllowed = %t", vars["roomIDOrAlias"], isAllowed)
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
||||||
{"councilnft": "0x2279b7a0a67db372996a5fab50d91eaa73d2ebe6"}
|
{"councilnft": "0x8a791620dd6260079bf849dc5567adc3f2fdc318"}
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"spacemanager": "0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0","usergranted": "0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9","tokengranted": "0xdc64a140aa3e981100a9beca4e685f962f0cf6c9"}
|
{"spacemanager": "0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9","usergranted": "0xdc64a140aa3e981100a9beca4e685f962f0cf6c9","tokengranted": "0x5fc8d32690cc91d4c39d9d3abcbd16989f875707"}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -2,12 +2,13 @@ package zion
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"math/big"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/matrix-org/dendrite/authorization"
|
"github.com/matrix-org/dendrite/authorization"
|
||||||
|
zion_goerli "github.com/matrix-org/dendrite/zion/contracts/goerli/zion_goerli"
|
||||||
|
zion_localhost "github.com/matrix-org/dendrite/zion/contracts/localhost/zion_localhost"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -23,8 +24,8 @@ var localhostJson []byte
|
||||||
var goerliJson []byte
|
var goerliJson []byte
|
||||||
|
|
||||||
type ZionAuthorization struct {
|
type ZionAuthorization struct {
|
||||||
spaceManagerLocalhost *ZionSpaceManagerLocalhost
|
spaceManagerLocalhost *zion_localhost.ZionSpaceManagerLocalhost
|
||||||
spaceManagerGoerli *ZionSpaceManagerGoerli
|
spaceManagerGoerli *zion_goerli.ZionSpaceManagerGoerli
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewZionAuthorization() (authorization.Authorization, error) {
|
func NewZionAuthorization() (authorization.Authorization, error) {
|
||||||
|
|
@ -52,15 +53,12 @@ func NewZionAuthorization() (authorization.Authorization, error) {
|
||||||
|
|
||||||
func (za *ZionAuthorization) IsAllowed(args authorization.AuthorizationArgs) (bool, error) {
|
func (za *ZionAuthorization) IsAllowed(args authorization.AuthorizationArgs) (bool, error) {
|
||||||
userIdentifier := CreateUserIdentifier(args.UserId)
|
userIdentifier := CreateUserIdentifier(args.UserId)
|
||||||
permission := DataTypesPermission{
|
|
||||||
Name: args.Permission,
|
|
||||||
}
|
|
||||||
|
|
||||||
switch userIdentifier.chainId {
|
switch userIdentifier.chainId {
|
||||||
case 1337, 31337:
|
case 1337, 31337:
|
||||||
return za.IsAllowedLocalhost(args.RoomId, userIdentifier.accountAddress, permission)
|
return za.IsAllowedLocalhost(args.RoomId, userIdentifier.accountAddress, args.Permission)
|
||||||
case 5:
|
case 5:
|
||||||
return za.IsAllowedGoerli(args.RoomId, userIdentifier.accountAddress, permission)
|
return za.IsAllowedGoerli(args.RoomId, userIdentifier.accountAddress, args.Permission)
|
||||||
default:
|
default:
|
||||||
log.Errorf("Unsupported chain id: %d\n", userIdentifier.chainId)
|
log.Errorf("Unsupported chain id: %d\n", userIdentifier.chainId)
|
||||||
}
|
}
|
||||||
|
|
@ -68,17 +66,19 @@ func (za *ZionAuthorization) IsAllowed(args authorization.AuthorizationArgs) (bo
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (za *ZionAuthorization) IsAllowedLocalhost(roomId string, user common.Address, permission DataTypesPermission) (bool, error) {
|
func (za *ZionAuthorization) IsAllowedLocalhost(roomId string, user common.Address, permission authorization.Permission) (bool, error) {
|
||||||
if za.spaceManagerLocalhost != nil {
|
if za.spaceManagerLocalhost != nil {
|
||||||
spaceId, err := za.spaceManagerLocalhost.GetSpaceIdByNetworkId(nil, roomId)
|
permission := zion_localhost.DataTypesPermission{
|
||||||
if err != nil {
|
Name: permission.String(),
|
||||||
return false, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addr := user.Hex()
|
||||||
|
_ = addr
|
||||||
|
|
||||||
isEntitled, err := za.spaceManagerLocalhost.IsEntitled(
|
isEntitled, err := za.spaceManagerLocalhost.IsEntitled(
|
||||||
nil,
|
nil,
|
||||||
spaceId,
|
roomId,
|
||||||
big.NewInt(0),
|
"", // todo: Support channelId
|
||||||
user,
|
user,
|
||||||
permission,
|
permission,
|
||||||
)
|
)
|
||||||
|
|
@ -93,17 +93,16 @@ func (za *ZionAuthorization) IsAllowedLocalhost(roomId string, user common.Addre
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (za *ZionAuthorization) IsAllowedGoerli(roomId string, user common.Address, permission DataTypesPermission) (bool, error) {
|
func (za *ZionAuthorization) IsAllowedGoerli(roomId string, user common.Address, permission authorization.Permission) (bool, error) {
|
||||||
if za.spaceManagerGoerli != nil {
|
if za.spaceManagerGoerli != nil {
|
||||||
spaceId, err := za.spaceManagerGoerli.GetSpaceIdByNetworkId(nil, roomId)
|
permission := zion_goerli.DataTypesPermission{
|
||||||
if err != nil {
|
Name: permission.String(),
|
||||||
return false, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isEntitled, err := za.spaceManagerGoerli.IsEntitled(
|
isEntitled, err := za.spaceManagerGoerli.IsEntitled(
|
||||||
nil,
|
nil,
|
||||||
spaceId,
|
roomId,
|
||||||
big.NewInt(0),
|
"", // todo: support channelId
|
||||||
user,
|
user,
|
||||||
permission,
|
permission,
|
||||||
)
|
)
|
||||||
|
|
@ -118,7 +117,7 @@ func (za *ZionAuthorization) IsAllowedGoerli(roomId string, user common.Address,
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newZionSpaceManagerLocalhost(endpointUrl string) (*ZionSpaceManagerLocalhost, error) {
|
func newZionSpaceManagerLocalhost(endpointUrl string) (*zion_localhost.ZionSpaceManagerLocalhost, error) {
|
||||||
addresses, err := loadSpaceManagerAddresses(localhostJson)
|
addresses, err := loadSpaceManagerAddresses(localhostJson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -131,7 +130,7 @@ func newZionSpaceManagerLocalhost(endpointUrl string) (*ZionSpaceManagerLocalhos
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
spaceManager, err := NewZionSpaceManagerLocalhost(address, client)
|
spaceManager, err := zion_localhost.NewZionSpaceManagerLocalhost(address, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -139,7 +138,7 @@ func newZionSpaceManagerLocalhost(endpointUrl string) (*ZionSpaceManagerLocalhos
|
||||||
return spaceManager, nil
|
return spaceManager, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newZionSpaceManagerGoerli(endpointUrl string) (*ZionSpaceManagerGoerli, error) {
|
func newZionSpaceManagerGoerli(endpointUrl string) (*zion_goerli.ZionSpaceManagerGoerli, error) {
|
||||||
addresses, err := loadSpaceManagerAddresses(goerliJson)
|
addresses, err := loadSpaceManagerAddresses(goerliJson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -152,7 +151,7 @@ func newZionSpaceManagerGoerli(endpointUrl string) (*ZionSpaceManagerGoerli, err
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
spaceManager, err := NewZionSpaceManagerGoerli(address, client)
|
spaceManager, err := zion_goerli.NewZionSpaceManagerGoerli(address, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
package zion
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/big"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DataTypesCreateSpaceData is an auto generated low-level Go binding around an user-defined struct.
|
|
||||||
type DataTypesCreateSpaceData struct {
|
|
||||||
SpaceName string
|
|
||||||
NetworkId string
|
|
||||||
}
|
|
||||||
|
|
||||||
// DataTypesCreateSpaceTokenEntitlementData is an auto generated low-level Go binding around an user-defined struct.
|
|
||||||
type DataTypesCreateSpaceTokenEntitlementData struct {
|
|
||||||
EntitlementModuleAddress common.Address
|
|
||||||
TokenAddress common.Address
|
|
||||||
Quantity *big.Int
|
|
||||||
Description string
|
|
||||||
EntitlementTypes []uint8
|
|
||||||
}
|
|
||||||
|
|
||||||
// DataTypesEntitlementModuleInfo is an auto generated low-level Go binding around an user-defined struct.
|
|
||||||
type DataTypesEntitlementModuleInfo struct {
|
|
||||||
EntitlementAddress common.Address
|
|
||||||
EntitlementName string
|
|
||||||
EntitlementDescription string
|
|
||||||
}
|
|
||||||
|
|
||||||
// DataTypesSpaceInfo is an auto generated low-level Go binding around an user-defined struct.
|
|
||||||
type DataTypesSpaceInfo struct {
|
|
||||||
SpaceId *big.Int
|
|
||||||
CreatedAt *big.Int
|
|
||||||
Name string
|
|
||||||
Creator common.Address
|
|
||||||
Owner common.Address
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue