/// <summary> /// Converts to AccountLinkTransactionMapping /// </summary> /// <param name="tx"></param> /// <param name="txInfo"></param> /// <returns></returns> private static AccountLinkTransaction ToAccountLinkTransaction(JObject tx, TransactionInfo txInfo) { var transaction = tx["transaction"].ToObject <JObject>(); var version = transaction["version"]; //Bug - It seems the dotnetcore does not //understand the Integer. //The workaround it to double cast the version int versionValue; try { versionValue = (int)((uint)version); } catch (Exception) { versionValue = (int)version; } var network = TransactionMappingUtils.ExtractNetworkType(versionValue); var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue); var deadline = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64()); var maxFee = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64(); var signature = transaction["signature"].ToObject <string>(); var signer = new PublicAccount(transaction["signer"].ToObject <string>(), network); var remoteAccount = new PublicAccount(transaction["remoteAccountKey"].ToObject <string>(), network); var action = transaction["action"] ?? transaction["linkAction"]; var linkAction = AccountLinkActionExtension.GetRawValue(action.ToObject <int>()); return(new AccountLinkTransaction(network, txVersion, deadline, maxFee, EntityType.LINK_ACCOUNT, remoteAccount, linkAction, signature, signer)); }
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); }
/// <summary> /// Gets a MultisigAccountGraphInfo for an account. /// </summary> /// <param name="accountId">The public account</param> /// <returns>IObservable<MultisigAccountGraphInfo></returns> public IObservable <MultisigAccountGraphInfo> GetMultisigAccountGraphInfo(PublicAccount accountId) { if (accountId == null) { throw new ArgumentNullException(nameof(accountId)); } var route = $"{BasePath}/account/{accountId.PublicKey}/multisig/graph"; var networkType = GetNetworkTypeObservable().Take(1); return(Observable.FromAsync(async ar => await route.GetJsonAsync <List <MultisigAccountGraphInfoDTO> >()) .Select(entry => { var graphInfoMap = new Dictionary <int, List <MultisigAccountInfo> >(); entry.ForEach(item => graphInfoMap.Add( item.Level.Value, item.MultisigEntries.Select(info => new MultisigAccountInfo( new PublicAccount(info.Multisig.Account, networkType.Wait()), info.Multisig.MinApproval.Value, info.Multisig.MinRemoval.Value, info.Multisig.Cosignatories.Select(cos => new PublicAccount( cos, networkType.Wait())).ToList(), info.Multisig.MultisigAccounts.Select(mul => new PublicAccount( mul, networkType.Wait())).ToList())).ToList())); return new MultisigAccountGraphInfo(graphInfoMap); } )); }
public bool Start(HostControl hostControl) { if (string.IsNullOrEmpty(TestConfig.Instance.ServerUrl)) { throw new Exception("Url为空 无法启动服务器"); } Pioneer.WxSdk.SdkSetup.MessageTokenGetter = (dic) => { PublicAccount pa = new PublicAccount(); pa.EncryptionKey = TestConfig.Instance.EncryptionKey; pa.MessageToken = TestConfig.Instance.Token; pa.AppId = TestConfig.Instance.AppId; return pa; }; SdkSetup.RegisterListener(new WxSdk.Message.DefaultMessageListener()); StartOptions so = new StartOptions(); so.Urls.Add(TestConfig.Instance.ServerUrl); innerHost = WebApp.Start(so, builder => { builder.Use(new MessageModel().ProcessRequest); }); logger.Info("监听地址:" + TestConfig.Instance.ServerUrl); logger.Info("启动成功"); return true; }
/// <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); })); }
/// <summary> /// Get multisig account information. /// </summary> /// <param name="account">The account for which multisig info should be returned.</param> /// <returns>An IObservable of type MultisigEntryDTO.</returns> /// <exception cref="ArgumentNullException">account</exception> public IObservable <MultisigAccountInfo> GetMultisigAccountInfo(PublicAccount account) { if (account == null) { throw new ArgumentNullException(nameof(account)); } IObservable <NetworkType.Types> networkTypeResolve = GetNetworkTypeObservable().Take(1); return(Observable.FromAsync(async ar => await AccountRoutesApi.GetAccountMultisigAsync(account.PublicKey)) .Select(entry => new MultisigAccountInfo( new PublicAccount( entry.Multisig.Account, networkTypeResolve.Wait()), entry.Multisig.MinApproval, entry.Multisig.MinRemoval, entry.Multisig.Cosignatories.Select( cosig => new PublicAccount( cosig, networkTypeResolve.Wait()) ).ToList(), entry.Multisig.MultisigAccounts.Select( cosig => new PublicAccount( cosig, networkTypeResolve.Wait()) ).ToList())).Take(1)); }
/// <summary> /// Gets the namespaces from account. /// </summary> /// <param name="account">The account.</param> /// <param name="query">The query.</param> /// <returns>IObservable<List<NamespaceInfoDTO>>.</returns> /// <exception cref="ArgumentNullException">account /// or /// query</exception> public IObservable <List <NamespaceInfo> > GetNamespacesFromAccount(PublicAccount account, QueryParams query) { if (account == null) { throw new ArgumentNullException(nameof(account)); } if (query == null) { throw new ArgumentNullException(nameof(query)); } IObservable <NetworkType.Types> networkTypeResolve = GetNetworkTypeObservable().Take(1); return(Observable.FromAsync(async ar => await NamespaceRoutesApi.GetNamespacesFromAccountAsync(account.PublicKey, query.GetPageSize(), query.GetId())) .Select(i => i.Select(e => new NamespaceInfo( e.Meta.Active, e.Meta.Index, e.Meta.Id, NamespaceTypes.GetRawValue(e.Namespace.Type), e.Namespace.Depth, ExtractLevels(e.Namespace), new NamespaceId(e.Namespace.ParentId), e.Namespace.StartHeight, e.Namespace.EndHeight, new PublicAccount(e.Namespace.Owner, networkTypeResolve.Wait()) )).ToList())); }
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); }
/// <summary> /// 删除公众号推广信息 /// </summary> /// <param name="publicaccount"></param> /// <param name="workUser"></param> /// <returns></returns> public ReturnValueModel DeletePublicAccount(PublicAccount publicAccount, WorkUser workUser) { ReturnValueModel rvm = new ReturnValueModel(); //查询要删除的对象 var deletePublic = _rep.FirstOrDefault <PublicAccount>(s => s.Id == publicAccount.Id && s.IsDeleted != 1 /*"select * from PublicAccount where Id='"+publicaccount.Id+"' and IsDeleted=0"*/); //判断需要删除的数据是否存在 if (deletePublic != null) { try { deletePublic.IsDeleted = 1; deletePublic.UpdateTime = DateTime.Now; deletePublic.UpdateUser = workUser.User.Id; _rep.Delete(deletePublic); var send = _rep.SaveChanges(); } catch (Exception ex) { rvm.Success = false; rvm.Msg = "'" + ex + "'"; throw; } rvm.Success = true; rvm.Msg = "success"; rvm.Result = deletePublic ?? deletePublic; } else { rvm.Success = true; rvm.Msg = "No such data was found."; } return(rvm); }
public static RequestMessage DeSerialize(Stream stream, string encrypttype, PublicAccount pi) { XmlDocument x = new XmlDocument(); x.Load(stream); logger.Trace("sourceXml"); logger.Trace(x.OuterXml); if (encrypttype == "raw") {//明文模式 直接反序列化 return DeSerialize(x.OuterXml); } else if (encrypttype == "aes") { using (StringReader sr = new StringReader(x.OuterXml)) { using (XmlReader xr = XmlReader.Create(sr)) { System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(RequestMessage)); RequestMessage rm = xs.Deserialize(xr) as RequestMessage; MessageCryptor mc = new MessageCryptor(pi.MessageToken, pi.EncryptionKey, pi.AppId); string emessage = mc.Decrypt(rm.Encrypt); return DeSerialize(emessage); } } } else { throw new NotSupportedException(); } }
public void Should_Create_From_Construction_PUBLIC() { var publicAccount = new PublicAccount(Constants.PUBLIC_PUBLIC_KEY, NetworkType.MAIN_NET); publicAccount.Address.Pretty.Should().BeEquivalentTo(Constants.PUBLIC_PRETTY_ADDRESS); publicAccount.Address.Plain.Should().BeEquivalentTo(Constants.PUBLIC_PLAIN_ADDRESS); }
/// <summary> /// Gets the namespace. /// </summary> /// <param name="namespaceId">The namespace Id</param> /// <returns>IObservable<NamespaceInfo></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 ) ))); }
/// <summary> /// Initializes a new instance of the <see cref="RegisterNamespaceTransaction"/> class. /// </summary> /// <param name="type">The type.</param> /// <param name="version">The version.</param> /// <param name="deadline">The deadline.</param> /// <param name="fee">The fee.</param> /// <param name="namespaceType">Type of the namespace.</param> /// <param name="duration">The duration.</param> /// <param name="parentId">The parent identifier.</param> /// <param name="namespaceName">Name of the namespace.</param> /// <param name="signer">The signer.</param> /// <param name="signature">The signature.</param> /// <param name="transactionInfo">The transaction information.</param> /// <exception cref="ArgumentNullException">parentId</exception> /// <exception cref="InvalidEnumArgumentException">type</exception> /// <exception cref="ArgumentOutOfRangeException">namespaceType</exception> public RegisterNamespaceTransaction(NetworkType.Types type, int version, Deadline deadline, ulong fee, byte namespaceType, ulong duration, NamespaceId parentId, NamespaceId namespaceName, PublicAccount signer, string signature, TransactionInfo transactionInfo) { if (parentId == null && namespaceName == null) { throw new ArgumentNullException(nameof(parentId) + " and " + nameof(namespaceName) + " cannot both be null"); } if (!Enum.IsDefined(typeof(NetworkType.Types), type)) { throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(NetworkType.Types)); } if (namespaceType != 0 && namespaceType != 1) { throw new ArgumentOutOfRangeException(nameof(namespaceType)); } NetworkType = type; Version = version; Deadline = deadline; Fee = fee; NamespaceType = NamespaceTypes.GetRawValue(namespaceType); TransactionType = TransactionTypes.Types.RegisterNamespace; Duration = duration; ParentId = parentId; NamespaceId = namespaceName; Signer = signer; Signature = signature; TransactionInfo = transactionInfo; }
/// <summary> /// Mosaic Metadata /// </summary> /// <param name="deadline"></param> /// <param name="account"></param> /// <param name="targetMosaicId"></param> /// <param name="scopedKey"></param> /// <param name="newValue"></param> /// <param name="oldValue"></param> /// <param name="networkType"></param> /// <returns></returns> public static MosaicMetadataTransaction Create(Deadline deadline, PublicAccount account, MosaicId targetMosaicId, string scopedKey, string newValue, string oldValue, NetworkType networkType, ulong?maxFee = 0) { byte[] newV = Encoding.UTF8.GetBytes(newValue); byte[] oldV = Encoding.UTF8.GetBytes(oldValue); byte[] scope_key = Encoding.UTF8.GetBytes(scopedKey); var scopekey = CryptoUtils.Sha3_256_To_Ulong(scope_key); var ValueSizeDelta = Convert.ToInt16(newV.Length - oldV.Length); var newValueSize = Math.Max(newV.Length, oldV.Length); valueDifference_Bytes = Converter.CompareValues(newV, oldV); return(new MosaicMetadataTransaction( networkType, EntityVersion.METADATA_MOSAIC.GetValue(), EntityType.MOSAIC_METADATA_V2, deadline, maxFee, scopekey, account, targetMosaicId, newValue, ValueSizeDelta, (ushort)newValueSize )); }
/// <summary> /// Modifies namespace metadata /// </summary> /// <param name="deadline"></param> /// <param name="namespaceId"></param> /// <param name="modifications"></param> /// <param name="networkType"></param> /// <returns></returns> public static NamespaceMetadataTransaction Create(Deadline deadline, PublicAccount account, NamespaceId targetNamespaceId, string scopedKey, string newValue, string oldValue, NetworkType networkType, ulong?maxFee = 0) { byte[] newV = Encoding.UTF8.GetBytes(newValue); byte[] oldV = Encoding.UTF8.GetBytes(oldValue); byte[] scope_key_byte = Encoding.UTF8.GetBytes(scopedKey); var scopekey = CryptoUtils.Sha3_256_To_Ulong(scope_key_byte); var deltasize = (newV.Length - oldV.Length); var ValueSizeDelta = Convert.ToInt16(deltasize); var max_Value_Size_Bytes = Math.Max(newV.Length, oldV.Length); valueDifference_Bytes = Converter.CompareValues(newV, oldV); return(new NamespaceMetadataTransaction( networkType, EntityVersion.METADATA_NAMESPACE.GetValue(), EntityType.NAMESPACE_METADATA_V2, deadline, maxFee, scopekey, account, targetNamespaceId, newValue, ValueSizeDelta, (ushort)max_Value_Size_Bytes )); }
public void Compare_Public_Account_On_Same_Different_Network() { var publicAccount = new PublicAccount(Constants.PUBLIC_TEST_PUBLIC_KEY, NetworkType.MAIN_NET); var publicAccount2 = new PublicAccount(Constants.PUBLIC_TEST_PUBLIC_KEY, NetworkType.TEST_NET); publicAccount.Should().NotBe(publicAccount2); }
private static MosaicSupplyChangeTransaction ToMosaicSupplyChangeTransaction(JObject tx, TransactionInfo txInfo) { var transaction = tx["transaction"].ToObject <JObject>(); var version = transaction["version"]; //Bug - It seems the dotnetcore does not //understand the Integer. //The workaround it to double cast the version int versionValue; try { versionValue = (int)((uint)version); } catch (Exception) { versionValue = (int)version; } var network = TransactionMappingUtils.ExtractNetworkType(versionValue); var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue); var deadline = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64()); var maxFee = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64() ?? 0; var mosaicId = new MosaicId(transaction["mosaicId"].ToObject <UInt64DTO>().ToUInt64()); var mosaicSupplyType = MosaicSupplyTypeExtension.GetRawValue(transaction["direction"].ToObject <int>()); var delta = transaction["delta"].ToObject <UInt64DTO>().ToUInt64(); var signature = transaction["signature"].ToObject <string>(); var signer = new PublicAccount(transaction["signer"].ToObject <string>(), network); return(new MosaicSupplyChangeTransaction(network, txVersion, deadline, maxFee, mosaicId, mosaicSupplyType, delta, signature, signer, txInfo)); }
private static AccountMetadataTransaction ToMetadataTransaction(JObject tx, TransactionInfo txInfo) { var transaction = tx["transaction"].ToObject <JObject>(); var version = transaction["version"]; //Bug - It seems the dotnetcore does not //understand the Integer. //The workaround it to double cast the version int versionValue; try { versionValue = (int)((uint)version); } catch (Exception) { versionValue = (int)version; } var network = TransactionMappingUtils.ExtractNetworkType(versionValue); var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue); var deadline = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64()); var maxFee = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64(); var signature = transaction["signature"].ToObject <string>(); var signer = new PublicAccount(transaction["signer"].ToObject <string>(), network); var type = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>()); var scopedMetadataKey = transaction["scopedMetadataKey"].ToObject <UInt64DTO>().ToUInt64(); var targetKey = new PublicAccount(transaction["targetKey"].ToObject <string>(), network); var valueSizeDelta = transaction["valueSizeDelta"].ToObject <short>(); var valueSize = transaction["valueSize"].ToObject <ushort>(); var value = transaction["value"].ToObject <string>(); var accountMetadataTransaction = new AccountMetadataTransaction(network, txVersion, type, deadline, maxFee, scopedMetadataKey, targetKey, value, valueSizeDelta, valueSize, signature, signer, txInfo); return(accountMetadataTransaction); }
public void ShouldCreatePublicAccountViaStaticConstructor() { var publicAccount = PublicAccount.CreateFromPublicKey(publicKey, NetworkType.Types.MIJIN_TEST); Assert.AreEqual(publicKey, publicAccount.PublicKey); Assert.AreEqual("SARNASAS2BIAB6LMFA3FPMGBPGIJGK6IJETM3ZSP", publicAccount.Address.Plain); }
/// <summary> /// ToModifyAccountPropertyTransaction /// </summary> /// <param name="tx"></param> /// <param name="txInfo"></param> /// <returns></returns> private static ModifyAccountPropertyTransaction <IUInt64Id> ToModifyAccountPropertyTransaction(JObject tx, TransactionInfo txInfo) { var transaction = tx["transaction"].ToObject <JObject>(); var version = transaction["version"]; //Bug - It seems the dotnetcore does not //understand the Integer. //The workaround it to double cast the version int versionValue; try { versionValue = (int)((uint)version); } catch (Exception) { versionValue = (int)version; } var network = TransactionMappingUtils.ExtractNetworkType(versionValue); var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue); var deadline = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64()); var maxFee = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64(); var signature = transaction["signature"].ToObject <string>(); var signer = new PublicAccount(transaction["signer"].ToObject <string>(), network); var type = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>()); var propertyType = PropertyTypeExtension.GetRawValue(transaction["propertyType"].ToObject <int>()); var modifications = transaction["modifications"]; var modificationList = modifications == null ? new List <AccountPropertyModification <IUInt64Id> >() : modifications.Select(e => { var mt = e["modificationType"] ?? e["type"]; var modificationType = PropertyModificationTypeExtension.GetRawValue(mt.ToObject <int>()); var mosaicId = new MosaicId(e["value"].ToObject <UInt64DTO>().ToUInt64()); var modification = new AccountPropertyModification <IUInt64Id>(modificationType, mosaicId); return(modification); }).ToList(); if (type == EntityType.MODIFY_ACCOUNT_PROPERTY_MOSAIC) { return(new MosaicModification( network, txVersion, deadline, propertyType, modificationList, maxFee, signature, signer, txInfo )); } throw new Exception("Unsupported transaction type"); }
private AggregateTransaction ToAggregateTransactionTransaction(JObject tx, TransactionInfo txInfo) { var transaction = tx["transaction"].ToObject <JObject>(); var version = transaction["version"]; //Bug - It seems the dotnetcore does not //understand the Integer. //The workaround it to double cast the version int versionValue; try { versionValue = (int)((uint)version); } catch (Exception) { versionValue = (int)version; } var network = TransactionMappingUtils.ExtractNetworkType(versionValue); var type = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>()); var deadline = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64()); var maxFee = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64(); var innerTransactions = MapInnerTransactions(tx); var cosignatures = MapCosignatures(tx); var signature = transaction["signature"].ToObject <string>(); var signer = new PublicAccount(transaction["signer"].ToObject <string>(), network); return(new AggregateTransaction( network, TransactionMappingUtils.ExtractTransactionVersion(versionValue), type, deadline, maxFee, innerTransactions, cosignatures, signature, signer, txInfo)); }
/// <summary> /// ToSecretProofTransaction /// </summary> /// <param name="tx"></param> /// <param name="txInfo"></param> /// <returns></returns> private static SecretProofTransaction ToSecretProofTransaction(JObject tx, TransactionInfo txInfo) { var transaction = tx["transaction"].ToObject <JObject>(); var version = transaction["version"]; //Bug - It seems the dotnetcore does not //understand the Integer. //The workaround it to double cast the version int versionValue; try { versionValue = (int)((uint)version); } catch (Exception) { versionValue = (int)version; } var network = TransactionMappingUtils.ExtractNetworkType(versionValue); var txVersion = TransactionMappingUtils.ExtractTransactionVersion(versionValue); var deadline = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64()); var maxFee = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64(); var signature = transaction["signature"].ToObject <string>(); var signer = new PublicAccount(transaction["signer"].ToObject <string>(), network); var recipient = Recipient.From(Address.CreateFromHex(transaction["recipient"].ToObject <string>())); var hashType = HashTypeExtension.GetRawValue(transaction["hashAlgorithm"].ToObject <int>()); var secret = transaction["secret"].ToObject <string>(); var proof = transaction["proof"].ToObject <string>(); return(new SecretProofTransaction( network, txVersion, deadline, maxFee, hashType, recipient, secret, proof, signature, signer, txInfo)); }
public void ShouldCreatePublicAccountViaStaticConstructor() { var publicAccount = PublicAccount.CreateFromPublicKey(publicKey, NetworkType.Types.TEST_NET); Assert.AreEqual(publicKey, publicAccount.PublicKey); Assert.AreEqual("TBDJXUULP2BRYNS7MWHY2WAFWKQNAF273KYBPFY5", publicAccount.Address.Plain); }
/// <summary> /// Checks if the aggregate is either initiated or signed the by account as a cosignature. /// </summary> /// <param name="publicAccount">The public account.</param> /// <returns><c>true</c> if signed by the account, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">publicAccount</exception> public bool IsSignedByAccount(PublicAccount publicAccount) { Guard.NotNull(publicAccount, nameof(publicAccount), "Public account should not be null"); return(Signer.PublicKey == publicAccount.PublicKey || Cosignatures.Any(e => e.Signer.PublicKey == publicAccount.PublicKey)); }
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); }
public void EqualityIsBasedOnPublicKeyAndNetwork() { var publicAccount = new PublicAccount(publicKey, NetworkType.Types.MIJIN_TEST); var publicAccount2 = new PublicAccount(publicKey, NetworkType.Types.MIJIN_TEST); Assert.AreEqual(publicAccount.Address.Pretty, publicAccount2.Address.Pretty); }
public void Compare_Public_Account_On_Same_Network() { var publicAccount = new PublicAccount(Constants.PUBLIC_TEST_PUBLIC_KEY, NetworkType.TEST_NET); var publicAccount2 = new PublicAccount(Constants.PUBLIC_TEST_PUBLIC_KEY, NetworkType.TEST_NET); publicAccount2.Should().BeEquivalentTo(publicAccount); }
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); }
/// <summary> /// Gets the mosaic list. /// </summary> /// <param name="mosaicIDs">The mosaicId</param> /// <returns>IObservable<List<MosaicInfo>></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())); }
public ExchangeOffer(Mosaic mosaic, ulong cost, ExchangeOfferType type, PublicAccount owner) { MosaicId = mosaic.Id; MosaicAmount = mosaic.Amount; Cost = cost; Type = type; Owner = owner; }
public BlockchainUpgradeTransaction(NetworkType networkType, int version, EntityType transactionType, Deadline deadline, ulong?maxFee, ulong upgradePeriod, BlockchainVersion newVersion, string signature = null, PublicAccount signer = null, TransactionInfo transactionInfo = null) : base(networkType, version, transactionType, deadline, maxFee, signature, signer, transactionInfo) { UpgradePeriod = upgradePeriod; NewVersion = newVersion; }
public static PublicAccount Refresh(PublicAccount ato) { PublicAccount tmpAto = null; if (tokens.TryGetValue(ato.OriginalId, out tmpAto)) { if (!tmpAto.IsExpired) { return tmpAto; } } return RegetAccessToken(ato); }
public static PublicAccount RegetAccessToken(PublicAccount ato) { AccessTokenRequest atr = new AccessTokenRequest(); atr.PublicAccountInfo = ato; var ret = atr.GetResponse(); ato.LastUpdateTime = DateTime.Now; ato.AccessToken = ret.Access_token; tokens[ato.OriginalId] = ato; return ato; }
internal static void Replace(PublicAccount ato) { tokens[ato.OriginalId] = ato; }