Exemple #1
0
        private void PostTransfer(ApplicationEngine engine, UInt160 from, UInt160 to, byte[] tokenId)
        {
            engine.SendNotification(Hash, "Transfer",
                                    new Array {
                from?.ToArray() ?? StackItem.Null, to?.ToArray() ?? StackItem.Null, 1, tokenId
            });

            if (to is not null && ContractManagement.GetContract(engine.Snapshot, to) is not null)
            {
                engine.CallFromNativeContract(Hash, to, "onNEP11Payment", from?.ToArray() ?? StackItem.Null, 1, tokenId);
            }
        }
Exemple #2
0
        private void PostTransfer(ApplicationEngine engine, UInt160 from, UInt160 to, BigInteger amount, StackItem data, bool callOnPayment)
        {
            // Send notification

            engine.SendNotification(Hash, "Transfer",
                new Array { from?.ToArray() ?? StackItem.Null, to?.ToArray() ?? StackItem.Null, amount });

            // Check if it's a wallet or smart contract

            if (!callOnPayment || to is null || ContractManagement.GetContract(engine.Snapshot, to) is null) return;

            // Call onNEP17Payment method

            engine.CallFromNativeContract(Hash, to, "onNEP17Payment", from?.ToArray() ?? StackItem.Null, amount, data);
        }
Exemple #3
0
 public override WAccount GetAccount(UInt160 publicKeyHash)
 {
     using (WalletDataContext ctx = new WalletDataContext(path))
     {
         return GetAccountInternal(ctx.Accounts.FirstOrDefault(p => p.PublicKeyHash == publicKeyHash.ToArray())?.PrivateKeyEncrypted);
     }
 }
Exemple #4
0
 private void PostTransfer(ApplicationEngine engine, UInt160 from, UInt160 to, byte[] tokenId)
 {
     engine.SendNotification(Hash, "Transfer",
                             new Array {
         from?.ToArray() ?? StackItem.Null, to?.ToArray() ?? StackItem.Null, 1, tokenId
     });
 }
Exemple #5
0
            public override StackItem ToStackItem(ReferenceCounter referenceCounter)
            {
                Struct @struct = (Struct)base.ToStackItem(referenceCounter);

                @struct.Add(Expiration);
                @struct.Add(Admin?.ToArray() ?? StackItem.Null);
                return(@struct);
            }
Exemple #6
0
        private void PostTransfer(ApplicationEngine engine, UInt160 from, UInt160 to, BigInteger amount, StackItem data)
        {
            // Send notification

            engine.SendNotification(Hash, "Transfer",
                                    new Array {
                from?.ToArray() ?? StackItem.Null, to?.ToArray() ?? StackItem.Null, amount
            });

            // Check if it's a wallet or smart contract

            if (to is null || engine.Snapshot.Contracts.TryGet(to) is null)
            {
                return;
            }

            // Call onPayment method (NEP-17)

            engine.CallFromNativeContract(null, to, "onPayment", from?.ToArray() ?? StackItem.Null, amount, data);
        }
Exemple #7
0
        private void OnDumpStorage(uint network, UInt160 key = null)
        {
            string path   = $"dump_{network:x8}.json";
            var    states = systems[network].StoreView.Find(key?.ToArray());
            JArray array  = new JArray(states.Where(p => !Settings.Default.Exclude.Contains(p.Key.Id)).Select(p => new JObject
            {
                ["key"]   = Convert.ToBase64String(p.Key.ToArray()),
                ["value"] = Convert.ToBase64String(p.Value.ToArray())
            }));

            File.WriteAllText(path, array.ToString());
            Console.WriteLine($"States ({array.Count}) have been dumped into file {path}");
        }
