2021-08-25 11:29:58 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (p *Put) setRawContainer(v []byte) {
|
|
|
|
if v != nil {
|
|
|
|
p.rawContainer = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Put) setSignature(v []byte) {
|
|
|
|
if v != nil {
|
|
|
|
p.signature = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Put) setPublicKey(v []byte) {
|
|
|
|
if v != nil {
|
|
|
|
p.publicKey = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Put) setToken(v []byte) {
|
|
|
|
if v != nil {
|
|
|
|
p.token = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var fieldSetters = []func(*Put, []byte){
|
|
|
|
// order on stack is reversed
|
|
|
|
(*Put).setToken,
|
|
|
|
(*Put).setPublicKey,
|
|
|
|
(*Put).setSignature,
|
|
|
|
(*Put).setRawContainer,
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
// PutNotaryEvent is method name for container put operations
|
|
|
|
// in `Container` contract. Is used as identificator for notary
|
|
|
|
// put container requests.
|
|
|
|
PutNotaryEvent = "put"
|
|
|
|
)
|
|
|
|
|
|
|
|
var errUnexpectedArgumentAmount = fmt.Errorf("unexpected arguments amount in %s call", PutNotaryEvent)
|
|
|
|
|
|
|
|
// ParsePutNotary from NotaryEvent into container event structure.
|
|
|
|
func ParsePutNotary(ne event.NotaryEvent) (event.Event, error) {
|
2021-09-09 11:41:04 +00:00
|
|
|
var (
|
|
|
|
ev Put
|
|
|
|
currentOp opcode.Opcode
|
|
|
|
)
|
2021-08-25 11:29:58 +00:00
|
|
|
|
|
|
|
fieldNum := 0
|
|
|
|
|
|
|
|
for _, op := range ne.Params() {
|
2021-09-09 11:41:04 +00:00
|
|
|
currentOp = op.Code()
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case opcode.PUSHDATA1 <= currentOp && currentOp <= opcode.PUSHDATA4:
|
2021-09-09 08:48:13 +00:00
|
|
|
if fieldNum == expectedItemNumPut {
|
2021-08-25 11:29:58 +00:00
|
|
|
return nil, errUnexpectedArgumentAmount
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldSetters[fieldNum](&ev, op.Param())
|
|
|
|
fieldNum++
|
2021-09-09 11:41:04 +00:00
|
|
|
case opcode.PUSH0 <= currentOp && currentOp <= opcode.PUSH16 || currentOp == opcode.PACK:
|
|
|
|
// array packing opcodes. do nothing with it
|
2021-08-25 11:29:58 +00:00
|
|
|
default:
|
2021-09-09 11:41:04 +00:00
|
|
|
return nil, event.UnexpectedOpcode(PutNotaryEvent, op.Code())
|
2021-08-25 11:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.notaryRequest = ne.Raw()
|
|
|
|
|
|
|
|
return ev, nil
|
|
|
|
}
|