Esempio n. 1
0
        public async Task AggregateNamespaceRentalExtensionShouldSucceed()
        {
            var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var transaction = RegisterNamespaceTransaction.CreateRootNamespace(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                "happy",
                10000)
                              .ToAggregate(PublicAccount.CreateFromPublicKey("B974668ABED344BE9C35EE257ACC246117EFFED939EAF42391AE995912F985FE", NetworkType.Types.MIJIN_TEST));

            var agg = AggregateTransaction.CreateComplete(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new List <Transaction>()
            {
                transaction
            })
                      .SignWith(signer);

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

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

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


            Assert.AreEqual(signer.PublicKeyString, status.Signer.PublicKey);
        }
Esempio n. 2
0
        /// <summary>
        ///     Gets the mosaic list.
        /// </summary>
        /// <param name="mosaicIDs">The mosaicId</param>
        /// <returns>IObservable&lt;List&lt;MosaicInfo&gt;&gt;</returns>
        /// <exception cref="ArgumentNullException">mosaicId</exception>
        public IObservable <List <MosaicInfo> > GetMosaicListAsync(List <string> mosaicIDs)
        {
            if (mosaicIDs.Count < 0)
            {
                throw new ArgumentNullException(nameof(mosaicIDs));
            }
            var route = $"{BasePath}/mosaic";

            var mosaicList = new MosaicIds
            {
                _MosaicIds = mosaicIDs
            };

            var networkType = GetNetworkTypeObservable().Take(1);

            return(Observable.FromAsync(async ar =>
                                        await route.PostJsonAsync(mosaicList).ReceiveJson <List <MosaicInfoDTO> >())
                   .Select(l => l.Select(info => new MosaicInfo(
                                             info.Meta.Id,
                                             new MosaicId(info.Mosaic.MosaicId.ToUInt64()),
                                             info.Mosaic.Supply.ToUInt64(),
                                             info.Mosaic.Height.ToUInt64(),
                                             PublicAccount.CreateFromPublicKey(info.Mosaic.Owner, networkType.Wait()),
                                             info.Mosaic.Revision,
                                             ExtractMosaicProperties(info.Mosaic.Properties),
                                             null
                                             )).ToList()));
        }
