diff --git a/cell/src/main/java/org/ton/java/tlb/types/ActionPhase.java b/cell/src/main/java/org/ton/java/tlb/types/ActionPhase.java index 239a53db..e9b62558 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/ActionPhase.java +++ b/cell/src/main/java/org/ton/java/tlb/types/ActionPhase.java @@ -1,13 +1,12 @@ package org.ton.java.tlb.types; +import java.math.BigInteger; import lombok.Builder; import lombok.Data; import org.ton.java.cell.Cell; import org.ton.java.cell.CellBuilder; import org.ton.java.cell.CellSlice; -import java.math.BigInteger; - /** *
* tr_phase_action$_ @@ -75,8 +74,8 @@ public static ActionPhase deserialize(CellSlice cs) { .valid(cs.loadBit()) .noFunds(cs.loadBit()) .statusChange(AccStatusChange.deserialize(cs)) - .totalFwdFees(cs.loadBit() ? cs.loadCoins() : null) - .totalActionFees(cs.loadBit() ? cs.loadCoins() : null) + .totalFwdFees(cs.loadBit() ? cs.loadCoins() : BigInteger.ZERO) + .totalActionFees(cs.loadBit() ? cs.loadCoins() : BigInteger.ZERO) .resultCode(cs.loadUint(32).longValue()) .resultArg(cs.loadBit() ? cs.loadUint(32).longValue() : 0) .totalActions(cs.loadUint(16).longValue()) diff --git a/cell/src/main/java/org/ton/java/tlb/types/CommonMsg.java b/cell/src/main/java/org/ton/java/tlb/types/CommonMsg.java deleted file mode 100644 index 7b2b8523..00000000 --- a/cell/src/main/java/org/ton/java/tlb/types/CommonMsg.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.ton.java.tlb.types; - - -public class CommonMsg { - -} diff --git a/cell/src/main/java/org/ton/java/tlb/types/Transaction.java b/cell/src/main/java/org/ton/java/tlb/types/Transaction.java index 412238a7..a44aef96 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/Transaction.java +++ b/cell/src/main/java/org/ton/java/tlb/types/Transaction.java @@ -1,5 +1,6 @@ package org.ton.java.tlb.types; +import static java.util.Objects.isNull; import static java.util.Objects.nonNull; import java.math.BigInteger; @@ -9,6 +10,7 @@ import org.ton.java.cell.CellBuilder; import org.ton.java.cell.CellSlice; import org.ton.java.cell.TonHashMapE; +import org.ton.java.utils.Utils; /** * @@ -179,4 +181,190 @@ public static AccountStates deserializeAccountState(byte state) { } return null; } + + public TransactionFees getTransactionFees() { + Transaction tx = this; + + BigInteger totalFees = tx.getTotalFees().getCoins(); + BigInteger totalForwardFees = getForwardFees(tx.getDescription()); + BigInteger computeFees = getComputeFees(tx.getDescription()); + + BigInteger inForwardFees = BigInteger.ZERO; + BigInteger valueIn = BigInteger.ZERO; + BigInteger valueOut = BigInteger.ZERO; + BigInteger op = null; + long exitCode = getExitCode(tx.getDescription()); + long actionCode = getActionCode(tx.getDescription()); + long totalActions = getTotalActions(tx.getDescription()); + + Message inMsg = tx.getInOut().getIn(); + Cell body = inMsg.getBody(); + + if (nonNull(body) && body.getBits().getUsedBits() >= 32) { + op = CellSlice.beginParse(body).preloadInt(32); + } else { + op = BigInteger.ONE.negate(); + } + + if (inMsg.getInfo() instanceof InternalMessageInfo) { + valueIn = ((InternalMessageInfo) inMsg.getInfo()).getValue().getCoins(); + inForwardFees = ((InternalMessageInfo) inMsg.getInfo()).getFwdFee(); + } + + for (Message outMsg : tx.getInOut().getOutMessages()) { + InternalMessageInfo intMsgInfo = (InternalMessageInfo) outMsg.getInfo(); + valueOut = valueOut.add(intMsgInfo.getValue().getCoins()); + } + + return TransactionFees.builder() + .op( + (isNull(op)) + ? "N/A" + : (op.compareTo(BigInteger.ONE.negate()) != 0) ? op.toString(16) : "no body") + .valueIn(valueIn) + .valueOut(valueOut) + .totalFees(totalFees) + .outForwardFee(totalForwardFees) + .computeFee(computeFees) + .inForwardFee(inForwardFees) + .exitCode(exitCode) + .actionCode(actionCode) + .totalActions(totalActions) + .build(); + } + + private BigInteger getComputeFees(TransactionDescription txDesc) { + if (txDesc instanceof TransactionDescriptionOrdinary) { + ComputePhase computePhase = ((TransactionDescriptionOrdinary) txDesc).getComputePhase(); + if (computePhase instanceof ComputePhaseVM) { + return ((ComputePhaseVM) computePhase).getGasFees(); + } + } else if (txDesc instanceof TransactionDescriptionSplitPrepare) { + ComputePhase computePhase = ((TransactionDescriptionSplitPrepare) txDesc).getComputePhase(); + if (computePhase instanceof ComputePhaseVM) { + return ((ComputePhaseVM) computePhase).getGasFees(); + } + } else if (txDesc instanceof TransactionDescriptionTickTock) { + ComputePhase computePhase = ((TransactionDescriptionTickTock) txDesc).getComputePhase(); + if (computePhase instanceof ComputePhaseVM) { + return ((ComputePhaseVM) computePhase).getGasFees(); + } + } else if (txDesc instanceof TransactionDescriptionMergeInstall) { + ComputePhase computePhase = ((TransactionDescriptionMergeInstall) txDesc).getComputePhase(); + if (computePhase instanceof ComputePhaseVM) { + return ((ComputePhaseVM) computePhase).getGasFees(); + } + } else { + return BigInteger.ZERO; + } + return BigInteger.ZERO; + } + + private BigInteger getForwardFees(TransactionDescription txDesc) { + if (txDesc instanceof TransactionDescriptionOrdinary) { + ActionPhase actionPhase = ((TransactionDescriptionOrdinary) txDesc).getActionPhase(); + return actionPhase.getTotalFwdFees(); + } else if (txDesc instanceof TransactionDescriptionSplitPrepare) { + ActionPhase actionPhase = ((TransactionDescriptionSplitPrepare) txDesc).getActionPhase(); + return actionPhase.getTotalFwdFees(); + } else if (txDesc instanceof TransactionDescriptionTickTock) { + ActionPhase actionPhase = ((TransactionDescriptionTickTock) txDesc).getActionPhase(); + return actionPhase.getTotalFwdFees(); + } else if (txDesc instanceof TransactionDescriptionMergeInstall) { + ActionPhase actionPhase = ((TransactionDescriptionMergeInstall) txDesc).getActionPhase(); + return actionPhase.getTotalFwdFees(); + } else { + return BigInteger.ZERO; + } + } + + private long getTotalActions(TransactionDescription txDesc) { + if (txDesc instanceof TransactionDescriptionOrdinary) { + ActionPhase actionPhase = ((TransactionDescriptionOrdinary) txDesc).getActionPhase(); + return actionPhase.getTotalActions(); + } else if (txDesc instanceof TransactionDescriptionSplitPrepare) { + ActionPhase actionPhase = ((TransactionDescriptionSplitPrepare) txDesc).getActionPhase(); + return actionPhase.getTotalActions(); + } else if (txDesc instanceof TransactionDescriptionTickTock) { + ActionPhase actionPhase = ((TransactionDescriptionTickTock) txDesc).getActionPhase(); + return actionPhase.getTotalActions(); + } else if (txDesc instanceof TransactionDescriptionMergeInstall) { + ActionPhase actionPhase = ((TransactionDescriptionMergeInstall) txDesc).getActionPhase(); + return actionPhase.getTotalActions(); + } else { + return -1; + } + } + + private long getActionCode(TransactionDescription txDesc) { + if (txDesc instanceof TransactionDescriptionOrdinary) { + ActionPhase actionPhase = ((TransactionDescriptionOrdinary) txDesc).getActionPhase(); + return actionPhase.getResultCode(); + } else if (txDesc instanceof TransactionDescriptionSplitPrepare) { + ActionPhase actionPhase = ((TransactionDescriptionSplitPrepare) txDesc).getActionPhase(); + return actionPhase.getResultCode(); + } else if (txDesc instanceof TransactionDescriptionTickTock) { + ActionPhase actionPhase = ((TransactionDescriptionTickTock) txDesc).getActionPhase(); + return actionPhase.getResultCode(); + } else if (txDesc instanceof TransactionDescriptionMergeInstall) { + ActionPhase actionPhase = ((TransactionDescriptionMergeInstall) txDesc).getActionPhase(); + return actionPhase.getResultCode(); + } else { + return -1; + } + } + + private long getExitCode(TransactionDescription txDesc) { + if (txDesc instanceof TransactionDescriptionOrdinary) { + ComputePhase computePhase = ((TransactionDescriptionOrdinary) txDesc).getComputePhase(); + if (computePhase instanceof ComputePhaseVM) { + return ((ComputePhaseVM) computePhase).getDetails().getExitCode(); + } + } else if (txDesc instanceof TransactionDescriptionSplitPrepare) { + ComputePhase computePhase = ((TransactionDescriptionSplitPrepare) txDesc).getComputePhase(); + if (computePhase instanceof ComputePhaseVM) { + return ((ComputePhaseVM) computePhase).getDetails().getExitCode(); + } + } else if (txDesc instanceof TransactionDescriptionTickTock) { + ComputePhase computePhase = ((TransactionDescriptionTickTock) txDesc).getComputePhase(); + if (computePhase instanceof ComputePhaseVM) { + return ((ComputePhaseVM) computePhase).getDetails().getExitCode(); + } + } else if (txDesc instanceof TransactionDescriptionMergeInstall) { + ComputePhase computePhase = ((TransactionDescriptionMergeInstall) txDesc).getComputePhase(); + if (computePhase instanceof ComputePhaseVM) { + return ((ComputePhaseVM) computePhase).getDetails().getExitCode(); + } + } else { + return -1; + } + return -1; + } + + public void printTransactionFees(boolean withHeader) { + TransactionFees txFees = getTransactionFees(); + String header = + "| op | valueIn | valueOut | totalFees | inForwardFee | outForwardFee | outActions | computeFee | exitCode | actionCode |"; + if (withHeader) { + System.out.println( + "_________________________________________________________________________________________________________________________________________________"); + System.out.println(header); + System.out.println( + "-------------------------------------------------------------------------------------------------------------------------------------------------"); + } + String str = + String.format( + "| %-9s| %-15s| %-15s| %-13s| %-13s| %-14s| %-11s| %-14s| %-9s| %-11s|", + txFees.getOp(), + Utils.formatNanoValue(txFees.getValueIn()), + Utils.formatNanoValue(txFees.getValueOut()), + Utils.formatNanoValue(txFees.getTotalFees()), + Utils.formatNanoValue(txFees.getInForwardFee().toString()), + Utils.formatNanoValue(txFees.getOutForwardFee()), + txFees.getTotalActions(), + Utils.formatNanoValue(txFees.getComputeFee()), + txFees.getExitCode(), + txFees.getActionCode()); + System.out.println(str); + } } diff --git a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescription.java b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescription.java index bdd8f8cc..01cd1c31 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescription.java +++ b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescription.java @@ -1,64 +1,105 @@ package org.ton.java.tlb.types; -import lombok.Builder; -import lombok.Data; import org.ton.java.cell.Cell; -import org.ton.java.cell.CellBuilder; import org.ton.java.cell.CellSlice; -@Builder -@Data -public class TransactionDescription { - Object description; // `tlb:"."` +/** + * + * + *+ * trans_ord$0000 credit_first:Bool + * storage_ph:(Maybe TrStoragePhase) + * credit_ph:(Maybe TrCreditPhase) + * compute_ph:TrComputePhase action:(Maybe ^TrActionPhase) + * aborted:Bool bounce:(Maybe TrBouncePhase) + * destroyed:Bool + * = TransactionDescr; + * + * trans_storage$0001 storage_ph:TrStoragePhase + * = TransactionDescr; + * + * trans_tick_tock$001 is_tock:Bool storage_ph:TrStoragePhase + * compute_ph:TrComputePhase action:(Maybe ^TrActionPhase) + * aborted:Bool destroyed:Bool = TransactionDescr; + * // + * split_merge_info$_ cur_shard_pfx_len:(## 6) + * acc_split_depth:(## 6) this_addr:bits256 sibling_addr:bits256 + * = SplitMergeInfo; + * trans_split_prepare$0100 split_info:SplitMergeInfo + * storage_ph:(Maybe TrStoragePhase) + * compute_ph:TrComputePhase action:(Maybe ^TrActionPhase) + * aborted:Bool destroyed:Bool + * = TransactionDescr; + * trans_split_install$0101 split_info:SplitMergeInfo + * prepare_transaction:^Transaction + * installed:Bool = TransactionDescr; + * + * trans_merge_prepare$0110 split_info:SplitMergeInfo + * storage_ph:TrStoragePhase aborted:Bool + * = TransactionDescr; + * + * trans_merge_install$0111 split_info:SplitMergeInfo + * prepare_transaction:^Transaction + * storage_ph:(Maybe TrStoragePhase) + * credit_ph:(Maybe TrCreditPhase) + * compute_ph:TrComputePhase action:(Maybe ^TrActionPhase) + * aborted:Bool destroyed:Bool + * = TransactionDescr; + *+ */ +public interface TransactionDescription { - public Cell toCell() { - CellBuilder c = CellBuilder.beginCell(); + Cell toCell(); - if (description instanceof TransactionDescriptionStorage) { - c.storeUint(0b0001, 3); - c.storeSlice(CellSlice.beginParse(((TransactionDescriptionStorage) description).toCell())); - } else if (description instanceof TransactionDescriptionOrdinary) { - c.storeUint(0b000, 3); - c.storeSlice(CellSlice.beginParse(((TransactionDescriptionOrdinary) description).toCell())); - } - return c.endCell(); - } + // { + // CellBuilder c = CellBuilder.beginCell(); + // + // if (description instanceof TransactionDescriptionStorage) { + // c.storeUint(0b0001, 3); + // c.storeSlice(CellSlice.beginParse(((TransactionDescriptionStorage) + // description).toCell())); + // } else if (description instanceof TransactionDescriptionOrdinary) { + // c.storeUint(0b000, 3); + // c.storeSlice(CellSlice.beginParse(((TransactionDescriptionOrdinary) + // description).toCell())); + // } + // return c.endCell(); + // } - public static TransactionDescription deserialize(CellSlice cs) { - int pfx = cs.preloadUint(3).intValue(); - switch (pfx) { - case 0b000: { - boolean isStorage = cs.preloadBit(); - if (isStorage) { - TransactionDescriptionStorage desc = TransactionDescriptionStorage.deserialize(cs); - return TransactionDescription.builder().description(desc).build(); - } - TransactionDescriptionOrdinary descOrdinary = TransactionDescriptionOrdinary.deserialize(cs); // skipped was true - return TransactionDescription.builder().description(descOrdinary).build(); - } - case 0b001: { - TransactionDescriptionTickTock descTickTock = TransactionDescriptionTickTock.deserialize(cs); // skipped was true - return TransactionDescription.builder().description(descTickTock).build(); - } - case 0b010: { - boolean isInstall = cs.preloadBit(); - if (isInstall) { - TransactionDescriptionSplitInstall descSplit = TransactionDescriptionSplitInstall.deserialize(cs); // skipped was true - return TransactionDescription.builder().description(descSplit).build(); - } - TransactionDescriptionSplitPrepare descSplitPrepare = TransactionDescriptionSplitPrepare.deserialize(cs); // skipped was true - return TransactionDescription.builder().description(descSplitPrepare).build(); - } - case 0b011: { - boolean isInstall = cs.preloadBit(); - if (isInstall) { - TransactionDescriptionMergeInstall descMerge = TransactionDescriptionMergeInstall.deserialize(cs); // skipped was true - return TransactionDescription.builder().description(descMerge).build(); - } - TransactionDescriptionMergePrepare descMergePrepare = TransactionDescriptionMergePrepare.deserialize(cs); // skipped was true - return TransactionDescription.builder().description(descMergePrepare).build(); - } + static TransactionDescription deserialize(CellSlice cs) { + int pfx = cs.preloadUint(3).intValue(); + switch (pfx) { + case 0b000: + { + boolean isStorage = cs.preloadBit(); + if (isStorage) { + return TransactionDescriptionStorage.deserialize(cs); + } + return TransactionDescriptionOrdinary.deserialize(cs); + } + case 0b001: + { + return TransactionDescriptionTickTock.deserialize(cs); + } + case 0b010: + { + boolean isInstall = cs.preloadBit(); + if (isInstall) { + return TransactionDescriptionSplitInstall.deserialize(cs); + } + return TransactionDescriptionSplitPrepare.deserialize(cs); + } + case 0b011: + { + boolean isInstall = cs.preloadBit(); + if (isInstall) { + return TransactionDescriptionMergeInstall.deserialize(cs); + } + return TransactionDescriptionMergePrepare.deserialize(cs); } - throw new Error("unknown transaction description type (must be in range [0..3], found 0x" + Integer.toBinaryString(pfx)); } + throw new Error( + "unknown transaction description type (must be in range [0..3], found 0x" + + Integer.toBinaryString(pfx)); + } } diff --git a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionMergeInstall.java b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionMergeInstall.java index 9d5464bb..83f4ed1c 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionMergeInstall.java +++ b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionMergeInstall.java @@ -7,6 +7,8 @@ import org.ton.java.cell.CellSlice; /** + * + * ** trans_merge_install$0111 * split_info:SplitMergeInfo @@ -21,49 +23,52 @@ */ @Builder @Data -public class TransactionDescriptionMergeInstall { - int magic; - SplitMergeInfo splitInfo; - Transaction prepareTransaction; - StoragePhase storagePhase; - CreditPhase creditPhase; - ComputePhase computePhase; - ActionPhase actionPhase; - boolean aborted; - boolean destroyed; +public class TransactionDescriptionMergeInstall implements TransactionDescription { + int magic; + SplitMergeInfo splitInfo; + Transaction prepareTransaction; + StoragePhase storagePhase; + CreditPhase creditPhase; + ComputePhase computePhase; + ActionPhase actionPhase; + boolean aborted; + boolean destroyed; - private String getMagic() { - return Long.toBinaryString(magic); - } + private String getMagic() { + return Long.toBinaryString(magic); + } - public Cell toCell() { - return CellBuilder.beginCell() - .storeUint(0b0111, 4) - .storeCell(splitInfo.toCell()) - .storeRef(prepareTransaction.toCell()) - .storeCellMaybe(storagePhase.toCell()) - .storeCellMaybe(creditPhase.toCell()) - .storeCell(computePhase.toCell()) - .storeRefMaybe(actionPhase.toCell()) - .storeBit(aborted) - .storeBit(destroyed) - .endCell(); - } + public Cell toCell() { + return CellBuilder.beginCell() + .storeUint(0b0111, 4) + .storeCell(splitInfo.toCell()) + .storeRef(prepareTransaction.toCell()) + .storeCellMaybe(storagePhase.toCell()) + .storeCellMaybe(creditPhase.toCell()) + .storeCell(computePhase.toCell()) + .storeRefMaybe(actionPhase.toCell()) + .storeBit(aborted) + .storeBit(destroyed) + .endCell(); + } - public static TransactionDescriptionMergeInstall deserialize(CellSlice cs) { - long magic = cs.loadUint(4).intValue(); - assert (magic == 0b0111) : "TransactionDescriptionMergeInstall: magic not equal to 0b0111, found 0x" + Long.toHexString(magic); + public static TransactionDescriptionMergeInstall deserialize(CellSlice cs) { + long magic = cs.loadUint(4).intValue(); + assert (magic == 0b0111) + : "TransactionDescriptionMergeInstall: magic not equal to 0b0111, found 0x" + + Long.toHexString(magic); - return TransactionDescriptionMergeInstall.builder() - .magic(0b0111) - .splitInfo(SplitMergeInfo.deserialize(cs)) - .prepareTransaction(Transaction.deserialize(CellSlice.beginParse(cs.loadRef()))) - .storagePhase(cs.loadBit() ? StoragePhase.deserialize(cs) : null) - .creditPhase(cs.loadBit() ? CreditPhase.deserialize(cs) : null) - .computePhase(ComputePhase.deserialize(cs)) - .actionPhase(cs.loadBit() ? ActionPhase.deserialize(CellSlice.beginParse(cs.loadRef())) : null) - .aborted(cs.loadBit()) - .destroyed(cs.loadBit()) - .build(); - } + return TransactionDescriptionMergeInstall.builder() + .magic(0b0111) + .splitInfo(SplitMergeInfo.deserialize(cs)) + .prepareTransaction(Transaction.deserialize(CellSlice.beginParse(cs.loadRef()))) + .storagePhase(cs.loadBit() ? StoragePhase.deserialize(cs) : null) + .creditPhase(cs.loadBit() ? CreditPhase.deserialize(cs) : null) + .computePhase(ComputePhase.deserialize(cs)) + .actionPhase( + cs.loadBit() ? ActionPhase.deserialize(CellSlice.beginParse(cs.loadRef())) : null) + .aborted(cs.loadBit()) + .destroyed(cs.loadBit()) + .build(); + } } diff --git a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionMergePrepare.java b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionMergePrepare.java index 386132d7..e02b049d 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionMergePrepare.java +++ b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionMergePrepare.java @@ -7,46 +7,46 @@ import org.ton.java.cell.CellSlice; /** + * + * *- * trans_split_prepare$0100 - * split_info:SplitMergeInfo - * storage_ph:(Maybe TrStoragePhase) - * compute_ph:TrComputePhase - * action:(Maybe ^TrActionPhase) - * aborted:Bool destroyed:Bool + * trans_merge_prepare$0110 split_info:SplitMergeInfo + * storage_ph:TrStoragePhase aborted:Bool * = TransactionDescr; **/ @Builder @Data -public class TransactionDescriptionMergePrepare { - int magic; - SplitMergeInfo splitInfo; - StoragePhase storagePhase; - boolean aborted; +public class TransactionDescriptionMergePrepare implements TransactionDescription { + int magic; + SplitMergeInfo splitInfo; + StoragePhase storagePhase; + boolean aborted; - private String getMagic() { - return Long.toBinaryString(magic); - } + private String getMagic() { + return Long.toBinaryString(magic); + } - public Cell toCell() { - return CellBuilder.beginCell() - .storeUint(0b0100, 4) - .storeCell(splitInfo.toCell()) - .storeCellMaybe(storagePhase.toCell()) - .storeBit(aborted) - .endCell(); - } + public Cell toCell() { + return CellBuilder.beginCell() + .storeUint(0b0100, 4) + .storeCell(splitInfo.toCell()) + .storeCellMaybe(storagePhase.toCell()) + .storeBit(aborted) + .endCell(); + } - public static TransactionDescriptionMergePrepare deserialize(CellSlice cs) { - long magic = cs.loadUint(4).intValue(); - assert (magic == 0b0110) : "TransactionDescriptionMergePrepare: magic not equal to 0b0110, found 0x" + Long.toHexString(magic); + public static TransactionDescriptionMergePrepare deserialize(CellSlice cs) { + long magic = cs.loadUint(4).intValue(); + assert (magic == 0b0110) + : "TransactionDescriptionMergePrepare: magic not equal to 0b0110, found 0x" + + Long.toHexString(magic); - return TransactionDescriptionMergePrepare.builder() - .magic(0b0110) - .splitInfo(SplitMergeInfo.deserialize(cs)) - .storagePhase(StoragePhase.deserialize(cs)) - .aborted(cs.loadBit()) - .build(); - } + return TransactionDescriptionMergePrepare.builder() + .magic(0b0110) + .splitInfo(SplitMergeInfo.deserialize(cs)) + .storagePhase(StoragePhase.deserialize(cs)) + .aborted(cs.loadBit()) + .build(); + } } diff --git a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionOrdinary.java b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionOrdinary.java index 413f826f..76b9eb1c 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionOrdinary.java +++ b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionOrdinary.java @@ -7,6 +7,8 @@ import org.ton.java.cell.CellSlice; /** + * + * ** trans_ord$0000 * credit_first:Bool @@ -22,49 +24,52 @@ */ @Builder @Data -public class TransactionDescriptionOrdinary { - int magic; - boolean creditFirst; - StoragePhase storagePhase; - CreditPhase creditPhase; - ComputePhase computePhase; - ActionPhase actionPhase; - boolean aborted; - BouncePhase bouncePhase; - boolean destroyed; +public class TransactionDescriptionOrdinary implements TransactionDescription { + int magic; + boolean creditFirst; + StoragePhase storagePhase; + CreditPhase creditPhase; + ComputePhase computePhase; + ActionPhase actionPhase; + boolean aborted; + BouncePhase bouncePhase; + boolean destroyed; - private String getMagic() { - return Long.toBinaryString(magic); - } + private String getMagic() { + return Long.toBinaryString(magic); + } - public Cell toCell() { - return CellBuilder.beginCell() - .storeUint(0b0000, 4) - .storeBit(creditFirst) - .storeCellMaybe(storagePhase.toCell()) - .storeCellMaybe(creditPhase.toCell()) - .storeCell(computePhase.toCell()) - .storeRefMaybe(actionPhase.toCell()) - .storeBit(aborted) - .storeCellMaybe(bouncePhase.toCell()) - .storeBit(destroyed) - .endCell(); - } + public Cell toCell() { + return CellBuilder.beginCell() + .storeUint(0b0000, 4) + .storeBit(creditFirst) + .storeCellMaybe(storagePhase.toCell()) + .storeCellMaybe(creditPhase.toCell()) + .storeCell(computePhase.toCell()) + .storeRefMaybe(actionPhase.toCell()) + .storeBit(aborted) + .storeCellMaybe(bouncePhase.toCell()) + .storeBit(destroyed) + .endCell(); + } - public static TransactionDescriptionOrdinary deserialize(CellSlice cs) { - long magic = cs.loadUint(4).intValue(); - assert (magic == 0b0000) : "TransactionDescriptionOrdinary: magic not equal to 0b0000, found 0x" + Long.toHexString(magic); + public static TransactionDescriptionOrdinary deserialize(CellSlice cs) { + long magic = cs.loadUint(4).intValue(); + assert (magic == 0b0000) + : "TransactionDescriptionOrdinary: magic not equal to 0b0000, found 0x" + + Long.toHexString(magic); - return TransactionDescriptionOrdinary.builder() - .magic(0b0000) - .creditFirst(cs.loadBit()) - .storagePhase(cs.loadBit() ? StoragePhase.deserialize(cs) : null) - .creditPhase(cs.loadBit() ? CreditPhase.deserialize(cs) : null) - .computePhase(ComputePhase.deserialize(cs)) - .actionPhase(cs.loadBit() ? ActionPhase.deserialize(CellSlice.beginParse(cs.loadRef())) : null) - .aborted(cs.loadBit()) - .bouncePhase(cs.loadBit() ? BouncePhase.deserialize(cs) : null) - .destroyed(cs.loadBit()) - .build(); - } + return TransactionDescriptionOrdinary.builder() + .magic(0b0000) + .creditFirst(cs.loadBit()) + .storagePhase(cs.loadBit() ? StoragePhase.deserialize(cs) : null) + .creditPhase(cs.loadBit() ? CreditPhase.deserialize(cs) : null) + .computePhase(ComputePhase.deserialize(cs)) + .actionPhase( + cs.loadBit() ? ActionPhase.deserialize(CellSlice.beginParse(cs.loadRef())) : null) + .aborted(cs.loadBit()) + .bouncePhase(cs.loadBit() ? BouncePhase.deserialize(cs) : null) + .destroyed(cs.loadBit()) + .build(); + } } diff --git a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionSplitInstall.java b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionSplitInstall.java index 1f8acebb..596f9462 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionSplitInstall.java +++ b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionSplitInstall.java @@ -7,6 +7,8 @@ import org.ton.java.cell.CellSlice; /** + * + * ** trans_split_install$0101 * split_info:SplitMergeInfo @@ -16,34 +18,36 @@ */ @Builder @Data -public class TransactionDescriptionSplitInstall { - int magic; - SplitMergeInfo splitInfo; - Transaction prepareTransaction; - boolean installed; +public class TransactionDescriptionSplitInstall implements TransactionDescription { + int magic; + SplitMergeInfo splitInfo; + Transaction prepareTransaction; + boolean installed; - private String getMagic() { - return Long.toBinaryString(magic); - } + private String getMagic() { + return Long.toBinaryString(magic); + } - public Cell toCell() { - return CellBuilder.beginCell() - .storeUint(0b0101, 4) - .storeCell(splitInfo.toCell()) - .storeRef(prepareTransaction.toCell()) - .storeBit(installed) - .endCell(); - } + public Cell toCell() { + return CellBuilder.beginCell() + .storeUint(0b0101, 4) + .storeCell(splitInfo.toCell()) + .storeRef(prepareTransaction.toCell()) + .storeBit(installed) + .endCell(); + } - public static TransactionDescriptionSplitInstall deserialize(CellSlice cs) { - long magic = cs.loadUint(4).intValue(); - assert (magic == 0b0101) : "TransactionDescriptionSplitInstall: magic not equal to 0b0101, found 0x" + Long.toHexString(magic); + public static TransactionDescriptionSplitInstall deserialize(CellSlice cs) { + long magic = cs.loadUint(4).intValue(); + assert (magic == 0b0101) + : "TransactionDescriptionSplitInstall: magic not equal to 0b0101, found 0x" + + Long.toHexString(magic); - return TransactionDescriptionSplitInstall.builder() - .magic(0b0101) - .splitInfo(SplitMergeInfo.deserialize(cs)) - .prepareTransaction(Transaction.deserialize(CellSlice.beginParse(cs.loadRef()))) - .installed(cs.loadBit()) - .build(); - } + return TransactionDescriptionSplitInstall.builder() + .magic(0b0101) + .splitInfo(SplitMergeInfo.deserialize(cs)) + .prepareTransaction(Transaction.deserialize(CellSlice.beginParse(cs.loadRef()))) + .installed(cs.loadBit()) + .build(); + } } diff --git a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionSplitPrepare.java b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionSplitPrepare.java index 7fadc26c..719892cd 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionSplitPrepare.java +++ b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionSplitPrepare.java @@ -7,6 +7,8 @@ import org.ton.java.cell.CellSlice; /** + * + * ** trans_split_prepare$0100 * split_info:SplitMergeInfo @@ -19,42 +21,45 @@ */ @Builder @Data -public class TransactionDescriptionSplitPrepare { - int magic; - SplitMergeInfo splitInfo; - StoragePhase storagePhase; - ComputePhase computePhase; - ActionPhase actionPhase; - boolean aborted; - boolean destroyed; +public class TransactionDescriptionSplitPrepare implements TransactionDescription { + int magic; + SplitMergeInfo splitInfo; + StoragePhase storagePhase; + ComputePhase computePhase; + ActionPhase actionPhase; + boolean aborted; + boolean destroyed; - private String getMagic() { - return Long.toBinaryString(magic); - } + private String getMagic() { + return Long.toBinaryString(magic); + } - public Cell toCell() { - return CellBuilder.beginCell() - .storeUint(0b0100, 4) - .storeCell(splitInfo.toCell()) - .storeCellMaybe(storagePhase.toCell()) - .storeCell(computePhase.toCell()) - .storeRefMaybe(actionPhase.toCell()) - .storeBit(aborted) - .storeBit(destroyed) - .endCell(); - } + public Cell toCell() { + return CellBuilder.beginCell() + .storeUint(0b0100, 4) + .storeCell(splitInfo.toCell()) + .storeCellMaybe(storagePhase.toCell()) + .storeCell(computePhase.toCell()) + .storeRefMaybe(actionPhase.toCell()) + .storeBit(aborted) + .storeBit(destroyed) + .endCell(); + } - public static TransactionDescriptionSplitPrepare deserialize(CellSlice cs) { - long magic = cs.loadUint(4).intValue(); - assert (magic == 0b0100) : "TransactionDescriptionSplitPrepare: magic not equal to 0b0100, found 0x" + Long.toHexString(magic); - return TransactionDescriptionSplitPrepare.builder() - .magic(0b0100) - .splitInfo(SplitMergeInfo.deserialize(cs)) - .storagePhase(cs.loadBit() ? StoragePhase.deserialize(cs) : null) - .computePhase(ComputePhase.deserialize(cs)) - .actionPhase(cs.loadBit() ? ActionPhase.deserialize(CellSlice.beginParse(cs.loadRef())) : null) - .aborted(cs.loadBit()) - .destroyed(cs.loadBit()) - .build(); - } + public static TransactionDescriptionSplitPrepare deserialize(CellSlice cs) { + long magic = cs.loadUint(4).intValue(); + assert (magic == 0b0100) + : "TransactionDescriptionSplitPrepare: magic not equal to 0b0100, found 0x" + + Long.toHexString(magic); + return TransactionDescriptionSplitPrepare.builder() + .magic(0b0100) + .splitInfo(SplitMergeInfo.deserialize(cs)) + .storagePhase(cs.loadBit() ? StoragePhase.deserialize(cs) : null) + .computePhase(ComputePhase.deserialize(cs)) + .actionPhase( + cs.loadBit() ? ActionPhase.deserialize(CellSlice.beginParse(cs.loadRef())) : null) + .aborted(cs.loadBit()) + .destroyed(cs.loadBit()) + .build(); + } } diff --git a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionStorage.java b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionStorage.java index 036c69b7..8c2b34d3 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionStorage.java +++ b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionStorage.java @@ -7,6 +7,8 @@ import org.ton.java.cell.CellSlice; /** + * + * ** trans_storage$0001 * storage_ph:TrStoragePhase @@ -15,28 +17,27 @@ */ @Builder @Data -public class TransactionDescriptionStorage { - int magic; - StoragePhase storagePhase; +public class TransactionDescriptionStorage implements TransactionDescription { + int magic; + StoragePhase storagePhase; - private String getMagic() { - return Long.toBinaryString(magic); - } + private String getMagic() { + return Long.toBinaryString(magic); + } - public Cell toCell() { - return CellBuilder.beginCell() - .storeUint(0b0001, 4) - .storeCell(storagePhase.toCell()) - .endCell(); - } + public Cell toCell() { + return CellBuilder.beginCell().storeUint(0b0001, 4).storeCell(storagePhase.toCell()).endCell(); + } - public static TransactionDescriptionStorage deserialize(CellSlice cs) { - long magic = cs.loadUint(4).intValue(); - assert (magic == 0b0001) : "TransactionDescriptionStorage: magic not equal to 0b0001, found 0x" + Long.toHexString(magic); + public static TransactionDescriptionStorage deserialize(CellSlice cs) { + long magic = cs.loadUint(4).intValue(); + assert (magic == 0b0001) + : "TransactionDescriptionStorage: magic not equal to 0b0001, found 0x" + + Long.toHexString(magic); - return TransactionDescriptionStorage.builder() - .magic(0b0001) - .storagePhase(StoragePhase.deserialize(cs)) - .build(); - } + return TransactionDescriptionStorage.builder() + .magic(0b0001) + .storagePhase(StoragePhase.deserialize(cs)) + .build(); + } } diff --git a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionTickTock.java b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionTickTock.java index 5680011d..f28358f0 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionTickTock.java +++ b/cell/src/main/java/org/ton/java/tlb/types/TransactionDescriptionTickTock.java @@ -7,6 +7,8 @@ import org.ton.java.cell.CellSlice; /** + * + * ** trans_tick_tock$001 * is_tock:Bool @@ -19,43 +21,46 @@ */ @Builder @Data -public class TransactionDescriptionTickTock { - int magic; - boolean isTock; - StoragePhase storagePhase; - ComputePhase computePhase; - ActionPhase actionPhase; - boolean aborted; - boolean destroyed; +public class TransactionDescriptionTickTock implements TransactionDescription { + int magic; + boolean isTock; + StoragePhase storagePhase; + ComputePhase computePhase; + ActionPhase actionPhase; + boolean aborted; + boolean destroyed; - private String getMagic() { - return Long.toBinaryString(magic); - } + private String getMagic() { + return Long.toBinaryString(magic); + } - public Cell toCell() { - return CellBuilder.beginCell() - .storeUint(0b001, 3) - .storeBit(isTock) - .storeCell(storagePhase.toCell()) - .storeCell(computePhase.toCell()) - .storeRefMaybe(actionPhase.toCell()) - .storeBit(aborted) - .storeBit(destroyed) - .endCell(); - } + public Cell toCell() { + return CellBuilder.beginCell() + .storeUint(0b001, 3) + .storeBit(isTock) + .storeCell(storagePhase.toCell()) + .storeCell(computePhase.toCell()) + .storeRefMaybe(actionPhase.toCell()) + .storeBit(aborted) + .storeBit(destroyed) + .endCell(); + } - public static TransactionDescriptionTickTock deserialize(CellSlice cs) { - long magic = cs.loadUint(3).intValue(); - assert (magic == 0b001) : "TransactionDescriptionTickTock: magic not equal to 0b001, found 0x" + Long.toHexString(magic); + public static TransactionDescriptionTickTock deserialize(CellSlice cs) { + long magic = cs.loadUint(3).intValue(); + assert (magic == 0b001) + : "TransactionDescriptionTickTock: magic not equal to 0b001, found 0x" + + Long.toHexString(magic); - return TransactionDescriptionTickTock.builder() - .magic(0b001) - .isTock(cs.loadBit()) - .storagePhase(StoragePhase.deserialize(cs)) - .computePhase(ComputePhase.deserialize(cs)) - .actionPhase(cs.loadBit() ? ActionPhase.deserialize(CellSlice.beginParse(cs.loadRef())) : null) - .aborted(cs.loadBit()) - .destroyed(cs.loadBit()) - .build(); - } + return TransactionDescriptionTickTock.builder() + .magic(0b001) + .isTock(cs.loadBit()) + .storagePhase(StoragePhase.deserialize(cs)) + .computePhase(ComputePhase.deserialize(cs)) + .actionPhase( + cs.loadBit() ? ActionPhase.deserialize(CellSlice.beginParse(cs.loadRef())) : null) + .aborted(cs.loadBit()) + .destroyed(cs.loadBit()) + .build(); + } } diff --git a/cell/src/main/java/org/ton/java/tlb/types/TransactionFees.java b/cell/src/main/java/org/ton/java/tlb/types/TransactionFees.java new file mode 100644 index 00000000..b4c4e40e --- /dev/null +++ b/cell/src/main/java/org/ton/java/tlb/types/TransactionFees.java @@ -0,0 +1,20 @@ +package org.ton.java.tlb.types; + +import java.math.BigInteger; +import lombok.Builder; +import lombok.Data; + +@Builder +@Data +public class TransactionFees { + String op; + BigInteger totalFees; + BigInteger computeFee; + BigInteger inForwardFee; + BigInteger outForwardFee; + BigInteger valueIn; + BigInteger valueOut; + long exitCode; + long actionCode; + long totalActions; +} diff --git a/cell/src/main/java/org/ton/java/tlb/types/TransactionIO.java b/cell/src/main/java/org/ton/java/tlb/types/TransactionIO.java index 314f26c4..0fbdc4b9 100644 --- a/cell/src/main/java/org/ton/java/tlb/types/TransactionIO.java +++ b/cell/src/main/java/org/ton/java/tlb/types/TransactionIO.java @@ -1,13 +1,17 @@ package org.ton.java.tlb.types; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import lombok.Builder; import lombok.Data; import org.ton.java.cell.Cell; import org.ton.java.cell.CellBuilder; -import org.ton.java.cell.CellSlice; import org.ton.java.cell.TonHashMapE; /** + * + * ** ^[ * in_msg:(Maybe ^(Message Any)) @@ -18,22 +22,23 @@ @Builder @Data public class TransactionIO { - Message in; - TonHashMapE out; + Message in; + TonHashMapE out; - public Cell toCell() { + public Cell toCell() { - Cell dictCell = out.serialize( - k -> CellBuilder.beginCell().storeUint((Long) k, 15).endCell().getBits(), - v -> CellBuilder.beginCell().storeRef((Cell) v).endCell() - ); - return CellBuilder.beginCell() - .storeRefMaybe(in.toCell()) - .storeDict(dictCell) - .endCell(); - } + Cell dictCell = + out.serialize( + k -> CellBuilder.beginCell().storeUint((Long) k, 15).endCell().getBits(), + v -> CellBuilder.beginCell().storeRef((Cell) v).endCell()); + return CellBuilder.beginCell().storeRefMaybe(in.toCell()).storeDict(dictCell).endCell(); + } - public static TransactionIO deserialize(CellSlice cs) { - return null; + public ListgetOutMessages() { + List msgs = new ArrayList<>(); + for (Map.Entry