Skip to content

Commit 6c7c1d4

Browse files
committed
feat: return proof bytes for value by keyHash
1 parent 01fcbb7 commit 6c7c1d4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

internal/api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ func handleGetValueByKeyHash(c *gin.Context) {
509509
// Convert value hash to hex for JSON response
510510
response := map[string]interface{}{
511511
"valueHash": hex.EncodeToString(result.ValueHash),
512+
"proof": result.Proof,
512513
"timestamp": result.Timestamp.Format(time.RFC3339Nano),
513514
"slot": result.Slot,
514515
}

internal/database/operation.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ type ValueHashWithTimestamp struct {
913913
ValueHash []byte `json:"valueHash"`
914914
Timestamp time.Time `json:"timestamp"`
915915
Slot int64 `json:"slot"`
916+
Proof string `json:"proof"`
916917
}
917918

918919
// GetValueByKey returns the current value for a specific object ID and raw key,
@@ -1032,9 +1033,26 @@ func (d *Database) GetValueHashByKeyHash(
10321033
return nil, nil
10331034
}
10341035

1036+
proof, err := d.ProveTrie(keyHash)
1037+
if err != nil {
1038+
return nil, fmt.Errorf(
1039+
"failed to prove trie for key hash %x: %w",
1040+
keyHash, err,
1041+
)
1042+
}
1043+
1044+
proofBytes, err := proof.MarshalCBOR()
1045+
if err != nil {
1046+
return nil, fmt.Errorf(
1047+
"failed to marshal proof for key hash %x: %w",
1048+
keyHash, err,
1049+
)
1050+
}
1051+
10351052
return &ValueHashWithTimestamp{
10361053
ValueHash: result.ValueHash,
10371054
Timestamp: result.DataTimestamp.UTC(),
10381055
Slot: result.DataSlot,
1056+
Proof: hex.EncodeToString(proofBytes),
10391057
}, nil
10401058
}

0 commit comments

Comments
 (0)