@@ -38,7 +38,7 @@ export namespace TezosNodeWriter {
3838
3939 log . debug ( `TezosNodeWriter.performPostRequest sending ${ payloadStr } \n->\n${ url } ` ) ;
4040
41- return fetch ( url , { method : 'post' , body : payloadStr , headers : { 'content-type ' : 'application/json' } } ) ;
41+ return fetch ( url , { method : 'post' , body : payloadStr , headers : { 'Content-Type ' : 'application/json' } } ) ;
4242 }
4343
4444 /**
@@ -269,9 +269,9 @@ export namespace TezosNodeWriter {
269269 } ) ;
270270
271271 return [ revealOp , ...operations ] ;
272+ } else {
273+ return operations . map ( ( o , i ) => { return { ...o , counter : `${ counter + i } ` } } ) ;
272274 }
273-
274- return operations ;
275275 }
276276
277277 /**
@@ -714,8 +714,6 @@ export namespace TezosNodeWriter {
714714 let operationResources : { gas : number , storageCost : number } [ ] = [ ] ;
715715
716716 for ( let i = 0 ; i < operations . length ; i ++ ) { // Estimate each operation.
717- const operation = operations [ i ] ;
718-
719717 // Estimate resources used in the set of prior transactions.
720718 // If there were no prior transactions, set resource usage to 0.
721719 let priorConsumedResources = { gas : 0 , storageCost : 0 } ;
@@ -726,7 +724,7 @@ export namespace TezosNodeWriter {
726724
727725 // Estimate resources for everything up to the current transaction. Newer transactions may depend on previous transactions, thus all transactions must be estimated.
728726 const currentTransactions = operations . slice ( 0 , i + 1 ) ;
729- const currentConsumedResources = await TezosNodeWriter . estimateOperation ( server , chainid , ...currentTransactions ) ;
727+ const currentConsumedResources = await estimateOperation ( server , chainid , ...currentTransactions ) ;
730728
731729 // Find the actual transaction cost by calculating the delta between the two transactions resource usages.
732730 const gasLimitDelta = currentConsumedResources . gas - priorConsumedResources . gas ;
@@ -772,7 +770,8 @@ export namespace TezosNodeWriter {
772770 chainid : string ,
773771 ...operations : TezosP2PMessageTypes . Operation [ ]
774772 ) : Promise < { gas : number , storageCost : number , estimatedFee : number , estimatedStorageBurn : number } > {
775- const localOperations = [ ...operations ] . map ( o => { return { gas_limit : TezosConstants . OperationGasCap . toString ( ) , storage_limit : TezosConstants . OperationStorageCap . toString ( ) , ...o } } ) ;
773+ const naiveOperationGasCap = Math . min ( Math . floor ( TezosConstants . BlockGasCap / operations . length ) , TezosConstants . OperationGasCap ) . toString ( ) ;
774+ const localOperations = [ ...operations ] . map ( o => { return { ...o , gas_limit : naiveOperationGasCap , storage_limit : TezosConstants . OperationStorageCap . toString ( ) } } ) ;
776775
777776 const responseJSON = await dryRunOperation ( server , chainid , ...localOperations ) ;
778777
@@ -866,6 +865,21 @@ export namespace TezosNodeWriter {
866865 return operationGroup ;
867866 }
868867
868+ export async function prepareOperationGroup ( server : string , keyStore : KeyStore , counter : number , operations : TezosP2PMessageTypes . StackableOperation [ ] , optimizeFee : boolean = false ) {
869+ const operationGroup = await appendRevealOperation ( server , keyStore . publicKey , keyStore . publicKeyHash , counter , operations ) ;
870+
871+ if ( optimizeFee ) {
872+ const estimate = await estimateOperationGroup ( server , 'main' , operationGroup ) ;
873+ operationGroup [ 0 ] . fee = estimate . estimatedFee . toString ( ) ;
874+ for ( let i = 0 ; i < operationGroup . length ; i ++ ) {
875+ operationGroup [ i ] . gas_limit = estimate . operationResources [ i ] . gas . toString ( ) ;
876+ operationGroup [ i ] . storage_limit = estimate . operationResources [ i ] . storageCost . toString ( ) ;
877+ }
878+ }
879+
880+ return operationGroup ;
881+ }
882+
869883 /**
870884 * This function checks if the server response contains an error. There are multiple formats for errors coming
871885 * back from the server, this method attempts to normalized them for downstream parsing.
0 commit comments