signer: fix listresponse, fix gas->uint64

This commit is contained in:
Martin Holst Swende 2018-02-22 12:46:22 +01:00
parent 69a96f8fef
commit 888c11e801
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
9 changed files with 84 additions and 35 deletions

View file

@ -125,9 +125,9 @@ func (m Metadata) String() string {
type ( type (
// SignTxRequest contains info about a Transaction to sign // SignTxRequest contains info about a Transaction to sign
SignTxRequest struct { SignTxRequest struct {
Transaction SendTxArgs `json:"transaction"` Transaction SendTxArgs `json:"transaction"`
Callinfo *ValidationMessages `json:"call_info"` Callinfo []ValidationInfo `json:"call_info"`
Meta Metadata `json:"meta"` Meta Metadata `json:"meta"`
} }
// SignTxResponse result from SignTxRequest // SignTxResponse result from SignTxRequest
SignTxResponse struct { SignTxResponse struct {
@ -287,7 +287,7 @@ func logDiff(original *SignTxRequest, new *SignTxResponse) bool {
log.Info("Recipient-account changed by UI", "was", t0, "is", t1) log.Info("Recipient-account changed by UI", "was", t0, "is", t1)
modified = true modified = true
} }
if g0, g1 := big.Int(original.Transaction.Gas), big.Int(new.Transaction.Gas); g0.Cmp(&g1) != 0 { if g0, g1 := original.Transaction.Gas, new.Transaction.Gas; g0 != g1 {
modified = true modified = true
log.Info("Gas changed by UI", "was", g0, "is", g1) log.Info("Gas changed by UI", "was", g0, "is", g1)
} }
@ -334,7 +334,7 @@ func (api *SignerAPI) SignTransaction(ctx context.Context, args SendTxArgs, meth
req := SignTxRequest{ req := SignTxRequest{
Transaction: args, Transaction: args,
Meta: MetadataFromContext(ctx), Meta: MetadataFromContext(ctx),
Callinfo: msgs, Callinfo: msgs.Messages,
} }
// Process approval // Process approval
result, err = api.UI.ApproveTx(&req) result, err = api.UI.ApproveTx(&req)

View file

@ -241,7 +241,7 @@ func TestSignData(t *testing.T) {
} }
func mkTestTx(from common.MixedcaseAddress) SendTxArgs { func mkTestTx(from common.MixedcaseAddress) SendTxArgs {
to := common.NewMixedcaseAddress(common.HexToAddress("0x1337")) to := common.NewMixedcaseAddress(common.HexToAddress("0x1337"))
gas := (hexutil.Big)(*big.NewInt(21000)) gas := hexutil.Uint64(21000)
gasPrice := (hexutil.Big)(*big.NewInt(2000000000)) gasPrice := (hexutil.Big)(*big.NewInt(2000000000))
value := (hexutil.Big)(*big.NewInt(1e18)) value := (hexutil.Big)(*big.NewInt(1e18))
nonce := (hexutil.Uint64)(0) nonce := (hexutil.Uint64)(0)

View file

@ -119,7 +119,7 @@ func (ui *CommandlineUI) ApproveTx(request *SignTxRequest) (SignTxResponse, erro
} }
if request.Callinfo != nil { if request.Callinfo != nil {
fmt.Printf("\nTransaction validation:\n") fmt.Printf("\nTransaction validation:\n")
for _, m := range request.Callinfo.Messages { for _, m := range request.Callinfo {
fmt.Printf(" * %s : %s", m.Typ, m.Message) fmt.Printf(" * %s : %s", m.Typ, m.Message)
} }
fmt.Println() fmt.Println()

View file

@ -45,12 +45,7 @@ func NewStdIOUI() *StdIOUI {
// dispatch sends a request over the stdio // dispatch sends a request over the stdio
func (ui *StdIOUI) dispatch(serviceMethod string, args interface{}, reply interface{}) error { func (ui *StdIOUI) dispatch(serviceMethod string, args interface{}, reply interface{}) error {
var err error err := ui.client.Call(&reply, serviceMethod, args)
if reply != nil {
err = ui.client.Call(nil, serviceMethod, args)
} else {
err = ui.client.Call(&reply, serviceMethod, args)
}
if err != nil { if err != nil {
log.Info("Error", "exc", err.Error()) log.Info("Error", "exc", err.Error())
} }

View file

@ -76,7 +76,7 @@ type TransactionArg struct {
type SendTxArgs struct { type SendTxArgs struct {
From common.MixedcaseAddress `json:"from"` From common.MixedcaseAddress `json:"from"`
To *common.MixedcaseAddress `json:"to"` To *common.MixedcaseAddress `json:"to"`
Gas hexutil.Big `json:"gas"` Gas hexutil.Uint64 `json:"gas"`
GasPrice hexutil.Big `json:"gasPrice"` GasPrice hexutil.Big `json:"gasPrice"`
Value hexutil.Big `json:"value"` Value hexutil.Big `json:"value"`
Nonce hexutil.Uint64 `json:"nonce"` Nonce hexutil.Uint64 `json:"nonce"`
@ -101,7 +101,7 @@ func (args *SendTxArgs) toTransaction() *types.Transaction {
input = *args.Input input = *args.Input
} }
if args.To == nil { if args.To == nil {
return types.NewContractCreation(uint64(args.Nonce), (*big.Int)(&args.Value), (*big.Int)(&args.Gas), (*big.Int)(&args.GasPrice), input) return types.NewContractCreation(uint64(args.Nonce), (*big.Int)(&args.Value), uint64(args.Gas), (*big.Int)(&args.GasPrice), input)
} }
return types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (*big.Int)(&args.Gas), (*big.Int)(&args.GasPrice), input) return types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (uint64)(args.Gas), (*big.Int)(&args.GasPrice), input)
} }

View file

@ -41,7 +41,7 @@ func dummyTxArgs(t txtestcase) *SendTxArgs {
to, _ := mixAddr(t.to) to, _ := mixAddr(t.to)
from, _ := mixAddr(t.from) from, _ := mixAddr(t.from)
n := toHexUint(t.n) n := toHexUint(t.n)
gas := toHexBig(t.g) gas := toHexUint(t.g)
gasPrice := toHexBig(t.gp) gasPrice := toHexBig(t.gp)
value := toHexBig(t.value) value := toHexBig(t.value)
var ( var (
@ -61,8 +61,8 @@ func dummyTxArgs(t txtestcase) *SendTxArgs {
To: to, To: to,
Value: value, Value: value,
Nonce: n, Nonce: n,
GasPrice: gas, GasPrice: gasPrice,
Gas: gasPrice, Gas: gas,
Data: data, Data: data,
Input: input, Input: input,
} }

View file

@ -1,5 +1,46 @@
### Changelog for internal API (ui-api) ### Changelog for internal API (ui-api)
### 2.0.0
* Modify how `call_info` on a transaction is conveyed. New format:
```
{
"jsonrpc": "2.0",
"id": 2,
"method": "ApproveTx",
"params": [
{
"transaction": {
"from": "0x82A2A876D39022B3019932D30Cd9c97ad5616813",
"to": "0x07a565b7ed7d7a678680a4c162885bedbb695fe0",
"gas": "0x333",
"gasPrice": "0x123",
"value": "0x10",
"nonce": "0x0",
"data": "0x4401a6e40000000000000000000000000000000000000000000000000000000000000012",
"input": null
},
"call_info": [
{
"type": "WARNING",
"message": "Invalid checksum on to-address"
},
{
"type": "WARNING",
"message": "Tx contains data, but provided ABI signature could not be matched: Did not match: test (0 matches)"
}
],
"meta": {
"remote": "127.0.0.1:54286",
"local": "localhost:8550",
"scheme": "HTTP/1.1"
}
}
]
}
```
#### 1.2.0 #### 1.2.0
* Add `OnStartup` method, to provide the UI with information about what API version * Add `OnStartup` method, to provide the UI with information about what API version

View file

@ -51,7 +51,7 @@ import (
const EXT_API_VERSION = "2.0.0" const EXT_API_VERSION = "2.0.0"
// INT_API_VERSION -- see intapi_changelog.md // INT_API_VERSION -- see intapi_changelog.md
const INT_API_VERSION = "1.2.0" const INT_API_VERSION = "2.0.0"
const legal_warning = ` const legal_warning = `
WARNING! WARNING!
@ -179,6 +179,7 @@ func init() {
utils.LightKDFFlag, utils.LightKDFFlag,
utils.NoUSBFlag, utils.NoUSBFlag,
utils.RPCListenAddrFlag, utils.RPCListenAddrFlag,
utils.RPCVirtualHostsFlag,
rpcPortFlag, rpcPortFlag,
signerSecretFlag, signerSecretFlag,
dBFlag, dBFlag,
@ -291,14 +292,18 @@ func addCredential(ctx *cli.Context) error {
} }
func initialize(c *cli.Context) error { func initialize(c *cli.Context) error {
if !confirm(legal_warning) {
return fmt.Errorf("aborted by user")
}
// Set up the logger to print everything // Set up the logger to print everything
logOutput := os.Stdout logOutput := os.Stdout
if c.Bool(stdiouiFlag.Name) { if c.Bool(stdiouiFlag.Name) {
logOutput = os.Stderr logOutput = os.Stderr
// If using the stdioui, we can't do the 'confirm'-flow
fmt.Fprintf(logOutput, legal_warning)
} else {
if !confirm(legal_warning) {
return fmt.Errorf("aborted by user")
}
} }
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(c.Int(logLevelFlag.Name)), log.StreamHandler(logOutput, log.TerminalFormat(true)))) log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(c.Int(logLevelFlag.Name)), log.StreamHandler(logOutput, log.TerminalFormat(true))))
return nil return nil
} }
@ -416,12 +421,22 @@ func signer(c *cli.Context) error {
"extapi_ipc": nil, "extapi_ipc": nil,
}, },
}) })
vhosts := splitAndTrim(c.GlobalString(utils.RPCVirtualHostsFlag.Name))
rpc.NewHTTPServer(cors, server).Serve(listener) rpc.NewHTTPServer(cors, vhosts, server).Serve(listener)
return nil return nil
} }
// splitAndTrim splits input separated by a comma
// and trims excessive white space from the substrings.
func splitAndTrim(input string) []string {
result := strings.Split(input, ",")
for i, r := range result {
result[i] = strings.TrimSpace(r)
}
return result
}
// DefaultConfigDir is the default config directory to use for the vaults and other // DefaultConfigDir is the default config directory to use for the vaults and other
// persistence requirements. // persistence requirements.
func DefaultConfigDir() string { func DefaultConfigDir() string {
@ -570,10 +585,10 @@ curl -i -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","me
// 4401a6e40000000000000000000000000000000000000000000000000000000000000012 // 4401a6e40000000000000000000000000000000000000000000000000000000000000012
// supplied abi // supplied abi
curl -i -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"account_signTransaction","params":["0x82A2A876D39022B3019932D30Cd9c97ad5616813",{"gas":"0x333","gasPrice":"0x123","nonce":"0x0","to":"0x07a565b7ed7d7a678680a4c162885bedbb695fe0", "value":"0x10", "data":"0x4401a6e40000000000000000000000000000000000000000000000000000000000000012"},"test"],"id":67}' http://localhost:8550/ curl -i -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"account_signTransaction","params":[{"from":"0x82A2A876D39022B3019932D30Cd9c97ad5616813","gas":"0x333","gasPrice":"0x123","nonce":"0x0","to":"0x07a565b7ed7d7a678680a4c162885bedbb695fe0", "value":"0x10", "data":"0x4401a6e40000000000000000000000000000000000000000000000000000000000000012"},"test"],"id":67}' http://localhost:8550/
// Not supplied // Not supplied
curl -i -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"account_signTransaction","params":["0x82A2A876D39022B3019932D30Cd9c97ad5616813",{"gas":"0x333","gasPrice":"0x123","nonce":"0x0","to":"0x07a565b7ed7d7a678680a4c162885bedbb695fe0", "value":"0x10", "data":"0x4401a6e40000000000000000000000000000000000000000000000000000000000000012"}],"id":67}' http://localhost:8550/ curl -i -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"account_signTransaction","params":[{"from":"0x82A2A876D39022B3019932D30Cd9c97ad5616813","gas":"0x333","gasPrice":"0x123","nonce":"0x0","to":"0x07a565b7ed7d7a678680a4c162885bedbb695fe0", "value":"0x10", "data":"0x4401a6e40000000000000000000000000000000000000000000000000000000000000012"}],"id":67}' http://localhost:8550/
// Sign data // Sign data

