Ejemplo n.º 1
0
        private static void ImportKeys(IRpcService service, string privateKeysFilePath)
        {
            verbosityLevel.Writer.WriteLine($"Importing private keys");
            if (service == null)
            {
                verbosityLevel.Writer.WriteLine("No X node found to import keys into.");
                return;
            }

            if (!File.Exists(privateKeysFilePath))
            {
                verbosityLevel.Writer.WriteLine($"{privateKeysFilePath} file not found.");
            }

            var keysToImport = JsonConvert.DeserializeObject <List <ImportedKey> >(File.ReadAllText(privateKeysFilePath));

            verbosityLevel.Writer.WriteLine($"Found {keysToImport.Count} private keys to import.");

            for (int i = 0; i < keysToImport.Count; i++)
            {
                var keyToImport = keysToImport[i];

                var request = new GenericCall(
                    "importprivkey",
                    ("privkey", keyToImport.PrivateKey),
                    ("label", keyToImport.Path),
                    ("rescan", false) //i == keysToImport.Count - 1)
                    );

                var result = service.CallSingle(request);

                Console.Write($"\rImporting key {i + 1}/{keysToImport.Count}");
                if (result.HasError)
                {
                    verbosityLevel.Writer.WriteLine($"\rimportprivkey error on key {i + 1}/{keysToImport.Count}: {result.Error}");
                }
            }

            verbosityLevel.Writer.WriteLine($"Check if first key has been imported");
            var dumpPrivKeyResult = service.CallSingle(new GenericCall("dumpprivkey", ("address", keysToImport.First().Address)));

            if (dumpPrivKeyResult.HasError)
            {
                verbosityLevel.Writer.WriteLine($"dumpprivkey error: {dumpPrivKeyResult.Error}");
            }
            else
            {
                verbosityLevel.Writer.WriteLine($"dumpprivkey result: {dumpPrivKeyResult.Result}");
            }
        }
Ejemplo n.º 2
0
        private void Initialize()
        {
            const int labelColumnWidth = 30;

            this.writer
            .DrawLine('▼')
            .WriteLine($"Initializing {this.rpcService.Name} Test Data")
            .DrawLine('.');

            this.BlockCount = ParseResponse <int>(new CallRequest.GetBlockCount());
            this.writer.WriteLine($"{"BlockCount".AlignLeft(labelColumnWidth)}{this.BlockCount}");

            this.BlockHash = ParseResponse <string>(new CallRequest.GetBlockHash(this.BlockCount));
            this.writer.WriteLine($"{"BlockHash".AlignLeft(labelColumnWidth)}{this.BlockHash}");

            this.addresses = ParseResponse <ListAddressGroupingsResponse>(new CallRequest.ListAddressGroupings()).AddressesGroups
                             .SelectMany(ag => ag)
                             .Select(detail => detail.Address)
                             .Distinct()
                             .ToList();
            this.writer.WriteLine($"{"Loaded Addresses".AlignLeft(labelColumnWidth)}{this.addresses.Count}");


            this.unspentTxIds = ParseResponse <ListUnspentResponse>(new CallRequest.ListUnspent(null, null, null, null, null))
                                .Select(unspent => unspent.TxId)
                                .ToList();
            this.writer.WriteLine($"{"Loaded UTXOs Ids".AlignLeft(labelColumnWidth)}{this.unspentTxIds.Count}");

            this.rawTxHex = new List <string>();
            foreach (var blockHeight in Enumerable.Range(1, 20))
            {
                var blockHash = ParseResponse <string>(new CallRequest.GetBlockHash(blockHeight));
                var block     = ParseResponse <GetBlockResponse>(new CallRequest.GetBlock(blockHash, null));
                foreach (var txId in block.Tx)
                {
                    this.rawTxHex.Add(ParseResponse <string>(new CallRequest.GetRawTransaction(txId, 0, null)));
                }
            }
            this.writer.WriteLine($"{"Loaded Raw Transactions tx Hex".AlignLeft(labelColumnWidth)}{this.rawTxHex.Count}");

            this.writer.WriteLine($"Unlocking wallet for {WALLET_UNLOCK_TIMEOUT} seconds");
            this.rpcService.CallSingle(new GenericCall("walletpassphrase", ("passphrase", this.rpcService.WalletPassword), ("timeout", WALLET_UNLOCK_TIMEOUT)));

            this.writer
            .DrawLine('.')
            .WriteLine($"End of {this.rpcService.Name} Test Data Initialization")
            .DrawLine('▲');
        }
Ejemplo n.º 3
0
    IEnumerator delayedCall(GenericCall func, float minReactionTime, float maxReactionTime)
    {
        yield return(new WaitForSeconds(Random.Range(minReactionTime / 1000f, maxReactionTime / 1000f)));

        func();
    }
Ejemplo n.º 4
0
 public override PegNode Clone()
 {
     GenericCall clone = new GenericCall(genericParam_, genericCall_);
     CloneSubTrees(clone);
     return clone;
 }