Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Using a sql.NullString for username
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Apr 6, 2022
1 parent b0fa955 commit 9bb9663
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
15 changes: 8 additions & 7 deletions model_paymails.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bux

import (
"context"
"database/sql"
"errors"

"github.com/BuxOrg/bux/datastore"
Expand All @@ -21,13 +22,13 @@ type PaymailAddress struct {
Model `bson:",inline"`

// Model specific fields
ID string `json:"id" toml:"id" yaml:"id" gorm:"<-:create;type:char(64);primaryKey;comment:This is the unique paymail record id" bson:"_id"` // Unique identifier
XpubID string `json:"xpub_id" toml:"xpub_id" yaml:"xpub_id" gorm:"<-:create;type:char(64);index;comment:This is the related xPub" bson:"xpub_id"` // Related xPub ID
Alias string `json:"alias" toml:"alias" yaml:"alias" gorm:"<-;type:varchar(64);comment:This is alias@" bson:"alias"` // Alias part of the paymail
Domain string `json:"domain" toml:"domain" yaml:"domain" gorm:"<-;type:varchar(255);comment:This is @domain.com" bson:"domain"` // Domain of the paymail
Username string `json:"username" toml:"username" yaml:"username" gorm:"<-;type:varchar(255);uniqueIndex;comment:This is username" bson:"username"` // Full username
Avatar string `json:"avatar" toml:"avatar" yaml:"avatar" gorm:"<-;type:text;comment:This is avatar url" bson:"avatar"` // This is the url of the user (public profile)
ExternalXpubKey string `json:"external_xpub_key" toml:"external_xpub_key" yaml:"external_xpub_key" gorm:"<-:create;type:varchar(512);index;comment:This is full xPub for external use, encryption optional" bson:"external_xpub_key"` // PublicKey hex encoded
ID string `json:"id" toml:"id" yaml:"id" gorm:"<-:create;type:char(64);primaryKey;comment:This is the unique paymail record id" bson:"_id"` // Unique identifier
XpubID string `json:"xpub_id" toml:"xpub_id" yaml:"xpub_id" gorm:"<-:create;type:char(64);index;comment:This is the related xPub" bson:"xpub_id"` // Related xPub ID
Alias string `json:"alias" toml:"alias" yaml:"alias" gorm:"<-;type:varchar(64);comment:This is alias@" bson:"alias"` // Alias part of the paymail
Domain string `json:"domain" toml:"domain" yaml:"domain" gorm:"<-;type:varchar(255);comment:This is @domain.com" bson:"domain"` // Domain of the paymail
Username sql.NullString `json:"username" toml:"username" yaml:"username" gorm:"<-;type:varchar(255);uniqueIndex;comment:This is username" bson:"username"` // Full username
Avatar string `json:"avatar" toml:"avatar" yaml:"avatar" gorm:"<-;type:text;comment:This is avatar url" bson:"avatar"` // This is the url of the user (public profile)
ExternalXpubKey string `json:"external_xpub_key" toml:"external_xpub_key" yaml:"external_xpub_key" gorm:"<-:create;type:varchar(512);index;comment:This is full xPub for external use, encryption optional" bson:"external_xpub_key"` // PublicKey hex encoded

// Private fields
externalXpubKeyDecrypted string
Expand Down
5 changes: 3 additions & 2 deletions model_paymails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func TestNewPaymail(t *testing.T) {
WithXPub(testXpub),
WithEncryptionKey(testEncryption),
)
p.Username = "Tester"
p.Username.String = "Tester"
p.Username.Valid = true
p.Avatar = "img url"
err = p.Save(ctx)
require.NoError(t, err)
Expand All @@ -70,7 +71,7 @@ func TestNewPaymail(t *testing.T) {
require.NotNil(t, identityKey)

assert.Equal(t, paymail, p2.Alias+"@"+p2.Domain)
assert.Equal(t, "Tester", p2.Username)
assert.Equal(t, "Tester", p2.Username.String)
assert.Equal(t, "img url", p2.Avatar)
assert.Equal(t, "d8c2bed524071d72d859caf90da5f448b5861cd4d4fd47697f94166c13c5a987", p2.XpubID)
assert.Equal(t, paymailIdentityXPub, identityKey.String())
Expand Down
2 changes: 1 addition & 1 deletion paymail_service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (p *PaymailDefaultServiceProvider) GetPaymailByAlias(ctx context.Context, a
Domain: paymailAddress.Domain,
ID: paymailAddress.ID,
LastAddress: destination.Address,
Name: paymailAddress.Username,
Name: paymailAddress.Username.String,
PubKey: pubKey,
}, nil
}
Expand Down

0 comments on commit 9bb9663

Please sign in to comment.