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

fix: 🐛 Fix getTransactionContent method #164

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 6 additions & 10 deletions lib/src/services/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,28 +236,24 @@ class ApiService with JsonRPCUtil {

/// Query the network to find a transaction from a list of addresses
Future<Map<String, String>> getTransactionContent(
Map<String, String> addresses,
List<String> addresses,
) async {
if (addresses.isEmpty) {
return {};
}

try {
final transactionChainMap = await getTransactionChain(
final transactionChainMap = await getTransaction(
addresses,
request: 'data { content }',
);

final contentMap = <String, String>{};

transactionChainMap.forEach((key, value) {
final transactionList = transactionChainMap[key];
if (transactionList != null) {
for (final element in transactionList) {
if (element.data != null && element.data!.content != null) {
contentMap[key] = element.data!.content!;
}
}
transactionChainMap.forEach((key, transaction) {
final content = transaction.data?.content;
if (content != null) {
contentMap[key] = content;
}
});

Expand Down
9 changes: 5 additions & 4 deletions test/api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ void main() {

test('getTransactionContent', () async {
final contentMap = await ApiService('https://testnet.archethic.net')
.getTransactionContent({
'0000C85F189C13846ED91FFE30B08EF3B0E009780DAEEF4581F8B3D717D99CC954C0':
'',
});
.getTransactionContent(
[
'0000C85F189C13846ED91FFE30B08EF3B0E009780DAEEF4581F8B3D717D99CC954C0',
],
);

expect(
contentMap[
Expand Down
10 changes: 5 additions & 5 deletions test/transaction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ condition inherit: [

const text = 'Hello👋';
final tx = Transaction(type: 'transfer', data: Transaction.initData())
.setContent(uint8ListToHex(Uint8List.fromList(text.codeUnits)))
.setContent(uint8ListToHex(utf8.encode(text)))
.addUCOTransfer(
'0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646',
toBigInt(0.00000001),
Expand Down Expand Up @@ -785,11 +785,11 @@ condition inherit: [
await completer.future;

final txAddress = tx.address!.address!;
final content = await apiService.getTransactionContent({
txAddress: '',
});
final content = await apiService.getTransactionContent(
[txAddress],
);

final decodedContent = String.fromCharCodes(
final decodedContent = utf8.decode(
hexToUint8List(
content[txAddress]!,
),
Expand Down