1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00
any-sync/commonspace/object/tree/objecttree/change.go
mcrakhman 3b2acf8021
Merge remote-tracking branch 'origin/add-content-with-validator' into GO-3996-add-tree-transactions
# Conflicts:
#	commonspace/object/tree/objecttree/change.go
#	commonspace/object/tree/objecttree/objecttree.go
#	commonspace/object/tree/synctree/synctree_test.go
2024-08-29 16:17:50 +02:00

62 lines
1.4 KiB
Go

package objecttree
import (
"errors"
"github.com/anyproto/protobuf/proto"
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
"github.com/anyproto/any-sync/util/crypto"
)
var (
ErrIncorrectSignature = errors.New("change has incorrect signature")
ErrIncorrectCid = errors.New("change has incorrect CID")
)
// Change is an abstract type for all types of changes
type Change struct {
Next []*Change
PreviousIds []string
AclHeadId string
Id string
SnapshotId string
Timestamp int64
ReadKeyId string
Identity crypto.PubKey
Data []byte
Model interface{}
Signature []byte
DataType string
IsSnapshot bool
IsDerived bool
IsNew bool
// iterator helpers
visited bool
branchesFinished bool
}
func NewChangeFromRoot(id string, identity crypto.PubKey, ch *treechangeproto.RootChange, signature []byte, isDerived bool) *Change {
changeInfo := &treechangeproto.TreeChangeInfo{
ChangeType: ch.ChangeType,
ChangePayload: ch.ChangePayload,
}
data, _ := proto.Marshal(changeInfo)
return &Change{
Next: nil,
AclHeadId: ch.AclHeadId,
Id: id,
IsSnapshot: true,
Timestamp: ch.Timestamp,
Identity: identity,
Signature: signature,
Data: data,
Model: changeInfo,
IsDerived: isDerived,
}
}
func (ch *Change) Cid() string {
return ch.Id
}