Skip to content

Commit 2736003

Browse files
committed
sn/container: Refactor Client.Put() method input
This will make it easier to support nspcc-dev/neofs-contract#534. Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
1 parent de788f5 commit 2736003

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

cmd/neofs-node/container.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,20 +385,13 @@ func (x *containersInChain) List(id user.ID) ([]cid.ID, error) {
385385
}
386386

387387
func (x *containersInChain) Put(cnr containerSDK.Container, pub, sig []byte, st *session.Container) (cid.ID, error) {
388-
d := cnr.ReadDomain()
389-
390388
var prm cntClient.PutPrm
391-
prm.SetContainer(cnr.Marshal())
392-
prm.SetName(d.Name())
393-
prm.SetZone(d.Zone())
389+
prm.SetContainer(cnr)
394390
prm.SetKey(pub)
395391
prm.SetSignature(sig)
396392
if st != nil {
397393
prm.SetToken(st.Marshal())
398394
}
399-
if v := cnr.Attribute("__NEOFS__METAINFO_CONSISTENCY"); v == "optimistic" || v == "strict" {
400-
prm.EnableMeta()
401-
}
402395

403396
return x.cCli.Put(prm)
404397
}

pkg/morph/client/container/put.go

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@ import (
55

66
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
77
fschaincontracts "github.com/nspcc-dev/neofs-node/pkg/morph/contracts"
8+
"github.com/nspcc-dev/neofs-sdk-go/container"
89
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
910
)
1011

1112
// PutPrm groups parameters of Put operation.
1213
type PutPrm struct {
13-
cnr []byte
14-
key []byte
15-
sig []byte
16-
token []byte
17-
name string
18-
zone string
19-
enableMetaOnChain bool
14+
cnr container.Container
15+
key []byte
16+
sig []byte
17+
token []byte
2018

2119
client.InvokePrmOptional
2220
}
2321

24-
// SetContainer sets container data.
25-
func (p *PutPrm) SetContainer(cnr []byte) {
22+
// SetContainer sets container.
23+
func (p *PutPrm) SetContainer(cnr container.Container) {
2624
p.cnr = cnr
2725
}
2826

@@ -41,22 +39,7 @@ func (p *PutPrm) SetToken(token []byte) {
4139
p.token = token
4240
}
4341

44-
// SetName sets native name.
45-
func (p *PutPrm) SetName(name string) {
46-
p.name = name
47-
}
48-
49-
// SetZone sets zone.
50-
func (p *PutPrm) SetZone(zone string) {
51-
p.zone = zone
52-
}
53-
54-
// EnableMeta enables meta-on-chain.
55-
func (p *PutPrm) EnableMeta() {
56-
p.enableMetaOnChain = true
57-
}
58-
59-
// Put saves binary container with its session token, key and signature
42+
// Put saves container with its session token, key and signature
6043
// in NeoFS system through Container contract call.
6144
//
6245
// Returns calculated container identifier and any error
@@ -69,7 +52,12 @@ func (c *Client) Put(p PutPrm) (cid.ID, error) {
6952
var prm client.InvokePrm
7053
prm.SetMethod(fschaincontracts.CreateContainerMethod)
7154
prm.InvokePrmOptional = p.InvokePrmOptional
72-
prm.SetArgs(p.cnr, p.sig, p.key, p.token, p.name, p.zone, p.enableMetaOnChain)
55+
56+
domain := p.cnr.ReadDomain()
57+
metaAttr := p.cnr.Attribute("__NEOFS__METAINFO_CONSISTENCY")
58+
metaEnabled := metaAttr == "optimistic" || metaAttr == "strict"
59+
cnrBytes := p.cnr.Marshal()
60+
prm.SetArgs(cnrBytes, p.sig, p.key, p.token, domain.Name(), domain.Zone(), metaEnabled)
7361

7462
// no magic bugs with notary requests anymore, this operation should
7563
// _always_ be notary signed so make it one more time even if it is
@@ -83,9 +71,9 @@ func (c *Client) Put(p PutPrm) (cid.ID, error) {
8371
if err = c.client.Invoke(prm); err != nil {
8472
return cid.ID{}, fmt.Errorf("could not invoke method (%s): %w", putMethod, err)
8573
}
86-
return cid.NewFromMarshalledContainer(p.cnr), nil
74+
return cid.NewFromMarshalledContainer(cnrBytes), nil
8775
}
8876
return cid.ID{}, fmt.Errorf("could not invoke method (%s): %w", fschaincontracts.CreateContainerMethod, err)
8977
}
90-
return cid.NewFromMarshalledContainer(p.cnr), nil
78+
return cid.NewFromMarshalledContainer(cnrBytes), nil
9179
}

0 commit comments

Comments
 (0)