99 "github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
1010 "github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore"
1111 "github.com/0chain/blobber/code/go/0chain.net/blobbercore/filestore"
12- "github.com/0chain/blobber/code/go/0chain.net/core/chain"
1312 "github.com/0chain/blobber/code/go/0chain.net/core/logging"
1413
1514 "github.com/0chain/blobber/code/go/0chain.net/core/node"
@@ -87,15 +86,15 @@ func RegisterBlobber(ctx context.Context) error {
8786
8887 b , err := config .ReloadFromChain (ctx , datastore .GetStore ().GetDB ())
8988 if err != nil || b .BaseURL != node .Self .GetURLBase () { // blobber is not registered yet, baseURL is changed
90- txnHash , err := sendSmartContractBlobberAdd (ctx )
89+ txn , err := sendSmartContractBlobberAdd (ctx )
9190 if err != nil {
9291 logging .Logger .Error ("Error when sending add request to blockchain" , zap .Any ("err" , err ))
9392 return err
9493 }
9594
96- t , err := TransactionVerify (txnHash )
95+ t , err := TransactionVerify (txn )
9796 if err != nil {
98- logging .Logger .Error ("Failed to verify blobber register transaction" , zap .Any ("err" , err ), zap .String ("txn.Hash" , txnHash ))
97+ logging .Logger .Error ("Failed to verify blobber register transaction" , zap .Any ("err" , err ), zap .String ("txn.Hash" , txn . Hash ))
9998 return err
10099 }
101100
@@ -115,14 +114,14 @@ func RegisterBlobber(ctx context.Context) error {
115114// UpdateBlobber update blobber
116115func UpdateBlobber (ctx context.Context ) error {
117116
118- txnHash , err := sendSmartContractBlobberAdd (ctx )
117+ txn , err := sendSmartContractBlobberAdd (ctx )
119118 if err != nil {
120119 return err
121120 }
122121
123- t , err := TransactionVerify (txnHash )
122+ t , err := TransactionVerify (txn )
124123 if err != nil {
125- logging .Logger .Error ("Failed to verify blobber update transaction" , zap .Any ("err" , err ), zap .String ("txn.Hash" , txnHash ))
124+ logging .Logger .Error ("Failed to verify blobber update transaction" , zap .Any ("err" , err ), zap .String ("txn.Hash" , txn . Hash ))
126125 return err
127126 }
128127
@@ -132,13 +131,13 @@ func UpdateBlobber(ctx context.Context) error {
132131}
133132
134133func RefreshPriceOnChain (ctx context.Context ) error {
135- txnHash , err := sendSmartContractBlobberAdd (ctx )
134+ txn , err := sendSmartContractBlobberAdd (ctx )
136135 if err != nil {
137136 return err
138137 }
139138
140- if t , err := TransactionVerify (txnHash ); err != nil {
141- logging .Logger .Error ("Failed to verify price refresh transaction" , zap .Any ("err" , err ), zap .String ("txn.Hash" , txnHash ))
139+ if t , err := TransactionVerify (txn ); err != nil {
140+ logging .Logger .Error ("Failed to verify price refresh transaction" , zap .Any ("err" , err ), zap .String ("txn.Hash" , txn . Hash ))
142141 } else {
143142 logging .Logger .Info ("Verified price refresh transaction" , zap .String ("txn_hash" , t .Hash ), zap .Any ("txn_output" , t .TransactionOutput ))
144143 }
@@ -147,39 +146,39 @@ func RefreshPriceOnChain(ctx context.Context) error {
147146}
148147
149148// sendSmartContractBlobberAdd Add or update blobber on blockchain
150- func sendSmartContractBlobberAdd (ctx context.Context ) (string , error ) {
149+ func sendSmartContractBlobberAdd (ctx context.Context ) (* transaction. Transaction , error ) {
151150 // initialize storage node (ie blobber)
152151 txn , err := transaction .NewTransactionEntity ()
153152 if err != nil {
154- return "" , err
153+ return nil , err
155154 }
156155
157156 sn , err := getStorageNode ()
158157 if err != nil {
159- return "" , err
158+ return nil , err
160159 }
161160
162161 err = txn .ExecuteSmartContract (transaction .STORAGE_CONTRACT_ADDRESS ,
163162 transaction .ADD_BLOBBER_SC_NAME , sn , 0 )
164163 if err != nil {
165164 logging .Logger .Error ("Failed to set blobber on the blockchain" ,
166165 zap .String ("err:" , err .Error ()))
167- return "" , err
166+ return nil , err
168167 }
169168
170- return txn . Hash , nil
169+ return txn , nil
171170}
172171
173172// UpdateBlobberOnChain updates latest changes in blobber's settings, capacity,etc.
174173func UpdateBlobberOnChain (ctx context.Context ) error {
175174
176- txnHash , err := sendSmartContractBlobberUpdate (ctx )
175+ txn , err := sendSmartContractBlobberUpdate (ctx )
177176 if err != nil {
178177 return err
179178 }
180179
181- if t , err := TransactionVerify (txnHash ); err != nil {
182- logging .Logger .Error ("Failed to verify blobber update transaction" , zap .Any ("err" , err ), zap .String ("txn.Hash" , txnHash ))
180+ if t , err := TransactionVerify (txn ); err != nil {
181+ logging .Logger .Error ("Failed to verify blobber update transaction" , zap .Any ("err" , err ), zap .String ("txn.Hash" , txn . Hash ))
183182 } else {
184183 logging .Logger .Info ("Verified blobber update transaction" , zap .String ("txn_hash" , t .Hash ), zap .Any ("txn_output" , t .TransactionOutput ))
185184 }
@@ -188,27 +187,27 @@ func UpdateBlobberOnChain(ctx context.Context) error {
188187}
189188
190189// sendSmartContractBlobberUpdate update blobber on blockchain
191- func sendSmartContractBlobberUpdate (ctx context.Context ) (string , error ) {
190+ func sendSmartContractBlobberUpdate (ctx context.Context ) (* transaction. Transaction , error ) {
192191 // initialize storage node (ie blobber)
193192 txn , err := transaction .NewTransactionEntity ()
194193 if err != nil {
195- return "" , err
194+ return nil , err
196195 }
197196
198197 sn , err := getStorageNode ()
199198 if err != nil {
200- return "" , err
199+ return nil , err
201200 }
202201
203202 err = txn .ExecuteSmartContract (transaction .STORAGE_CONTRACT_ADDRESS ,
204203 transaction .UPDATE_BLOBBER_SC_NAME , sn , 0 )
205204 if err != nil {
206205 logging .Logger .Error ("Failed to set blobber on the blockchain" ,
207206 zap .String ("err:" , err .Error ()))
208- return "" , err
207+ return txn , err
209208 }
210209
211- return txn . Hash , nil
210+ return txn , nil
212211}
213212
214213// ErrBlobberHasRemoved represents service health check error, where the
@@ -220,15 +219,15 @@ var ErrBlobberHasRemoved = errors.New("blobber has been removed")
220219// ErrBlobberNotFound it is not registered on chain
221220var ErrBlobberNotFound = errors .New ("blobber is not found" )
222221
223- func TransactionVerify (txnHash string ) (t * transaction.Transaction , err error ) {
222+ func TransactionVerify (txn * transaction. Transaction ) (t * transaction.Transaction , err error ) {
224223 for i := 0 ; i < util .MAX_RETRIES ; i ++ {
225224 time .Sleep (transaction .SLEEP_FOR_TXN_CONFIRMATION * time .Second )
226- if t , err = transaction .VerifyTransaction ( txnHash , chain . GetServerChain ()); err == nil {
225+ if t , err = transaction .VerifyTransactionWithNonce ( txn . Hash , txn . GetTransaction (). GetTransactionNonce ()); err == nil {
227226 return t , nil
228227 }
229228 }
230229
231- return nil , errors .New ("[txn]max retries exceeded with " + txnHash )
230+ return nil , errors .New ("[txn]max retries exceeded with " + txn . Hash )
232231}
233232
234233func WalletRegister () error {
@@ -244,11 +243,12 @@ func WalletRegister() error {
244243
245244// SendHealthCheck send heartbeat to blockchain
246245func SendHealthCheck () (string , error ) {
247- txnHash , err := BlobberHealthCheck ()
246+ txn , err := BlobberHealthCheck ()
248247 if err != nil {
249- return txnHash , err
248+ return "" , err
250249 }
251- _ , err = TransactionVerify (txnHash )
252250
253- return txnHash , err
251+ _ , err = TransactionVerify (txn )
252+
253+ return txn .Hash , err
254254}
0 commit comments