コード例 #1
0
        /// <summary>
        /// transaction processing under Key-Upload Mode
        /// </summary>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string, FiscoTransResBody> GetTrans(FiscoTransReq reqBody)
        {
            try
            {
                var tx = new FiscoClient(config).GetTransData(reqBody);
                if (!string.IsNullOrEmpty(tx.Item2))
                {
                    return(new Tuple <bool, string, FiscoTransResBody>(false, tx.Item2, null));
                }

                NodeApiReqBody <FiscoTransReqBody> req = new NodeApiReqBody <FiscoTransReqBody>
                {
                    header = GetReqHeader()
                };
                req.body = new FiscoTransReqBody()
                {
                    ContractName = reqBody.Contract.ContractName,
                    TransData    = "0x" + tx.Item1
                };
                req.mac = sign.Sign(FiscoReqMacExtends.GetFiscoTransReqMac(req));
                var res = SendHelper.SendPost <NodeApiResBody <FiscoTransResBody> >(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, FiscoTransResBody>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = FiscoResMacExtends.GetFiscoTransactionResMac(res);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, FiscoTransResBody>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, FiscoTransResBody>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, FiscoTransResBody>(false, "The deal failed", null));
        }
コード例 #2
0
        /// <summary>
        /// transactions under Key-Trust Mode
        /// </summary>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string, FiscoTransResBody> ReqChainCode(FiscoTransReqDataBody reqBody)
        {
            try
            {
                NodeApiReqBody <FiscoTransReqDataBody> req = new NodeApiReqBody <FiscoTransReqDataBody>
                {
                    header = GetReqHeader(),
                    body   = reqBody
                };
                req.mac = sign.Sign(FiscoReqMacExtends.GetFiscoTransReqMac(req));
                var res = SendHelper.SendPost <NodeApiResBody <FiscoTransResBody> >(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, FiscoTransResBody>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = FiscoResMacExtends.GetFiscoTransactionResMac(res);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, FiscoTransResBody>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, FiscoTransResBody>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, FiscoTransResBody>(false, "The deal failed", null));
        }