6. updateCpt

基本信息

  1. 接口名称:com.webank.weid.rpc.CptService.updateCpt
  2. 接口定义:ResponseData<CptBaseInfo> updateCpt(CptMapArgs args, Integer cptId)
  3. 接口描述: 传入cptIdJsonSchema(Map类型),WeIdentity DIDWeIdentity DID所属私钥,进行更新CPT信息,更新成功版本自动+1

接口入参: com.webank.weid.protocol.request.CptMapArgs,Integer

名称类型非空说明备注
argsCptMapArgsYCPT信息具体见下
cptIdIntegerY发布的CPT编号

com.webank.weid.protocol.request.CptMapArgs

名称类型非空说明备注
weIdAuthenticationWeIdAuthenticationY认证信息,包含WeIdentity DID和私钥用于WeIdentity DID的身份认证
cptJsonSchemaMap<String, Object>YMap类型的JsonSchema信息基本使用见调用示例

com.webank.weid.protocol.base.WeIdAuthentication

名称类型非空说明备注
weIdStringYCPT发布者的WeIdentity DIDWeIdentity DID的格式传入
weIdPublicKeyIdStringN公钥Id
weIdPrivateKeyWeIdPrivateKeyY 交易私钥,见下

com.webank.weid.protocol.base.WeIdPrivateKey

名称类型非空说明备注
privateKeyStringY私钥值使用十进制数字表示

接口返回: com.webank.weid.protocol.response.ResponseData<CptBaseInfo>;

名称类型说明备注
errorCodeInteger返回结果码此接口返回的code
errorMessageString返回结果描述
resultCptBaseInfo CPT基础数据,见下
transactionInfoTransactionInfo交易信息

com.webank.weid.protocol.response.TransactionInfo

名称类型说明备注
blockNumberBigInteger交易块高
transactionHashString交易hash
transactionIndexBigInteger交易索引

com.webank.weid.protocol.base.CptBaseInfo

名称类型说明备注
cptIdIntegercpId编号
cptVersionInteger版本号

此方法返回code

enumcodedesc
SUCCESS0成功
WEID_INVALID100101WeIdentity DID无效
WEID_PRIVATEKEY_INVALID100103私钥无效
WEID_PRIVATEKEY_DOES_NOT_MATCH100106私钥与WeIdentity DID不匹配
WEID_AUTHORITY_INVALID100109授权信息无效
CPT_JSON_SCHEMA_INVALID100301schema无效
CPT_ID_ILLEGAL100303cptId无效
CPT_EVENT_LOG_NULL100304交易日志异常
TRANSACTION_TIMEOUT160001超时
TRANSACTION_EXECUTE_ERROR160002交易错误
UNKNOW_ERROR160003未知异常
ILLEGAL_INPUT160004参数为空
CPT_NOT_EXISTS500301CPT不存在
CPT_ID_AUTHORITY_ISSUER_EXCEED_MAX500302为权威机构生成的cptId超过上限
CPT_PUBLISHER_NOT_EXIST500303CPT发布者的WeIdentity DID不存在
CPT_ALREADY_EXIST500304CPT已经存在
CPT_NO_PERMISSION500305CPT无权限

调用示例

  1. CptService cptService = new CptServiceImpl();
  2.  
  3. HashMap<String, Object> cptJsonSchema = new HashMap<String, Object>(3);
  4. cptJsonSchema.put(JsonSchemaConstant.TITLE_KEY, "cpt template");
  5. cptJsonSchema.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is a cpt template");
  6.  
  7. HashMap<String, Object> propertitesMap1 = new HashMap<String, Object>(2);
  8. propertitesMap1.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
  9. propertitesMap1.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is name");
  10.  
  11. String[] genderEnum = { "F", "M" };
  12. HashMap<String, Object> propertitesMap2 = new HashMap<String, Object>(2);
  13. propertitesMap2.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
  14. propertitesMap2.put(JsonSchemaConstant.DATA_TYPE_ENUM, genderEnum);
  15.  
  16. HashMap<String, Object> propertitesMap3 = new HashMap<String, Object>(2);
  17. propertitesMap3.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_NUMBER);
  18. propertitesMap3.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is age");
  19.  
  20. HashMap<String, Object> cptJsonSchemaKeys = new HashMap<String, Object>(3);
  21. cptJsonSchemaKeys.put("name", propertitesMap1);
  22. cptJsonSchemaKeys.put("gender", propertitesMap2);
  23. cptJsonSchemaKeys.put("age", propertitesMap3);
  24. cptJsonSchema.put(JsonSchemaConstant.PROPERTIES_KEY, cptJsonSchemaKeys);
  25.  
  26. String[] genderRequired = { "name", "gender" };
  27. cptJsonSchema.put(JsonSchemaConstant.REQUIRED_KEY, genderRequired);
  28.  
  29. WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
  30. weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
  31.  
  32. WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
  33. weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  34. weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
  35.  
  36. CptMapArgs cptMapArgs = new CptMapArgs();
  37. cptMapArgs.setCptJsonSchema(cptJsonSchema);
  38. cptMapArgs.setWeIdAuthentication(weIdAuthentication);
  39.  
  40. Integer cptId = Integer.valueOf(1017);
  41.  
  42. ResponseData<CptBaseInfo> response = cptService.updateCpt(cptMapArgs, cptId);
  1. 返回数据如下:
  2. result:(com.webank.weid.protocol.base.CptBaseInfo)
  3. cptId: 1017
  4. cptVersion: 2
  5. errorCode: 0
  6. errorMessage: success
  7. transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
  8. blockNumber: 29989
  9. transactionHash: 0x4435fa88f9f138f14671d8baa5e5f16c69c5efa3591c4912772b9b1233af398a
  10. transactionIndex: 0

时序图

(同时也包含重载updateCpt时序)

sequenceDiagram调用者->>WeIdentity SDK : 传入自己已有的WeIdentity DID及对应的私钥,及其需新版本的jsonSchema,调用updateCpt来更新CPT。opt 参数校验Note over WeIdentity SDK:如果WeIdentity DID或者私钥为空或不匹配WeIdentity SDK->>WeIdentity SDK:报错,提示参数不合法并退出endWeIdentity SDK->>区块链节点: 将java对象转换为合约所需的字段,调用智能合约,将更新的CPT信息上链opt 身份校验Note over 区块链节点:如果传入WeIdentity DID在链上不存在区块链节点->>区块链节点:报错,提示WeIdentity DID不存在并退出end区块链节点->>区块链节点:写入CPT更新信息区块链节点—>>WeIdentity SDK:返回WeIdentity SDK—>>调用者:返回调用结果