public async Task CanCreateMosaicWithLevy()
        {
            var keyPair     = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);
            var transaction = MosaicDefinitionTransaction.CreateWithLevy(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(1),
                new MosaicProperties(4, 1000000000, true, true),
                MosaicId.CreateFromMosaicIdentifier("myspace:subspacewithlevy"),
                new MosaicLevy(Mosaic.CreateFromIdentifier("myspace:subspace", 100), 1, Address.CreateFromEncoded("TCTUIF-557ZCQ-OQPW2M-6GH4TC-DPM2ZY-BBL54K-GNHR")),
                PublicAccount.CreateFromPublicKey(keyPair.PublicKeyString, NetworkType.Types.TEST_NET),
                "new mosaic test"
                ).SignWith(keyPair);

            var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(transaction);

            Assert.AreEqual("FAILURE_MOSAIC_MODIFICATION_NOT_ALLOWED", response.Message);
        }
Example #2
0
        public Task <(string hash, string signedTransaction)> SignTransactionAsync(
            string transactionContext, IReadOnlyList <string> privateKeys)
        {
            if (privateKeys.Count != 1)
            {
                throw new ArgumentException("Only single private key is allowed");
            }

            var key = KeyPair.CreateFromPrivateKey(privateKeys[0]);
            var signedTransaction = TransferTransaction.FromJson(transactionContext).SignWith(key);
            var result            = (
                signedTransaction.Hash,
                signedTransaction.ToJson()
                );

            return(Task.FromResult(result));
        }
        public async Task PartialTransactionWithMissingCosigner()
        {
            var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var keyPair2 = KeyPair.CreateFromPrivateKey("14A239D2ADB96753CFC160BB262F27B01BCCC8C74599F51771BC6BD39980F4E7");

            var aggregateBonded = AggregateTransaction.CreateBonded(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new List <Transaction>
            {
                TransferTransactionTests.CreateInnerTransferTransaction(
                    "nem:xem").ToAggregate(PublicAccount.CreateFromPublicKey(keyPair2.PublicKeyString, NetworkType.Types.MIJIN_TEST)),
                TransferTransactionTests.CreateInnerTransferTransaction(
                    "nem:xem").ToAggregate(PublicAccount.CreateFromPublicKey(keyPair2.PublicKeyString, NetworkType.Types.MIJIN_TEST)),
            },
                null)
                                  .SignWith(keyPair);

            WatchForFailure(aggregateBonded);

            var hashLock = LockFundsTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                0,
                new Mosaic(new MosaicId("nem:xem"), 10000000),
                10000,
                aggregateBonded
                )
                           .SignWith(KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain));

            WatchForFailure(hashLock);

            await new TransactionHttp(host).Announce(hashLock);

            var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(hashLock.Signer, NetworkType.Types.MIJIN_TEST)).Where(e => e.TransactionInfo.Hash == hashLock.Hash).Take(1);

            Assert.AreEqual(keyPair.PublicKeyString, status.Signer.PublicKey);

            await new TransactionHttp(host).AnnounceAggregateBonded(aggregateBonded);

            var status2 = await listener.AggregateBondedAdded(Address.CreateFromPublicKey(aggregateBonded.Signer, NetworkType.Types.MIJIN_TEST)).Where(e => e.TransactionInfo.Hash == aggregateBonded.Hash).Take(1);

            Assert.AreEqual(keyPair.PublicKeyString, status2.Signer.PublicKey);
        }
        public async Task AnnounceTransferTransactionWithMosaicWithSecureMessage()
        {
            var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                Address.CreateFromEncoded("TAVPDJ-DR3R3X-4FJUKN-PY2IQB-NNRFV2-QR5NJZ-J3WR"),
                new List <Mosaic> {
                Mosaic.CreateFromIdentifier("nem:xem", 10)
            },
                SecureMessage.Create("hello2", Config.PrivateKeyMain, "4cc7409929a72019240065c9e53aa339f87ba889238ff9fbe978251fdbb05d9f")
                ).SignWith(keyPair);

            var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(transaction);

            Assert.AreEqual("SUCCESS", response.Message);
        }
