-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
523 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package registry | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/iotaledger/wasp/packages/hashing" | ||
"github.com/iotaledger/wasp/plugins/database" | ||
"github.com/iotaledger/wasp/plugins/publisher" | ||
) | ||
|
||
func dbkeyProgramCode(progHash *hashing.HashValue) []byte { | ||
return database.MakeKey(database.ObjectTypeProgramCode, progHash[:]) | ||
} | ||
|
||
// TODO save program code in the smart contract state | ||
func GetProgramCode(progHash *hashing.HashValue) ([]byte, error) { | ||
db := database.GetRegistryPartition() | ||
data, err := db.Get(dbkeyProgramCode(progHash)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
hash := hashing.HashData(data) | ||
if *hash != *progHash { | ||
return nil, fmt.Errorf("program code is corrupted. Expected: %s. Got: %s", progHash.String(), hash.String()) | ||
} | ||
return data, nil | ||
} | ||
|
||
func SaveProgramCode(programCode []byte) (ret hashing.HashValue, err error) { | ||
progHash := hashing.HashData(programCode) | ||
db := database.GetRegistryPartition() | ||
if err = db.Set(dbkeyProgramCode(progHash), programCode); err != nil { | ||
return | ||
} | ||
ret = *progHash | ||
|
||
defer publisher.Publish("programcode", progHash.String()) | ||
return | ||
} |
Oops, something went wrong.