mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-26 00:31:14 +02:00
nip19: helper for building nevent from RelayEvent.
This commit is contained in:
parent
1b31dd892e
commit
f19efb4013
34
nip19/helpers.go
Normal file
34
nip19/helpers.go
Normal file
@ -0,0 +1,34 @@
|
||||
package nip19
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
)
|
||||
|
||||
const (
|
||||
TLVDefault uint8 = 0
|
||||
TLVRelay uint8 = 1
|
||||
TLVAuthor uint8 = 2
|
||||
TLVKind uint8 = 3
|
||||
)
|
||||
|
||||
func readTLVEntry(data []byte) (typ uint8, value []byte) {
|
||||
if len(data) < 2 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
typ = data[0]
|
||||
length := int(data[1])
|
||||
if len(data) < 2+length {
|
||||
return typ, nil
|
||||
}
|
||||
|
||||
value = data[2 : 2+length]
|
||||
return
|
||||
}
|
||||
|
||||
func writeTLVEntry(buf *bytes.Buffer, typ uint8, value []byte) {
|
||||
length := len(value)
|
||||
buf.WriteByte(typ)
|
||||
buf.WriteByte(uint8(length))
|
||||
buf.Write(value)
|
||||
}
|
@ -1,34 +1,8 @@
|
||||
package nip19
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
)
|
||||
import "github.com/nbd-wtf/go-nostr"
|
||||
|
||||
const (
|
||||
TLVDefault uint8 = 0
|
||||
TLVRelay uint8 = 1
|
||||
TLVAuthor uint8 = 2
|
||||
TLVKind uint8 = 3
|
||||
)
|
||||
|
||||
func readTLVEntry(data []byte) (typ uint8, value []byte) {
|
||||
if len(data) < 2 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
typ = data[0]
|
||||
length := int(data[1])
|
||||
if len(data) < 2+length {
|
||||
return typ, nil
|
||||
}
|
||||
|
||||
value = data[2 : 2+length]
|
||||
return
|
||||
}
|
||||
|
||||
func writeTLVEntry(buf *bytes.Buffer, typ uint8, value []byte) {
|
||||
length := len(value)
|
||||
buf.WriteByte(typ)
|
||||
buf.WriteByte(uint8(length))
|
||||
buf.Write(value)
|
||||
func NeventFromRelayEvent(ie nostr.RelayEvent) string {
|
||||
v, _ := EncodeEvent(ie.ID, []string{ie.Relay.URL}, ie.PubKey)
|
||||
return v
|
||||
}
|
||||
|
4
pool.go
4
pool.go
@ -46,9 +46,7 @@ type RelayEvent struct {
|
||||
Relay *Relay
|
||||
}
|
||||
|
||||
func (ie RelayEvent) String() string {
|
||||
return fmt.Sprintf("[%s] >> %s", ie.Relay.URL, ie.Event)
|
||||
}
|
||||
func (ie RelayEvent) String() string { return fmt.Sprintf("[%s] >> %s", ie.Relay.URL, ie.Event) }
|
||||
|
||||
type PoolOption interface {
|
||||
ApplyPoolOption(*SimplePool)
|
||||
|
Loading…
x
Reference in New Issue
Block a user