@@ -523,22 +523,36 @@ public long getPreviousBalance(AtMachineState state) {
523523
524524 @ Override
525525 public void sendToAddressInB (long val , AtMachineState state ) {
526- if (val < 1 )
526+ if (val < 1 ) {
527+ logger .debug ("sendToAddressInB aborted: val {} < 1" , val );
527528 return ;
529+ }
530+
531+ logger .debug (
532+ "sendToAddressInB start - val: {}, version: {}" ,
533+ val ,
534+ state .getVersion ()
535+ );
528536
529537 if (state .getVersion () > 2 ) {
530538 long assetId = AtApiHelper .getLong (state .getB2 ());
539+ logger .debug ("sendToAddressInB asset path - assetId: {}" , assetId );
531540 if (assetId != 0L ) {
532541 long assetBalance = state .getgBalance (assetId );
542+ logger .debug ("asset balance: {}" , assetBalance );
533543 if (val > assetBalance ) {
544+ logger .debug ("adjusting val from {} to asset balance {}" , val , assetBalance );
534545 val = assetBalance ;
535546 }
536547
537548 // optional coin amount besides the asset
538549 long amount = AtApiHelper .getLong (state .getB3 ());
550+ logger .debug ("coin amount in B3 before adjustment: {}" , amount );
539551 if (amount > 0L ) {
540552 long balance = state .getgBalance ();
553+ logger .debug ("available coin balance: {}" , balance );
541554 if (amount > balance ) {
555+ logger .debug ("adjusting coin amount from {} to balance {}" , amount , balance );
542556 amount = balance ;
543557 }
544558 state .setgBalance (balance - amount );
@@ -548,35 +562,72 @@ public void sendToAddressInB(long val, AtMachineState state) {
548562
549563 AtTransaction tx = new AtTransaction (TransactionType .ColoredCoins .ASSET_TRANSFER ,
550564 state .getId (), state .getB1 ().clone (), amount , assetId , val , null );
565+ logger .debug (
566+ "asset transfer tx created - sender: {}, assetId: {}, amount: {}, quantity: {}" ,
567+ AtApiHelper .getLong (state .getId ()),
568+ assetId ,
569+ amount ,
570+ val
571+ );
551572 state .addTransaction (tx );
552573
553574 state .setgBalance (assetId , assetBalance - val );
575+ logger .debug (
576+ "sendToAddressInB asset path end - new asset gBalance: {}" ,
577+ state .getgBalance (assetId )
578+ );
554579 return ;
555580 }
556581 }
557582
558583 if (val > state .getgBalance ()) {
584+ logger .debug (
585+ "adjusting val from {} to current gBalance {}" ,
586+ val ,
587+ state .getgBalance ()
588+ );
559589 val = state .getgBalance ();
560590 }
561591 AtTransaction tx = new AtTransaction (TransactionType .Payment .ORDINARY , state .getId (), state .getB1 ().clone (), val , null );
592+ logger .debug (
593+ "ordinary payment tx created - sender: {}, amount: {}" ,
594+ AtApiHelper .getLong (state .getId ()),
595+ val
596+ );
562597 state .addTransaction (tx );
563598
564599 state .setgBalance (state .getgBalance () - val );
600+ logger .debug ("sendToAddressInB end - new gBalance: {}" , state .getgBalance ());
565601 }
566602
567603 @ Override
568604 public void mintAsset (AtMachineState state ) {
569605 if (state .getVersion () < 3 ) {
606+ logger .debug ("mintAsset aborted: AT version {} < 3" , state .getVersion ());
570607 return ;
571608 }
572609
573610 long assetId = AtApiHelper .getLong (state .getB2 ());
574611 long accountId = AtApiHelper .getLong (state .getId ());
575612 long quantity = AtApiHelper .getLong (state .getB1 ());
576613
614+ logger .debug (
615+ "mintAsset input - assetId: {}, accountId: {}, quantity: {}, current gBalance: {}" ,
616+ assetId ,
617+ accountId ,
618+ quantity ,
619+ state .getgBalance (assetId )
620+ );
621+
577622 Asset asset = Signum .getStores ().getAssetStore ().getAsset (assetId );
578623 if (asset == null || asset .getAccountId () != accountId || quantity <= 0L ) {
579624 // only assets that we have created internally and no burning by mint
625+ logger .debug (
626+ "mintAsset aborted: asset null={}, account check={}, quantity={} <= 0" ,
627+ asset == null ,
628+ asset != null && asset .getAccountId () != accountId ,
629+ quantity
630+ );
580631 return ;
581632 }
582633
@@ -585,11 +636,28 @@ public void mintAsset(AtMachineState state) {
585636 long newSupply = circulatingSupply + quantity ;
586637 if (newSupply > Constants .MAX_ASSET_QUANTITY_QNT ) {
587638 // do not mint extra to keep the limit
639+ logger .debug (
640+ "mintAsset aborted: newSupply {} > MAX_ASSET_QUANTITY_QNT {}" ,
641+ newSupply ,
642+ Constants .MAX_ASSET_QUANTITY_QNT
643+ );
588644 return ;
589645 }
590646
647+ logger .debug (
648+ "mintAsset creating transaction - version: {}, newSupply: {}" ,
649+ state .getVersion (),
650+ newSupply
651+ );
652+
591653 AtTransaction tx = new AtTransaction (TransactionType .ColoredCoins .ASSET_MINT ,
592654 state .getId (), null , 0L , assetId , quantity , null );
655+ logger .debug (
656+ "mintAsset tx created - sender: {}, assetId: {}, quantity: {}" ,
657+ AtApiHelper .getLong (state .getId ()),
658+ assetId ,
659+ quantity
660+ );
593661 state .addTransaction (tx );
594662
595663 state .setgBalance (assetId , state .getgBalance (assetId ) + quantity );
0 commit comments