Пример #1
0
        /// <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));
        }
Пример #2
0
        /// <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));;
        }
Пример #3
0
        /// <summary>
        /// transactions under Key-Trust Mode
        /// </summary>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string, CitaTransResBody> ReqChainCode(CitaTransReqDataBody reqBody)
        {
            try
            {
                NodeApiReqBody <CitaTransReqDataBody> req = new NodeApiReqBody <CitaTransReqDataBody>
                {
                    header = GetReqHeader(),
                    body   = reqBody
                };
                req.mac = sign.Sign(CitaReqMacExtends.GetCitaTransReqMac(req));

                var res = SendHelper.SendPost <NodeApiResBody <CitaTransResBody> >(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, 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));
        }
Пример #4
0
        /// <summary>
        /// event query
        /// </summary>
        /// <returns></returns>
        public Tuple <bool, string, CitaQueryEventResData> EventQuery()
        {
            try
            {
                NodeApiReq req = new NodeApiReq()
                {
                    header = GetReqHeader()
                };
                req.mac = sign.Sign(CitaReqMacExtends.GetReqHeaderMac(req.header));
                var res = SendHelper.SendPost <NodeApiResBody <CitaQueryEventResData> >(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, CitaQueryEventResData>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = CitaResMacExtends.GetCitaQueryEventResMac(res);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, CitaQueryEventResData>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, CitaQueryEventResData>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, CitaQueryEventResData>(false, "failed to query the chaincode", null));
        }