Exemple #8
0
 public override bool DeleteAccount(UInt160 publicKeyHash)
 {
     bool flag = base.DeleteAccount(publicKeyHash);
     if (flag)
     {
         using (WalletDataContext ctx = new WalletDataContext(DbPath))
         {
             Account account = ctx.Accounts.FirstOrDefault(p => p.PublicKeyHash.SequenceEqual(publicKeyHash.ToArray()));
             if (account != null)
             {
                 ctx.Accounts.Remove(account);
                 ctx.SaveChanges();
             }
         }
     }
     return flag;
 }
Exemple #9
0
        public override bool DeleteAccount(UInt160 scriptHash)
        {
            UserWalletAccount account;

            lock (accounts)
            {
                if (accounts.TryGetValue(scriptHash, out account))
                {
                    accounts.Remove(scriptHash);
                }
            }
            if (account != null)
            {
                indexer.UnregisterAccounts(new[] { scriptHash });
                lock (db_lock)
                    using (WalletDataContext ctx = new WalletDataContext(path))
                    {
                        if (account.HasKey)
                        {
                            Account db_account = ctx.Accounts.First(p => p.PublicKeyHash.SequenceEqual(account.Key.PublicKeyHash.ToArray()));
                            ctx.Accounts.Remove(db_account);
                        }
                        if (account.Contract != null)
                        {
                            Contract db_contract = ctx.Contracts.First(p => p.ScriptHash.SequenceEqual(scriptHash.ToArray()));
                            ctx.Contracts.Remove(db_contract);
                        }
                        //delete address
                        {
                            Address db_address = ctx.Addresses.First(p => p.ScriptHash.SequenceEqual(scriptHash.ToArray()));
                            ctx.Addresses.Remove(db_address);
                        }
                        ctx.SaveChanges();
                    }
                return(true);
            }
            return(false);
        }
Exemple #10
0
 /// <summary>
 /// Return true if the signature is valid
 /// </summary>
 /// <param name="hash">Contract Hash</param>
 /// <returns>Return true or false</returns>
 public bool IsValid(UInt160 hash)
 {
     return(Crypto.VerifySignature(hash.ToArray(), Signature, PubKey));
 }
Exemple #11
0
 protected override void DeleteAccount(UInt160 publicKeyHash)
 {
     using (WalletDataContext ctx = new WalletDataContext(connectionString))
     {
         DbAccount account = ctx.Accounts.FirstOrDefault(p => p.PublicKeyHash == publicKeyHash.ToArray());
         if (account != null)
         {
             ctx.Contracts.RemoveRange(ctx.Contracts.Where(p => p.PublicKeyHash == publicKeyHash.ToArray()));
             ctx.Accounts.Remove(account);
             ctx.SaveChanges();
         }
     }
 }
Exemple #12
0
        // address and scripthash
        public static (string, string) AddressToScriptHash(string address)
        {
            UInt160 scriptHash = address.ToScriptHash();

            return(scriptHash.ToString(), scriptHash.ToArray().ToHexString());  // big, little
        }
Exemple #13
0
 public byte[] ToArray()
 {
     return(ScriptHash.ToArray());
 }
Exemple #14
0
        protected override void GetEncryptedEntry(UInt160 scriptHash, out byte[] redeemScript, out byte[] encryptedPrivateKey)
        {
            using (WalletDataContext ctx = new WalletDataContext(connectionString))
            {
                //Account account = ctx.Accounts.FirstOrDefault(p => p.ScriptHash == scriptHash.ToArray());
                //It throws a NotSupportedException:
                //LINQ to Entities does not recognize the method 'Byte[] ToArray()' method, and this method cannot be translated into a store expression.
                //I don't know why.
                //So,
                byte[] temp = scriptHash.ToArray();
                Account account = ctx.Accounts.FirstOrDefault(p => p.ScriptHash == temp);
                //It works!

                if (account == null)
                {
                    redeemScript = null;
                    encryptedPrivateKey = null;
                    return;
                }
                redeemScript = account.RedeemScript;
                encryptedPrivateKey = account.PrivateKeyEncrypted;
            }
        }
