public async Task Should_Serialize_And_Sign_TransactionAsync()
        {
            var account2 = Account.CreateFromPrivateKey("D54AC0CB0FF50FB44233782B3A6B5FDE2F1C83B9AE2F1352119F93713F3AB923", NetworkType.TEST_NET);
            // var nonce = MosaicNonce.CreateRandom();
            var account = Account.CreateFromPrivateKey("feab2970d23c9a6f0170adf9b846575831c63084bcf1f0d7e70644818c546017", NetworkType.TEST_NET);
            // var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey);
            var mosaicToTransfer = NetworkCurrencyMosaic.CreateRelative(1000);

            var transferTransaction = TransferTransaction.Create(Deadline.Create(),
                                                                 Recipient.From(Address.CreateFromRawAddress("VDVLDGVUEZ2X2CB5AZLOVHV6UK4DPCQHHWHCV75T")),
                                                                 new List <Mosaic>()
            {
                mosaicToTransfer
            },
                                                                 PlainMessage.Create("test-message"),
                                                                 NetworkType.TEST_NET
                                                                 );

            var generationHash = "B750FC8ADD9FAB8C71F0BB90B6409C66946844F07C5CADB51F27A9FAF219BFC7";

            var signedTransaction = account.Sign(transferTransaction, generationHash);

            //var payload = signedTransaction.Payload;

            signedTransaction.Payload.Should().NotBeNullOrEmpty();
            signedTransaction.Hash.Should().NotBeNullOrEmpty();
        }
        public static async System.Threading.Tasks.Task CreateTransactionAsync(int xpxAmount, List <Account> recipients)
        {
            foreach (var recipient in recipients)
            {
                var client              = new SiriusClient("http://bctestnet1.brimstone.xpxsirius.io:3000");
                var networkType         = client.NetworkHttp.GetNetworkType().Wait();
                var mosaicToTransfer    = NetworkCurrencyMosaic.CreateRelative((ulong)xpxAmount);
                var transferTransaction = TransferTransaction.Create(
                    Deadline.Create(),
                    recipient.Address,
                    new List <Mosaic>()
                {
                    mosaicToTransfer
                },
                    PlainMessage.Create("Transfered " + xpxAmount.ToString() + " successfully."),
                    NetworkType.TEST_NET
                    );


                var generationHash = await client.BlockHttp.GetGenerationHash();

                var signedTransaction = senderAccount.Sign(transferTransaction, generationHash);
                await client.TransactionHttp.Announce(signedTransaction);

                var newAccountInfo = await client.AccountHttp.GetAccountInfo(senderAccount.Address);

                Console.WriteLine("Sent " + Convert.ToInt32(xpxAmount) + " XPX to: \n");
                Console.WriteLine($"{nameof(newAccountInfo)} : {newAccountInfo}");
            }
        }
        public async Task <Account> GenerateAccountWithCurrency(ulong amount)
        {
            var account = Account.GenerateNewAccount(NetworkType);
            var mosaic  = NetworkCurrencyMosaic.CreateRelative(amount);
            var message = PlainMessage.Create("Send some money");
            var tx      = await Transfer(SeedAccount, account.Address, mosaic, message, GenerationHash);

            return(account);
        }
        public async Task <Account> GenerateAccountAndSendSomeMoney(int amount)
        {
            var networkType = Client.NetworkHttp.GetNetworkType().Wait();
            var account     = Account.GenerateNewAccount(networkType);

            var money = (ulong)amount;

            var mosaicToTransfer = NetworkCurrencyMosaic.CreateRelative(money);

            var transferTransaction = TransferTransaction.Create(
                Deadline.Create(),
                account.Address,
                new List <Mosaic>()
            {
                // mosaicToTransfer
            },
                PlainMessage.Create("transferTest"),
                networkType);

            var signedTransaction = SeedAccount.Sign(transferTransaction, Environment.GenerationHash);

            WatchForFailure(signedTransaction);
            try
            {
                await WebSocket.Listener.Open();

                var tx = WebSocket.Listener.ConfirmedTransactionsGiven(account.Address).Take(1).Timeout(TimeSpan.FromSeconds(100));


                await Client.TransactionHttp.Announce(signedTransaction);

                var result = await tx;

                if (result.IsConfirmed())
                {
                    return(account);
                }
                else
                {
                    throw new Exception($"Unable to send money to account {account.Address.Plain}");
                }
            }
            finally
            {
                try
                {
                    // WebSocket.Listener.Close();
                }
                catch (Exception)
                {
                    //do nothing
                }
            }
        }
        public async Task Should_Announce_Transfer_Transaction_With_NetworkCurrencyMosaic_PlainMessage()
        {
            var account = Account.GenerateNewAccount(Fixture.NetworkType);
            var mosaic  = NetworkCurrencyMosaic.CreateRelative(10);
            var message = PlainMessage.Create("Test message");
            var result  = await Fixture.Transfer(Fixture.SeedAccount, account.Address, mosaic, message, Fixture.GenerationHash);

            Log.WriteLine($"Transaction confirmed {result.TransactionInfo.Hash}");
            result.TransactionInfo.Hash.Should().NotBeNullOrWhiteSpace();
            //result.TransactionType.Should().Be(EntityType.TRANSFER);
            ((TransferTransaction)result).Message.GetMessageType().Should().Be(MessageType.PLAIN_MESSAGE.GetValueInByte());
        }
        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}");
        }
        public async Task Should_Send_Some_Money_To_New_Account()
        {
            var aliceAccount = await Fixture.GenerateAccountWithCurrency(500);



            var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(aliceAccount.Address).Take(1);

            Log.WriteLine($"Alice Account {aliceAccount.Address.Plain} \r\n Private Key: {aliceAccount.PrivateKey} \r\n Public Key {aliceAccount.PublicKey}");

            const ulong amount           = (ulong)10;
            var         mosaicToTransfer = NetworkCurrencyMosaic.CreateRelative(amount);

            var transferTransaction = TransferTransaction.Create(
                Deadline.Create(),
                aliceAccount.Address,
                new List <Mosaic>()
            {
                mosaicToTransfer
            },
                PlainMessage.Create("transferTest"),
                Fixture.NetworkType);

            var signedTransaction = Fixture.SeedAccount.Sign(transferTransaction, Fixture.GenerationHash);

            Log.WriteLine($"Going to send {amount} XPP to {aliceAccount.Address.Pretty} with transaction {signedTransaction.Hash}");
            Fixture.WatchForFailure(signedTransaction);
            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);

            var result = await tx;

            Log.WriteLine($"Request confirmed with public key {result.Signer.PublicKey}");

            var aliceAccountInfo = await Fixture.SiriusClient.AccountHttp.GetAccountInfo(aliceAccount.Address);

            aliceAccountInfo.Mosaics[0]?.Amount.Should().BeGreaterThan(0);

            var outgoingTxs = Fixture.SiriusClient.AccountHttp.OutgoingTransactions(aliceAccountInfo.PublicAccount).Wait();

            var recipientAddress = "VDG4WG-FS7EQJ-KFQKXM-4IUCQG-PXUW5H-DJVIJB-OXJG";
            var address          = Address.CreateFromRawAddress(recipientAddress);

            var mosaicAmounts = (from TransferTransaction t in outgoingTxs
                                 where t.TransactionType == EntityType.TRANSFER &&
                                 t.Recipient.Address.Plain == address.Plain &&
                                 t.Mosaics.Count == 1 &&
                                 t.Mosaics[0].HexId == NetworkCurrencyMosaic.Id.HexId
                                 select(long) t.Mosaics[0].Amount).ToList();

            Console.WriteLine($"Total xpx send to account {address.Plain} is {mosaicAmounts.Sum()}");
        }
