Skip to content

Commit

Permalink
Add prefix to namespace (#297)
Browse files Browse the repository at this point in the history
## tl;dr

- Add prefix to namespace

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced error messages for namespace validation to include the
invalid input.
	- Updated output format of the namespace to include a "xmtpd-" prefix.

- **Bug Fixes**
	- Improved clarity of error messages related to namespace validation.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
neekolas authored Dec 2, 2024
1 parent a50c51e commit 906ba3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/db/pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func isValidNamespace(namespace string) error {
// PostgreSQL identifiers must start with a letter or underscore
if !allowedNamespaceRe.MatchString(namespace) {
return fmt.Errorf(
"namespace must start with a letter or underscore and contain only letters, numbers, and underscores",
"namespace must start with a letter or underscore and contain only letters, numbers, and underscores. Instead is %s",
namespace,
)
}
return nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/utils/namespace.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package utils

import (
"fmt"

ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/xmtp/xmtpd/pkg/config"
)
Expand All @@ -11,5 +13,5 @@ func BuildNamespace(options config.ServerOptions) string {
[]byte(options.Contracts.NodesContractAddress),
)

return HexEncode(hash)[:12]
return fmt.Sprintf("xmtpd_%s", HexEncode(hash)[:12])
}

0 comments on commit 906ba3f

Please sign in to comment.