public static async Task getResponse() { try { Account account = Account.CreateFromPrivateKey("5cd5a454be8045056bd3c5e67c20dea92a8eb4921351d850f0249983a804a903", NetworkType.Types.TEST_NET); KeyPair keyPair = account.KeyPair; var transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), Address.CreateFromEncoded("TB2Z7J-R2K3BZ-2TRS6D-H5747F-Y3XKUM-BNWCI4-BPDJ"), new List <Mosaic> { Xem.CreateRelative(10) }, PlainMessage.Create("Well shit. W/ mosaic") ); SignedTransaction signedTransaction = transaction.SignWith(keyPair); TransactionResponse response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(signedTransaction); Console.WriteLine(response.Message); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } }
public static async Task getResponse() { try { Account sender = Account.CreateFromPrivateKey("5cd5a454be8045056bd3c5e67c20dea92a8eb4921351d850f0249983a804a903", NetworkType.Types.TEST_NET); KeyPair keyPair1 = sender.KeyPair; Account reciever = Account.CreateFromPrivateKey("5cd5a454be8045056bd3c5e67c20dea92a8eb4921351d850f0249983a804a903", NetworkType.Types.TEST_NET); KeyPair keyPair2 = reciever.KeyPair; var transaction = TransferTransaction.Create( NetworkType.Types.TEST_NET, Deadline.CreateHours(2), Address.CreateFromEncoded("TB2Z7J-R2K3BZ-2TRS6D-H5747F-Y3XKUM-BNWCI4-BPDJ"), new List <Mosaic> { Xem.CreateRelative(1) }, SecureMessage.Create("Well shit. W/ mosaic", sender.PrivateKey, reciever.PublicKey) ); SignedTransaction signedTransaction = transaction.SignWith(keyPair1); TransactionResponse response = await new TransactionHttp(host).Announce(signedTransaction); Console.WriteLine(response.Message); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } }
public void ShouldCreateAbsoluteXEM() { var xem = Xem.CreateAbsolute(1); Assert.AreEqual((ulong)1, xem.Amount); Assert.AreEqual(Xem.Id.HexId, xem.MosaicId.HexId); }
public void ShouldCreateRelativeXEM() { var xem = Xem.CreateRelative(1); Assert.AreEqual((ulong)1000000, xem.Amount); Assert.AreEqual(Xem.Id.HexId, xem.MosaicId.HexId); }
public void ShouldCreateXEMViaConstructor() { var xem = new Xem(0); Assert.AreEqual((ulong)0, xem.Amount); Assert.AreEqual(Xem.Id.HexId, xem.MosaicId.HexId); }
public void ShouldCreateAccountInfoFromConstructor() { var mosaics = new List <Mosaic> { Xem.CreateRelative(10) }; var accountInfo = new AccountInfo( Address.CreateFromEncoded("SDGLFWDSHILTIUHGIBH5UGX2VYF5VNJEKCCDBR26"), 966, "cf893ffcc47c33e7f68ab1db56365c156b0736824a0c1e273f9e00b8df8f01eb", 964, 0, 0, mosaics ); Assert.AreEqual(Address.CreateFromEncoded("SDGLFWDSHILTIUHGIBH5UGX2VYF5VNJEKCCDBR26").Plain, accountInfo.Address.Plain); Assert.AreEqual((ulong)966, accountInfo.AddressHeight); Assert.AreEqual("cf893ffcc47c33e7f68ab1db56365c156b0736824a0c1e273f9e00b8df8f01eb", accountInfo.PublicKey); Assert.AreEqual((ulong)964, accountInfo.PublicKeyHeight); Assert.AreEqual((ulong)0, accountInfo.Importance); Assert.AreEqual((ulong)0, accountInfo.ImportanceHeight); Assert.AreEqual(mosaics, accountInfo.Mosaics); }
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() ); }
public void ShouldCreateAbsoluteXEM() { var xem = Xem.CreateAbsolute(1); Assert.AreEqual((ulong)1, xem.Amount); }