Example #5
0
        public async Task MutableMosaicCreationTransaction()
        {
            var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = MosaicDefinitionTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(1),
                "happy",
                "test2",
                new MosaicProperties(true, true, false, 0x04, 100000))
                              .SignWith(signer);

            await new TransactionHttp(host).Announce(transaction);

            var status = await listener.TransactionStatus(Address.CreateFromPublicKey(signer.PublicKeyString, NetworkType.Types.MIJIN_TEST)).Where(e => e.Hash == transaction.Hash).Take(1);

            Assert.AreEqual("Failure_Mosaic_Modification_No_Changes", status.Status);
        }
Example #6
0
        public async Task MosaicSupplyIncreaseTransction()
        {
            var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = MosaicSupplyChangeTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new MosaicId("happy:test2"),
                MosaicSupplyType.Type.INCREASE,
                (ulong)new Random().Next(100000000, 1100000000)

                ).SignWith(signer);

            await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction);

            var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)).Take(1);

            Assert.AreEqual(signer.PublicKeyString, status.Signer.PublicKey);
        }
Example #7
0
        public async Task MosaicSupplyIncreaseShouldFailImmutableSupply()
        {
            var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = MosaicSupplyChangeTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new MosaicId("happy:test3"),
                MosaicSupplyType.Type.INCREASE,
                10000)
                              .SignWith(signer);

            await new TransactionHttp(host).Announce(transaction);
            listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(signer.PublicKeyString,
                                                                            NetworkType.Types.MIJIN_TEST)).Subscribe(e => Console.WriteLine(e.TransactionInfo.Hash));
            var status = await listener.TransactionStatus(Address.CreateFromPublicKey(signer.PublicKeyString, NetworkType.Types.MIJIN_TEST)).Where(e => e.Hash == transaction.Hash).Take(1);

            Assert.AreEqual("Failure_Mosaic_Supply_Immutable", status.Status);
        }
        public async Task AnnounceTransferTransactionWithMultipleMosaicsWithoutMessage()
        {
            var keyPair =
                KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                Address.CreateFromEncoded("TALICE-ROONSJ-CPHC63-F52V6F-Y3SDMS-VAEUGH-MB7C"),
                new List <Mosaic>()
            {
                Mosaic.CreateFromIdentifier("nem:xem", 10)
            },
                EmptyMessage.Create()
                ).SignWith(keyPair);

            var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(transaction);

            Assert.AreEqual("SUCCESS", response.Message);
        }
        public async Task AggregateTransactionWithOnlyInitiator()
        {
            var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var aggregateTransaction = AggregateTransaction.CreateComplete(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new List <Transaction>
            {
                TransferTransactionTests.CreateInnerTransferTransaction("nem:xem")
                .ToAggregate(PublicAccount.CreateFromPublicKey("B974668ABED344BE9C35EE257ACC246117EFFED939EAF42391AE995912F985FE", NetworkType.Types.MIJIN_TEST)),
            }
                ).SignWith(keyPair);

            await new TransactionHttp(host).Announce(aggregateTransaction);

            var status2 = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(aggregateTransaction.Signer, NetworkType.Types.MIJIN_TEST)).Where(e => e.TransactionInfo.Hash == aggregateTransaction.Hash).Take(1);

            Assert.AreEqual(keyPair.PublicKeyString, status2.Signer.PublicKey);
        }
        public async Task AnnounceTransferTransactionWithMultipleMosaicsWithSecureMessage()
        {
            var keyPair =
                KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                Address.CreateFromEncoded("TALICE-ROONSJ-CPHC63-F52V6F-Y3SDMS-VAEUGH-MB7C"),
                new List <Mosaic>()
            {
                Mosaic.CreateFromIdentifier("nem:xem", 1000),
                //Mosaic.CreateFromIdentifier("nis1porttest:test", 10), TODO: fix multiple mosaic transfer
            },
                SecureMessage.Create("hello2", Config.PrivateKeyMain, "5D8BEBBE80D7EA3B0088E59308D8671099781429B449A0BBCA6D950A709BA068")
                ).SignWith(keyPair);

            var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(transaction);

            Assert.AreEqual("SUCCESS", response.Message);
        }
        public async Task CanModifyMultisigAccount()
        {
            var keyPair = KeyPair.CreateFromPrivateKey("8db858dcc8e2827074498204b3829154ec4c4f24d13738d3f501003b518ef256");

            var transaction = MultisigAggregateModificationTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(1),
                1,
                new List <MultisigModification>()
            {
                new MultisigModification(PublicAccount.CreateFromPublicKey("eb100d6b2da10fc5359ab35a5801b0e6f0b6cc18d849c0aa78ba1aab2b945dea", NetworkType.Types.TEST_NET),
                                         CosignatoryModificationType.Types.Add)
            });

            var multisigTransaction = MultisigTransaction.Create(NetworkType.Types.TEST_NET, Deadline.CreateHours(1), transaction)
                                      .SignWith(keyPair, PublicAccount.CreateFromPublicKey("29c4a4aa674953749053c8a35399b37b713dedd5d002cb29b3331e56ff1ea65a", NetworkType.Types.TEST_NET));

            var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(multisigTransaction);

            Assert.AreEqual("FAILURE_MULTISIG_ALREADY_A_COSIGNER", response.Message);
        }
