Exemplo n.º 1
0
        public override WalletAccount CreateAccount(Contract contract, KeyPair key = null)
        {
            TLP6Contract tlp6contract = contract as TLP6Contract;

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

            if (key == null)
            {
                account = new TLP6Account(this, tlp6contract.ScriptHash);
            }
            else
            {
                account = new TLP6Account(this, tlp6contract.ScriptHash, key, password);
            }
            account.Contract = tlp6contract;
            AddAccount(account, false);
            return(account);
        }
Exemplo n.º 2
0
 private void AddAccount(TLP6Account account, bool is_import)
 {
     lock (accounts)
     {
         if (accounts.TryGetValue(account.ScriptHash, out TLP6Account 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
             {
                 TLP6Contract contract_old = (TLP6Contract)account_old.Contract;
                 if (contract_old != null)
                 {
                     TLP6Contract contract = (TLP6Contract)account.Contract;
                     contract.ParameterNames = contract_old.ParameterNames;
                     contract.Deployed       = contract_old.Deployed;
                 }
             }
             account.Extra = account_old.Extra;
         }
         accounts[account.ScriptHash] = account;
     }
 }
Exemplo n.º 3
0
 public static TLP6Account FromJson(JObject json, TLP6Wallet wallet)
 {
     return(new TLP6Account(wallet, json["address"].AsString().ToScriptHash(), json["key"]?.AsString())
     {
         Label = json["label"]?.AsString(),
         IsDefault = json["isDefault"].AsBoolean(),
         Lock = json["lock"].AsBoolean(),
         Contract = TLP6Contract.FromJson(json["contract"]),
         Extra = json["extra"]
     });
 }
Exemplo n.º 4
0
        public override WalletAccount Import(string wif)
        {
            KeyPair      key      = new KeyPair(GetPrivateKeyFromWIF(wif));
            TLP6Contract contract = new TLP6Contract
            {
                Script         = Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList  = new[] { ContractParameterType.Signature },
                ParameterNames = new[] { "signature" },
                Deployed       = false
            };
            TLP6Account account = new TLP6Account(this, contract.ScriptHash, key, password)
            {
                Contract = contract
            };

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

            AddAccount(account, false);
            return(account);
        }
Exemplo n.º 6
0
        public override WalletAccount Import(X509Certificate2 cert)
        {
            KeyPair key;

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

            AddAccount(account, true);
            return(account);
        }
Exemplo n.º 7
0
        public override WalletAccount Import(string tlp2, string passphrase, int N = 16384, int r = 8, int p = 8)
        {
            KeyPair      key      = new KeyPair(GetPrivateKeyFromTLP2(tlp2, passphrase, N, r, p));
            TLP6Contract contract = new TLP6Contract
            {
                Script         = Contract.CreateSignatureRedeemScript(key.PublicKey),
                ParameterList  = new[] { ContractParameterType.Signature },
                ParameterNames = new[] { "signature" },
                Deployed       = false
            };
            TLP6Account account;

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