Skip to content

Commit

Permalink
Merge branch 'zano-pr' into zano-pr-CW-685-collab
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCyjaneK committed Jan 19, 2025
2 parents 3147549 + d769af0 commit 3dee563
Show file tree
Hide file tree
Showing 152 changed files with 5,706 additions and 205 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ cw_shared_external/ios/External/
cw_haven/ios/External/
cw_haven/android/.externalNativeBuild/
cw_haven/android/.cxx/

cw_zano/ios/External/
lib/bitcoin/bitcoin.dart
lib/monero/monero.dart
lib/haven/haven.dart
Expand All @@ -137,6 +137,7 @@ lib/polygon/polygon.dart
lib/solana/solana.dart
lib/tron/tron.dart
lib/wownero/wownero.dart
lib/zano/zano.dart

ios/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_180.png
ios/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_120.png
Expand Down Expand Up @@ -179,3 +180,5 @@ scripts/monero_c
# iOS generated framework bin
ios/MoneroWallet.framework/MoneroWallet
ios/WowneroWallet.framework/WowneroWallet
ios/ZanoWallet.framework/ZanoWallet
*_libwallet2_api_c.dylib
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ analyzer:
lib/solana/cw_solana.dart,
lib/tron/cw_tron.dart,
lib/wownero/cw_wownero.dart,
lib/zano/cw_zano.dart,
]
language:
strict-casts: true
Expand Down
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifestBase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<data android:scheme="wownero" />
<data android:scheme="wownero-wallet" />
<data android:scheme="wownero_wallet" />
<data android:scheme="zano" />
<data android:scheme="zano-wallet" />
<data android:scheme="zano_wallet" />
</intent-filter>
<!-- nano-gpt link scheme -->
<intent-filter android:autoVerify="true">
Expand Down
Binary file added assets/images/zano_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/zano_node_list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-
uri: 37.27.100.59:10500
is_default: true
useSSL: false
16 changes: 16 additions & 0 deletions cw_bitcoin/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.10"
decimal:
dependency: transitive
description:
name: decimal
sha256: "24a261d5d5c87e86c7651c417a5dbdf8bcd7080dd592533910e8d0505a279f21"
url: "https://pub.dev"
source: hosted
version: "2.3.3"
encrypt:
dependency: transitive
description:
Expand Down Expand Up @@ -797,6 +805,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.2.2"
rational:
dependency: transitive
description:
name: rational
sha256: cb808fb6f1a839e6fc5f7d8cb3b0a10e1db48b3be102de73938c627f0b636336
url: "https://pub.dev"
source: hosted
version: "2.2.3"
rxdart:
dependency: "direct main"
description:
Expand Down
10 changes: 10 additions & 0 deletions cw_core/lib/amount_converter.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:decimal/decimal.dart';
import 'package:decimal/intl.dart';
import 'package:intl/intl.dart';
import 'package:cw_core/crypto_currency.dart';

Expand Down Expand Up @@ -43,6 +45,8 @@ class AmountConverter {
case CryptoCurrency.xnzd:
case CryptoCurrency.xusd:
return _moneroAmountToString(amount);
case CryptoCurrency.zano:
return _moneroAmountToStringUsingDecimals(amount);
default:
return '';
}
Expand All @@ -59,4 +63,10 @@ class AmountConverter {

static String _wowneroAmountToString(int amount) => _wowneroAmountFormat
.format(cryptoAmountToDouble(amount: amount, divider: _wowneroAmountDivider));

static Decimal cryptoAmountToDecimal({required int amount, required int divider}) =>
(Decimal.fromInt(amount) / Decimal.fromInt(divider)).toDecimal();

static String _moneroAmountToStringUsingDecimals(int amount) => _moneroAmountFormat.format(
DecimalIntl(cryptoAmountToDecimal(amount: amount, divider: _moneroAmountDivider)));
}
3 changes: 2 additions & 1 deletion cw_core/lib/crypto_currency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
CryptoCurrency.usdcTrc20,
CryptoCurrency.tbtc,
CryptoCurrency.wow,
CryptoCurrency.zano,
CryptoCurrency.ton,
];

Expand Down Expand Up @@ -225,7 +226,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
static const tbtc = CryptoCurrency(title: 'tBTC', fullName: 'Testnet Bitcoin', raw: 93, name: 'tbtc', iconPath: 'assets/images/tbtc.png', decimals: 8);
static const wow = CryptoCurrency(title: 'WOW', fullName: 'Wownero', raw: 94, name: 'wow', iconPath: 'assets/images/wownero_icon.png', decimals: 11);
static const ton = CryptoCurrency(title: 'TON', fullName: 'Toncoin', raw: 95, name: 'ton', iconPath: 'assets/images/ton_icon.png', decimals: 8);