Exemple #15
0
        protected virtual bool Transfer(ApplicationEngine engine, UInt160 from, UInt160 to, BigInteger amount)
        {
            if (amount.Sign < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount));
            }
            if (!from.Equals(engine.CallingScriptHash) && !engine.CheckWitnessInternal(from))
            {
                return(false);
            }
            ContractState contract_to = engine.Snapshot.Contracts.TryGet(to);

            if (contract_to?.Payable == false)
            {
                return(false);
            }
            StorageKey  key_from     = CreateStorageKey(Prefix_Account).Add(from);
            StorageItem storage_from = engine.Snapshot.Storages.GetAndChange(key_from);

            if (amount.IsZero)
            {
                if (storage_from != null)
                {
                    TState state_from = storage_from.GetInteroperable <TState>();
                    OnBalanceChanging(engine, from, state_from, amount);
                }
            }
            else
            {
                if (storage_from is null)
                {
                    return(false);
                }
                TState state_from = storage_from.GetInteroperable <TState>();
                if (state_from.Balance < amount)
                {
                    return(false);
                }
                if (from.Equals(to))
                {
                    OnBalanceChanging(engine, from, state_from, BigInteger.Zero);
                }
                else
                {
                    OnBalanceChanging(engine, from, state_from, -amount);
                    if (state_from.Balance == amount)
                    {
                        engine.Snapshot.Storages.Delete(key_from);
                    }
                    else
                    {
                        state_from.Balance -= amount;
                    }
                    StorageKey  key_to     = CreateStorageKey(Prefix_Account).Add(to);
                    StorageItem storage_to = engine.Snapshot.Storages.GetAndChange(key_to, () => new StorageItem(new TState()));
                    TState      state_to   = storage_to.GetInteroperable <TState>();
                    OnBalanceChanging(engine, to, state_to, amount);
                    state_to.Balance += amount;
                }
            }
            engine.SendNotification(Hash, "Transfer", new Array {
                from.ToArray(), to.ToArray(), amount
            });
            return(true);
        }
Exemple #16
0
 public static string ToAddress(UInt160 scriptHash)
 {
     byte[] data = new byte[] { CoinVersion }.Concat(scriptHash.ToArray()).ToArray();
     return Base58.Encode(data.Concat(data.Sha256().Sha256().Take(4)).ToArray());
 }
Exemple #17
0
        public void Test_SetAdmin()
        {
            var snapshot = _snapshot.CreateSnapshot();
            // Fake blockchain

            var persistingBlock = new Block {
                Header = new Header {
                    Index = 1000
                }
            };
            UInt160 committeeAddress = NativeContract.NEO.GetCommitteeAddress(snapshot);

            // committee member,add a new root and then register, setrecord
            string validroot = "testroot";

            Check_AddRoot(snapshot, committeeAddress, validroot, persistingBlock).Should().BeTrue();

            string name   = "testname";
            string domain = name + "." + validroot;

            //before register
            var checkAvail_ret = Check_IsAvailable(snapshot, UInt160.Zero, domain, persistingBlock);

            checkAvail_ret.Result.Should().BeTrue();
            checkAvail_ret.State.Should().BeTrue();

            byte[] from         = Contract.GetBFTAddress(ProtocolSettings.Default.StandbyValidators).ToArray();
            var    register_ret = Check_Register(snapshot, domain, from, persistingBlock);

            register_ret.Result.Should().BeTrue();
            register_ret.State.Should().BeTrue();

            //check NFT token
            Assert.AreEqual(NativeContract.NameService.BalanceOf(snapshot, from), (BigInteger)1);

            //after register
            checkAvail_ret = Check_IsAvailable(snapshot, UInt160.Zero, domain, persistingBlock);
            checkAvail_ret.Result.Should().BeTrue();
            checkAvail_ret.State.Should().BeFalse();

            UInt160 admin          = Contract.CreateSignatureContract(ECCurve.Secp256r1.G).ScriptHash;
            var     checkadmin_ret = Check_SetAdmin(snapshot, domain, admin, from, persistingBlock);

            checkadmin_ret.Should().BeTrue();

            //setrecord with admin account
            string testA         = "10.10.10.10";
            var    setRecord_ret = Check_SetRecord(snapshot, domain, RecordType.A, testA, admin.ToArray(), persistingBlock);

            setRecord_ret.Should().BeTrue();

            var getRecord_ret = Check_GetRecord(snapshot, domain, RecordType.A, persistingBlock);

            getRecord_ret.State.Should().BeTrue();
            getRecord_ret.Result.Should().Equals(testA);

            //transfer the NFT token, admin set to null
            byte[] to           = UInt160.Zero.ToArray();
            var    transfer_ret = Check_Transfer(snapshot, UInt160.Zero, domain, new UInt160(from), persistingBlock);

            transfer_ret.Should().BeTrue();
            Assert.AreEqual(NativeContract.NameService.BalanceOf(snapshot, from), (BigInteger)0);

            setRecord_ret = Check_SetRecord(snapshot, domain, RecordType.A, testA, admin.ToArray(), persistingBlock);
            setRecord_ret.Should().BeFalse();

            setRecord_ret = Check_SetRecord(snapshot, domain, RecordType.A, testA, from, persistingBlock);
            setRecord_ret.Should().BeFalse();

            checkadmin_ret = Check_SetAdmin(snapshot, domain, admin, from, persistingBlock);
            checkadmin_ret.Should().BeFalse();
        }
