chore: fix type casting and safety across multiple coin packages (#3791)
What changed, and why it matters
This commit is a broad cleanup across multiple cryptocurrency wallet packages that adds explicit type casts when handling JSON and binary data. The changes mostly prevent runtime crashes caused by unexpected data types (for example, a number arriving as an integer instead of a decimal, or a string where a list was expected). In a few places, the casts also make the code safer when parsing values that could be attacker-influenced, such as Etherscan API responses or Trezor hardware-wallet transaction data. The patch is defensive and does not appear to introduce new vulnerabilities, but it is also partial: it fixes many symptoms without addressing the underlying lack of structured validation, so some edge cases may still crash or behave incorrectly.
Treat this as a defensive hardening patch. Review whether any remaining uncast dynamic values in the same call sites still reach sensitive operations, and consider adding structured deserialization (e.g., generated JSON models or validation schemas) for RPC/API responses rather than relying on ad-hoc casts. Test malformed API responses and edge-case Trezor payloads to confirm crashes are resolved. No urgent security deployment is indicated solely from this diff.
Security signals we found
Type-safety hardening across JSON-RPC and REST API response handling
Explicit casts added to hardware-wallet (Trezor) transaction credential parsing
CRC32 byte-range validation tightened in Zcash utility
Decred amount/fee decoding changed from `double` to `num` to handle Go integer-encoded float64
No new cryptographic, authorization, or network-layer changes observed
Evidence from the diff
The commit adds explicit Dart type casts across cw_decred, cw_evm, cw_solana, cw_tron, cw_zcash, cw_wownero, and cw_monero. Key patterns: (1) JSON map/list values are cast to expected primitive types before use, often with fallback defaults; (2) Go-produced float64 values in Decred are cast to num rather than double to handle whole-number serialization; (3) EVM Etherscan/Trezor paths now cast strings, BigInt inputs, and byte lists; (4) Solana/TRON/Zcash RPC and model parsing receive explicit casts; (5) Zcash CRC32 byte validation is tightened. The changes reduce TypeError crashes and make malformed API responses fail more predictably. They do not add full input schemas or sanitization, so parsing of untrusted RPC/API data remains a trust boundary with residual risk.
Changed components
cw_decred wallet, address, transaction, unspent, and libdcrwallet JSON decodingcw_evm Etherscan client, ERC20 balance, transaction model, Trezor credentialscw_solana client, balance, pending transaction, transaction info, SPL token metadatacw_tron balance, client, transaction info, TRC20 transaction modelcw_zcash Ywallet migration and CRC32 utilitycw_wownero wallet manager pointer typingcw_monero wallet cache serializationInspect captured patch +131 / −120
### cw_decred/lib/api/libdcrwallet.dart
@@ -468,7 +468,7 @@ class Libwallet {
_commands.send((id, req));
final res = await completer.future as PayloadResult;
try {
- return jsonDecode(res.payload);
+ return jsonDecode(res.payload) as Map<String, dynamic>;
} catch (_) {
if (throwOnError) {
rethrow;
### cw_decred/lib/api/util.dart
@@ -27,13 +27,13 @@ PayloadResult executePayloadFn({
if (jsonStr == null) throw DecredPayloadExecutionException("no json return from wallet library");
final decoded = json.decode(jsonStr);
- final err = decoded["error"] ?? "";
+ final err = decoded["error"] as String? ?? "";
if (!skipErrorCheck && (err as String? ?? "").isNotEmpty) {
- throw DecredPayloadExecutionException(err as String);
+ throw DecredPayloadExecutionException(err);
}
- final payload = decoded["payload"] ?? "";
- final errCode = decoded["errorcode"] ?? -1;
+ final payload = decoded["payload"] as String? ?? "";
+ final errCode = decoded["errorcode"] as int? ?? -1;
return new PayloadResult(payload, err, errCode);
}
### cw_decred/lib/wallet.dart
@@ -234,13 +234,13 @@ abstract class DecredWalletBase
final syncStatusJSON = await _libwallet.syncStatus(walletInfo.name);
final decoded = json.decode(syncStatusJSON.isEmpty ? "{}" : syncStatusJSON);
- final syncStatusCode = decoded["syncstatuscode"] ?? 0;
+ final syncStatusCode = decoded["syncstatuscode"] as int? ?? 0;
// final syncStatusStr = decoded["syncstatus"] ?? "";
- final targetHeight = decoded["targetheight"] ?? 1;
+ final targetHeight = decoded["targetheight"] as int? ?? 1;
final numPeers = decoded["numpeers"] ?? 0;
// final cFiltersHeight = decoded["cfiltersheight"] ?? 0;
- final headersHeight = decoded["headersheight"] ?? 0;
- final rescanHeight = decoded["rescanheight"] ?? 0;
+ final headersHeight = decoded["headersheight"] as int? ?? 0;
+ final rescanHeight = decoded["rescanheight"] as int? ?? 0;
if (numPeers == 0) {
syncStatus = NotConnectedSyncStatus();
@@ -421,18 +421,18 @@ abstract class DecredWalletBase
};
final res = await _libwallet.createSignedTransaction(walletInfo.name, jsonEncode(signReq));
final decoded = json.decode(res);
- final signedHex = decoded["hex"];
+ final signedHex = decoded["hex"] as String? ?? "";
final send = () async {
await _libwallet.sendRawTransaction(walletInfo.name, signedHex);
await updateBalance();
};
- final fee = decoded["fee"] ?? 0;
+ final fee = decoded["fee"] as int? ?? 0;
if (sendAll) {
totalAmt = (totalAmt - fee).round();
}
return DecredPendingTransaction(
- txId: decoded["txid"] ?? "",
+ txId: decoded["txid"] as String? ?? "",
amount: Money.fromInt(totalAmt, currency),
fee: Money.fromInt(fee, currency),
rawHex: signedHex,
@@ -497,18 +497,20 @@ abstract class DecredWalletBase
final decoded = json.decode(res);
final txs = <String, DecredTransactionInfo>{};
- for (final d in decoded) {
- final txid = uniqueTxID(d["txid"] ?? "", d["vout"] ?? 0);
+ for (final d in decoded as Iterable<dynamic>) {
+ final txid = uniqueTxID(d["txid"] as String? ?? "", d["vout"] as int? ?? 0);
var direction = TransactionDirection.outgoing;
if (d["category"] == "receive") {
direction = TransactionDirection.incoming;
}
- final amountDouble = d["amount"] ?? 0.0;
+ // amount and fee are Go float64s, and Go writes whole values without a decimal point
+ // (1, not 1.0), so they can decode as int. Cast to num, never double.
+ final amountDouble = d["amount"] as num? ?? 0.0;
final amount = (amountDouble * 1e8).round().abs();
- final feeDouble = d["fee"] ?? 0.0;
+ final feeDouble = d["fee"] as num? ?? 0.0;
final fee = (feeDouble * 1e8).round().abs();
- final confs = d["confirmations"] ?? 0;
- final sendTime = d["time"] ?? 0;
+ final confs = d["confirmations"] as int? ?? 0;
+ final sendTime = d["time"] as int? ?? 0;
txs[txid] = DecredTransactionInfo(
id: txid,
@@ -517,9 +519,9 @@ abstract class DecredWalletBase
direction: direction,
isPending: confs == 0,
date: DateTime.fromMillisecondsSinceEpoch(sendTime * 1000, isUtc: false),
- height: d["height"] ?? 0,
+ height: d["height"] as int? ?? 0,
confirmations: confs,
- to: d["address"] ?? "",
+ to: d["address"] as String? ?? "",
);
}
return txs;
@@ -603,8 +605,8 @@ abstract class DecredWalletBase
});
balance[CryptoCurrency.dcr] = DecredBalance(
- confirmed: Money.fromInt(balanceMap["confirmed"] ?? 0, currency),
- unconfirmed: Money.fromInt(balanceMap["unconfirmed"] ?? 0, currency),
+ confirmed: Money.fromInt(balanceMap["confirmed"] as int? ?? 0, currency),
+ unconfirmed: Money.fromInt(balanceMap["unconfirmed"] as int? ?? 0, currency),
frozen: Money.fromInt(totalFrozen, currency),
);
}
@@ -672,15 +674,22 @@ abstract class DecredWalletBase
final res = await _libwallet.listUnspents(walletInfo.name);
final decoded = json.decode(res);
final unspents = <Unspent>[];
- for (final d in decoded) {
- final spendable = d["spendable"] ?? false;
+ for (final d in decoded as Iterable<dynamic>) {
+ final spendable = d["spendable"] as bool? ?? false;
if (!spendable) {
continue;
}
- final amountDouble = d["amount"] ?? 0.0;
+ // A Go float64, so it can decode as int (see fetchFiveTransactions): num, not double.
+ final amountDouble = d["amount"] as num? ?? 0.0;
final amount = (amountDouble * 1e8).round().abs();
- final utxo = Unspent(d["address"] ?? "", d["txid"] ?? "", amount, d["vout"] ?? 0, null);
- utxo.isChange = d["ischange"] ?? false;
+ final utxo = Unspent(
+ d["address"] as String? ?? "",
+ d["txid"] as String? ?? "",
+ amount,
+ d["vout"] as int? ?? 0,
+ null,
+ );
+ utxo.isChange = d["ischange"] as bool? ?? false;
unspents.add(utxo);
}
_unspents = unspents;
@@ -765,7 +774,7 @@ abstract class DecredWalletBase
if (decoded["setfromheight"] == true || decoded["setfromtime"] == true) {
return -1;
}
- return decoded["height"] ?? 0;
+ return decoded["height"] as int? ?? 0;
} on FormatException catch (_) {
return 0;
}
### cw_decred/lib/wallet_addresses.dart
@@ -44,7 +44,7 @@ abstract class DecredWalletAddressesBase extends WalletAddresses with Store {
@override
Future<void> updateAddressesInBox() async {
final addrs = await _libAddresses();
- final allAddrs = List.from(addrs.usedAddrs)..addAll(addrs.unusedAddrs);
+ final allAddrs = List<String>.from(addrs.usedAddrs)..addAll(addrs.unusedAddrs);
// Add all addresses.
allAddrs.forEach((addr) {
@@ -99,10 +99,10 @@ abstract class DecredWalletAddressesBase extends WalletAddresses with Store {
try {
final res = await _libwallet.addresses(walletInfo.name, nUsed, nUnused);
final decoded = json.decode(res);
- final usedAddrs = List<String>.from(decoded["used"] ?? []);
- final unusedAddrs = List<String>.from(decoded["unused"] ?? []);
+ final usedAddrs = List<String>.from(decoded["used"] as Iterable<dynamic>? ?? []);
+ final unusedAddrs = List<String>.from(decoded["unused"] as Iterable<dynamic>? ?? []);
// index is the index of the first unused address.
- final index = decoded["index"] ?? 0;
+ final index = decoded["index"] as int? ?? 0;
return _LibAddresses(usedAddrs, unusedAddrs, index);
} catch (e) {
printV(e);
### cw_evm/lib/clients/evm_chain_client.dart
@@ -53,7 +53,7 @@ class EVMChainClient {
final jsonResponse = json.decode(response.body) as Map<String, dynamic>;
if (jsonResponse['result'] is String) {
- log(jsonResponse['result']);
+ log(jsonResponse['result'] as String);
return [];
}
@@ -66,7 +66,7 @@ class EVMChainClient {
final spamThresholdWei = BigInt.from(10000000000000);
res.removeWhere((e) {
try {
- final value = BigInt.parse(e['value'] ?? '0');
+ final value = BigInt.parse(e['value'] as String? ?? '0');
final isIncoming = e['to']?.toLowerCase() == address.toLowerCase() &&
e['from']?.toLowerCase() != address.toLowerCase();
return isIncoming && value < spamThresholdWei;
@@ -85,7 +85,7 @@ class EVMChainClient {
if (mergedMap.containsKey(key)) {
try {
final currentNet = getNetFlow(mergedMap[key]!, address);
- final newNet = getNetFlow(tx, address);
+ final newNet = getNetFlow(tx as Map<String, dynamic>, address);
final totalNet = currentNet + newNet;
mergedMap[key]!['value'] = totalNet.abs().toString();
@@ -99,7 +99,7 @@ class EVMChainClient {
printV('Error merging transaction values: $e');
}
} else {
- mergedMap[key] = Map<String, dynamic>.from(tx);
+ mergedMap[key] = Map<String, dynamic>.from(tx as Map<dynamic, dynamic>);
}
}
@@ -120,7 +120,7 @@ class EVMChainClient {
}
BigInt getNetFlow(Map<String, dynamic> txData, String address) {
- final val = BigInt.parse(txData['value'] ?? '0');
+ final val = BigInt.parse(txData['value'] as String? ?? '0');
final isIncoming = txData['to']?.toLowerCase() == address.toLowerCase();
final isOutgoing = txData['from']?.toLowerCase() == address.toLowerCase();
@@ -605,8 +605,8 @@ class EVMChainClient {
String filteredSymbol = symbol.replaceFirst(RegExp('^\\\$'), '');
final name = (decodedResponse['name'] ?? '').toString();
- final decimal = decodedResponse['decimals'] ?? '0';
- final iconPath = decodedResponse['logo'] ?? '';
+ final decimal = (decodedResponse['decimals'] ?? '0') as String;
+ final iconPath = (decodedResponse['logo'] ?? '') as String;
return Erc20Token(
name: name,
### cw_evm/lib/evm_chain_transaction_model.dart
@@ -38,21 +38,21 @@ class EVMChainTransactionModel {
factory EVMChainTransactionModel.fromJson(
Map<String, dynamic> json, String defaultSymbol, int chainId) =>
EVMChainTransactionModel(
- date: DateTime.fromMillisecondsSinceEpoch(int.parse(json["timeStamp"]) * 1000),
- hash: json["hash"] ?? "",
- from: json["from"] ?? "",
- to: json["to"] ?? "",
- amount: BigInt.parse(json["value"] ?? "0"),
- gasUsed: int.parse(json["gasUsed"] ?? "0"),
- gasPrice: BigInt.parse(json["gasPrice"] ?? "0"),
- contractAddress: json["contractAddress"] ?? "",
- confirmations: int.parse(json["confirmations"] ?? "0"),
- blockNumber: int.parse(json["blockNumber"] ?? "0"),
- tokenSymbol: json["tokenSymbol"] ?? defaultSymbol,
- tokenDecimal: int.tryParse(json["tokenDecimal"] ?? ""),
+ date: DateTime.fromMillisecondsSinceEpoch(int.parse(json["timeStamp"] as String) * 1000),
+ hash: json["hash"] as String? ?? "",
+ from: json["from"] as String? ?? "",
+ to: json["to"] as String? ?? "",
+ amount: BigInt.parse(json["value"] as String? ?? "0"),
+ gasUsed: int.parse(json["gasUsed"] as String? ?? "0"),
+ gasPrice: BigInt.parse(json["gasPrice"] as String? ?? "0"),
+ contractAddress: json["contractAddress"] as String? ?? "",
+ confirmations: int.parse(json["confirmations"] as String? ?? "0"),
+ blockNumber: int.parse(json["blockNumber"] as String? ?? "0"),
+ tokenSymbol: json["tokenSymbol"] as String? ?? defaultSymbol,
+ tokenDecimal: int.tryParse(json["tokenDecimal"] as String? ?? ""),
isError: json["isError"] == "1",
- input: json["input"] ?? "",
- evmSignatureName: json["evmSignatureName"],
+ input: json["input"] as String? ?? "",
+ evmSignatureName: json["evmSignatureName"] as String?,
chainId: chainId,
);
}
### cw_evm/lib/evm_erc20_balance.dart
@@ -15,7 +15,7 @@ class EVMChainERC20Balance extends Balance {
final decoded = json.decode(jsonSource) as Map;
try {
- return EVMChainERC20Balance(Money(BigInt.parse(decoded["balanceInWei"]), currency));
+ return EVMChainERC20Balance(Money(BigInt.parse(decoded["balanceInWei"] as String), currency));
} catch (e) {
return EVMChainERC20Balance(Money.zero(currency));
}
### cw_evm/lib/hardware/evm_chain_trezor_credentials.dart
@@ -41,14 +41,14 @@ class EvmTrezorCredentials extends CredentialsWithKnownAddress {
TrezorEthereumTransaction tx;
if (isEIP1559) {
- final chainId = data[0][0];
- final nonce = bytesToHex(data[1], include0x: true);
- final maxPriorityFeePerGas = bytesToHex(data[2], include0x: true);
- final maxFeePerGas = bytesToHex(data[3], include0x: true);
- final maxGas = bytesToHex(data[4], include0x: true);
- final to = bytesToHex(data[5], include0x: true);
- final value = bytesToHex(data[6], include0x: true);
- final txData = bytesToHex(data[7], include0x: true);
+ final chainId = data[0][0] as int;
+ final nonce = bytesToHex(data[1] as List<int>, include0x: true);
+ final maxPriorityFeePerGas = bytesToHex(data[2] as List<int>, include0x: true);
+ final maxFeePerGas = bytesToHex(data[3] as List<int>, include0x: true);
+ final maxGas = bytesToHex(data[4] as List<int>, include0x: true);
+ final to = bytesToHex(data[5] as List<int>, include0x: true);
+ final value = bytesToHex(data[6] as List<int>, include0x: true);
+ final txData = bytesToHex(data[7] as List<int>, include0x: true);
tx = TrezorEthereumTransaction(
to: to,
@@ -61,12 +61,12 @@ class EvmTrezorCredentials extends CredentialsWithKnownAddress {
data: txData,
);
} else {
- final nonce = bytesToHex(data[0]);
- final gasPrice = bytesToHex(data[1]);
- final maxGas = bytesToHex(data[2]);
- final to = bytesToHex(data[3]);
- final value = bytesToHex(data[4]);
- final txData = bytesToHex(data[5]);
+ final nonce = bytesToHex(data[0] as List<int>);
+ final gasPrice = bytesToHex(data[1] as List<int>);
+ final maxGas = bytesToHex(data[2] as List<int>);
+ final to = bytesToHex(data[3] as List<int>);
+ final value = bytesToHex(data[4] as List<int>);
+ final txData = bytesToHex(data[5] as List<int>);
tx = TrezorEthereumTransaction(
to: to,
value: value,
### cw_monero/lib/api/wallet.dart
@@ -473,7 +473,7 @@ Map<String, dynamic> getWalletCacheDebug() {
monero.MONERO_Wallet_serializeCacheToJson(Pointer.fromAddress(currentWallet!.ffiAddress()));
final blob = json.decode(jsonString);
blob['cake:unspent'] = getAllUnspent();
- return blob;
+ return blob as Map<String, dynamic>;
} catch (e) {
return {
"error": e.toString(),
### cw_solana/lib/pending_solana_transaction.dart
@@ -30,7 +30,7 @@ class PendingSolanaTransaction with PendingTransaction {
@override
Future<void> commit() async {
- _sig = await sendTransaction();
+ _sig = await sendTransaction() as String?;
}
@override
### cw_solana/lib/solana_balance.dart
@@ -15,7 +15,7 @@ class SolanaBalance extends Balance {
final decoded = json.decode(jsonSource) as Map;
try {
- return SolanaBalance(currency.parseAmount(decoded["balance"]));
+ return SolanaBalance(currency.parseAmount(decoded["balance"] as String));
} catch (e) {
return SolanaBalance(Money.zero(currency));
}
### cw_solana/lib/solana_client.dart
@@ -85,7 +85,7 @@ class SolanaWalletClient {
final balance = await _provider!.requestWithContext(
SolanaRPCGetBalance(account: SolAddress(walletAddress)),
);
- return Money(balance.result, CryptoCurrency.sol);
+ return Money(balance.result as BigInt, CryptoCurrency.sol);
} catch (_) {
if (throwOnError) {
rethrow;
@@ -1105,7 +1105,7 @@ class SolanaWalletClient {
try {
return await _provider!.request(
SolanaRPCGetTransaction(
- transactionSignature: signature['signature'],
+ transactionSignature: signature['signature'] as String,
encoding: SolanaRPCEncoding.jsonParsed,
maxSupportedTransactionVersion: 1,
skipVerification: true,
@@ -1299,11 +1299,11 @@ class SolanaWalletClient {
}
return SPLToken(
- name: name,
- mint: symbol,
- symbol: filteredTokenSymbol,
+ name: name as String,
+ mint: symbol as String,
+ symbol: filteredTokenSymbol as String,
mintAddress: mintAddress,
- iconPath: iconPath,
+ iconPath: iconPath as String?,
decimal: decimals,
);
} catch (e, s) {
@@ -2017,7 +2017,7 @@ class SolanaWalletClient {
final jsonResponse = json.decode(response.body) as Map<String, dynamic>;
if (response.statusCode >= 200 && response.statusCode < 300) {
- return jsonResponse['image'];
+ return jsonResponse['image'] as String?;
} else {
return null;
}
### cw_solana/lib/solana_transaction_info.dart
@@ -48,9 +48,9 @@ class SolanaTransactionInfo extends TransactionInfo {
direction: parseTransactionDirectionFromInt(data['direction'] as int),
date: DateTime.fromMillisecondsSinceEpoch(data['blockTime'] as int),
isPending: data['isPending'] as bool,
- to: data['to'],
- from: data['from'],
- fee: Money.parse(data['txFee'], CryptoCurrency.sol),
+ to: data['to'] as String?,
+ from: data['from'] as String?,
+ fee: Money.parse(data['txFee'] as String, CryptoCurrency.sol),
);
}
### cw_tron/lib/tron_balance.dart
@@ -17,7 +17,7 @@ class TronBalance extends Balance {
final decoded = json.decode(jsonSource) as Map;
try {
- return TronBalance(Money(BigInt.parse(decoded['balance']), currency));
+ return TronBalance(Money(BigInt.parse(decoded['balance'] as String), currency));
} catch (e) {
return TronBalance(Money.zero(currency));
}
### cw_tron/lib/tron_client.dart
@@ -469,7 +469,7 @@ class TronClient {
),
);
- final outputResult = request.outputResult?.first ?? BigInt.zero;
+ final outputResult = request.outputResult?.first as BigInt? ?? BigInt.zero;
return TronBalance(Money(outputResult, currency));
} catch (_) {
### cw_tron/lib/tron_transaction_info.dart
@@ -46,13 +46,13 @@ class TronTransactionInfo extends TransactionInfo {
return TronTransactionInfo(
id: data['id'] as String,
- amount: Money(BigInt.parse(data['tronAmount']), currency),
+ amount: Money(BigInt.parse(data['tronAmount'] as String), currency),
fee: Money.tryParse(data['txFee']?.toString() ?? '0', CryptoCurrency.trx, isBaseUnit: true),
direction: parseTransactionDirectionFromInt(data['direction'] as int),
blockTime: DateTime.fromMillisecondsSinceEpoch(data['blockTime'] as int),
- to: data['to'],
- from: data['from'],
- isPending: data['isPending'],
+ to: data['to'] as String?,
+ from: data['from'] as String?,
+ isPending: data['isPending'] as bool,
);
}
### cw_tron/lib/tron_transaction_model.dart
@@ -44,13 +44,13 @@ class TronTRC20TransactionModel extends TronTransactionModel {
});
TronTRC20TransactionModel.fromJson(Map<String, dynamic> json) {
- transactionId = json['transaction_id'];
- tokenSymbol = json['token_info'] != null ? json['token_info']['symbol'] : null;
- decimals = json['token_info'] != null ? json['token_info']['decimals'] : null;
- timestamp = json['block_timestamp'];
- from = json['from'];
- to = json['to'];
- value = json['value'];
+ transactionId = json['transaction_id'] as String?;
+ tokenSymbol = json['token_info'] != null ? json['token_info']['symbol'] as String? : null;
+ decimals = json['token_info'] != null ? json['token_info']['decimals'] as int? : null;
+ timestamp = json['block_timestamp'] as int?;
+ from = json['from'] as String?;
+ to = json['to'] as String?;
+ value = json['value'] as String?;
}
}
@@ -95,11 +95,11 @@ class TronTransactionModel {
if (json['ret'] != null) {
ret = <Ret>[];
json['ret'].forEach((v) {
- ret!.add(Ret.fromJson(v));
+ ret!.add(Ret.fromJson(v as Map<String, dynamic>));
});
}
- txID = json['txID'];
- blockTimestamp = json['block_timestamp'];
+ txID = json['txID'] as String?;
+ blockTimestamp = json['block_timestamp'] as int?;
contracts = json['raw_data'] != null
? (json['raw_data']['contract'] as List)
.map((e) => Contract.fromJson(e as Map<String, dynamic>))
@@ -115,8 +115,8 @@ class Ret {
Ret({this.contractRet, this.fee});
Ret.fromJson(Map<String, dynamic> json) {
- contractRet = json['contractRet'];
- fee = json['fee'];
+ contractRet = json['contractRet'] as String?;
+ fee = json['fee'] as int?;
}
}
@@ -127,8 +127,10 @@ class Contract {
Contract({this.parameter, this.type});
Contract.fromJson(Map<String, dynamic> json) {
- parameter = json['parameter'] != null ? Parameter.fromJson(json['parameter']) : null;
- type = json['type'];
+ parameter = json['parameter'] != null
+ ? Parameter.fromJson(json['parameter'] as Map<String, dynamic>)
+ : null;
+ type = json['type'] as String?;
}
}
@@ -139,8 +141,8 @@ class Parameter {
Parameter({this.value, this.typeUrl});
Parameter.fromJson(Map<String, dynamic> json) {
- value = json['value'] != null ? Value.fromJson(json['value']) : null;
- typeUrl = json['type_url'];
+ value = json['value'] != null ? Value.fromJson(json['value'] as Map<String, dynamic>) : null;
+ typeUrl = json['type_url'] as String?;
}
}
@@ -213,13 +215,13 @@ class Value {
this.assetName});
Value.fromJson(Map<String, dynamic> json) {
- data = json['data'];
- ownerAddress = json['owner_address'];
- contractAddress = json['contract_address'];
- amount = json['amount'];
+ data = json['data'] as String?;
+ ownerAddress = json['owner_address'] as String?;
+ contractAddress = json['contract_address'] as String?;
+ amount = json['amount'] as int?;
callValue = int.tryParse(json['call_value']?.toString() ?? "");
- toAddress = json['to_address'];
- assetName = json['asset_name'];
+ toAddress = json['to_address'] as String?;
+ assetName = json['asset_name'] as String?;
}
/// To get the address from the encoded data field
### cw_wownero/lib/api/wallet_manager.dart
@@ -100,7 +100,7 @@ void restoreWalletFromSeedSync(
required String seed,
int nettype = 0,
int restoreHeight = 0}) {
- var newWptr;
+ final wownero.wallet newWptr;
if (seed.split(" ").length == 14) {
txhistory = null;
newWptr = wownero.WOWNERO_deprecated_restore14WordSeed(
### cw_zcash/lib/src/migrate.dart
@@ -49,13 +49,13 @@ class YwalletAccountInfo {
final String ivk;
final String address;
static YwalletAccountInfo fromJson(final Map<String, dynamic> j) => YwalletAccountInfo(
- idAccount: j['id_account'],
- name: j['name'],
- seed: j['seed'],
- aindex: j['aindex'],
- sk: j['sk'],
- ivk: j['ivk'],
- address: j['address'],
+ idAccount: j['id_account'] as int,
+ name: j['name'] as String,
+ seed: j['seed'] as String,
+ aindex: j['aindex'] as int,
+ sk: j['sk'] as String,
+ ivk: j['ivk'] as String,
+ address: j['address'] as String,
);
}
### cw_zcash/lib/src/util/crc32.dart
@@ -20,11 +20,11 @@ class CRC32 {
crc = crc ^ (0xffffffff);
- for (final byte in input) {
- if (!(byte >= -128 && byte <= 255))
+ for (final byte in input as Iterable<dynamic>) {
+ if (!((byte >= -128) as bool && (byte <= 255) as bool))
throw new FormatException("Invalid value in input: $byte");
- final x = CRC32._table[(crc ^ byte) & 0xff];
+ final x = CRC32._table[(crc ^ (byte as int)) & 0xff];
crc = (crc & 0xffffffff) >> 8; // crc >>> 8 (32-bit unsigned integer)
crc ^= x;
}Why this scored 47/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.