Skip to content

Commit

Permalink
feat(manifest): implement Version function
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Jul 18, 2023
1 parent 4a220dd commit f7be814
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions go/manifest/v2beta2/manifest.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package v2beta2

import (
"crypto/sha256"
"encoding/json"
"fmt"
"regexp"

sdk "github.com/cosmos/cosmos-sdk/types"

dtypes "github.com/akash-network/akash-api/go/node/deployment/v1beta3"
)

Expand Down Expand Up @@ -43,3 +47,21 @@ func (m Manifest) CheckAgainstDeployment(dgroups []dtypes.Group) error {
func (m Manifest) CheckAgainstGSpecs(gspecs dtypes.GroupSpecs) error {
return m.GetGroups().CheckAgainstGSpecs(gspecs)
}

// Version calculates the identifying deterministic hash for an SDL.
// Sha256 returns 32 byte sum of the SDL.
func (m Manifest) Version() ([]byte, error) {
data, err := json.Marshal(m)
if err != nil {
return nil, err
}

sortedBytes, err := sdk.SortJSON(data)
if err != nil {
return nil, err
}

sum := sha256.Sum256(sortedBytes)

return sum[:], nil
}

0 comments on commit f7be814

Please sign in to comment.