fix encoding and decoding of event "extra" fields.

fixes https://github.com/nbd-wtf/go-nostr/issues/31
This commit is contained in:
fiatjaf
2023-01-03 14:46:50 -03:00
parent 4a62a753e6
commit 3349b2a52b
3 changed files with 63 additions and 5 deletions

View File

@@ -36,11 +36,17 @@ func (evt Event) GetExtraNumber(key string) float64 {
if !ok {
return 0
}
val, ok := ival.(float64)
if !ok {
return 0
switch val := ival.(type) {
case float64:
return val
case int:
return float64(val)
case int64:
return float64(val)
}
return val
return 0
}
// GetExtraBoolean is like [Event.GetExtra], but only works if the value is a boolean,