Skip to content

Instantly share code, notes, and snippets.

@siburu
Last active June 27, 2019 07:57
Show Gist options
  • Save siburu/517330fbd0aa39fbd9f9637ab8f38c86 to your computer and use it in GitHub Desktop.
Save siburu/517330fbd0aa39fbd9f9637ab8f38c86 to your computer and use it in GitHub Desktop.
package main
import "github.com/ethereum/go-ethereum/common"
func main() {
hashes := []common.Hash{{1}, {2}, {3}}
ss := convertDirectly(hashes)
checkResult("direct", ss)
ss = convertIndirectly(hashes)
checkResult("indirect", ss)
}
func convertDirectly(hashes []common.Hash) (ss [][]byte) {
for _, hash := range hashes {
ss = append(ss, hash[:])
}
return
}
func convertIndirectly(hashes []common.Hash) (ss [][]byte) {
for _, hash := range hashes {
ss = append(ss, hash.Bytes())
}
return
}
func checkResult(title string, ss [][]byte) {
println(title)
for _, s := range ss {
println(s[0])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment