mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +00:00
fetch raw tx call
This commit is contained in:
parent
bcadb07e9b
commit
d4cba56e81
2 changed files with 213 additions and 0 deletions
150
lib/dto/ethereum/pending_eth_tx_dto.dart
Normal file
150
lib/dto/ethereum/pending_eth_tx_dto.dart
Normal file
|
@ -0,0 +1,150 @@
|
|||
/// blockHash : null
|
||||
/// blockNumber : null
|
||||
/// from : "0x..."
|
||||
/// gas : "0x7e562"
|
||||
/// maxPriorityFeePerGas : "0x444380"
|
||||
/// maxFeePerGas : "0x342570c00"
|
||||
/// hash : "0x...da64e4"
|
||||
/// input : "....."
|
||||
/// nonce : "0x70"
|
||||
/// to : "0x00....."
|
||||
/// transactionIndex : null
|
||||
/// value : "0x0"
|
||||
/// type : "0x2"
|
||||
/// accessList : []
|
||||
/// chainId : "0x1"
|
||||
/// v : "0x0"
|
||||
/// r : "0xd..."
|
||||
/// s : "0x17d...6e6"
|
||||
|
||||
class PendingEthTxDto {
|
||||
PendingEthTxDto({
|
||||
required this.blockHash,
|
||||
required this.blockNumber,
|
||||
required this.from,
|
||||
required this.gas,
|
||||
required this.maxPriorityFeePerGas,
|
||||
required this.maxFeePerGas,
|
||||
required this.hash,
|
||||
required this.input,
|
||||
required this.nonce,
|
||||
required this.to,
|
||||
required this.transactionIndex,
|
||||
required this.value,
|
||||
required this.type,
|
||||
required this.accessList,
|
||||
required this.chainId,
|
||||
required this.v,
|
||||
required this.r,
|
||||
required this.s,
|
||||
});
|
||||
|
||||
factory PendingEthTxDto.fromMap(Map<String, dynamic> map) => PendingEthTxDto(
|
||||
blockHash: map['blockHash'] as String?,
|
||||
blockNumber: map['blockNumber'] as int?,
|
||||
from: map['from'] as String,
|
||||
gas: map['gas'] as String,
|
||||
maxPriorityFeePerGas: map['maxPriorityFeePerGas'] as String,
|
||||
maxFeePerGas: map['maxFeePerGas'] as String,
|
||||
hash: map['hash'] as String,
|
||||
input: map['input'] as String,
|
||||
nonce: map['nonce'] as String,
|
||||
to: map['to'] as String,
|
||||
transactionIndex: map['transactionIndex'] as int?,
|
||||
value: map['value'] as String,
|
||||
type: map['type'] as String,
|
||||
accessList: map['accessList'] as List? ?? [],
|
||||
chainId: map['chainId'] as String,
|
||||
v: map['v'] as String,
|
||||
r: map['r'] as String,
|
||||
s: map['s'] as String,
|
||||
);
|
||||
|
||||
final String? blockHash;
|
||||
final int? blockNumber;
|
||||
final String from;
|
||||
final String gas;
|
||||
final String maxPriorityFeePerGas;
|
||||
final String maxFeePerGas;
|
||||
final String hash;
|
||||
final String input;
|
||||
final String nonce;
|
||||
final String to;
|
||||
final int? transactionIndex;
|
||||
final String value;
|
||||
final String type;
|
||||
final List<dynamic> accessList;
|
||||
final String chainId;
|
||||
final String v;
|
||||
final String r;
|
||||
final String s;
|
||||
|
||||
PendingEthTxDto copyWith({
|
||||
String? blockHash,
|
||||
int? blockNumber,
|
||||
String? from,
|
||||
String? gas,
|
||||
String? maxPriorityFeePerGas,
|
||||
String? maxFeePerGas,
|
||||
String? hash,
|
||||
String? input,
|
||||
String? nonce,
|
||||
String? to,
|
||||
int? transactionIndex,
|
||||
String? value,
|
||||
String? type,
|
||||
List<dynamic>? accessList,
|
||||
String? chainId,
|
||||
String? v,
|
||||
String? r,
|
||||
String? s,
|
||||
}) =>
|
||||
PendingEthTxDto(
|
||||
blockHash: blockHash ?? this.blockHash,
|
||||
blockNumber: blockNumber ?? this.blockNumber,
|
||||
from: from ?? this.from,
|
||||
gas: gas ?? this.gas,
|
||||
maxPriorityFeePerGas: maxPriorityFeePerGas ?? this.maxPriorityFeePerGas,
|
||||
maxFeePerGas: maxFeePerGas ?? this.maxFeePerGas,
|
||||
hash: hash ?? this.hash,
|
||||
input: input ?? this.input,
|
||||
nonce: nonce ?? this.nonce,
|
||||
to: to ?? this.to,
|
||||
transactionIndex: transactionIndex ?? this.transactionIndex,
|
||||
value: value ?? this.value,
|
||||
type: type ?? this.type,
|
||||
accessList: accessList ?? this.accessList,
|
||||
chainId: chainId ?? this.chainId,
|
||||
v: v ?? this.v,
|
||||
r: r ?? this.r,
|
||||
s: s ?? this.s,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
final map = <String, dynamic>{};
|
||||
map['blockHash'] = blockHash;
|
||||
map['blockNumber'] = blockNumber;
|
||||
map['from'] = from;
|
||||
map['gas'] = gas;
|
||||
map['maxPriorityFeePerGas'] = maxPriorityFeePerGas;
|
||||
map['maxFeePerGas'] = maxFeePerGas;
|
||||
map['hash'] = hash;
|
||||
map['input'] = input;
|
||||
map['nonce'] = nonce;
|
||||
map['to'] = to;
|
||||
map['transactionIndex'] = transactionIndex;
|
||||
map['value'] = value;
|
||||
map['type'] = type;
|
||||
map['accessList'] = accessList;
|
||||
map['chainId'] = chainId;
|
||||
map['v'] = v;
|
||||
map['r'] = r;
|
||||
map['s'] = s;
|
||||
return map;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return toMap().toString();
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import 'package:http/http.dart';
|
|||
import 'package:stackwallet/dto/ethereum/eth_token_tx_dto.dart';
|
||||
import 'package:stackwallet/dto/ethereum/eth_token_tx_extra_dto.dart';
|
||||
import 'package:stackwallet/dto/ethereum/eth_tx_dto.dart';
|
||||
import 'package:stackwallet/dto/ethereum/pending_eth_tx_dto.dart';
|
||||
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
|
||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||
import 'package:stackwallet/utilities/default_nodes.dart';
|
||||
|
@ -90,6 +91,68 @@ abstract class EthereumAPI {
|
|||
}
|
||||
}
|
||||
|
||||
static Future<EthereumResponse<PendingEthTxDto>> getEthTransactionByHash(
|
||||
String txid) async {
|
||||
try {
|
||||
final response = await post(
|
||||
Uri.parse(
|
||||
"$stackBaseServer/v1/mainnet",
|
||||
),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: json.encode({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "eth_getTransactionByHash",
|
||||
"params": [
|
||||
txid,
|
||||
],
|
||||
"id": DateTime.now().millisecondsSinceEpoch,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
if (response.body.isNotEmpty) {
|
||||
try {
|
||||
final json = jsonDecode(response.body) as Map;
|
||||
final result = json["result"] as Map;
|
||||
return EthereumResponse(
|
||||
PendingEthTxDto.fromMap(Map<String, dynamic>.from(result)),
|
||||
null,
|
||||
);
|
||||
} catch (_) {
|
||||
throw EthApiException(
|
||||
"getEthTransactionByHash($txid) failed with response: "
|
||||
"${response.body}",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw EthApiException(
|
||||
"getEthTransactionByHash($txid) response is empty but status code is "
|
||||
"${response.statusCode}",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw EthApiException(
|
||||
"getEthTransactionByHash($txid) failed with status code: "
|
||||
"${response.statusCode}",
|
||||
);
|
||||
}
|
||||
} on EthApiException catch (e) {
|
||||
return EthereumResponse(
|
||||
null,
|
||||
e,
|
||||
);
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
"getEthTransactionByHash($txid): $e\n$s",
|
||||
level: LogLevel.Error,
|
||||
);
|
||||
return EthereumResponse(
|
||||
null,
|
||||
EthApiException(e.toString()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<EthereumResponse<List<Tuple2<EthTxDTO, int?>>>>
|
||||
getEthTransactionNonces(
|
||||
List<EthTxDTO> txns,
|
||||
|
|
Loading…
Reference in a new issue