feat: alchemy

This commit is contained in:
hashbro
2026-09-29 05:51:48 +08:00
parent 15c45a4fd2
commit eb82aa8332
2 changed files with 95 additions and 6 deletions
+22 -6
View File
@@ -142,8 +142,10 @@ class MnemonicWalletDiscovery
return count($saved);
});
// Scheduled run: mark complete once every chain has been probed at least once.
if (! $force && count($covered) === count(self::CHAINS)) {
// Scheduled run: mark complete as soon as derivation has run at least once
// (any chain covered — linked / miss-cached / probed). Subsequent scheduled
// runs skip this mnemonic entirely; manual force=true still re-probes.
if (! $force && $covered !== []) {
WalletMnemonic::query()
->whereKey($mnemonic->id)
->update([
@@ -260,7 +262,7 @@ class MnemonicWalletDiscovery
continue;
}
$saved[] = $this->persistActivated(
$persisted = $this->persistActivated(
$mnemonic,
$source,
$chainType,
@@ -268,6 +270,9 @@ class MnemonicWalletDiscovery
$index,
$probe['coins'],
);
if ($persisted !== null) {
$saved[] = $persisted;
}
}
return $saved;
@@ -483,7 +488,13 @@ class MnemonicWalletDiscovery
}
/**
* Persist (or refresh) an activated derived address. Returns the row only
* when this is a first-time association (new row, or previously unlinked) so
* the caller can fire a single "可归集" notification. Already-linked rows are
* refreshed silently and return null to avoid duplicate notifications.
*
* @param array<string, string> $coins
* @return WalletAddress|null null when the row was already linked to this mnemonic
*/
private function persistActivated(
WalletMnemonic $mnemonic,
@@ -492,7 +503,7 @@ class MnemonicWalletDiscovery
string $address,
int $index,
array $coins,
): WalletAddress {
): ?WalletAddress {
$row = WalletAddress::query()->firstOrNew([
'device_id' => $mnemonic->device_id,
'address' => $address,
@@ -500,11 +511,16 @@ class MnemonicWalletDiscovery
'chain_type' => $chainType,
]);
// First-time association = brand-new row OR an existing row that had no
// mnemonic link yet. Only these warrant a collectable notification.
$isNew = ! $row->exists;
$wasUnlinked = $isNew || $row->getOriginal('mnemonic_id') === null;
$row->chain_type = $chainType;
$row->mnemonic_id = $mnemonic->id;
$row->derive_index = $index;
$row->monitor = 1;
if (! $row->exists) {
if ($isNew) {
$row->monitor_synced = false;
$row->monitor_failures = 0;
}
@@ -514,7 +530,7 @@ class MnemonicWalletDiscovery
$row->save();
$this->enableMonitor($row);
return $row;
return $wasUnlinked ? $row : null;
}
/**