-
Notifications
You must be signed in to change notification settings - Fork 50
Support setAttribute container contract method #3728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -179,6 +179,10 @@ func (cp *Processor) ListenerNotaryParsers() []event.NotaryParserInfo { | |||||||
| p.SetRequestType(fschaincontracts.AddContainerStructsMethod) | ||||||||
| p.SetParser(containerEvent.RestoreAddStructsRequest) | ||||||||
|
|
||||||||
| // set attribute | ||||||||
| p.SetRequestType(containerEvent.SetAttributeNotaryEvent) | ||||||||
| p.SetParser(containerEvent.ParseSetAttribute) | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| return pp | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -240,6 +244,11 @@ func (cp *Processor) ListenerNotaryHandlers() []event.NotaryHandlerInfo { | |||||||
| h.SetHandler(cp.handleObjectPut) | ||||||||
| hh = append(hh, h) | ||||||||
|
|
||||||||
| // container setAttribute | ||||||||
| h.SetRequestType(containerEvent.SetAttributeNotaryEvent) | ||||||||
| h.SetHandler(cp.handleSetAttribute) | ||||||||
| hh = append(hh, h) | ||||||||
|
|
||||||||
| // migrate protobuf->struct | ||||||||
| h.SetRequestType(fschaincontracts.AddContainerStructsMethod) | ||||||||
| h.SetHandler(func(ev event.Event) { | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||
| package container | ||||||
|
|
||||||
| import ( | ||||||
| "github.com/nspcc-dev/neo-go/pkg/network/payload" | ||||||
| "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" | ||||||
| "github.com/nspcc-dev/neofs-node/pkg/morph/event" | ||||||
| ) | ||||||
|
|
||||||
| const ( | ||||||
| // SetAttributeNotaryEvent is method name for setAttribute operations in `Container` contract. | ||||||
| SetAttributeNotaryEvent = "setAttribute" | ||||||
| ) | ||||||
|
|
||||||
| // SetAttribute represents structure of notification about modified container attributes | ||||||
| // coming from NeoFS Container contract. | ||||||
| type SetAttribute struct { | ||||||
| CID []byte | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can validate it there. currently, any size of CID and any token can be signed by the alphabet and sent to the contract |
||||||
| Name []byte | ||||||
| Value []byte | ||||||
| Token []byte | ||||||
|
|
||||||
| // For notary notifications only. | ||||||
| // Contains raw transactions of notary request. | ||||||
| NotaryRequest *payload.P2PNotaryRequest | ||||||
| } | ||||||
|
|
||||||
| // MorphEvent implements [event.Event]. | ||||||
| func (r SetAttribute) MorphEvent() {} | ||||||
|
|
||||||
| // ParseSetAttribute from NotaryEvent into container event structure. | ||||||
| func ParseSetAttribute(ne event.NotaryEvent) (event.Event, error) { | ||||||
| const expectedItemNumAnnounceLoad = 4 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| args, err := getArgsFromEvent(ne, expectedItemNumAnnounceLoad) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| var ev SetAttribute | ||||||
|
|
||||||
| ev.Token, err = getValueFromArg(args, 0, "session token", stackitem.ByteArrayT, event.BytesFromOpcode) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| ev.Value, err = getValueFromArg(args, 1, "attribute value", stackitem.ByteArrayT, event.BytesFromOpcode) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| ev.Name, err = getValueFromArg(args, 2, "attribute name", stackitem.ByteArrayT, event.BytesFromOpcode) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| ev.CID, err = getValueFromArg(args, 3, "container ID", stackitem.ByteArrayT, event.BytesFromOpcode) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| ev.NotaryRequest = ne.Raw() | ||||||
|
|
||||||
| return ev, nil | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so 3rd party can add attribute to my container w/o my approval?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no. I consider, we will check this with token parameter inside contact setAttribute, when it be done in contracts