Esempio n. 1
0
        public Tuple <string, string> GetTransData(FiscoTransReq data)
        {
            var blockLimit = GetBlockLimit();
            var groupId    = GetGroupId();
            var key        = FiscoConfig.GetUserKey(data.UserName, config);
            var tx         = FiscoTrans.TransData(data.Contract.ContractAbi, data.Contract.ContractAddress, data.FuncName, data.Args, groupId, blockLimit, null, isSM(), key);

            return(tx);
        }
Esempio n. 2
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));
        }