private static AccountMetadataTransaction 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 valueSizeDelta = transaction["valueSizeDelta"].ToObject <short>(); var valueSize = transaction["valueSize"].ToObject <ushort>(); var value = transaction["value"].ToObject <string>(); var accountMetadataTransaction = new AccountMetadataTransaction(network, txVersion, type, deadline, maxFee, scopedMetadataKey, targetKey, value, valueSizeDelta, valueSize, signature, signer, txInfo); return(accountMetadataTransaction); }
public async Task Should_Add_Metadata_To_Account() { 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}"); // await Fixture.SiriusWebSocketClient.Listener.Open(); var metadatatrx = AccountMetadataTransaction.Create(Deadline.Create(), account.PublicAccount, "test", "test", "", Fixture.NetworkType); var aggregateTransaction = AggregateTransaction.CreateBonded( Deadline.Create(), new List <Transaction> { metadatatrx.ToAggregate(account.PublicAccount), }, Fixture.NetworkType); var aggregateTransactionsigned = account.Sign(aggregateTransaction, Fixture.GenerationHash); var hashLockTransaction = HashLockTransaction.Create( Deadline.Create(), //new Mosaic(new MosaicId("0BB1469B94E6FEF8"), 10), NetworkCurrencyMosaic.CreateRelative(10), (ulong)3650, aggregateTransactionsigned, 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}"); Thread.Sleep(4000); Log.WriteLine($"Going to announce aggregate transaction {aggregateTransactionsigned.Hash}"); await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBonded(aggregateTransactionsigned); Fixture.WatchForFailure(aggregateTransactionsigned); var aggregateTransactiontx = Fixture.SiriusWebSocketClient.Listener .ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(500)); //var aggregateTransactionConfirmed = await aggregateTransactiontx; //Log.WriteLine($" Request confirmed with aggregate transaction {aggregateTransactionConfirmed.TransactionInfo.Hash}"); }