Skip to content

Commit

Permalink
cmd/evm: add hash to t9n tool
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Sep 4, 2021
1 parent 8d8a21a commit 4e4d17c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions cmd/evm/internal/t8ntool/transaction.go
Expand Up @@ -36,20 +36,25 @@ import (
type result struct {
Error error
Address common.Address
Hash common.Hash
}

// MarshalJSON marshals as JSON with a hash.
func (r *result) MarshalJSON() ([]byte, error) {
type xx struct {
Error string `json:"error,omitempty"`
Address *common.Address `json:"address,omitempty"`
Hash *common.Hash `json:"hash,omitempty"`
}
var out xx
if r.Error != nil {
out.Error = r.Error.Error()
}
if r.Address != (common.Address{}) {
out.Address = &r.Address
}
if r.Error != nil {
out.Error = r.Error.Error()
if r.Hash != (common.Hash{}) {
out.Hash = &r.Hash
}
return json.Marshal(out)
}
Expand Down Expand Up @@ -124,7 +129,7 @@ func Transaction(ctx *cli.Context) error {
results = append(results, result{Error: err})
continue
}
results = append(results, result{Address: sender})
results = append(results, result{Address: sender, Hash: tx.Hash()})
}
out, err := json.MarshalIndent(results, "", " ")
fmt.Println(string(out))
Expand Down
6 changes: 4 additions & 2 deletions cmd/evm/testdata/15/exp2.json
@@ -1,8 +1,10 @@
[
{
"address": "0xd02d72e067e77158444ef2020ff2d325f929b363"
"address": "0xd02d72e067e77158444ef2020ff2d325f929b363",
"hash": "0xa98a24882ea90916c6a86da650fbc6b14238e46f0af04a131ce92be897507476"
},
{
"address": "0xd02d72e067e77158444ef2020ff2d325f929b363"
"address": "0xd02d72e067e77158444ef2020ff2d325f929b363",
"hash": "0x36bad80acce7040c45fd32764b5c2b2d2e6f778669fb41791f73f546d56e739a"
}
]

0 comments on commit 4e4d17c

Please sign in to comment.