コード例 #1
0
        /// <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));
        }
コード例 #2
0
        /// <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));
        }