import clc from 'cli-color' ; import ArgumentsInterface from '../faces/arguments' ; import { getWallet } from '../utils/wallet' ; import CommandInterface from '../faces/command' ; import walletOption from '../options/wallet' ; import debugOption from '../options/debug' ; import helpOption from '../options/help' ; import timeoutOption from '../options/timeout' ; import useBundlerOption from '../options/useBundler' ; import { JWKInterface } from 'blockweave/dist/faces/lib/wallet' ; const command = { name : 'fund-bundler' , description : 'Fund your bundler account' , args : [ 'amount' ] , usage : [ '0.3' ] , options : [ walletOption , debugOption , helpOption , timeoutOption , useBundlerOption ] , execute : async ( args ) : Promise < void > => { const { walletPath , bundler , debug , config , blockweave , commandValues , useBundler } = args ; if ( ! commandValues || ! commandValues . length ) { console . log ( clc . red ( 'You forgot to set the amount.' ) ) ; return ; } const amount = commandValues [ 0 ] ; const wallet = await getWallet ( walletPath , config , debug ) ; if ( ! wallet ) { return ; } if ( ! useBundler ) { console . log ( clc . red ( 'Please set bundler address' ) ) ; return ; } let bundlerAddress ; try { const res = await bundler . get ( '/info' ) ; bundlerAddress = res . data . address || res . data . addresses . arweave ; } catch ( e ) { clc . red ( 'Error getting bundler address, see more info with the --debug option.' ) ; if ( debug ) console . log ( e ) ; process . exit ( 1 ) ; } try { const addy = await blockweave . wallets . jwkToAddress ( wallet ) ; const tx = await blockweave . createTransaction ( { target : bundlerAddress , quantity : blockweave . ar . arToWinston ( amount . toString ( ) ) , } , wallet ) ; tx . reward = parseInt ( tx . reward , 10 ) . toString ( ) ; await blockweave . transactions . sign ( tx , wallet ) ; await blockweave . transactions . post ( tx ) ; console . log ( clc . cyan ( `Bundler funded with ${ amount . toString ( ) } AR, transaction ID: ${ tx . id }` ) ) ; } catch ( e ) { clc . red ( 'Error funding bundler address, see more info with the --debug option.' ) ; if ( debug ) console . log ( e ) ; } } , } ; export default command ;