diff --git a/chainio/clients/elcontracts/types.go b/chainio/clients/elcontracts/types.go index b12e37e7..6e0c4fa5 100644 --- a/chainio/clients/elcontracts/types.go +++ b/chainio/clients/elcontracts/types.go @@ -42,7 +42,7 @@ type RegistrationRequest struct { } type RemovePermissionRequest struct { - Account common.Address + AccountAddress common.Address UserAddress common.Address Target common.Address Selector [4]byte @@ -50,9 +50,32 @@ type RemovePermissionRequest struct { } 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 +} diff --git a/chainio/clients/elcontracts/writer.go b/chainio/clients/elcontracts/writer.go index 024b0ea3..b0a93c2a 100644 --- a/chainio/clients/elcontracts/writer.go +++ b/chainio/clients/elcontracts/writer.go @@ -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") } @@ -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, @@ -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, @@ -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 +}