Skip to content

Commit

Permalink
Adding admin mutation request types and APIs to writer implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Chatham committed Dec 11, 2024
1 parent fdae593 commit 52f4546
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 5 deletions.
27 changes: 25 additions & 2 deletions chainio/clients/elcontracts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,40 @@ type RegistrationRequest struct {
}

type RemovePermissionRequest struct {
Account common.Address
AccountAddress common.Address
UserAddress common.Address
Target common.Address
Selector [4]byte
WaitForReceipt bool
}

type SetPermissionRequest struct {
Account common.Address
AccountAddress common.Address
UserAddress common.Address
Target common.Address
Selector [4]byte
WaitForReceipt bool
}

type AcceptAdminRequest struct {
AccountAddress common.Address
WaitForReceipt bool
}

type AddPendingAdminRequest struct {
AccountAddress common.Address
AdminAddress common.Address
WaitForReceipt bool
}

type RemoveAdminRequest struct {
AccountAddress common.Address
AdminAddress common.Address
WaitForReceipt bool
}

type RemovePendingAdminRequest struct {
AccountAddress common.Address
AdminAddress common.Address
WaitForReceipt bool
}
77 changes: 74 additions & 3 deletions chainio/clients/elcontracts/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,10 @@ func (w *ChainWriter) RegisterForOperatorSets(
return receipt, nil
}

func (w *ChainWriter) RemovePermission(ctx context.Context, request RemovePermissionRequest) (*gethtypes.Receipt, error) {
func (w *ChainWriter) RemovePermission(
ctx context.Context,
request RemovePermissionRequest,
) (*gethtypes.Receipt, error) {
if w.permissionController == nil {
return nil, errors.New("permission contract not provided")
}
Expand All @@ -563,7 +566,7 @@ func (w *ChainWriter) RemovePermission(ctx context.Context, request RemovePermis

tx, err := w.permissionController.RemoveAppointee(
noSendTxOpts,
request.Account,
request.AccountAddress,
request.UserAddress,
request.Target,
request.Selector,
Expand All @@ -586,7 +589,7 @@ func (w *ChainWriter) SetPermission(ctx context.Context, request SetPermissionRe

tx, err := w.permissionController.SetAppointee(
noSendTxOpts,
request.Account,
request.AccountAddress,
request.UserAddress,
request.Target,
request.Selector,
Expand All @@ -597,3 +600,71 @@ func (w *ChainWriter) SetPermission(ctx context.Context, request SetPermissionRe
receipt, err := w.txMgr.Send(ctx, tx, request.WaitForReceipt)
return receipt, err
}

func (w *ChainWriter) AcceptAdmin(ctx context.Context, request AcceptAdminRequest) (*gethtypes.Receipt, error) {
if w.permissionController == nil {
return nil, errors.New("permission contract not provided")
}
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, utils.WrapError("failed to get no send tx opts", err)
}

tx, err := w.permissionController.AcceptAdmin(noSendTxOpts, request.AccountAddress)
if err != nil {
return nil, errors.New("call to permission controller failed: " + err.Error())
}
receipt, err := w.txMgr.Send(ctx, tx, request.WaitForReceipt)
return receipt, err
}

func (w *ChainWriter) AddPendingAdmin(ctx context.Context, request AddPendingAdminRequest) (*gethtypes.Receipt, error) {
if w.permissionController == nil {
return nil, errors.New("permission contract not provided")
}
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, utils.WrapError("failed to get no send tx opts", err)
}

tx, err := w.permissionController.AddPendingAdmin(noSendTxOpts, request.AccountAddress, request.AdminAddress)
if err != nil {
return nil, errors.New("call to permission controller failed: " + err.Error())
}
receipt, err := w.txMgr.Send(ctx, tx, request.WaitForReceipt)
return receipt, err
}

func (w *ChainWriter) RemoveAdmin(ctx context.Context, request RemoveAdminRequest) (*gethtypes.Receipt, error) {
if w.permissionController == nil {
return nil, errors.New("permission contract not provided")
}
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, utils.WrapError("failed to get no send tx opts", err)
}

tx, err := w.permissionController.RemoveAdmin(noSendTxOpts, request.AccountAddress, request.AdminAddress)
if err != nil {
return nil, errors.New("call to permission controller failed: " + err.Error())
}
receipt, err := w.txMgr.Send(ctx, tx, request.WaitForReceipt)
return receipt, err
}

func (w *ChainWriter) RemovePendingAdmin(ctx context.Context, request RemovePendingAdminRequest) (*gethtypes.Receipt, error) {
if w.permissionController == nil {
return nil, errors.New("permission contract not provided")
}
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, utils.WrapError("failed to get no send tx opts", err)
}

tx, err := w.permissionController.RemovePendingAdmin(noSendTxOpts, request.AccountAddress, request.AdminAddress)
if err != nil {
return nil, errors.New("call to permission controller failed: " + err.Error())
}
receipt, err := w.txMgr.Send(ctx, tx, request.WaitForReceipt)
return receipt, err
}

0 comments on commit 52f4546

Please sign in to comment.