Esempio n. 3
0
        /// <summary>
        /// Get multisig graph information
        /// </summary>
        /// <param name="account">The account for which multisig graph information should be returned.</param>
        /// <returns>An IObservable list of MultisigAccountGraphInfoDTO</returns>
        /// <exception cref="ArgumentNullException">account</exception>
        public IObservable <MultisigAccountGraphInfo> GetMultisigAccountGraphInfo(Address account)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            return(Observable.FromAsync(async ar => await AccountRoutesApi.GetAccountMultisigGraphAsync(account.Plain))
                   .Select(entry =>
            {
                Dictionary <int, List <MultisigAccountInfo> > graphInfoMap = new Dictionary <int, List <MultisigAccountInfo> >();

                entry.ForEach(item => graphInfoMap.Add(
                                  item.Level,
                                  item.MultisigEntries.Select(i =>
                                                              new MultisigAccountInfo(
                                                                  PublicAccount.CreateFromPublicKey(
                                                                      i.Multisig.Account,
                                                                      GetNetworkTypeObservable().Wait()
                                                                      ),
                                                                  i.Multisig.MinApproval,
                                                                  i.Multisig.MinRemoval,
                                                                  i.Multisig.Cosignatories.Select(
                                                                      e => PublicAccount.CreateFromPublicKey(
                                                                          e, GetNetworkTypeObservable().Wait()
                                                                          )).ToList(),
                                                                  i.Multisig.MultisigAccounts.Select(
                                                                      o => PublicAccount.CreateFromPublicKey(
                                                                          o, GetNetworkTypeObservable().Wait()
                                                                          )).ToList())).ToList()));

                return new MultisigAccountGraphInfo(graphInfoMap);
            }));
        }
        public async Task SignAggregateTransactionComplete()
        {
            var signerKey =
                KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var account = new Account(Config.PrivateKeySecond,
                                      NetworkType.Types.MIJIN_TEST);

            var aggregateTransaction = AggregateTransaction.CreateComplete(
                NetworkType.Types.MIJIN_TEST,
                Deadline.CreateHours(2),
                new List <Transaction>
            {
                TransferTransactionTests.CreateInnerTransferTransaction("nem:xem")
                .ToAggregate(PublicAccount.CreateFromPublicKey(signerKey.PublicKeyString, NetworkType.Types.MIJIN_TEST)),
                TransferTransactionTests.CreateInnerTransferTransaction("nem:xem")
                .ToAggregate(PublicAccount.CreateFromPublicKey(account.PublicKey, NetworkType.Types.MIJIN_TEST))
            })
                                       .SignWithAggregateCosigners(signerKey, new List <Account>()
            {
                Account.CreateFromPrivateKey(Config.PrivateKeySecond,
                                             NetworkType.Types.MIJIN_TEST)
            }
                                                                   );

            WatchForFailure(aggregateTransaction);

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

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

            Assert.AreEqual(signerKey.PublicKeyString, status.Signer.PublicKey);
        }
        public async Task Get_Account_Property_By_PublicKey()
        {
            using (var httpTest = new HttpTest())
            {
                var fakeJson =
                    TestHelper.LoadJsonFileToObject(@"Testdata\\Account\\GetAccountPropertyByAddress.json");

                httpTest.RespondWithJson(fakeJson);

                var account        = PublicAccount.CreateFromPublicKey("EC49CB3C5E0F565F9D27F90FD5830E21DF08205353C837540088C18936E41397", NetworkType.TEST_NET);
                var blockedAddress = Address.CreateFromHex("A8DE118FEE2EA3EC52C03E37CD5F5764E3CDA9819D497692D5");

                var accountFilter = await _accountHttp.GetAccountProperty(account);

                accountFilter.Should().NotBeNull();

                var blockAddressFilter =
                    accountFilter.AccountProperties.Properties.Single(ap =>
                                                                      ap.PropertyType == PropertyType.BLOCK_ADDRESS);

                foreach (var ba in blockAddressFilter.Values)
                {
                    var ad = Address.CreateFromHex(ba.ToString());
                    ad.Should().NotBeNull();
                }

                blockAddressFilter.Should().NotBeNull();
                var resBlockedAddress = blockAddressFilter.Values.Single(a => Address.CreateFromHex(a.ToString()).Plain == blockedAddress.Plain);
                resBlockedAddress.Should().NotBeNull();
            }
        }
        public async Task AnnounceMultisigTransaction()
        {
            var cosignatory     = KeyPair.CreateFromPrivateKey("8db858dcc8e2827074498204b3829154ec4c4f24d13738d3f501003b518ef256");
            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);
        }
Esempio n. 7
0
        /// <summary>
        ///     Gets the namespace.
        /// </summary>
        /// <param name="namespaceId">The namespace Id</param>
        /// <returns>IObservable&lt;NamespaceInfo&gt;</returns>
        public IObservable <NamespaceInfo> GetNamespace(NamespaceId namespaceId)
        {
            var route = $"{BasePath}/namespace/{namespaceId.HexId}";

            if (namespaceId == null)
            {
                throw new ArgumentNullException(nameof(namespaceId));
            }

            var networkType = GetNetworkTypeObservable().Take(1);

            return(Observable.FromAsync(async ar => await route.GetJsonAsync <NamespaceInfoDTO>())
                   .Select(info => new NamespaceInfo(
                               info.Meta.Active,
                               info.Meta.Index,
                               info.Meta.Id,
                               NamespaceTypeExtension.GetRawValue((int)info.Namespace.Type),
                               info.Namespace.Depth,
                               ExtractLevels(info.Namespace.Level0, info.Namespace.Level1, info.Namespace.Level2),
                               info.Namespace.ParentId.ToUInt64() == 0
                        ? null
                        : new NamespaceId(info.Namespace.ParentId.ToUInt64()),
                               PublicAccount.CreateFromPublicKey(info.Namespace.Owner, networkType.Wait()),
                               info.Namespace.StartHeight.ToUInt64(),
                               info.Namespace.EndHeight.ToUInt64(),
                               new Alias(AliasTypeExtension.GetRawValue((int)info.Namespace.Alias.Type),
                                         info.Namespace.Alias.Address != null
                            ? Address.CreateFromHex(info.Namespace.Alias.Address)
                            : null,
                                         info.Namespace.Alias.MosaicId != null
                            ? new MosaicId(info.Namespace.Alias.MosaicId.ToUInt64())
                            : null
                                         )
                               )));
        }
        public void ShouldCreatePublicAccountViaStaticConstructor()
        {
            var publicAccount = PublicAccount.CreateFromPublicKey(publicKey, NetworkType.Types.TEST_NET);

            Assert.AreEqual(publicKey, publicAccount.PublicKey);
            Assert.AreEqual("TBDJXUULP2BRYNS7MWHY2WAFWKQNAF273KYBPFY5", publicAccount.Address.Plain);
        }
