private Hash SettleSwapToNeo(Hash sourceHash) { return(SettleSwapToExternal(NeoWallet.NeoPlatform, sourceHash, (destination, token, amount) => { var total = UnitConversion.ToDecimal(amount, token.Decimals); var wif = wifs["neo"]; var neoKeys = Phantasma.Neo.Core.NeoKeys.FromWIF(wif); var destAddress = NeoWallet.DecodeAddress(destination); logger.Message($"NEOSWAP: Trying transfer of {total} {token.Symbol} from {neoKeys.Address} to {destAddress}"); Neo.Core.Transaction tx; if (token.Symbol == "NEO" || token.Symbol == "GAS") { tx = neoAPI.SendAsset(neoKeys, destAddress, token.Symbol, total); } else { var nep5 = neoAPI.GetToken(token.Symbol); tx = nep5.Transfer(neoKeys, destAddress, total); } if (tx == null) { logger.Error("NeoAPI error: " + neoAPI.LastError); return Hash.Null; } var txHash = Hash.Parse(tx.Hash.ToString()); return txHash; })); }
private void button2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(toAddressBox.Text)) { MessageBox.Show("Please insert destination address"); return; } var symbol = assetComboBox.SelectedItem.ToString(); int amount = int.Parse(amountBox.Text); if (amount <= 0) { MessageBox.Show("Please insert a valid amount of " + symbol); return; } if (!balances.ContainsKey(symbol) || balances[symbol] < amount) { MessageBox.Show("You dont have enough " + symbol); return; } if (api.IsAsset(symbol)) { api.SendAsset(keyPair, toAddressBox.Text, symbol, amount); } else { var token = api.GetToken(symbol); token.Transfer(keyPair, toAddressBox.Text, amount); } }
private Hash SettleSwapToNeo(Hash sourceHash) { return(SettleSwapToExternal(NeoWallet.NeoPlatform, sourceHash, (destination, token, amount) => { var total = UnitConversion.ToDecimal(amount, token.Decimals); var wif = wifs["neo"]; var neoKeys = Phantasma.Neo.Core.NeoKeys.FromWIF(wif); var destAddress = NeoWallet.DecodeAddress(destination); Neo.Core.Transaction tx; if (token.Symbol == "NEO" || token.Symbol == "GAS") { tx = neoAPI.SendAsset(neoKeys, destAddress, token.Symbol, total); } else { var nep5 = neoAPI.GetToken(token.Symbol); tx = nep5.Transfer(neoKeys, destAddress, total); } var txHash = Hash.Parse(tx.Hash.ToString()); return txHash; })); }
private static Hash NeoTransfer(NeoKeys neoKeys, string toAddress, string tokenSymbol, decimal tempAmount, NeoAPI neoAPI) { Neo.Core.Transaction neoTx; logger.Message($"Sending {tempAmount} {tokenSymbol} to {toAddress}..."); Thread.Sleep(500); try { if (tokenSymbol == "NEO" || tokenSymbol == "GAS") { neoTx = neoAPI.SendAsset(neoKeys, toAddress, tokenSymbol, tempAmount, out string usedRpc); } else { var nep5 = neoAPI.GetToken(tokenSymbol); if (nep5 == null) { throw new CommandException($"Could not find interface for NEP5: {tokenSymbol}"); } neoTx = nep5.Transfer(neoKeys, toAddress, tempAmount); } logger.Success($"Waiting for confirmations, could take up to a minute..."); Thread.Sleep(45000); logger.Success($"Sent transaction with hash {neoTx.Hash}!"); var hash = Hash.Parse(neoTx.Hash.ToString()); return(hash); } catch (Exception e) { logger.Message("Error sending NEO transaction: " + e); return(Hash.Null); } }
public void Init() { api = NeoRPC.ForTestNet(); token = api.GetToken("RPX"); }
// NOTE no locks happen here because this callback is called from within a lock internal override Hash SettleSwap(Hash sourceHash, Address destination, IToken token, Numerics.BigInteger amount) { Hash txHash = Hash.Null; string txStr = null; var inProgressMap = new StorageMap(TokenSwapper.InProgressTag, Swapper.Storage); var rpcMap = new StorageMap(TokenSwapper.UsedRpcTag, Swapper.Storage); if (inProgressMap.ContainsKey <Hash>(sourceHash)) { txStr = inProgressMap.Get <Hash, string>(sourceHash); if (!string.IsNullOrEmpty(txStr)) { return(VerifyNeoTx(sourceHash, txStr)); } } var total = Numerics.UnitConversion.ToDecimal(amount, token.Decimals); var neoKeys = NeoKeys.FromWIF(this.WIF); var destAddress = NeoWallet.DecodeAddress(destination); Logger.Debug($"NEOSWAP: Trying transfer of {total} {token.Symbol} from {neoKeys.Address} to {destAddress}"); var nonce = sourceHash.ToByteArray(); Neo.Core.Transaction tx = null; string usedRpc = null; try { if (token.Symbol == "NEO" || token.Symbol == "GAS") { tx = neoAPI.SendAsset(neoKeys, destAddress, token.Symbol, total, out usedRpc); } else { var nep5 = neoAPI.GetToken(token.Symbol); tx = nep5.Transfer(neoKeys, destAddress, total, nonce, x => usedRpc = x); } // persist resulting tx hash as in progress inProgressMap.Set <Hash, string>(sourceHash, tx.Hash.ToString()); rpcMap.Set <Hash, string>(sourceHash, usedRpc); Logger.Debug("broadcasted neo tx: " + tx); } catch (Exception e) { Logger.Error("Error during transfering {token.Symbol}: " + e); return(Hash.Null); } if (tx == null) { Logger.Error($"NeoAPI error {neoAPI.LastError} or possible failed neo swap sourceHash: {sourceHash} no transfer happend."); return(Hash.Null); } var strHash = tx.Hash.ToString(); return(VerifyNeoTx(sourceHash, strHash)); }
public void Init() { api = NeoDB.ForMainNet(); token = api.GetToken("RPX"); }