neodix42 / ton4j

Java libraries for interacting with TON blockchain.
GNU General Public License v3.0
78 stars 27 forks source link

Cannot invoke "org.ton.java.tonlib.types.LastTransactionId.getLt()" #13

Closed SaitgalinKhannan closed 5 months ago

SaitgalinKhannan commented 5 months ago

java.lang.NullPointerException: Cannot invoke "org.ton.java.tonlib.types.LastTransactionId.getLt()" because the return value of "org.ton.java.tonlib.types.FullAccountState.getLast_transaction_id()" is null at org.ton.java.tonlib.Tonlib.getRawTransactions(Tonlib.java:510)

This code gives an error:

val tonlib: Tonlib = Tonlib.builder().build() val address: Address = Address.of("EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr") val rawTransactions = tonlib.getRawTransactions(address.toString(false), null, null)

Is this a bug or is it supposed to be like this? This does not always happen. If you call the function a second time, everything works fine.

neodix42 commented 5 months ago

Hi, I cannot reproduce your issue. This code works fine:

    @Test
    public void testIssue13() {
        Tonlib tonlib = Tonlib.builder().build();
        Address address = Address.of("EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr");
        RawTransactions txs = tonlib.getRawTransactions(address.toString(false), null, null);
        for (RawTransaction tx : txs.getTransactions()) {
            if (nonNull(tx.getIn_msg()) && (!tx.getIn_msg().getSource().getAccount_address().equals(""))) {
                log.info("{}, {} <<<<< {} : {} ", Utils.toUTC(tx.getUtime()), tx.getIn_msg().getSource().getAccount_address(), tx.getIn_msg().getDestination().getAccount_address(), Utils.formatNanoValue(tx.getIn_msg().getValue()));
            }
            if (nonNull(tx.getOut_msgs())) {
                for (RawMessage msg : tx.getOut_msgs()) {
                    log.info("{}, {} >>>>> {} : {} ", Utils.toUTC(tx.getUtime()), msg.getSource().getAccount_address(), msg.getDestination().getAccount_address(), Utils.formatNanoValue(msg.getValue()));
                }
            }
        }
    }

output:

 2024-06-04 19:29:13, EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO <<<<< EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr : 0.100000000 
 2024-06-04 17:24:04, EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO <<<<< EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr : 0.050000000 
 2024-06-04 17:21:17, EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO <<<<< EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr : 0.010000000 
 2024-06-04 17:21:17, EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr >>>>> EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO : 0.022085200 
 2024-06-04 17:21:17, EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr >>>>> EQBAjOtY-bKifsd1Yrq311qy35lzTjMJ4wYxPUUtE-MkdYA_ : 0.112078800 
 2024-06-04 17:20:43, EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO <<<<< EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr : 0.100000000 
 2024-06-04 17:19:55, EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO <<<<< EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr : 0.010000000 
 2024-06-04 17:19:55, EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr >>>>> EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO : 0.007230400 
 2024-06-04 17:18:13, EQBAjOtY-bKifsd1Yrq311qy35lzTjMJ4wYxPUUtE-MkdYA_ <<<<< EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr : 0.100000000 
 2024-06-04 16:23:40, EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO <<<<< EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr : 0.050000000 
 2024-06-04 16:23:40, EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr >>>>> EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO : 0.126866585 
 2024-06-04 16:16:47, EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO <<<<< EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr : 0.050000000 
 2024-06-04 16:16:47, EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr >>>>> EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO : 0.070770800 
 2024-06-04 16:16:47, EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr >>>>> EQAEBELEbfrTtfyaT1ny28DCdQzSu34-mLv7gY-1czOlZJhO : 0.070777200 
 2024-06-04 16:16:47, EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr >>>>> EQAkpkgqM5V6B6TEF_H2nnuWwEFwQq3Pd0ObkphwMjEchbba : 0.120764400 
 2024-06-04 16:16:47, EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr >>>>> EQBMFI3FIEwqotFL8kLHsxBtfyB4C3ogWglPbxDMaZFlxZCl : 0.070777200 
 2024-06-04 16:12:34, EQBMFI3FIEwqotFL8kLHsxBtfyB4C3ogWglPbxDMaZFlxZCl <<<<< EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr : 0.100000000 
 2024-06-04 16:10:37, EQAkpkgqM5V6B6TEF_H2nnuWwEFwQq3Pd0ObkphwMjEchbba <<<<< EQA870ez59EjeBmDNWBaQhvUTeGRKeJYJbJ_quKgCT__UjWr : 0.100000000 
neodix42 commented 5 months ago

which version of ton4j are you using? I have tested with the latest one.

SaitgalinKhannan commented 5 months ago

which version of ton4j are you using? I have tested with the latest one.

latest tonlibjson and 0.4.3 ton4j

During synchronization, an error occurs, the message "Synchronized: 90.91%" appears and after a few seconds the error "java.lang.NullPointerException" is displayed. But this happens rarely (this happens one time out of ten) and only if the request is made immediately after the program is turned on.

Synchronized: 90.91% java.lang.NullPointerException: Cannot invoke "org.ton.java.tonlib.types.LastTransactionId.getLt()" because the return value of "org.ton.java.tonlib.types.FullAccountState.getLast_transaction_id()" is null at org.ton.java.tonlib.Tonlib.getRawTransactions(Tonlib.java:510) at com.khannan.ton.Ton$tonlibTransactions$2.invokeSuspend(Ton.kt:35) at com.khannan.ton.Ton$tonlibTransactions$2.invoke(Ton.kt) at com.khannan.ton.Ton$tonlibTransactions$2.invoke(Ton.kt)

neodix42 commented 5 months ago

Yes, this happens to me as well. The reason for that is that Lite Server cannot response in time, one needs just to handle this case.