Example #12
0
        public async Task MosaicSupplyDecreaseTransction()
        {
            var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = MosaicSupplyChangeTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new MosaicId("happy:test2"),
                MosaicSupplyType.Type.DECREASE,
                10000)
                              .SignWith(signer);

            await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction);

            listener.TransactionStatus(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST))
            .Subscribe(e => Console.WriteLine(e.Status));

            var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)).Take(1);

            Assert.AreEqual("B974668ABED344BE9C35EE257ACC246117EFFED939EAF42391AE995912F985FE", status.Signer.PublicKey);
        }
        public async Task LockFundsTransactionTest()
        {
            var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var aggregateTransaction = AggregateTransaction.CreateBonded(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new List <Transaction>
            {
                TransferTransactionTests.CreateInnerTransferTransaction(
                    "nem:xem").ToAggregate(PublicAccount.CreateFromPublicKey("10CC07742437C205D9A0BC0434DC5B4879E002114753DE70CDC4C4BD0D93A64A", NetworkType.Types.MIJIN_TEST)),
                TransferTransactionTests.CreateInnerTransferTransaction(
                    "nem:xem").ToAggregate(PublicAccount.CreateFromPublicKey("A8FCF4371B9C4B26CE19A407BA803D3813647608D57ABC1550925A54AEE2C9EA", NetworkType.Types.MIJIN_TEST))
            },
                null)
                                       .SignWith(signer);

            var hashLock = LockFundsTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                0,
                new Mosaic(new MosaicId("nem:xem"), 10000000),
                10000,
                aggregateTransaction)
                           .SignWith(KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain));

            WatchForFailure(hashLock);

            await new TransactionHttp(host).Announce(hashLock);

            var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(hashLock.Signer, NetworkType.Types.MIJIN_TEST)).Where(e => e.TransactionInfo.Hash == hashLock.Hash).Take(1);

            Assert.AreEqual(signer.PublicKeyString, status.Signer.PublicKey);

            await new TransactionHttp(host).AnnounceAggregateBonded(aggregateTransaction);

            var status2 = await listener.AggregateBondedAdded(Address.CreateFromPublicKey(aggregateTransaction.Signer, NetworkType.Types.MIJIN_TEST)).Where(e => e.TransactionInfo.Hash == aggregateTransaction.Hash).Take(1);

            Assert.AreEqual(signer.PublicKeyString, status2.Signer.PublicKey);
        }
        public async Task AnnounceTransferTransactionWithMosaicWithMessage()
        {
            KeyPair keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            TransferTransaction transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                Address.CreateFromEncoded("TACOPE-XRLZTU-WBQA3U-XV66R4-55L76E-NWK6OY-ITBJ"),
                new List <Mosaic> {
                Mosaic.CreateFromIdentifier("nem:xem", 1)
            },
                EmptyMessage.Create()
                );

            SignedTransaction signedTransaction = transaction.SignWith(keyPair);

            Console.WriteLine(signedTransaction.Hash);
            Console.WriteLine(transaction.Fee);
            TransactionResponse response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(signedTransaction);

            Assert.AreEqual("SUCCESS", response.Message);
        }
        public async Task AggregateTransactionWithMissingCosignatures()
        {
            var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var keyPair2 = KeyPair.CreateFromPrivateKey(Config.PrivateKeySecond);

            var aggregateTransaction = AggregateTransaction.CreateBonded(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new List <Transaction>
            {
                RegisterNamespaceTransaction.CreateRootNamespace(NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), "happy23", 10000)
                .ToAggregate(PublicAccount.CreateFromPublicKey(keyPair.PublicKeyString, NetworkType.Types.MIJIN_TEST)),
                TransferTransactionTests.CreateInnerTransferTransaction("nem:xem")
                .ToAggregate(PublicAccount.CreateFromPublicKey(keyPair2.PublicKeyString, NetworkType.Types.MIJIN_TEST)),
            },
                null
                ).SignWith(keyPair);

            WatchForFailure(aggregateTransaction);

            var hashLock = LockFundsTransaction.Create(NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), 0, new Mosaic(new MosaicId("nem:xem"), 10000000), 10000, aggregateTransaction)
                           .SignWith(KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain));

            WatchForFailure(hashLock);

            await new TransactionHttp(host).Announce(hashLock);

            var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(hashLock.Signer, NetworkType.Types.MIJIN_TEST)).Where(e => e.TransactionInfo.Hash == hashLock.Hash).Take(1);

            Assert.AreEqual(keyPair.PublicKeyString, status.Signer.PublicKey);

            await new TransactionHttp(host).AnnounceAggregateBonded(aggregateTransaction);

            var status2 = await listener.AggregateBondedAdded(Address.CreateFromPublicKey(aggregateTransaction.Signer, NetworkType.Types.MIJIN_TEST)).Where(e => e.TransactionInfo.Hash == aggregateTransaction.Hash).Take(1);

            Assert.AreEqual(keyPair.PublicKeyString, status2.Signer.PublicKey);
        }
