mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
Added pretty print to data/typed UI
This commit is contained in:
parent
89348aaf1e
commit
346518d442
2 changed files with 14 additions and 5 deletions
|
|
@ -164,7 +164,7 @@ func (ui *CommandlineUI) ApproveSignData(request *SignDataRequest) (SignDataResp
|
||||||
|
|
||||||
fmt.Printf("-------- Sign data request--------------\n")
|
fmt.Printf("-------- Sign data request--------------\n")
|
||||||
fmt.Printf("Account: %s\n", request.Address.String())
|
fmt.Printf("Account: %s\n", request.Address.String())
|
||||||
fmt.Printf("message: \n%q\n", request.Message)
|
fmt.Printf("message: \n%v\n", request.Message)
|
||||||
fmt.Printf("raw data: \n%v\n", request.Rawdata)
|
fmt.Printf("raw data: \n%v\n", request.Rawdata)
|
||||||
fmt.Printf("message hash: %v\n", request.Hash)
|
fmt.Printf("message hash: %v\n", request.Hash)
|
||||||
fmt.Printf("-------------------------------------------\n")
|
fmt.Printf("-------------------------------------------\n")
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package core
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -275,9 +276,12 @@ func (api *SignerAPI) SignTypedData(ctx context.Context, addr common.MixedcaseAd
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
msg := fmt.Sprintf("\x19\x01%s%s", string(domainSeparator), string(typedDataHash))
|
msg, err := json.MarshalIndent(typedData.Message, "", " ")
|
||||||
sighash := crypto.Keccak256([]byte(msg))
|
if err != nil {
|
||||||
req := &SignDataRequest{ContentType: DataTyped.Mime, Rawdata: typedData.Map(), Message: msg, Hash: sighash}
|
return nil, err
|
||||||
|
}
|
||||||
|
sighash := crypto.Keccak256([]byte(fmt.Sprintf("\x19\x01%s%s", string(domainSeparator), string(typedDataHash))))
|
||||||
|
req := &SignDataRequest{ContentType: DataTyped.Mime, Rawdata: typedData, Message: string(msg), Hash: sighash}
|
||||||
signature, err := api.Sign(ctx, addr, req)
|
signature, err := api.Sign(ctx, addr, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.UI.ShowError(err.Error())
|
api.UI.ShowError(err.Error())
|
||||||
|
|
@ -591,7 +595,7 @@ func (typedData *TypedData) IsValid() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map is a helper function to generate a map version of the typed data
|
// Map generates a map version of the typed data
|
||||||
func (typedData *TypedData) Map() map[string]interface{} {
|
func (typedData *TypedData) Map() map[string]interface{} {
|
||||||
dataMap := map[string]interface{}{
|
dataMap := map[string]interface{}{
|
||||||
"types": typedData.Types,
|
"types": typedData.Types,
|
||||||
|
|
@ -603,6 +607,11 @@ func (typedData *TypedData) Map() map[string]interface{} {
|
||||||
return dataMap
|
return dataMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrettyPrint generates a pretty version of the typed data
|
||||||
|
func (typedData *TypedData) PrettyPrint() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// IsValid checks if the types object is conformant to the specs
|
// IsValid checks if the types object is conformant to the specs
|
||||||
func (types *EIP712Types) IsValid() error {
|
func (types *EIP712Types) IsValid() error {
|
||||||
for typeKey, typeArr := range *types {
|
for typeKey, typeArr := range *types {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue