Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import 'package:komodo_defi_rpc_methods/src/common_structures/common_structures.dart';
import 'package:komodo_defi_types/komodo_defi_type_utils.dart';
import 'package:komodo_defi_types/komodo_defi_types.dart';

/// SIA-specific activation parameters
/// Activation parameters specific to SIA protocol coins.
///
/// Supports:
/// - serverUrl: SiaScan-compatible wallet API base URL
/// - txHistory: whether to fetch transaction history on enable
/// - requiredConfirmations: confirmations to wait for swap steps
/// This extends the generic [ActivationParams] with:
/// - a required [serverUrl] pointing at a SiaScan-compatible wallet API
/// - an optional [password] for the SIA wallet daemon
/// - a [txHistory] flag that controls whether transaction history is enabled
///
/// The shape produced by [toRpcParams] matches the KDF
/// `task::enable_sia::init` API, nesting values under `activation_params.client_conf`.
class SiaActivationParams extends ActivationParams {
const SiaActivationParams({
required this.serverUrl,
this.password,
this.txHistory = true,
int? requiredConfirmations,
PrivateKeyPolicy privKeyPolicy = const PrivateKeyPolicy.contextPrivKey(),
}) : super(
requiredConfirmations: requiredConfirmations,
privKeyPolicy: privKeyPolicy,
);
super.requiredConfirmations,
super.privKeyPolicy,
});

