public bool AddWalletAddress(WalletAddress address, bool mergePast, out bool empty)
        {
            empty = true;
            if (!AddAddress(address))
            {
                return(false);
            }

            if (address.HDKeySet != null)
            {
                KeyDataTable.GetChild(address.WalletName, address.HDKeySet.Name).Create(Encode(address.ScriptPubKey), address.HDKey, false);
            }

            var entry = address.CreateWalletRuleEntry();

            Indexer.AddWalletRule(entry.WalletId, entry.Rule);
            if (mergePast)
            {
                CancellationTokenSource cancel = new CancellationTokenSource();
                cancel.CancelAfter(10000);
                empty = !Indexer.MergeIntoWallet(address.WalletName, address, entry.Rule, cancel.Token);
            }
            if (!empty)
            {
                GetBalanceSummaryCacheTable(address.WalletName, true).Delete();
                GetBalanceSummaryCacheTable(address.WalletName, false).Delete();
            }
            return(true);
        }
Beispiel #2
0
        public HDKeyData NewKey(string walletName, string keysetName)
        {
            HDKeyData keyData;

            while (true)
            {
                var keySetData = GetKeySetData(walletName, keysetName);
                if (keySetData == null)
                {
                    return(null);
                }
                KeyPath next;
                if (keySetData.State.CurrentPath == null)
                {
                    var root = keySetData.KeySet.Path ?? new KeyPath();
                    next = root.Derive(0);
                }
                else
                {
                    next = Inc(keySetData.State.CurrentPath);
                }
                keyData            = new HDKeyData();
                keyData.ExtPubKeys = keySetData
                                     .KeySet
                                     .ExtPubKeys
                                     .Select(k => k.ExtPubKey.Derive(next).GetWif(Network)).ToArray();
                keyData.Path         = next;
                keyData.RedeemScript = CreateScriptPubKey(keyData.ExtPubKeys, keySetData.KeySet.SignatureCount, !keySetData.KeySet.NoP2SH);
                if (keySetData.KeySet.NoP2SH)
                {
                    keyData.ScriptPubKey = keyData.RedeemScript;
                    keyData.RedeemScript = null;
                    keyData.Address      = keyData.ScriptPubKey.GetDestinationAddress(Network);
                }
                else
                {
                    keyData.ScriptPubKey = keyData.RedeemScript.Hash.ScriptPubKey;
                    keyData.Address      = keyData.ScriptPubKey.GetDestinationAddress(Network);
                }

                if (KeyDataTable.GetChild(walletName, keysetName).Create(Encode(keyData.ScriptPubKey), keyData, false))
                {
                    keySetData.State.CurrentPath = next;
                    KeySetTable.GetChild(walletName).Create(keysetName, keySetData);
                    break;
                }
            }
            var entry = Indexer.AddWalletRule(walletName, new ScriptRule
            {
                RedeemScript = keyData.RedeemScript,
                ScriptPubKey = keyData.ScriptPubKey
            });
            var clientIndexer = Indexer.Configuration.CreateIndexerClient();

            clientIndexer.MergeIntoWallet(walletName, keyData.ScriptPubKey, entry.Rule);
            return(keyData);
        }
Beispiel #3
0
        public bool DeleteKeySet(string walletName, string keyset)
        {
            if (!KeySetTable.GetChild(walletName).Delete(keyset, true))
            {
                return(false);
            }

            KeyDataTable.GetChild(walletName, keyset).Delete();
            return(true);
        }
Beispiel #4
0
 internal HDKeyData[] GetKeys(string walletName, string keysetName)
 {
     return(KeyDataTable.GetChild(walletName, keysetName).Read());
 }