public class ActivePermissionOperationsUtils
extends java.lang.Object
Each bit in the 32-byte operations field corresponds to a Chain.Transaction.Contract.ContractType,
allowing up to 256 different contract types to be represented.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
NONE_OPERATIONS |
| Constructor and Description |
|---|
ActivePermissionOperationsUtils() |
| Modifier and Type | Method and Description |
|---|---|
static com.google.protobuf.ByteString |
buildOperations(com.google.protobuf.ByteString currentOperations,
boolean enable,
Chain.Transaction.Contract.ContractType... contractTypes)
Build a new operations ByteString by enabling or disabling specified contract types.
|
static Chain.Transaction.Contract.ContractType[] |
decodeOperations(com.google.protobuf.ByteString operations)
Decode operations to list of contract types
|
static Chain.Transaction.Contract.ContractType[] |
decodeOperations(java.lang.String hexOperations)
Decode operations hex string to list of contract type names
|
static java.lang.String |
encodeOperations(Chain.Transaction.Contract.ContractType[] contractTypes)
Encode contract types to operations hex string
|
static java.lang.String |
encodeOperations(int[] contractIds)
Encode contract types to operations hex string using contract IDs.
|
static java.lang.String |
encodeOperations(java.lang.String[] contractNames)
Encode contract types to operations hex string using contract names
|
static Chain.Transaction.Contract.ContractType |
getContractTypeById(int contractId)
Get contractType by ID
|
static Chain.Transaction.Contract.ContractType |
getContractTypeByName(java.lang.String contractName)
Get contractType by name
|
static boolean |
isValidOperations(com.google.protobuf.ByteString operations)
Validate if operations string is valid
|
public static final java.lang.String NONE_OPERATIONS
public static java.lang.String encodeOperations(Chain.Transaction.Contract.ContractType[] contractTypes)
contractTypes - Array of contract types to encodepublic static java.lang.String encodeOperations(int[] contractIds)
Each bit in the 32-byte operations array represents a Chain.Transaction.Contract.ContractType.
Up to 256 different contract types are supported (8 bits × 32 bytes).
contractIds - Array of contract IDs to encodepublic static java.lang.String encodeOperations(java.lang.String[] contractNames)
contractNames - Array of contract names to encodepublic static Chain.Transaction.Contract.ContractType[] decodeOperations(com.google.protobuf.ByteString operations)
operations - ByteString representation of operationspublic static Chain.Transaction.Contract.ContractType[] decodeOperations(java.lang.String hexOperations)
hexOperations - Hex string representation of operationspublic static boolean isValidOperations(com.google.protobuf.ByteString operations)
operations - ByteString representation of operationspublic static Chain.Transaction.Contract.ContractType getContractTypeByName(java.lang.String contractName)
contractName - Name of the contractpublic static Chain.Transaction.Contract.ContractType getContractTypeById(int contractId)
contractId - ID of the contractpublic static com.google.protobuf.ByteString buildOperations(com.google.protobuf.ByteString currentOperations,
boolean enable,
Chain.Transaction.Contract.ContractType... contractTypes)
Note: This method does not modify the input currentOperations, it returns a new ByteString.
If currentOperations not contain any of the specified contract types to disable, or already contains those to enable,
no changes will be made, but a new ByteString which is equal to currentOperations will be returned.
// enable TransferContract and disable VoteContract from account current operations
ByteString currentOps = account.getActivePermission(0).getOperations();
ByteString updatedOps = buildOperations(currentOps, true, ContractType.TransferContract);
updatedOps = buildOperations(updatedOps, false, ContractType.VoteContract);
// buildOperations from scratch by enabling TransferAssetContract and TransferContract
ByteString options = ActivePermissionOperationsUtils.buildOperations(
ByteString.EMPTY,
true,
ContractType.TransferAssetContract,
ContractType.TransferContract);
currentOperations - current operations ByteString, use ByteString.EMPTY to start from scratchenable - true to enable the specified contract types, false to disablecontractTypes - contract types to update, if null or empty, no changes will be made