Exemple #18
0
 public ScriptBuilder EmitAppCall(UInt160 scriptHash, bool useTailCall = false)
 {
     return(Emit(useTailCall ? OpCode.TAILCALL : OpCode.APPCALL, scriptHash.ToArray()));
 }
Exemple #19
0
 public Transaction Transfer(NeoKey from_key, UInt160 to_address_hash, decimal value)
 {
     return(Transfer(from_key, to_address_hash.ToArray(), value));
 }
Exemple #20
0
 protected override void SaveEncryptedEntry(UInt160 scriptHash, byte[] redeemScript, byte[] encryptedPrivateKey)
 {
     using (WalletDataContext ctx = new WalletDataContext(connectionString))
     {
         byte[] scriptHashBytes = scriptHash.ToArray();
         Account account = ctx.Accounts.FirstOrDefault(p => p.ScriptHash == scriptHashBytes);
         if (account == null)
         {
             account = ctx.Accounts.Add(new Account
             {
                 ScriptHash = scriptHash.ToArray(),
                 RedeemScript = redeemScript,
                 PrivateKeyEncrypted = encryptedPrivateKey
             });
         }
         else
         {
             account.RedeemScript = redeemScript;
             account.PrivateKeyEncrypted = encryptedPrivateKey;
         }
         ctx.SaveChanges();
     }
 }
Exemple #21
0
        public override bool DeleteKey(UInt160 publicKeyHash)
        {
            bool flag = base.DeleteKey(publicKeyHash);

            if (flag)
            {
                using (WalletDataContext ctx = new WalletDataContext(DbPath))
                {
                    Account account = ctx.Accounts.FirstOrDefault(p => p.PublicKeyHash.SequenceEqual(publicKeyHash.ToArray()));
                    if (account != null)
                    {
                        foreach (byte[] hash in ctx.Contracts.Where(p => p.PublicKeyHash.SequenceEqual(publicKeyHash.ToArray())).Select(p => p.ScriptHash))
                        {
                            Address address = ctx.Addresses.FirstOrDefault(p => p.ScriptHash.SequenceEqual(hash));
                            if (address != null)
                            {
                                ctx.Addresses.Remove(address);
                            }
                        }
                        ctx.Accounts.Remove(account);
                        ctx.SaveChanges();
                    }
                }
            }
            return(flag);
        }
Exemple #22
0
 public static string ToAddress(UInt160 scriptHash)
 {
     byte[] data = new byte[] { AddressVersion }.Concat(scriptHash.ToArray()).ToArray();
     return(Base58.Encode(data.Concat(Crypto.Default.Hash256(data).Take(4)).ToArray()));
 }