Example #16
0
        public static async void CreateTransaction(Account receiverAcc, String message)
        {
            KeyPair keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                Address.CreateFromEncoded(receiverAcc.Address.Plain),
                new List <Mosaic> {
                Mosaic.CreateFromIdentifier("nem:xem", 2000000)
            },
                SecureMessage.Create(message, Config.PrivateKeyMain, receiverAcc.PublicKey)
                );
            TransactionHttp   transactionHttp   = new TransactionHttp("http://" + Config.Domain + ":7890");
            SignedTransaction signedTransaction = transaction.SignWith(keyPair);

            Thread.Sleep(2000);
            await transactionHttp.Announce(signedTransaction);

            Console.WriteLine(signedTransaction.Hash);
            Console.WriteLine(receiverAcc.Address.Plain + " recve something from : " + Config.Address);
            Thread.Sleep(2000);
        }
Example #17
0
        public void Should_Sign_Data_And_Verify_Signature_SHA3_256()
        {
            var pk      = "A574ECE8F79DE11A39C6BADF0EF87C2C88730A5EA4CF2C0BD7E27103390BC4F4";
            var pubKey  = "2B0FF0CADE0D945A23D1AF7AF266A0BAB7E07B163756F5F16CC75F24A4EEF23B";
            var keyPair = KeyPair.CreateFromPrivateKey(pk);
            var message = "This is a test data";
            var data    = Encoding.UTF8.GetBytes(message);

            var encryptedData = CryptoUtils.Sha3_256(data);
            var encryptedHex  = CryptoBytes.ToHexStringUpper(encryptedData);

            var signature = keyPair.Sign(encryptedData);

            var sigHex = CryptoBytes.ToHexStringUpper(signature);

            var sig2 = CryptoBytes.FromHexString(sigHex);

            var publicAccount = PublicAccount.CreateFromPublicKey(pubKey, NetworkType.MIJIN_TEST);

            var isValid = publicAccount.VerifySignature(encryptedData, sig2);

            isValid.Should().BeTrue();
        }
        public async Task AnnounceTransferTransactionWithMosaicWithSecureMessage()
        {
            var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = TransferTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                Address.CreateFromEncoded("SAAA57-DREOPY-KUFX4O-G7IQXK-ITMBWK-D6KXTV-BBQP"),
                new List <Mosaic> {
                Mosaic.CreateFromIdentifier("nem:xem", 10)
            },
                SecureMessage.Create("hello2", Config.PrivateKeyMain, "5D8BEBBE80D7EA3B0088E59308D8671099781429B449A0BBCA6D950A709BA068")
                ).SignWith(keyPair);

            await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction);

            listener.TransactionStatus(Address.CreateFromPublicKey(keyPair.PublicKeyString, NetworkType.Types.MIJIN_TEST))
            .Subscribe(e => Console.WriteLine(e.Status));

            var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)).Take(1);

            Assert.AreEqual(keyPair.PublicKeyString, status.Signer.PublicKey);
        }