static const zano = CryptoCurrency(title: 'ZANO', tag: 'ZANO', fullName: 'Zano', raw: 96, name: 'zano', iconPath: 'assets/images/zano_icon.png', decimals: 12);

static final Map<int, CryptoCurrency> _rawCurrencyMap =
[...all, ...havenCurrencies].fold<Map<int, CryptoCurrency>>(<int, CryptoCurrency>{}, (acc, item) {
Expand Down
3 changes: 3 additions & 0 deletions cw_core/lib/currency_for_wallet_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ CryptoCurrency currencyForWalletType(WalletType type, {bool? isTestnet}) {
return CryptoCurrency.trx;
case WalletType.wownero:
return CryptoCurrency.wow;
case WalletType.zano:
return CryptoCurrency.zano;
case WalletType.none:
throw Exception(

'Unexpected wallet type: ${type.toString()} for CryptoCurrency currencyForWalletType');
}
}
Expand Down
3 changes: 2 additions & 1 deletion cw_core/lib/hive_type_ids.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ const DERIVATION_INFO_TYPE_ID = 17;
const TRON_TOKEN_TYPE_ID = 18;
const HARDWARE_WALLET_TYPE_TYPE_ID = 19;
const MWEB_UTXO_TYPE_ID = 20;
const HAVEN_SEED_STORE_TYPE_ID = 21;
const HAVEN_SEED_STORE_TYPE_ID = 21;
const ZANO_ASSET_TYPE_ID = 22;
14 changes: 11 additions & 3 deletions cw_core/lib/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ class Node extends HiveObject with Keyable {
case WalletType.solana:
case WalletType.tron:
return Uri.parse(
"http${isSSL ? "s" : ""}://$uriRaw${path!.startsWith("/") ? path : "/$path"}");
"http${isSSL ? "s" : ""}://$uriRaw${path!.startsWith("/") ? path : "/$path"}");
case WalletType.zano:
return Uri.https(uriRaw, '');
case WalletType.none:
throw Exception('Unexpected type ${type.toString()} for Node uri');
}
Expand Down Expand Up @@ -161,6 +163,8 @@ class Node extends HiveObject with Keyable {
case WalletType.solana:
case WalletType.tron:
return requestElectrumServer();
case WalletType.zano:
return requestZanoNode();
case WalletType.none:
return false;
}
Expand All @@ -169,14 +173,18 @@ class Node extends HiveObject with Keyable {
}
}

