@@ -46,6 +46,12 @@ public function __construct(\stdClass $metadata, bool $calculateTradingFees = fa
4646 if ($ mptQuantity !== null )
4747 $ quantities [$ mptQuantity ['account ' ]][] = $ mptQuantity ;
4848 }
49+
50+ if ($ node ->LedgerEntryType == 'MPTokenIssuance ' ) {
51+ $ mptOaQuantity = $ this ->getMPTOaQuantity ($ node );
52+ if ($ mptOaQuantity !== null )
53+ $ quantities [$ mptOaQuantity ['account ' ]][] = $ mptOaQuantity ;
54+ }
4955 }
5056 # Reorganize quantities array
5157 $ final = [];
@@ -184,6 +190,66 @@ private function getMPTQuantity(\stdClass $node): ?array
184190 return $ result ;
185191 }
186192
193+ /**
194+ * Get OutstandingAmount balance change from MPTokenIssuance
195+ */
196+ private function getMPTOaQuantity (\stdClass $ node ): ?array
197+ {
198+ $ value = $ this ->computeMPTOutstandingAmountChange ($ node );
199+
200+ if ($ value === null )
201+ return null ;
202+ $ account = null ;
203+ if ($ node ->FinalFields && $ node ->FinalFields ->Issuer )
204+ $ account = $ node ->FinalFields ->Issuer ;
205+ elseif ($ node ->NewFields && $ node ->NewFields ->Issuer )
206+ $ account = $ node ->NewFields ->Issuer ;
207+ if ($ account === null )
208+ return null ;
209+ $ fields = ($ node ->NewFields === null ) ? $ node ->FinalFields : $ node ->NewFields ;
210+
211+ $ result = [
212+ 'account ' => (string )$ account ,
213+ 'balance ' => [
214+ 'mpt_issuance_id ' => Util::makeMptID ($ fields ->Sequence ,$ fields ->Issuer ),
215+ 'value ' => (string )BigDecimal::of ($ value ->toInt ())->stripTrailingZeros (), //unscaled
216+ ]
217+ ];
218+
219+ return $ result ;
220+ }
221+
222+ private function computeMPTOutstandingAmountChange (\stdClass $ node ): ?BigDecimal
223+ {
224+ $ value = null ;
225+ if ($ node ->NewFields !== null && isset ($ node ->NewFields ->OutstandingAmount )) {
226+ $ value = $ this ->getValue ($ node ->NewFields ->OutstandingAmount );
227+ } elseif ($ node ->PreviousFields !== null && isset ($ node ->PreviousFields ->OutstandingAmount ) && $ node ->FinalFields !== null && isset ($ node ->FinalFields ->OutstandingAmount )) {
228+ $ value = $ this ->getValue ($ node ->FinalFields ->OutstandingAmount )->minus ($ this ->getValue ($ node ->PreviousFields ->OutstandingAmount ));
229+ }
230+
231+ /*elseif($node->PreviousFields !== null && !isset($node->PreviousFields->OutstandingAmount) && $node->FinalFields !== null && isset($node->FinalFields->OutstandingAmount)) {
232+ $PreviousFieldsKeys = \array_keys((array)$node->PreviousFields);
233+ if(count($PreviousFieldsKeys)) {
234+ //there was some prev keys but MPTAmount was not set, something else than balance was changed
235+ $value = $this->getValue('0');
236+ } else {
237+ //there was no prev keys set
238+ //see 732EE5C1222385C34F965EF0FC7C2CD3E952AAA6A4CF2CA2F35D43C4CD40DCF6
239+ $value = $this->getValue('0');
240+ }
241+ }*/
242+
243+ if ($ value === null )
244+ return null ;
245+
246+ if ($ value ->isEqualTo (0 ))
247+ return null ;
248+ return $ value ->negated ();
249+ //return $value;
250+
251+ }
252+
187253 private function computeMPTAmountChange (\stdClass $ node ): ?BigDecimal
188254 {
189255 $ value = null ;
0 commit comments