@@ -178,9 +178,8 @@ public static function checkAssetTransferring($asset)
178178 public static function processTreansferred ()
179179 {
180180 $ offers = OfferService::getTransferredOffers ();
181- _log ("Processing treansferred offers count= " .count ($ offers ));
181+ _log ("Processing transferred offers count= " .count ($ offers ));
182182 foreach ($ offers as $ offer ) {
183- _log ("Processing treansferred offer # {$ offer ['id ' ]}" );
184183 $ base_transfer_tx_id = null ;
185184 $ quote_transfer_tx_id = null ;
186185 $ market = OfferService::getMarket ($ offer ['market_id ' ]);
@@ -189,32 +188,36 @@ public static function processTreansferred()
189188 $ amount = $ offer ['base_amount ' ];
190189 $ toAddress = $ offer ['base_receive_address ' ];
191190 $ base_transfer_tx_id = $ baseService ->createPayment ($ amount , $ toAddress , $ offer );
191+ $ symbol = $ market ['base ' ];
192192 if (!$ base_transfer_tx_id ) {
193- _log ("Failed to create PHPCoin Payment " );
193+ _log ("$ symbol Offer # { $ offer [ ' id ' ]} - Failed to create $ symbol Payment " );
194194 } else {
195195 $ res = OfferService::setBaseTransferTxId ($ base_transfer_tx_id , $ offer ['id ' ], $ market ['base_asset_id ' ]);
196196 if (!$ res ) {
197- _log ("Failed to set base_transfer_tx_id " );
197+ _log ("$ symbol Offer # { $ offer [ ' id ' ]} - Failed to set base_transfer_tx_id " );
198198 }
199+ _log ("$ symbol Offer # {$ offer ['id ' ]} - Created $ symbol payment txid= $ base_transfer_tx_id " );
199200 }
200201 }
201202 if (empty ($ offer ['quote_transfer_tx_id ' ])) {
202203 $ quoteService = OfferService::getService ($ market ['quote_service ' ]);
203204 $ amount = $ offer ['base_amount ' ] * $ offer ['base_price ' ];
204205 $ toAddress = $ offer ['quote_receive_address ' ];
205206 $ quote_transfer_tx_id = $ quoteService ->createPayment ($ amount , $ toAddress , $ offer );
207+ $ symbol = $ market ['quote ' ];
206208 if (!$ quote_transfer_tx_id ) {
207- _log ("Failed to create Coin Payment " );
209+ _log ("$ symbol Offer # { $ offer [ ' id ' ]} - Failed to create $ symbol Payment " );
208210 } else {
209211 $ res = OfferService::setQuoteTransferTxId ($ quote_transfer_tx_id , $ offer ['id ' ], $ market ['quote_asset_id ' ]);
210212 if (!$ res ) {
211- _log ("Failed to set quote_transfer_tx_id " );
213+ _log ("$ symbol Offer # { $ offer [ ' id ' ]} - Failed to set quote_transfer_tx_id " );
212214 }
215+ _log ("$ symbol Offer # {$ offer ['id ' ]} - Created $ symbol payment txid= $ quote_transfer_tx_id " );
213216 }
214217 }
215218 $ res = OfferService::setOfferPaying ($ offer ['id ' ]);
216219 if (!$ res ) {
217- _log ("Failed to set offer paying " );
220+ _log ("Offer # { $ offer [ ' id ' ]} - Failed to set offer paying " );
218221 }
219222 }
220223 }
@@ -225,42 +228,52 @@ public static function processPayingOffers()
225228 _log ("Processing paying offers count= " .count ($ offers ));
226229 foreach ($ offers as $ offer ) {
227230 $ market = OfferService::getMarket ($ offer ['market_id ' ]);
231+ $ base_completed = false ;
228232 if (empty ($ offer ['base_transfer_tx_id ' ])) {
229- _log ("No base_transfer_tx_id " );
230- continue ;
231- }
232- $ baseService = OfferService::getService ($ market ['base_service ' ]);
233- $ tx = $ baseService ->findTransaction ($ offer ['base_transfer_tx_id ' ]);
234- if (!$ tx ) {
235- _log ("Not found php payment tx id " );
236- continue ;
237- }
238- $ block_height = $ baseService ->getLastHeight ();
239- $ confirmations = $ block_height - $ tx ['height ' ];
240- $ requiredConfirmations =$ baseService ->getConfirmations ('paying ' );
241- if ($ confirmations <= $ requiredConfirmations ) {
242- _log ("Offer # " .$ offer ['id ' ]." base= " .$ market ['base ' ]." tx= " .$ offer ['base_transfer_tx_id ' ]." Waiting confirmations $ confirmations / " .$ requiredConfirmations );
243- continue ;
233+ _log ("Offer # {$ offer ['id ' ]} - No base_transfer_tx_id " );
234+ } else {
235+ $ baseService = OfferService::getService ($ market ['base_service ' ]);
236+ $ tx = $ baseService ->findTransaction ($ offer ['base_transfer_tx_id ' ]);
237+ if (!$ tx ) {
238+ _log ("Offer # {$ offer ['id ' ]} Not found php payment tx id " );
239+ } else {
240+ $ block_height = $ baseService ->getLastHeight ();
241+ $ confirmations = $ block_height - $ tx ['height ' ];
242+ $ requiredConfirmations =$ baseService ->getConfirmations ('paying ' );
243+ if ($ confirmations <= $ requiredConfirmations ) {
244+ _log ("Offer # " .$ offer ['id ' ]." base= " .$ market ['base ' ]." tx= " .$ offer ['base_transfer_tx_id ' ]." Waiting confirmations $ confirmations / " .$ requiredConfirmations );
245+ } else {
246+ _log ("Offer # " .$ offer ['id ' ]." base= " .$ market ['base ' ]." tx= " .$ offer ['base_transfer_tx_id ' ]." - completed " );
247+ $ base_completed = true ;
248+ }
249+ }
250+
244251 }
252+
253+ $ quote_completed = false ;
245254 if (empty ($ offer ['quote_transfer_tx_id ' ])) {
246- _log ("No quote_transfer_tx_id " );
247- continue ;
248- }
249- $ quoteService = OfferService::getService ($ market ['quote_service ' ]);
250- $ tx = $ quoteService ->findTransaction ($ offer ['quote_transfer_tx_id ' ]);
251- if (!$ tx ) {
252- _log ('Not found coin payment tx id ' );
253- continue ;
255+ _log ("Offer # {$ offer ['id ' ]} - No quote_transfer_tx_id " );
256+ } else {
257+ $ quoteService = OfferService::getService ($ market ['quote_service ' ]);
258+ $ tx = $ quoteService ->findTransaction ($ offer ['quote_transfer_tx_id ' ]);
259+ if (!$ tx ) {
260+ _log ("Offer # {$ offer ['id ' ]} - Not found coin payment tx id " );
261+ } else {
262+ $ block_height = $ quoteService ->getLastHeight ();
263+ $ confirmations = $ block_height - $ tx ['height ' ];
264+ $ requiredConfirmations =$ baseService ->getConfirmations ('paying ' );
265+ if ($ confirmations <= $ requiredConfirmations ) {
266+ _log ("Offer # " .$ offer ['id ' ]." quote= " .$ market ['quote ' ]." tx= " .$ offer ['quote_transfer_tx_id ' ]." Waiting confirmations $ confirmations / " .$ requiredConfirmations );
267+ } else {
268+ _log ("Offer # " .$ offer ['id ' ]." quote= " .$ market ['quote ' ]." tx= " .$ offer ['quote_transfer_tx_id ' ]." - completed " );
269+ $ quote_completed = true ;
270+ }
271+ }
254272 }
255- $ block_height = $ quoteService ->getLastHeight ();
256- $ confirmations = $ block_height - $ tx ['height ' ];
257- $ requiredConfirmations =$ baseService ->getConfirmations ('paying ' );
258- if ($ confirmations <= $ requiredConfirmations ) {
259- _log ("Offer # " .$ offer ['id ' ]." base= " .$ market ['quote ' ]." tx= " .$ offer ['quote_transfer_tx_id ' ]." Waiting confirmations $ confirmations / " .$ requiredConfirmations );
260- continue ;
273+ if ($ base_completed && $ quote_completed ) {
274+ _log ("Offer # " .$ offer ['id ' ]." payments completed - closed " );
275+ OfferService::setOfferClosed ($ offer );
261276 }
262- _log ("Offer # " .$ offer ['id ' ]." payments completed - closed " );
263- OfferService::setOfferClosed ($ offer );
264277 }
265278 }
266279
@@ -327,4 +340,36 @@ public static function returnDeposit(string $symbol, string $deposit_tx_id)
327340 $ hash = $ service ->createPayment ($ amount , $ dst , null );
328341 _log ("$ symbol Return deposit tx $ deposit_tx_id - created transaction $ hash " );
329342 }
343+
344+ public static function checkDepositingOffers ()
345+ {
346+ $ offers = OfferService::getDepositingOffers ();
347+ _log ("Found " .count ($ offers )." depositing offers " );
348+ foreach ($ offers as $ offer ) {
349+ $ deposit_tx_id = $ offer ['deposit_tx_id ' ];
350+ $ market = OfferService::getMarket ($ offer ['market_id ' ]);
351+ if ($ offer ['type ' ]==OfferService::TYPE_SELL ) {
352+ $ symbol = $ market ['base ' ];
353+ $ service = OfferService::getService ($ market ['base_service ' ]);
354+ } else {
355+ $ symbol = $ market ['quote ' ];
356+ $ service = OfferService::getService ($ market ['quote_service ' ]);
357+ }
358+ $ depositTx = $ service ->findTransaction ($ deposit_tx_id );
359+ if (!$ depositTx ) {
360+ _log ("$ symbol Offer # {$ offer ['id ' ]} Not found deposit tx $ deposit_tx_id " );
361+ continue ;
362+ }
363+ $ block_height = $ service ->getLastHeight ();
364+ $ last_height = $ depositTx ['height ' ];
365+ $ confirmations = $ block_height - $ last_height ;
366+ $ requiredConfirmations =$ service ->getConfirmations ('wait ' );
367+ if ($ confirmations <= $ requiredConfirmations ) {
368+ _log ($ symbol . " Offer # {$ offer ['id ' ]} deposit {$ deposit_tx_id } waiting confirmations $ confirmations/ " .$ requiredConfirmations );
369+ return ;
370+ }
371+ OfferService::setOfferOpen ($ offer ['id ' ]);
372+ _log ($ symbol . " Offer # {$ offer ['id ' ]} Deposit # {$ deposit_tx_id } - set status opened " );
373+ }
374+ }
330375}
0 commit comments