コード例 #1
0
ファイル: Work_4_3.cs プロジェクト: CREDITSCOM/cs-wallet-web
 public API_TransactionFlowResult_4_3(TransactionFlowResult tfr)
 {
     Status = new API_APIResponse_4_3(tfr.Status);
     if (tfr.__isset.smart_contract_result)
     {
         Smart_contract_result = new API_Variant_4_3(tfr.Smart_contract_result);
     }
 }
コード例 #2
0
ファイル: Work_4_3.cs プロジェクト: CREDITSCOM/cs-wallet-web
        public API_TransactionFlowResult SendTransaction(CreateTransactionModel model)
        {
            Transaction T = CreateTransaction(model);

            T.Currency = 1;
            TransactionFlowResult Res = _connect.TransactionFlow(T);

            if (Res.Status.Code > 0)
            {
                throw new Exception(Res.Status.Message);
            }
            return(new API_TransactionFlowResult_4_3(Res));
        }
コード例 #3
0
ファイル: Work_4_3.cs プロジェクト: CREDITSCOM/cs-wallet-web
        public API_TransactionFlowResult SendTransaction(CreateTransactionModel model, byte[] PrivateKey)
        {
            Transaction T = CreateTransaction(model);

            T.Currency  = 1;
            T.Signature = SignTransaction(PrivateKey, CreatePervStr(T));
            TransactionFlowResult Res = _connect.TransactionFlow(T);

            if (Res.Status.Code > 0)
            {
                throw new Exception(Res.Status.Message);
            }
            return(new API_TransactionFlowResult_4_3(Res));
        }
コード例 #4
0
ファイル: Work_4_3.cs プロジェクト: CREDITSCOM/cs-wallet-web
        public T SendTransaction <T>(CreateTransactionModel model, byte[] PrivateKey) where T : CreateTransactionModel
        {
            Transaction t = CreateTransaction(model);

            t.Currency  = 1;
            t.Signature = SignTransaction(PrivateKey, CreatePervStr(t));
            TransactionFlowResult Res = _connect.TransactionFlow(t);

            if (Res.Status.Code > 0)
            {
                throw new Exception(Res.Status.Message);
            }
            model.Target = t.Target;

            return((T)model);
        }
コード例 #5
0
        public ResponseApiModel ExecuteTransaction(RequestApiModel request, int isDelegate = 0)
        {
            ResponseApiModel response = null;

            using (var client = GetClientByModel(request))
            {
                //снова инициируем транзакцию
                var transac = InitTransaction(request);
                transac.Signature = SimpleBase.Base58.Bitcoin.Decode(request.TransactionSignature).ToArray();

                if (request.DelegateEnable && !request.DelegateDisable)
                {
                    transac.UserFields = new byte[15] {
                        0, 1, 5, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0
                    }
                }
                ;
                else if (request.DelegateDisable && !request.DelegateEnable)
                {
                    transac.UserFields = new byte[15] {
                        0, 1, 5, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0
                    }
                }
                ;

                TransactionFlowResult result = client.TransactionFlow(transac);
                response            = new ResponseApiModel();
                response.FlowResult = result;
                if (request.MethodApi == ApiMethodConstant.SmartDeploy)
                {
                    response.DataResponse.PublicKey = SimpleBase.Base58.Bitcoin.Encode(transac.Target);
                }
                if (result.Status.Code > 0)
                {
                    response.Success = false;
                    response.Message = result.Status.Message;
                }
                else
                {
                    response.Success            = true;
                    response.TransactionInnerId = transac.Id;
                    if (result.Id != null)
                    {
                        response.TransactionId = $"{result.Id.PoolSeq}.{result.Id.Index + 1}";
                    }
                    response.DataResponse.RecommendedFee = BCTransactionTools.GetDecimalByAmount(response.FlowResult.Fee);
                    if (response.DataResponse.RecommendedFee == 0)
                    {
                        response.DataResponse.RecommendedFee = MinTransactionFee;
                    }
                    var sum = BCTransactionTools.GetDecimalByAmount(transac.Amount);
                    if (sum > 0)
                    {
                        if (response.Amount == 0)
                        {
                            response.Amount = sum;
                        }
                        if (response.ActualSum == 0)
                        {
                            response.ActualSum = sum;
                        }
                    }
                    //TODO: extract fee from node
                    if (result.Fee != null)
                    {
                        response.ActualFee = BCTransactionTools.GetDecimalByAmount(result.Fee);
                        if (response.ActualFee == 0M)
                        {
                            response.ActualFee = MinTransactionFee;
                        }
                    }

                    if (result.ExtraFee != null)
                    {
                        response.ExtraFee = new List <EFeeItem>();
                        foreach (var eFee in result.ExtraFee)
                        {
                            var feeSum = BCTransactionTools.GetDecimalByAmount(eFee.Sum);
                            response.ExtraFee.Add(new EFeeItem()
                            {
                                Fee     = feeSum,
                                Comment = eFee.Comment
                            });
                        }
                    }
                    if (request.MethodApi == ApiMethodConstant.SmartMethodExecute)
                    {
                        if (result.Smart_contract_result != null)
                        {
                            try
                            {
                                response.DataResponse.SmartContractResult = result.Smart_contract_result.ToString();
                            }
                            catch (Exception ex)
                            {
                                response.DataResponse.SmartContractResult = "";
                            }
                        }
                    }
                }
            }

            return(response);
        }
    }