Esempio n. 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));
        }
Esempio n. 2
0
        /// <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));;
        }
Esempio n. 3
0
        /// <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));
        }
Esempio n. 4
0
        /// <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));
        }
Esempio n. 5
0
        /// <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));
        }
Esempio n. 6
0
        /// <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));
        }