mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-12 09:27:01 +00:00
Update tx send to use abstract class send functions
This commit is contained in:
parent
b178c30620
commit
8ec8c6c914
2 changed files with 43 additions and 133 deletions
|
@ -124,51 +124,6 @@ Future<void> executeNative(Map<String, dynamic> arguments) async {
|
|||
sendPort.send(result);
|
||||
return;
|
||||
}
|
||||
} else if (function == "createTransaction") {
|
||||
final wallet = arguments['wallet'] as String?;
|
||||
final amount = arguments['amount'] as int?;
|
||||
final address = arguments['address'] as String?;
|
||||
final secretKeyIndex = arguments['secretKeyIndex'] as int?;
|
||||
final epicboxConfig = arguments['epicboxConfig'] as String?;
|
||||
final minimumConfirmations = arguments['minimumConfirmations'] as int?;
|
||||
final onChainNote = arguments['onChainNote'] as String?;
|
||||
|
||||
Map<String, dynamic> result = {};
|
||||
if (!(wallet == null ||
|
||||
amount == null ||
|
||||
address == null ||
|
||||
secretKeyIndex == null ||
|
||||
epicboxConfig == null ||
|
||||
minimumConfirmations == null)) {
|
||||
var res = await createTransaction(wallet, amount, address,
|
||||
secretKeyIndex, epicboxConfig, minimumConfirmations, onChainNote!);
|
||||
result['result'] = res;
|
||||
sendPort.send(result);
|
||||
return;
|
||||
}
|
||||
} else if (function == "txHttpSend") {
|
||||
final wallet = arguments['wallet'] as String?;
|
||||
final selectionStrategyIsAll =
|
||||
arguments['selectionStrategyIsAll'] as int?;
|
||||
final minimumConfirmations = arguments['minimumConfirmations'] as int?;
|
||||
final message = arguments['message'] as String?;
|
||||
final amount = arguments['amount'] as int?;
|
||||
final address = arguments['address'] as String?;
|
||||
|
||||
Map<String, dynamic> result = {};
|
||||
|
||||
if (!(wallet == null ||
|
||||
selectionStrategyIsAll == null ||
|
||||
minimumConfirmations == null ||
|
||||
message == null ||
|
||||
amount == null ||
|
||||
address == null)) {
|
||||
var res = await txHttpSend(wallet, selectionStrategyIsAll,
|
||||
minimumConfirmations, message, amount, address);
|
||||
result['result'] = res;
|
||||
sendPort.send(result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Logging.instance.log(
|
||||
|
@ -381,12 +336,10 @@ class EpicCashWallet extends CoinServiceAPI
|
|||
Future<String> confirmSend({required Map<String, dynamic> txData}) async {
|
||||
try {
|
||||
final wallet = await _secureStore.read(key: '${_walletId}_wallet');
|
||||
|
||||
EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig();
|
||||
|
||||
// TODO determine whether it is worth sending change to a change address.
|
||||
dynamic message;
|
||||
|
||||
String slateId;
|
||||
String receiverAddress = txData['addresss'] as String;
|
||||
|
||||
if (!receiverAddress.startsWith("http://") ||
|
||||
|
@ -398,96 +351,36 @@ class EpicCashWallet extends CoinServiceAPI
|
|||
}
|
||||
}
|
||||
|
||||
// await m.protect(() async {
|
||||
// if (receiverAddress.startsWith("http://") ||
|
||||
// receiverAddress.startsWith("https://")) {
|
||||
// const int selectionStrategyIsAll = 0;
|
||||
// ReceivePort receivePort = await getIsolate({
|
||||
// "function": "txHttpSend",
|
||||
// "wallet": wallet!,
|
||||
// "selectionStrategyIsAll": selectionStrategyIsAll,
|
||||
// "minimumConfirmations": MINIMUM_CONFIRMATIONS,
|
||||
// "message": txData['onChainNote'],
|
||||
// "amount": (txData['recipientAmt'] as Amount).raw.toInt(),
|
||||
// "address": txData['addresss'] as String,
|
||||
// }, name: walletName);
|
||||
//
|
||||
// message = await receivePort.first;
|
||||
// if (message is String) {
|
||||
// Logging.instance
|
||||
// .log("this is a string $message", level: LogLevel.Error);
|
||||
// stop(receivePort);
|
||||
// throw Exception(message);
|
||||
// }
|
||||
// stop(receivePort);
|
||||
// Logging.instance
|
||||
// .log('Closing txHttpSend!\n $message', level: LogLevel.Info);
|
||||
// } else {
|
||||
// ReceivePort receivePort = await getIsolate({
|
||||
// "function": "createTransaction",
|
||||
// "wallet": wallet!,
|
||||
// "amount": (txData['recipientAmt'] as Amount).raw.toInt(),
|
||||
// "address": txData['addresss'] as String,
|
||||
// "secretKeyIndex": 0,
|
||||
// "epicboxConfig": epicboxConfig.toString(),
|
||||
// "minimumConfirmations": MINIMUM_CONFIRMATIONS,
|
||||
// "onChainNote": txData['onChainNote'],
|
||||
// }, name: walletName);
|
||||
//
|
||||
// message = await receivePort.first;
|
||||
// if (message is String) {
|
||||
// Logging.instance
|
||||
// .log("this is a string $message", level: LogLevel.Error);
|
||||
// stop(receivePort);
|
||||
// throw Exception("createTransaction isolate failed");
|
||||
// }
|
||||
// stop(receivePort);
|
||||
// Logging.instance.log('Closing createTransaction!\n $message',
|
||||
// level: LogLevel.Info);
|
||||
// }
|
||||
// });
|
||||
({String commitId, String slateId}) transaction;
|
||||
|
||||
// return message;
|
||||
var transaction = await epiccash.LibEpiccash.createTransaction(
|
||||
wallet: wallet!,
|
||||
amount: (txData['recipientAmt'] as Amount).raw.toInt(),
|
||||
address: txData['addresss'] as String,
|
||||
secretKeyIndex: 0,
|
||||
epicboxConfig: epicboxConfig.toString(),
|
||||
minimumConfirmations: MINIMUM_CONFIRMATIONS,
|
||||
note: txData['onChainNote'] as String);
|
||||
if (receiverAddress.startsWith("http://") ||
|
||||
receiverAddress.startsWith("https://")) {
|
||||
|
||||
transaction = await epiccash.LibEpiccash.txHttpSend(
|
||||
wallet: wallet!,
|
||||
selectionStrategyIsAll: 0,
|
||||
minimumConfirmations: MINIMUM_CONFIRMATIONS,
|
||||
message: txData['onChainNote'] as String,
|
||||
amount: (txData['recipientAmt'] as Amount).raw.toInt(),
|
||||
address: txData['addresss'] as String);
|
||||
} else {
|
||||
transaction = await epiccash.LibEpiccash.createTransaction(
|
||||
wallet: wallet!,
|
||||
amount: (txData['recipientAmt'] as Amount).raw.toInt(),
|
||||
address: txData['addresss'] as String,
|
||||
secretKeyIndex: 0,
|
||||
epicboxConfig: epicboxConfig.toString(),
|
||||
minimumConfirmations: MINIMUM_CONFIRMATIONS,
|
||||
note: txData['onChainNote'] as String);
|
||||
}
|
||||
|
||||
// final String sendTx = message['result'] as String;
|
||||
// if (sendTx.contains("Error")) {
|
||||
// throw BadEpicHttpAddressException(message: sendTx);
|
||||
// }
|
||||
//
|
||||
Map<String, String> txAddressInfo = {};
|
||||
txAddressInfo['from'] = await currentReceivingAddress;
|
||||
txAddressInfo['to'] = txData['addresss'] as String;
|
||||
await putSendToAddresses(transaction, txAddressInfo);
|
||||
|
||||
return transaction.slateId;
|
||||
//
|
||||
// Logging.instance.log("CONFIRM_RESULT_IS $sendTx", level: LogLevel.Info);
|
||||
//
|
||||
// final decodeData = json.decode(sendTx);
|
||||
//
|
||||
// if (decodeData[0] == "transaction_failed") {
|
||||
// String errorMessage = decodeData[1] as String;
|
||||
// throw Exception("Transaction failed with error code $errorMessage");
|
||||
// } else {
|
||||
// final txCreateResult = decodeData[0];
|
||||
// // //TODO: second problem
|
||||
// final transaction = json.decode(txCreateResult as String);
|
||||
//
|
||||
// final tx = transaction[0];
|
||||
// final txLogEntry = json.decode(tx as String);
|
||||
// final txLogEntryFirst = txLogEntry[0];
|
||||
// final slateId = txLogEntryFirst['tx_slate_id'] as String;
|
||||
// // return slateId!;
|
||||
//
|
||||
// }
|
||||
slateId = transaction.slateId;
|
||||
return slateId;
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("Error sending $e - $s", level: LogLevel.Error);
|
||||
rethrow;
|
||||
|
|
|
@ -579,7 +579,7 @@ abstract class LibEpiccash {
|
|||
///
|
||||
///
|
||||
///
|
||||
static Future<String> txHttpSend({
|
||||
static Future<({String commitId, String slateId})> txHttpSend({
|
||||
required String wallet,
|
||||
required int selectionStrategyIsAll,
|
||||
required int minimumConfirmations,
|
||||
|
@ -588,7 +588,7 @@ abstract class LibEpiccash {
|
|||
required String address,
|
||||
}) async {
|
||||
try {
|
||||
return await compute(_txHttpSendWrapper, (
|
||||
var result = await compute(_txHttpSendWrapper, (
|
||||
wallet: wallet,
|
||||
selectionStrategyIsAll: selectionStrategyIsAll,
|
||||
minimumConfirmations: minimumConfirmations,
|
||||
|
@ -596,6 +596,23 @@ abstract class LibEpiccash {
|
|||
amount: amount,
|
||||
address: address,
|
||||
));
|
||||
|
||||
if (result.toUpperCase().contains("ERROR")) {
|
||||
throw Exception("Error creating transaction ${result.toString()}");
|
||||
}
|
||||
|
||||
//Decode sent tx and return Slate Id
|
||||
final slate0 = jsonDecode(result);
|
||||
final slate = jsonDecode(slate0[0] as String);
|
||||
final part1 = jsonDecode(slate[0] as String);
|
||||
final part2 = jsonDecode(slate[1] as String);
|
||||
|
||||
({String slateId, String commitId}) data = (
|
||||
slateId: part1[0]['tx_slate_id'],
|
||||
commitId: part2['tx']['body']['outputs'][0]['commit'],
|
||||
);
|
||||
|
||||
return data;
|
||||
} catch (e) {
|
||||
throw ("Error sending tx HTTP : ${e.toString()}");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue