Exemplo n.º 1
0
        private bool SendTxTransfer(string symbol, string sender, string toAddress, string amount, string fee, string privateKey)
        {
            try
            {
                TransactionTransferRequest data = new TransactionTransferRequest();
                data.Body             = new TransactionTransferRequestBody();
                data.Body.Nonce       = DateTimeUtility.CurrentUnixTimeUTC();
                data.Body.Fee         = fee;
                data.Body.TokenSymbol = symbol;
                data.Body.Sender      = sender;
                data.Body.ToAddress   = toAddress;
                data.Body.Amount      = amount;
                data.Signature        = KeySignature.Sign(privateKey, JsonConvert.SerializeObject(data.Body));

                string endpoint = nodeServerAddress + "/transaction/transfer";
                Log("Api:" + endpoint);
                string responseData = this.SendPostRequest(endpoint, JsonConvert.SerializeObject(data));
                Log("Response:" + responseData);

                return(true);
            }
            catch (Exception ex)
            {
                Log("Failed: " + ex.Message);
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool SendTransaction(string nodeAddress, long nonce)
        {
            bool isSuccessful = false;

            try
            {
                //Test send native token from owner wallet to another wallet
                TransactionTransferRequest data = new TransactionTransferRequest();
                data.Body = new TransactionTransferRequestBody()
                {
                    Nonce       = nonce,
                    TokenSymbol = "DXR",
                    Sender      = "N4ue7ZC1ciuiDjn9QgKHH5etHnVAjhRsJtwnyVLH7TqBBmaobL7ZtZm7MD8YhZgyvkw89BBkyzWJwd8CGfTxDLNR",
                    ToAddress   = "SK8mWrHYb5LFznZxi7XThogYHdS4ZCkrd7182dUuS7G2vzkTgEKoCPbhrBLfdPujxnTS9JPhBcwaYqrKxcnqA2dZ",
                    Amount      = "1"
                };
                //data.Signature = KeySignature.Sign(this.PrivateKey, JsonConvert.SerializeObject(data.Body));

                Node sender = new Node()
                {
                    ServerAddress = "http://localhost:8080"
                };
                string endpoint     = nodeAddress + "/transaction/transfer";
                string responseData = this.SendPostRequest(sender, endpoint, JsonConvert.SerializeObject(data));

                isSuccessful = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                isSuccessful = false;
            }

            return(isSuccessful);
        }
Exemplo n.º 3
0
        public GenericResponse Transfer(TransactionTransferRequest value)
        {
            try
            {
                VerifySignature(value.Body, value.Signature, value.Body.Sender);

                if (!ApplicationState.IsChainUpToDate)
                {
                    return(new GenericResponse(null, ResponseCodes.Success, ResponseMessages.NodeNotConsensusReady));
                }

                //Perform transaction
                TransactionServices transactionService = new TransactionServices();
                string txId = transactionService.AddTransfer(
                    value.Body.Nonce,
                    Convert.ToDecimal(value.Body.Fee),
                    value.Body.TokenSymbol,
                    value.Body.Sender,
                    value.Body.ToAddress,
                    Convert.ToDecimal(value.Body.Amount));

                ApplicationLog.Info("Transaction added to queue for next block. TxId: " + txId);
                return(new GenericResponse(txId, ResponseCodes.Success, "Transaction added to queue for next block."));
            }
            catch (ValidationException vex)
            {
                ApplicationLog.Warn("ValidationException [" + vex.Code + "]: " + vex.Message);
                return(new GenericResponse(null, vex.Code, vex.Message));
            }
            catch (Exception ex)
            {
                ApplicationLog.Exception(ex);
                return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error));
            }
        }
Exemplo n.º 4
0
        // POST: /transaction/transfer
        public static HttpResponse AddTransfer(HttpRequest request)
        {
            TransactionTransferRequest requestData = JsonConvert.DeserializeObject <TransactionTransferRequest>(request.Content);

            TransactionController controller = new TransactionController();
            var response = controller.Transfer(requestData);

            Echo(request);

            return(CreateHttpResponse(response));
        }