Exemple #23
0
 public static string ToAddress(UInt160 scriptHash)
 {
     byte[] data = new byte[] { CoinVersion }.Concat(scriptHash.ToArray()).ToArray();
     return(Base58.Encode(data.Concat(data.Sha256().Sha256().Take(4)).ToArray()));
 }
Exemple #24
0
        public override bool DeleteAccount(UInt160 publicKeyHash)
        {
            bool flag = base.DeleteAccount(publicKeyHash);

            if (flag)
            {
                using (WalletDataContext ctx = new WalletDataContext(DbPath))
                {
                    Account account = ctx.Accounts.FirstOrDefault(p => p.PublicKeyHash.SequenceEqual(publicKeyHash.ToArray()));
                    if (account != null)
                    {
                        ctx.Accounts.Remove(account);
                        ctx.SaveChanges();
                    }
                }
            }
            return(flag);
        }
        public static DebugInfo?TryGet(IReadOnlyStore store, UInt160 scriptHash)
        {
            var value = store.TryGet(DEBUG_INFO_PREFIX, scriptHash.ToArray());

            return(value == null ? null : value.AsSerializable <DebugInfo>());
        }
Exemple #26
0
        internal protected virtual void Burn(ApplicationEngine engine, UInt160 account, BigInteger amount)
        {
            if (amount.Sign < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount));
            }
            if (amount.IsZero)
            {
                return;
            }
            StorageKey  key     = CreateAccountKey(account);
            StorageItem storage = engine.Snapshot.Storages.GetAndChange(key);
            TState      state   = new TState();

            state.FromByteArray(storage.Value);
            if (state.Balance < amount)
            {
                throw new InvalidOperationException();
            }
            OnBalanceChanging(engine, account, state, -amount);
            if (state.Balance == amount)
            {
                engine.Snapshot.Storages.Delete(key);
            }
            else
            {
                state.Balance -= amount;
                storage.Value  = state.ToByteArray();
            }
            storage = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_TotalSupply));
            BigInteger totalSupply = new BigInteger(storage.Value);

            totalSupply  -= amount;
            storage.Value = totalSupply.ToByteArrayStandard();
            engine.SendNotification(Hash, new Array(engine.ReferenceCounter, new StackItem[] { "Transfer", account.ToArray(), StackItem.Null, amount }));
        }
Exemple #27
0
        protected virtual bool Transfer(ApplicationEngine engine, UInt160 from, UInt160 to, BigInteger amount)
        {
            if (amount.Sign < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount));
            }
            if (!from.Equals(engine.CallingScriptHash) && !InteropService.CheckWitness(engine, from))
            {
                return(false);
            }
            ContractState contract_to = engine.Snapshot.Contracts.TryGet(to);

            if (contract_to?.Payable == false)
            {
                return(false);
            }
            StorageKey  key_from     = CreateAccountKey(from);
            StorageItem storage_from = engine.Snapshot.Storages.TryGet(key_from);

            if (amount.IsZero)
            {
                if (storage_from != null)
                {
                    TState state_from = new TState();
                    state_from.FromByteArray(storage_from.Value);
                    OnBalanceChanging(engine, from, state_from, amount);
                }
            }
            else
            {
                if (storage_from is null)
                {
                    return(false);
                }
                TState state_from = new TState();
                state_from.FromByteArray(storage_from.Value);
                if (state_from.Balance < amount)
                {
                    return(false);
                }
                if (from.Equals(to))
                {
                    OnBalanceChanging(engine, from, state_from, BigInteger.Zero);
                }
                else
                {
                    OnBalanceChanging(engine, from, state_from, -amount);
                    if (state_from.Balance == amount)
                    {
                        engine.Snapshot.Storages.Delete(key_from);
                    }
                    else
                    {
                        state_from.Balance -= amount;
                        storage_from        = engine.Snapshot.Storages.GetAndChange(key_from);
                        storage_from.Value  = state_from.ToByteArray();
                    }
                    StorageKey  key_to     = CreateAccountKey(to);
                    StorageItem storage_to = engine.Snapshot.Storages.GetAndChange(key_to, () => new StorageItem
                    {
                        Value = new TState().ToByteArray()
                    });
                    TState state_to = new TState();
                    state_to.FromByteArray(storage_to.Value);
                    OnBalanceChanging(engine, to, state_to, amount);
                    state_to.Balance += amount;
                    storage_to.Value  = state_to.ToByteArray();
                }
            }
            engine.SendNotification(Hash, new Array(engine.ReferenceCounter, new StackItem[] { "Transfer", from.ToArray(), to.ToArray(), amount }));
            return(true);
        }