Пример #8
0
        public void Should_Serialize_And_Sign_LockFundTransaction()
        {
            var account         = Account.CreateFromPrivateKey("26b64cb10f005e5988a36744ca19e20d835ccc7c105aaa5f3b212da593180930", NetworkType.MIJIN_TEST);
            var generationHash  = "B750FC8ADD9FAB8C71F0BB90B6409C66946844F07C5CADB51F27A9FAF219BFC7";
            var network         = NetworkType.MIJIN_TEST;
            var multiSigAccount = Account.GenerateNewAccount(network);
            var coginatory1     = Account.GenerateNewAccount(network);
            var coginatory2     = Account.GenerateNewAccount(network);

            var coginatories = new List <MultisigCosignatoryModification>
            {
                new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
                                                    coginatory1.PublicAccount),
                new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
                                                    coginatory2.PublicAccount),
            };

            var convertIntoMultisigTransaction = ModifyMultisigAccountTransaction.Create(
                Deadline.Create(),
                1,
                1,
                coginatories,
                network);

            var aggregateTransaction = AggregateTransaction.CreateBonded(
                Deadline.Create(),
                new List <Transaction>
            {
                convertIntoMultisigTransaction.ToAggregate(multiSigAccount.PublicAccount)
            },
                network);


            var signedTransaction = multiSigAccount.Sign(aggregateTransaction, generationHash);

            var builder = new LockFundsTransactionBuilder();

            builder.SetDeadline(Deadline.Create())
            .SetDuration((ulong)700)
            .SetMosaic(NetworkCurrencyMosaic.CreateRelative(10))
            .SetSignedTransaction(signedTransaction)
            .SetNetworkType(network);

            var hashLockTransaction = builder.Build();

            var hashLockTransactionSigned = multiSigAccount.Sign(hashLockTransaction, generationHash);

            hashLockTransactionSigned.Payload.Should().NotBeNullOrEmpty();
            hashLockTransactionSigned.Hash.Should().NotBeNullOrEmpty();
        }
        public void Should_Serialize_And_Sign_LockFundTransaction()
        {
            var account         = Account.CreateFromPrivateKey("26b64cb10f005e5988a36744ca19e20d835ccc7c105aaa5f3b212da593180930", NetworkType.TEST_NET);
            var generationHash  = "AC87FDA8FD94B72F3D0790A7D62F248111BD5E37B95B16E4216DA99C212530A5";
            var network         = NetworkType.TEST_NET;
            var multiSigAccount = Account.GenerateNewAccount(network);
            var coginatory1     = Account.GenerateNewAccount(network);
            var coginatory2     = Account.GenerateNewAccount(network);

            var coginatories = new List <MultisigCosignatoryModification>
            {
                new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
                                                    coginatory1.PublicAccount),
                new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
                                                    coginatory2.PublicAccount),
            };

            var convertIntoMultisigTransaction = ModifyMultisigAccountTransaction.Create(
                Deadline.Create(),
                1,
                1,
                coginatories,
                network);

            var aggregateTransaction = AggregateTransaction.CreateBonded(
                Deadline.Create(),
                new List <Transaction>
            {
                convertIntoMultisigTransaction.ToAggregate(multiSigAccount.PublicAccount)
            },
                network);

            var signedTransaction = multiSigAccount.Sign(aggregateTransaction, generationHash);

            var builder = new LockFundsTransactionBuilder();

            builder.SetDeadline(Deadline.Create())
            .SetDuration((ulong)700)
            .SetMosaic(NetworkCurrencyMosaic.CreateRelative(10))
            .SetSignedTransaction(signedTransaction)
            .SetNetworkType(network);

            var hashLockTransaction = builder.Build();

            var hashLockTransactionSigned = multiSigAccount.Sign(hashLockTransaction, generationHash);

            hashLockTransactionSigned.Payload.Should().NotBeNullOrEmpty();
            hashLockTransactionSigned.Hash.Should().NotBeNullOrEmpty();
        }
        public async Task Should_Announce_Transfer_Transaction_With_NetworkCurrencyMosaic_SecureMessage()
        {
            var account = Account.GenerateNewAccount(Fixture.NetworkType);

            Log.WriteLine($"Reciever private key {account.KeyPair.PrivateKeyString}, reciever public key {account.PublicAccount.PublicKey}");
            var mosaic = NetworkCurrencyMosaic.CreateRelative(10);

            Log.WriteLine($"Sender private key {Fixture.SeedAccount.KeyPair.PrivateKeyString}, sender public key {Fixture.SeedAccount.PublicAccount.PublicKey}");
            var message = SecureMessage.Create("Test secure message", Fixture.SeedAccount.KeyPair.PrivateKeyString, account.PublicAccount.PublicKey);
            var result  = await Fixture.Transfer(Fixture.SeedAccount, account.Address, mosaic, message, Fixture.GenerationHash);

            Log.WriteLine($"Transaction confirmed {result.TransactionInfo.Hash}");
            result.TransactionInfo.Hash.Should().NotBeNullOrWhiteSpace();
            //result.TransactionType.Should().Be(EntityType.TRANSFER);
            ((TransferTransaction)result).Message.GetMessageType().Should().Be(MessageType.SECURED_MESSAGE.GetValueInByte());
        }
        public async Task Should_Send_Some_Money_To_New_Account()
        {
            // var aliceAccount = await Fixture.GenerateAccountWithCurrency(100000);

            var aliceAccount = Account.CreateFromPrivateKey("101a4dfcffe3d5abddee535c0c7fa7bb386b99eb7c19f0c73cdc3837c5844477", Fixture.NetworkType);

            var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(aliceAccount.Address).Take(1);

            Log.WriteLine($"Alice Account {aliceAccount.Address.Plain} \r\n Private Key: {aliceAccount.PrivateKey} \r\n Public Key {aliceAccount.PublicKey}");

            const ulong amount           = (ulong)1000;
            var         mosaicToTransfer = NetworkCurrencyMosaic.CreateRelative(amount);

            var transferTransaction = TransferTransaction.Create(
                Deadline.Create(),
                aliceAccount.Address,
                new List <Mosaic>()
            {
                mosaicToTransfer
            },
                PlainMessage.Create("transferTest"),
                Fixture.NetworkType);

            var signedTransaction = Fixture.SeedAccount.Sign(transferTransaction, Fixture.GenerationHash);

            Log.WriteLine($"Going to send {amount} XPP to {aliceAccount.Address.Pretty} with transaction {signedTransaction.Hash}");
            Fixture.WatchForFailure(signedTransaction);

            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);

            var result = await tx;

            Log.WriteLine($"Request confirmed with public key {result.Signer.PublicKey}");

            var aliceAccountInfo = await Fixture.SiriusClient.AccountHttp.GetAccountInfo(aliceAccount.Address);

            Log.WriteLine($"Alice Account Info: {aliceAccountInfo.Mosaics[0]}");

            aliceAccountInfo.Mosaics[0]?.Amount.Should().BeGreaterThan(0);

            var outgoingTxs = Fixture.SiriusClient.AccountHttp.OutgoingTransactions(PublicAccount.CreateFromPublicKey(result.Signer.PublicKey, Fixture.NetworkType)).Wait();

            outgoingTxs.Transactions.Count().Should().BeGreaterThan(0);
            Log.WriteLine($"Complete");
        }
