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 registration
        /// </summary>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string, RegisterEventResData> EventRegister(FiscoRegisterReqDataBody reqBody)
        {
            try
            {
                NodeApiReqBody <FiscoRegisterReqDataBody> req = new NodeApiReqBody <FiscoRegisterReqDataBody>
                {
                    header = GetReqHeader(),
                    body   = reqBody
                };
                req.mac = sign.Sign(FiscoReqMacExtends.GetFiscoEventRegisterReqMac(req));
                var res = SendHelper.SendPost <NodeApiResBody <RegisterEventResData> >(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, RegisterEventResData>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = FiscoResMacExtends.GetFiscoEventRegisterResMac(res);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, RegisterEventResData>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, RegisterEventResData>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, RegisterEventResData>(false, "failed to register chaincode event", null));
        }
Esempio n. 5
0
        /// <summary>
        /// Get application block height information
        ///  </summary>
        /// <returns></returns>
        public Tuple <bool, string, GetBlockHeightResBody> GetBlockHeight()
        {
            try
            {
                NodeApiReq req = new NodeApiReq()
                {
                    header = GetReqHeader()
                };
                req.mac = sign.Sign(FiscoReqMacExtends.GetReqHeaderMac(req.header));
                var res = SendHelper.SendPost <NodeApiResBody <GetBlockHeightResBody> >(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, 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 block height in the application", null));
        }