Exemple #1
0
 public override void AddContract(VerificationContract contract)
 {
     base.AddContract(contract);
     using (WalletDataContext ctx = new WalletDataContext(DbPath))
     {
         Contract db_contract = ctx.Contracts.FirstOrDefault(p => p.ScriptHash.SequenceEqual(contract.ScriptHash.ToArray()));
         if (db_contract != null)
         {
             db_contract.PublicKeyHash = contract.PublicKeyHash.ToArray();
         }
         else
         {
             Address db_address = ctx.Addresses.FirstOrDefault(p => p.ScriptHash.SequenceEqual(contract.ScriptHash.ToArray()));
             if (db_address == null)
             {
                 ctx.Addresses.Add(new Address
                 {
                     ScriptHash = contract.ScriptHash.ToArray()
                 });
             }
             ctx.Contracts.Add(new Contract
             {
                 RawData       = contract.ToArray(),
                 ScriptHash    = contract.ScriptHash.ToArray(),
                 PublicKeyHash = contract.PublicKeyHash.ToArray()
             });
         }
         ctx.SaveChanges();
     }
 }
Exemple #2
0
        public override WalletKeyPair CreateKey(byte[] privateKey)
        {
            WalletKeyPair account = base.CreateKey(privateKey);

            OnCreateAccount(account);
            AddContract(VerificationContract.CreateSignatureContract(account.PublicKey));
            return(account);
        }
Exemple #3
0
 private Dictionary <UInt160, WalletAccount> LoadAccounts()
 {
     using (WalletDataContext ctx = new WalletDataContext(path))
     {
         Dictionary <UInt160, WalletAccount> accounts = ctx.Addresses.Select(p => p.ScriptHash).AsEnumerable().Select(p => new UserWalletAccount(new UInt160(p))).ToDictionary(p => p.ScriptHash, p => (WalletAccount)p);
         foreach (Contract db_contract in ctx.Contracts.Include(p => p.Account))
         {
             VerificationContract contract = db_contract.RawData.AsSerializable <VerificationContract>();
             UserWalletAccount    account  = (UserWalletAccount)accounts[contract.ScriptHash];
             account.Contract = contract;
             account.Key      = new KeyPair(DecryptPrivateKey(db_contract.Account.PrivateKeyEncrypted));
         }
         return(accounts);
     }
 }
Exemple #4
0
        public override WalletAccount CreateAccount(byte[] privateKey)
        {
            KeyPair key = new KeyPair(privateKey);
            VerificationContract contract = new VerificationContract
            {
                Script        = SmartContract.Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList = new[] { ContractParameterType.Signature }
            };
            UserWalletAccount account = new UserWalletAccount(contract.ScriptHash)
            {
                Key      = key,
                Contract = contract
            };

            AddAccount(account, false);
            return(account);
        }
Exemple #5
0
        public override WalletAccount CreateAccount(SmartContract.Contract contract, KeyPair key = null)
        {
            VerificationContract verification_contract = contract as VerificationContract;

            if (verification_contract == null)
            {
                verification_contract = new VerificationContract
                {
                    Script        = contract.Script,
                    ParameterList = contract.ParameterList
                };
            }
            UserWalletAccount account = new UserWalletAccount(verification_contract.ScriptHash)
            {
                Key      = key,
                Contract = verification_contract
            };

            AddAccount(account, false);
            return(account);
        }