View file

@ -422,7 +422,7 @@ func dummyTx(value hexutil.Big) *core.SignTxRequest {
to, _ := mixAddr("000000000000000000000000000000000000dead") to, _ := mixAddr("000000000000000000000000000000000000dead")
from, _ := mixAddr("000000000000000000000000000000000000dead") from, _ := mixAddr("000000000000000000000000000000000000dead")
n := hexutil.Uint64(3) n := hexutil.Uint64(3)
gas := hexutil.Big(*big.NewInt(21000)) gas := hexutil.Uint64(21000)
gasPrice := hexutil.Big(*big.NewInt(2000000)) gasPrice := hexutil.Big(*big.NewInt(2000000))
return &core.SignTxRequest{ return &core.SignTxRequest{
@ -431,13 +431,11 @@ func dummyTx(value hexutil.Big) *core.SignTxRequest {
To: to, To: to,
Value: value, Value: value,
Nonce: n, Nonce: n,
GasPrice: gas, GasPrice: gasPrice,
Gas: gasPrice, Gas: gas,
}, },
Callinfo: &core.ValidationMessages{ Callinfo: []core.ValidationInfo{
[]core.ValidationInfo{ {"Warning", "All your base are bellong to us"},
{"Warning", "All your base are bellong to us"},
},
}, },
Meta: core.Metadata{"remoteip", "localip", "inproc"}, Meta: core.Metadata{"remoteip", "localip", "inproc"},
} }
@ -450,7 +448,7 @@ func dummyTxWithV(value uint64) *core.SignTxRequest {
} }
func dummySigned(value *big.Int) *types.Transaction { func dummySigned(value *big.Int) *types.Transaction {
to := common.HexToAddress("000000000000000000000000000000000000dead") to := common.HexToAddress("000000000000000000000000000000000000dead")
gas := big.NewInt(21000) gas := uint64(21000)
gasPrice := big.NewInt(2000000) gasPrice := big.NewInt(2000000)
data := make([]byte, 0) data := make([]byte, 0)
return types.NewTransaction(3, to, value, gas, gasPrice, data) return types.NewTransaction(3, to, value, gas, gasPrice, data)