Example #19
0
        public static async Task <bool> TransferTest()
        {
            KeyPair keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            TransferTransaction transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                Address.CreateFromEncoded("TBZQXJ-N7JNQL-N7ZAMC-HFFZAU-WBMPB4-4RMIZU-XKNQ"),
                new List <Mosaic> {
                Mosaic.CreateFromIdentifier("nem:xem", 1000000)
            },
                PlainMessage.Create("Sr Alejo")
                );

            SignedTransaction signedTransaction = transaction.SignWith(keyPair);

            Console.WriteLine(signedTransaction.Hash);
            Console.WriteLine(transaction.Fee);
            TransactionResponse response = await
                                           new TransactionHttp("http://" + Config.Domain + ":7890").Announce(signedTransaction);

            return(true);
        }
Example #20
0
        public async Task SecretLockTransactionTest()
        {
            var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var secretHash = new byte[64];

            var digest = new Sha3Digest(512);

            digest.BlockUpdate("5D8BEBBE80D7EA3B0088E59308D8671099781429".FromHex(), 0, "5D8BEBBE80D7EA3B0088E59308D8671099781429".FromHex().Length);
            digest.DoFinal(secretHash, 0);

            var transaction = SecretLockTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                3,
                Deadline.CreateHours(2),
                0,
                new Mosaic(new MosaicId("nem:xem"), 10000000),
                10000,
                HashType.Types.SHA3_512,
                secretHash.ToHexLower(),
                Address.CreateFromPublicKey("5D8BEBBE80D7EA3B0088E59308D8671099781429B449A0BBCA6D950A709BA068", NetworkType.Types.MIJIN_TEST)
                )
                              .SignWith(signer);

            listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST))
            .Subscribe(
                e =>
            {
                Assert.Fail("Success");
            });

            await new TransactionHttp(host).Announce(transaction);

            var status = await listener.TransactionStatus(Address.CreateFromPublicKey(signer.PublicKeyString, NetworkType.Types.MIJIN_TEST)).Where(e => e.Hash == transaction.Hash).Take(1);

            Assert.AreEqual("Failure_Lock_Hash_Exists", status.Status);
        }
Example #21
0
        //[TestMethod, Timeout(20000)]
        public async Task ListenForPartialTransactionAdded()
        {
            var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var aggregateTransaction = AggregateTransaction.CreateBonded(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new List <Transaction>
            {
                TransferTransactionTests.CreateInnerTransferTransaction("nem:xem"),
            },
                null
                ).SignWith(keyPair);

            var hashLock = LockFundsTransaction.Create(NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), 0, duration: 10000, mosaic: new Mosaic(new MosaicId("nem:xem"), 10000000), transaction: aggregateTransaction)
                           .SignWith(KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain));

            await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(hashLock);

            var listener = new Listener(Config.Domain);

            await listener.Open();

            await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(
                                                          keyPair.PublicKeyString,
                                                          NetworkType.Types.MIJIN_TEST)
                                                      ).Take(1);

            await new TransactionHttp("http://" + Config.Domain + ":3000").AnnounceAggregateBonded(aggregateTransaction);

            var result = await listener.AggregateBondedAdded(Address.CreateFromPublicKey(
                                                                 keyPair.PublicKeyString,
                                                                 NetworkType.Types.MIJIN_TEST)
                                                             ).Take(1);

            Assert.AreEqual("10CC07742437C205D9A0BC0434DC5B4879E002114753DE70CDC4C4BD0D93A64A", result.Signer);
        }