Esempio n. 9
0
        public void ShouldCreatePublicAccountViaStaticConstructor()
        {
            var publicAccount = PublicAccount.CreateFromPublicKey(publicKey, NetworkType.Types.MIJIN_TEST);

            Assert.AreEqual(publicKey, publicAccount.PublicKey);
            Assert.AreEqual("SARNASAS2BIAB6LMFA3FPMGBPGIJGK6IJETM3ZSP", publicAccount.Address.Plain);
        }
        public void Should_Create_From_Public_Key_PUBLIC_TEST()
        {
            var publicAccount = PublicAccount.CreateFromPublicKey(Constants.PUBLIC_TEST_PUBLIC_KEY, NetworkType.TEST_NET);

            publicAccount.Address.Pretty.Should().BeEquivalentTo(Constants.PUBLIC_TEST_PRETTY_ADDRESS);
            publicAccount.Address.Plain.Should().BeEquivalentTo(Constants.PUBLIC_TEST_PLAIN_ADDRESS);
        }
Esempio n. 11
0
        public static BalanceChangeReceipt FromDto(JObject dto, NetworkType networkType)
        {
            var type     = ReceiptTypeExtension.GetRawValue(dto["type"].ToObject <int>());
            var account  = PublicAccount.CreateFromPublicKey(dto["account"].ToObject <string>(), networkType);
            var mosaicId = dto["mosaicId"].ToObject <UInt64DTO>().ToUInt64();
            var amount   = dto["amount"].ToObject <UInt64DTO>().ToUInt64();

            return(new BalanceChangeReceipt(account, new MosaicId(mosaicId), amount, ReceiptVersion.BALANCE_CHANGE, type, null));
        }
Esempio n. 12
0
        /// <summary>
        /// </summary>
        /// <param name="accounts"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public IObservable <List <NamespaceInfo> > GetNamespacesFromAccount(List <Address> accounts, QueryParams query)
        {
            if (accounts.Count < 0)
            {
                throw new ArgumentNullException(nameof(accounts));
            }


            var addresses = new Addresses
            {
                _Addresses = accounts.Select(a => a.Plain).ToList()
            };

            var route = $"{BasePath}/account/namespaces";

            if (query != null)
            {
                if (query.PageSize > 0)
                {
                    route.SetQueryParam("pageSize", query.PageSize);
                }

                if (!string.IsNullOrEmpty(query.Id))
                {
                    route.SetQueryParam("id", query.Id);
                }
            }

            var networkType = GetNetworkTypeObservable().Take(1);

            return(Observable.FromAsync(async ar =>
                                        await route.PostJsonAsync(addresses).ReceiveJson <List <NamespaceInfoDTO> >())
                   .Select(i => i.Select(info => new NamespaceInfo(
                                             info.Meta.Active,
                                             info.Meta.Index,
                                             info.Meta.Id,
                                             NamespaceTypeExtension.GetRawValue((int)info.Namespace.Type),
                                             info.Namespace.Depth,
                                             ExtractLevels(info.Namespace.Level0, info.Namespace.Level1, info.Namespace.Level2),
                                             new NamespaceId(info.Namespace.ParentId.ToUInt64()),
                                             PublicAccount.CreateFromPublicKey(info.Namespace.Owner, networkType.Wait()),
                                             info.Namespace.StartHeight.ToUInt64(),
                                             info.Namespace.EndHeight.ToUInt64(),
                                             new Alias(AliasTypeExtension.GetRawValue((int)info.Namespace.Alias.Type),
                                                       info.Namespace.Alias.Address != null
                            ? Address.CreateFromRawAddress(info.Namespace.Alias.Address)
                            : null,
                                                       info.Namespace.Alias.MosaicId != null
                            ? new MosaicId(info.Namespace.Alias.MosaicId.ToUInt64())
                            : null
                                                       )
                                             )).ToList()));
        }