Future<bool> requestMoneroNode() async {
Future<bool> requestZanoNode() async {
return requestMoneroNode(methodName: "getinfo");
}

Future<bool> requestMoneroNode({String methodName = "get_info"}) async {
if (uri.toString().contains(".onion") || useSocksProxy) {
return await requestNodeWithProxy();
}
final path = '/json_rpc';
final rpcUri = isSSL ? Uri.https(uri.authority, path) : Uri.http(uri.authority, path);
final realm = 'monero-rpc';
final body = {'jsonrpc': '2.0', 'id': '0', 'method': 'get_info'};
final body = {'jsonrpc': '2.0', 'id': '0', 'method': methodName};

try {
final authenticatingClient = HttpClient();
Expand Down
18 changes: 17 additions & 1 deletion cw_core/lib/wallet_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const walletTypes = [
WalletType.polygon,
WalletType.solana,
WalletType.tron,
WalletType.zano,
];

@HiveType(typeId: WALLET_TYPE_TYPE_ID)
Expand Down Expand Up @@ -58,6 +59,10 @@ enum WalletType {

@HiveField(12)
wownero,

@HiveField(13)
zano,

}

int serializeToInt(WalletType type) {
Expand Down Expand Up @@ -86,6 +91,8 @@ int serializeToInt(WalletType type) {
return 10;
case WalletType.wownero:
return 11;
case WalletType.zano:
return 12;
case WalletType.none:
return -1;
}
Expand Down Expand Up @@ -117,8 +124,11 @@ WalletType deserializeFromInt(int raw) {
return WalletType.tron;
case 11:
return WalletType.wownero;
case 12:
return WalletType.zano;
default:
throw Exception('Unexpected token: $raw for WalletType deserializeFromInt');
throw Exception(
'Unexpected token: $raw for WalletType deserializeFromInt');
}
}

Expand Down Expand Up @@ -148,6 +158,8 @@ String walletTypeToString(WalletType type) {
return 'Tron';
case WalletType.wownero:
return 'Wownero';
case WalletType.zano:
return 'Zano';
case WalletType.none:
return '';
}
Expand Down Expand Up @@ -179,6 +191,8 @@ String walletTypeToDisplayName(WalletType type) {
return 'Tron (TRX)';
case WalletType.wownero:
return 'Wownero (WOW)';
case WalletType.zano:
return 'Zano (ZANO)';
case WalletType.none:
return '';
}
Expand Down Expand Up @@ -213,6 +227,8 @@ CryptoCurrency walletTypeToCryptoCurrency(WalletType type, {bool isTestnet = fal
return CryptoCurrency.trx;
case WalletType.wownero:
return CryptoCurrency.wow;
case WalletType.zano:
return CryptoCurrency.zano;
case WalletType.none:
throw Exception(
'Unexpected wallet type: ${type.toString()} for CryptoCurrency walletTypeToCryptoCurrency');
Expand Down
117 changes: 117 additions & 0 deletions cw_core/lib/zano_asset.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/hive_type_ids.dart';
import 'package:hive/hive.dart';

part 'zano_asset.g.dart';

@HiveType(typeId: ZanoAsset.typeId)
class ZanoAsset extends CryptoCurrency with HiveObjectMixin {
@HiveField(0)
final String fullName;
@HiveField(1)
final String ticker;
@HiveField(2)
final String assetId;
@HiveField(3)
final int decimalPoint;
@HiveField(4, defaultValue: true)
bool _enabled;
@HiveField(5)
final String? iconPath;
// @HiveField(6)
// final String? tag;
@HiveField(6)
final String owner;
@HiveField(7)
final String metaInfo;
@HiveField(8)
final BigInt currentSupply;
@HiveField(9)
final bool hiddenSupply;
@HiveField(10)
final BigInt totalMaxSupply;
@HiveField(11)
final bool isInGlobalWhitelist;

bool get enabled => _enabled;

set enabled(bool value) => _enabled = value;

ZanoAsset({
this.fullName = '',
this.ticker = '',
required this.assetId,
this.decimalPoint = 12,
bool enabled = true,
this.iconPath,
this.owner = defaultOwner,
this.metaInfo = '',
required this.currentSupply,
this.hiddenSupply = false,
required this.totalMaxSupply,
this.isInGlobalWhitelist = false,
}) : _enabled = enabled,
super(
name: fullName,
title: ticker.toUpperCase(),
fullName: fullName,
tag: 'ZANO',
iconPath: iconPath,
decimals: decimalPoint,
);

ZanoAsset.copyWith(ZanoAsset other, {String? icon, String? assetId, bool enabled = true})
: this.fullName = other.fullName,
this.ticker = other.ticker,
this.assetId = assetId ?? other.assetId,
this.decimalPoint = other.decimalPoint,
this._enabled = enabled && other.enabled,
this.iconPath = icon,
this.currentSupply = other.currentSupply,
this.hiddenSupply = other.hiddenSupply,
this.metaInfo = other.metaInfo,
this.owner = other.owner,
this.totalMaxSupply = other.totalMaxSupply,
this.isInGlobalWhitelist = other.isInGlobalWhitelist,
super(
name: other.name,
title: other.ticker.toUpperCase(),
fullName: other.name,
tag: 'ZANO',
iconPath: icon,
decimals: other.decimalPoint,
enabled: enabled,
);

factory ZanoAsset.fromJson(Map<String, dynamic> json, {bool isInGlobalWhitelist = false}) => ZanoAsset(
assetId: json['asset_id'] as String? ?? '',
currentSupply: bigIntFromDynamic(json['current_supply']),
decimalPoint: json['decimal_point'] as int? ?? 12,
fullName: json['full_name'] as String? ?? '',
hiddenSupply: json['hidden_supply'] as bool? ?? false,
metaInfo: json['meta_info'] as String? ?? '',
owner: json['owner'] as String? ?? '',
ticker: json['ticker'] as String? ?? '',
totalMaxSupply: bigIntFromDynamic(json['total_max_supply']),
isInGlobalWhitelist: isInGlobalWhitelist,
);



static const typeId = ZANO_ASSET_TYPE_ID;
static const zanoAssetsBoxName = 'zanoAssetsBox';
static const defaultOwner = '0000000000000000000000000000000000000000000000000000000000000000';
}

BigInt bigIntFromDynamic(dynamic d) {
if (d is int) {
return BigInt.from(d);
} else if (d is BigInt) {
return d;
} else if (d == null) {
return BigInt.zero;
} else {
throw 'cannot cast value of type ${d.runtimeType} to BigInt';
//return BigInt.zero;
}
}
Loading

0 comments on commit 3dee563

Please sign in to comment.