Exemple #28
0
 public override Contract GetContract(UInt160 scriptHash)
 {
     using (WalletDataContext ctx = new WalletDataContext(connectionString))
     {
         byte[] redeemScript = ctx.Contracts.FirstOrDefault(p => p.ScriptHash == scriptHash.ToArray())?.RedeemScript;
         if (redeemScript == null) return null;
         return new Contract(redeemScript);
     }
 }
Exemple #29
0
        internal protected virtual void Mint(ApplicationEngine engine, UInt160 account, BigInteger amount)
        {
            if (amount.Sign < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount));
            }
            if (amount.IsZero)
            {
                return;
            }
            StorageItem storage = engine.Snapshot.Storages.GetAndChange(CreateAccountKey(account), () => new StorageItem
            {
                Value = new TState().ToByteArray()
            });
            TState state = new TState();

            state.FromByteArray(storage.Value);
            OnBalanceChanging(engine, account, state, amount);
            state.Balance += amount;
            storage.Value  = state.ToByteArray();
            storage        = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_TotalSupply), () => new StorageItem
            {
                Value = BigInteger.Zero.ToByteArrayStandard()
            });
            BigInteger totalSupply = new BigInteger(storage.Value);

            totalSupply  += amount;
            storage.Value = totalSupply.ToByteArrayStandard();
            engine.SendNotification(Hash, new Array(engine.ReferenceCounter, new StackItem[] { "Transfer", StackItem.Null, account.ToArray(), amount }));
        }
Exemple #30
0
 public override Account GetAccountByScriptHash(UInt160 scriptHash)
 {
     using (WalletDataContext ctx = new WalletDataContext(connectionString))
     {
         byte[] publicKeyHash = ctx.Contracts.FirstOrDefault(p => p.ScriptHash == scriptHash.ToArray())?.PublicKeyHash;
         if (publicKeyHash == null) return null;
         return GetAccountInternal(ctx.Accounts.FirstOrDefault(p => p.PublicKeyHash == publicKeyHash)?.PrivateKeyEncrypted);
     }
 }
Exemple #31
0
 public override WContract GetContract(UInt160 scriptHash)
 {
     using (WalletDataContext ctx = new WalletDataContext(path))
     {
         byte[] redeemScript = ctx.Contracts.FirstOrDefault(p => p.ScriptHash == scriptHash.ToArray())?.RedeemScript;
         if (redeemScript == null)
         {
             return(null);
         }
         return(new WContract(redeemScript));
     }
 }
Exemple #32
0
 public override bool DeleteContract(UInt160 scriptHash)
 {
     bool flag = base.DeleteContract(scriptHash);
     if (flag)
     {
         using (WalletDataContext ctx = new WalletDataContext(DbPath))
         {
             Contract contract = ctx.Contracts.FirstOrDefault(p => p.ScriptHash.SequenceEqual(scriptHash.ToArray()));
             if (contract != null)
             {
                 ctx.Contracts.Remove(contract);
                 ctx.SaveChanges();
             }
         }
     }
     return flag;
 }
