public JsonResult Transfer([FromBody] JObject jsonData)
        {
            return(DoWithRetry(GetRetryValueFromJson(jsonData), (retryCount) =>
            {
                /** Get transfer data */
                var toAddress = jsonData.GetValue("recipientAddress").Value <string>();

                /** Get the type of currency */
                var amount = jsonData.GetValue("amount").Value <decimal>();
                var asset = jsonData.GetValue("asset").Value <string>();

                /* Get owner data from private key */
                var fromPrivateKey = jsonData.GetValue("ownerPrivateKeyHash").Value <string>();
                var fromKeyPair = new KeyPair(LuxUtils.HexToBytes(fromPrivateKey));

                try
                {
                    var transactionResult = LuxApiFactory.GetLuxApi().SendAsset(fromKeyPair, toAddress, asset, amount);
                    if (transactionResult != null)
                    {
                        dynamic result = new JObject();
                        result.result = transactionResult.ToString();
                        result.retries = retryCount;
                        return Json(result);
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message + "\n" + e.StackTrace);
                }

                return null;
            }));
        }
        public JsonResult GenerateTo([FromBody] JObject jsonData)
        {
            return(DoWithRetry(GetRetryValueFromJson(jsonData), retryCount =>
            {
                /** Get transfer data */
                var contractScripHash = jsonData.GetValue("contractScriptHash").Value <string>();
                var toAddress = jsonData.GetValue("recipientAddress").Value <string>();
                var amount = jsonData.GetValue("amount").Value <double>();
                Log.Debug($"GenerateTo called with recipient {toAddress} and value {amount}");
                /* Get owner data from private key */
                var fromPrivateKey = jsonData.GetValue("ownerPrivateKeyHash").Value <string>();
                var fromKeyPair = new KeyPair(LuxUtils.HexToBytes(fromPrivateKey));

                var token = new NeoFluxNEP5(LuxApiFactory.GetLuxApi(), contractScripHash, null,
                                            GetDecimalsValueFromJson(jsonData));
                try
                {
                    Log.Debug($"Running transaction for recipient {toAddress}");
                    var transactionResult = token.GenerateTo(fromKeyPair, toAddress, new BigInteger(amount));
                    if (transactionResult != null)
                    {
                        dynamic result = new JObject();
                        result.result = transactionResult.ToString();
                        result.retries = retryCount;
                        Log.Debug($"Sent {amount} to {toAddress}");
                        return Json(result);
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message + "\n" + e.StackTrace);
                }
                return null;
            }));
        }
Beispiel #3
0
 public static byte[] HexToBytes(this string hex)
 {
     return(LuxUtils.HexToBytes(hex));
 }