@@ -23,6 +23,7 @@ import { promptCurrency } from '../../utils/currency'
2323import { promptExpiration } from '../../utils/expiration'
2424import { getExplorer } from '../../utils/explorer'
2525import { selectFee } from '../../utils/fees'
26+ import { sendTransactionWithLedger } from '../../utils/ledger'
2627import { watchTransaction } from '../../utils/transaction'
2728
2829export class Mint extends IronfishCommand {
@@ -96,12 +97,22 @@ This will create tokens and increase supply for a given asset.`
9697 transferOwnershipTo : Flags . string ( {
9798 description : 'The public address of the account to transfer ownership of this asset to.' ,
9899 } ) ,
100+ transferTo : Flags . string ( {
101+ description : 'transfer all newly minted coins to this public address' ,
102+ } ) ,
103+ transferToMemo : Flags . string ( {
104+ description : 'The memo of transfer when using transferTo' ,
105+ } ) ,
99106 unsignedTransaction : Flags . boolean ( {
100107 default : false ,
101108 description :
102109 'Return a serialized UnsignedTransaction. Use it to create a transaction and build proofs but not post to the network' ,
103110 exclusive : [ 'rawTransaction' ] ,
104111 } ) ,
112+ ledger : Flags . boolean ( {
113+ default : false ,
114+ description : 'Mint a transaction using a Ledger device' ,
115+ } ) ,
105116 }
106117
107118 async start ( ) : Promise < void > {
@@ -140,7 +151,7 @@ This will create tokens and increase supply for a given asset.`
140151 name = await ui . inputPrompt ( 'Enter the name for the new asset' , true )
141152 }
142153
143- if ( ! metadata ) {
154+ if ( metadata == null ) {
144155 metadata = await ui . inputPrompt ( 'Enter metadata for the new asset' )
145156 }
146157
@@ -213,6 +224,12 @@ This will create tokens and increase supply for a given asset.`
213224 }
214225 }
215226
227+ if ( flags . transferTo ) {
228+ if ( ! isValidPublicAddress ( flags . transferTo ) ) {
229+ this . error ( 'transferTo must be a valid public address' )
230+ }
231+ }
232+
216233 let expiration = flags . expiration
217234 if ( ( flags . rawTransaction || flags . unsignedTransaction ) && expiration === undefined ) {
218235 expiration = await promptExpiration ( { logger : this . logger , client : client } )
@@ -223,25 +240,34 @@ This will create tokens and increase supply for a given asset.`
223240 this . exit ( 1 )
224241 }
225242
243+ const mint = {
244+ // Only provide the asset id if we are not minting an asset for the first time
245+ ...( assetData != null ? { assetId } : { } ) ,
246+ name : name ,
247+ metadata : metadata ,
248+ value : CurrencyUtils . encode ( amount ) ,
249+ transferOwnershipTo : flags . transferOwnershipTo ,
250+ }
251+
226252 const params : CreateTransactionRequest = {
227253 account,
228254 outputs : [ ] ,
229- mints : [
230- {
231- // Only provide the asset id if we are not minting an asset for the first time
232- ...( assetData != null ? { assetId } : { } ) ,
233- name,
234- metadata,
235- value : CurrencyUtils . encode ( amount ) ,
236- transferOwnershipTo : flags . transferOwnershipTo ,
237- } ,
238- ] ,
255+ mints : [ mint ] ,
239256 fee : flags . fee ? CurrencyUtils . encode ( flags . fee ) : null ,
240257 feeRate : flags . feeRate ? CurrencyUtils . encode ( flags . feeRate ) : null ,
241258 expiration : expiration ,
242259 confirmations : flags . confirmations ,
243260 }
244261
262+ if ( flags . transferTo ) {
263+ params . outputs . push ( {
264+ publicAddress : flags . transferTo ,
265+ amount : mint . value ,
266+ assetId : assetId ,
267+ memo : flags . transferToMemo ,
268+ } )
269+ }
270+
245271 let raw : RawTransaction
246272 if ( params . fee === null && params . feeRate === null ) {
247273 raw = await selectFee ( {
@@ -282,10 +308,23 @@ This will create tokens and increase supply for a given asset.`
282308 name ,
283309 metadata ,
284310 flags . transferOwnershipTo ,
311+ flags . transferTo ,
285312 flags . confirm ,
286313 assetData ,
287314 )
288315
316+ if ( flags . ledger ) {
317+ await sendTransactionWithLedger (
318+ client ,
319+ raw ,
320+ account ,
321+ flags . watch ,
322+ flags . confirm ,
323+ this . logger ,
324+ )
325+ this . exit ( 0 )
326+ }
327+
289328 ux . action . start ( 'Sending the transaction' )
290329
291330 const response = await client . wallet . postTransaction ( {
@@ -324,6 +363,7 @@ This will create tokens and increase supply for a given asset.`
324363 Value : renderedValue ,
325364 Fee : renderedFee ,
326365 Hash : transaction . hash ( ) . toString ( 'hex' ) ,
366+ 'Transfered To' : flags . transferTo ? flags . transferTo : undefined ,
327367 } ) ,
328368 )
329369
@@ -356,6 +396,7 @@ This will create tokens and increase supply for a given asset.`
356396 name ?: string ,
357397 metadata ?: string ,
358398 transferOwnershipTo ?: string ,
399+ transferTo ?: string ,
359400 confirm ?: boolean ,
360401 assetData ?: RpcAsset ,
361402 ) : Promise < void > {
@@ -376,6 +417,17 @@ This will create tokens and increase supply for a given asset.`
376417 `Fee: ${ renderedFee } ` ,
377418 ]
378419
420+ if ( transferTo ) {
421+ confirmMessage . push (
422+ `\nAll ${ CurrencyUtils . render (
423+ amount ,
424+ false ,
425+ assetId ,
426+ assetData ?. verification ,
427+ ) } of this asset will be transferred to ${ transferTo } .`,
428+ )
429+ }
430+
379431 if ( transferOwnershipTo ) {
380432 confirmMessage . push (
381433 `Ownership of this asset will be transferred to ${ transferOwnershipTo } . The current account will no longer have any permission to mint or modify this asset. This cannot be undone.` ,
0 commit comments