/// Creates [SiaActivationParams] from a coins-config JSON entry.
///
/// The SIA server URL is taken from:
/// - `server_url`, or
/// - the first `nodes[].url` entry as a fallback.
///
/// Throws [ArgumentError] if no usable URL can be found.
factory SiaActivationParams.fromConfigJson(JsonMap json) {
String? serverUrl = json.valueOrNull<String>('server_url');
var serverUrl = json.valueOrNull<String>('server_url');
if (serverUrl == null && json.containsKey('nodes')) {
final nodes = json.value<List<dynamic>>('nodes');
if (nodes.isNotEmpty) {
Expand All @@ -45,15 +52,19 @@ class SiaActivationParams extends ActivationParams {
);
}

/// Base URL of the SIA wallet API (e.g. `https://api.siascan.com/wallet/api`).
final String serverUrl;

/// Optional password to unlock or authenticate the SIA wallet daemon.
final String? password;

/// Whether SIA transaction history should be enabled on activation.
final bool txHistory;

@override
Map<String, dynamic> toRpcParams() => super.toRpcParams().deepMerge({
'client_conf': {
'server_url': serverUrl,
},
'tx_history': txHistory,
});
// SIA activation uses a nested client_conf object
'client_conf': {'server_url': serverUrl, 'password': ?password},
Comment thread
takenagain marked this conversation as resolved.
Comment thread
takenagain marked this conversation as resolved.
'tx_history': txHistory,
Comment thread
takenagain marked this conversation as resolved.
});
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ export 'activation/activation_params/utxo_activation_params.dart';
export 'activation/activation_params/zhtlc_activation_params.dart';
export 'activation/coin_protocol.dart';
export 'activation/evm_node.dart';
export 'activation/strategies/utxo_activation_strategy.dart';
export 'activation/tokens_request.dart';
export 'activation/utxo_merge_params.dart';
export 'general/address_format.dart';
export 'general/balance_info.dart';
export 'general/fee_info.dart';
export 'general/new_address_info.dart';
export 'general/scan_address_info.dart';
export 'general/sync_status.dart';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TransactionInfo {
required this.coin,
required this.internalId,
required this.memo,
this.txJson,
this.spentByMe,
this.receivedByMe,
this.transactionFee,
Expand All @@ -24,14 +25,14 @@ class TransactionInfo {
txHash: json.value<String>('tx_hash'),
from: List<String>.from(json.value('from')),
to: List<String>.from(json.value('to')),
txJson: json.valueOrNull<JsonMap>('tx_json'),
myBalanceChange: json.value<String>('my_balance_change'),
blockHeight: json.value<int>('block_height'),
confirmations: json.value<int>('confirmations'),
timestamp: json.value<int>('timestamp'),
feeDetails:
json.containsKey('fee_details')
? FeeInfo.fromJson(json.value('fee_details'))
: null,
feeDetails: json.containsKey('fee_details')
? FeeInfo.fromJson(json.value('fee_details'))
: null,
transactionFee: json.valueOrNull<String>('transaction_fee'),
coin: json.value<String>('coin'),
internalId: json.value<String>('internal_id'),
Expand All @@ -47,6 +48,9 @@ class TransactionInfo {
final String myBalanceChange;
final int blockHeight;
final int confirmations;

/// Raw transaction JSON (present for SIA protocol transactions).
final JsonMap? txJson;
final int timestamp;
final FeeInfo? feeDetails;
final String? transactionFee;
Expand All @@ -60,6 +64,7 @@ class TransactionInfo {
'tx_hash': txHash,
'from': from,
'to': to,
'tx_json': ?txJson,
Comment thread
takenagain marked this conversation as resolved.
Comment thread
takenagain marked this conversation as resolved.
Comment thread
takenagain marked this conversation as resolved.
'my_balance_change': myBalanceChange,
'block_height': blockHeight,
'confirmations': confirmations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export 'wallet/get_wallet_names_response.dart';
export 'wallet/my_balance.dart';
export 'wallet/unban_pubkeys.dart';
export 'withdrawal/send_raw_transaction_request.dart';
export 'withdrawal/sia_withdraw_request.dart';
export 'withdrawal/withdraw_request.dart';
export 'withdrawal/withdrawal_rpc_namespace.dart';
export 'zhtlc/z_coin_tx_history.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'package:komodo_defi_rpc_methods/src/internal_exports.dart';
import 'package:komodo_defi_types/komodo_defi_type_utils.dart';

/// Request for the `task::enable_sia::init` RPC.
///
/// Starts a task-managed activation flow for a SIA protocol coin and returns
/// a [NewTaskResponse] containing the activation task ID.
class TaskEnableSiaInit
extends BaseRequest<NewTaskResponse, GeneralErrorResponse> {
TaskEnableSiaInit({
required this.ticker,
required this.params,
super.rpcPass,
}) : super(method: 'task::enable_sia::init', mmrpc: RpcVersion.v2_0);
TaskEnableSiaInit({required this.ticker, required this.params, super.rpcPass})
: super(method: 'task::enable_sia::init', mmrpc: RpcVersion.v2_0);

final String ticker;

Expand All @@ -17,22 +18,22 @@ class TaskEnableSiaInit

@override
Map<String, dynamic> toJson() => {
...super.toJson(),
'userpass': rpcPass,
'mmrpc': mmrpc,
'method': method,
'params': {
'ticker': ticker,
'activation_params': params.toRpcParams(),
},
};
...super.toJson(),
'userpass': rpcPass,
'mmrpc': mmrpc,
'method': method,
'params': {'ticker': ticker, 'activation_params': params.toRpcParams()},
};

@override
NewTaskResponse parse(Map<String, dynamic> json) {
return NewTaskResponse.parse(json);
}
}

/// Request for the `task::enable_sia::status` RPC.
///
/// Polls the status of an ongoing SIA activation task.
class TaskEnableSiaStatus
extends BaseRequest<TaskStatusResponse, GeneralErrorResponse> {
TaskEnableSiaStatus({
Expand All @@ -46,39 +47,99 @@ class TaskEnableSiaStatus

@override
Map<String, dynamic> toJson() => {
...super.toJson(),
'userpass': rpcPass,
'mmrpc': mmrpc,
'method': method,
'params': {'task_id': taskId, 'forget_if_finished': forgetIfFinished},
};
...super.toJson(),
'userpass': rpcPass,
'mmrpc': mmrpc,
'method': method,
'params': {'task_id': taskId, 'forget_if_finished': forgetIfFinished},
};

@override
TaskStatusResponse parse(Map<String, dynamic> json) {
return TaskStatusResponse.parse(json);
}
}

/// Request for the `task::enable_sia::cancel` RPC.
///
/// Cancels an ongoing SIA activation task and returns a [SiaCancelResponse]
/// indicating whether the cancel operation was successful.
class TaskEnableSiaCancel
extends BaseRequest<TaskStatusResponse, GeneralErrorResponse> {
TaskEnableSiaCancel({
extends BaseRequest<SiaCancelResponse, GeneralErrorResponse> {
TaskEnableSiaCancel({required this.taskId, super.rpcPass})
: super(method: 'task::enable_sia::cancel', mmrpc: RpcVersion.v2_0);

final int taskId;

@override
Map<String, dynamic> toJson() => {
...super.toJson(),
'userpass': rpcPass,
'mmrpc': mmrpc,
'method': method,
'params': {'task_id': taskId},
};

@override
SiaCancelResponse parse(Map<String, dynamic> json) =>
SiaCancelResponse.parse(json);
}

/// Request for the `task::enable_sia::user_action` RPC.
///
/// Used when the SIA activation flow requires user interaction, such as
/// providing a hardware-wallet PIN or passphrase.
class TaskEnableSiaUserAction
extends BaseRequest<UserActionResponse, GeneralErrorResponse> {
TaskEnableSiaUserAction({
required this.taskId,
required this.actionType,
this.pin,
this.passphrase,
super.rpcPass,
}) : super(method: 'task::enable_sia::cancel', mmrpc: RpcVersion.v2_0);
}) : super(method: 'task::enable_sia::user_action', mmrpc: RpcVersion.v2_0);

final int taskId;
final String actionType;
final String? pin;
final String? passphrase;

@override
Map<String, dynamic> toJson() => {
...super.toJson(),
'userpass': rpcPass,
'mmrpc': mmrpc,
'method': method,
'params': {'task_id': taskId},
};
...super.toJson(),
'userpass': rpcPass,
'mmrpc': mmrpc,
'method': method,
'params': {
'task_id': taskId,
'user_action': {
'action_type': actionType,
if (pin != null) 'pin': pin,
if (passphrase != null) 'passphrase': passphrase,
},
},
};

@override
TaskStatusResponse parse(Map<String, dynamic> json) =>
TaskStatusResponse.parse(json);
UserActionResponse parse(Map<String, dynamic> json) =>
UserActionResponse.parse(JsonMap.of(json));
}

/// Response returned by the `task::enable_sia::cancel` RPC.
///
/// Wraps a simple [result] string, which is `"success"` on success.
class SiaCancelResponse extends BaseResponse {
SiaCancelResponse({required super.mmrpc, required this.result});

factory SiaCancelResponse.parse(Map<String, dynamic> json) {
return SiaCancelResponse(
mmrpc: json.value<String>('mmrpc'),
result: json.value<String>('result'),
);
}

final String result;

@override
Map<String, dynamic> toJson() => {'mmrpc': mmrpc, 'result': result};
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import 'package:komodo_defi_rpc_methods/komodo_defi_rpc_methods.dart';
import 'package:komodo_defi_types/komodo_defi_type_utils.dart';

/// High-level namespace for SIA-specific RPC methods.
///
/// Provides typed helpers over the raw `task::enable_sia::*` APIs.
class SiaMethodsNamespace extends BaseRpcMethodNamespace {
SiaMethodsNamespace(super.client);

/// Initialize SIA activation using `task::enable_sia::init`.
///
/// Returns a [NewTaskResponse] with the activation task ID.
Future<NewTaskResponse> enableSiaInit({
required String ticker,
required SiaActivationParams params,
Expand All @@ -17,6 +22,7 @@ class SiaMethodsNamespace extends BaseRpcMethodNamespace {
);
}

/// Get activation status using `task::enable_sia::status`.
Future<TaskStatusResponse> enableSiaStatus(
int taskId, {
bool forgetIfFinished = true,
Expand All @@ -30,10 +36,33 @@ class SiaMethodsNamespace extends BaseRpcMethodNamespace {
);
}

Future<BaseResponse> enableSiaCancel({required int taskId}) {
/// Cancel an activation task using `task::enable_sia::cancel`.
///
/// Returns a [SiaCancelResponse] that indicates success or failure.
Future<SiaCancelResponse> enableSiaCancel({required int taskId}) {
return execute(
TaskEnableSiaCancel(taskId: taskId, rpcPass: rpcPass),
);
}

/// Provide user interaction for SIA activation via `task::enable_sia::user_action`.
///
/// Typically used to pass Trezor PIN or passphrase when required.
Future<UserActionResponse> enableSiaUserAction({
required int taskId,
required String actionType,
String? pin,
String? passphrase,
}) {
return execute(
TaskEnableSiaUserAction(
taskId: taskId,
actionType: actionType,
pin: pin,
passphrase: passphrase,
rpcPass: rpcPass,
),
);
}
}

Loading
Loading