@@ -7,6 +7,10 @@ const web3Eth = require('web3-eth');
77
88const bigNumber : any = require ( 'bn.js' ) ;
99
10+ // Confirmation to wait in order to create metadata of the new added hash
11+ // TODO(PROT-252): Find the optimal value or fix to use 1
12+ const CONFIRMATION_TO_WAIT = 2 ;
13+
1014/**
1115 * Manages the smart contract used by the storage layer
1216 * to store the hashes of the data on Ethereum
@@ -82,7 +86,7 @@ export default class SmartContractManager {
8286 // Get the accounts on the provider
8387 // Throws an error if timeout is reached
8488 const accounts = await Promise . race ( [
85- this . timeoutPromise ( this . timeout , 'Web3 provider connection timeout' ) ,
89+ this . timeoutPromise ( this . timeout , 'Web3 getAccounts connection timeout' ) ,
8690 this . eth . getAccounts ( ) ,
8791 ] ) ;
8892
@@ -110,13 +114,15 @@ export default class SmartContractManager {
110114 // Get the fee from the size of the content
111115 // Throws an error if timeout is reached
112116 const fee = await Promise . race ( [
113- this . timeoutPromise ( this . timeout , 'Web3 provider connection timeout' ) ,
117+ this . timeoutPromise ( this . timeout , 'Web3 getFeesAmount connection timeout' ) ,
114118 this . requestHashStorage . methods . getFeesAmount ( contentSize ) . call ( ) ,
115119 ] ) ;
116120
117121 const gasPriceToUse = gasPrice || config . getDefaultEthereumGasPrice ( ) ;
118122
119123 // Send transaction to contract
124+ // TODO(PROT-181): Implement a log manager for the library
125+ // use it for the different events (error, transactionHash, receipt and confirmation)
120126 return new Promise (
121127 ( resolve , reject ) : any => {
122128 this . requestHashStorage . methods
@@ -130,22 +136,9 @@ export default class SmartContractManager {
130136 . on ( 'error' , ( transactionError : string ) => {
131137 reject ( Error ( `Ethereum transaction error: ${ transactionError } ` ) ) ;
132138 } )
133- . on ( 'transactionHash' , ( transactionHash : string ) => {
134- // TODO(PROT-181): Implement a log manager for the library
135- /* tslint:disable:no-console */
136- console . log ( `transactionHash : ${ transactionHash } ` ) ;
137- } )
138- . on ( 'receipt' , ( receiptInCallback : string ) => {
139- // TODO(PROT-181): Implement a log manager for the library
140- /* tslint:disable:no-console */
141- console . log ( `receipt : ${ JSON . stringify ( receiptInCallback ) } ` ) ;
142- } )
143139 . on ( 'confirmation' , ( confirmationNumber : number , receiptAfterConfirmation : any ) => {
144- // TODO(PROT-181): Implement a log manager for the library
145- // TODO(PROT-252): return after X confirmation instead of 0
146-
147- // We have to wait at least one confirmation to get Ethereum metadata
148- if ( confirmationNumber > 0 ) {
140+ // TODO(PROT-252): search for the best number of confirmation to wait for
141+ if ( confirmationNumber >= CONFIRMATION_TO_WAIT ) {
149142 const gasFee = new bigNumber ( receiptAfterConfirmation . gasUsed ) . mul (
150143 new bigNumber ( gasPriceToUse ) ,
151144 ) ;
@@ -234,7 +227,7 @@ export default class SmartContractManager {
234227
235228 // Reading all event logs
236229 let events = await Promise . race ( [
237- this . timeoutPromise ( this . timeout , 'Web3 provider connection timeout' ) ,
230+ this . timeoutPromise ( this . timeout , 'Web3 getPastEvents connection timeout' ) ,
238231 this . requestHashStorage . getPastEvents ( {
239232 event : 'NewHash' ,
240233 fromBlock,
@@ -338,7 +331,8 @@ export default class SmartContractManager {
338331 try {
339332 blockTimestamp = await this . ethereumBlocks . getBlockTimestamp ( blockNumber ) ;
340333 } catch ( error ) {
341- throw Error ( `Error getting block timestamp: ${ error } ` ) ;
334+
335+ throw Error ( `Error getting block ${ blockNumber } timestamp: ${ error } ` ) ;
342336 }
343337
344338 return {
0 commit comments