Documentation
¶
Index ¶
- Constants
- Variables
- func GetRoleMembersView(ctx context.Context, client ton.APIClientWrapped, addr *address.Address, ...) ([]*address.Address, error)
- type Data
- type ExitCode
- type GetRoleMemberArgs
- type GrantRole
- type RenounceRole
- type RevokeRole
- type RoleAdminChanged
- type RoleData
- type RoleGranted
- type RoleRevoked
Constants ¶
const (
DefaultAdminRole = 0x00
)
Variables ¶
var ( OpcodeRoleGranted = tvm.MustExtractMagic(reflect.TypeOf(RoleGranted{})) OpcodeRoleRevoked = tvm.MustExtractMagic(reflect.TypeOf(RoleRevoked{})) )
var ExitCodeCodec tvm.ExitCodeCodecInt[ExitCode] = ExitCode(tvm.ExitCode(-1))
var GetRoleMember = tvm.Getter[GetRoleMemberArgs, *address.Address]{ Name: "getRoleMember", Decoder: tvm.NewResultDecoder(func(r *ton.ExecutionResult) (*address.Address, error) { sAddr, err := r.Slice(0) if err != nil { return nil, fmt.Errorf("error decoding getRoleMember result: %w", err) } addr, err := sAddr.LoadAddr() if err != nil { return nil, fmt.Errorf("error decoding getRoleMember result slice: %w", err) } return addr, nil }), }
var GetRoleMemberCount = tvm.Getter[*big.Int, uint64]{ Name: "getRoleMemberCount", Decoder: tvm.NewResultDecoder(func(r *ton.ExecutionResult) (uint64, error) { rs, err := r.Int(0) if err != nil { return 0, fmt.Errorf("error decoding getRoleMemberCount result: %w", err) } return rs.Uint64(), nil }), }
var TLBs = tvm.MustNewTLBMap([]any{ GrantRole{}, RevokeRole{}, RenounceRole{}, RoleGranted{}, RoleRevoked{}, RoleAdminChanged{}, }).MustWithStorageType(Data{})
Functions ¶
Types ¶
type GetRoleMemberArgs ¶
type GrantRole ¶
type GrantRole struct {
// Query ID of the change request.
QueryID uint64 `tlb:"## 64"`
Role *tlbe.Uint256 `tlb:"."` // Role definition.
Account *address.Address `tlb:"addr"` // New account to add.
// contains filtered or unexported fields
}
@dev Grants `role` to `account`.
If `account` had not been already granted `role`, emits a {AccessControl_RoleGranted} event.
Requirements:
- the caller must have `role`'s admin role.
May emit a {AccessControl_RoleGranted} event.
type RenounceRole ¶
type RenounceRole struct {
// Query ID of the change request.
QueryID uint64 `tlb:"## 64"`
Role *tlbe.Uint256 `tlb:"."` // Role definition.
CallerConfirmation *address.Address `tlb:"addr"` // Account to revoke.
// contains filtered or unexported fields
}
@dev Revokes `role` from the calling account.
Roles are often managed via {AccessControl_GrantRole} and {AccessControl_RevokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced).
If `account` had been granted `role`, emits a {AccessControl_RoleRevoked} event.
Requirements:
- the caller must be `callerConfirmation`.
May emit a {AccessControl_RoleRevoked} event.
type RevokeRole ¶
type RevokeRole struct {
// Query ID of the change request.
QueryID uint64 `tlb:"## 64"`
Role *tlbe.Uint256 `tlb:"."` // Role definition.
Account *address.Address `tlb:"addr"` // Account to revoke.
// contains filtered or unexported fields
}
@dev Revokes `role` from `account`.
If `account` had been granted `role`, emits a {AccessControl_RoleRevoked} event.
Requirements:
- the caller must have `role`'s admin role.
May emit a {AccessControl_RoleRevoked} event.
type RoleAdminChanged ¶
type RoleAdminChanged struct {
// Query ID of the change request.
QueryID uint64 `tlb:"## 64"`
Role *tlbe.Uint256 `tlb:"."` // Role definition.
PreviousAdminRole *tlbe.Uint256 `tlb:"."` // Previous admin role of the specific role.
NewAdminRole *tlbe.Uint256 `tlb:"."` // New admin role of the specific role.
// contains filtered or unexported fields
}
@dev Emitted when `newAdminRole` is set as “role“'s admin role, replacing `previousAdminRole`
`DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite {AccessControl_RoleAdminChanged} not being emitted to signal this.
type RoleData ¶
type RoleData struct {
AdminRole *tlbe.Uint256 `tlb:"."`
// Number of members in the role
MembersLen uint64 `tlb:"## 64"`
// Members of the role, indexed by their address hash.
HasRole *tlbe.Dict[common.AddressWrap, bool] `tlb:"."`
}
Internal storage struct for role data
Each role has a mapping of accounts that have been granted that role, and an admin role that can manage that role.
type RoleGranted ¶
type RoleGranted struct {
// Query ID of the change request.
QueryID uint64 `tlb:"## 64"`
Role *tlbe.Uint256 `tlb:"."` // Role definition.
Account *address.Address `tlb:"addr"` // New account added.
Sender *address.Address `tlb:"addr"` // Account that requested the change.
// contains filtered or unexported fields
}
@dev Emitted when `account` is granted `role`.
`sender` is the account that originated the contract call. This account bears the admin role (for the granted role). Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
type RoleRevoked ¶
type RoleRevoked struct {
// Query ID of the change request.
QueryID uint64 `tlb:"## 64"`
Role *tlbe.Uint256 `tlb:"."` // Role definition.
Account *address.Address `tlb:"addr"` // Account revoked.
Sender *address.Address `tlb:"addr"` // Account that requested the change.
// contains filtered or unexported fields
}
@dev Emitted when `account` is revoked `role`.
`sender` is the account that originated the contract call:
- if using `revokeRole`, it is the admin role bearer
- if using `renounceRole`, it is the role bearer (i.e. `account`)