Beispiel #1
0
        public override WalletAccount CreateAccount(Contract contract, KeyPair key = null)
        {
            BHP6Contract BHP6Contract = contract as BHP6Contract;

            if (BHP6Contract == null)
            {
                BHP6Contract = new BHP6Contract
                {
                    Script         = contract.Script,
                    ParameterList  = contract.ParameterList,
                    ParameterNames = contract.ParameterList.Select((p, i) => $"parameter{i}").ToArray(),
                    Deployed       = false
                };
            }
            BHP6Account account;

            if (key == null)
            {
                account = new BHP6Account(this, BHP6Contract.ScriptHash);
            }
            else
            {
                account = new BHP6Account(this, BHP6Contract.ScriptHash, key, password);
            }
            account.Contract = BHP6Contract;
            AddAccount(account, false);
            return(account);
        }
Beispiel #2
0
 private void AddAccount(BHP6Account account, bool is_import)
 {
     lock (accounts)
     {
         if (accounts.TryGetValue(account.ScriptHash, out BHP6Account account_old))
         {
             account.Label     = account_old.Label;
             account.IsDefault = account_old.IsDefault;
             account.Lock      = account_old.Lock;
             if (account.Contract == null)
             {
                 account.Contract = account_old.Contract;
             }
             else
             {
                 BHP6Contract contract_old = (BHP6Contract)account_old.Contract;
                 if (contract_old != null)
                 {
                     BHP6Contract contract = (BHP6Contract)account.Contract;
                     contract.ParameterNames = contract_old.ParameterNames;
                     contract.Deployed       = contract_old.Deployed;
                 }
             }
             account.Extra = account_old.Extra;
         }
         else
         {
             WalletIndexer.RegisterAccounts(new[] { account.ScriptHash }, is_import ? 0 : Blockchain.Default?.Height ?? 0);
         }
         accounts[account.ScriptHash] = account;
     }
 }
Beispiel #3
0
 public static BHP6Account FromJson(JObject json, BHP6Wallet wallet)
 {
     return(new BHP6Account(wallet, Wallet.ToScriptHash(json["address"].AsString()), json["key"]?.AsString())
     {
         Label = json["label"]?.AsString(),
         IsDefault = json["isDefault"].AsBoolean(),
         Lock = json["lock"].AsBoolean(),
         Contract = BHP6Contract.FromJson(json["contract"]),
         Extra = json["extra"]
     });
 }
Beispiel #4
0
        public override WalletAccount Import(string wif)
        {
            KeyPair      key      = new KeyPair(GetPrivateKeyFromWIF(wif));
            BHP6Contract contract = new BHP6Contract
            {
                Script         = Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList  = new[] { ContractParameterType.Signature },
                ParameterNames = new[] { "signature" },
                Deployed       = false
            };
            BHP6Account account = new BHP6Account(this, contract.ScriptHash, key, password)
            {
                Contract = contract
            };

            AddAccount(account, true);
            return(account);
        }
Beispiel #5
0
        public override WalletAccount CreateAccount(byte[] privateKey)
        {
            KeyPair      key      = new KeyPair(privateKey);
            BHP6Contract contract = new BHP6Contract
            {
                Script         = Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList  = new[] { ContractParameterType.Signature },
                ParameterNames = new[] { "signature" },
                Deployed       = false
            };
            BHP6Account account = new BHP6Account(this, contract.ScriptHash, key, password)
            {
                Contract = contract
            };

            AddAccount(account, false);
            return(account);
        }
Beispiel #6
0
        public override WalletAccount Import(X509Certificate2 cert)
        {
            KeyPair key;

            using (ECDsa ecdsa = cert.GetECDsaPrivateKey())
            {
                key = new KeyPair(ecdsa.ExportParameters(true).D);
            }
            BHP6Contract contract = new BHP6Contract
            {
                Script         = Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList  = new[] { ContractParameterType.Signature },
                ParameterNames = new[] { "signature" },
                Deployed       = false
            };
            BHP6Account account = new BHP6Account(this, contract.ScriptHash, key, password)
            {
                Contract = contract
            };

            AddAccount(account, true);
            return(account);
        }
Beispiel #7
0
        public override WalletAccount Import(string nep2, string passphrase)
        {
            KeyPair      key      = new KeyPair(GetPrivateKeyFromNEP2(nep2, passphrase));
            BHP6Contract contract = new BHP6Contract
            {
                Script         = Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList  = new[] { ContractParameterType.Signature },
                ParameterNames = new[] { "signature" },
                Deployed       = false
            };
            BHP6Account account;

            if (Scrypt.N == 16384 && Scrypt.R == 8 && Scrypt.P == 8)
            {
                account = new BHP6Account(this, contract.ScriptHash, nep2);
            }
            else
            {
                account = new BHP6Account(this, contract.ScriptHash, key, passphrase);
            }
            account.Contract = contract;
            AddAccount(account, true);
            return(account);
        }