diff --git a/consensus/types/proposal.go b/consensus/types/proposal.go index a306f032a..d2fb4b15f 100644 --- a/consensus/types/proposal.go +++ b/consensus/types/proposal.go @@ -39,8 +39,7 @@ func (p *Proposal) String() string { } func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - // We hex encode the chain_id name so we don't deal with escaping issues. - binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err) + binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err) binary.WriteTo([]byte(`,"proposal":{"block_parts":`), w, n, err) p.BlockParts.WriteSignBytes(w, n, err) binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_parts":`, p.Height)), w, n, err) diff --git a/consensus/types/proposal_test.go b/consensus/types/proposal_test.go index fa8f37be3..5cc4a5f38 100644 --- a/consensus/types/proposal_test.go +++ b/consensus/types/proposal_test.go @@ -19,7 +19,7 @@ func TestProposalSignable(t *testing.T) { } signBytes := account.SignBytes(config.GetString("chain_id"), proposal) signStr := string(signBytes) - expected := Fmt(`{"chain_id":"%X","proposal":{"block_parts":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_parts":{"hash":"706F6C7061727473","total":222},"round":23456}}`, + expected := Fmt(`{"chain_id":"%s","proposal":{"block_parts":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_parts":{"hash":"706F6C7061727473","total":222},"round":23456}}`, config.GetString("chain_id")) if signStr != expected { t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr) diff --git a/types/names.go b/types/names.go index 22d20a357..3e31991fa 100644 --- a/types/names.go +++ b/types/names.go @@ -38,7 +38,7 @@ func BaseEntryCost(name, data string) uint64 { type NameRegEntry struct { Name string `json:"name"` // registered name for the entry Owner []byte `json:"owner"` // address that created the entry - Data string `json:"data"` // binary encoded byte array + Data string `json:"data"` // data to store under this name Expires uint64 `json:"expires"` // block at which this entry expires } diff --git a/types/tx.go b/types/tx.go index 8bb596407..811ab1fd0 100644 --- a/types/tx.go +++ b/types/tx.go @@ -135,8 +135,7 @@ type SendTx struct { } func (tx *SendTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - // We hex encode the chain_id so we don't deal with escaping issues. - binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err) + binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err) for i, in := range tx.Inputs { in.WriteSignBytes(w, n, err) @@ -169,8 +168,7 @@ type CallTx struct { } func (tx *CallTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - // We hex encode the chain_id so we don't deal with escaping issues. - binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err) + binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","data":"%X"`, TxTypeCall, tx.Address, tx.Data)), w, n, err) binary.WriteTo([]byte(Fmt(`,"fee":%v,"gas_limit":%v,"input":`, tx.Fee, tx.GasLimit)), w, n, err) tx.Input.WriteSignBytes(w, n, err) @@ -191,8 +189,7 @@ type NameTx struct { } func (tx *NameTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - // We hex encode the network name so we don't deal with escaping issues. - binary.WriteTo([]byte(Fmt(`{"network":"%X"`, chainID)), w, n, err) + binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"name":"%s","data":"%s"`, TxTypeName, tx.Name, tx.Data)), w, n, err) binary.WriteTo([]byte(Fmt(`,"fee":%v,"input":`, tx.Fee)), w, n, err) tx.Input.WriteSignBytes(w, n, err) @@ -239,8 +236,7 @@ type BondTx struct { } func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - // We hex encode the chain_id so we don't deal with escaping issues. - binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err) + binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err) for i, in := range tx.Inputs { in.WriteSignBytes(w, n, err) @@ -273,8 +269,7 @@ type UnbondTx struct { } func (tx *UnbondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - // We hex encode the chain_id so we don't deal with escaping issues. - binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err) + binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err) } @@ -291,8 +286,7 @@ type RebondTx struct { } func (tx *RebondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - // We hex encode the chain_id so we don't deal with escaping issues. - binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err) + binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err) } diff --git a/types/tx_test.go b/types/tx_test.go index 5ac1f908d..703f873ed 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -41,7 +41,7 @@ func TestSendTxSignable(t *testing.T) { } signBytes := account.SignBytes(chainID, sendTx) signStr := string(signBytes) - expected := Fmt(`{"chain_id":"%X","tx":[1,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"outputs":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`, + expected := Fmt(`{"chain_id":"%s","tx":[1,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"outputs":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`, config.GetString("chain_id")) if signStr != expected { t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr) @@ -62,7 +62,7 @@ func TestCallTxSignable(t *testing.T) { } signBytes := account.SignBytes(chainID, callTx) signStr := string(signBytes) - expected := Fmt(`{"chain_id":"%X","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`, + expected := Fmt(`{"chain_id":"%s","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`, config.GetString("chain_id")) if signStr != expected { t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr) @@ -98,7 +98,7 @@ func TestBondTxSignable(t *testing.T) { } signBytes := account.SignBytes(chainID, bondTx) signStr := string(signBytes) - expected := Fmt(`{"chain_id":"%X","tx":[17,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"pub_key":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"unbond_to":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`, + expected := Fmt(`{"chain_id":"%s","tx":[17,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"pub_key":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"unbond_to":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`, config.GetString("chain_id")) if signStr != expected { t.Errorf("Got unexpected sign string for BondTx") @@ -112,7 +112,7 @@ func TestUnbondTxSignable(t *testing.T) { } signBytes := account.SignBytes(chainID, unbondTx) signStr := string(signBytes) - expected := Fmt(`{"chain_id":"%X","tx":[18,{"address":"6164647265737331","height":111}]}`, + expected := Fmt(`{"chain_id":"%s","tx":[18,{"address":"6164647265737331","height":111}]}`, config.GetString("chain_id")) if signStr != expected { t.Errorf("Got unexpected sign string for UnbondTx") @@ -126,7 +126,7 @@ func TestRebondTxSignable(t *testing.T) { } signBytes := account.SignBytes(chainID, rebondTx) signStr := string(signBytes) - expected := Fmt(`{"chain_id":"%X","tx":[19,{"address":"6164647265737331","height":111}]}`, + expected := Fmt(`{"chain_id":"%s","tx":[19,{"address":"6164647265737331","height":111}]}`, config.GetString("chain_id")) if signStr != expected { t.Errorf("Got unexpected sign string for RebondTx") diff --git a/types/vote.go b/types/vote.go index def488e92..365b5a9af 100644 --- a/types/vote.go +++ b/types/vote.go @@ -46,8 +46,7 @@ const ( ) func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { - // We hex encode the chain_id name so we don't deal with escaping issues. - binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err) + binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err) binary.WriteTo([]byte(Fmt(`,"vote":{"block_hash":"%X","block_parts":%v`, vote.BlockHash, vote.BlockParts)), w, n, err) binary.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err) }