@@ -34,13 +34,14 @@ function getFinalOptions(options) {
3434 from : Issuer ,
3535 gasPrice : defaultGasPrice ,
3636 value : undefined ,
37- factor : 1.2
37+ factor : 1.2 ,
38+ minNonce : 0
3839 }
3940 return Object . assign ( defaultOptions , options )
4041} ;
4142
4243async function getGasLimit ( options , action ) {
43- let block = await web3 . eth . getBlock ( " latest" ) ;
44+ let block = await web3 . eth . getBlock ( ' latest' ) ;
4445 let networkGasLimit = block . gasLimit ;
4546 let gas = Math . round ( options . factor * ( await action . estimateGas ( { from : options . from . address , value : options . value } ) ) ) ;
4647 return ( gas > networkGasLimit ) ? networkGasLimit : gas ;
@@ -98,101 +99,21 @@ module.exports = {
9899 %%%.
99100` ) ;
100101 } ,
101- << < << << HEAD
102+ getNonce : async function ( from ) {
103+ return ( await web3 . eth . getTransactionCount ( from . address , "pending" ) ) ;
104+ } ,
102105 sendTransaction : async function ( action , options ) {
103106 await checkPermissions ( action ) ;
104107
105108 options = getFinalOptions ( options ) ;
106109 let gasLimit = await getGasLimit ( options , action ) ;
107- = === ===
108- getNonce: async function ( from ) {
109- return ( await web3 . eth . getTransactionCount ( from . address , "pending" ) ) ;
110- } ,
111- sendTransaction : async function ( from , action , gasPrice , value , factor ) {
112- let contractRegistry = await connect ( action . _parent . options . jsonInterface , action . _parent . _address ) ;
113-
114- //NOTE this is a condition to verify if the transaction comes from a module or not.
115- if ( contractRegistry . methods . hasOwnProperty ( 'factory' ) ) {
116- let moduleAddress = await contractRegistry . methods . factory ( ) . call ( ) ;
117- let moduleRegistry = await connect ( abis . moduleFactory ( ) , moduleAddress )
118- let parentModule = await moduleRegistry . methods . getName ( ) . call ( ) ;
119- let result = await checkPermission ( web3 . utils . hexToUtf8 ( parentModule ) , action . _method . name , contractRegistry ) ;
120- if ( ! result ) {
121- console . log ( "You haven't the right permissions to execute this method." ) ;
122- process . exit ( 0 ) ;
123- }
124- }
125-
126- if ( typeof factor === 'undefined' ) factor = 1.2 ;
127-
128- let block = await web3 . eth . getBlock ( "latest" ) ;
129- let networkGasLimit = block . gasLimit ;
130- let gas = Math . round ( factor * ( await action . estimateGas ( { from : from . address , value : value } ) ) ) ;
131- if ( gas > networkGasLimit ) gas = networkGasLimit ;
132-
133- console . log ( chalk . black . bgYellowBright ( `---- Transaction executed: ${ action . _method . name } - Gas limit provided: ${ gas } ----` ) ) ;
134-
135- let nonce = await web3 . eth . getTransactionCount ( from . address ) ;
136- let abi = action . encodeABI ( ) ;
137- let parameter = {
138- from : from . address ,
139- to : action . _parent . _address ,
140- data : abi ,
141- gasLimit : gas ,
142- gasPrice : gasPrice ,
143- nonce : nonce ,
144- value : web3 . utils . toHex ( value )
145- } ;
146-
147- const transaction = new Tx ( parameter ) ;
148- transaction . sign ( Buffer . from ( from . privateKey . replace ( '0x' , '' ) , 'hex' ) ) ;
149- return await web3 . eth . sendSignedTransaction ( '0x' + transaction . serialize ( ) . toString ( 'hex' ) )
150- . on ( 'transactionHash' , function ( hash ) {
151- console . log ( `
152- Your transaction is being processed. Please wait...
153- TxHash: ${ hash } `
154- ) ;
155- } )
156- . on ( 'receipt' , function ( receipt ) {
157- console . log ( `
158- Congratulations! The transaction was successfully completed.
159- Gas used: ${ receipt . gasUsed } - Gas spent: ${ web3 . utils . fromWei ( ( new web3 . utils . BN ( gasPrice ) ) . mul ( new web3 . utils . BN ( receipt . gasUsed ) ) ) } Ether
160- Review it on Etherscan.
161- TxHash: ${ receipt . transactionHash } \n`
162- ) ;
163- } ) ;
164- } ,
165- sendTransactionWithNonce : async function ( from , action , gasPrice , minNonce , value , factor ) {
166- let contractRegistry = await connect ( action . _parent . options . jsonInterface , action . _parent . _address ) ;
167-
168- //NOTE this is a condition to verify if the transaction comes from a module or not.
169- if ( contractRegistry . methods . hasOwnProperty ( 'factory' ) ) {
170- let moduleAddress = await contractRegistry . methods . factory ( ) . call ( ) ;
171- let moduleRegistry = await connect ( abis . moduleFactory ( ) , moduleAddress )
172- let parentModule = await moduleRegistry . methods . getName ( ) . call ( ) ;
173- let result = await checkPermission ( web3 . utils . hexToUtf8 ( parentModule ) , action . _method . name , contractRegistry ) ;
174- if ( ! result ) {
175- console . log ( "You haven't the right permissions to execute this method." ) ;
176- process . exit ( 0 ) ;
177- }
178- }
179- if ( typeof factor === 'undefined' ) factor = 1.2 ;
180-
181- let block = await web3 . eth . getBlock ( "latest" ) ;
182- let networkGasLimit = block . gasLimit ;
183- > >>> >>> master - dev - 2.1
184110
185111 console . log ( chalk . black . bgYellowBright ( `---- Transaction executed: ${ action . _method . name } - Gas limit provided: ${ gasLimit } ----` ) ) ;
186112
187- < << << << HEAD
188113 let nonce = await web3 . eth . getTransactionCount ( options . from . address ) ;
189- = === ===
190- let nonce = await web3 . eth . getTransactionCount ( from . address ) ;
191-
192- if ( nonce < minNonce ) {
114+ if ( nonce < options . minNonce ) {
193115 nonce = minNonce ;
194116 }
195- > >>> >>> master - dev - 2.1
196117 let abi = action . encodeABI ( ) ;
197118 let parameter = {
198119 from : options . from . address ,
0 commit comments