Skip to content

Commit d892955

Browse files
Merge pull request #24 from cypherstack/staging
Add trusted node feature to Monero and Wownero
2 parents e450f07 + 80b1893 commit d892955

14 files changed

Lines changed: 86 additions & 6 deletions

File tree

cw_core/lib/node.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class Node extends HiveObject with Keyable {
1919
required WalletType type,
2020
this.login,
2121
this.password,
22-
this.useSSL}) {
22+
this.useSSL,
23+
this.trusted = false}) {
2324
uriRaw = uri;
2425
this.type = type;
2526
}
@@ -29,7 +30,8 @@ class Node extends HiveObject with Keyable {
2930
login = map['login'] as String?,
3031
password = map['password'] as String?,
3132
typeRaw = map['typeRaw'] as int?,
32-
useSSL = map['useSSL'] as bool?;
33+
useSSL = map['useSSL'] as bool?,
34+
trusted = map['trusted'] as bool? ?? false;
3335

3436
static const typeId = 1;
3537
static const boxName = 'Nodes';
@@ -49,6 +51,9 @@ class Node extends HiveObject with Keyable {
4951
@HiveField(4)
5052
bool? useSSL;
5153

54+
@HiveField(5)
55+
bool trusted;
56+
5257
bool get isSSL => useSSL ?? false;
5358

5459
Uri? get uri {

cw_monero/ios/Classes/monero_api.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,16 @@ extern "C"
795795
return strdup(get_current_wallet()->getSubaddressLabel(accountIndex, addressIndex).c_str());
796796
}
797797

798+
void set_trusted_daemon(bool arg)
799+
{
800+
m_wallet->setTrustedDaemon(arg);
801+
}
802+
803+
bool trusted_daemon()
804+
{
805+
return m_wallet->trustedDaemon();
806+
}
807+
798808
bool validate_address(char *address)
799809
{
800810
return get_current_wallet()->addressValid(std::string(address), 0); // TODO fix like by making the command below work or by otherwise detecting nettype

cw_monero/ios/Classes/monero_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ void set_refresh_from_block_height(uint64_t height);
3030
void set_recovering_from_seed(bool is_recovery);
3131
void store(char *path);
3232

33+
void set_trusted_daemon(bool arg);
34+
bool trusted_daemon();
35+
3336
bool validate_address(char *address);
3437

3538
#ifdef __cplusplus

cw_monero/lib/api/signatures.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,8 @@ typedef rescan_blockchain = Void Function();
137137
typedef get_subaddress_label = Pointer<Utf8> Function(
138138
Int32 accountIndex, Int32 addressIndex);
139139

140-
typedef validate_address = Int8 Function(
141-
Pointer<Utf8> address);
140+
typedef set_trusted_daemon = Void Function(Int8 trusted);
141+
142+
typedef trusted_daemon = Int8 Function();
143+
144+
typedef validate_address = Int8 Function(Pointer<Utf8> address);

cw_monero/lib/api/types.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,8 @@ typedef RescanBlockchainAsync = void Function();
136136
typedef GetSubaddressLabel = Pointer<Utf8> Function(
137137
int accountIndex, int addressIndex);
138138

139+
typedef SetTrustedDaemon = void Function(int);
140+
141+
typedef TrustedDaemon = int Function();
142+
139143
typedef ValidateAddress = int Function(Pointer<Utf8> address);

cw_monero/lib/api/wallet.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ final getSubaddressLabelNative = moneroApi
123123
.lookup<NativeFunction<get_subaddress_label>>('get_subaddress_label')
124124
.asFunction<GetSubaddressLabel>();
125125

126+
final setTrustedDaemonNative = moneroApi
127+
.lookup<NativeFunction<set_trusted_daemon>>('set_trusted_daemon')
128+
.asFunction<SetTrustedDaemon>();
129+
130+
final trustedDaemonNative = moneroApi
131+
.lookup<NativeFunction<trusted_daemon>>('trusted_daemon')
132+
.asFunction<TrustedDaemon>();
133+
126134
final validateAddressNative = moneroApi
127135
.lookup<NativeFunction<validate_address>>('validate_address')
128136
.asFunction<ValidateAddress>();
@@ -394,6 +402,11 @@ String getSubaddressLabel(int accountIndex, int addressIndex) {
394402
pointer: getSubaddressLabelNative(accountIndex, addressIndex));
395403
}
396404

405+
Future setTrustedDaemon(bool trusted) async =>
406+
setTrustedDaemonNative(_boolToInt(trusted));
407+
408+
Future<bool> trustedDaemon() async => trustedDaemonNative() != 0;
409+
397410
bool validateAddress(String address) {
398411
final addressPointer = address.toNativeUtf8();
399412
final valid = validateAddressNative(addressPointer) != 0;

cw_monero/lib/monero_wallet.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
145145
password: node.password,
146146
useSSL: node.isSSL,
147147
isLightWallet: false); // FIXME: hardcoded value
148+
149+
monero_wallet.setTrustedDaemon(node.trusted);
148150
syncStatus = ConnectedSyncStatus();
149151
syncStatusChanged?.call();
150152
} catch (e) {

cw_wownero/ios/Classes/wownero_api.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,16 @@ extern "C"
886886
return strdup(get_current_wallet()->getSubaddressLabel(accountIndex, addressIndex).c_str());
887887
}
888888

889+
void set_trusted_daemon(bool arg)
890+
{
891+
m_wallet->setTrustedDaemon(arg);
892+
}
893+
894+
bool trusted_daemon()
895+
{
896+
return m_wallet->trustedDaemon();
897+
}
898+
889899
bool validate_address(char *address)
890900
{
891901
return get_current_wallet()->addressValid(std::string(address), 0); // TODO fix like by making the command below work or by otherwise detecting nettype

cw_wownero/ios/Classes/wownero_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ void set_refresh_from_block_height(uint64_t height);
3232
void set_recovering_from_seed(bool is_recovery);
3333
void store(char *path);
3434

35+
void set_trusted_daemon(bool arg);
36+
bool trusted_daemon();
37+
3538
bool validate_address(char *address);
3639

3740
#ifdef __cplusplus

cw_wownero/lib/api/signatures.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ typedef rescan_blockchain = Void Function();
145145
typedef get_subaddress_label = Pointer<Utf8> Function(
146146
Int32 accountIndex, Int32 addressIndex);
147147

148-
typedef validate_address = Int8 Function(
149-
Pointer<Utf8> address);
148+
typedef set_trusted_daemon = Void Function(Int8 trusted);
150149

150+
typedef trusted_daemon = Int8 Function();
151+
152+
typedef validate_address = Int8 Function(Pointer<Utf8> address);

0 commit comments

Comments
 (0)