private static NamespaceMetadataTransaction ToMetadataTransaction(JObject tx, TransactionInfo txInfo) { var transaction = tx["transaction"].ToObject <JObject>(); var version = transaction["version"]; //Bug - It seems the dotnetcore does not //understand the Integer. //The workaround it to double cast the version int versionValue; try { versionValue = (int)((uint)version); } catch (Exception) { versionValue = (int)version; } var network = TransactionMappingUtils.ExtractNetworkType(versionValue); var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue); var deadline = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64()); var maxFee = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64(); var signature = transaction["signature"].ToObject <string>(); var signer = new PublicAccount(transaction["signer"].ToObject <string>(), network); var type = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>()); var scopedMetadataKey = transaction["scopedMetadataKey"].ToObject <UInt64DTO>().ToUInt64(); var targetKey = new PublicAccount(transaction["targetKey"].ToObject <string>(), network); var targetId = new NamespaceId(transaction["targetNamespaceId"].ToObject <UInt64DTO>().ToUInt64()); var valueSizeDelta = transaction["valueSizeDelta"].ToObject <short>(); var valueSize = transaction["valueSize"].ToObject <ushort>(); var value = transaction["value"].ToObject <string>(); var namespaceMetadataTransaction = new NamespaceMetadataTransaction(network, txVersion, type, deadline, maxFee, scopedMetadataKey, targetKey, targetId, value, valueSizeDelta, valueSize, signature, signer, txInfo); return(namespaceMetadataTransaction); }
public async Task Should_Add_Metadata_To_Namespace() { 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 rootNs = "namespace_metadata_test"; var rootId = new NamespaceId(rootNs); var registerRootTransaction = RegisterNamespaceTransaction.CreateRootNamespace( Deadline.Create(), rootNs, 3650, Fixture.NetworkType); var aggregateTransactiontx = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { registerRootTransaction.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 aggregateTransactiontxs = Fixture.SiriusWebSocketClient.Listener * .ConfirmedTransactionsGiven(account.Address).Take(1) * .Timeout(TimeSpan.FromSeconds(500)); * * var aggregateTransactionConfirmed = await aggregateTransactiontxs; * Log.WriteLine($" Request confirmed with aggregate transaction {aggregateTransactionConfirmed.TransactionInfo.Hash}");*/ var metadatatrx = NamespaceMetadataTransaction.Create( Deadline.Create(), account.PublicAccount, rootId, "test_Namespace", "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(aggregateTrxsigned); /* Log.WriteLine($" {aggregateTransactionConfirmed.TransactionType}Request confirmed with aggregate transaction {aggregateTransactionConfirmed.TransactionInfo.Hash}");*/ 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 {aggregateTrxsigned.Hash}"); await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBonded(aggregateTrxsigned); Fixture.WatchForFailure(aggregateTrxsigned); var aggregateTrntx = Fixture.SiriusWebSocketClient.Listener .ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(500)); var aggregateTrxConfirmed = await aggregateTrntx; Log.WriteLine($"Request confirmed with aggregate transaction {aggregateTrxConfirmed.TransactionInfo.Hash}"); }