-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathRpcService.cs
More file actions
784 lines (626 loc) · 30.7 KB
/
RpcService.cs
File metadata and controls
784 lines (626 loc) · 30.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
// Copyright (c) 2014 - 2016 George Kimionis
// See the accompanying file LICENSE for the Software License Aggrement
using BitcoinLib.Requests.AddNode;
using BitcoinLib.Requests.CreateRawTransaction;
using BitcoinLib.Requests.SignRawTransaction;
using BitcoinLib.Responses;
using BitcoinLib.RPC.Connector;
using BitcoinLib.RPC.Specifications;
using BitcoinLib.Services.Coins.Base;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using BitcoinLib.Requests.FundRawTransaction;
using Newtonsoft.Json;
namespace BitcoinLib.Services
{
// Implementation of API calls list, as found at: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list (note: this list is often out-of-date so call "help" in your bitcoin-cli to get the latest signatures)
public partial class CoinService : ICoinService
{
protected readonly IRpcConnector _rpcConnector;
public CoinService()
{
_rpcConnector = new RpcConnector(this);
Parameters = new CoinParameters(this, null, null, null, null, 0);
}
public CoinService(bool useTestnet) : this()
{
Parameters.UseTestnet = useTestnet;
}
public CoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword)
{
_rpcConnector = new RpcConnector(this);
Parameters = new CoinParameters(this, daemonUrl, rpcUsername, rpcPassword, walletPassword, 0);
}
// this provides support for cases where *.config files are not an option
public CoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword, short rpcRequestTimeoutInSeconds)
{
_rpcConnector = new RpcConnector(this);
Parameters = new CoinParameters(this, daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds);
}
public string AddMultiSigAddress(int nRquired, List<string> publicKeys, string account)
{
return account != null
? _rpcConnector.MakeRequest<string>(RpcMethods.addmultisigaddress, nRquired, publicKeys, account)
: _rpcConnector.MakeRequest<string>(RpcMethods.addmultisigaddress, nRquired, publicKeys);
}
public void AddNode(string node, NodeAction action)
{
_rpcConnector.MakeRequest<string>(RpcMethods.addnode, node, action.ToString());
}
public string AddWitnessAddress(string address)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.addwitnessaddress, address);
}
public void BackupWallet(string destination)
{
_rpcConnector.MakeRequest<string>(RpcMethods.backupwallet, destination);
}
public CreateMultiSigResponse CreateMultiSig(int nRquired, List<string> publicKeys)
{
return _rpcConnector.MakeRequest<CreateMultiSigResponse>(RpcMethods.createmultisig, nRquired, publicKeys);
}
public string CreateRawTransaction(CreateRawTransactionRequest rawTransaction)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.createrawtransaction, rawTransaction.Inputs, rawTransaction.Outputs);
}
/// <summary>
/// Lower level CreateRawTransaction RPC request to allow other kinds of output, e.g.
/// "data":"text" for OP_RETURN Null Data for chat on the blockchain. CreateRawTransaction(
/// CreateRawTransactionRequest) only allows for "receiver":amount outputs.
/// </summary>
public string CreateRawTransaction(IList<CreateRawTransactionInput> inputs,
string chatHex, string receiverAddress, decimal receiverAmount)
{
// Must be a dictionary to become an json object, an array will fail on the RPC side
var outputs = new Dictionary<string, string>
{
{ "data", chatHex },
{ receiverAddress, receiverAmount.ToString(NumberFormatInfo.InvariantInfo) }
};
return _rpcConnector.MakeRequest<string>(RpcMethods.createrawtransaction, inputs, outputs);
}
public DecodeRawTransactionResponse DecodeRawTransaction(string rawTransactionHexString)
{
return _rpcConnector.MakeRequest<DecodeRawTransactionResponse>(RpcMethods.decoderawtransaction, rawTransactionHexString);
}
public DecodeScriptResponse DecodeScript(string hexString)
{
return _rpcConnector.MakeRequest<DecodeScriptResponse>(RpcMethods.decodescript, hexString);
}
public string DumpPrivKey(string bitcoinAddress)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.dumpprivkey, bitcoinAddress);
}
public void DumpWallet(string filename)
{
_rpcConnector.MakeRequest<string>(RpcMethods.dumpwallet, filename);
}
public decimal EstimateFee(ushort nBlocks)
{
return _rpcConnector.MakeRequest<decimal>(RpcMethods.estimatefee, nBlocks);
}
public EstimateSmartFeeResponse EstimateSmartFee(ushort nBlocks)
{
return _rpcConnector.MakeRequest<EstimateSmartFeeResponse>(RpcMethods.estimatesmartfee, nBlocks);
}
public decimal EstimatePriority(ushort nBlocks)
{
return _rpcConnector.MakeRequest<decimal>(RpcMethods.estimatepriority, nBlocks);
}
public string GetAccount(string bitcoinAddress)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.getaccount, bitcoinAddress);
}
public string GetAccountAddress(string account)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.getaccountaddress, account);
}
public GetAddedNodeInfoResponse GetAddedNodeInfo(string dns, string node)
{
return string.IsNullOrWhiteSpace(node)
? _rpcConnector.MakeRequest<GetAddedNodeInfoResponse>(RpcMethods.getaddednodeinfo, dns)
: _rpcConnector.MakeRequest<GetAddedNodeInfoResponse>(RpcMethods.getaddednodeinfo, dns, node);
}
public List<string> GetAddressesByAccount(string account)
{
return _rpcConnector.MakeRequest<List<string>>(RpcMethods.getaddressesbyaccount, account);
}
public Dictionary<string, GetAddressesByLabelResponse> GetAddressesByLabel(string label)
{
return _rpcConnector.MakeRequest<Dictionary<string, GetAddressesByLabelResponse>>(RpcMethods.getaddressesbylabel, label);
}
public GetAddressInfoResponse GetAddressInfo(string bitcoinAddress)
{
return _rpcConnector.MakeRequest<GetAddressInfoResponse>(RpcMethods.getaddressinfo, bitcoinAddress);
}
public decimal GetBalance(string account, int minConf, bool? includeWatchonly)
{
return includeWatchonly == null
? _rpcConnector.MakeRequest<decimal>(RpcMethods.getbalance, (string.IsNullOrWhiteSpace(account) ? "*" : account), minConf)
: _rpcConnector.MakeRequest<decimal>(RpcMethods.getbalance, (string.IsNullOrWhiteSpace(account) ? "*" : account), minConf, includeWatchonly);
}
public string GetBestBlockHash()
{
return _rpcConnector.MakeRequest<string>(RpcMethods.getbestblockhash);
}
public GetBlockResponse GetBlock(string hash, bool verbose)
{
return _rpcConnector.MakeRequest<GetBlockResponse>(RpcMethods.getblock, hash, verbose);
}
public GetBlockResponseVerbose GetBlock(string hash, int verbosity)
{
if (verbosity < 2)
{
throw new ArgumentException("This method is only available for verbosity levels above 1. Please use method where 2nd argument is a boolean instead.");
}
return _rpcConnector.MakeRequest<GetBlockResponseVerbose>(RpcMethods.getblock, hash, verbosity);
}
public GetBlockchainInfoResponse GetBlockchainInfo()
{
return _rpcConnector.MakeRequest<GetBlockchainInfoResponse>(RpcMethods.getblockchaininfo);
}
public uint GetBlockCount()
{
return _rpcConnector.MakeRequest<uint>(RpcMethods.getblockcount);
}
public string GetBlockHash(long index)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.getblockhash, index);
}
public GetBlockTemplateResponse GetBlockTemplate(params object[] parameters)
{
return parameters == null
? _rpcConnector.MakeRequest<GetBlockTemplateResponse>(RpcMethods.getblocktemplate)
: _rpcConnector.MakeRequest<GetBlockTemplateResponse>(RpcMethods.getblocktemplate, parameters);
}
public List<GetChainTipsResponse> GetChainTips()
{
return _rpcConnector.MakeRequest<List<GetChainTipsResponse>>(RpcMethods.getchaintips);
}
public int GetConnectionCount()
{
return _rpcConnector.MakeRequest<int>(RpcMethods.getconnectioncount);
}
public double GetDifficulty()
{
return _rpcConnector.MakeRequest<double>(RpcMethods.getdifficulty);
}
public bool GetGenerate()
{
return _rpcConnector.MakeRequest<bool>(RpcMethods.getgenerate);
}
[Obsolete("Please use calls: GetWalletInfo(), GetBlockchainInfo() and GetNetworkInfo() instead")]
public GetInfoResponse GetInfo()
{
return _rpcConnector.MakeRequest<GetInfoResponse>(RpcMethods.getinfo);
}
public GetMemPoolInfoResponse GetMemPoolInfo()
{
return _rpcConnector.MakeRequest<GetMemPoolInfoResponse>(RpcMethods.getmempoolinfo);
}
public GetMiningInfoResponse GetMiningInfo()
{
return _rpcConnector.MakeRequest<GetMiningInfoResponse>(RpcMethods.getmininginfo);
}
public GetNetTotalsResponse GetNetTotals()
{
return _rpcConnector.MakeRequest<GetNetTotalsResponse>(RpcMethods.getnettotals);
}
public ulong GetNetworkHashPs(uint blocks, long height)
{
return _rpcConnector.MakeRequest<ulong>(RpcMethods.getnetworkhashps);
}
public GetNetworkInfoResponse GetNetworkInfo()
{
return _rpcConnector.MakeRequest<GetNetworkInfoResponse>(RpcMethods.getnetworkinfo);
}
public string GetNewAddress(string account)
{
return string.IsNullOrWhiteSpace(account)
? _rpcConnector.MakeRequest<string>(RpcMethods.getnewaddress)
: _rpcConnector.MakeRequest<string>(RpcMethods.getnewaddress, account);
}
public List<GetPeerInfoResponse> GetPeerInfo()
{
return _rpcConnector.MakeRequest<List<GetPeerInfoResponse>>(RpcMethods.getpeerinfo);
}
public GetRawMemPoolResponse GetRawMemPool(bool verbose)
{
var getRawMemPoolResponse = new GetRawMemPoolResponse
{
IsVerbose = verbose
};
var rpcResponse = _rpcConnector.MakeRequest<object>(RpcMethods.getrawmempool, verbose);
if (!verbose)
{
var rpcResponseAsArray = (JArray)rpcResponse;
foreach (string txId in rpcResponseAsArray)
{
getRawMemPoolResponse.TxIds.Add(txId);
}
return getRawMemPoolResponse;
}
IList<KeyValuePair<string, JToken>> rpcResponseAsKvp = (new EnumerableQuery<KeyValuePair<string, JToken>>(((JObject)(rpcResponse)))).ToList();
IList<JToken> children = JObject.Parse(rpcResponse.ToString()).Children().ToList();
for (var i = 0; i < children.Count(); i++)
{
var getRawMemPoolVerboseResponse = new GetRawMemPoolVerboseResponse
{
TxId = rpcResponseAsKvp[i].Key
};
getRawMemPoolResponse.TxIds.Add(getRawMemPoolVerboseResponse.TxId);
foreach (var property in children[i].SelectMany(grandChild => grandChild.OfType<JProperty>()))
{
switch (property.Name)
{
case "currentpriority":
double currentPriority;
if (double.TryParse(property.Value.ToString(), out currentPriority))
{
getRawMemPoolVerboseResponse.CurrentPriority = currentPriority;
}
break;
case "depends":
foreach (var jToken in property.Value)
{
getRawMemPoolVerboseResponse.Depends.Add(jToken.Value<string>());
}
break;
case "fee":
decimal fee;
if (decimal.TryParse(property.Value.ToString(), out fee))
{
getRawMemPoolVerboseResponse.Fee = fee;
}
break;
case "height":
int height;
if (int.TryParse(property.Value.ToString(), out height))
{
getRawMemPoolVerboseResponse.Height = height;
}
break;
case "size":
int size;
if (int.TryParse(property.Value.ToString(), out size))
{
getRawMemPoolVerboseResponse.Size = size;
}
break;
case "startingpriority":
double startingPriority;
if (double.TryParse(property.Value.ToString(), out startingPriority))
{
getRawMemPoolVerboseResponse.StartingPriority = startingPriority;
}
break;
case "time":
int time;
if (int.TryParse(property.Value.ToString(), out time))
{
getRawMemPoolVerboseResponse.Time = time;
}
break;
default:
throw new Exception("Unkown property: " + property.Name + " in GetRawMemPool()");
}
}
getRawMemPoolResponse.VerboseResponses.Add(getRawMemPoolVerboseResponse);
}
return getRawMemPoolResponse;
}
public string GetRawChangeAddress()
{
return _rpcConnector.MakeRequest<string>(RpcMethods.getrawchangeaddress);
}
public GetRawTransactionResponse GetRawTransaction(string txId, int verbose)
{
if (verbose == 0)
{
return new GetRawTransactionResponse
{
Hex = _rpcConnector.MakeRequest<string>(RpcMethods.getrawtransaction, txId, verbose)
};
}
if (verbose == 1)
{
return _rpcConnector.MakeRequest<GetRawTransactionResponse>(RpcMethods.getrawtransaction, txId, verbose);
}
throw new Exception("Invalid verbose value: " + verbose + " in GetRawTransaction()!");
}
public decimal GetReceivedByAccount(string account, int minConf)
{
return _rpcConnector.MakeRequest<decimal>(RpcMethods.getreceivedbyaccount, account, minConf);
}
public decimal GetReceivedByAddress(string bitcoinAddress, int minConf)
{
return _rpcConnector.MakeRequest<decimal>(RpcMethods.getreceivedbyaddress, bitcoinAddress, minConf);
}
public decimal GetReceivedByLabel(string bitcoinAddress, int minConf)
{
return _rpcConnector.MakeRequest<decimal>(RpcMethods.getreceivedbylabel, bitcoinAddress, minConf);
}
public GetTransactionResponse GetTransaction(string txId, bool? includeWatchonly)
{
return includeWatchonly == null
? _rpcConnector.MakeRequest<GetTransactionResponse>(RpcMethods.gettransaction, txId)
: _rpcConnector.MakeRequest<GetTransactionResponse>(RpcMethods.gettransaction, txId, includeWatchonly);
}
public GetTransactionResponse GetTxOut(string txId, int n, bool includeMemPool)
{
return _rpcConnector.MakeRequest<GetTransactionResponse>(RpcMethods.gettxout, txId, n, includeMemPool);
}
public GetTxOutSetInfoResponse GetTxOutSetInfo()
{
return _rpcConnector.MakeRequest<GetTxOutSetInfoResponse>(RpcMethods.gettxoutsetinfo);
}
public decimal GetUnconfirmedBalance()
{
return _rpcConnector.MakeRequest<decimal>(RpcMethods.getunconfirmedbalance);
}
public GetWalletInfoResponse GetWalletInfo()
{
return _rpcConnector.MakeRequest<GetWalletInfoResponse>(RpcMethods.getwalletinfo);
}
public string Help(string command)
{
return string.IsNullOrWhiteSpace(command)
? _rpcConnector.MakeRequest<string>(RpcMethods.help)
: _rpcConnector.MakeRequest<string>(RpcMethods.help, command);
}
public void ImportAddress(string address, string label, bool rescan)
{
_rpcConnector.MakeRequest<string>(RpcMethods.importaddress, address, label, rescan);
}
public string ImportPrivKey(string privateKey, string label, bool rescan)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.importprivkey, privateKey, label, rescan);
}
public void ImportWallet(string filename)
{
_rpcConnector.MakeRequest<string>(RpcMethods.importwallet, filename);
}
public string KeyPoolRefill(uint newSize)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.keypoolrefill, newSize);
}
public Dictionary<string, decimal> ListAccounts(int minConf, bool? includeWatchonly)
{
return includeWatchonly == null
? _rpcConnector.MakeRequest<Dictionary<string, decimal>>(RpcMethods.listaccounts, minConf)
: _rpcConnector.MakeRequest<Dictionary<string, decimal>>(RpcMethods.listaccounts, minConf, includeWatchonly);
}
public List<List<ListAddressGroupingsResponse>> ListAddressGroupings()
{
var unstructuredResponse = _rpcConnector.MakeRequest<List<List<List<object>>>>(RpcMethods.listaddressgroupings);
var structuredResponse = new List<List<ListAddressGroupingsResponse>>(unstructuredResponse.Count);
for (var i = 0; i < unstructuredResponse.Count; i++)
{
for (var j = 0; j < unstructuredResponse[i].Count; j++)
{
if (unstructuredResponse[i][j].Count > 1)
{
var response = new ListAddressGroupingsResponse
{
Address = unstructuredResponse[i][j][0].ToString()
};
decimal balance;
if (decimal.TryParse(unstructuredResponse[i][j][1].ToString(), out balance))
{
response.Balance = balance;
}
if (unstructuredResponse[i][j].Count > 2)
{
response.Account = unstructuredResponse[i][j][2].ToString();
}
if (structuredResponse.Count < i + 1)
{
structuredResponse.Add(new List<ListAddressGroupingsResponse>());
}
structuredResponse[i].Add(response);
}
}
}
return structuredResponse;
}
public List<string> ListLabels()
{
return _rpcConnector.MakeRequest<List<string>>(RpcMethods.listlabels);
}
public string ListLockUnspent()
{
return _rpcConnector.MakeRequest<string>(RpcMethods.listlockunspent);
}
public List<ListReceivedByAccountResponse> ListReceivedByAccount(int minConf, bool includeEmpty, bool? includeWatchonly)
{
return includeWatchonly == null
? _rpcConnector.MakeRequest<List<ListReceivedByAccountResponse>>(RpcMethods.listreceivedbyaccount, minConf, includeEmpty)
: _rpcConnector.MakeRequest<List<ListReceivedByAccountResponse>>(RpcMethods.listreceivedbyaccount, minConf, includeEmpty, includeWatchonly);
}
public List<ListReceivedByAddressResponse> ListReceivedByAddress(int minConf, bool includeEmpty, bool? includeWatchonly)
{
return includeWatchonly == null
? _rpcConnector.MakeRequest<List<ListReceivedByAddressResponse>>(RpcMethods.listreceivedbyaddress, minConf, includeEmpty)
: _rpcConnector.MakeRequest<List<ListReceivedByAddressResponse>>(RpcMethods.listreceivedbyaddress, minConf, includeEmpty, includeWatchonly);
}
public List<ListReceivedByLabelResponse> ListReceivedByLabel(int minConf, bool includeEmpty, bool? includeWatchonly)
{
return _rpcConnector.MakeRequest<List<ListReceivedByLabelResponse>>(RpcMethods.listreceivedbylabel, minConf, includeEmpty, includeWatchonly);
}
public ListSinceBlockResponse ListSinceBlock(string blockHash, int targetConfirmations, bool? includeWatchonly)
{
return includeWatchonly == null
? _rpcConnector.MakeRequest<ListSinceBlockResponse>(RpcMethods.listsinceblock, (string.IsNullOrWhiteSpace(blockHash) ? "" : blockHash), targetConfirmations)
: _rpcConnector.MakeRequest<ListSinceBlockResponse>(RpcMethods.listsinceblock, (string.IsNullOrWhiteSpace(blockHash) ? "" : blockHash), targetConfirmations, includeWatchonly);
}
public List<ListTransactionsResponse> ListTransactions(string account, int count, int from, bool? includeWatchonly)
{
return includeWatchonly == null
? _rpcConnector.MakeRequest<List<ListTransactionsResponse>>(RpcMethods.listtransactions, (string.IsNullOrWhiteSpace(account) ? "*" : account), count, from)
: _rpcConnector.MakeRequest<List<ListTransactionsResponse>>(RpcMethods.listtransactions, (string.IsNullOrWhiteSpace(account) ? "*" : account), count, from, includeWatchonly);
}
public List<ListUnspentResponse> ListUnspent(int minConf, int maxConf, List<string> addresses)
{
return _rpcConnector.MakeRequest<List<ListUnspentResponse>>(RpcMethods.listunspent, minConf, maxConf, (addresses ?? new List<string>()));
}
public bool LockUnspent(bool unlock, IList<ListUnspentResponse> listUnspentResponses)
{
IList<object> transactions = new List<object>();
foreach (var listUnspentResponse in listUnspentResponses)
{
transactions.Add(new
{
txid = listUnspentResponse.TxId,
vout = listUnspentResponse.Vout
});
}
return _rpcConnector.MakeRequest<bool>(RpcMethods.lockunspent, unlock, transactions.ToArray());
}
public bool Move(string fromAccount, string toAccount, decimal amount, int minConf, string comment)
{
return _rpcConnector.MakeRequest<bool>(RpcMethods.move, fromAccount, toAccount, amount, minConf, comment);
}
public void Ping()
{
_rpcConnector.MakeRequest<string>(RpcMethods.ping);
}
public bool PrioritiseTransaction(string txId, decimal priorityDelta, decimal feeDelta)
{
return _rpcConnector.MakeRequest<bool>(RpcMethods.prioritisetransaction, txId, priorityDelta, feeDelta);
}
public string SendFrom(string fromAccount, string toBitcoinAddress, decimal amount, int minConf, string comment, string commentTo)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.sendfrom, fromAccount, toBitcoinAddress, amount, minConf, comment, commentTo);
}
public string SendMany(string fromAccount, Dictionary<string, decimal> toBitcoinAddress, int minConf, string comment)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.sendmany, fromAccount, toBitcoinAddress, minConf, comment);
}
public string SendRawTransaction(string rawTransactionHexString, bool? allowHighFees)
{
return allowHighFees == null
? _rpcConnector.MakeRequest<string>(RpcMethods.sendrawtransaction, rawTransactionHexString)
: _rpcConnector.MakeRequest<string>(RpcMethods.sendrawtransaction, rawTransactionHexString, allowHighFees);
}
public string SendToAddress(string bitcoinAddress, decimal amount, string comment, string commentTo, bool subtractFeeFromAmount)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.sendtoaddress, bitcoinAddress, amount, comment, commentTo, subtractFeeFromAmount);
}
public string SetAccount(string bitcoinAddress, string account)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.setaccount, bitcoinAddress, account);
}
public string SetLabel(string bitcoinAddress, string label)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.setlabel, bitcoinAddress, label);
}
public string SetGenerate(bool generate, short generatingProcessorsLimit)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.setgenerate, generate, generatingProcessorsLimit);
}
public string SetTxFee(decimal amount)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.settxfee, amount);
}
public string SignMessage(string bitcoinAddress, string message)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.signmessage, bitcoinAddress, message);
}
public SignRawTransactionResponse SignRawTransaction(SignRawTransactionRequest request)
{
#region default values
if (request.Inputs.Count == 0)
{
request.Inputs = null;
}
if (string.IsNullOrWhiteSpace(request.SigHashType))
{
request.SigHashType = SigHashType.All;
}
if (request.PrivateKeys.Count == 0)
{
request.PrivateKeys = null;
}
#endregion
return _rpcConnector.MakeRequest<SignRawTransactionResponse>(RpcMethods.signrawtransaction, request.RawTransactionHex, request.Inputs, request.PrivateKeys, request.SigHashType);
}
public SignRawTransactionWithKeyResponse SignRawTransactionWithKey(SignRawTransactionWithKeyRequest request)
{
#region default values
if (request.PrivateKeys.Count == 0)
{
request.PrivateKeys = null;
}
if (request.Inputs.Count == 0)
{
request.Inputs = null;
}
if (string.IsNullOrWhiteSpace(request.SigHashType))
{
request.SigHashType = SigHashType.All;
}
#endregion
return _rpcConnector.MakeRequest<SignRawTransactionWithKeyResponse>(RpcMethods.signrawtransactionwithkey, request.RawTransactionHex, request.PrivateKeys, request.Inputs, request.SigHashType);
}
public SignRawTransactionWithWalletResponse SignRawTransactionWithWallet(SignRawTransactionWithWalletRequest request)
{
#region default values
if (request.Inputs.Count == 0)
{
request.Inputs = null;
}
if (string.IsNullOrWhiteSpace(request.SigHashType))
{
request.SigHashType = SigHashType.All;
}
#endregion
return _rpcConnector.MakeRequest<SignRawTransactionWithWalletResponse>(RpcMethods.signrawtransactionwithwallet, request.RawTransactionHex, request.Inputs, request.SigHashType);
}
public GetFundRawTransactionResponse GetFundRawTransaction(string rawTransactionHex, FundRawTransactionOptions options = null)
{
var jData = JObject.Parse(JsonConvert.SerializeObject(options.Data));
return _rpcConnector.MakeRequest<GetFundRawTransactionResponse>(RpcMethods.fundrawtransaction, rawTransactionHex, jData);
}
public string Stop()
{
return _rpcConnector.MakeRequest<string>(RpcMethods.stop);
}
public string SubmitBlock(string hexData, params object[] parameters)
{
return parameters == null
? _rpcConnector.MakeRequest<string>(RpcMethods.submitblock, hexData)
: _rpcConnector.MakeRequest<string>(RpcMethods.submitblock, hexData, parameters);
}
public ValidateAddressResponse ValidateAddress(string bitcoinAddress)
{
return _rpcConnector.MakeRequest<ValidateAddressResponse>(RpcMethods.validateaddress, bitcoinAddress);
}
public bool VerifyChain(ushort checkLevel, uint numBlocks)
{
return _rpcConnector.MakeRequest<bool>(RpcMethods.verifychain, checkLevel, numBlocks);
}
public bool VerifyMessage(string bitcoinAddress, string signature, string message)
{
return _rpcConnector.MakeRequest<bool>(RpcMethods.verifymessage, bitcoinAddress, signature, message);
}
public string WalletLock()
{
return _rpcConnector.MakeRequest<string>(RpcMethods.walletlock);
}
public string WalletPassphrase(string passphrase, int timeoutInSeconds)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.walletpassphrase, passphrase, timeoutInSeconds);
}
public string WalletPassphraseChange(string oldPassphrase, string newPassphrase)
{
return _rpcConnector.MakeRequest<string>(RpcMethods.walletpassphrasechange, oldPassphrase, newPassphrase);
}
public override string ToString()
{
return Parameters.CoinLongName;
}
}
}