private static MosaicProperties ExtractMosaicProperties(List <MosaicPropertyDTO> properties) { var flags = "00" + Convert.ToString((long)properties[0].Value.FromUInt8Array(), 2); var bitMapFlags = flags.Substring(flags.Length - 3, 3); return(MosaicProperties.Create(bitMapFlags.ToCharArray()[2] == '1', bitMapFlags.ToCharArray()[1] == '1', bitMapFlags.ToCharArray()[0] == '1', (int)properties[1].Value.FromUInt8Array(), properties.Count == 3 ? properties[2].Value.FromUInt8Array() : 0)); }
public async Task <MosaicId> CreateMosaic(Account account) { var nonce = MosaicNonce.CreateRandom(); var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey); var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( nonce, mosaicId, Deadline.Create(), MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 0, duration: 1000 ), NetworkType); var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicSupplyType.INCREASE, 1000000, NetworkType); var aggregateTransaction = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { mosaicDefinitionTransaction.ToAggregate(account.PublicAccount), mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount) }, NetworkType); var signedTransaction = account.Sign(aggregateTransaction, GenerationHash); WatchForFailure(signedTransaction); var tx = SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(3000)); await SiriusClient.TransactionHttp.Announce(signedTransaction); var result = await tx; return(mosaicId); }
public async Task Should_Add_Metadata_To_Mosaic() { var account = await Fixture.GenerateAccountWithCurrency(10000); Log.WriteLine($"Company Account {account.Address.Plain} \r\n Private Key: {account.PrivateKey} \r\n Public Key {account.PublicKey}"); var nonce = MosaicNonce.CreateRandom(); var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey); var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( nonce, mosaicId, Deadline.Create(), MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 6, duration: 0 ), Fixture.NetworkType); Log.WriteLine($"Going to create mosaic {mosaicDefinitionTransaction.MosaicId.HexId}"); var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicSupplyType.INCREASE, 1000, Fixture.NetworkType); var aggregateTransactiontx = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { mosaicDefinitionTransaction.ToAggregate(account.PublicAccount), mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount) }, Fixture.NetworkType); var aggregateTransactionsigned = account.Sign(aggregateTransactiontx, Fixture.GenerationHash); await Fixture.SiriusWebSocketClient.Listener.Open(); Log.WriteLine($"Going to announce aggregate transaction: {aggregateTransactionsigned.Hash}"); await Fixture.SiriusClient.TransactionHttp.Announce(aggregateTransactionsigned); var metadatatrx = MosaicMetadataTransaction.Create( Deadline.Create(), account.PublicAccount, mosaicDefinitionTransaction.MosaicId, "test_mosaic", "1", "", Fixture.NetworkType); var aggregateTransaction = AggregateTransaction.CreateBonded( Deadline.Create(), new List <Transaction> { metadatatrx.ToAggregate(account.PublicAccount), }, Fixture.NetworkType); var aggregateTrxsigned = account.Sign(aggregateTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(aggregateTransactionsigned); var hashLockTransaction = HashLockTransaction.Create( Deadline.Create(), //new Mosaic(new MosaicId("0BB1469B94E6FEF8"), 10), NetworkCurrencyMosaic.CreateRelative(10), (ulong)3650, aggregateTrxsigned, Fixture.NetworkType); var hashLockTransactionSigned = account.Sign(hashLockTransaction, Fixture.GenerationHash); Log.WriteLine($"Going to announce hashlock transaction: {hashLockTransactionSigned.Hash}"); await Fixture.SiriusClient.TransactionHttp.Announce(hashLockTransactionSigned); var hashLocktx = Fixture.SiriusWebSocketClient.Listener .ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(500)); Fixture.WatchForFailure(hashLockTransactionSigned); var hashLockConfirmed = await hashLocktx; Log.WriteLine($"Request confirmed with hash lock transaction {hashLockConfirmed.TransactionInfo.Hash}"); Log.WriteLine($"Going to announce aggregate transaction {aggregateTransactionsigned.Hash}"); await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBonded(aggregateTransactionsigned); Fixture.WatchForFailure(aggregateTransactionsigned); var aggregateTrntx = Fixture.SiriusWebSocketClient.Listener .ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(500)); var MosaicMetadataDetail = await Fixture.SiriusClient.MetadataHttp.SearchMetadata(new MetadataQueryParams(1, Order.ASC, 1, Address.CreateFromRawAddress(account.Address.ToString()), null, null, null)); Log.WriteLine($"Metadata mosaic {MosaicMetadataDetail}"); }
public async Task Should_Create_Mosaic_With_Builder() { var account = Fixture.SeedAccount; var nonce = MosaicNonce.CreateRandom(); var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey); var builder = new MosaicDefinitionTransactionBuilder(); builder.SetNonce(nonce) .SetMosaicId(mosaicId) .SetMosaicProperties(MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 0, duration: 1000 )) .SetDeadline(Deadline.Create()) .SetNetworkType(Fixture.NetworkType); /* * var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( * nonce, * mosaicId, * Deadline.Create(), * MosaicProperties.Create( * supplyMutable: true, * transferable: true, * levyMutable: false, * divisibility: 0, * duration: 1000 * ), * Fixture.NetworkType); */ var mosaicDefinitionTransaction = builder.Build(); Log.WriteLine($"Going to create mosaic {mosaicId}"); var supplyBuilder = new MosaicSupplyChangeTransactionBuilder(); supplyBuilder .SetDeadline(Deadline.Create()) .SetNetworkType(Fixture.NetworkType) .IncreaseSupplyFor(mosaicDefinitionTransaction.MosaicId) .SetDelta(1000000); var mosaicSupplyChangeTransaction = supplyBuilder.Build(); /* * var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( * Deadline.Create(), * mosaicDefinitionTransaction.MosaicId, * MosaicSupplyType.INCREASE, * 1000000, * Fixture.NetworkType); */ var aggregateTransaction = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { mosaicDefinitionTransaction.ToAggregate(account.PublicAccount), mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount) }, Fixture.NetworkType); var signedTransaction = account.Sign(aggregateTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(signedTransaction); Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}"); var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(3000)); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction); var result = await tx; Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}"); var mosaicInfo = await Fixture.SiriusClient.MosaicHttp.GetMosaic(mosaicDefinitionTransaction.MosaicId); Log.WriteLine($"Mosaic created {mosaicInfo}"); mosaicInfo.Should().NotBeNull(); mosaicInfo.Divisibility.Should().Be(0); mosaicInfo.Duration.Should().Be(1000); mosaicInfo.IsLevyMutable.Should().BeFalse(); mosaicInfo.IsSupplyMutable.Should().BeTrue(); mosaicInfo.IsTransferable.Should().BeTrue(); mosaicInfo.Supply.Should().Be(1000000); }
public async Task Should_Link_Namespace_To_Mosaic() { #region Create mosaic var account = await Fixture.GenerateAccountWithCurrency(1500); var nonce = MosaicNonce.CreateRandom(); var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( nonce, MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey), Deadline.Create(), MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 0, duration: 1000 ), Fixture.NetworkType); var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicSupplyType.INCREASE, 1000000, Fixture.NetworkType); var aggregateTransaction = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { mosaicDefinitionTransaction.ToAggregate(account.PublicAccount), mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount) }, Fixture.NetworkType); var signedTransaction = account.Sign(aggregateTransaction, Fixture.GenerationHash); Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}"); var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(3000)); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction); var result = await tx; Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}"); var mosaicInfo = await Fixture.SiriusClient.MosaicHttp.GetMosaic(mosaicDefinitionTransaction.MosaicId); mosaicInfo.Should().NotBeNull(); mosaicInfo.Divisibility.Should().Be(0); mosaicInfo.Duration.Should().Be(1000); mosaicInfo.IsLevyMutable.Should().BeFalse(); mosaicInfo.IsSupplyMutable.Should().BeTrue(); mosaicInfo.IsTransferable.Should().BeTrue(); mosaicInfo.Supply.Should().Be(1000000); #endregion #region register new namespace var namespaceName = "nsp" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6); var registerNamespaceTransaction = RegisterNamespaceTransaction.CreateRootNamespace( Deadline.Create(), namespaceName, 100, Fixture.NetworkType ); var registeredNsSignedTransaction = account.Sign(registerNamespaceTransaction, Fixture.GenerationHash); tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(3000)); await Fixture.SiriusClient.TransactionHttp.Announce(registeredNsSignedTransaction); Log.WriteLine( $"Registered namespace {namespaceName} for account {account.Address.Plain} with transaction {registeredNsSignedTransaction.Hash}"); result = await tx; Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}"); var expectedId = new NamespaceId(namespaceName); var nsInfo = await Fixture.SiriusClient.NamespaceHttp.GetNamespace(expectedId); Log.WriteLine( $"Retrieved namespace {namespaceName} successfully. The namespace HexId {nsInfo.Id.HexId}"); nsInfo.Should().NotBeNull(); #endregion #region Link namespace to the mosaic var mosaicAliasTransaction = AliasTransaction.CreateForMosaic( mosaicInfo.MosaicId, nsInfo.Id, AliasActionType.LINK, Deadline.Create(), Fixture.NetworkType ); tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1); var aliasSignedTransaction = account.Sign(mosaicAliasTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(aliasSignedTransaction); await Fixture.SiriusClient.TransactionHttp.Announce(aliasSignedTransaction); result = await tx; Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}"); nsInfo = await Fixture.SiriusClient.NamespaceHttp.GetNamespace(expectedId); nsInfo.Should().NotBeNull(); nsInfo.HasAlias.Should().BeTrue(); nsInfo.Alias.Type.Should().BeEquivalentTo(AliasType.MOSAIC_ID); nsInfo.Alias.MosaicId.HexId.Should().BeEquivalentTo(mosaicInfo.MosaicId.HexId); #endregion #region Send mosaic using namespace alias to recipient var newAccount = Account.GenerateNewAccount(Fixture.NetworkType); var transferTransaction = TransferTransaction.Create( Deadline.Create(), Recipient.From(newAccount.Address), new List <Mosaic>() { new Mosaic(nsInfo.Id, 10) }, PlainMessage.Create("Send some mosaic to new address"), Fixture.NetworkType); var tx2 = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(newAccount.Address).Take(1) .Timeout(TimeSpan.FromSeconds(3000)); var nsSignedTransferTransaction = account.Sign(transferTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(nsSignedTransferTransaction); await Fixture.SiriusClient.TransactionHttp.Announce(nsSignedTransferTransaction); var result2 = await tx2; Log.WriteLine($"Request confirmed with transaction {result2.TransactionInfo.Hash}"); var newAccountInfo = await Fixture.SiriusClient.AccountHttp.GetAccountInfo(newAccount.Address); Log.WriteLine($"Account {newAccountInfo.Address.Plain} with mosaic {newAccountInfo.Mosaics[0]} after transfer to the namespace alias"); var expectedMosaicAmount = Convert.ToUInt64(10); newAccountInfo.Mosaics[0].Id.Id.Should().Be(mosaicInfo.MosaicId.Id); newAccountInfo.Mosaics[0]?.Amount.Should().Be(expectedMosaicAmount); #endregion }
public async Task Should_Increase_Mosaic_Supply() { var account = Fixture.SeedAccount; var nonce = MosaicNonce.CreateRandom(); var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey); var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( nonce, mosaicId, Deadline.Create(), MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 3, duration: 1000 ), Fixture.NetworkType); Log.WriteLine($"Going to create mosaic {mosaicId}"); var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicSupplyType.INCREASE, 1000000, Fixture.NetworkType); var aggregateTransaction = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { mosaicDefinitionTransaction.ToAggregate(account.PublicAccount), mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount) }, Fixture.NetworkType); var signedTransaction = account.Sign(aggregateTransaction, Fixture.GenerationHash); Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}"); var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(3000)); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction); var result = await tx; Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}"); var mosaicDecreaseSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicSupplyType.INCREASE, 500000, Fixture.NetworkType); const ulong expectedAmount = 1000000 + 500000; var signedDecreaseTransaction = account.Sign(mosaicDecreaseSupplyChangeTransaction, Fixture.GenerationHash); await Fixture.SiriusClient.TransactionHttp.Announce(signedDecreaseTransaction); var result2 = await tx; Log.WriteLine($"Request confirmed with transaction {result2.TransactionInfo.Hash}"); var mosaicInfo = await Fixture.SiriusClient.MosaicHttp.GetMosaic(mosaicDefinitionTransaction.MosaicId); mosaicInfo.Should().NotBeNull(); mosaicInfo.Divisibility.Should().Be(3); mosaicInfo.Duration.Should().Be(1000); mosaicInfo.IsLevyMutable.Should().BeFalse(); mosaicInfo.IsSupplyMutable.Should().BeTrue(); mosaicInfo.IsTransferable.Should().BeTrue(); mosaicInfo.Supply.Should().Be(expectedAmount); }
public async Task Should_Remove_Metadata_From_Mosaic() { var account = Fixture.SeedAccount; await Fixture.SiriusWebSocketClient.Listener.Open(); var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1).Timeout(TimeSpan.FromSeconds(500)); var nonce = MosaicNonce.CreateRandom(); var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey); Log.WriteLine($"Going to generate mosaicId {mosaicId}"); var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( nonce, mosaicId, Deadline.Create(), MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 0, duration: 1000 ), Fixture.NetworkType); var signedTransaction = account.Sign(mosaicDefinitionTransaction, Fixture.GenerationHash); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction); var result = await tx; Log.WriteLine($"Request create mosaic confirmed with transaction {result.TransactionInfo.Hash}"); var modifications = new List <MetadataModification> { MetadataModification.Add("company", "ProximaX"), MetadataModification.Add("department", "IT") }; var modifyMetadataTransaction = ModifyMetadataTransaction.CreateForMosaic( Deadline.Create(), mosaicId, modifications, Fixture.NetworkType); signedTransaction = account.Sign(modifyMetadataTransaction, Fixture.GenerationHash); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction); result = await tx; Log.WriteLine($"Request add metadata to mosaic confirmed with transaction {result.TransactionInfo.Hash}"); modifications = new List <MetadataModification> { MetadataModification.Remove("department") }; modifyMetadataTransaction = ModifyMetadataTransaction.CreateForMosaic( Deadline.Create(), mosaicId, modifications, Fixture.NetworkType); signedTransaction = account.Sign(modifyMetadataTransaction, Fixture.GenerationHash); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction); result = await tx; Log.WriteLine($"Request remove metadata from mosaic confirmed with transaction {result.TransactionInfo.Hash}"); var metaInfo = await Fixture.SiriusClient.MetadataHttp.GetMetadataFromMosaic(mosaicId); metaInfo.Fields.Should().HaveCount(1); metaInfo.Type.Should().BeEquivalentTo(MetadataType.MOSAIC); }
public async Task Should_Create_Levy_WithPercentageFee() { var account = Fixture.SeedAccount; var nonce = MosaicNonce.CreateRandom(); var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey); var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( nonce, mosaicId, Deadline.Create(), MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 0, duration: 0 ), Fixture.NetworkType); Log.WriteLine($"Going to create mosaic {mosaicDefinitionTransaction.MosaicId.HexId}"); Log.WriteLine($"{account.PublicAccount.PublicKey}"); Log.WriteLine($"{account.PublicAccount.Address}"); var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicSupplyType.INCREASE, 1000000, Fixture.NetworkType); var aggregateTransaction = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { mosaicDefinitionTransaction.ToAggregate(account.PublicAccount), mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount) }, Fixture.NetworkType); var signedTransaction = account.Sign(aggregateTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(signedTransaction); Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}"); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction); var recipient = Account.GenerateNewAccount(Fixture.NetworkType); var mosaic_Id = new MosaicId(mosaicId.HexId); Log.WriteLine($"Mosaic Id: {mosaic_Id.HexId}"); var mosaicLevy = ModifyMosaicLevyTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicLevy.CreateWithPercentageFee( Recipient.From(recipient.Address), mosaicDefinitionTransaction.MosaicId, 200), Fixture.NetworkType); var signedTransaction_mosaicLevy = account.Sign(mosaicLevy, Fixture.GenerationHash); Fixture.WatchForFailure(signedTransaction_mosaicLevy); var tx_Levy = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1).Timeout(TimeSpan.FromSeconds(3000)); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction_mosaicLevy); var result_levy = await tx_Levy; Log.WriteLine($"Request confirmed with transaction {result_levy.TransactionInfo.Hash}"); }