You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NewWallet(ctx context.Context, id idriver.WalletID, role idriver.IdentityRoleType, isIdentitySupport, info idriver.IdentityInfo) (driver.Wallet, error)
23
23
}
24
24
25
+
// WalletIDStatus classifies the outcome of resolving an identity to the wallet id
26
+
// bound to it. It exists so callers branch on an explicit, named state instead of
27
+
// re-deriving intent from the ambiguous "(string, error)" shape — where ("", nil),
28
+
// ("", err) and ("id", nil) each mean something different and the difference is easy
29
+
// to get wrong (see issue #2063).
30
+
typeWalletIDStatusint
31
+
32
+
const (
33
+
// WalletIDUnknown is the zero value and never returned by GetWalletID. It is the
34
+
// guard against a WalletIDResolution constructed without going through GetWalletID
35
+
// (a mock, or a future constructor that forgets to set Status): because callers act
36
+
// on a fallthrough only when authoritative() is true — Bound or Unbound — this zero
37
+
// value is treated as a lookup failure, not as a safe "no binding" that would create
38
+
// a duplicate wallet.
39
+
WalletIDUnknownWalletIDStatus=iota
40
+
// WalletIDBound means storage holds a wallet id for the identity. WalletID is set.
41
+
WalletIDBound
42
+
// WalletIDUnbound means storage answered authoritatively that the identity has no
43
+
// wallet binding. This is a definitive, successful miss: it is safe to fall through
44
+
// to the next resolution step and, ultimately, to create a wallet.
45
+
WalletIDUnbound
46
+
// WalletIDFailed means the storage lookup itself failed (timeout, connection reset,
47
+
// ...), so whether a binding exists is UNKNOWN. Err carries the cause. Callers MUST
48
+
// NOT treat this as WalletIDUnbound: doing so lets a transient blip masquerade as an
49
+
// unregistered identity and triggers the creation of a duplicate wallet.
50
+
WalletIDFailed
51
+
)
52
+
53
+
// WalletIDResolution is the explicit result of resolving an identity to its bound
54
+
// wallet id. It is the single shared value every wallet-lookup fallback branches on,
55
+
// so the "not found" vs "could not check" distinction is decided once (in GetWalletID)
56
+
// rather than re-inferred at each call site.
57
+
typeWalletIDResolutionstruct {
58
+
// Status is the outcome of the lookup. Always inspect it via Bound/Unbound/Failed
59
+
// before reading the other fields, and branch exhaustively: any status that is
60
+
// neither Bound nor Unbound (Failed, or the WalletIDUnknown zero value) is not
61
+
// authoritative and must abort the lookup rather than fall through to creation.
62
+
StatusWalletIDStatus
63
+
// WalletID is the bound wallet id; meaningful only when Status is WalletIDBound.
64
+
WalletID idriver.WalletID
65
+
// Err is the underlying storage failure; set only when Status is WalletIDFailed.
66
+
Errerror
67
+
}
68
+
69
+
// Bound reports whether the identity has a wallet id bound to it.
r.Logger.DebugfContext(ctx, "no wallet found, there is a wallet for identity [%s]: [%s]", passedIdentity, passedWalletID)
201
+
res:=r.GetWalletID(ctx, passedIdentity)
202
+
if!res.authoritative() {
203
+
// A storage failure — or a resolution that never went through GetWalletID —
204
+
// leaves the binding unknown; it must not be treated as "not registered", or
205
+
// a transient blip would fall through to wallet creation and duplicate state.
206
+
returnnil, nil, "", res.abortError(id)
207
+
}
208
+
ifres.Bound() {
209
+
r.Logger.DebugfContext(ctx, "no wallet found, there is a wallet for identity [%s]: [%s]", passedIdentity, res.WalletID)
117
210
// we got a hit
118
211
r.WalletMu.RLock()
119
-
walletEntry, ok=r.Wallets[passedWalletID]
212
+
walletEntry, ok=r.Wallets[res.WalletID]
120
213
r.WalletMu.RUnlock()
121
214
ifok {
122
-
returnwalletEntry, nil, passedWalletID, nil
215
+
returnwalletEntry, nil, res.WalletID, nil
123
216
}
124
-
r.Logger.DebugfContext(ctx, "no wallet found, there is a wallet for identity [%s]: [%s] but it has not been recreated yet", passedIdentity, passedWalletID)
217
+
r.Logger.DebugfContext(ctx, "no wallet found, there is a wallet for identity [%s]: [%s] but it has not been recreated yet", passedIdentity, res.WalletID)
0 commit comments