Exemple #1
0
        public override WalletAccount CreateAccount(Contract contract, KeyPair key = null)
        {
            if (!(contract is TERC1Contract nep6contract))
            {
                nep6contract = new TERC1Contract
                {
                    Script         = contract.Script,
                    ParameterList  = contract.ParameterList,
                    ParameterNames = contract.ParameterList.Select((p, i) => $"parameter{i}").ToArray(),
                    Deployed       = false
                };
            }
            TERC1Account account;

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

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

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

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

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

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