Esempio n. 13
0
        public async Task <TransactionResponse> Send(object data)
        {
            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);



            TransactionResponse response = await new TransactionHttp(host).Announce(multisigTransaction);

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

            TransactionResponse response2 = await new TransactionHttp(host).Announce(signatureTransaction);

            //var localVarPath = "/transaction/announce";
            //var client = new RestClient(host);
            //var request = new RestRequest(localVarPath, Method.POST);
            //request.AddParameter("application/json", data, ParameterType.RequestBody);
            //var resp = client.Execute(request);

            if (response.Status == "1")
            {
                TransactionInfo transactionInfo = new TransactionInfo
                {
                    Id = 1, Hash = response.Hash, InnerHash = response.InnerHash
                };
                _transactionInfoRepository.AddTransaction(transactionInfo);
            }

            return(null);
        }
        public async Task Get_Namespaces_By_PublicKey_Should_Return_NamespaceInfo_List()
        {
            using (var httpTest = new HttpTest())
            {
                var fakeJson = TestHelper.LoadJsonFileToArray(@"Testdata\\Namespace\\GetNamespacesbyAccountid.json");
                httpTest.RespondWithJson(fakeJson);
                var account = PublicAccount.CreateFromPublicKey("0D22E9D42F124072E14C4F804E4FC7F5431C831EAF03BEFD55D521B9A9D0B89D", NetworkType.TEST_NET);

                var namespaceInfoList = await _namespaceHttp.GetNamespacesFromAccount(account, null);

                // namespaceInfoList.
                namespaceInfoList.Should().NotBeEmpty();
            }
        }
Esempio n. 15
0
        public async Task CanDelegateImportanceUsingImportanceTransfer()
        {
            var keyPair = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);

            var importanceTransfer = ImportanceTransferTransaction.Create(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(1),
                ImportanceTransferMode.Mode.Add,
                PublicAccount.CreateFromPublicKey("6ea3fd5f2cf4fbeb54cd96a48d11cd2ff0b4106472c6a97c7e4e5736243cb2db", NetworkType.Types.TEST_NET))
                                     .SignWith(keyPair);

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

            Assert.AreEqual("FAILURE_IMPORTANCE_TRANSFER_NEEDS_TO_BE_DEACTIVATED", response.Message);
        }
Esempio n. 16
0
        /// <summary>
        /// Signs the transaction with the given <see cref="KeyPair"/>.
        /// </summary>
        /// <param name="keyPair">The <see cref="KeyPair"/>.</param>
        /// <returns><see cref="SignedTransaction"/>.</returns>
        /// <exception cref="ArgumentNullException">keyPair</exception>
        public SignedTransaction SignWith(KeyPair keyPair)
        {
            if (keyPair == null)
            {
                throw new ArgumentNullException(nameof(keyPair));
            }

            Signer = PublicAccount.CreateFromPublicKey(keyPair.PublicKeyString, NetworkType);

            Bytes = GenerateBytes();

            var sig = TransactionExtensions.SignTransaction(keyPair, Bytes);

            return(SignedTransaction.Create(Bytes, sig, TransactionExtensions.Hasher(Bytes), keyPair.PublicKey, TransactionType));
        }
        public async Task Get_Confirmed_Transaction_From_Account()
        {
            using (var httpTest = new HttpTest())
            {
                var fakeJson =
                    TestHelper.LoadJsonFileToObject(@"Testdata\\Account\\GetConfirmedTxFromAccount.json");

                httpTest.RespondWithJson(fakeJson);
                var account = PublicAccount.CreateFromPublicKey("6482AC2A82AC884B87B10D54120B28DB94AF56C596EA04AE54E77A4CE8A196F0", NetworkType.TEST_NET);

                var transactions = await _accountHttp.Transactions(account);

                transactions.Transactions.Should().HaveCount(1);
                transactions.Should().NotBeNull();
            }
        }
        public async Task CanCreateMosaicWithoutLevy()
        {
            var keyPair     = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain);
            var transaction = MosaicDefinitionTransaction.CreateWithoutLevy(
                NetworkType.Types.TEST_NET,
                Deadline.CreateHours(1),
                new MosaicProperties(4, 1000000000, true, true),
                MosaicId.CreateFromMosaicIdentifier("myspace:subspace"),
                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);
        }
        public async Task Get_OutGoing_Transaction_From_Account()
        {
            using (var httpTest = new HttpTest())
            {
                var fakeJson =
                    TestHelper.LoadJsonFileToArray(@"Testdata\\Account\\GetOutgoingTxFromAccount.json");

                httpTest.RespondWithJson(fakeJson);

                var account = PublicAccount.CreateFromPublicKey("D03918E35573C66578B5A0EED723FE2A46208783E13498751D9315115CA06D4B", NetworkType.MIJIN_TEST);

                var transactions = await _accountHttp.OutgoingTransactions(account, new QueryParams(10, "", Order.DESC));

                transactions.Should().HaveCountGreaterOrEqualTo(1);
            }
        }
        public async Task Get_Incoming_Transaction_From_Account()
        {
            using (var httpTest = new HttpTest())
            {
                var fakeJson =
                    TestHelper.LoadJsonFileToArray(@"Testdata\\Account\\GetIncomingTxFromAccount.json");

                httpTest.RespondWithJson(fakeJson);

                var account = PublicAccount.CreateFromPublicKey("D70ECC83DC6BDE5F8E1070A98ECB9B65B473F72E675E1366137AF56A55ECC902", NetworkType.MIJIN_TEST);

                var transactions = await _accountHttp.IncomingTransactions(account, new QueryParams(10, "", Order.DESC));

                transactions.Should().HaveCountGreaterOrEqualTo(1);
            }
        }