Exemple #33
0
 public static string ToAddress(UInt160 hash, bool p2sh)
 {
     byte version = p2sh ? P2SHVersion : CoinVersion;
     byte[] data = new byte[] { version }.Concat(hash.ToArray()).ToArray();
     return Base58.Encode(data.Concat(data.Sha256().Sha256().Take(4)).ToArray());
 }
Exemple #34
0
 public static ScriptBuilder EmitAppCall(this ScriptBuilder sb, UInt160 scriptHash, bool useTailCall = false)
 {
     TR.Enter();
     return(TR.Exit(sb.EmitAppCall(scriptHash.ToArray(), useTailCall)));
 }
Exemple #35
0
 public override WAccount GetAccount(UInt160 publicKeyHash)
 {
     using (WalletDataContext ctx = new WalletDataContext(path))
     {
         return(GetAccountInternal(ctx.Accounts.FirstOrDefault(p => p.PublicKeyHash == publicKeyHash.ToArray())?.PrivateKeyEncrypted));
     }
 }
Exemple #36
0
 public StackItem ToStackItem(ReferenceCounter referenceCounter)
 {
     return(new Array(referenceCounter, new StackItem[] { Id, (int)UpdateCounter, Hash.ToArray(), Nef.ToArray(), Manifest.ToStackItem(referenceCounter) }));
 }
Exemple #37
0
 public override WAccount GetAccountByScriptHash(UInt160 scriptHash)
 {
     using (WalletDataContext ctx = new WalletDataContext(path))
     {
         byte[] publicKeyHash = ctx.Contracts.FirstOrDefault(p => p.ScriptHash == scriptHash.ToArray())?.PublicKeyHash;
         if (publicKeyHash == null)
         {
             return(null);
         }
         return(GetAccountInternal(ctx.Accounts.FirstOrDefault(p => p.PublicKeyHash == publicKeyHash)?.PrivateKeyEncrypted));
     }
 }
Exemple #38
0
        public override bool DeleteAddress(UInt160 scriptHash)
        {
            bool flag = base.DeleteAddress(scriptHash);

            if (flag)
            {
                using (WalletDataContext ctx = new WalletDataContext(DbPath))
                {
                    Address address = ctx.Addresses.FirstOrDefault(p => p.ScriptHash.SequenceEqual(scriptHash.ToArray()));
                    if (address != null)
                    {
                        ctx.Addresses.Remove(address);
                        ctx.SaveChanges();
                    }
                }
            }
            return(flag);
        }
Exemple #39
0
        public override bool DeleteContract(UInt160 scriptHash)
        {
            bool flag = base.DeleteContract(scriptHash);

            if (flag)
            {
                using (WalletDataContext ctx = new WalletDataContext(DbPath))
                {
                    Contract contract = ctx.Contracts.FirstOrDefault(p => p.ScriptHash.SequenceEqual(scriptHash.ToArray()));
                    if (contract != null)
                    {
                        ctx.Contracts.Remove(contract);
                        ctx.SaveChanges();
                    }
                }
            }
            return(flag);
        }
Exemple #40
0
 protected override void DeleteAccount(UInt160 publicKeyHash)
 {
     using (WalletDataContext ctx = new WalletDataContext(path))
     {
         Account account = ctx.Accounts.FirstOrDefault(p => p.PublicKeyHash == publicKeyHash.ToArray());
         if (account != null)
         {
             ctx.Contracts.RemoveRange(ctx.Contracts.Where(p => p.PublicKeyHash == publicKeyHash.ToArray()));
             ctx.Accounts.Remove(account);
             ctx.SaveChanges();
         }
     }
 }
Exemple #41
0
 protected override void DeleteEntry(UInt160 scriptHash)
 {
     using (WalletDataContext ctx = new WalletDataContext(connectionString))
     {
         Account account = ctx.Accounts.FirstOrDefault(p => p.ScriptHash == scriptHash.ToArray());
         if (account != null)
         {
             ctx.Accounts.Remove(account);
             ctx.SaveChanges();
         }
     }
 }