11package container
22
33import (
4+ "context"
45 "fmt"
56
6- "github.com/nspcc-dev/neofs-node/pkg/morph/client"
77 fschaincontracts "github.com/nspcc-dev/neofs-node/pkg/morph/contracts"
88 "github.com/nspcc-dev/neofs-sdk-go/container"
99 cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
@@ -15,8 +15,6 @@ type PutPrm struct {
1515 key []byte
1616 sig []byte
1717 token []byte
18-
19- client.InvokePrmOptional
2018}
2119
2220// SetContainer sets container.
@@ -39,47 +37,42 @@ func (p *PutPrm) SetToken(token []byte) {
3937 p .token = token
4038}
4139
42- // Put saves container with its session token, key and signature
43- // in NeoFS system through Container contract call.
40+ // Put calls Container contract to create container with parameterized
41+ // credentials. If transaction is accepted for processing, Put waits for it to
42+ // be successfully executed. Waiting is performed within ctx,
43+ // [client.ErrTxAwaitTimeout] is returned when it is done.
4444//
4545// Returns calculated container identifier and any error
4646// encountered that caused the saving to interrupt.
47- func (c * Client ) Put (p PutPrm ) (cid.ID , error ) {
47+ func (c * Client ) Put (ctx context. Context , p PutPrm ) (cid.ID , error ) {
4848 if len (p .sig ) == 0 || len (p .key ) == 0 {
4949 return cid.ID {}, errNilArgument
5050 }
5151
52- var prm client.InvokePrm
53- prm .SetMethod (fschaincontracts .CreateContainerV2Method )
54- prm .InvokePrmOptional = p .InvokePrmOptional
55- prm .SetArgs (containerToStackItem (p .cnr ), p .sig , p .key , p .token )
56-
57- // no magic bugs with notary requests anymore, this operation should
58- // _always_ be notary signed so make it one more time even if it is
59- // a repeated flag setting
60- prm .RequireAlphabetSignature ()
61-
62- err := c .client .Invoke (prm )
52+ err := c .client .CallWithAlphabetWitness (ctx , fschaincontracts .CreateContainerV2Method , []any {
53+ containerToStackItem (p .cnr ), p .sig , p .key , p .token ,
54+ })
6355 if err == nil {
6456 return cid .NewFromMarshalledContainer (p .cnr .Marshal ()), nil
6557 }
6658 if ! isMethodNotFoundError (err , fschaincontracts .CreateContainerV2Method ) {
6759 return cid.ID {}, fmt .Errorf ("could not invoke method (%s): %w" , fschaincontracts .CreateContainerV2Method , err )
6860 }
6961
70- prm .SetMethod (fschaincontracts .CreateContainerMethod )
71-
7262 domain := p .cnr .ReadDomain ()
7363 metaAttr := p .cnr .Attribute ("__NEOFS__METAINFO_CONSISTENCY" )
7464 metaEnabled := metaAttr == "optimistic" || metaAttr == "strict"
7565 cnrBytes := p .cnr .Marshal ()
76- prm .SetArgs (cnrBytes , p .sig , p .key , p .token , domain .Name (), domain .Zone (), metaEnabled )
7766
78- err = c .client .Invoke (prm )
67+ err = c .client .CallWithAlphabetWitness (ctx , fschaincontracts .CreateContainerMethod , []any {
68+ cnrBytes , p .sig , p .key , p .token , domain .Name (), domain .Zone (), metaEnabled ,
69+ })
7970 if err != nil {
8071 if isMethodNotFoundError (err , fschaincontracts .CreateContainerMethod ) {
81- prm .SetMethod (putMethod )
82- if err = c .client .Invoke (prm ); err != nil {
72+ err = c .client .CallWithAlphabetWitness (ctx , putMethod , []any {
73+ cnrBytes , p .sig , p .key , p .token , domain .Name (), domain .Zone (), metaEnabled ,
74+ })
75+ if err != nil {
8376 return cid.ID {}, fmt .Errorf ("could not invoke method (%s): %w" , putMethod , err )
8477 }
8578 return cid .NewFromMarshalledContainer (cnrBytes ), nil
0 commit comments