Пример #12
0
        private TransferTransaction CreateTransaction(Address recipientAddress, int transactionDeadline,
                                                      List <Mosaic> transactionMosaics, IMessage message)
        {
            var mosaics = (transactionMosaics == null || transactionMosaics.Count <= 0) ? new List <Mosaic> {
                NetworkCurrencyMosaic.CreateRelative(0)
            } : transactionMosaics;

            var recipient = Recipient.From(recipientAddress);

            var builder = new TransferTransactionBuilder();

            var transferTransaction = builder
                                      .SetNetworkType(BlockchainNetworkConnection.NetworkType)
                                      .SetDeadline(Deadline.Create(transactionDeadline))
                                      .SetMosaics(mosaics)
                                      .SetRecipient(recipient)
                                      .SetMessage(message)
                                      .SetFeeCalculationStrategy(BlockchainNetworkConnection.FeeCalculationStrategy)
                                      .Build();

            return(transferTransaction);
        }
        public async Task Should_Announce_Transfer_Transaction_With_Default_Fee()
        {
            var account = Account.GenerateNewAccount(Fixture.NetworkType);
            var mosaic  = NetworkCurrencyMosaic.CreateRelative(10);
            var message = PlainMessage.Create("Test message");

            var builder = new TransferTransactionBuilder();

            var transferTransaction = builder
                                      .SetNetworkType(Fixture.NetworkType)
                                      .SetDeadline(Deadline.Create())
                                      .SetMosaics(new List <Mosaic>()
            {
                mosaic
            })
                                      .SetRecipient(Recipient.From(account.Address))
                                      .SetMessage(message)
                                      .SetFeeCalculationStrategy(FeeCalculationStrategyType.LOW)
                                      .Build();


            var signedTransaction = Fixture.SeedAccount.Sign(transferTransaction, Fixture.GenerationHash);

            Fixture.WatchForFailure(signedTransaction);

            //Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}");

            var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(Fixture.SeedAccount.Address).Take(1);

            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);

            var result = await tx;

            Log.WriteLine($"Transaction confirmed {result.TransactionInfo.Hash}");
            result.TransactionInfo.Hash.Should().NotBeNullOrWhiteSpace();
            //result.TransactionType.Should().Be(EntityType.TRANSFER);
            ((TransferTransaction)result).Message.GetMessageType().Should().Be(MessageType.PLAIN_MESSAGE.GetValueInByte());
        }
        public async Task Should_Link_Namespace_To_An_Account()
        {
            var company = Account.GenerateNewAccount(Fixture.NetworkType);

            await Fixture.SiriusWebSocketClient.Listener.Open();

            var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(company.Address).Take(1);

            #region Create account and send some money to it

            Log.WriteLine($"Alice Account {company.Address.Plain} \r\n Private Key: {company.PrivateKey} \r\n Public Key {company.PublicKey}");

            const ulong amount           = (ulong)150;
            var         mosaicToTransfer = NetworkCurrencyMosaic.CreateRelative(amount);

            var transferTransaction = TransferTransaction.Create(
                Deadline.Create(),
                company.Address,
                new List <Mosaic>()
            {
                mosaicToTransfer
            },
                PlainMessage.Create("transferTest"),
                Fixture.NetworkType);

            var signedTransaction = Fixture.SeedAccount.Sign(transferTransaction, Fixture.GenerationHash);
            Log.WriteLine($"Going to send {amount} XPP to {company.Address.Pretty} with transaction {signedTransaction.Hash}");

            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);

            var result = await tx;

            Log.WriteLine($"Request confirmed with public key {result.Signer.PublicKey}");

            var companyAccountInfo = await Fixture.SiriusClient.AccountHttp.GetAccountInfo(company.Address);

            Log.WriteLine($"Account {companyAccountInfo.Address.Plain} with initial mosaic {companyAccountInfo.Mosaics[0]}");

            companyAccountInfo.Mosaics[0]?.Amount.Should().BeGreaterThan(0);

            #endregion Create account and send some money to it

            #region register new namespace

            var namespaceName = "nsp" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6);
            var registerNamespaceTransaction = RegisterNamespaceTransaction.CreateRootNamespace(
                Deadline.Create(),
                namespaceName,
                10000,
                Fixture.NetworkType
                );

            var registeredNsSignedTransaction = company.Sign(registerNamespaceTransaction, Fixture.GenerationHash);

            tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(company.Address).Take(1)
                 .Timeout(TimeSpan.FromSeconds(3000));

            await Fixture.SiriusClient.TransactionHttp.Announce(registeredNsSignedTransaction);

            Log.WriteLine(
                $"Registered namespace {namespaceName} for account {company.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();

            companyAccountInfo = await Fixture.SiriusClient.AccountHttp.GetAccountInfo(company.Address);

            Log.WriteLine($"Account {companyAccountInfo.Address.Plain} with mosaic {companyAccountInfo.Mosaics[0]} after registered namespace");

            #endregion register new namespace

            #region Link namespace to the address

            /*var addressAliasTransaction = AliasTransaction.CreateForAddress(
             *  company.Address,
             *  nsInfo.Id,
             *  AliasActionType.LINK,
             *  Deadline.Create(),
             *  Fixture.NetworkType
             * );*/

            var builder = AliasTransactionBuilder.CreateForAddress();
            var addressAliasTransaction = builder
                                          .SetNamespaceId(nsInfo.Id)
                                          .SetDeadline(Deadline.Create())
                                          .SetNetworkType(Fixture.NetworkType)
                                          .SetFeeCalculationStrategy(FeeCalculationStrategyType.LOW)
                                          .Link(company.Address)
                                          .Build();

            tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(company.Address).Take(1);

            var aliasSignedTransaction = company.Sign(addressAliasTransaction, Fixture.GenerationHash);

            Fixture.WatchForFailure(aliasSignedTransaction);

            await Fixture.SiriusClient.TransactionHttp.Announce(aliasSignedTransaction);

            result = await tx;

            Log.WriteLine($"Request confirmed with aliasSignedTransaction transaction {aliasSignedTransaction.Hash}");

            nsInfo = await Fixture.SiriusClient.NamespaceHttp.GetNamespace(expectedId);

            nsInfo.Should().NotBeNull();
            nsInfo.HasAlias.Should().BeTrue();
            nsInfo.Alias.Address.Plain.Should().BeEquivalentTo(company.Address.Plain);

            #endregion Link namespace to the address

            #region Send mosaic to namespace instead of address

            transferTransaction = TransferTransaction.Create(
                Deadline.Create(),
                nsInfo.Id,
                new List <Mosaic>()
            {
                NetworkCurrencyMosaic.CreateRelative(10)
            },
                PlainMessage.Create("Send to namespace"),
                Fixture.NetworkType);

            tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(Fixture.SeedAccount.Address).Take(1)
                 .Timeout(TimeSpan.FromSeconds(3000));

            var nsSignedTransferTransaction = Fixture.SeedAccount.Sign(transferTransaction, Fixture.GenerationHash);

            Fixture.WatchForFailure(nsSignedTransferTransaction);

            await Fixture.SiriusClient.TransactionHttp.Announce(nsSignedTransferTransaction);

            var result2 = await tx;

            Log.WriteLine($"Request confirmed with transaction {result2.TransactionInfo.Hash}");

            companyAccountInfo = await Fixture.SiriusClient.AccountHttp.GetAccountInfo(company.Address);

            Log.WriteLine($"Account {companyAccountInfo.Address.Plain} with mosaic {companyAccountInfo.Mosaics[0]} after transfer to the alias");

            //var expectedMosaicAmount = Convert.ToUInt64(Math.Pow(10, 6)) * (150 - 100 + 10);

            companyAccountInfo.Mosaics[0]?.Amount.Should().BeGreaterThan(0);

            #endregion Send mosaic to namespace instead of address
        }
        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_Add_Cosignatory()
        {
            //account = Account.CreateFromPrivateKey("EC2A2026948C28BAA8CDF061D7768397E0080E8E7913DE2ABF3066D2D4DCA0A6", NetworkType);
            //cosignatory1 = Account.CreateFromPrivateKey("39E80B97D7528E59997AA11DD499B42EFEE2E85BE372179CE88E622541F5DEDB", NetworkType);
            //cosignatory2 = Account.CreateFromPrivateKey("38296AE980C69D24D018D119C40A00D3894713F3A2F7BB27E495671D3D8C2E6D", NetworkType);
            // cosignatory3 = Account.CreateFromPrivateKey("748EFC97BBB2EC5A304DAD9B712B6540A8AD6A3EC2C60BDB03D20F6DB34513AD", NetworkType);

            Thread.Sleep(4000);
            Log.WriteLine($"MultiSig account {Fixture.MultiSigAccount}");
            Log.WriteLine($"Cosignatory1 account {Fixture.Cosignatory1}");
            Log.WriteLine($"Cosignatory3 account {Fixture.Cosignatory3}");

            var multisigCosignatoryModification = new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD, Fixture.Cosignatory3.PublicAccount);

            // Define a modify multisig account transaction to increase the minAprovalDelta in one unit
            var modifyMultisigAccountTransaction = ModifyMultisigAccountTransaction.Create(
                Deadline.Create(),
                0,
                0,
                new List <MultisigCosignatoryModification>
            {
                multisigCosignatoryModification
            },
                Fixture.NetworkType);

            // Wrap the modify multisig account transaction in an aggregate transaction,
            // attaching the multisig public key as the signer
            var aggregateTransaction = AggregateTransaction.CreateBonded(
                Deadline.Create(),
                new List <Transaction>
            {
                modifyMultisigAccountTransaction.ToAggregate(Fixture.MultiSigAccount.PublicAccount)
            },
                Fixture.NetworkType
                );

            var signedTransaction = Fixture.Cosignatory1.Sign(aggregateTransaction, Fixture.GenerationHash);

            // Before sending an aggregate bonded transaction,
            // the future multisig account needs to lock at least 10 cat.currency.
            // This transaction is required to prevent network spamming and ensure that
            // the inner transactions are cosigned
            var hashLockTransaction = HashLockTransaction.Create(
                Deadline.Create(),
                NetworkCurrencyMosaic.CreateRelative(10),
                (ulong)700,
                signedTransaction,
                Fixture.NetworkType);


            var hashLockTransactionSigned = Fixture.Cosignatory1.Sign(hashLockTransaction, Fixture.GenerationHash);

            /*var hashLocktx =SiriusWebSocketClient.Listener
             *     .ConfirmedTransactionsGiven(cosignatory1.Address).Take(1)
             *     .Timeout(TimeSpan.FromSeconds(500));*/

            Fixture.WatchForFailure(hashLockTransactionSigned);

            Log.WriteLine($"Going to announce hash lock transaction {hashLockTransactionSigned.Hash}");

            // Announce the hash lock transaction
            await Fixture.SiriusClient.TransactionHttp.Announce(hashLockTransactionSigned);

            Thread.Sleep(8000);

            // Wait for the hash lock transaction to be confirmed
            //var hashLockConfirmed = await hashLocktx;

            // if (hashLockConfirmed.TransactionInfo.Hash == hashLockTransactionSigned.Hash)
            //  {

            Fixture.WatchForFailure(signedTransaction);

            Log.WriteLine($"Going to announce aggregate bonded transaction {signedTransaction.Hash}");

            // Announce the AnnounceAggregateBonded transaction
            await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBonded(signedTransaction);

            // sleep for await
            Thread.Sleep(8000);

            /*var cosignatory3Cosigned =SiriusWebSocketClient.Listener
             *   .CosignatureAdded(cosignatory3.Address).Take(1)
             *   .Timeout(TimeSpan.FromSeconds(2000));*/
            Thread.Sleep(2000);
            var cosignatory3AggTxs = await Fixture.SiriusClient.AccountHttp.AggregateBondedTransactions(Fixture.Cosignatory3.PublicAccount);

            foreach (AggregateTransaction tx in cosignatory3AggTxs)
            {
                if (!tx.IsSignedByAccount(Fixture.Cosignatory3.PublicAccount))
                {
                    var cosignatureSignedTransaction = CosignAggregateBondedTransaction(tx, Fixture.Cosignatory3);

                    Fixture.WatchForFailure(cosignatureSignedTransaction);

                    await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBondedCosignatureAsync(cosignatureSignedTransaction);

                    Thread.Sleep(2000);
                    //var resultTx = await cosignatory1Cosigned;

                    //Log.WriteLine($"Completed Cosign 1 {resultTx}");
                }
            }

            /*var cosignatory2Cosigned =SiriusWebSocketClient.Listener
             * .CosignatureAdded(cosignatory2.Address).Take(1)
             * .Timeout(TimeSpan.FromSeconds(2000));*/
            Thread.Sleep(2000);
            var cosignatory2AggTxs = await Fixture.SiriusClient.AccountHttp.AggregateBondedTransactions(Fixture.Cosignatory2.PublicAccount);

            foreach (AggregateTransaction tx in cosignatory2AggTxs)
            {
                if (!tx.IsSignedByAccount(Fixture.Cosignatory2.PublicAccount))
                {
                    var cosignatureSignedTransaction = CosignAggregateBondedTransaction(tx, Fixture.Cosignatory2);

                    Fixture.WatchForFailure(cosignatureSignedTransaction);

                    await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBondedCosignatureAsync(cosignatureSignedTransaction);

                    Thread.Sleep(2000);
                    //var resultTx = await cosignatory1Cosigned;

                    //Log.WriteLine($"Completed Cosign 1 {resultTx}");
                }
            }

            Thread.Sleep(10000);
            // verify the account is multisig
            var multiSigAcc = await Fixture.SiriusClient.AccountHttp.GetMultisigAccountInfo(Fixture.MultiSigAccount.Address);

            Log.WriteLine($"Multisig account {multiSigAcc}");

            multiSigAcc.IsMultisig.Should().BeTrue();
            multiSigAcc.Cosignatories.Should().HaveCount(2);

            Log.WriteLine($"Completed");
            //  }
        }
        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}");
        }
        public async Task Should_Add_Cosignatory()
        {
            Log.WriteLine($"MultiSig account {Fixture.MultiSigAccount}");
            Log.WriteLine($"Cosignatory1 account {Fixture.Cosignatory1}");
            Log.WriteLine($"Cosignatory3 account {Fixture.Cosignatory3}");

            // Define a modify multisig account transaction to increase the minAprovalDelta in one unit
            var modifyMultisigAccountTransaction = ModifyMultisigAccountTransaction.Create(
                Deadline.Create(),
                0,
                0,
                new List <MultisigCosignatoryModification>
            {
                new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
                                                    Fixture.Cosignatory1.PublicAccount),
                new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
                                                    Fixture.Cosignatory3.PublicAccount),
            },
                Fixture.NetworkType);

            // Wrap the modify multisig account transaction in an aggregate transaction,
            // attaching the multisig public key as the signer
            var aggregateTransaction = AggregateTransaction.CreateComplete(
                Deadline.Create(),
                new List <Transaction>
            {
                modifyMultisigAccountTransaction.ToAggregate(Fixture.MultiSigAccount.PublicAccount)
            },
                Fixture.NetworkType
                );

            var signedTransaction = Fixture.MultiSigAccount.Sign(aggregateTransaction, Fixture.GenerationHash);

            Fixture.WatchForFailure(signedTransaction);

            // Before sending an aggregate bonded transaction,
            // the future multisig account needs to lock at least 10 cat.currency.
            // This transaction is required to prevent network spamming and ensure that
            // the inner transactions are cosigned
            var hashLockTransaction = HashLockTransaction.Create(
                Deadline.Create(),
                NetworkCurrencyMosaic.CreateRelative(10),
                (ulong)700,
                signedTransaction,
                Fixture.NetworkType);

            var hashLockTransactionSigned = Fixture.SeedAccount.Sign(hashLockTransaction, Fixture.GenerationHash);

            try
            {
                var hashLocktx = Fixture.SiriusWebSocketClient.Listener
                                 .ConfirmedTransactionsGiven(Fixture.Cosignatory1.Address).Take(1)
                                 .Timeout(TimeSpan.FromSeconds(500));
                Fixture.WatchForFailure(hashLockTransactionSigned);

                // Announce the hash lock transaction
                Log.WriteLine($"Going to announce hash lock transaction {hashLockTransactionSigned.Hash}");
                await Fixture.SiriusClient.TransactionHttp.Announce(hashLockTransactionSigned);

                var hashLockConfirmed = await hashLocktx;

                if (hashLockConfirmed.TransactionInfo.Hash == hashLockTransactionSigned.Hash)
                {
                    // Announce the AnnounceAggregateBonded transaction
                    await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBonded(signedTransaction);

                    Log.WriteLine($"Going to announce aggregate bonded transaction {signedTransaction.Hash}");

                    // sleep for await
                    Thread.Sleep(8000);
                    Fixture.WatchForFailure(signedTransaction);

                    var cosignatory3AggTxs = await Fixture.SiriusClient.AccountHttp.AggregateBondedTransactions(Fixture.Cosignatory3.PublicAccount);

                    foreach (AggregateTransaction tx in cosignatory3AggTxs.Transactions)
                    {
                        if (!tx.IsSignedByAccount(Fixture.Cosignatory3.PublicAccount))
                        {
                            var cosignatureSignedTransaction = CosignAggregateBondedTransaction(tx, Fixture.Cosignatory3);

                            Fixture.WatchForFailure(cosignatureSignedTransaction);
                            Log.WriteLine($"Going to announce cosign aggregate bonded transaction {cosignatureSignedTransaction.ParentHash}");
                            await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBondedCosignatureAsync(cosignatureSignedTransaction);

                            Thread.Sleep(2000);
                        }
                    }

                    var cosignatory2AggTxs = await Fixture.SiriusClient.AccountHttp.AggregateBondedTransactions(Fixture.Cosignatory2.PublicAccount);

                    foreach (AggregateTransaction tx in cosignatory2AggTxs.Transactions)
                    {
                        if (!tx.IsSignedByAccount(Fixture.Cosignatory2.PublicAccount))
                        {
                            var cosignatureSignedTransaction = CosignAggregateBondedTransaction(tx, Fixture.Cosignatory2);

                            Fixture.WatchForFailure(cosignatureSignedTransaction);

                            await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBondedCosignatureAsync(cosignatureSignedTransaction);

                            Thread.Sleep(2000);
                        }
                    }

                    Log.WriteLine($"Completed");
                }
            }
            catch (Exception e)
            {
                Log.WriteLine(e.Message);
            }
        }
        public async Task Should_Convert_Account_To_1to2_MultiSig()
        {
            // Get current network type


            // Create an account to be converted to multisig with some money
            // var account = await GenerateAccountAndSendSomeMoney(100);
            Log.WriteLine($"MultiSig account {Fixture.MultiSigAccount}");

            // var cosignatory1 = await GenerateAccountAndSendSomeMoney(100);
            // var cosignatory2 = await GenerateAccountAndSendSomeMoney(100);
            //var account = GetAccountFromKey("F40DAD4B22DAFBBAA6BD33531E14C51810AFEF5BDDBFFE5E2ACB1C1D77EF0D93", NetworkType);
            // var cosignatory2 = GetAccountFromKey("574D23DEF92D1C89DD50750DF303EA2A4C26ADBC9B966546B6BACAB827761088", NetworkType);
            // var cosignatory1 = GetAccountFromKey("5F558CE1B471980D76BE8C716334E098DEDDCACA71736620BA7B48436C5972D2", NetworkType);

            // Create two other accounts
            // var cosignatory1 = Account.GenerateNewAccount(NetworkType);
            Log.WriteLine($"MultiSig cosignatory1 {Fixture.Cosignatory1}");

            // var cosignatory2 = Account.GenerateNewAccount(NetworkType);
            Log.WriteLine($"MultiSig cosignatory2 {Fixture.Cosignatory2}");

            // Create a modify multisig account transaction to convert the shared account into a multisig account
            // 1 to 2 multisig
            var multiSigBuilder = new ModifyMultisigAccountTransactionBuilder();

            multiSigBuilder.SetDeadline(Deadline.Create())
            .SetMinApprovalDelta(1)
            .SetMinRemovalDelta(1)
            .SetModifications(new List <MultisigCosignatoryModification>
            {
                new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
                                                    Fixture.Cosignatory1.PublicAccount),
                new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
                                                    Fixture.Cosignatory2.PublicAccount),
            })
            .SetNetworkType(Fixture.NetworkType);
            var convertIntoMultisigTransaction = multiSigBuilder.Build();

            /*
             * var convertIntoMultisigTransaction = ModifyMultisigAccountTransaction.Create(
             *  Deadline.Create(),
             *  1,
             *  1,
             *  new List<MultisigCosignatoryModification>
             *  {
             *      new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
             *          Fixture.Cosignatory1.PublicAccount),
             *      new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
             *          Fixture.Cosignatory2.PublicAccount),
             *  },
             *  Fixture.NetworkType);
             */

            // Create an aggregate bonded transaction, wrapping the modify multisig account transaction
            var aggregateTransaction = AggregateTransaction.CreateBonded(
                Deadline.Create(),
                new List <Transaction>
            {
                convertIntoMultisigTransaction.ToAggregate(Fixture.MultiSigAccount.PublicAccount)
            },
                Fixture.NetworkType);



            // Sign the aggregate transaction using the private key of the multisig account
            var signedTransaction = Fixture.MultiSigAccount.Sign(aggregateTransaction, Fixture.GenerationHash);

            // Before sending an aggregate bonded transaction,
            // the future multisig account needs to lock at least 10 cat.currency.
            // This transaction is required to prevent network spamming and ensure that
            // the inner transactions are cosigned
            var builder = new LockFundsTransactionBuilder();

            builder.SetDeadline(Deadline.Create())
            .SetDuration((ulong)700)
            .SetMosaic(NetworkCurrencyMosaic.CreateRelative(10))
            .SetSignedTransaction(signedTransaction)
            .SetNetworkType(Fixture.NetworkType);

            var hashLockTransaction = builder.Build();

            /*
             * var hashLockTransaction = HashLockTransaction.Create(
             *  Deadline.Create(),
             *  NetworkCurrencyMosaic.CreateRelative(10),
             *  (ulong)700,
             *  signedTransaction,
             *  Fixture.NetworkType);
             */
            var hashLockTransactionSigned = Fixture.SeedAccount.Sign(hashLockTransaction, Fixture.GenerationHash);

            // register transaction with web socket
            try
            {
                // awaitSiriusWebSocketClient.Listener.Open();

                var hashLocktx = Fixture.SiriusWebSocketClient.Listener
                                 .ConfirmedTransactionsGiven(Fixture.SeedAccount.Address).Take(1)
                                 .Timeout(TimeSpan.FromSeconds(500));

                Fixture.WatchForFailure(hashLockTransactionSigned);

                Log.WriteLine($"Going to announce hash lock transaction {hashLockTransactionSigned.Hash}");

                // Announce the hash lock transaction
                await Fixture.SiriusClient.TransactionHttp.Announce(hashLockTransactionSigned);

                // Wait for the hash lock transaction to be confirmed
                var hashLockConfirmed = await hashLocktx;

                // After the hash lock transaction has been confirmed,
                // announce the aggregate transaction.
                if (hashLockConfirmed.TransactionInfo.Hash == hashLockTransactionSigned.Hash)
                {
                    //var aggBonded = Fixture.SiriusWebSocketClient.Listener
                    //   .AggregateBondedAdded(Fixture.SeedAccount.Address).Take(1)
                    // .Timeout(TimeSpan.FromSeconds(2000));

                    // var aggBondedConfirmed = Fixture.SiriusWebSocketClient.Listener
                    //   .ConfirmedTransactionsGiven(Fixture.MultiSigAccount.Address).Take(1)
                    //    .Timeout(TimeSpan.FromSeconds(2000));

                    Fixture.WatchForFailure(signedTransaction);

                    Log.WriteLine($"Going to announce aggregate bonded transaction {signedTransaction.Hash}");

                    // Announce the hash lock transaction
                    await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBonded(signedTransaction);

                    // sleep for await
                    Thread.Sleep(5000);

                    //var aggBondedTx = await aggBondedConfirmed;


                    //if(aggBondedTx.IsConfirmed())
                    // {
                    // Cosign the aggregate transaction with cosignatory1
                    var cosignatory1Cosigned = Fixture.SiriusWebSocketClient.Listener
                                               .CosignatureAdded(Fixture.Cosignatory1.Address).Take(1)
                                               .Timeout(TimeSpan.FromSeconds(2000));

                    var cosignatory1AggTxs = await Fixture.SiriusClient.AccountHttp.AggregateBondedTransactions(Fixture.Cosignatory1.PublicAccount);

                    foreach (AggregateTransaction tx in cosignatory1AggTxs)
                    {
                        if (!tx.IsSignedByAccount(Fixture.Cosignatory1.PublicAccount))
                        {
                            var cosignatureSignedTransaction = CosignAggregateBondedTransaction(tx, Fixture.Cosignatory1);

                            Fixture.WatchForFailure(cosignatureSignedTransaction);

                            await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBondedCosignatureAsync(cosignatureSignedTransaction);

                            Thread.Sleep(2000);
                            //var resultTx = await cosignatory1Cosigned;

                            //Log.WriteLine($"Completed Cosign 1 {resultTx}");
                        }
                    }

                    // Cosign the aggregate transaction with cosignatory2
                    var cosignatory2Cosigned = Fixture.SiriusWebSocketClient.Listener
                                               .CosignatureAdded(Fixture.Cosignatory2.Address).Take(1)
                                               .Timeout(TimeSpan.FromSeconds(2000));


                    var cosignatory2AggTxs = await Fixture.SiriusClient.AccountHttp.AggregateBondedTransactions(Fixture.Cosignatory2.PublicAccount);

                    foreach (AggregateTransaction tx in cosignatory2AggTxs)
                    {
                        if (!tx.IsSignedByAccount(Fixture.Cosignatory2.PublicAccount))
                        {
                            var cosignatureSignedTransaction = CosignAggregateBondedTransaction(tx, Fixture.Cosignatory2);

                            Fixture.WatchForFailure(cosignatureSignedTransaction);

                            await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBondedCosignatureAsync(cosignatureSignedTransaction);

                            Thread.Sleep(2000);
                            //var resultTx = await cosignatory2Cosigned;

                            //Log.WriteLine($"Completed Cosign 2 {resultTx}");
                        }
                    }

                    // }
                    Thread.Sleep(10000);
                    // verify the account is multisig
                    var multiSigAcc = await Fixture.SiriusClient.AccountHttp.GetMultisigAccountInfo(Fixture.MultiSigAccount.Address);

                    Log.WriteLine($"Multisig account {multiSigAcc}");

                    multiSigAcc.IsMultisig.Should().BeTrue();
                    multiSigAcc.MinApproval.Should().Be(1);
                    multiSigAcc.MinRemoval.Should().Be(1);
                    multiSigAcc.Cosignatories.Should().HaveCount(2);

                    Log.WriteLine($"Completed");
                }
            }
            catch (Exception e)
            {
                Log.WriteLine(e.Message);
            }
            finally
            {
                try
                {
                    //SiriusWebSocketClient.Listener.Close();
                }
                catch (Exception)
                {
                    //do nothing
                }
            }
        }
        public async Task Should_Convert_Account_To_1to2_MultiSig()
        {
            // Get current network type

            // Create an account to be converted to multisig with some money
            // var account = await GenerateAccountAndSendSomeMoney(100);
            Log.WriteLine($"MultiSig account {Fixture.MultiSigAccount}");

            // Create two other accounts
            // var cosignatory1 = Account.GenerateNewAccount(NetworkType);
            Log.WriteLine($"MultiSig cosignatory1 {Fixture.Cosignatory1}");

            // var cosignatory2 = Account.GenerateNewAccount(NetworkType);
            Log.WriteLine($"MultiSig cosignatory2 {Fixture.Cosignatory2}");

            // Create a modify multisig account transaction to convert the shared account into a multisig account
            // 1 to 2 multisig
            var multiSigBuilder = new ModifyMultisigAccountTransactionBuilder();

            multiSigBuilder.SetDeadline(Deadline.Create())
            .SetMinApprovalDelta(1)
            .SetMinRemovalDelta(1)
            .SetModifications(new List <MultisigCosignatoryModification>
            {
                new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
                                                    Fixture.Cosignatory1.PublicAccount),
                new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD,
                                                    Fixture.Cosignatory2.PublicAccount),
            })
            .SetNetworkType(Fixture.NetworkType);
            var convertIntoMultisigTransaction = multiSigBuilder.Build();

            // Create an aggregate bonded transaction, wrapping the modify multisig account transaction
            var aggregateTransaction = AggregateTransaction.CreateBonded(
                Deadline.Create(),
                new List <Transaction>
            {
                convertIntoMultisigTransaction.ToAggregate(Fixture.MultiSigAccount.PublicAccount)
            },
                Fixture.NetworkType);

            // Sign the aggregate transaction using the private key of the multisig account
            var signedTransaction = Fixture.MultiSigAccount.Sign(aggregateTransaction, Fixture.GenerationHash);

            // Before sending an aggregate bonded transaction,
            // the future multisig account needs to lock at least 10 cat.currency.
            // This transaction is required to prevent network spamming and ensure that
            // the inner transactions are cosigned
            var builder = new LockFundsTransactionBuilder();

            builder.SetDeadline(Deadline.Create())
            .SetDuration((ulong)700)
            .SetMosaic(NetworkCurrencyMosaic.CreateRelative(10))
            .SetSignedTransaction(signedTransaction)
            .SetNetworkType(Fixture.NetworkType);

            var hashLockTransaction = builder.Build();

            var hashLockTransactionSigned = Fixture.SeedAccount.Sign(hashLockTransaction, Fixture.GenerationHash);

            // register transaction with web socket
            try
            {
                var hashLocktx = Fixture.SiriusWebSocketClient.Listener
                                 .ConfirmedTransactionsGiven(Fixture.SeedAccount.Address).Take(1)
                                 .Timeout(TimeSpan.FromSeconds(500));

                Fixture.WatchForFailure(hashLockTransactionSigned);

                Log.WriteLine($"Going to announce hash lock transaction {hashLockTransactionSigned.Hash}");

                // Announce the hash lock transaction
                await Fixture.SiriusClient.TransactionHttp.Announce(hashLockTransactionSigned);

                // Wait for the hash lock transaction to be confirmed
                var hashLockConfirmed = await hashLocktx;

                // After the hash lock transaction has been confirmed,
                // announce the aggregate transaction.
                if (hashLockConfirmed.TransactionInfo.Hash == hashLockTransactionSigned.Hash)
                {
                    Fixture.WatchForFailure(signedTransaction);

                    Log.WriteLine($"Going to announce aggregate bonded transaction {signedTransaction.Hash}");

                    // Announce the hash lock transaction
                    await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBonded(signedTransaction);

                    // sleep for await
                    Thread.Sleep(5000);

                    // Cosign the aggregate transaction with cosignatory1
                    var cosignatory1Cosigned = Fixture.SiriusWebSocketClient.Listener.CosignatureAdded(Fixture.Cosignatory1.Address).Take(1).Timeout(TimeSpan.FromSeconds(2000));

                    var cosignatory1AggTxs = await Fixture.SiriusClient.AccountHttp.AggregateBondedTransactions(Fixture.Cosignatory1.PublicAccount);

                    foreach (AggregateTransaction tx in cosignatory1AggTxs.Transactions)
                    {
                        if (!tx.IsSignedByAccount(Fixture.Cosignatory1.PublicAccount))
                        {
                            var cosignatureSignedTransaction = CosignAggregateBondedTransaction(tx, Fixture.Cosignatory1);

                            Fixture.WatchForFailure(cosignatureSignedTransaction);

                            await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBondedCosignatureAsync(cosignatureSignedTransaction);

                            Thread.Sleep(8000);
                        }
                    }

                    // Cosign the aggregate transaction with cosignatory2
                    var cosignatory2Cosigned = Fixture.SiriusWebSocketClient.Listener
                                               .CosignatureAdded(Fixture.Cosignatory2.Address).Take(1)
                                               .Timeout(TimeSpan.FromSeconds(2000));
                    var cosignatory2AggTxs = await Fixture.SiriusClient.AccountHttp.AggregateBondedTransactions(Fixture.Cosignatory2.PublicAccount);

                    foreach (AggregateTransaction tx in cosignatory2AggTxs.Transactions)
                    {
                        if (!tx.IsSignedByAccount(Fixture.Cosignatory2.PublicAccount))
                        {
                            var cosignatureSignedTransaction = CosignAggregateBondedTransaction(tx, Fixture.Cosignatory2);

                            Fixture.WatchForFailure(cosignatureSignedTransaction);

                            await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBondedCosignatureAsync(cosignatureSignedTransaction);

                            Thread.Sleep(2000);
                        }
                    }

                    Thread.Sleep(10000);
                    // verify the account is multisig
                    var multiSigAcc = await Fixture.SiriusClient.AccountHttp.GetMultisigAccountInfo(Fixture.MultiSigAccount.Address);

                    Log.WriteLine($"Multisig account {multiSigAcc}");

                    multiSigAcc.IsMultisig.Should().BeTrue();
                    multiSigAcc.MinApproval.Should().Be(1);
                    multiSigAcc.MinRemoval.Should().Be(1);
                    multiSigAcc.Cosignatories.Should().HaveCount(2);

                    Log.WriteLine($"Completed");
                }
            }
            catch (Exception e)
            {
                Log.WriteLine(e.Message);
            }

            /*  finally
             * {
             *    try
             *    {
             *        //SiriusWebSocketClient.Listener.Close();
             *    }
             *    catch (Exception)
             *    {
             *        //do nothing
             *    }
             * }*/
        }