@@ -2626,16 +2626,22 @@ class Wallet extends EventEmitter {
2626
2626
* Make a transfer MTX.
2627
2627
* @param {String } name
2628
2628
* @param {Address } address
2629
+ * @param {String|Number } acct
2629
2630
* @returns {MTX }
2630
2631
*/
2631
2632
2632
- async makeTransfer ( name , address ) {
2633
+ async makeTransfer ( name , address , acct ) {
2633
2634
assert ( typeof name === 'string' ) ;
2634
2635
assert ( address instanceof Address ) ;
2635
2636
2636
2637
if ( ! rules . verifyName ( name ) )
2637
2638
throw new Error ( 'Invalid name.' ) ;
2638
2639
2640
+ if ( acct != null ) {
2641
+ assert ( ( acct >>> 0 ) === acct || typeof acct === 'string' ) ;
2642
+ acct = await this . getAccountIndex ( acct ) ;
2643
+ }
2644
+
2639
2645
const rawName = Buffer . from ( name , 'ascii' ) ;
2640
2646
const nameHash = rules . hashName ( rawName ) ;
2641
2647
const ns = await this . getNameState ( nameHash ) ;
@@ -2658,6 +2664,9 @@ class Wallet extends EventEmitter {
2658
2664
if ( coin . height < ns . height )
2659
2665
throw new Error ( `Wallet does not own: "${ name } ".` ) ;
2660
2666
2667
+ if ( acct != null && ! await this . txdb . hasCoinByAccount ( acct , hash , index ) )
2668
+ throw new Error ( `Account does not own: "${ name } ".` ) ;
2669
+
2661
2670
const state = ns . state ( height , network ) ;
2662
2671
2663
2672
if ( state !== states . CLOSED )
@@ -2696,7 +2705,8 @@ class Wallet extends EventEmitter {
2696
2705
*/
2697
2706
2698
2707
async _createTransfer ( name , address , options ) {
2699
- const mtx = await this . makeTransfer ( name , address ) ;
2708
+ const acct = options ? options . account : null ;
2709
+ const mtx = await this . makeTransfer ( name , address , acct ) ;
2700
2710
await this . fill ( mtx , options ) ;
2701
2711
return this . finalize ( mtx , options ) ;
2702
2712
}
@@ -2876,15 +2886,21 @@ class Wallet extends EventEmitter {
2876
2886
* Make a transfer-finalizing MTX.
2877
2887
* @private
2878
2888
* @param {String } name
2889
+ * @param {String|Number } acct
2879
2890
* @returns {MTX }
2880
2891
*/
2881
2892
2882
- async makeFinalize ( name ) {
2893
+ async makeFinalize ( name , acct ) {
2883
2894
assert ( typeof name === 'string' ) ;
2884
2895
2885
2896
if ( ! rules . verifyName ( name ) )
2886
2897
throw new Error ( 'Invalid name.' ) ;
2887
2898
2899
+ if ( acct != null ) {
2900
+ assert ( ( acct >>> 0 ) === acct || typeof acct === 'string' ) ;
2901
+ acct = await this . getAccountIndex ( acct ) ;
2902
+ }
2903
+
2888
2904
const rawName = Buffer . from ( name , 'ascii' ) ;
2889
2905
const nameHash = rules . hashName ( rawName ) ;
2890
2906
const ns = await this . getNameState ( nameHash ) ;
@@ -2907,6 +2923,9 @@ class Wallet extends EventEmitter {
2907
2923
if ( coin . height < ns . height )
2908
2924
throw new Error ( `Wallet does not own: "${ name } ".` ) ;
2909
2925
2926
+ if ( acct != null && ! await this . txdb . hasCoinByAccount ( acct , hash , index ) )
2927
+ throw new Error ( `Account does not own: "${ name } ".` ) ;
2928
+
2910
2929
const state = ns . state ( height , network ) ;
2911
2930
2912
2931
if ( state !== states . CLOSED )
@@ -2955,7 +2974,8 @@ class Wallet extends EventEmitter {
2955
2974
*/
2956
2975
2957
2976
async _createFinalize ( name , options ) {
2958
- const mtx = await this . makeFinalize ( name ) ;
2977
+ const acct = options ? options . account : null ;
2978
+ const mtx = await this . makeFinalize ( name , acct ) ;
2959
2979
await this . fill ( mtx , options ) ;
2960
2980
return this . finalize ( mtx , options ) ;
2961
2981
}
0 commit comments