status-im / status-console-client

Status messaging console user interface
Mozilla Public License 2.0
10 stars 2 forks source link

Move SQL serialization of ECDSA Public Key in Contact struct #45

Open adambabik opened 5 years ago

adambabik commented 5 years ago

The idea is to implement a custom type and SQL serializer:

type ECDSAPublicKeySQL ecdsa.PublicKey

func (k *ECDSAPublicKeySQL) Scan(src interface{}) error {
// ...
}

The value can be either assigned to Contact like this:

h.Contact.PublicKey = pubKey.ECDSAPublicKey()

or it can be a separate field and getting the ECDSA Public Key struct will be done through a method:

type Contact struct {
publicKey *ECDSAPublicKeySQL
}

func (c Contact) PublicKey() *ecdsa.PublicKey {
pk := ecdsa.PublicKey(*c.publicKey)
return &pk
}

h.Contact.ECDSAPublicKey()

The latter approach is less appealing in this case because for Contact struct we only use fields for now so we end up with collecting some values as fields and one using a method.