mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-11 05:04:35 +00:00
show only token transfers in token tx history (for now)
This commit is contained in:
parent
4bd87e8dce
commit
6612dde2ef
2 changed files with 66 additions and 74 deletions
|
@ -387,15 +387,14 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
||||||
final List<Tuple2<Transaction, Address?>> txnsData = [];
|
final List<Tuple2<Transaction, Address?>> txnsData = [];
|
||||||
|
|
||||||
for (final tuple in data) {
|
for (final tuple in data) {
|
||||||
int amount;
|
// ignore all non Transfer events (for now)
|
||||||
String fromAddress, toAddress;
|
if (tuple.item1.topics[0] == kTransferEventSignature) {
|
||||||
if (tuple.item1.articulatedLog == null) {
|
final Amount amount;
|
||||||
if (tuple.item1.topics.length != 3) {
|
String fromAddress, toAddress;
|
||||||
throw Exception("Topics length != 3 for "
|
amount = Amount(
|
||||||
"${ethWallet.walletName} ${ethWallet.walletId}: "
|
rawValue: tuple.item1.data.toBigIntFromHex,
|
||||||
"${tuple.item1.toString()}");
|
fractionDigits: tokenContract.decimals,
|
||||||
}
|
);
|
||||||
amount = tuple.item1.data.toBigIntFromHex.toInt();
|
|
||||||
|
|
||||||
fromAddress = _addressFromTopic(
|
fromAddress = _addressFromTopic(
|
||||||
tuple.item1.topics[1],
|
tuple.item1.topics[1],
|
||||||
|
@ -403,74 +402,63 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
||||||
toAddress = _addressFromTopic(
|
toAddress = _addressFromTopic(
|
||||||
tuple.item1.topics[2],
|
tuple.item1.topics[2],
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
amount = int.parse(
|
|
||||||
tuple.item1.articulatedLog!.inputs.amount,
|
|
||||||
);
|
|
||||||
fromAddress = checksumEthereumAddress(
|
|
||||||
tuple.item1.articulatedLog!.inputs.from,
|
|
||||||
);
|
|
||||||
toAddress = checksumEthereumAddress(
|
|
||||||
tuple.item1.articulatedLog!.inputs.to,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isIncoming;
|
bool isIncoming;
|
||||||
bool isSentToSelf = false;
|
bool isSentToSelf = false;
|
||||||
if (fromAddress == addressString) {
|
if (fromAddress == addressString) {
|
||||||
isIncoming = false;
|
isIncoming = false;
|
||||||
if (toAddress == addressString) {
|
if (toAddress == addressString) {
|
||||||
isSentToSelf = true;
|
isSentToSelf = true;
|
||||||
|
}
|
||||||
|
} else if (toAddress == addressString) {
|
||||||
|
isIncoming = true;
|
||||||
|
} else {
|
||||||
|
throw Exception("Unknown token transaction found for "
|
||||||
|
"${ethWallet.walletName} ${ethWallet.walletId}: "
|
||||||
|
"${tuple.item1.toString()}");
|
||||||
}
|
}
|
||||||
} else if (toAddress == addressString) {
|
|
||||||
isIncoming = true;
|
final txn = Transaction(
|
||||||
} else {
|
walletId: ethWallet.walletId,
|
||||||
throw Exception("Unknown token transaction found for "
|
txid: tuple.item1.transactionHash,
|
||||||
"${ethWallet.walletName} ${ethWallet.walletId}: "
|
timestamp: tuple.item2.timestamp,
|
||||||
"${tuple.item1.toString()}");
|
type:
|
||||||
|
isIncoming ? TransactionType.incoming : TransactionType.outgoing,
|
||||||
|
subType: TransactionSubType.ethToken,
|
||||||
|
amount: amount.raw.toInt(),
|
||||||
|
amountString: amount.toJsonString(),
|
||||||
|
fee: (tuple.item2.gasUsed.raw * tuple.item2.gasPrice.raw).toInt(),
|
||||||
|
height: tuple.item1.blockNumber,
|
||||||
|
isCancelled: false,
|
||||||
|
isLelantus: false,
|
||||||
|
slateId: null,
|
||||||
|
otherData: tuple.item1.address,
|
||||||
|
inputs: [],
|
||||||
|
outputs: [],
|
||||||
|
);
|
||||||
|
|
||||||
|
Address? transactionAddress = await ethWallet.db
|
||||||
|
.getAddresses(ethWallet.walletId)
|
||||||
|
.filter()
|
||||||
|
.valueEqualTo(toAddress)
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
transactionAddress ??= Address(
|
||||||
|
walletId: ethWallet.walletId,
|
||||||
|
value: toAddress,
|
||||||
|
publicKey: [],
|
||||||
|
derivationIndex: isSentToSelf ? 0 : -1,
|
||||||
|
derivationPath: isSentToSelf
|
||||||
|
? (DerivationPath()..value = "$hdPathEthereum/0")
|
||||||
|
: null,
|
||||||
|
type: AddressType.ethereum,
|
||||||
|
subType: isSentToSelf
|
||||||
|
? AddressSubType.receiving
|
||||||
|
: AddressSubType.nonWallet,
|
||||||
|
);
|
||||||
|
|
||||||
|
txnsData.add(Tuple2(txn, transactionAddress));
|
||||||
}
|
}
|
||||||
|
|
||||||
final txn = Transaction(
|
|
||||||
walletId: ethWallet.walletId,
|
|
||||||
txid: tuple.item1.transactionHash,
|
|
||||||
timestamp: tuple.item2.timestamp,
|
|
||||||
type: isIncoming ? TransactionType.incoming : TransactionType.outgoing,
|
|
||||||
subType: TransactionSubType.ethToken,
|
|
||||||
amount: amount,
|
|
||||||
amountString: Amount(
|
|
||||||
rawValue: BigInt.from(amount),
|
|
||||||
fractionDigits: tokenContract.decimals,
|
|
||||||
).toJsonString(),
|
|
||||||
fee: tuple.item2.gasUsed * tuple.item2.gasPrice.toInt(),
|
|
||||||
height: tuple.item1.blockNumber,
|
|
||||||
isCancelled: false,
|
|
||||||
isLelantus: false,
|
|
||||||
slateId: null,
|
|
||||||
otherData: tuple.item1.address,
|
|
||||||
inputs: [],
|
|
||||||
outputs: [],
|
|
||||||
);
|
|
||||||
|
|
||||||
Address? transactionAddress = await ethWallet.db
|
|
||||||
.getAddresses(ethWallet.walletId)
|
|
||||||
.filter()
|
|
||||||
.valueEqualTo(toAddress)
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
transactionAddress ??= Address(
|
|
||||||
walletId: ethWallet.walletId,
|
|
||||||
value: toAddress,
|
|
||||||
publicKey: [],
|
|
||||||
derivationIndex: isSentToSelf ? 0 : -1,
|
|
||||||
derivationPath: isSentToSelf
|
|
||||||
? (DerivationPath()..value = "$hdPathEthereum/0")
|
|
||||||
: null,
|
|
||||||
type: AddressType.ethereum,
|
|
||||||
subType:
|
|
||||||
isSentToSelf ? AddressSubType.receiving : AddressSubType.nonWallet,
|
|
||||||
);
|
|
||||||
|
|
||||||
txnsData.add(Tuple2(txn, transactionAddress));
|
|
||||||
}
|
}
|
||||||
await ethWallet.db.addNewTransactionData(txnsData, ethWallet.walletId);
|
await ethWallet.db.addNewTransactionData(txnsData, ethWallet.walletId);
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,10 @@ class GasTracker {
|
||||||
|
|
||||||
const hdPathEthereum = "m/44'/60'/0'/0";
|
const hdPathEthereum = "m/44'/60'/0'/0";
|
||||||
|
|
||||||
|
// equal to "0x${keccak256("Transfer(address,address,uint256)".toUint8ListFromUtf8).toHex}";
|
||||||
|
const kTransferEventSignature =
|
||||||
|
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
||||||
|
|
||||||
String getPrivateKey(String mnemonic, String mnemonicPassphrase) {
|
String getPrivateKey(String mnemonic, String mnemonicPassphrase) {
|
||||||
final isValidMnemonic = bip39.validateMnemonic(mnemonic);
|
final isValidMnemonic = bip39.validateMnemonic(mnemonic);
|
||||||
if (!isValidMnemonic) {
|
if (!isValidMnemonic) {
|
||||||
|
|
Loading…
Reference in a new issue