コード例 #1
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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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
             *    }
             * }*/
        }
コード例 #4
0
        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
                }
            }
        }