public async Task AnnounceTransferTransactionWithMosaicWithMessage() { var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var account = new Account("E45030D2A22D97FDC4C78923C4BBF7602BBAC3B018FFAD2ED278FB49CD6F218C", NetworkType.Types.MIJIN_TEST); var transaction = TransferTransaction.Create( NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), account.Address, new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 100000000000) }, PlainMessage.Create("hello") ).SignWith(keyPair); listener.TransactionStatus(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)) .Subscribe(e => { Console.WriteLine(e.Status); }); await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction); var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)).Take(1); Assert.AreEqual(keyPair.PublicKeyString, status.Signer.PublicKey); }
public void CreateANewMosaicWithIdentifier() { Mosaic mosaic = Mosaic.CreateFromIdentifier("nem:xem", 24); Assert.IsTrue(mosaic.MosaicId.HexId == Xem.Id.HexId); Assert.IsTrue(mosaic.Amount.Equals(24)); }
public async Task AnnounceMultisigTransaction() { var cosignatory = KeyPair.CreateFromPrivateKey("8db858dcc8e2827074498204b3829154ec4c4f24d13738d3f501003b518ef256"); var multisigAccount = PublicAccount.CreateFromPublicKey("29c4a4aa674953749053c8a35399b37b713dedd5d002cb29b3331e56ff1ea65a", NetworkType.Types.TEST_NET); var recipient = new Account("E45030D2A22D97FDC4C78923C4BBF7602BBAC3B018FFAD2ED278FB49CD6F218C", NetworkType.Types.TEST_NET); var transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), recipient.Address, new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 1000000) }, PlainMessage.Create("hello") ); var multisigTransaction = MultisigTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(1), transaction ).SignWith(cosignatory, multisigAccount); var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(multisigTransaction); Assert.AreEqual("SUCCESS", response.Message); }
public async Task AnnounceTransferTransactionWithMultipleMosaicsWithoutMessage() { var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = TransferTransaction.Create( NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), Address.CreateFromEncoded("SAAA57-DREOPY-KUFX4O-G7IQXK-ITMBWK-D6KXTV-BBQP"), new List <Mosaic>() { Mosaic.CreateFromIdentifier("happy:test2", 10), Mosaic.CreateFromIdentifier("nem:xem", 10), }, EmptyMessage.Create() ).SignWith(keyPair); await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction); listener.TransactionStatus(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)) .Subscribe(e => Console.WriteLine(e.Status)); var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)).Take(1); Assert.AreEqual(keyPair.PublicKeyString, status.Signer.PublicKey); }
protected MosaicDefinitionTransaction ToMosaicDefinitionTransaction(JObject tx, TransactionInfo txInfo) { return(new MosaicDefinitionTransaction( ExtractNetworkType(int.Parse(tx["version"].ToString())), ExtractVersion(int.Parse(tx["version"].ToString())), new Deadline(int.Parse(tx["deadline"].ToString())), ulong.Parse(tx["fee"].ToString()), new MosaicProperties( int.Parse(tx["mosaicDefinition"]["properties"].ToList()[0]["value"].ToString()), ulong.Parse(tx["mosaicDefinition"]["properties"].ToList()[1]["value"].ToString()), bool.Parse(tx["mosaicDefinition"]["properties"].ToList()[2]["value"].ToString()), bool.Parse(tx["mosaicDefinition"]["properties"].ToList()[3]["value"].ToString())), MosaicId.CreateFromMosaicIdentifier(tx["mosaicDefinition"]["id"]["namespaceId"] + ":" + tx["mosaicDefinition"]["id"]["name"]), tx["mosaicDefinition"]["levy"].ToString() == "{}" ? null : new MosaicLevy( Mosaic.CreateFromIdentifier( (tx["mosaicDefinition"]["levy"]["mosaicId"]["namespaceId"] + ":" + tx["mosaicDefinition"]["levy"]["mosaicId"]["name"]), ulong.Parse(tx["mosaicDefinition"]["levy"]["fee"].ToString())), int.Parse(tx["mosaicDefinition"]["levy"]["type"].ToString()), Address.CreateFromEncoded(tx["mosaicDefinition"]["levy"]["recipient"].ToString())), new PublicAccount(tx["mosaicDefinition"]["creator"].ToString(), ExtractNetworkType(int.Parse(tx["version"].ToString()))), tx["mosaicDefinition"]["description"].ToString(), tx["signature"].ToString(), new PublicAccount(tx["signer"].ToString(), ExtractNetworkType(int.Parse(tx["version"].ToString()))), txInfo )); }
public static async Task <bool> SendFromNewAccount(String message, Account newAcc) { KeyPair keyPair = KeyPair.CreateFromPrivateKey(newAcc.PrivateKey); var transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), Address.CreateFromEncoded(Config.Address), new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 10) }, SecureMessage.Create(message, newAcc.PrivateKey, Config.PublicKey) ); TransactionHttp transactionHttp = new TransactionHttp("http://" + Config.Domain + ":7890"); SignedTransaction signedTransaction = transaction.SignWith(keyPair); Thread.Sleep(2000); await transactionHttp.Announce(signedTransaction); Thread.Sleep(2000); Console.WriteLine(signedTransaction.Hash); Console.WriteLine(Config.Address + " recve something from : " + newAcc.Address.Plain); return(true); }
public async Task <object> TestingTransfer(string from, string privateKey, string to, IAsset asset, decimal amount) { var nodeHttp = new NodeHttp(_nemUrl); var networkType = await nodeHttp.GetNetworkType(); var networkTime = (int)(await nodeHttp.GetExtendedNodeInfo()).NisInfo.CurrentTime; var toAddressParts = to.Split(AddressSeparator); var message = toAddressParts.Length > 1 ? PlainMessage.Create(toAddressParts[1]) as IMessage : EmptyMessage.Create(); var mosaic = Mosaic.CreateFromIdentifier(asset.AssetId, (ulong)asset.ToBaseUnit(amount)); var fee = await TransferTransaction.CalculateFee(networkType, message, new[] { mosaic }, new NamespaceMosaicHttp(_nemUrl)); var tx = TransferTransaction.Create( networkType, new Deadline(networkTime + _expiresInSeconds), fee.fee, Address.CreateFromEncoded(toAddressParts[0]), new List <Mosaic> { mosaic }, message, networkTime); var signed = tx.SignWith(KeyPair.CreateFromPrivateKey(privateKey)); var result = await new TransactionHttp(_nemUrl).Announce(signed); return(result); }
public void CreateANewMosaicWithIdentifier() { Mosaic mosaic = Mosaic.CreateFromIdentifier("nem:xem", 24); Assert.IsTrue(mosaic.MosaicName == "xem"); Assert.IsTrue(mosaic.NamespaceName == "nem"); Assert.IsTrue(mosaic.Amount.Equals(24)); }
internal static TransferTransaction CreateInnerTransferTransaction(String signer) { return(TransferTransaction.Create( NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), Address.CreateFromEncoded("SAAA57DREOPYKUFX4OG7IQXKITMBWKD6KXTVBBQP"), new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 10) }, PlainMessage.Create("hey"))); }
internal static TransferTransaction CreateInnerTransferTransaction(string mosaic, ulong amount = 10) { return(TransferTransaction.Create( NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), Address.CreateFromEncoded("SAAA57-DREOPY-KUFX4O-G7IQXK-ITMBWK-D6KXTV-BBQP"), new List <Mosaic> { Mosaic.CreateFromIdentifier(mosaic, amount) }, PlainMessage.Create("hey") )); }
public async Task <TransactionResponse> Send(object data) { var cosignatory = KeyPair.CreateFromPrivateKey("8db858dcc8e2827074498204b3829154ec4c4f24d13738d3f501003b518ef256"); var secondCosig = KeyPair.CreateFromPrivateKey("cfe47dd9801a5d4fe37183e8f6ca49fff532a2fe6fe099436df93b3d62fe17d5"); var multisigAccount = PublicAccount.CreateFromPublicKey("29c4a4aa674953749053c8a35399b37b713dedd5d002cb29b3331e56ff1ea65a", NetworkType.Types.TEST_NET); var recipient = new Account("E45030D2A22D97FDC4C78923C4BBF7602BBAC3B018FFAD2ED278FB49CD6F218C", NetworkType.Types.TEST_NET); var transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), recipient.Address, new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 1000000) }, PlainMessage.Create("hello") ); var multisigTransaction = MultisigTransaction .Create(NetworkType.Types.TEST_NET, Deadline.CreateHours(1), transaction) .SignWith(cosignatory, multisigAccount); TransactionResponse response = await new TransactionHttp(host).Announce(multisigTransaction); var signatureTransaction = CosignatureTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(1), "59f5f7cbbdaa996b8d3c45ce814280aab3b5d322a98fe95c00ae516cf436172d", multisigAccount.Address ).SignWith(secondCosig); TransactionResponse response2 = await new TransactionHttp(host).Announce(signatureTransaction); //var localVarPath = "/transaction/announce"; //var client = new RestClient(host); //var request = new RestRequest(localVarPath, Method.POST); //request.AddParameter("application/json", data, ParameterType.RequestBody); //var resp = client.Execute(request); if (response.Status == "1") { TransactionInfo transactionInfo = new TransactionInfo { Id = 1, Hash = response.Hash, InnerHash = response.InnerHash }; _transactionInfoRepository.AddTransaction(transactionInfo); } return(null); }
public async Task CanCreateMosaicWithLevy() { var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = MosaicDefinitionTransaction.CreateWithLevy( NetworkType.Types.TEST_NET, Deadline.CreateHours(1), new MosaicProperties(4, 1000000000, true, true), MosaicId.CreateFromMosaicIdentifier("myspace:subspacewithlevy"), new MosaicLevy(Mosaic.CreateFromIdentifier("myspace:subspace", 100), 1, Address.CreateFromEncoded("TCTUIF-557ZCQ-OQPW2M-6GH4TC-DPM2ZY-BBL54K-GNHR")), PublicAccount.CreateFromPublicKey(keyPair.PublicKeyString, NetworkType.Types.TEST_NET), "new mosaic test" ).SignWith(keyPair); var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(transaction); Assert.AreEqual("FAILURE_MOSAIC_MODIFICATION_NOT_ALLOWED", response.Message); }
public async Task AnnounceTransaction(ulong amount = 10) { var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = TransferTransaction.Create( NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), Address.CreateFromEncoded("SCEYFB35CYFF2U7UZ32RYXXZ5JTPCSKU4P6BRXZR"), new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", amount) }, PlainMessage.Create("hello") ).SignWith(keyPair); await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction); }
public async Task AnnounceTransferTransactionWithMosaicWithSecureMessage() { var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), Address.CreateFromEncoded("TAVPDJ-DR3R3X-4FJUKN-PY2IQB-NNRFV2-QR5NJZ-J3WR"), new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 10) }, SecureMessage.Create("hello2", Config.PrivateKeyMain, "4cc7409929a72019240065c9e53aa339f87ba889238ff9fbe978251fdbb05d9f") ).SignWith(keyPair); var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(transaction); Assert.AreEqual("SUCCESS", response.Message); }
public async Task AnnounceTransferTransactionWithMultipleMosaicsWithoutMessage() { var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), Address.CreateFromEncoded("TALICE-ROONSJ-CPHC63-F52V6F-Y3SDMS-VAEUGH-MB7C"), new List <Mosaic>() { Mosaic.CreateFromIdentifier("nem:xem", 10) }, EmptyMessage.Create() ).SignWith(keyPair); var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(transaction); Assert.AreEqual("SUCCESS", response.Message); }
public async Task AnnounceTransferTransactionWithMultipleMosaicsWithSecureMessage() { var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), Address.CreateFromEncoded("TALICE-ROONSJ-CPHC63-F52V6F-Y3SDMS-VAEUGH-MB7C"), new List <Mosaic>() { Mosaic.CreateFromIdentifier("nem:xem", 1000), //Mosaic.CreateFromIdentifier("nis1porttest:test", 10), TODO: fix multiple mosaic transfer }, SecureMessage.Create("hello2", Config.PrivateKeyMain, "5D8BEBBE80D7EA3B0088E59308D8671099781429B449A0BBCA6D950A709BA068") ).SignWith(keyPair); var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(transaction); Assert.AreEqual("SUCCESS", response.Message); }
public async Task AnnounceTransferTransactionWithMosaicWithMessage() { KeyPair keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); TransferTransaction transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), Address.CreateFromEncoded("TACOPE-XRLZTU-WBQA3U-XV66R4-55L76E-NWK6OY-ITBJ"), new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 1) }, EmptyMessage.Create() ); SignedTransaction signedTransaction = transaction.SignWith(keyPair); Console.WriteLine(signedTransaction.Hash); Console.WriteLine(transaction.Fee); TransactionResponse response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(signedTransaction); Assert.AreEqual("SUCCESS", response.Message); }
public static async void CreateTransaction(Account receiverAcc, String message) { KeyPair keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), Address.CreateFromEncoded(receiverAcc.Address.Plain), new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 2000000) }, SecureMessage.Create(message, Config.PrivateKeyMain, receiverAcc.PublicKey) ); TransactionHttp transactionHttp = new TransactionHttp("http://" + Config.Domain + ":7890"); SignedTransaction signedTransaction = transaction.SignWith(keyPair); Thread.Sleep(2000); await transactionHttp.Announce(signedTransaction); Console.WriteLine(signedTransaction.Hash); Console.WriteLine(receiverAcc.Address.Plain + " recve something from : " + Config.Address); Thread.Sleep(2000); }
public async Task AnnounceTransferTransactionWithMosaicWithSecureMessage() { var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = TransferTransaction.Create( NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), Address.CreateFromEncoded("SAAA57-DREOPY-KUFX4O-G7IQXK-ITMBWK-D6KXTV-BBQP"), new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 10) }, SecureMessage.Create("hello2", Config.PrivateKeyMain, "5D8BEBBE80D7EA3B0088E59308D8671099781429B449A0BBCA6D950A709BA068") ).SignWith(keyPair); await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction); listener.TransactionStatus(Address.CreateFromPublicKey(keyPair.PublicKeyString, NetworkType.Types.MIJIN_TEST)) .Subscribe(e => Console.WriteLine(e.Status)); var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)).Take(1); Assert.AreEqual(keyPair.PublicKeyString, status.Signer.PublicKey); }
public static async Task <bool> TransferTest() { KeyPair keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); TransferTransaction transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), Address.CreateFromEncoded("TBZQXJ-N7JNQL-N7ZAMC-HFFZAU-WBMPB4-4RMIZU-XKNQ"), new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 1000000) }, PlainMessage.Create("Sr Alejo") ); SignedTransaction signedTransaction = transaction.SignWith(keyPair); Console.WriteLine(signedTransaction.Hash); Console.WriteLine(transaction.Fee); TransactionResponse response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(signedTransaction); return(true); }
public static async Task <bool> CreateTransaction() { KeyPair keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), Address.CreateFromEncoded("TCPCAZ-7XJ2X4-SWR6AG-6BUEKS-6DQ7DL-Z2D6QB-5M2V"), new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 10) }, SecureMessage.Create("hello", Config.PrivateKeyMain, "d72f89db8d0a3655168c9d2abe8de2910aaf4506a47d46e22ca48c7e0442e8ef") ); TransactionHttp transactionHttp = new TransactionHttp("http://" + Config.Domain + ":7890"); SignedTransaction signedTransaction = transaction.SignWith(keyPair); Thread.Sleep(2000); await transactionHttp.Announce(signedTransaction); Console.WriteLine(signedTransaction.Hash); Thread.Sleep(2000); return(true); }
public async Task CanSignMultisigTransaction() { var cosignatory = KeyPair.CreateFromPrivateKey("8db858dcc8e2827074498204b3829154ec4c4f24d13738d3f501003b518ef256"); var secondCosig = KeyPair.CreateFromPrivateKey("cfe47dd9801a5d4fe37183e8f6ca49fff532a2fe6fe099436df93b3d62fe17d5"); var multisigAccount = PublicAccount.CreateFromPublicKey("29c4a4aa674953749053c8a35399b37b713dedd5d002cb29b3331e56ff1ea65a", NetworkType.Types.TEST_NET); var recipient = new Account("E45030D2A22D97FDC4C78923C4BBF7602BBAC3B018FFAD2ED278FB49CD6F218C", NetworkType.Types.TEST_NET); var transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), recipient.Address, new List <Mosaic> { Mosaic.CreateFromIdentifier("nem:xem", 1000000) }, PlainMessage.Create("hello") ); var multisigTransaction = MultisigTransaction .Create(NetworkType.Types.TEST_NET, Deadline.CreateHours(1), transaction) .SignWith(cosignatory, multisigAccount); var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(multisigTransaction); Assert.AreEqual("SUCCESS", response.Message); var signatureTransaction = CosignatureTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(1), "59f5f7cbbdaa996b8d3c45ce814280aab3b5d322a98fe95c00ae516cf436172d", multisigAccount.Address ).SignWith(secondCosig); var response2 = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(signatureTransaction); Assert.AreEqual("FAILURE_MULTISIG_NO_MATCHING_MULTISIG", response2.Message); }
public async Task AnnounceTransferTransactionWithMultipleMosaicsWithSecureMessage() { var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = TransferTransaction.Create( NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), Address.CreateFromEncoded("SAOV4Y5W627UXLIYS5O43SVU23DD6VNRCFP222P2"), new List <Mosaic>() { Mosaic.CreateFromIdentifier("nem:xem", 1000000000000), //Mosaic.CreateFromIdentifier("happy:test2", 10), }, SecureMessage.Create("hello2", Config.PrivateKeyMain, "5D8BEBBE80D7EA3B0088E59308D8671099781429B449A0BBCA6D950A709BA068") ).SignWith(keyPair); await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction); var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)).Take(1); Assert.AreEqual(keyPair.PublicKeyString, status.Signer.PublicKey); }
public void CreateANewMosaicWithIdentifierThrowsExeption(string data) { Mosaic.CreateFromIdentifier(data, 24); }
public async Task <(string transactionContext, decimal fee, long expiration)> BuildTransactionAsync(Guid operationId, IAsset asset, IReadOnlyList <IOperationAction> actions, bool includeFee) { // from one side NEM supports single sender and single receiver per transaction, // from the other side we support single asset per transaction, // finally only single transfers are allowed if (actions.Count != 1) { throw new ArgumentException("Transaction must contain a single transfer only"); } var nodeHttp = new NodeHttp(_nemUrl); var networkType = await nodeHttp.GetNetworkType(); var action = actions[0]; var toAddressParts = action.To.Split(AddressSeparator); var toAddress = toAddressParts[0]; var memo = toAddressParts.Length > 1 ? toAddressParts[1] : ""; var message = !string.IsNullOrEmpty(memo) ? PlainMessage.Create(memo) as IMessage : EmptyMessage.Create(); var mosaic = Mosaic.CreateFromIdentifier(asset.AssetId, (ulong)asset.ToBaseUnit(action.Amount)); var fee = await TransferTransaction.CalculateFee(networkType, message, new[] { mosaic }, new NamespaceMosaicHttp(_nemUrl)); if (includeFee) { try { checked { if (mosaic.NamespaceName == Xem.NamespaceName && mosaic.MosaicName == Xem.MosaicName) { mosaic.Amount -= fee.fee; } // only single transfers are supported, // so there must be single levy var levy = fee.levies.SingleOrDefault(); if (levy != null && mosaic.NamespaceName == levy.NamespaceName && mosaic.MosaicName == levy.MosaicName) { mosaic.Amount -= levy.Amount; } } } catch (OverflowException) { throw new BlockchainException(BlockchainErrorCode.AmountIsTooSmall, "Amount is less than fee"); } } // check balances of FromAddress for all required assets var fromAddress = action.From.Split(AddressSeparator)[0]; var owned = await new AccountHttp(_nemUrl).MosaicsOwned(Address.CreateFromEncoded(fromAddress)); var required = fee.levies .Append(Xem.CreateAbsolute(fee.fee)) .Append(mosaic) .GroupBy(m => new { m.NamespaceName, m.MosaicName }) .Select(g => new Mosaic(g.Key.NamespaceName, g.Key.MosaicName, g.Aggregate(0UL, (v, m) => v += m.Amount))) .ToList(); foreach (var req in required) { var own = owned.FirstOrDefault(m => m.NamespaceName == req.NamespaceName && m.MosaicName == req.MosaicName)?.Amount ?? 0UL; if (own < req.Amount) { throw new BlockchainException(BlockchainErrorCode.NotEnoughBalance, $"Not enough {req.NamespaceName}:{req.MosaicName}"); } } var networkTime = (int)(await nodeHttp.GetExtendedNodeInfo()).NisInfo.CurrentTime; var tx = TransferTransaction.Create( networkType, new Deadline(networkTime + _expiresInSeconds), fee.fee, Address.CreateFromEncoded(toAddress), new List <Mosaic> { mosaic }, message, networkTime); return( tx.ToJson(), Convert.ToDecimal(fee.fee * 1e-6), tx.Deadline.GetInstant() ); }