public void TestImportNep6AndPassphraseWalletIsNotOpened() { var mockWalletManager = GetAWalletManagerWithoutAnWallet(); // Act IWalletAccount walletAccount = mockWalletManager.ImportEncryptedWif("6PYVwbrWfiyKCFnj4EjjBESUer4hbQ48hPfn8as8ivyS3FTVVmAJomvYuv", _defaultPassword); }
public override IWalletTransactionHistoryFileInfo UpdateLocalTransactionHistoryEntry(TransactionId transactionId, WalletTransactionHistory.TransactionStatuses status) { this.EnsureWalletLoaded(); IWalletTransactionHistoryFileInfo historyEntry = base.UpdateLocalTransactionHistoryEntry(transactionId, status); IWalletAccount account = this.WalletFileInfo.WalletBase.Accounts.Values.SingleOrDefault(a => (a.GetAccountId() == transactionId.Account) || (a.PresentationTransactionId == transactionId)); if (account == null) { throw new ApplicationException("Invalid account"); } if (historyEntry is INeuraliumWalletTransactionHistoryFileInfo neuraliumWalletTransactionHistoryFileInfo && this.WalletFileInfo.Accounts[account.AccountUuid] is INeuraliumAccountFileInfo neuraliumAccountFileInfo) { INeuraliumWalletTimelineFileInfo neuraliumWalletTimelineFileInfo = neuraliumAccountFileInfo.WalletTimelineFileInfo; if (status == WalletTransactionHistory.TransactionStatuses.Confirmed) { // now let's add a neuralium timeline entry neuraliumWalletTimelineFileInfo.ConfirmLocalTimelineEntry(transactionId); } else if (status == WalletTransactionHistory.TransactionStatuses.Rejected) { // now let's add a neuralium timeline entry neuraliumWalletTimelineFileInfo.RemoveLocalTimelineEntry(transactionId); } } return(historyEntry); }
/// <summary> /// Adds the or replace an account in the system. /// If the account with that scriptHash already exists, /// it's going to be replaced /// </summary> /// <param name="account">Account.</param> private void AddOrReplaceAccount(IWalletAccount account) { CheckWalletIsOpen(); var currentAccount = TryGetAccount(account.Contract.ScriptHash); if (currentAccount == null) { AddAccount(account); } else { //Account exists. Clone it. var clonedAccount = new NEP6Account(account.Contract) { Label = account.Label, IsDefault = account.IsDefault, Extra = account.Extra, Key = account.Key, Lock = account.Lock }; Wallet.Accounts.Remove(account); AddAccount(clonedAccount); } SaveWallet(); }
public void TestImportPrivateKeyWalletIsNotOpened() { var mockWalletManager = GetAWalletManagerWithoutAnWallet(); var privateKey = GetPrivateKeyFromWIF("KxLNhtdXXqaYUW1DKBc1XYQLxhouxXPLgQhR8kk7SYG3ajjR8M8a"); // Act IWalletAccount walletAccount = mockWalletManager.ImportPrivateKey(privateKey, _defaultPassword); }
public void TestImportWifWalletIsNotOpened() { var mockWalletManager = GetAWalletManagerWithoutAnWallet(); // Act IWalletAccount walletAccount = mockWalletManager.ImportWif("KxLNhtdXXqaYUW1DKBc1XYQLxhouxXPLgQhR8kk7SYG3ajjR8M8a", _defaultPassword); }
public void TestCreateAccountWithSamePassword() { var mockWalletManager = GetAWalletManagerWithAnWallet(); // Act IWalletAccount walletAccount = mockWalletManager.CreateAccount(_defaultPassword); IWalletAccount walletAccount2 = mockWalletManager.CreateAccount(_defaultPassword); }
/// <inheritdoc /> public ContractTransaction BuildContractTransaction( IWalletAccount from, TransactionAttribute[] attributes, TransactionOutput[] outputs) { //TODO #396: Complete transaction return(new ContractTransaction()); }
/// <summary> /// Adds the account to the Account list. /// </summary> /// <param name="account">Account.</param> private void AddAccount(IWalletAccount account) { var internalAccount = account ?? throw new ArgumentException(nameof(account)); account.ValidateAccount(); //Accounts is a set, it cannot contain duplicates. Wallet.Accounts.Add(account); SaveWallet(); }
public void TestDeleteAccountWalletIsNotOpened() { var mockWalletManager = GetAWalletManagerWithoutAnWallet(); IWalletAccount walletAccount = mockWalletManager.CreateAccount(_defaultPassword); Assert.IsTrue(mockWalletManager.Wallet.Accounts.ToList().Count == 1); mockWalletManager = new Nep6WalletManager(new FileWrapper(), new JsonConverterWrapper()); mockWalletManager.DeleteAccount(walletAccount.Contract.ScriptHash); }
public void TestGetAccountPublicKeyWalletIsNotOpened() { var mockWalletManager = GetAWalletManagerWithoutAnWallet(); // Act IWalletAccount walletAccount = mockWalletManager.ImportWif("KxLNhtdXXqaYUW1DKBc1XYQLxhouxXPLgQhR8kk7SYG3ajjR8M8a", _defaultPassword); byte[] privateKey = GetPrivateKeyFromWIF("KxLNhtdXXqaYUW1DKBc1XYQLxhouxXPLgQhR8kk7SYG3ajjR8M8a"); ECPoint publicKey = new ECPoint(Crypto.Default.ComputePublicKey(privateKey, true)); mockWalletManager = new Nep6WalletManager(new FileWrapper(), new JsonConverterWrapper()); IWalletAccount walletAccount2 = mockWalletManager.GetAccount(publicKey); }
public static void ValidateAccount(this IWalletAccount account) { if (account.Contract == null) { throw new ArgumentException("Empty contract"); } if (account.Contract.ScriptHash == null) { throw new ArgumentException("Invalid Script Hash"); } }
public void TestCreateAccountWithDifferentPassword() { var mockWalletManager = GetAWalletManagerWithAnWallet(); // Act IWalletAccount walletAccount = mockWalletManager.CreateAccount(_defaultPassword); var differentPassword = new SecureString(); differentPassword.AppendChar('x'); IWalletAccount walletAccount2 = mockWalletManager.CreateAccount(differentPassword); }
public void TestDeleteAccount() { var mockWalletManager = GetAWalletManagerWithAnWallet(); // Act IWalletAccount walletAccount = mockWalletManager.CreateAccount(_defaultPassword); Assert.IsTrue(mockWalletManager.Wallet.Accounts.ToList().Count == 1); mockWalletManager.DeleteAccount(walletAccount.Contract.ScriptHash); Assert.IsTrue(mockWalletManager.Wallet.Accounts.ToList().Count == 0); }
/// <summary> /// Adds the account to the Account list. /// </summary> /// <param name="account">Account.</param> private void AddAccount(IWalletAccount account) { var internalAccount = account ?? throw new ArgumentException(nameof(account)); account.ValidateAccount(); var accountList = Wallet.Accounts.ToList(); if (!accountList.Contains(account)) { accountList.Add(account); Wallet.Accounts = accountList.ToArray(); SaveWallet(); } }
public void TestImportWif() { var mockWalletManager = GetAWalletManagerWithAnWallet(); // Act IWalletAccount walletAccount = mockWalletManager.ImportWif("KxLNhtdXXqaYUW1DKBc1XYQLxhouxXPLgQhR8kk7SYG3ajjR8M8a", _defaultPassword); // Asset Assert.IsNotNull(walletAccount); String address = walletAccount.Contract.ScriptHash.ToAddress(); Assert.IsTrue(address.Equals("AdYJeaHepN3jmdUduBLWPESqwQ9QYQCFi7")); Assert.IsTrue(mockWalletManager.Wallet.Accounts.ToList().Count == 1); }
public void TestGetAccountPublicKey() { var mockWalletManager = GetAWalletManagerWithAnWallet(); // Act IWalletAccount walletAccount = mockWalletManager.ImportWif("KxLNhtdXXqaYUW1DKBc1XYQLxhouxXPLgQhR8kk7SYG3ajjR8M8a", _defaultPassword); byte[] privateKey = GetPrivateKeyFromWIF("KxLNhtdXXqaYUW1DKBc1XYQLxhouxXPLgQhR8kk7SYG3ajjR8M8a"); ECPoint publicKey = new ECPoint(Crypto.Default.ComputePublicKey(privateKey, true)); IWalletAccount walletAccount2 = mockWalletManager.GetAccount(publicKey); Assert.IsNotNull(walletAccount); //TODO: Improve //Assert.IsFalse(String.IsNullOrWhiteSpace(walletAccount.Address)); }
public void TestGetAccountPublicKey() { var mockWalletManager = GetAWalletManagerWithAnWallet(); // Act IWalletAccount walletAccount = mockWalletManager.ImportWif("KxLNhtdXXqaYUW1DKBc1XYQLxhouxXPLgQhR8kk7SYG3ajjR8M8a", _defaultPassword); byte[] privateKey = GetPrivateKeyFromWIF("KxLNhtdXXqaYUW1DKBc1XYQLxhouxXPLgQhR8kk7SYG3ajjR8M8a"); ECPoint publicKey = new ECPoint(Crypto.Default.ComputePublicKey(privateKey, true)); IWalletAccount walletAccount2 = mockWalletManager.GetAccount(publicKey); Assert.IsNotNull(walletAccount); Assert.AreEqual("AdYJeaHepN3jmdUduBLWPESqwQ9QYQCFi7", walletAccount.Address); }
public void TestImportNEP6AndPassphrase() { var mockWalletManager = GetAWalletManagerWithAnWallet(); // Act IWalletAccount walletAccount = mockWalletManager.ImportEncryptedWif("6PYVwbrWfiyKCFnj4EjjBESUer4hbQ48hPfn8as8ivyS3FTVVmAJomvYuv", _defaultPassword); // Asset Assert.IsNotNull(walletAccount); String address = walletAccount.Contract.ScriptHash.ToAddress(); Assert.IsTrue(address.Equals("AdYJeaHepN3jmdUduBLWPESqwQ9QYQCFi7")); Assert.IsTrue(mockWalletManager.Wallet.Accounts.ToList().Count == 1); }
/// <summary> /// Verifies the password. /// </summary> /// <returns><c>true</c>, if password was verifyed, <c>false</c> otherwise.</returns> /// <param name="walletAccout">Wallet accout.</param> /// <param name="password">Password.</param> public bool VerifyPassword(IWalletAccount walletAccout, SecureString password) { if (walletAccout == null) { throw new ArgumentException(); } try { _walletHelper.DecryptWif(walletAccout.Key, password); } catch (FormatException) { return(false); } return(true); }
/// <summary> /// Retrieves the account from the Account list using the script hash/ /// Replaces the account information with those provided in the newAccountInformation parameter /// Returns the account but does not save it /// This should be used when the user wants to update a current account, /// like replacing the paraters from the contract or replacing the label. /// </summary> /// <returns>The account.</returns> /// <param name="newAccountInformation">Account script hash.</param> private IWalletAccount CloneAndUpdate(IWalletAccount newAccountInformation) { newAccountInformation.ValidateAccount(); var currentAccountWithScriptHash = TryGetAccount(newAccountInformation.Contract.ScriptHash); if (currentAccountWithScriptHash == null) { throw new ArgumentException("Account not found."); } var clonedAccount = new NEP6Account(newAccountInformation.Contract) { Label = newAccountInformation.Label, IsDefault = newAccountInformation.IsDefault, Lock = newAccountInformation.Lock, }; return(clonedAccount); }
public override IWalletElectionsHistory InsertElectionsHistoryEntry(SynthesizedBlock.SynthesizedElectionResult electionResult, AccountId electedAccountId) { this.EnsureWalletLoaded(); IWalletElectionsHistory historyEntry = base.InsertElectionsHistoryEntry(electionResult, electedAccountId); // now let's add a neuralium timeline entry if (historyEntry is INeuraliumWalletElectionsHistory neuraliumWalletElectionsHistory && electionResult is NeuraliumSynthesizedBlock.NeuraliumSynthesizedElectionResult neuraliumSynthesizedElectionResult) { IWalletAccount account = this.WalletFileInfo.WalletBase.Accounts.Values.SingleOrDefault(a => a.GetAccountId() == electedAccountId); if (account == null) { throw new ApplicationException("Invalid account"); } if (this.WalletFileInfo.Accounts[account.AccountUuid] is INeuraliumAccountFileInfo neuraliumAccountFileInfo) { NeuraliumWalletTimeline neuraliumWalletTimeline = new NeuraliumWalletTimeline(); INeuraliumWalletTimelineFileInfo neuraliumWalletTimelineFileInfo = neuraliumAccountFileInfo.WalletTimelineFileInfo; neuraliumWalletTimeline.Timestamp = neuraliumSynthesizedElectionResult.Timestamp; neuraliumWalletTimeline.Amount = neuraliumSynthesizedElectionResult.ElectedGains[electedAccountId].bountyShare; neuraliumWalletTimeline.Tips = neuraliumSynthesizedElectionResult.ElectedGains[electedAccountId].tips; neuraliumWalletTimeline.RecipientAccountId = electedAccountId; neuraliumWalletTimeline.Direction = NeuraliumWalletTimeline.MoneratyTransactionTypes.Credit; neuraliumWalletTimeline.CreditType = NeuraliumWalletTimeline.CreditTypes.Election; neuraliumWalletTimeline.Total = this.GetAccountBalance(electedAccountId, false).Total + neuraliumWalletTimeline.Amount + neuraliumWalletTimeline.Tips; neuraliumWalletTimelineFileInfo.InsertTimelineEntry(neuraliumWalletTimeline); } } return(historyEntry); }
protected override void CreateNewAccountInfoContents(IAccountFileInfo accountFileInfo, IWalletAccount account) { this.EnsureWalletLoaded(); base.CreateNewAccountInfoContents(accountFileInfo, account); if (accountFileInfo is INeuraliumAccountFileInfo neuraliumAccountFileInfo) { neuraliumAccountFileInfo.WalletTimelineFileInfo = this.SerialisationFal.CreateNeuraliumWalletTimelineFileInfo(account, this.WalletFileInfo.WalletSecurityDetails); } }
/// <summary> /// Constructor /// </summary> public NEP6Wallet() { Scrypt = ScryptParameters.Default; Accounts = new IWalletAccount[0]; }
public UnspentCoinsDictionary GetBalance(IWalletAccount from) { throw new NotImplementedException(); }
/// <inheritdoc /> public InvocationTransaction BuildInvocationTransaction(IWalletAccount from, TransactionAttribute[] attributes, TransactionOutput[] outputs, string script, Fixed8 fee = default(Fixed8)) { //TODO #397: Complete transaction return(new InvocationTransaction()); }
public NeuraliumWalletAccountSnapshotFileInfo(IWalletAccount account, string filename, BlockchainServiceSet serviceSet, IWalletSerialisationFal serialisationFal, WalletPassphraseDetails walletSecurityDetails) : base(account, filename, serviceSet, serialisationFal, walletSecurityDetails) { }
public UInt256 BroadcastTransaction(IWalletAccount account, Transaction transaction) { throw new NotImplementedException(); }
protected override void FillJointAccountSnapshot(IWalletAccount account, IWalletJointAccountSnapshot accountSnapshot) { base.FillJointAccountSnapshot(account, accountSnapshot); // anything else? }
private void InsertNeuraliumTransactionTimelineEntry(ITransaction transaction, AccountId targetAccountId, INeuraliumWalletTransactionHistory neuraliumWalletTransactionHistory) { if ((neuraliumWalletTransactionHistory.Amount == 0) && (neuraliumWalletTransactionHistory.Tip == 0)) { // this transaction is most probably not a token influencing transaction. let's ignore 0 values return; } // this is an incomming transaction, now let's add a neuralium timeline entry IWalletAccount account = this.WalletFileInfo.WalletBase.Accounts.Values.SingleOrDefault(a => a.GetAccountId() == targetAccountId); if (account == null) { throw new ApplicationException("Invalid account"); } if (this.WalletFileInfo.Accounts[account.AccountUuid] is INeuraliumAccountFileInfo neuraliumAccountFileInfo) { NeuraliumWalletTimeline neuraliumWalletTimeline = new NeuraliumWalletTimeline(); INeuraliumWalletTimelineFileInfo neuraliumWalletTimelineFileInfo = neuraliumAccountFileInfo.WalletTimelineFileInfo; neuraliumWalletTimeline.Timestamp = this.serviceSet.TimeService.GetTimestampDateTime(transaction.TransactionId.Timestamp.Value, this.centralCoordinator.ChainComponentProvider.ChainStateProvider.ChainInception); neuraliumWalletTimeline.Amount = neuraliumWalletTransactionHistory.Amount; neuraliumWalletTimeline.Tips = 0; neuraliumWalletTimeline.TransactionId = transaction.TransactionId.ToString(); bool local = targetAccountId == transaction.TransactionId.Account; neuraliumWalletTimeline.SenderAccountId = transaction.TransactionId.Account; neuraliumWalletTimeline.RecipientAccountId = targetAccountId; decimal total = this.GetAccountBalance(targetAccountId, false).Total; if (local) { // in most cases, transactions we make wil be debits neuraliumWalletTimeline.Direction = NeuraliumWalletTimeline.MoneratyTransactionTypes.Debit; neuraliumWalletTimeline.Total = total - neuraliumWalletTimeline.Amount; neuraliumWalletTimeline.Tips = neuraliumWalletTransactionHistory.Tip; #if TESTNET || DEVNET if (transaction is INeuraliumRefillNeuraliumsTransaction) { neuraliumWalletTimeline.Total = total + neuraliumWalletTimeline.Amount; neuraliumWalletTimeline.Direction = NeuraliumWalletTimeline.MoneratyTransactionTypes.Credit; neuraliumWalletTimeline.CreditType = NeuraliumWalletTimeline.CreditTypes.Tranasaction; } #endif neuraliumWalletTimeline.Total -= neuraliumWalletTimeline.Tips; neuraliumWalletTimeline.Confirmed = false; } else { neuraliumWalletTimeline.Total = total + neuraliumWalletTimeline.Amount; neuraliumWalletTimeline.Confirmed = true; neuraliumWalletTimeline.Direction = NeuraliumWalletTimeline.MoneratyTransactionTypes.Credit; neuraliumWalletTimeline.CreditType = NeuraliumWalletTimeline.CreditTypes.Tranasaction; } neuraliumWalletTimelineFileInfo.InsertTimelineEntry(neuraliumWalletTimeline); } }
public INeuraliumWalletTimelineFileInfo CreateNeuraliumWalletTimelineFileInfo(IWalletAccount account, WalletPassphraseDetails walletPassphraseDetails) { return(new NeuraliumWalletTimelineFileInfo(account, this.GetNeuraliumWalletTimelinePath(account.AccountUuid), this.centralCoordinator.BlockchainServiceSet, this, walletPassphraseDetails)); }