diff --git a/go/manifest/v2beta2/manifest.go b/go/manifest/v2beta2/manifest.go index 43480448..69b7ce95 100644 --- a/go/manifest/v2beta2/manifest.go +++ b/go/manifest/v2beta2/manifest.go @@ -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" ) @@ -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 +}