Skip to content
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
2 changes: 1 addition & 1 deletion packages/komodo_defi_framework/app_build/build_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"coins": {
"fetch_at_build_enabled": true,
"update_commit_on_build": true,
"bundled_coins_repo_commit": "4d9b6b1da8f2e9da4dc35a4f0311c7e8c0746d53",
"bundled_coins_repo_commit": "16496a71d9473bfab1357ab0b71511c7ba106ce4",
"coins_repo_api_url": "https://api.github.com/repos/GLEECBTC/coins",
"coins_repo_content_url": "https://raw.githubusercontent.com/GLEECBTC/coins",
"coins_repo_branch": "feat/add-tron-coins",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:komodo_defi_rpc_methods/komodo_defi_rpc_methods.dart';
import 'package:komodo_defi_sdk/src/activation/protocol_strategies/custom_erc20_activation_strategy.dart';
import 'package:komodo_defi_sdk/src/activation/protocol_strategies/erc20_activation_strategy.dart';
import 'package:komodo_defi_sdk/src/activation/protocol_strategies/eth_task_activation_strategy.dart';
import 'package:komodo_defi_sdk/src/activation/protocol_strategies/eth_with_tokens_activation_strategy.dart';
import 'package:komodo_defi_rpc_methods/komodo_defi_rpc_methods.dart';
import 'package:komodo_defi_types/komodo_defi_types.dart';
import 'package:test/test.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Asset _createEvmAsset({
}

