implement GetByID

This commit is contained in:
regnersen 2024-01-14 19:14:19 +07:00
parent b3d38cabb9
commit c35638d36d
2 changed files with 44 additions and 0 deletions

View file

@ -31,10 +31,28 @@ type BlockchainStorage struct {
contract *Contract
}
type StorageClientInfo struct {
login string
password util.Uint256
}
func NewBlockchainStorage(actor Actor, hash util.Uint160) *BlockchainStorage {
return &BlockchainStorage{contract: New(actor, hash)}
}
func (storage BlockchainStorage) GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error) {
password, err := storage.contract.GetUser(id)
if err != nil {
return nil, err
}
return &StorageClientInfo{login: id, password: password}, nil
}
func (storage BlockchainStorage) Set(id string, cli oauth2.ClientInfo) (err error) {
// how to check whether user exists? (util.Uint256 conversion)
}
func (storage BlockchainStorage) Delete(id string) (err error) {
// how to use hash and ValidUntilBlock?
_, _, err = storage.contract.DeleteUser(id)
@ -50,6 +68,26 @@ func (storage BlockchainStorage) CheckPassword(id string, secret util.Uint256) (
return true, nil
}
func (model StorageClientInfo) GetID() string {
return model.login
}
func (model StorageClientInfo) GetSecret() string {
return model.password.String()
}
func (model StorageClientInfo) GetDomain() string {
// implement as in-memory
}
func (model StorageClientInfo) IsPublic() bool {
// implement as in-memory
}
func (model StorageClientInfo) GetUserID() string {
// implement as in-memory
}
func main() {
manager := manage.NewDefaultManager()
manager.SetAuthorizeCodeTokenCfg(manage.DefaultAuthorizeCodeTokenCfg)

View file

@ -6,6 +6,7 @@ package main
import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
"github.com/nspcc-dev/neo-go/pkg/util"
)
@ -54,6 +55,11 @@ func (c *ContractReader) CheckUser(login string, givenPassword util.Uint256) (*r
c.invoker.Call(c.hash, "checkUser", login, givenPassword)
}
// GetUser invokes `getUser` method of contract.
func (c *ContractReader) GetUser(login string) (util.Uint256, error) {
return unwrap.Uint256(c.invoker.Call(c.hash, "getUser", login))
}
// CreateUser creates a transaction invoking `createUser` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.