use of utils.Bytes in project jdchain-core by blockchain-jd-com.
the class JVMContractEngine method setupContract.
@Override
public ContractCode setupContract(ContractInfo contractInfo) {
Bytes address = contractInfo.getAddress();
long version = contractInfo.getChainCodeVersion();
String codeName = getCodeName(address, version);
ContractCode contractCode = contracts.get(version);
if (null == contractCode) {
synchronized (JVMContractEngine.class) {
contractCode = contracts.get(version);
if (null == contractCode) {
contractCode = loaders.get(contractInfo.getLang()).loadContract(address, version, contractInfo.getChainCode());
if (null != contractCode) {
contracts.put(codeName, contractCode);
}
}
}
}
return contractCode;
}
use of utils.Bytes in project jdchain-core by blockchain-jd-com.
the class UserAuthorizeOperationHandle method doProcess.
@Override
protected void doProcess(UserAuthorizeOperation operation, LedgerTransactionContext transactionContext, TransactionRequestExtension request, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
// 权限校验;
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
securityPolicy.checkEndpointPermission(LedgerPermission.CONFIGURE_ROLES, MultiIDsPolicy.AT_LEAST_ONE);
// 操作账本;
UserRolesEntry[] urcfgs = operation.getUserRolesAuthorizations();
UserAuthorizationSettings userRoleDataset = transactionContext.getDataset().getAdminDataset().getAdminSettings().getAuthorizations();
RolePrivilegeSettings rolesSettings = transactionContext.getDataset().getAdminDataset().getAdminSettings().getRolePrivileges();
if (urcfgs != null) {
for (UserRolesEntry urcfg : urcfgs) {
//
String[] authRoles = urcfg.getAuthorizedRoles();
Arrays.stream(authRoles).forEach(role -> {
if (!rolesSettings.contains(role)) {
throw new RoleDoesNotExistException(String.format("Role doesn't exist! --[Role=%s]", role));
}
});
for (Bytes address : urcfg.getUserAddresses()) {
UserRoles ur = userRoleDataset.getUserRoles(address);
if (ur == null) {
// 这是新的授权;
RolesPolicy policy = urcfg.getPolicy();
if (policy == null) {
policy = RolesPolicy.UNION;
}
((UserRoleDatasetEditor) userRoleDataset).addUserRoles(address, policy, authRoles);
} else {
// 更改之前的授权;
ur.addRoles(authRoles);
ur.removeRoles(urcfg.getUnauthorizedRoles());
// 如果请求中设置了策略,才进行更新;
RolesPolicy policy = urcfg.getPolicy();
if (policy != null) {
ur.setPolicy(policy);
}
((UserRoleDatasetEditor) userRoleDataset).updateUserRoles(ur);
}
}
}
}
}
use of utils.Bytes in project jdchain-core by blockchain-jd-com.
the class ConsensusSettingsUpdateOperationHandle method updateProperties.
private void updateProperties(ConsensusSettingsUpdateOperation op, LedgerAdminDataSet adminAccountDataSet, LedgerQuery previousBlockDataset) {
ConsensusProvider provider = null;
ConsensusViewSettings consensusSettings = null;
provider = ConsensusProviders.getProvider(((LedgerAdminDataSetEditor) adminAccountDataSet).getSettings().getConsensusProvider());
consensusSettings = provider.getSettingsFactory().getConsensusSettingsEncoder().decode(((LedgerAdminDataSetEditor) adminAccountDataSet).getSettings().getConsensusSetting().toBytes());
// update consensus settings according to properties config
ConsensusViewSettings newConsensusSettings = provider.getSettingsFactory().getConsensusSettingsBuilder().updateSettings(consensusSettings, PropertiesUtils.createProperties(op.getProperties()));
LedgerSettings ledgerSetting = new LedgerConfiguration(((LedgerAdminDataSetEditor) adminAccountDataSet).getSettings().getConsensusProvider(), new Bytes(provider.getSettingsFactory().getConsensusSettingsEncoder().encode(newConsensusSettings)), ((LedgerAdminDataSetEditor) adminAccountDataSet).getPreviousSetting().getCryptoSetting());
// set new consensus settings to ledger
((LedgerAdminDataSetEditor) adminAccountDataSet).setLedgerSetting(ledgerSetting);
}
use of utils.Bytes in project jdchain-core by blockchain-jd-com.
the class ConsensusSettingsUpdateOperationHandle method switchConsensus.
private void switchConsensus(ConsensusSettingsUpdateOperation op, LedgerAdminDataSet adminAccountDataSet, LedgerQuery previousBlockDataset) {
ConsensusProvider provider = ConsensusProviders.getProvider(op.getProvider());
int participantCount = (int) adminAccountDataSet.getParticipantDataset().getParticipantCount();
ParticipantNode[] participantNodes = adminAccountDataSet.getAdminSettings().getParticipants();
ArrayList<Replica> replicas = new ArrayList<>();
for (int i = 0; i < participantCount; i++) {
if (participantNodes[i].getParticipantNodeState() == ParticipantNodeState.CONSENSUS) {
Replica replica = new ReplicaImpl(participantNodes[i].getId(), participantNodes[i].getAddress(), participantNodes[i].getName(), participantNodes[i].getPubKey());
replicas.add(replica);
}
}
// create new consensus settings according to properties config
ConsensusViewSettings newConsensusSettings = provider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(PropertiesUtils.createProperties(op.getProperties()), replicas.toArray(new Replica[replicas.size()]));
LedgerSettings ledgerSetting = new LedgerConfiguration(op.getProvider(), new Bytes(provider.getSettingsFactory().getConsensusSettingsEncoder().encode(newConsensusSettings)), ((LedgerAdminDataSetEditor) adminAccountDataSet).getPreviousSetting().getCryptoSetting());
// set new consensus settings to ledger
((LedgerAdminDataSetEditor) adminAccountDataSet).setLedgerSetting(ledgerSetting);
}
use of utils.Bytes in project jdchain-core by blockchain-jd-com.
the class TransactionSetEditor method loadResultKv.
private TransactionResult loadResultKv(long seq) {
// transaction has only one version;
Bytes key = encodeKvResultKey(seq);
byte[] txBytes = txStateSet.getValue(key, 0);
if (txBytes == null) {
return null;
}
return BinaryProtocol.decode(txBytes, TransactionResult.class);
}
Aggregations