Заимплементил Set в интеграции #4

Merged
glebus merged 2 commits from integration-3 into master 2024-01-14 15:56:59 +00:00

View file

@ -23,9 +23,9 @@ import (
type IBlockchainStorage interface {
GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error) // read
Set(id string, cli oauth2.ClientInfo) (err error) // create and update
Delete(id string) (err error) // delete
CheckPassword(id string, secret util.Uint256) (bool, error) // CheckUser
Set(clt oauth2.ClientInfo) error // create and update
Delete(id string) error // delete
CheckPassword(id string, secret string) (bool, error) // CheckUser
}
type BlockchainStorage struct {
@ -33,8 +33,8 @@ type BlockchainStorage struct {
}
type StorageClientInfo struct {
login string
password util.Uint256
id string
secret string
}
func NewBlockchainStorage(actor Actor, hash util.Uint160) *BlockchainStorage {
@ -47,21 +47,40 @@ func (storage BlockchainStorage) GetByID(ctx context.Context, id string) (oauth2
return nil, err
}
return &StorageClientInfo{login: id, password: password}, nil
return &StorageClientInfo{id: id, secret: password.StringLE()}, nil
}
func (storage BlockchainStorage) Set(id string, cli oauth2.ClientInfo) (err error) {
// how to check whether user exists? (util.Uint256 conversion)
func (storage BlockchainStorage) Set(clt oauth2.ClientInfo) error {
password, decodeErr := util.Uint256DecodeStringLE(clt.GetSecret())
if decodeErr != nil {
return decodeErr
}
_, _, err := storage.contract.UpdateUser(clt.GetID(), password)
if err != nil {
_, _, err = storage.contract.CreateUser(clt.GetID(), password)
if err != nil {
return errors.New("Something went wrong")
}
}
return nil
}
func (storage BlockchainStorage) Delete(id string) (err error) {
// how to use hash and ValidUntilBlock?
_, _, err = storage.contract.DeleteUser(id)
return err
func (storage BlockchainStorage) Delete(id string) error {
// should we use hash and ValidUntilBlock?
_, _, res := storage.contract.DeleteUser(id)
return res
}
func (storage BlockchainStorage) CheckPassword(id string, secret util.Uint256) (bool, error) {
_, err := storage.contract.CheckUser(id, secret)
func (storage BlockchainStorage) CheckPassword(id string, secret string) (bool, error) {
password, decodeErr := util.Uint256DecodeStringLE(secret)
if decodeErr != nil {
return false, decodeErr
}
_, err := storage.contract.CheckUser(id, password)
if err != nil {
return false, err
}
@ -70,11 +89,11 @@ func (storage BlockchainStorage) CheckPassword(id string, secret util.Uint256) (
}
func (model StorageClientInfo) GetID() string {
return model.login
return model.id
}
func (model StorageClientInfo) GetSecret() string {
return model.password.String()
return model.secret
}
func (model StorageClientInfo) GetDomain() string {