/// <summary> /// user cert application /// </summary> /// <param name="config">basic information</param> /// <param name="reqBody">user cert requests</param> /// <returns></returns> public Tuple <bool, string> EnrollUser(EnrollUserReqBody reqBody) { try { NodeApiReqBody <EnrollUserReqBody> req = new NodeApiReqBody <EnrollUserReqBody>() { body = new EnrollUserReqBody() { name = reqBody.name, secret = reqBody.secret }, header = new ReqHeader() { appCode = config.appInfo.AppCode, userCode = config.userCode } }; ////get csr var resCsr = config.appInfo.AlgorithmType == EmAlgorithmType.SM2 ? CsrHelper.GetSMCsr(string.Format("{0}@{1}", reqBody.name, config.appInfo.AppCode)) : CsrHelper.GetCsr(string.Format("{0}@{1}", reqBody.name, config.appInfo.AppCode)); req.body.csrPem = resCsr.Item1.Replace("\r", ""); // assemble the original string to sign var data = ReqMacExtends.GetEnrollUserReqMac(req); req.mac = sign.Sign(data); var res = SendHelper.SendPost <NodeApiResBody <EnrollUserResBody> >(config.reqUrl + EnrollUserUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string>(false, res.header.msg)); } //assemble the original string to sign var datares = ResMacExtends.GetEnrollUserResMac(res); //verify data if (sign.Verify(res.mac, datares)) { //save the private key and cert if (!string.IsNullOrEmpty(res.body.cert)) { CertStore.SaveCert(res.body.cert, Path.Combine(config.mspDir, string.Format("{0}@{1}_cert.pem", reqBody.name, config.appInfo.AppCode))); ECDSAStore.SavePriKey(resCsr.Item2, Path.Combine(config.mspDir, string.Format("{0}@{1}_sk.pem", reqBody.name, config.appInfo.AppCode))); } return(new Tuple <bool, string>(true, "cert registration successful")); } else { return(new Tuple <bool, string>(false, "failed to verify the signature")); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string>(false, "failed to verify the cert")); }
/// <summary> /// transaction processing under Key-Upload Mode /// </summary> /// <param name="reqBody"></param> /// <returns></returns> public Tuple <bool, string, CitaTransResBody> SDKTrans(CitaTransReq reqBody) { try { if (config.appInfo.CAType == EmCAType.Trusteeship) { return(new Tuple <bool, string, CitaTransResBody>(false, "the trusteeship application cannot call the api", null)); } var tx = new CitaClient(config).GetTransData(reqBody); if (!string.IsNullOrEmpty(tx.Item2)) { return(new Tuple <bool, string, CitaTransResBody>(false, tx.Item2, null)); } NodeApiReqBody <CitaTransReqBody> req = new NodeApiReqBody <CitaTransReqBody> { header = GetReqHeader() }; req.body = new CitaTransReqBody() { ContractName = reqBody.Contract.ContractName, TransData = "0x" + tx.Item1 }; req.mac = sign.Sign(CitaReqMacExtends.GetSDKTransReqMac(req)); var res = SendHelper.SendPost <NodeApiResBody <CitaTransResBody> >(config.reqUrl + TransUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, CitaTransResBody>(false, res.header.msg, null)); } //assemble the original string to verify var datares = CitaResMacExtends.GetCitaTransactionResMac(res); //data verified if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, CitaTransResBody>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, CitaTransResBody>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, CitaTransResBody>(false, "The deal failed", null)); }
/// <summary> /// get block data /// </summary> /// <param name="config"></param> /// <param name="reqBody"></param> /// <returns></returns> public Tuple <bool, string, GetBlockDataResBody> GetBlockData(GetBlockReqBody reqBody) { try { NodeApiReqBody <GetBlockReqBody> req = new NodeApiReqBody <GetBlockReqBody>() { body = new GetBlockReqBody() { txId = reqBody.txId, blockHash = reqBody.blockHash, blockNumber = reqBody.blockNumber, dataType = reqBody.dataType }, header = new ReqHeader() { appCode = config.appInfo.AppCode, userCode = config.userCode } }; //assemble the string to sign var data = ReqMacExtends.GetBlockInfoReqMac(req); //sign the data req.mac = sign.Sign(data); var res = SendHelper.SendPost <NodeApiResBody <GetBlockDataResBody> >(config.reqUrl + GetBlockDataUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, GetBlockDataResBody>(false, res.header.msg, null)); } //Assemble the original string to sign var datares = ResMacExtends.GetBlockDataResMac(res); //verify data if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, GetBlockDataResBody>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, GetBlockDataResBody>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, GetBlockDataResBody>(false, "failed to get block data", null)); }
/// <summary> /// chaincode event registration /// </summary> /// <param name="config"></param> /// <param name="reqBody"></param> /// <returns></returns> public Tuple <bool, string, EventRegisterResBody> EventRegister(EventRegisterReqBody reqBody) { try { NodeApiReqBody <EventRegisterReqBody> req = new NodeApiReqBody <EventRegisterReqBody>() { header = new ReqHeader() { appCode = config.appInfo.AppCode, userCode = config.userCode }, body = new EventRegisterReqBody() { attachArgs = reqBody.attachArgs, chainCode = reqBody.chainCode, eventKey = reqBody.eventKey, notifyUrl = reqBody.notifyUrl } }; //assemble the original string to sign var data = ReqMacExtends.EventRegisterReqMac(req); //sign data req.mac = sign.Sign(data); var res = SendHelper.SendPost <NodeApiResBody <EventRegisterResBody> >(config.reqUrl + EventRegisterUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, EventRegisterResBody>(false, res.header.msg, null)); } //assemble the original string to be checked var datares = ResMacExtends.EventRegisterResMac(res); //verify data if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, EventRegisterResBody>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, EventRegisterResBody>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, EventRegisterResBody>(false, "failed to register chaincode event", null)); }
/// <summary> /// user registration /// </summary> /// <param name="req">request content</param> /// <param name="url">interface address</param> /// <param name="certPath">https cert path</param> /// <returns></returns> public Tuple <bool, string, RegisterUserResBody> RegisterUser(RegisterUserReqBody reqBody) { try { NodeApiReqBody <RegisterUserReqBody> req = new NodeApiReqBody <RegisterUserReqBody>() { body = new RegisterUserReqBody() { name = reqBody.name, //one user can only be registered once, the second call returns a failed registration secret = reqBody.secret, //If the password is empty, a random password will be returned. Users under Key Mode needs to store the returned random password and pass it in when registering the certificate extendProperties = reqBody.extendProperties }, header = new ReqHeader() { appCode = config.appInfo.AppCode, userCode = config.userCode } }; // assemble the orginal string to sign var data = ReqMacExtends.GetRegisterUserReqMac(req); //data signature req.mac = sign.Sign(data); var res = SendHelper.SendPost <NodeApiResBody <RegisterUserResBody> >(config.reqUrl + registerUserUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, RegisterUserResBody>(false, res.header.msg, null)); } //assemble the original string to verify var datares = ResMacExtends.GetRegisterUserResMac(res); //data verified if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, RegisterUserResBody>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, RegisterUserResBody>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, RegisterUserResBody>(false, "failed to register the user", null));; }
/// <summary> /// transaction processing under Key-Upload Mode /// </summary> /// <param name="config"></param> /// <param name="reqBody"></param> /// <returns></returns> public Tuple <bool, string, ReqChainCodeResBody> Trans(TransRequest reqBody) { try { NodeApiReqBody <TransReqBody> req = new NodeApiReqBody <TransReqBody>() { header = new ReqHeader() { appCode = config.appInfo.AppCode, userCode = config.userCode }, body = new TransReqBody() { transData = Transaction.CreateRequest(config, reqBody) } }; //Assemble the original string to sign var data = ReqMacExtends.TransReqMac(req); //sign data req.mac = sign.Sign(data); var res = SendHelper.SendPost <NodeApiResBody <ReqChainCodeResBody> >(config.reqUrl + TransUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, ReqChainCodeResBody>(false, res.header.msg, null)); } //assemble the original string to sign var datares = ResMacExtends.ReqChainCodeResMac(res); //verify data if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, ReqChainCodeResBody>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, ReqChainCodeResBody>(false, "failed to verify data", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, ReqChainCodeResBody>(false, "failed to process transactions under Key-Trust Mode", null)); }
/// <summary> /// event chaincode logout /// </summary> /// <param name="config"></param> /// <param name="reqBody"></param> /// <returns></returns> public Tuple <bool, string> EventRemove(EventRemoveReqBody reqBody) { try { NodeApiReqBody <EventRemoveReqBody> req = new NodeApiReqBody <EventRemoveReqBody> { header = new ReqHeader() { appCode = config.appInfo.AppCode, userCode = config.userCode }, body = new EventRemoveReqBody() { eventId = reqBody.eventId } }; //assemble the original string to sign var data = ReqMacExtends.EventRemoveReqMac(req); //sign data req.mac = sign.Sign(data); var res = SendHelper.SendPost <NodeApiRes>(config.reqUrl + EventRemoveUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string>(false, res.header.msg)); } //assemble the original string to sign var datares = ResMacExtends.GetResHeaderMac(res.header); //verify data if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string>(true, res.header.msg)); } else { return(new Tuple <bool, string>(false, "failed to sign the signature")); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string>(false, "failed to logout event chaincode")); }
/// <summary> /// get the ledger info /// </summary> /// <param name="config"></param> /// <returns></returns> public Tuple <bool, string, GetLedgerResBody> GetLedgerInfo() { try { NodeApiReq req = new NodeApiReq() { header = new ReqHeader() { appCode = config.appInfo.AppCode, userCode = config.userCode } }; //assemble the original string to sign var data = ReqMacExtends.GetReqHeaderMac(req.header); //sign data req.mac = sign.Sign(data); var res = SendHelper.SendPost <NodeApiResBody <GetLedgerResBody> >(config.reqUrl + GetLedgerUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, GetLedgerResBody>(false, res.header.msg, null)); } //assemble the original strong to sign var datares = ResMacExtends.GetLedgerInfoResMac(res); //verify data if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, GetLedgerResBody>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, GetLedgerResBody>(false, "failed to sign ", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, GetLedgerResBody>(false, "failed to get ledger info", null)); }
/// <summary> /// event chaincode query /// </summary> /// <param name="config"></param> /// <param name="reqBody"></param> /// <returns></returns> public Tuple <bool, string, List <EventQueryResBody> > EventQuery() { try { NodeApiReq req = new NodeApiReq { header = new ReqHeader() { appCode = config.appInfo.AppCode, userCode = config.userCode } }; //assemble the original string var data = ReqMacExtends.GetReqHeaderMac(req.header); //sign data req.mac = sign.Sign(data); var res = SendHelper.SendPost <NodeApiResBody <List <EventQueryResBody> > >(config.reqUrl + EventQueryUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, List <EventQueryResBody> >(false, res.header.msg, null)); } //assemble the original string to verify var datares = ResMacExtends.EventQueryResMac(res); //verify data if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, List <EventQueryResBody> >(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, List <EventQueryResBody> >(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, List <EventQueryResBody> >(false, "failed to query the chaincode", null)); }
/// <summary> /// register an user /// </summary> public Tuple <bool, string, FiscoRegisterUserResBody> RegisterUser(FiscoRegisterReqBody reqBody) { try { NodeApiReqBody <FiscoRegisterReqBody> req = new NodeApiReqBody <FiscoRegisterReqBody>() { body = new FiscoRegisterReqBody() { UserId = reqBody.UserId,//同一个用户名只能注册一次,第二次调用会返回注册失败 }, header = GetReqHeader() }; //数据进行Base64编码 req.mac = sign.Sign(FiscoReqMacExtends.GetRegisterUserReqMac(req)); var res = SendHelper.SendPost <NodeApiResBody <FiscoRegisterUserResBody> >(config.reqUrl + registerUserUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, FiscoRegisterUserResBody>(false, res.header.msg, null)); } //assemble the original string to verify var datares = FiscoResMacExtends.GetRegisterUserResMac(res); //data verified if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, FiscoRegisterUserResBody>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, FiscoRegisterUserResBody>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, FiscoRegisterUserResBody>(false, "用户注册失败", null));; }
/// <summary> /// transactions under Key-Trust Mode /// </summary> /// <param name="reqBody"></param> /// <returns></returns> public Tuple <bool, string, CallContractResDataBody> ReqChainCode(CallContractReqDataReqDataBody reqBody) { try { NodeApiReqBody <CallContractReqDataReqDataBody> req = new NodeApiReqBody <CallContractReqDataReqDataBody>() { header = GetReqHeader(), body = reqBody }; var data = XuperchainReqMacExtends.ReqChainCodeReqMac(req); req.mac = sign.Sign(data); var res = SendHelper.SendPost <NodeApiResBody <CallContractResDataBody> >(config.reqUrl + ReqChainCodeUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, CallContractResDataBody>(false, res.header.msg, null)); } //assemble the original string to verify var datares = XuperchainResMacExtends.ReqChainCodeResMac(res); //data verified if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, CallContractResDataBody>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, CallContractResDataBody>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, CallContractResDataBody>(false, "failed to transact", null)); }
/// <summary> /// register an user /// </summary> public Tuple <bool, string, CitaRegisterUserResBody> RegisterUser(CitaRegisterReqBody reqBody) { try { NodeApiReqBody <CitaRegisterReqBody> req = new NodeApiReqBody <CitaRegisterReqBody>() { body = new CitaRegisterReqBody() { UserId = reqBody.UserId,//one user can only be registered once, the second call returns a failed registration }, header = GetReqHeader() }; req.mac = sign.Sign(CitaReqMacExtends.GetRegisterUserReqMac(req)); var res = SendHelper.SendPost <NodeApiResBody <CitaRegisterUserResBody> >(config.reqUrl + registerUserUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, CitaRegisterUserResBody>(false, res.header.msg, null)); } //assemble the original string to verify var datares = CitaResMacExtends.GetRegisterUserResMac(res); //data verified if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, CitaRegisterUserResBody>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, CitaRegisterUserResBody>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, CitaRegisterUserResBody>(false, "failed to register the user", null));; }
/// <summary> /// gets the total number of transactions in the block /// </summary> /// <returns></returns> public Tuple <bool, string, GetBlockHeightResBody> GetTxCountByBlockNumber(string blockNumber) { try { NodeApiReqBody <FiscoBlockReqDataBody> req = new NodeApiReqBody <FiscoBlockReqDataBody> { header = GetReqHeader(), body = new FiscoBlockReqDataBody() { BlockNumber = blockNumber } }; req.mac = sign.Sign(FiscoReqMacExtends.GetFiscoBlockInfoReqMac(req)); var res = SendHelper.SendPost <NodeApiResBody <GetBlockHeightResBody> >(config.reqUrl + GetTxCountByBlockNumberUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, GetBlockHeightResBody>(false, res.header.msg, null)); } //assemble the original string to verify var datares = FiscoResMacExtends.GetBlockHeightResMac(res); //data verified if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, GetBlockHeightResBody>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, GetBlockHeightResBody>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, GetBlockHeightResBody>(false, "failed to get the total number of transactions in the block", null)); }
/// <summary> /// get block info /// </summary> /// <param name="reqBody"></param> /// <returns></returns> public Tuple <bool, string, FiscoBlockData> GetBlockInfo(FiscoBlockReqDataBody reqBody) { try { NodeApiReqBody <FiscoBlockReqDataBody> req = new NodeApiReqBody <FiscoBlockReqDataBody> { header = GetReqHeader(), body = reqBody }; req.mac = sign.Sign(FiscoReqMacExtends.GetFiscoBlockInfoReqMac(req)); var res = SendHelper.SendPost <NodeApiResBody <FiscoBlockData> >(config.reqUrl + BlockInfoUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, FiscoBlockData>(false, res.header.msg, null)); } //assemble the original string to verify var datares = FiscoResMacExtends.GetFiscoBlockInfoResMac(res); //data verified if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, FiscoBlockData>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, FiscoBlockData>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, FiscoBlockData>(false, "failed to get block info", null)); }
/// <summary> /// event registration /// </summary> /// <param name="reqBody"></param> /// <returns></returns> public Tuple <bool, string, CitaRegisterEventResData> EventRegister(CitaRegisterEventReqDataBody reqBody) { try { NodeApiReqBody <CitaRegisterEventReqDataBody> req = new NodeApiReqBody <CitaRegisterEventReqDataBody> { header = GetReqHeader(), body = reqBody }; req.mac = sign.Sign(CitaReqMacExtends.GetCitaEventRegisterReqMac(req)); var res = SendHelper.SendPost <NodeApiResBody <CitaRegisterEventResData> >(config.reqUrl + EventRegisterUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, CitaRegisterEventResData>(false, res.header.msg, null)); } //assemble the original string to verify var datares = CitaResMacExtends.GetCitaEventRegisterResMac(res); //data verified if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, CitaRegisterEventResData>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, CitaRegisterEventResData>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, CitaRegisterEventResData>(false, "failed to register chaincode event", null)); }
/// <summary> /// event logout /// </summary> /// <returns></returns> public Tuple <bool, string, NodeApiRes> EventRemove(RemoveReqDataBody reqBody) { try { NodeApiReqBody <RemoveReqDataBody> req = new NodeApiReqBody <RemoveReqDataBody>() { header = GetReqHeader(), body = reqBody }; req.mac = sign.Sign(FiscoReqMacExtends.GetFiscoEventRemoveReqMac(req)); var res = SendHelper.SendPost <NodeApiRes>(config.reqUrl + EventremoveUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, NodeApiRes>(false, res.header.msg, null)); } //assemble the original string to verify var datares = ResMacExtends.GetResHeaderMac(res.header); //data verified if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, NodeApiRes>(true, res.header.msg, res)); } else { return(new Tuple <bool, string, NodeApiRes>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, NodeApiRes>(false, "failed to logout event chaincode", null)); }
/// <summary> /// Get application block height information /// </summary> /// <returns></returns> public Tuple <bool, string, CitaBlockHeightResBody> GetBlockHeight() { try { NodeApiReq req = new NodeApiReq() { header = GetReqHeader() }; req.mac = sign.Sign(CitaReqMacExtends.GetReqHeaderMac(req.header)); var res = SendHelper.SendPost <NodeApiResBody <CitaBlockHeightResBody> >(config.reqUrl + GetBlockHeightUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, CitaBlockHeightResBody>(false, res.header.msg, null)); } //assemble the original string to verify var datares = CitaResMacExtends.GetBlockHeightResMac(res); //data verified if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, CitaBlockHeightResBody>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, CitaBlockHeightResBody>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, CitaBlockHeightResBody>(false, "failed to get the block height in the application", null)); }
/// <summary> /// event query /// </summary> /// <returns></returns> public Tuple <bool, string, QueryEventResData> EventQuery() { try { NodeApiReq req = new NodeApiReq() { header = GetReqHeader() }; req.mac = sign.Sign(FiscoReqMacExtends.GetReqHeaderMac(req.header)); var res = SendHelper.SendPost <NodeApiResBody <QueryEventResData> >(config.reqUrl + EventQueryUrl, JsonConvert.SerializeObject(req), config.httpsCert); if (res != null) { //Check the status codes in turn if (res.header.code != 0) { return(new Tuple <bool, string, QueryEventResData>(false, res.header.msg, null)); } //assemble the original string to verify var datares = FiscoResMacExtends.GetFiscoQueryEventResMac(res); //data verified if (sign.Verify(res.mac, datares)) { return(new Tuple <bool, string, QueryEventResData>(true, res.header.msg, res.body)); } else { return(new Tuple <bool, string, QueryEventResData>(false, "failed to verify the signature", null)); } } } catch (Exception ex) { throw ex; } return(new Tuple <bool, string, QueryEventResData>(false, "failed to query the chaincode", null)); }