6. setHashValue

基本信息

  1. 接口名称:com.webank.weid.rpc.EvidenceService.setHashValue
  2. 接口定义:ResponseData<String> setHashValue(String hashValue, String evidenceAddress, WeIdPrivateKey weIdPrivateKey)
  3. 接口描述: 对指定的空存证地址,将其链上的Hash值设定为所传入的Hash值。传入的私钥必须是创建存证时所声明的签名者之一。注意:当存证非空时,接口将返回失败。

接口入参:

Hashable java.lang.Object

java.lang.String

名称类型非空说明备注
hashValueStringY存证Hash值SHA3算法生成,符合SECP256K1规范,共64个字节,以“0x”开头

java.lang.String

名称类型非空说明备注
evidenceAddressStringY存证地址

com.webank.weid.protocol.base.WeIdPrivateKey

名称类型说明备注
privateKeyString私钥使用十进制数字表示

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

名称类型说明备注
errorCodeInteger返回结果码
errorMessageString返回结果描述
resultString创建的凭证合约地址业务数据
transactionInfoTransactionInfo交易信息

com.webank.weid.protocol.response.TransactionInfo

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

此方法返回code

enumcodedesc
SUCCESS0成功
CREDENTIAL_PRIVATE_KEY_NOT_EXISTS100415私钥为空
CREDENTIAL_ISSUER_INVALID100418WeIdentity DID无效
CREDENTIAL_EVIDENCE_BASE_ERROR100500Evidence标准错误
TRANSACTION_TIMEOUT160001超时
TRANSACTION_EXECUTE_ERROR160002交易错误
ILLEGAL_INPUT160004参数为空
CREDENTIAL_EVIDENCE_CONTRACT_FAILURE_ILLEAGAL_INPUT500401Evidence参数非法

调用示例

  1. EvidenceService evidenceService = new EvidenceServiceImpl();
  2.  
  3. WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
  4. weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
  5.  
  6. List<String> signer = new ArrayList<>();
  7. signer.add("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  8. signer.add("did:weid:101:0x48f6f6f663ef77409144014ceb063713b65611f8");
  9.  
  10. //创建空Evidence
  11. ResponseData<String> emptyEvidenceResp = evidenceService.createEvidence(null, signer, weIdPrivateKey);
  12.  
  13. String eviAddr = emptyEvidenceResp.getResult();
  14. weIdPrivateKey.setPrivateKey("3171324536025850958917764441489874006048340539971987768716844");
  15. String hash = "0x1f9e62fa152eb5fce859dcf81c7c0eddcbcab63c40629d1c745058c227693dae";
  16. ResponseData<Boolean> resp = evidenceService.setHashValue(hash, eviAddr, weIdPrivateKey);
  1. 返回结果如:
  2. result: true
  3. errorCode: 0
  4. errorMessage: success
  5. transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
  6. blockNumber: 30014
  7. transactionHash: 0x3e8f711b236fc6fce859dcf81c7c0eddcbcab63c40629d1c745058c338704fbf
  8. transactionIndex: 0

时序图

sequenceDiagramparticipant 调用者participant EvidenceServiceparticipant 区块链节点调用者->>EvidenceService: 调用setHashValue()EvidenceService->>EvidenceService: 入参非空、格式及合法性检查opt 入参校验失败EvidenceService—>>调用者: 报错,提示参数不合法并退出endEvidenceService->>区块链节点: 检查存证是否为空存证区块链节点—>>EvidenceService: 返回检查结果opt 非空EvidenceService—>>调用者: 报错并退出endEvidenceService->>区块链节点: 设置Hash值区块链节点—>>EvidenceService: 返回结果opt 失败EvidenceService—>>调用者: 报错并退出endEvidenceService->>区块链节点: 设置根据Hash值生成签名值并设置存证签名区块链节点—>>EvidenceService: 返回结果opt 失败EvidenceService—>>调用者: 报错并退出endEvidenceService—>>调用者: 返回成功