|
|
|
@ -57,14 +57,14 @@ public class SmartContractService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public SmartContractPageResult computeContractDigest(InstitutionKeySubject subject, ContractDigestRequest request) {
|
|
|
|
public String computeContractDigest(InstitutionKeySubject subject, ContractDigestRequest request) {
|
|
|
|
if (!"SM3".equalsIgnoreCase(request.getAlgorithm() != null ? request.getAlgorithm().trim() : "")) {
|
|
|
|
if (!"SM3".equalsIgnoreCase(request.getAlgorithm() != null ? request.getAlgorithm().trim() : "")) {
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
if (c.getContractDigest() != null) {
|
|
|
|
if (c.getContractDigest() != null) {
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return c.getContractDigest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
verifyStep3RegistrationConfirmed(subject);
|
|
|
|
verifyStep3RegistrationConfirmed(subject);
|
|
|
|
String storedWalletId = resolveWalletId(subject);
|
|
|
|
String storedWalletId = resolveWalletId(subject);
|
|
|
|
@ -84,14 +84,20 @@ public class SmartContractService {
|
|
|
|
String digest = cryptography.sm3(c.getContractPlaintext());
|
|
|
|
String digest = cryptography.sm3(c.getContractPlaintext());
|
|
|
|
c.computeContractDigest(digest);
|
|
|
|
c.computeContractDigest(digest);
|
|
|
|
contractRepository.update(c);
|
|
|
|
contractRepository.update(c);
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return digest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public SmartContractPageResult outputContract(InstitutionKeySubject subject) {
|
|
|
|
public ContractOutputResult outputContract(InstitutionKeySubject subject) {
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
if (c.getContractJson() != null) {
|
|
|
|
if (c.getContractJson() != null) {
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
ContractLimits limits = new ContractLimits(
|
|
|
|
|
|
|
|
c.getSinglePaymentLimit(), c.getDailyPaymentLimit(),
|
|
|
|
|
|
|
|
c.getAnnualPaymentLimit(), c.getBalanceCeiling());
|
|
|
|
|
|
|
|
return new ContractOutputResult(
|
|
|
|
|
|
|
|
c.getContractId(), c.getWalletId(), c.getWalletType(),
|
|
|
|
|
|
|
|
limits, c.getValidity(), c.getContractDigest(),
|
|
|
|
|
|
|
|
"已生效", c.getContractEffectiveTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c.getContractDigest() == null) {
|
|
|
|
if (c.getContractDigest() == null) {
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
@ -103,14 +109,21 @@ public class SmartContractService {
|
|
|
|
String json = buildContractJson(contractId, c);
|
|
|
|
String json = buildContractJson(contractId, c);
|
|
|
|
c.outputContract(contractId, json, effectiveTime);
|
|
|
|
c.outputContract(contractId, json, effectiveTime);
|
|
|
|
contractRepository.update(c);
|
|
|
|
contractRepository.update(c);
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
ContractLimits limits = new ContractLimits(
|
|
|
|
|
|
|
|
c.getSinglePaymentLimit(), c.getDailyPaymentLimit(),
|
|
|
|
|
|
|
|
c.getAnnualPaymentLimit(), c.getBalanceCeiling());
|
|
|
|
|
|
|
|
return new ContractOutputResult(
|
|
|
|
|
|
|
|
contractId, c.getWalletId(), c.getWalletType(),
|
|
|
|
|
|
|
|
limits, c.getValidity(), c.getContractDigest(),
|
|
|
|
|
|
|
|
"已生效", effectiveTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public SmartContractPageResult acquireActivateTimestamp(InstitutionKeySubject subject) {
|
|
|
|
public ActivateTimestampResult acquireActivateTimestamp(InstitutionKeySubject subject) {
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
if (c.getStatus() != null && c.getStatus().ordinal() >= SmartContractGeneration.Status.ACTIVATE_TIMESTAMP_ACQUIRED.ordinal()) {
|
|
|
|
if (c.getStatus() != null && c.getStatus().ordinal() >= SmartContractGeneration.Status.ACTIVATE_TIMESTAMP_ACQUIRED.ordinal()) {
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return new ActivateTimestampResult(
|
|
|
|
|
|
|
|
c.getActivateTimestamp(), c.getWalletId(), c.getOrgCode(), c.getContractId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c.getContractId() == null) {
|
|
|
|
if (c.getContractId() == null) {
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
@ -120,18 +133,18 @@ public class SmartContractService {
|
|
|
|
String timestamp = LocalDateTime.now().format(TIMESTAMP_FORMAT);
|
|
|
|
String timestamp = LocalDateTime.now().format(TIMESTAMP_FORMAT);
|
|
|
|
c.acquireActivateTimestamp(timestamp, orgCode);
|
|
|
|
c.acquireActivateTimestamp(timestamp, orgCode);
|
|
|
|
contractRepository.update(c);
|
|
|
|
contractRepository.update(c);
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return new ActivateTimestampResult(timestamp, c.getWalletId(), orgCode, c.getContractId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public SmartContractPageResult computeActivateDigest(InstitutionKeySubject subject, ActivateDigestRequest request) {
|
|
|
|
public String computeActivateDigest(InstitutionKeySubject subject, ActivateDigestRequest request) {
|
|
|
|
if (!"SM3".equalsIgnoreCase(request.getAlgorithm() != null ? request.getAlgorithm().trim() : "")) {
|
|
|
|
if (!"SM3".equalsIgnoreCase(request.getAlgorithm() != null ? request.getAlgorithm().trim() : "")) {
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
if (c.getActivateDigest() != null) {
|
|
|
|
if (c.getActivateDigest() != null) {
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return c.getActivateDigest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c.getContractId() == null) {
|
|
|
|
if (c.getContractId() == null) {
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
@ -145,18 +158,18 @@ public class SmartContractService {
|
|
|
|
String digest = cryptography.sm3(c.getActivatePlaintext());
|
|
|
|
String digest = cryptography.sm3(c.getActivatePlaintext());
|
|
|
|
c.computeActivateDigest(digest);
|
|
|
|
c.computeActivateDigest(digest);
|
|
|
|
contractRepository.update(c);
|
|
|
|
contractRepository.update(c);
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return digest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public SmartContractPageResult signActivate(InstitutionKeySubject subject, String privateKeyInput, String algorithm) {
|
|
|
|
public String signActivate(InstitutionKeySubject subject, String privateKeyInput, String algorithm) {
|
|
|
|
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
|
|
|
|
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
if (c.getActivateSignature() != null) {
|
|
|
|
if (c.getActivateSignature() != null) {
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return c.getActivateSignature();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c.getActivateDigest() == null) {
|
|
|
|
if (c.getActivateDigest() == null) {
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
@ -175,14 +188,16 @@ public class SmartContractService {
|
|
|
|
String signature = cryptography.sign(storedPrivateKey, c.getActivateDigest());
|
|
|
|
String signature = cryptography.sign(storedPrivateKey, c.getActivateDigest());
|
|
|
|
c.signActivate(privateKeyInput.trim(), signature);
|
|
|
|
c.signActivate(privateKeyInput.trim(), signature);
|
|
|
|
contractRepository.update(c);
|
|
|
|
contractRepository.update(c);
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return signature;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public SmartContractPageResult outputConfirm(InstitutionKeySubject subject) {
|
|
|
|
public ActivateConfirmOutputResult outputConfirm(InstitutionKeySubject subject) {
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
if (c.getConfirmJson() != null) {
|
|
|
|
if (c.getConfirmJson() != null) {
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return new ActivateConfirmOutputResult(
|
|
|
|
|
|
|
|
c.getConfirmId(), c.getWalletId(), c.getOrgCode(), c.getContractId(),
|
|
|
|
|
|
|
|
c.getActivateDigest(), c.getActivateSignature(), c.getActivateTimestamp(), "ACTIVATED");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c.getActivateSignature() == null) {
|
|
|
|
if (c.getActivateSignature() == null) {
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
@ -193,14 +208,16 @@ public class SmartContractService {
|
|
|
|
String json = buildConfirmJson(confirmId, c);
|
|
|
|
String json = buildConfirmJson(confirmId, c);
|
|
|
|
c.outputConfirm(confirmId, json);
|
|
|
|
c.outputConfirm(confirmId, json);
|
|
|
|
contractRepository.update(c);
|
|
|
|
contractRepository.update(c);
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return new ActivateConfirmOutputResult(
|
|
|
|
|
|
|
|
confirmId, c.getWalletId(), c.getOrgCode(), c.getContractId(),
|
|
|
|
|
|
|
|
c.getActivateDigest(), c.getActivateSignature(), c.getActivateTimestamp(), "ACTIVATED");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public SmartContractPageResult send(InstitutionKeySubject subject) {
|
|
|
|
public String send(InstitutionKeySubject subject) {
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
SmartContractGeneration c = getOrCreate(subject);
|
|
|
|
if (c.isSent()) {
|
|
|
|
if (c.isSent()) {
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return "成功";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c.getConfirmJson() == null) {
|
|
|
|
if (c.getConfirmJson() == null) {
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
scoreService.recordError(subject.getUserId());
|
|
|
|
@ -209,7 +226,7 @@ public class SmartContractService {
|
|
|
|
c.markSent();
|
|
|
|
c.markSent();
|
|
|
|
contractRepository.update(c);
|
|
|
|
contractRepository.update(c);
|
|
|
|
scoreService.markStepCompleted(subject.getUserId(), 6);
|
|
|
|
scoreService.markStepCompleted(subject.getUserId(), 6);
|
|
|
|
return new SmartContractPageResult(c);
|
|
|
|
return "成功";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String buildContractJson(String contractId, SmartContractGeneration c) {
|
|
|
|
private String buildContractJson(String contractId, SmartContractGeneration c) {
|
|
|
|
|