-
Notifications
You must be signed in to change notification settings - Fork 1
/
Wallet.ts
888 lines (831 loc) · 30.5 KB
/
Wallet.ts
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
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
import { AddressValidation, PubKeyValidation } from '../contracts/validation';
import { BackupPrivateKeys } from '../contracts/backupPrivateKeys';
import { BackupWallet } from '../contracts/backupWallet';
import { BalanceDetail } from '../contracts/balanceDetail';
import { WalletFailStatus, WalletSuccessStatus } from '../contracts/checkwallet';
import { KeysPair } from '../contracts/keysPair';
import { ListSinceBlock } from '../contracts/listSinceBolck';
import { RainByMagnitude } from '../contracts/rainByMagnitude';
import { Output, RawTransaction } from '../contracts/rawTransaction';
import { Receivement } from '../contracts/receivement';
import { Reserve } from '../contracts/reserve';
import { Script } from '../contracts/script';
import { StakeListing } from '../contracts/stake';
import { DetailedRawTransaction, Transaction } from '../contracts/transaction';
import { SigHashType, TransactionDependencies, TransactionSigned } from '../contracts/transactionRaw';
import { TransactionShort } from '../contracts/transactionShort';
import { TransactionUnspent } from '../contracts/transactionUnspent';
import { UnspentReport, UTXO } from '../contracts/utxo';
import { WalletInfo } from '../contracts/walletInfo';
import { RPCBase } from '../RPCBase';
import {
Address,
Hex,
PublicKey,
TX,
} from '../types';
export class Wallet extends RPCBase {
/**
* Add a nrequired-to-sign multisignature address to the wallet.
*
* @description
* Adds a multisignature address to the wallet.
* Returns the address addeded.
* Requires to tell the number of keys needed for a transaction and list of
* keys (keys are either addresses or a hexadecimal public key).
* If an account is given, the address will go into that account.
* Multisignature addresses make it so that you can share a wallet with multiple people and
* require nrequired people to approve of a transaction. The maximum number keys is 16.
* @example
* grcRPC.addmultisigaddress(2, ['SBqubTKufqwpupnZsvzC3kSv9MCLrFXEUz', 'mhE9F4Cixhx9Dn8cB4Uf2EXLMCJR7muAFZ']);
*
* @param {number} nrequired - The minimum (m) number of signatures required to spend this m-of-n multisig script.
* @param {(Array<Address> | Array<PublicKey>)} keys - A public key against which signatures will be checked.
* @param {string} [account] - The account name in which the address should be stored. Leave blank for the default account.
* @returns {Promise<Address> | never}
* @memberof Wallet
*/
public async addMultisigAddress(
nrequired: number,
keys: Address[] | PublicKey[],
account?: string,
): Promise<Address> | never {
return this.call<Address>(
'addmultisigaddress',
nrequired,
keys,
account,
);
}
/**
* Adds a reedemscript specified in hex to the wallet.
* Will return the address generated.
* If account is given, the pay to script hash will go into that account.
*
* @param {Hex} redeemScript
* @param {string} [account]
* @returns {Promise<Address>}
* @memberof Wallet
*/
public async addRedeemScript(
redeemScript: Hex,
account?: string,
): Promise<Address> {
return this.call<Address>(
'addredeemscript',
redeemScript,
account,
);
}
/**
* Creates a backup of the private keys and creates a keys.dat files (also includes the date in the filename).
* The data in the file is formatted like this: Address: ADDRESS, Secret: PRIVATE KEY.
* File location and "result": true will be given if it successes, otherwise it will show an error message.
* Requires the wallet to be fully unlocked
*
* @returns {(Promise<BackupPrivateKeys> | never)}
* @memberof Wallet
*/
public async backupPrivateKeys(): Promise<BackupPrivateKeys> | never {
return this.call<BackupPrivateKeys>('backupprivatekeys');
}
/**
* Creates a backup of the wallet.dat and gridcoinresearch.conf files (it also adds dates in the backup files’ names).
* Returns if it was successful for each file
* The files will be created in the walletbackups folder.
* See the Config Wiki Page to find the location for your operating system of the walletbackups folder and other Gridcoin files
* @see https://gridcoin.us/wiki/config-file
*
* @returns {Promise<BackupWallet>}
* @memberof Wallet
*/
public async backupWallet(): Promise<BackupWallet> {
return this.call<BackupWallet>('backupwallet');
}
/**
* Creates a transaction that will send the given amount (rounded to 0.00000001) to no one making the coins disappear permanently.
* No one can get back the coins spent by this command.
* If *hex string* is specified, it will add on to the script used in the transaction.
*
* Requires the wallet to be fully unlocked
*
* @param {number} amount - Amount to be burned down
* @param {string} [hexString]
* @returns {Promise<string>}
* @memberof Wallet
*/
public async burn(amount: number, hexString?: Hex): Promise<TX> {
return this.call<TX>('burn', amount, hexString);
}
/**
* Checks that the wallet is reporting the correct balance and is not missing any transactions.
* Returns { walletCheckPassed: true } if it finds no issues. On error it will return:
* {
* mismatchedSpentCoins: nMismatchSpent,
* amountInQuestion: nBalanceInQuestion
* }
* with nMismatchSpent numbers showing the number of transactions missed (either counted when it shouldn’t be or not counted when it should)
* and nBalanceInQuestion showing the amount involved in those transactions (absolute value, does not subtract)
*
* @returns {Promise<any>}
* @memberof Wallet
*/
public async checkWallet(): Promise<WalletFailStatus | WalletSuccessStatus> {
return this.call<WalletFailStatus | WalletSuccessStatus>('checkwallet');
}
/**
* Create a transaction spending the given inputs and creating new outputs.
*
* Outputs can be addresses or data.
* Returns hex-encoded raw transaction.
* Note that the transaction's inputs are not signed, and
* it is not stored in the wallet or transmitted to the network.
*
* @param {RawTransaction[]} transactions - A json array of json objects
* @example
* [
* {
* "txid":"id", (string, required) The transaction id
* "vout":n (numeric, required) The output number
* }
* ,...
* ]
* @param {Output} outputs - a json object with outputs
* @example
* {
* "address": x.xxx (numeric, required) The key is the bitcoin address, the value is the CURRENCY_UNIT amount
* "data\": "hex", (string, required) The key is "data", the value is hex encoded data
* ...
* }
* @returns {Promise<{ transaction: string }>}
* @memberof Wallet
*/
public async createRawTransaction(
transactions: RawTransaction[],
outputs: Output,
): Promise<{ transaction: string }> {
return this.call<{ transaction: string }>(
'createrawtransaction',
transactions as any,
outputs,
);
}
/** @todo: consolidatemsunspent */
/**
* Return a JSON object representing the serialized, hex-encoded transaction
*
* @param {string} rawTransaction - hex string
* @returns {Promise<Transaction>}
* @memberof Wallet
*/
public async decodeRawTransaction(rawTransaction: string): Promise<Transaction> {
return this.call<Transaction>('decoderawtransaction', rawTransaction);
}
/**
* Decode a hex-encoded script
*
* @param {string} script - hex string
* @returns {Promise<Script>}
* @memberof Wallet
*/
public async decodeScript(script: string): Promise<Script> {
return this.call<Script>('decodescript', script);
}
/** @todo: dumpprivkey */
/** @todo: dumpwallet */
/** @todo: encryptwallet */
/**
* Returns the account associated with the given address.
*
* @param {string} gridcoinAddress
* @returns {Promise<string>} - an account name
* @memberof Wallet
*/
public async getAccount(gridcoinAddress: Address): Promise<string> {
return this.call<string>('getaccount', gridcoinAddress);
}
/**
* Returns the current Gridcoin address for receiving payments to this account.
* @description
* If account does not exist, it will be created along with an associated new address that will be returned.
*
* @param {string} account - an account name
* @returns {Promise<Address>} - GRC address
* @memberof Wallet
*/
public async getAccountAddress(account: string): Promise<Address> {
return this.call<Address>('getaccountaddress', account);
}
/**
* Returns the list of addresses for the given account.
*
* @param {string} account - the account name
* @returns {Promise<Address[]>} - a list of addresses
* @memberof Wallet
*/
public async getAddressesByAccount(account: string): Promise<Address[]> {
return this.call<Address[]>('getaddressesbyaccount', account);
}
/**
* Get current balance
* @description
* If account is not specified, returns the server's total available balance
* If account is specified, returns the balance in the account
* Note that the account "" is not the same as leaving the parameter out
* The server total may be different to the balance in the default "" account.
*
* @param {string} [account='*'] - The selected account, or "*" for entire wallet. It may be the default account using
* @param {number} [minConf=1] - Only include transactions confirmed at least this many times.
* @param {boolean} [includeWatchOnly=false] - Also include balance in watchonly addresses (@see importAddress)
* @returns {Promise<number>}
* @memberof Wallet
*/
public async getBalance(
account = '*',
minConf = 1,
includeWatchOnly = false,
): Promise<number> {
return this.call<number>('getbalance', account, minConf, includeWatchOnly);
}
/**
* Lists outputs similar to listtransactions that compose the entire balance
*
* @param {number} [minConf=1] - Only include transactions confirmed at least this many times
* @param {boolean} [includeWatchOnly=false] - Also include balance in watchonly addresses (@see importAddress)
* @returns {Promise<BalanceDetail>}
* @memberof Wallet
*/
public async getBalanceDetail(
minConf = 1,
includeWatchOnly = false,
): Promise<BalanceDetail> {
return this.call<BalanceDetail>('getbalancedetail', minConf, includeWatchOnly);
}
/**
* Returns a new Gridcoin address for receiving payments.
* @description
* If [account] is specified, it is added to the address book
* so payments received with the address will be credited to *account*.
*
* @param {string} [account]
* @returns {Promise<string>}
* @memberof Wallet
*/
public async getNewAddress(account?: string): Promise<Address> {
return this.call<Address>('getnewaddress', account);
}
/**
* Returns new public key for coinbase generation.
*
* @param {string} [account]
* @returns {Promise<PublicKey>}
* @memberof Wallet
*/
public async getNewPubkey(account?: string): Promise<PublicKey> {
return this.call<PublicKey>('getnewpubkey', account);
}
/**
* returns an Object with information about txid
*
* @template Type
* @param {TX} txid
* @param {Type} verbose
* @returns {Promise<Type extends true ? DetailedRawTransaction : string>}
* @memberof Wallet
*/
public async getRawTransaction<Type extends boolean>(
txid: TX,
verbose: Type,
): Promise<Type extends true ? DetailedRawTransaction : string> {
return this.call('getrawtransaction', txid, verbose);
}
/**
* Get a string that is serialized, hex-encoded data for txid from the wallet.
*
* @param {TX} txid
* @returns {Promise<string>}
* @memberof Wallet
*/
public async getRawWalletTransaction(txid: TX): Promise<string> {
return this.call<string>('getrawwallettransaction', txid);
}
/**
* Returns the total amount received by addresses with *account* in transactions with at least *minconf* confirmations.
* If *account* not provided return will include all transactions to all accounts.
*
* @param {string} account - the account name
* @param {number} [minconf=1] - the minimum number of confirmations
* @returns {Promise<number>} - the number of coins received
* @deprecated
* @memberof Wallet
*/
public async getReceivedByAccount(account: string, minconf = 1): Promise<number> {
return this.call<number>('getreceivedbyaccount', account, minconf);
}
/**
* Returns the amount received by gridcoinaddress in transactions with at least *minconf* confirmations.
* @description
* It correctly handles the case where someone has sent to the address in multiple transactions.
* Keep in mind that addresses are only ever used for receiving transactions.
* Works only for addresses in the local wallet, external addresses will always show 0.
*
* @param {string} gridcoinAddress - the address
* @param {number} [minconf=1] - the minimum number of confirmations
* @returns {Promise<number>} - the number of coins received
* @memberof Wallet
*/
public async getReceivedByAddress(
gridcoinAddress: string,
minconf = 1,
): Promise<number> {
return this.call<number>('getreceivedbyaddress', gridcoinAddress, minconf);
}
/**
* Get detailed information about in-wallet transaction txid
*
* @param {TX} txid - The transaction id
* @param {boolean} [includeWatchOnly=false] - Whether to include watchonly addresses in balance calculation and details
* @returns {Promise<Transaction>}
* @memberof Wallet
*/
public async getTransaction(
txid: TX,
includeWatchOnly = false,
): Promise<Transaction> {
return this.call<Transaction>('gettransaction', txid, includeWatchOnly);
}
/**
* returns the unconfirmed balance in the wallet
*
* @returns {Promise<number>}
* @memberof Wallet
*/
public async getUnconfirmedBalance(): Promise<number> {
return this.call<number>('getunconfirmedbalance');
}
/**
* Returns useful information about current wallet state.
*
* @returns {Promise<WalletInfo>}
* @memberof Wallet
*/
public async getWalletInfo(): Promise<WalletInfo> {
return this.call<WalletInfo>('getwalletinfo');
}
/** @todo: importprivkey */
/** @todo: importwallet */
/**
* Fills the keypool.
*
* @param {number} newSize
* @returns {Promise<null>}
* @memberof Wallet
*/
public async keyPoolRefill(newSize: number): Promise<null> {
return this.call('keypoolrefill', newSize);
}
/**
* Returns UniValue that has account names as keys, account balances as values.
*
* @deprecated
* @param {number} [minConf=1] - Only include transactions with at least this many confirmations
* @param {boolean} [includeWatchOnly=false] Include balances in watchonly addresses (@see importaddress)
* @returns {Promise<{ [key: string]: number }>} - The property name is the account name, and the value is the total balance for the account
* @memberof Wallet
*/
public async listAccounts(
minConf = 1,
includeWatchOnly = false,
): Promise<{ [key: string]: number }> {
return this.call('listaccounts', minConf, includeWatchOnly);
}
/**
* Lists groups of addresses which have had their common ownership
* made public by common use as inputs or as the resulting change in past transactions
*
* @returns {Promise<[string, number][][]>}
* @memberof Wallet
*/
public async listAddressGroupings(): Promise<[string, number][][]> {
return this.call('listaddressgroupings');
}
/** @todo: listreceivedbyaccount */
/**
* List balances by receiving address.
*
* @param {number} [minConf=1] - The minimum number of confirmations before payments are included.
* @param {boolean} [includeEmpty=false] - Whether to include addresses that haven't received any payments.
* @param {boolean} [includeWatchOnly=false] - Whether to include watchonly addresses (see 'importaddress').
* @returns {Promise<Receivement[]>}
* @memberof Wallet
*/
public listReceivedByAddress(
minConf = 1,
includeEmpty = false,
includeWatchOnly = false,
): Promise<Receivement[]> {
return this.call<Receivement[]>(
'listreceivedbyaddress',
minConf,
includeEmpty,
includeWatchOnly,
);
}
/**
* Get all transactions in blocks since block *blockhash*, or all transactions if omitted
*
* @param {string} [blockHash] - The block hash to list transactions since
* @param {number} [targetConfirmations] - The confirmations required, must be 1 or more
* @param {boolean} [includeWatchonly] - Include transactions to watchonly addresses (@see importaddress)
* @returns {Promise<ListSinceBlock>}
* @memberof GridcoinRPC
*/
public async listSinceBlock(
blockHash?: string,
targetConfirmations?: number,
includeWatchonly?: boolean,
): Promise<ListSinceBlock> {
return this.call<ListSinceBlock>(
'listsinceblock',
blockHash,
targetConfirmations,
includeWatchonly,
);
}
/**
* Returns count most recent stakes.
*
* @param {number} [count=10]
* @returns {Promise<StakeListing[]>}
* @memberof Wallet
*/
public async listStakes(count = 10): Promise<StakeListing[]> {
return this.call<StakeListing[]>('liststakes', count);
}
/**
* Returns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.
*
* @param {string} [account='*'] - The account name. If not included, it will list all transactions for all accounts.
* @param {number} [count=10] - The number of transactions to return
* @param {number} [from=0] - The number of transactions to skip
* @param {boolean} [includeWatchonly=false] - Include transactions to watchonly addresses (@see importaddress) If is set true, it will list sent transactions as well
* @returns {Promise<ITransactionShort>}
* @memberof Wallet
*/
public async listTransactions(
account = '*',
count = 10,
from = 0,
includeWatchonly = false,
): Promise<TransactionShort[]> {
return this.call<TransactionShort[]>(
'listtransactions',
account,
count,
from,
includeWatchonly,
);
}
/**
* Returns array of unspent transaction outputs with between minconf and maxconf (inclusive) confirmations
* Optionally filtered to only include txouts paid to specified addresses
* Results are an array of Objects, each of which has
* {txid, vout, scriptPubKey, amount, confirmations}
*
* @param {number} [minConf]
* @param {number} [maxConf]
* @param {...Address[]} addresses
* @returns {Promise<TransactionUnspent[]>}
* @memberof Wallet
*/
public async listUnspent(
minConf?: number,
maxConf?: number,
...addresses: Address[]
): Promise<TransactionUnspent[]> {
return this.call<TransactionUnspent[]>('listunspent', minConf, maxConf, ...addresses);
}
/** @todo: consolidateunspent */
/**
* Make a public/private key pair.
*
* @param {string} [prefix] - is optional preferred prefix for the public key
* @returns {Promise<KeysPair>}
* @memberof Wallet
*/
public async makeKeyPair(prefix?: string): Promise<KeysPair> {
return this.call<KeysPair>('makekeypair', prefix);
}
/** @todo: maintainbackups */
/**
* rain coins by magnitude on network
*
* @param {string} project - Required: If a project is specified, rain will be limited to that project. Use * for network-wide.
* @param {number} amount - Required: Specify amount of coins to be rained in double precision float
* @param {string} [message] - Optional: Provide a message rained to all rainees
* @returns {Promise<RainByMagnitude>}
* @memberof Wallet
*/
public async rainByMagnitude(
project: string,
amount: number,
message?: string,
): Promise<RainByMagnitude> {
return this.call<RainByMagnitude>('rainbymagnitude', project, amount, message);
}
/**
* Repair wallet if checkwallet reports any problem.
*
* @returns {Promise<RepairWallet>}
* @memberof Wallet
*/
public async repairWallet(): Promise<WalletSuccessStatus | WalletFailStatus> {
return this.call<WalletSuccessStatus | WalletFailStatus>('repairwallet');
}
/**
* Resend any failed or unsent transactions.
* Requires unlocked wallet
*
* @returns {Promise<null>}
* @memberof Wallet
*/
public async resendTx(): Promise<null> {
return this.call('resendtx');
}
/**
* Reserved amount secures a balance in wallet that can be spendable at anytime.
* However reserve will secure utxo(s) of any size to respect this setting.
* If no parameters provided current setting is printed
*
* @param {boolean} [reserve] - is true or false to turn balance reserve on or off.
* @param {number} [amount] - is a real and rounded to cent
* @returns {Promise<Reserve>}
* @memberof Wallet
*/
public async reserveBalance(reserve?: boolean, amount?: number): Promise<Reserve> {
return this.call<Reserve>('reservebalance', reserve, amount);
}
/**
* Searches a block range for a specified address with unspent utxos
* and displays them in a json response with the option of exporting
* to file
*
* @param {Address} address - Multi-signature address
* @param {number} blockStart - Block number to start search from
* @param {number} blockEnd - Block number to end search on
* @param {string} [exports] - Exports to a file in backup-dir/rpc in format of multisigaddress-datetime.type
* @param {boolean} [type] - Export to a file with file type (xml, txt or json -- Required if export true)
* @returns {Promise<[UTXO[], UnspentReport]>}
* @memberof Wallet
*/
public async scanForUnspent(
address: Address,
blockStart: number,
blockEnd: number,
exports?: boolean,
type?: string,
): Promise<[UTXO[], UnspentReport]> {
return this.call(
'scanforunspent',
address,
blockStart,
blockEnd,
exports,
type,
);
}
/**
* Sends *amount* of Gridcoin from *account* to *gridcoinaddress*.
*
* @param {string} account - Account FROM
* @param {Address} address - Address TO
* @param {number} amount - Amount to send
* @param {number} [minConf] - is the minimum number of confirmations for a UTXO to be used.
* @param {string} [comment] - is a personal comment about what the transaction is for (doesn’t go into the transaction, it is only stored locally).
* @param {string} [commentTo] - is also a personal comment about who you are sending to (also only local).
* @param {string} [message] - is a message/comment that is sent publicly on the transaction.
* @returns {Promise<TX>}
* @memberof Wallet
*/
public async sendFrom(
account: string,
address: Address,
amount: number,
minConf?: number,
comment?: string,
commentTo?: string,
message?: string,
): Promise<TX> {
return this.call<TX>(
'sendfrom',
account,
address,
amount,
minConf,
comment,
commentTo,
message,
);
}
/**
* Send from *fromaccount* to a list of addresses.
* Use '' if you don’t want to limit to one account label. Addresses should be listed in JSON format.
*
* @param {string} account - - Account FROM
* @param {{ [key: string]: number }} recipients - { Address1: amount1, Address2: amount2, ... }
* @param {number} [minConf=1] - is the minimum number of confirmations for a UTXO to be used.
* @param {string} [comment] - is a personal comment about what the transaction is for (doesn’t go into the transaction, it is only stored locally).
* @returns {Promise<any>}
* @memberof Wallet
*/
public async sendMany(
account: string,
recipients: { [key: string]: number },
minConf = 1, // eslint-disable-line default-param-last
comment?: string,
): Promise<TX> {
return this.call<TX>(
'sendmany',
account,
recipients,
minConf,
comment,
);
}
/**
* Submits raw transaction (serialized, hex-encoded) to local node and network
*
* @param {string} rawTransaction - raw transaction (serialized, hex-encoded)
* @returns {Promise<TX>}
* @memberof Wallet
*/
public async sendRawTransaction(rawTransaction: string): Promise<TX> {
return this.call<TX>('sendrawtransaction', rawTransaction);
}
/**
* Sends amount of Gridcoin to gridcoinaddress.
*
* @param {Address} address - Recipient address
* @param {number} amount - is a real and is rounded to the nearest 0.000001
* @param {string} [comment] - a comment used to store what the transaction is for. This is not part of the transaction, just kept in your wallet.
* @param {string} [commentTo] - a comment to store the name of the person or organization to which you're sending the transaction. This is not part of the transaction, just kept in your wallet
* @param {string} [message] - Optional message to add to the receiver.
* @returns {Promise<TX>}
* @memberof Wallet
*/
public async sendToAddress(
address: Address,
amount: number,
comment?: string,
commentTo?: string,
message?: string,
): Promise<TX> {
return this.call<TX>(
'sendtoaddress',
address,
amount,
comment,
commentTo,
message,
);
}
/**
* Sets the account associated with the given address.
* Assigning address that is already assigned to the same account will create a new address associated with that account.
*
* @param {Address} address
* @param {string} account
* @returns {Promise<null>}
* @memberof Wallet
*/
public async setAccount(address: Address, account: string): Promise<null> {
return this.call('setaccount', address, account);
}
/**
* Set the transaction fee per kilobyte paid by transactions created by this wallet.
*
* @param {number} amount - TX fee, rounds to 0.00000001 GRC
* @returns {Promise<boolean>}
* @memberof Wallet
*/
public async setTXfee(amount: number): Promise<boolean> {
return this.call('settxfee', amount);
}
/**
* Returns a signed a message using the private key from *Gridcoinaddress*.
* Lets you prove that this message came from the owner of an address.
* You can verify a signed message with the verify message command.
* (It will not send this message anywhere. You have to do that)
*
* @param {Address} address
* @param {string} message
* @returns {Promise<string>} - Base64 signature
* @memberof Wallet
*/
public async signMessage(address: Address, message: string): Promise<string> {
return this.call('signmessage', address, message);
}
/**
* Sign inputs for raw transaction (serialized, hex-encoded).
*
*
* @param {string} rawTransaction - raw transaction (serialized, hex-encoded)
* @param {TransactionDependencies[]|null} transactionDependencies - is an array of previous transaction outputs that this transaction depends on but may not yet be in the blockchain.
* @param {string[]|null} privateKeys - is an array of base58-encoded private keys that, if given, will be the only keys used to sign the transaction
* @param {SigHashType} sigHashType - is a string that is one of six values; ALL, NONE, SINGLE or ALL|ANYONECANPAY, NONE|ANYONECANPAY, SINGLE|ANYONECANPAY.
* @returns {Promise<TransactionSigned>}
* @memberof Wallet
*/
public async signRawTransaction(
rawTransaction: string,
transactionDependencies: TransactionDependencies[] | null,
privateKeys: string[] | null,
sigHashType: SigHashType,
): Promise<TransactionSigned> {
return this.call<TransactionSigned>(
'signrawtransaction',
rawTransaction,
transactionDependencies as any,
privateKeys,
sigHashType,
);
}
/**
* Return information about *gridcoinaddress*.
* @description
* The validateaddress RPC accepts a block
* verifies it is a valid addition to the block chain
* and broadcasts it to the network.
*
* @param {Address} gridcoinAddress
* @returns {Promise<AddressValidation>}
* @memberof GridcoinRPC
*/
public async validateAddress(gridcoinAddress: Address): Promise<AddressValidation> {
return this.call<AddressValidation>('validateaddress', gridcoinAddress);
}
/**
* Return information about *gridcoinpubkey*.
*
* @param {PublicKey} gridcoinPubkey
* @returns {Promise<IAddress>}
* @memberof GridcoinRPC
*/
public async validatePubkey(gridcoinPubkey: PublicKey): Promise<PubKeyValidation> {
return this.call<PubKeyValidation>('validatepubkey', gridcoinPubkey);
}
/**
* Verify a signed message.
* @description
* The P2PKH address corresponding to the private key which made the signature.
* A P2PKH address is a hash of the public key corresponding to the private key which made the signature.
* When the ECDSA signature is checked, up to four possible ECDSA public keys will be reconstructed from the signature;
* each key will be hashed and compared against the P2PKH address provided to see if any of them match.
* If there are no matches, signature validation will fail.
*
* @param {Address} gridcoinAddress - The gridcoin address to use for the signature.
* @param {string} signature - The signature provided by the signer in base 64 encoding.
* @param {string} message - The message that was signed.
* @returns {Promise<boolean>}
* @memberof GridcoinRPC
* @see signmessage
*/
public async verifyMessage(gridcoinAddress: Address, signature: string, message: string): Promise<boolean> {
return this.call('verifymessage', gridcoinAddress, signature, message);
}
/**
* Removes the wallet encryption key from memory, locking the wallet.
* After calling this method, you will need to call @see walletPassPhrase again
* before being able to call any methods which require the wallet to be unlocked.
*
* @returns {Promise<null>}
* @memberof Wallet
*/
public async walletLock(): Promise<null> {
return this.call('walletlock');
}
/**
* Stores the wallet decryption key in memory for *timeout* seconds.
* if *stakingonly* is true sending functions are disabled.
*
* @param {string} passphrase
* @param {number} timeout
* @param {boolean} isStakingOnly
* @returns {Promise<null>}
* @memberof Wallet
*/
public async walletPassPhrase(passphrase: string, timeout: number, isStakingOnly: boolean): Promise<null> {
return this.call('walletpassphrase', passphrase, timeout, isStakingOnly);
}
/**
* Changes the wallet passphrase from *oldpassphrase* to *newpassphrase*
*
* @param {string} oldPassphrase
* @param {string} newPassphrase
* @returns {Promise<null>}
* @memberof Wallet
*/
public async walletPassPhraseChange(oldPassphrase: string, newPassphrase: string): Promise<null> {
return this.call('walletpassphrasechange', oldPassphrase, newPassphrase);
}
}