[#1400] owner: Upgrade SDK package

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-05-17 16:59:46 +03:00 committed by LeL
parent f8ac4632f8
commit bb25ecbd15
60 changed files with 379 additions and 327 deletions

View file

@ -10,8 +10,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/owner"
"github.com/nspcc-dev/neofs-sdk-go/session"
"github.com/nspcc-dev/neofs-sdk-go/user"
)
var (
@ -21,7 +21,7 @@ var (
)
type ownerIDSource interface {
OwnerID() *owner.ID
OwnerID() *user.ID
}
func tokenFromEvent(src interface {
@ -52,7 +52,15 @@ func (cp *Processor) checkKeyOwnership(ownerIDSrc ownerIDSource, key *keys.Publi
}
}
if ownerIDSrc.OwnerID().Equal(owner.NewIDFromPublicKey((*ecdsa.PublicKey)(key))) {
ownerSrc := ownerIDSrc.OwnerID()
if ownerSrc == nil {
return errors.New("missing owner")
}
var ownerKey user.ID
user.IDFromKey(&ownerKey, (ecdsa.PublicKey)(*key))
if ownerSrc.Equals(ownerKey) {
return nil
}
@ -82,8 +90,10 @@ func (cp *Processor) checkKeyOwnershipWithToken(ownerIDSrc ownerIDSource, key *k
return errors.New("signed with a non-session key")
}
ownerToken, ownerSrc := token.OwnerID(), ownerIDSrc.OwnerID()
// check owner
if !token.OwnerID().Equal(ownerIDSrc.OwnerID()) {
if ownerToken == nil || ownerSrc == nil || !ownerToken.Equals(*ownerSrc) {
return errors.New("owner differs with token owner")
}

View file

@ -286,6 +286,11 @@ func checkNNS(ctx *putContainerContext, cnr *containerSDK.Container) error {
}
func checkSubnet(subCli *morphsubnet.Client, cnr *containerSDK.Container) error {
owner := cnr.OwnerID()
if owner == nil {
return errors.New("missing owner")
}
prm := morphsubnet.UserAllowedPrm{}
subID := cnr.PlacementPolicy().SubnetID()
@ -298,13 +303,8 @@ func checkSubnet(subCli *morphsubnet.Client, cnr *containerSDK.Container) error
return fmt.Errorf("could not marshal container subnetwork: %w", err)
}
ownerID, err := cnr.OwnerID().Marshal()
if err != nil {
return fmt.Errorf("could not marshal container ownerID: %w", err)
}
prm.SetID(rawSubID)
prm.SetClient(ownerID)
prm.SetClient(owner.WalletBytes())
res, err := subCli.UserAllowed(prm)
if err != nil {

View file

@ -8,7 +8,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
"github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs"
"github.com/nspcc-dev/neofs-sdk-go/owner"
"github.com/nspcc-dev/neofs-sdk-go/user"
"go.uber.org/zap"
)
@ -84,8 +84,11 @@ func (np *Processor) approveBindCommon(e *bindCommonContext) {
return
}
var id user.ID
id.SetScriptHash(u160)
prm := neofsid.CommonBindPrm{}
prm.SetOwnerID(owner.ScriptHashToIDBytes(u160))
prm.SetOwnerID(id.WalletBytes())
prm.SetKeys(e.Keys())
prm.SetHash(e.bindCommon.TxHash())

View file

@ -14,7 +14,7 @@ import (
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/owner"
"github.com/nspcc-dev/neofs-sdk-go/user"
"go.uber.org/zap"
)
@ -323,11 +323,14 @@ func (c *singleResultCtx) auditEpoch() uint64 {
return c.eAudit
}
func ownerFromKey(key []byte) (*owner.ID, error) {
func ownerFromKey(key []byte) (*user.ID, error) {
pubKey, err := keys.NewPublicKeyFromBytes(key, elliptic.P256())
if err != nil {
return nil, err
}
return owner.NewIDFromPublicKey((*ecdsa.PublicKey)(pubKey)), nil
var id user.ID
user.IDFromKey(&id, (ecdsa.PublicKey)(*pubKey))
return &id, nil
}

View file

@ -65,7 +65,7 @@ func (inc *IncomeSettlementContext) Collect() {
txTable.Transfer(&common.TransferTx{
From: owner.Owner(),
To: inc.bankOwner,
To: &inc.bankOwner,
Amount: total,
})
}

View file

@ -7,7 +7,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/common"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
"github.com/nspcc-dev/neofs-sdk-go/owner"
"github.com/nspcc-dev/neofs-sdk-go/user"
"go.uber.org/zap"
)
@ -22,7 +22,7 @@ type (
// BalanceFetcher uses NEP-17 compatible balance contract
BalanceFetcher interface {
Balance(id *owner.ID) (*big.Int, error)
Balance(id *user.ID) (*big.Int, error)
}
IncomeSettlementContext struct {
@ -39,7 +39,7 @@ type (
exchange common.Exchanger
accounts common.AccountStorage
bankOwner *owner.ID
bankOwner user.ID
// this table is not thread safe, make sure you use it with mu.Lock()
distributeTable *NodeSizeTable
@ -58,11 +58,8 @@ type (
}
)
func NewIncomeSettlementContext(p *IncomeSettlementContextPrms) (*IncomeSettlementContext, error) {
bankingAccount := owner.NewID()
bankingAccount.SetScriptHash(util.Uint160{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})
return &IncomeSettlementContext{
func NewIncomeSettlementContext(p *IncomeSettlementContextPrms) *IncomeSettlementContext {
res := &IncomeSettlementContext{
log: p.Log,
epoch: p.Epoch,
rate: p.Rate,
@ -72,7 +69,10 @@ func NewIncomeSettlementContext(p *IncomeSettlementContextPrms) (*IncomeSettleme
placement: p.Placement,
exchange: p.Exchange,
accounts: p.Accounts,
bankOwner: bankingAccount,
distributeTable: NewNodeSizeTable(),
}, nil
}
res.bankOwner.SetScriptHash(util.Uint160{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})
return res
}

View file

@ -14,7 +14,7 @@ func (inc *IncomeSettlementContext) Distribute() {
txTable := common.NewTransferTable()
bankBalance, err := inc.balances.Balance(inc.bankOwner)
bankBalance, err := inc.balances.Balance(&inc.bankOwner)
if err != nil {
inc.log.Error("can't fetch balance of banking account",
zap.String("error", err.Error()))
@ -35,7 +35,7 @@ func (inc *IncomeSettlementContext) Distribute() {
}
txTable.Transfer(&common.TransferTx{
From: inc.bankOwner,
From: &inc.bankOwner,
To: nodeOwner,
Amount: normalizedValue(n, total, bankBalance),
})

View file

@ -4,7 +4,7 @@ import (
"math/big"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/owner"
"github.com/nspcc-dev/neofs-sdk-go/user"
)
// NodeInfo groups the data about the storage node
@ -21,7 +21,7 @@ type NodeInfo interface {
// necessary for calculating audit fee.
type ContainerInfo interface {
// Must return identifier of the container owner.
Owner() *owner.ID
Owner() *user.ID
}
// ContainerStorage is an interface of
@ -42,7 +42,7 @@ type PlacementCalculator interface {
type AccountStorage interface {
// Must resolve information about the storage node
// to its ID in system.
ResolveKey(NodeInfo) (*owner.ID, error)
ResolveKey(NodeInfo) (*user.ID, error)
}
// Exchanger is an interface of monetary component.
@ -50,5 +50,5 @@ type Exchanger interface {
// Must transfer amount of GASe-12 from sender to recipient.
//
// Amount must be positive.
Transfer(sender, recipient *owner.ID, amount *big.Int, details []byte)
Transfer(sender, recipient *user.ID, amount *big.Int, details []byte)
}

View file

@ -3,7 +3,7 @@ package common
import (
"math/big"
"github.com/nspcc-dev/neofs-sdk-go/owner"
"github.com/nspcc-dev/neofs-sdk-go/user"
)
type TransferTable struct {
@ -11,7 +11,7 @@ type TransferTable struct {
}
type TransferTx struct {
From, To *owner.ID
From, To *user.ID
Amount *big.Int
}
@ -23,7 +23,7 @@ func NewTransferTable() *TransferTable {
}
func (t *TransferTable) Transfer(tx *TransferTx) {
if tx.From.Equal(tx.To) {
if tx.From.Equals(*tx.To) {
return
}

View file

@ -4,9 +4,9 @@ import (
"errors"
"fmt"
"github.com/nspcc-dev/neofs-sdk-go/owner"
"github.com/nspcc-dev/neofs-sdk-go/subnet"
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
"github.com/nspcc-dev/neofs-sdk-go/user"
)
// Put represents a notification about NeoFS subnet creation.
@ -17,7 +17,7 @@ type Put interface {
// ReadCreator reads the user ID of the subnet creator.
// Returns an error if the ID is missing.
ReadCreator(id *owner.ID) error
ReadCreator(id *user.ID) error
// ReadInfo reads information about a subnet to be created.
ReadInfo(info *subnet.Info) error
@ -57,7 +57,7 @@ func (x PutValidator) Assert(event Put) error {
}
// read creator's user ID in NeoFS system
var creator owner.ID
var creator user.ID
if err = event.ReadCreator(&creator); err != nil {
return fmt.Errorf("read creator: %w", err)
}

View file

@ -4,10 +4,10 @@ import (
"errors"
"testing"
ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test"
"github.com/nspcc-dev/neofs-sdk-go/user"
usertest "github.com/nspcc-dev/neofs-sdk-go/user/test"
"github.com/stretchr/testify/require"
"github.com/nspcc-dev/neofs-sdk-go/owner"
"github.com/nspcc-dev/neofs-sdk-go/subnet"
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
)
@ -15,7 +15,7 @@ import (
type put struct {
idEvent
creator owner.ID
creator user.ID
creatorErr error
@ -24,7 +24,7 @@ type put struct {
infoErr error
}
func (x put) ReadCreator(id *owner.ID) error {
func (x put) ReadCreator(id *user.ID) error {
if x.creatorErr != nil {
return x.creatorErr
}
@ -99,9 +99,7 @@ func TestPutValidator_Assert(t *testing.T) {
e.info.SetID(e.id)
// diff explicit creator and the one in info
var creator2 owner.ID
creator2 = *ownertest.ID()
creator2 := *usertest.ID()
e.info.SetOwner(creator2)