rpc: return tx hash, creates contract, contract addr in broadcast (required some helper functions). Closes #30

This commit is contained in:
Ethan Buchman
2015-03-21 02:44:20 -07:00
parent bf87ec1070
commit f93bb35c02
3 changed files with 41 additions and 11 deletions

View File

@ -61,16 +61,21 @@ func HashFromHashes(hashes [][]byte) []byte {
func HashFromBinaries(items []interface{}) []byte {
hashes := [][]byte{}
for _, item := range items {
hasher, n, err := sha256.New(), new(int64), new(error)
binary.WriteBinary(item, hasher, n, err)
if *err != nil {
panic(err)
}
hashes = append(hashes, hasher.Sum(nil))
hashes = append(hashes, HashFromBinary(item))
}
return HashFromHashes(hashes)
}
// General Convenience
func HashFromBinary(item interface{}) []byte {
hasher, n, err := sha256.New(), new(int64), new(error)
binary.WriteBinary(item, hasher, n, err)
if *err != nil {
panic(err)
}
return hasher.Sum(nil)
}
// Convenience for HashFromHashes.
func HashFromHashables(items []Hashable) []byte {
hashes := [][]byte{}