diff --git a/app/consts_test.go b/app/consts_test.go index 682f958..966f434 100644 --- a/app/consts_test.go +++ b/app/consts_test.go @@ -82,9 +82,11 @@ var ( "created_by": "2ef471c2-f997-4503-94c8-60b5c929a3c3", "created_at": 1737045849174, "confirmation_status": "CONFIRMED", - "merklelog_commit": { - "index": "1", - "idtimestamp": "019470003611017900" + "event_type": "", + "ledger_entry": { + "index": "18446744073709551614", + "idtimestamp": "019470003611017900", + "log_id": "112758ce-a8cb-4924-8df8-fcba1e31f8b0" } } ] diff --git a/app/eventsv1.go b/app/eventsv1.go index 2f419fe..5c891d6 100644 --- a/app/eventsv1.go +++ b/app/eventsv1.go @@ -4,13 +4,12 @@ import ( "encoding/json" "errors" "sort" + "strconv" "strings" - "github.com/datatrails/go-datatrails-common-api-gen/assets/v2/assets" "github.com/datatrails/go-datatrails-logverification/logverification/app" "github.com/datatrails/go-datatrails-serialization/eventsv1" "github.com/google/uuid" - "google.golang.org/protobuf/encoding/protojson" ) var ( @@ -70,6 +69,24 @@ func NewEventsV1AppEntries(eventsJson []byte, logTenant string) ([]app.AppEntry, return events, nil } +type ledgerEntry struct { + Index string `json:"index,omitempty"` + Idtimestamp string `json:"idtimestamp,omitempty"` + LogId string `json:"log_id,omitempty"` +} + +type eventData struct { + Identity string `json:"identity,omitempty"` + OriginTenant string `json:"origin_tenant,omitempty"` + + Attributes map[string]any `json:"attributes,omitempty"` + Trails []string `json:"trails,omitempty"` + EventType string `json:"event_type,omitempty"` + + // Note: the proof_details top level field can be ignored here because it is a 'oneof' + LedgerEntry json.RawMessage `json:"ledger_entry,omitempty"` +} + // NewEventsV1AppEntry takes a single eventsv1 event JSON and returns a VerifiableEventsV1Event, // providing just enough information to verify and identify the event. func NewEventsV1AppEntry(eventJson []byte, logTenant string) (*app.AppEntry, error) { @@ -81,16 +98,7 @@ func NewEventsV1AppEntry(eventJson []byte, logTenant string) (*app.AppEntry, err // Unmarshal into a generic type to get just the bits we need. Use // defered decoding to get the raw merklelog entry as it must be // unmarshaled using protojson and the specific generated target type. - entry := struct { - Identity string `json:"identity,omitempty"` - OriginTenant string `json:"origin_tenant,omitempty"` - - Attributes map[string]any `json:"attributes,omitempty"` - Trails []string `json:"trails,omitempty"` - - // Note: the proof_details top level field can be ignored here because it is a 'oneof' - MerkleLogCommit json.RawMessage `json:"merklelog_commit,omitempty"` - }{} + entry := eventData{} err := json.Unmarshal(eventJson, &entry) if err != nil { @@ -102,6 +110,7 @@ func NewEventsV1AppEntry(eventJson []byte, logTenant string) (*app.AppEntry, err return nil, ErrInvalidEventsV1EventJson } + //TODO: don't need to pass in logTenant any more // if logTenant isn't given, default to the origin tenant // for log tenant. if logTenant == "" { @@ -109,8 +118,8 @@ func NewEventsV1AppEntry(eventJson []byte, logTenant string) (*app.AppEntry, err } // get the merklelog commit info - merkleLogCommit := &assets.MerkleLogCommit{} - err = protojson.Unmarshal(entry.MerkleLogCommit, merkleLogCommit) + eventLedgerEntry := &ledgerEntry{} + err = json.Unmarshal(entry.LedgerEntry, eventLedgerEntry) if err != nil { return nil, err } @@ -126,12 +135,18 @@ func NewEventsV1AppEntry(eventJson []byte, logTenant string) (*app.AppEntry, err serializableEvent := eventsv1.SerializableEvent{ Attributes: entry.Attributes, Trails: entry.Trails, + EventType: entry.EventType, } serializedBytes, err := serializableEvent.Serialize() if err != nil { return nil, err } + entryIndex, err := strconv.ParseUint(eventLedgerEntry.Index, 10, 64) + if err != nil { + return nil, err + } + return app.NewAppEntry( entry.Identity, logId[:], @@ -139,6 +154,6 @@ func NewEventsV1AppEntry(eventJson []byte, logTenant string) (*app.AppEntry, err byte(0), serializedBytes, ), - merkleLogCommit.Index, + entryIndex, ), nil } diff --git a/app/eventsv1_test.go b/app/eventsv1_test.go index d2dd02b..4ad039b 100644 --- a/app/eventsv1_test.go +++ b/app/eventsv1_test.go @@ -68,7 +68,7 @@ func TestVerifiableEventsV1EventsFromData(t *testing.T) { 0x5b, 0x5d, 0x7d, }, // serialized bytes ), - 1, // mmr index + 18446744073709551614, // mmr index ), }, err: nil, @@ -94,7 +94,7 @@ func TestVerifiableEventsV1EventsFromData(t *testing.T) { 0x5b, 0x5d, 0x7d, }, // serialized bytes ), - 1, // mmr index + 18446744073709551614, // mmr index ), }, err: nil, diff --git a/go.mod b/go.mod index c2a93de..de9b167 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/datatrails/go-datatrails-merklelog/massifs v0.4.0 github.com/datatrails/go-datatrails-merklelog/mmr v0.2.0 github.com/datatrails/go-datatrails-merklelog/mmrtesting v0.2.0 - github.com/datatrails/go-datatrails-serialization/eventsv1 v0.0.2 + github.com/datatrails/go-datatrails-serialization/eventsv1 v0.0.3 github.com/datatrails/go-datatrails-simplehash v0.0.5 github.com/gosuri/uiprogress v0.0.1 github.com/urfave/cli/v2 v2.27.6 diff --git a/go.sum b/go.sum index 76de847..295dbf3 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,8 @@ github.com/datatrails/go-datatrails-merklelog/mmr v0.2.0 h1:NUP0OUVixuyWf+Gmi/e3 github.com/datatrails/go-datatrails-merklelog/mmr v0.2.0/go.mod h1:iLipg39Ce3U68NjXFxjxwxXR9U0T6Dm6pldJA47Lx8s= github.com/datatrails/go-datatrails-merklelog/mmrtesting v0.2.0 h1:cv8JincUm3h/4hyVcuofPt5pAtOZ+KYLnsDdvQ3D6Lc= github.com/datatrails/go-datatrails-merklelog/mmrtesting v0.2.0/go.mod h1:h8b1O0xAoMv2DsVQuo6vNyM4RLL2DlJCWJqgysX127w= -github.com/datatrails/go-datatrails-serialization/eventsv1 v0.0.2 h1:yEk+0KvWkn/xYbf3WgdFCAZNkLE4pze9ySqeCr6Pnos= -github.com/datatrails/go-datatrails-serialization/eventsv1 v0.0.2/go.mod h1:9i6Tip2lIXwSZ3SxP7XEhU2eQ9zkpxhEBmPmlOGqv/8= +github.com/datatrails/go-datatrails-serialization/eventsv1 v0.0.3 h1:BLHfCXjzXUgr1knXE9XtZC+jNnf2orGEL+BTAWqSyp4= +github.com/datatrails/go-datatrails-serialization/eventsv1 v0.0.3/go.mod h1:9i6Tip2lIXwSZ3SxP7XEhU2eQ9zkpxhEBmPmlOGqv/8= github.com/datatrails/go-datatrails-simplehash v0.0.5 h1:igu4QRYO87RQXrJlqSm3fgMA2Q0F4jglWqBlfvKrXKQ= github.com/datatrails/go-datatrails-simplehash v0.0.5/go.mod h1:XuOwViwdL+dyz7fGYIjaByS1ElMFsrVI0goKX0bNimA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/tests/katdata/eventsingles.go b/tests/katdata/eventsingles.go index bd43e80..7c1eaea 100644 --- a/tests/katdata/eventsingles.go +++ b/tests/katdata/eventsingles.go @@ -85,9 +85,10 @@ var ( "created_by": "a3732a3f-1406-45b6-bdce-2976945752fc", "created_at": 1738143218368, "confirmation_status": "CONFIRMED", - "merklelog_commit": { + "ledger_entry": { "index": "4", - "idtimestamp": "0194b168bcde03be00" + "idtimestamp": "0194b168bcde03be00", + "log_id": "97e90a09-8c56-40df-a4de-42fde462ef6f" } }`)