@@ -42,7 +42,7 @@ function getFinalOptions(options) {
4242async function getGasLimit ( options , action ) {
4343 let block = await web3 . eth . getBlock ( "latest" ) ;
4444 let networkGasLimit = block . gasLimit ;
45- let gas = Math . round ( options . factor * ( await action . estimateGas ( { from : options . from . address , value : options . value } ) ) ) ;
45+ let gas = Math . round ( options . factor * ( await action . estimateGas ( { from : options . from . address , value : options . value } ) ) ) ;
4646 return ( gas > networkGasLimit ) ? networkGasLimit : gas ;
4747}
4848
@@ -65,16 +65,16 @@ async function checkPermissions(action) {
6565module . exports = {
6666 convertToDaysRemaining : function ( timeRemaining ) {
6767 var seconds = parseInt ( timeRemaining , 10 ) ;
68-
68+
6969 var days = Math . floor ( seconds / ( 3600 * 24 ) ) ;
70- seconds -= days * 3600 * 24 ;
71- var hrs = Math . floor ( seconds / 3600 ) ;
72- seconds -= hrs * 3600 ;
70+ seconds -= days * 3600 * 24 ;
71+ var hrs = Math . floor ( seconds / 3600 ) ;
72+ seconds -= hrs * 3600 ;
7373 var mnts = Math . floor ( seconds / 60 ) ;
74- seconds -= mnts * 60 ;
74+ seconds -= mnts * 60 ;
7575 return ( days + " days, " + hrs + " Hrs, " + mnts + " Minutes, " + seconds + " Seconds" ) ;
7676 } ,
77- logAsciiBull : function ( ) {
77+ logAsciiBull : function ( ) {
7878 console . log ( `
7979 /######%%, /#(
8080 ##########%%%%%, ,%%%. %
@@ -103,8 +103,8 @@ module.exports = {
103103
104104 options = getFinalOptions ( options ) ;
105105 let gasLimit = await getGasLimit ( options , action ) ;
106-
107- console . log ( chalk . black . bgYellowBright ( `---- Transaction executed: ${ action . _method . name } - Gas limit provided: ${ gasLimit } ----` ) ) ;
106+
107+ console . log ( chalk . black . bgYellowBright ( `---- Transaction executed: ${ action . _method . name } - Gas limit provided: ${ gasLimit } ----` ) ) ;
108108
109109 let nonce = await web3 . eth . getTransactionCount ( options . from . address ) ;
110110 let abi = action . encodeABI ( ) ;
@@ -117,24 +117,24 @@ module.exports = {
117117 nonce : nonce ,
118118 value : web3 . utils . toHex ( options . value )
119119 } ;
120-
120+
121121 const transaction = new Tx ( parameter ) ;
122122 transaction . sign ( Buffer . from ( options . from . privateKey . replace ( '0x' , '' ) , 'hex' ) ) ;
123123 return await web3 . eth . sendSignedTransaction ( '0x' + transaction . serialize ( ) . toString ( 'hex' ) )
124- . on ( 'transactionHash' , function ( hash ) {
125- console . log ( `
124+ . on ( 'transactionHash' , function ( hash ) {
125+ console . log ( `
126126 Your transaction is being processed. Please wait...
127127 TxHash: ${ hash } `
128- ) ;
129- } )
130- . on ( 'receipt' , function ( receipt ) {
131- console . log ( `
128+ ) ;
129+ } )
130+ . on ( 'receipt' , function ( receipt ) {
131+ console . log ( `
132132 Congratulations! The transaction was successfully completed.
133133 Gas used: ${ receipt . gasUsed } - Gas spent: ${ web3 . utils . fromWei ( ( new web3 . utils . BN ( options . gasPrice ) ) . mul ( new web3 . utils . BN ( receipt . gasUsed ) ) ) } Ether
134134 Review it on Etherscan.
135135 TxHash: ${ receipt . transactionHash } \n`
136- ) ;
137- } ) ;
136+ ) ;
137+ } ) ;
138138 } ,
139139 getEventFromLogs : function ( jsonInterface , logs , eventName ) {
140140 let eventJsonInterface = jsonInterface . find ( o => o . name === eventName && o . type === 'event' ) ;
@@ -145,5 +145,22 @@ module.exports = {
145145 let eventJsonInterface = jsonInterface . find ( o => o . name === eventName && o . type === 'event' ) ;
146146 let filteredLogs = logs . filter ( l => l . topics . includes ( eventJsonInterface . signature ) ) ;
147147 return filteredLogs . map ( l => web3 . eth . abi . decodeLog ( eventJsonInterface . inputs , l . data , l . topics . slice ( 1 ) ) ) ;
148+ } ,
149+ splitIntoBatches : function ( data , batchSize ) {
150+ let allBatches = [ ] ;
151+ for ( let index = 0 ; index < data . length ; index += batchSize ) {
152+ allBatches . push ( data . slice ( index , index + batchSize ) ) ;
153+ }
154+ return allBatches ;
155+ } ,
156+ transposeBatches : function ( batches ) {
157+ let result = [ ] ;
158+ if ( batches . length > 0 && batches [ 0 ] . length > 0 ) {
159+ let columns = batches [ 0 ] [ 0 ] . length ;
160+ for ( let index = 0 ; index < columns ; index ++ ) {
161+ result [ index ] = batches . map ( batch => batch . map ( record => record [ index ] ) ) ;
162+ }
163+ }
164+ return result ;
148165 }
149166} ;
0 commit comments