Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify TronTransaction raw transaction handling and remov… #126

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:

generate-docs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
permissions:
contents: write # Required for pushing to gh-pages
pages: write # Required for deploying to Pages
Expand Down
3 changes: 1 addition & 2 deletions lib/src/crypto/tron/entities/tron_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ base class TronTransaction extends EVMTransaction {
);

final rawData = raw_data_hex.hexToBytes;
final tron.Transaction_raw rawTx =
tron.Transaction_raw.fromBuffer(rawData);
final Transaction_raw rawTx = Transaction_raw.fromBuffer(rawData);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add a null or empty-check for rawTx.contract to prevent runtime errors.

If rawTx.contract is empty, calling rawTx.contract.first will cause an out-of-range error. Consider adding a guard clause before accessing .first.

Proposed fix:

 if (json
     case {
       "txID": String hash,
       "net_usage": int _,
       "net_fee": int netFee,
       "energy_usage": int _,
       "energy_fee": int energyFee,
       "blockNumber": int block,
       "block_timestamp": int block_timestamp,
       "raw_data_hex": String raw_data_hex,
     }) {
   final fee = Amount(
     value: BigInt.from(netFee + energyFee),
     decimals: 6,
   );

   final rawData = raw_data_hex.hexToBytes;
+  // Guard check for empty contract list
+  if (rawData.isEmpty) {
+    return null; // or handle appropriately
+  }
 
-  final Transaction_raw rawTx = Transaction_raw.fromBuffer(rawData);
+  final rawTx = Transaction_raw.fromBuffer(rawData);
+  if (rawTx.contract.isEmpty) {
+    return null; // or handle appropriately
+  }
   final contract = rawTx.contract.first;
   ...
 }

Committable suggestion skipped: line range outside the PR's diff.


final contract = rawTx.contract.first;
final contractType = contract.type;
Expand Down
2 changes: 0 additions & 2 deletions lib/src/domain/entities/generic_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import 'package:walletkit_dart/src/common/http_repository.dart';
import 'package:walletkit_dart/src/crypto/utxo/entities/payments/p2h.dart';
import 'package:walletkit_dart/src/crypto/utxo/utils/pubkey_to_address.dart';
import 'package:walletkit_dart/walletkit_dart.dart';
import 'package:walletkit_dart/src/crypto/tron/repositories/rpc/core/Tron.pb.dart'
as tron;

part '../../crypto/evm/entities/transactions/evm_transaction.dart';
part '../../crypto/utxo/entities/transactions/utxo_transaction.dart';
Expand Down
Loading