Asset _createZhtlcAsset() {
final protocol = ZhtlcProtocol.fromJson({
final protocol = ZhtlcProtocol.fromJson(const {
'type': 'ZHTLC',
'electrum_servers': [
{'url': 'lightwalletd.pirate.black', 'port': 9067, 'protocol': 'SSL'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ abstract class ProtocolClass with ExplorerUrlMixin implements Equatable {
}

bool supportsTxHistoryStreaming({required bool isChildAsset}) {
// TRON does not currently expose KDF-backed tx history.
if (subClass == CoinSubClass.trx || subClass == CoinSubClass.trc20) {
return false;
}
// EVM does not support tx history streaming in KDF
if (evmCoinSubClasses.contains(subClass)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@ class ExplorerUrlPattern {
});

factory ExplorerUrlPattern.fromJson(JsonMap config) {
final baseUrl = config.valueOrNull<String>('explorer_url');
final baseUrl = _normalizePatternValue(
config.valueOrNull<String>('explorer_url'),
);
if (baseUrl == null) return const ExplorerUrlPattern();

// Add scheme if missing
final urlString = baseUrl.startsWith('http') ? baseUrl : 'https://$baseUrl';
return ExplorerUrlPattern(
baseUrl: Uri.tryParse(urlString),
txPattern: config.valueOrNull<String>('explorer_tx_url'),
addressPattern: config.valueOrNull<String>('explorer_address_url'),
blockPattern: config.valueOrNull<String>('explorer_block_url'),
txPattern: _normalizePatternValue(
config.valueOrNull<String>('explorer_tx_url'),
),
addressPattern: _normalizePatternValue(
config.valueOrNull<String>('explorer_address_url'),
),
blockPattern: _normalizePatternValue(
config.valueOrNull<String>('explorer_block_url'),
),
);
}

Expand All @@ -45,14 +53,36 @@ class ExplorerUrlPattern {

// If no placeholders were found, append the first param value
if (params.isNotEmpty && url == pattern) {
url = '$url/${Uri.encodeComponent(params.values.first)}';
url = '$url${Uri.encodeComponent(params.values.first)}';
}

final resolvedBaseUrl = baseUrl;
if (resolvedBaseUrl == null) return null;

if (resolvedBaseUrl.fragment.isNotEmpty && !url.startsWith('#')) {
final baseFragment = resolvedBaseUrl.fragment;
final normalizedBaseFragment = baseFragment.endsWith('/')
? baseFragment
: '$baseFragment/';
final normalizedUrl = url.startsWith('/') ? url.substring(1) : url;

return resolvedBaseUrl.replace(
fragment: '$normalizedBaseFragment$normalizedUrl',
);
}

return baseUrl?.resolve(url);
return resolvedBaseUrl.resolve(url);
} catch (e) {
return null;
}
}

static String? _normalizePatternValue(String? value) {
if (value == null) return null;

final normalized = value.trim();
return normalized.isEmpty ? null : normalized;
}
}

/// Mixin to provide explorer URL functionality to Protocol classes
Expand All @@ -63,30 +93,29 @@ mixin ExplorerUrlMixin {
Uri? explorerTxUrl(String txHash) {
if (txHash.isEmpty) return null;

final hash =
needs0xPrefix && !txHash.startsWith('0x') ? '0x$txHash' : txHash;
final hash = needs0xPrefix && !txHash.startsWith('0x')
? '0x$txHash'
: txHash;

return explorerPattern.buildUrl(
explorerPattern.txPattern,
{'HASH': hash, 'TX': hash},
);
return explorerPattern.buildUrl(explorerPattern.txPattern, {
'HASH': hash,
'TX': hash,
});
}

Uri? explorerAddressUrl(String address) {
if (address.isEmpty) return null;

return explorerPattern.buildUrl(
explorerPattern.addressPattern,
{'ADDRESS': address},
);
return explorerPattern.buildUrl(explorerPattern.addressPattern, {
'ADDRESS': address,
});
}

Uri? explorerBlockUrl(String blockId) {
if (blockId.isEmpty) return null;

return explorerPattern.buildUrl(
explorerPattern.blockPattern,
{'BLOCK': blockId},
);
return explorerPattern.buildUrl(explorerPattern.blockPattern, {
'BLOCK': blockId,
});
}
}
26 changes: 24 additions & 2 deletions packages/komodo_defi_types/test/tron_protocol_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Map<String, dynamic> _trxConfig() => {
'decimals': 6,
'required_confirmations': 1,
'derivation_path': "m/44'/195'",
'explorer_url': 'https://tronscan.org/',
'explorer_tx_url': '#/transaction/',
'explorer_address_url': '#/address/',
'protocol': {
'type': 'TRX',
'protocol_data': {'network': 'Mainnet'},
Expand All @@ -27,6 +30,9 @@ Map<String, dynamic> _trc20Config() => {
'mm2': 1,
'decimals': 6,
'derivation_path': "m/44'/195'",
'explorer_url': 'https://tronscan.org/',
'explorer_tx_url': '#/transaction/',
'explorer_address_url': '#/address/',
'protocol': {
'type': 'TRC20',
'protocol_data': {
Expand Down Expand Up @@ -116,7 +122,15 @@ void main() {
expect(protocol.subClass, CoinSubClass.trx);
expect((protocol as TrxProtocol).nodes, isEmpty);
expect(protocol.network, 'Mainnet');
expect(protocol.supportsTxHistoryStreaming(isChildAsset: false), isTrue);
expect(protocol.supportsTxHistoryStreaming(isChildAsset: false), isFalse);
expect(
protocol.explorerTxUrl('abc123')?.toString(),
'https://tronscan.org/#/transaction/abc123',
);
expect(
protocol.explorerAddressUrl('TAddress123')?.toString(),
'https://tronscan.org/#/address/TAddress123',
);
});

test('Asset.fromJson links TRC20 child asset to TRX parent', () {
Expand All @@ -128,7 +142,15 @@ void main() {
expect(child.id.parentId, parent.id);
expect(parent.id.subClass.canBeParentOf(child.id.subClass), isTrue);
expect(child.supportsBalanceStreaming, isTrue);
expect(child.supportsTxHistoryStreaming, isTrue);
expect(child.supportsTxHistoryStreaming, isFalse);
expect(
child.protocol.explorerTxUrl('def456')?.toString(),
'https://tronscan.org/#/transaction/def456',
);
expect(
child.protocol.explorerAddressUrl('TTokenAddress456')?.toString(),
'https://tronscan.org/#/address/TTokenAddress456',
);
});

test('non-TRON platform assets keep top-level subtype precedence', () {
Expand Down
Loading