-
Notifications
You must be signed in to change notification settings - Fork 43
/
persona_signer.go
52 lines (44 loc) · 1.59 KB
/
persona_signer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cardinal
import (
"errors"
"pkg.world.dev/world-engine/cardinal/persona"
)
const (
PersonaStatusUnknown = "unknown"
PersonaStatusAvailable = "available"
PersonaStatusAssigned = "assigned"
)
// PersonaSignerQueryRequest is the desired request body for the query-persona-signer endpoint.
type PersonaSignerQueryRequest struct {
PersonaTag string `json:"personaTag"`
Tick uint64 `json:"tick"`
}
// PersonaSignerQueryResponse is used as the response body for the query-persona-signer endpoint. Status can be:
// "assigned": The requested persona tag has been assigned the returned SignerAddress
// "unknown": The game tick has not advanced far enough to know what the signer address. SignerAddress will be empty.
// "available": The game tick has advanced, and no signer address has been assigned. SignerAddress will be empty.
type PersonaSignerQueryResponse struct {
Status string `json:"status"`
SignerAddress string `json:"signerAddress"`
}
func PersonaSignerQuery(wCtx WorldContext, req *PersonaSignerQueryRequest) (*PersonaSignerQueryResponse, error) {
var status string
addr, err := wCtx.getSignerForPersonaTag(req.PersonaTag, req.Tick)
if err != nil {
//nolint:gocritic // cant switch case this.
if errors.Is(err, persona.ErrPersonaTagHasNoSigner) {
status = PersonaStatusAvailable
} else if errors.Is(err, persona.ErrCreatePersonaTxsNotProcessed) {
status = PersonaStatusUnknown
} else {
return nil, err
}
} else {
status = PersonaStatusAssigned
}
res := PersonaSignerQueryResponse{
Status: status,
SignerAddress: addr,
}
return &res, nil
}