Example #22
0
        public string GetMessagePayload(TransferTransaction transferTransaction, string accountPrivateKey)
        {
            CheckParameter(transferTransaction != null, "transferTransaction is required");

            switch (transferTransaction.Message)
            {
            case PlainMessage plainMessage:
                return(plainMessage.GetStringPayload());

            case SecureMessage secureMessage:
                if (accountPrivateKey == null)
                {
                    throw new MissingPrivateKeyOnDownloadException(
                              "accountPrivateKey is required to download a secure message");
                }
                var retrieverKeyPair = KeyPair.CreateFromPrivateKey(accountPrivateKey);
                return(secureMessage.GetDecodedPayload(accountPrivateKey,
                                                       GetTransactionOtherPartyPublicKey(retrieverKeyPair, transferTransaction)));

            default:
                throw new NotSupportedException(
                          $"Download of message type {transferTransaction.Message} is not supported");
            }
        }
        public async Task AnnounceTransferTransactionWithMultipleMosaicsWithSecureMessage()
        {
            var keyPair =
                KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = TransferTransaction.Create(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                Address.CreateFromEncoded("SAOV4Y5W627UXLIYS5O43SVU23DD6VNRCFP222P2"),
                new List <Mosaic>()
            {
                Mosaic.CreateFromIdentifier("nem:xem", 1000000000000),
                //Mosaic.CreateFromIdentifier("happy:test2", 10),
            },
                SecureMessage.Create("hello2", Config.PrivateKeyMain, "5D8BEBBE80D7EA3B0088E59308D8671099781429B449A0BBCA6D950A709BA068")

                ).SignWith(keyPair);

            await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction);

            var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)).Take(1);

            Assert.AreEqual(keyPair.PublicKeyString, status.Signer.PublicKey);
        }
        public async Task CanSignMultisigTransaction()
        {
            var cosignatory     = KeyPair.CreateFromPrivateKey("8db858dcc8e2827074498204b3829154ec4c4f24d13738d3f501003b518ef256");
            var secondCosig     = KeyPair.CreateFromPrivateKey("cfe47dd9801a5d4fe37183e8f6ca49fff532a2fe6fe099436df93b3d62fe17d5");
            var multisigAccount = PublicAccount.CreateFromPublicKey("29c4a4aa674953749053c8a35399b37b713dedd5d002cb29b3331e56ff1ea65a", NetworkType.Types.TEST_NET);
            var recipient       = new Account("E45030D2A22D97FDC4C78923C4BBF7602BBAC3B018FFAD2ED278FB49CD6F218C", NetworkType.Types.TEST_NET);

            var transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                recipient.Address,
                new List <Mosaic> {
                Mosaic.CreateFromIdentifier("nem:xem", 1000000)
            },
                PlainMessage.Create("hello")
                );

            var multisigTransaction = MultisigTransaction
                                      .Create(NetworkType.Types.TEST_NET, Deadline.CreateHours(1), transaction)
                                      .SignWith(cosignatory, multisigAccount);

            var response = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(multisigTransaction);

            Assert.AreEqual("SUCCESS", response.Message);

            var signatureTransaction = CosignatureTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(1),
                "59f5f7cbbdaa996b8d3c45ce814280aab3b5d322a98fe95c00ae516cf436172d",
                multisigAccount.Address
                ).SignWith(secondCosig);

            var response2 = await new TransactionHttp("http://" + Config.Domain + ":7890").Announce(signatureTransaction);

            Assert.AreEqual("FAILURE_MULTISIG_NO_MATCHING_MULTISIG", response2.Message);
        }
Example #25
0
        public static async Task <bool> CreateTransaction()
        {
            KeyPair keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = TransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(2),
                Address.CreateFromEncoded("TCPCAZ-7XJ2X4-SWR6AG-6BUEKS-6DQ7DL-Z2D6QB-5M2V"),
                new List <Mosaic> {
                Mosaic.CreateFromIdentifier("nem:xem", 10)
            },
                SecureMessage.Create("hello", Config.PrivateKeyMain, "d72f89db8d0a3655168c9d2abe8de2910aaf4506a47d46e22ca48c7e0442e8ef")
                );

            TransactionHttp   transactionHttp   = new TransactionHttp("http://" + Config.Domain + ":7890");
            SignedTransaction signedTransaction = transaction.SignWith(keyPair);

            Thread.Sleep(2000);
            await transactionHttp.Announce(signedTransaction);

            Console.WriteLine(signedTransaction.Hash);
            Thread.Sleep(2000);
            return(true);
        }
Example #26
0
        public async Task GetMultisigGraphInfo()
        {
            var response = await new AccountHttp(host).GetMultisigAccountGraphInfo(new PublicAccount(KeyPair.CreateFromPrivateKey("9abcd1bd50b994799f8a2e27f7ffd952831ef16a443a48241f1f78942322d5c6").PublicKeyString, NetworkType.Types.MIJIN_TEST));

            Assert.AreEqual(2, response.MultisigAccounts[0][0].MinApproval);
            Assert.AreEqual(2, response.MultisigAccounts[0][0].MinRemoval);
            Assert.AreEqual("A8FCF4371B9C4B26CE19A407BA803D3813647608D57ABC1550925A54AEE2C9EA", response.MultisigAccounts[0][0].Account.PublicKey);
        }