Last active
June 27, 2019 07:57
-
-
Save siburu/517330fbd0aa39fbd9f9637ab8f38c86 to your computer and use it in GitHub Desktop.
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
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