Esempio n. 21
0
        public void Should_Sign_Data_And_Verify_Signature()
        {
            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 signature = keyPair.Sign(data);
            var sigHex    = CryptoBytes.ToBase64String(signature);

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

            var isValid = publicAccount.VerifySignature(data, signature);

            isValid.Should().BeTrue();
        }
        public async Task Get_AccountInfo_By_PublicKey()
        {
            using (var httpTest = new HttpTest())
            {
                var fakeJson =
                    TestHelper.LoadJsonFileToObject(@"Testdata\\Account\\GetAccountInfoByPublicKey.json");

                httpTest.RespondWithJson(fakeJson);

                const string publicKey   = "20D57BED1C5DA5C224D83B22BEFF1CCC7D5D94054C9B75E83E08EF3ED5F992CD";
                var          account     = PublicAccount.CreateFromPublicKey(publicKey, NetworkType.MIJIN_TEST);
                var          accountInfo = await _accountHttp.GetAccountInfo(account.Address);

                accountInfo.Should().NotBeNull();
                accountInfo.PublicAccount.PublicKey.Should().BeEquivalentTo(publicKey);
            }
        }
Esempio n. 23
0
        internal BlockInfo Apply(string blockData)
        {
            var jobject = JObject.Parse(blockData);

            return(new BlockInfo
            {
                PreviousBlockHash = jobject["prevBlockHash"]["data"].ToString(),
                Height = ulong.Parse(jobject["height"].ToString()),
                Signer = PublicAccount.CreateFromPublicKey(jobject["signer"].ToString(), ExtractNetworkType(Int32.Parse(jobject["version"].ToString()))),
                Signature = jobject["signature"].ToString(),
                TimeStamp = int.Parse(jobject["timeStamp"].ToString()),
                Transactions = jobject["transactions"].ToList().Select(e => new TransactionMapping().Apply(e.ToString())).ToList(),
                Type = int.Parse(jobject["type"].ToString()),
                Version = ExtractVersion(int.Parse(jobject["version"].ToString())),
                Network = ExtractNetworkType(int.Parse(jobject["version"].ToString()))
            });
        }
        public async Task Get_AccountInfo_By_PublicKey()
        {
            using (var httpTest = new HttpTest())
            {
                var fakeJson =
                    TestHelper.LoadJsonFileToObject(@"Testdata\\Account\\GetAccountInfoByPublicKey.json");

                httpTest.RespondWithJson(fakeJson);

                const string publicKey   = "D9A659A3AA42FD62BE88E1D96B0F10EB91F6097F8D24EC8FD7C94EC6455735EC";
                var          account     = PublicAccount.CreateFromPublicKey(publicKey, NetworkType.TEST_NET);
                var          accountInfo = await _accountHttp.GetAccountInfo(account.Address);

                accountInfo.Should().NotBeNull();
                accountInfo.PublicAccount.PublicKey.Should().BeEquivalentTo(publicKey);
            }
        }
        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");
        }
        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 Get_UnConfirmed_Transaction_From_Account()
        {
            using (var httpTest = new HttpTest())
            {
                var fakeJson =
                    TestHelper.LoadJsonFileToArray(@"Testdata\\Account\\GetUnConfirmedTxFromAccount.json");

                httpTest.RespondWithJson(fakeJson);

                var account = PublicAccount.CreateFromPublicKey("B00D4317CC4FEB2976DF3EBEEF6A788B769F6F37B61883F24282ACA034C15DDF", NetworkType.MIJIN_TEST);

                var transactions = await _accountHttp.UnconfirmedTransactions(account, new QueryParams(10, "", Order.DESC));

                transactions.Should().HaveCount(1);
                transactions.First().TransactionType.Should().BeEquivalentTo(EntityType.TRANSFER);
                transactions.First().TransactionInfo.Should().NotBeNull();
            }
        }
        /// <summary>
        /// Gets mosaic info for a given namespace up to the provided database id with a given page size.
        /// </summary>
        /// <param name="nameSpace">The name space.</param>
        /// <param name="id">The database id of the namespace.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <returns>An IObservable List of MosaicInfo.</returns>
        /// <example>
        /// This sample shows how to use the <see>
        ///         <cref>GetNamespaceMosaics</cref>
        ///     </see>
        ///     method.
        /// <code>
        /// LList&lt;MosaicInfo&gt; namespaceInfo = await new NamespaceMosaicHttp("<!--insert host like: http://0.0.0.0:7890-->").GetNamespaceMosaics("test", "xyz", 10);
        /// </code>
        /// </example>
        public IObservable <List <MosaicInfo> > GetNamespaceMosaics(string nameSpace, string id, int pageSize)
        {
            return(Observable.FromAsync(async ar => await NamespaceMosaicRoutesApi.NamespaceMosaicInfoAsync(nameSpace, id, pageSize))

                   .Select(e =>
                           e.Select(i => new MosaicInfo(
                                        int.Parse(i["meta"]["id"].ToString()),
                                        PublicAccount.CreateFromPublicKey(i["mosaic"]["creator"].ToString(), GetNetworkTypeObservable().Wait()),
                                        i["mosaic"]["description"].ToString(),
                                        MosaicId.CreateFromMosaicIdentifier(i["mosaic"]["id"]["namespaceId"].ToString() + ":" + i["mosaic"]["id"]["name"].ToString()),
                                        new MosaicProperties(
                                            int.Parse(i["mosaic"]["properties"].ToList()[0]["value"].ToString()),
                                            ulong.Parse(i["mosaic"]["properties"].ToList()[1]["value"].ToString()),
                                            bool.Parse(i["mosaic"]["properties"].ToList()[2]["value"].ToString()),
                                            bool.Parse(i["mosaic"]["properties"].ToList()[3]["value"].ToString())),
                                        null)).ToList()
                           ));
        }
Esempio n. 29
0
        public void Should_Create_Id_Given_Nonce_And_Owner()
        {
            var owner = PublicAccount.CreateFromPublicKey(PublicKey, NetworkType.MIJIN_TEST);
            var bytes = new byte[4]
            {
                0x0, 0x0, 0x0, 0x0
            };

            var mosaicNonce = new MosaicNonce(bytes);
            var mosaicId    = MosaicId.CreateFromNonce(mosaicNonce, owner.PublicKey);

            var id = new UInt64DTO {
                481110499, 231112638
            };
            var expectedId = id.ToUInt64();

            mosaicId.Id.Should().Be(expectedId);
        }
Esempio n. 30
0
        /// <summary>
        /// Signs the MultisigTransaction with a KeyPair and sets the inner transaction signer.
        /// </summary>
        /// <param name="cosignatory">The cosignatory.</param>
        /// <param name="multisigAccount">The multisig account.</param>
        /// <returns>SignedMultisigTransaction.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// cosignatory
        /// or
        /// multisigAccount
        /// </exception>
        public SignedMultisigTransaction SignWith(KeyPair cosignatory, PublicAccount multisigAccount)
        {
            if (cosignatory == null)
            {
                throw new ArgumentNullException(nameof(cosignatory));
            }
            if (multisigAccount == null)
            {
                throw new ArgumentNullException(nameof(multisigAccount));
            }

            Signer = PublicAccount.CreateFromPublicKey(cosignatory.PublicKeyString, NetworkType);
            InnerTransaction.Signer = multisigAccount;
            Bytes = GenerateBytes();
            var sig = TransactionExtensions.SignTransaction(cosignatory, Bytes);

            return(SignedMultisigTransaction.Create(Bytes, sig, TransactionExtensions.Hasher(Bytes), InnerTransaction.CreateTransactionHash().FromHex(), cosignatory.PublicKey, TransactionType));
        }